Compare commits
127
Commits
42b5019464
...
v0.1.38
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d2e491348d | ||
|
|
562d278f60 | ||
|
|
c6f6faf64f | ||
|
|
1c3ee9e8c7 | ||
|
|
aa91063211 | ||
|
|
fa2d5d40dd | ||
|
|
6ccef162f6 | ||
|
|
48dac139a5 | ||
|
|
a090e5af20 | ||
|
|
0c1358b862 | ||
|
|
a9035c4c3b | ||
|
|
137c7c005f | ||
|
|
8eeea968f2 | ||
|
|
0ca6568005 | ||
|
|
af90db44c9 | ||
|
|
5de46e9c0e | ||
|
|
1d9b677c1b | ||
|
|
54178ee56c | ||
|
|
10e7597612 | ||
|
|
142ccbc587 | ||
|
|
f75ad48d78 | ||
|
|
5a9e8f79f9 | ||
|
|
fbea74a74b | ||
|
|
925dc33696 | ||
|
|
4b0737e1cd | ||
|
|
4f4007aff1 | ||
|
|
8e687c4420 | ||
|
|
604f20eed7 | ||
|
|
6a2da94e47 | ||
|
|
e121ca900e | ||
|
|
79629c5a2c | ||
|
|
026e451aa4 | ||
|
|
f11c675d11 | ||
|
|
0fae09ba3c | ||
|
|
8f642bd618 | ||
|
|
6643c8fc1e | ||
|
|
fd90b60430 | ||
|
|
0aae6f0539 | ||
|
|
be7b79612c | ||
|
|
557c77670b | ||
|
|
d277218784 | ||
|
|
cf16a7b27a | ||
|
|
51bf14f376 | ||
|
|
8d9bcfd8b5 | ||
|
|
3c7a593f63 | ||
|
|
9d1352ba30 | ||
|
|
4cf2bfeb3e | ||
|
|
94c94fefb4 | ||
|
|
d600bca374 | ||
|
|
ffaab543d2 | ||
|
|
41db78c201 | ||
|
|
c042244da8 | ||
|
|
5a2e99f496 | ||
|
|
8a925782ab | ||
|
|
7685a103e8 | ||
|
|
ee5c881df9 | ||
|
|
6814a41ae4 | ||
|
|
dd7ad4d9c7 | ||
|
|
934db6d44b | ||
|
|
d307e29145 | ||
|
|
ff88142471 | ||
|
|
887e9beb9e | ||
|
|
e6457b3f6b | ||
|
|
eb0c01c5d2 | ||
|
|
40cc012124 | ||
|
|
44196f5620 | ||
|
|
9ceb1b8c22 | ||
|
|
32c234fbdb | ||
|
|
d65d7a8e5f | ||
|
|
b5f5be15f6 | ||
|
|
f5949427cc | ||
|
|
5d1287735e | ||
|
|
7ea0cb8655 | ||
|
|
b553513c9f | ||
|
|
b5a4eb177a | ||
|
|
f1a5be2a93 | ||
|
|
add7a99f6d | ||
|
|
982ef636b8 | ||
|
|
9aad49f16d | ||
|
|
2b5c14385d | ||
|
|
bca3e46293 | ||
|
|
f09d2bf9df | ||
|
|
702421be48 | ||
|
|
bb471df21c | ||
|
|
bfb0d7d7c9 | ||
|
|
1974bf1a2b | ||
|
|
0c9bf6758c | ||
|
|
25da7d49a9 | ||
|
|
40c10089ab | ||
|
|
d6e7c8b0b1 | ||
|
|
5bc7d748f8 | ||
|
|
7117673ecc | ||
|
|
14351b0c94 | ||
|
|
ad57fad1ea | ||
|
|
fa32cca03f | ||
|
|
2d0551a845 | ||
|
|
bb84122061 | ||
|
|
b823a22b9b | ||
|
|
70fc6da811 | ||
|
|
729b84d3af | ||
|
|
b962f6756e | ||
|
|
79d00b84e3 | ||
|
|
842be5edb5 | ||
|
|
7e59a7f2b3 | ||
|
|
5bfbe9a887 | ||
|
|
01f91154e0 | ||
|
|
6c2940aebc | ||
|
|
670693bde8 | ||
|
|
bca6a7c8aa | ||
|
|
21c1fa49b6 | ||
|
|
435b924fd9 | ||
|
|
af5c6af0e7 | ||
|
|
c6ef644842 | ||
|
|
5783d43547 | ||
|
|
e4d2d10c7e | ||
|
|
fe62fd4644 | ||
|
|
9ecdc6d713 | ||
|
|
ca35aad286 | ||
|
|
d6255f9f8f | ||
|
|
b58c9c55cf | ||
|
|
3c4bcc28f1 | ||
|
|
972c681650 | ||
|
|
2b4eb0151f | ||
|
|
7192d32e65 | ||
|
|
b65b48832b | ||
|
|
4cb334c912 | ||
|
|
6ebb299d6c |
@@ -0,0 +1,270 @@
|
|||||||
|
name: Module Package Release
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
tags:
|
||||||
|
- "v*"
|
||||||
|
workflow_dispatch:
|
||||||
|
inputs:
|
||||||
|
release_tag:
|
||||||
|
description: Existing protected version tag to publish
|
||||||
|
required: true
|
||||||
|
type: string
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
publish-packages:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
env:
|
||||||
|
GITEA_REPOSITORY: ${{ gitea.repository }}
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5
|
||||||
|
with:
|
||||||
|
fetch-depth: 0
|
||||||
|
- uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065
|
||||||
|
with:
|
||||||
|
python-version: "3.12"
|
||||||
|
- uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020
|
||||||
|
with:
|
||||||
|
node-version: "22"
|
||||||
|
- name: Select and validate protected release tag
|
||||||
|
shell: bash
|
||||||
|
env:
|
||||||
|
REQUESTED_TAG: ${{ inputs.release_tag }}
|
||||||
|
TRIGGER_TAG: ${{ gitea.ref_name }}
|
||||||
|
run: |
|
||||||
|
set -euo pipefail
|
||||||
|
tag="${REQUESTED_TAG:-$TRIGGER_TAG}"
|
||||||
|
case "$tag" in
|
||||||
|
v[0-9]*.[0-9]*.[0-9]*) ;;
|
||||||
|
*) echo "Release tag must start with a SemVer-shaped vX.Y.Z value" >&2; exit 1 ;;
|
||||||
|
esac
|
||||||
|
git fetch --force origin "refs/tags/$tag:refs/tags/$tag" refs/heads/main:refs/remotes/origin/main
|
||||||
|
tag_commit="$(git rev-list -n 1 "$tag")"
|
||||||
|
git merge-base --is-ancestor "$tag_commit" refs/remotes/origin/main || {
|
||||||
|
echo "Release tag is not contained in main" >&2
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
git checkout --detach "$tag"
|
||||||
|
printf 'RELEASE_TAG=%s\n' "$tag" >> "$GITEA_ENV"
|
||||||
|
printf 'SOURCE_DATE_EPOCH=%s\n' "$(git show -s --format=%ct HEAD)" >> "$GITEA_ENV"
|
||||||
|
- name: Validate package versions
|
||||||
|
run: |
|
||||||
|
python - <<'PY'
|
||||||
|
import json
|
||||||
|
from pathlib import Path
|
||||||
|
import os
|
||||||
|
import re
|
||||||
|
import tomllib
|
||||||
|
|
||||||
|
tag = os.environ["RELEASE_TAG"]
|
||||||
|
expected = tag.removeprefix("v")
|
||||||
|
project = tomllib.loads(Path("pyproject.toml").read_text(encoding="utf-8"))["project"]
|
||||||
|
if project.get("version") != expected:
|
||||||
|
raise SystemExit(f"pyproject version {project.get('version')!r} does not match {tag}")
|
||||||
|
if re.fullmatch(r"govoplan-[a-z0-9-]+", str(project.get("name", ""))) is None:
|
||||||
|
raise SystemExit("Python distribution name must use the govoplan-* namespace")
|
||||||
|
webui = Path("webui/package.json")
|
||||||
|
if webui.is_file():
|
||||||
|
package = json.loads(webui.read_text(encoding="utf-8"))
|
||||||
|
if package.get("version") != expected:
|
||||||
|
raise SystemExit(f"WebUI version {package.get('version')!r} does not match {tag}")
|
||||||
|
if re.fullmatch(r"@govoplan/[a-z0-9-]+-webui", str(package.get("name", ""))) is None:
|
||||||
|
raise SystemExit("WebUI package name must use the @govoplan/*-webui namespace")
|
||||||
|
release = Path("webui/package.release.json")
|
||||||
|
if release.is_file():
|
||||||
|
release_package = json.loads(release.read_text(encoding="utf-8"))
|
||||||
|
if (
|
||||||
|
release_package.get("name") != package.get("name")
|
||||||
|
or release_package.get("version") != expected
|
||||||
|
):
|
||||||
|
raise SystemExit("WebUI release package identity does not match package.json and the release tag")
|
||||||
|
PY
|
||||||
|
- name: Build immutable package artifacts
|
||||||
|
shell: bash
|
||||||
|
run: |
|
||||||
|
set -euo pipefail
|
||||||
|
python -m pip install --disable-pip-version-check build==1.5.0 twine==7.0.0
|
||||||
|
rm -rf dist .package-webui
|
||||||
|
python -m build --wheel --outdir dist
|
||||||
|
python -m twine check dist/*.whl
|
||||||
|
if [[ -f webui/package.json ]]; then
|
||||||
|
mkdir .package-webui
|
||||||
|
cp -a webui/. .package-webui/
|
||||||
|
rm -rf .package-webui/node_modules .package-webui/dist
|
||||||
|
if [[ -f .package-webui/package.release.json ]]; then
|
||||||
|
cp .package-webui/package.release.json .package-webui/package.json
|
||||||
|
fi
|
||||||
|
node <<'NODE'
|
||||||
|
const fs = require("node:fs");
|
||||||
|
const path = ".package-webui/package.json";
|
||||||
|
const packageJson = JSON.parse(fs.readFileSync(path, "utf8"));
|
||||||
|
const groups = ["dependencies", "optionalDependencies", "peerDependencies"];
|
||||||
|
for (const group of groups) {
|
||||||
|
for (const [name, specifier] of Object.entries(packageJson[group] || {})) {
|
||||||
|
if (!name.startsWith("@govoplan/")) continue;
|
||||||
|
if (typeof specifier !== "string") {
|
||||||
|
throw new Error(`${group}.${name} must use a string version`);
|
||||||
|
}
|
||||||
|
const packageSlug = name.slice("@govoplan/".length);
|
||||||
|
if (!packageSlug.endsWith("-webui")) {
|
||||||
|
throw new Error(`${group}.${name} is outside the WebUI package namespace`);
|
||||||
|
}
|
||||||
|
const repository = `govoplan-${packageSlug.slice(0, -"-webui".length)}`;
|
||||||
|
const escapedRepository = repository.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
||||||
|
const gitTag = specifier.match(
|
||||||
|
new RegExp(
|
||||||
|
`^git\\+(?:ssh://git@|https://)git\\.add-ideas\\.de/(?:GovOPlaN|add-ideas)/${escapedRepository}\\.git#v([0-9]+\\.[0-9]+\\.[0-9]+)$`,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
if (gitTag) {
|
||||||
|
packageJson[group][name] = gitTag[1];
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (specifier.startsWith("file:") || specifier.startsWith("git+")) {
|
||||||
|
throw new Error(
|
||||||
|
`${group}.${name} must resolve to an exact registry version for publication`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
delete packageJson.private;
|
||||||
|
fs.writeFileSync(path, `${JSON.stringify(packageJson, null, 2)}\n`);
|
||||||
|
NODE
|
||||||
|
npm pkg delete private --prefix .package-webui
|
||||||
|
(cd .package-webui && npm pack --ignore-scripts --pack-destination ../dist)
|
||||||
|
fi
|
||||||
|
python - <<'PY'
|
||||||
|
import hashlib
|
||||||
|
import json
|
||||||
|
from pathlib import Path
|
||||||
|
import os
|
||||||
|
import subprocess
|
||||||
|
|
||||||
|
artifacts = []
|
||||||
|
for path in sorted(Path("dist").iterdir()):
|
||||||
|
if path.suffix not in {".whl", ".tgz"}:
|
||||||
|
continue
|
||||||
|
digest = hashlib.sha256(path.read_bytes()).hexdigest()
|
||||||
|
artifacts.append({"filename": path.name, "sha256": digest, "size": path.stat().st_size})
|
||||||
|
payload = {
|
||||||
|
"schema_version": "1",
|
||||||
|
"repository": os.environ["GITEA_REPOSITORY"],
|
||||||
|
"tag": os.environ["RELEASE_TAG"],
|
||||||
|
"commit": subprocess.check_output(["git", "rev-parse", "HEAD"], text=True).strip(),
|
||||||
|
"artifacts": artifacts,
|
||||||
|
}
|
||||||
|
Path("dist/package-artifacts.json").write_text(
|
||||||
|
json.dumps(payload, indent=2, sort_keys=True) + "\n",
|
||||||
|
encoding="utf-8",
|
||||||
|
)
|
||||||
|
PY
|
||||||
|
- name: Retain package hash evidence
|
||||||
|
uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32
|
||||||
|
with:
|
||||||
|
name: module-packages-${{ gitea.ref_name }}
|
||||||
|
path: dist/package-artifacts.json
|
||||||
|
- name: Check immutable registry state
|
||||||
|
shell: bash
|
||||||
|
env:
|
||||||
|
PACKAGE_TOKEN: ${{ secrets.GOVOPLAN_PACKAGE_TOKEN }}
|
||||||
|
run: |
|
||||||
|
set -euo pipefail
|
||||||
|
test -n "$PACKAGE_TOKEN"
|
||||||
|
python - <<'PY'
|
||||||
|
import hashlib
|
||||||
|
import json
|
||||||
|
import os
|
||||||
|
from pathlib import Path
|
||||||
|
import tomllib
|
||||||
|
from urllib.error import HTTPError
|
||||||
|
from urllib.parse import quote
|
||||||
|
from urllib.request import Request, urlopen
|
||||||
|
|
||||||
|
api_root = "https://git.add-ideas.de/api/v1/packages/GovOPlaN"
|
||||||
|
token = os.environ["PACKAGE_TOKEN"]
|
||||||
|
|
||||||
|
def should_publish(kind, name, version, path):
|
||||||
|
package_url = "/".join(
|
||||||
|
(api_root, kind, quote(name, safe=""), quote(version, safe=""), "files")
|
||||||
|
)
|
||||||
|
request = Request(
|
||||||
|
package_url,
|
||||||
|
headers={"Accept": "application/json", "Authorization": f"token {token}"},
|
||||||
|
)
|
||||||
|
try:
|
||||||
|
with urlopen(request, timeout=30) as response:
|
||||||
|
files = json.load(response)
|
||||||
|
except HTTPError as exc:
|
||||||
|
if exc.code == 404:
|
||||||
|
print(f"{kind} package {name}=={version} is not published yet")
|
||||||
|
return True
|
||||||
|
raise
|
||||||
|
if not isinstance(files, list) or len(files) != 1:
|
||||||
|
raise SystemExit(
|
||||||
|
f"immutable {kind} package {name}=={version} has an unexpected file set"
|
||||||
|
)
|
||||||
|
expected_sha256 = hashlib.sha256(path.read_bytes()).hexdigest()
|
||||||
|
if files[0].get("sha256") != expected_sha256:
|
||||||
|
raise SystemExit(
|
||||||
|
f"immutable {kind} package {name}=={version} already exists with a different SHA-256"
|
||||||
|
)
|
||||||
|
print(f"verified existing {kind} package {name}=={version} ({expected_sha256})")
|
||||||
|
return False
|
||||||
|
|
||||||
|
project = tomllib.loads(Path("pyproject.toml").read_text(encoding="utf-8"))["project"]
|
||||||
|
wheels = tuple(Path("dist").glob("*.whl"))
|
||||||
|
if len(wheels) != 1:
|
||||||
|
raise SystemExit("release build must contain exactly one wheel")
|
||||||
|
publish_pypi = should_publish(
|
||||||
|
"pypi", str(project["name"]), str(project["version"]), wheels[0]
|
||||||
|
)
|
||||||
|
|
||||||
|
tarballs = tuple(Path("dist").glob("*.tgz"))
|
||||||
|
if len(tarballs) > 1:
|
||||||
|
raise SystemExit("release build must contain at most one npm package")
|
||||||
|
publish_npm = False
|
||||||
|
if tarballs:
|
||||||
|
webui = json.loads(
|
||||||
|
Path(".package-webui/package.json").read_text(encoding="utf-8")
|
||||||
|
)
|
||||||
|
publish_npm = should_publish(
|
||||||
|
"npm", str(webui["name"]), str(webui["version"]), tarballs[0]
|
||||||
|
)
|
||||||
|
|
||||||
|
with Path(os.environ["GITEA_ENV"]).open("a", encoding="utf-8") as env_file:
|
||||||
|
env_file.write(f"PUBLISH_PYPI={int(publish_pypi)}\n")
|
||||||
|
env_file.write(f"PUBLISH_NPM={int(publish_npm)}\n")
|
||||||
|
PY
|
||||||
|
- name: Publish wheel and WebUI package
|
||||||
|
shell: bash
|
||||||
|
env:
|
||||||
|
PACKAGE_USERNAME: ${{ secrets.GOVOPLAN_PACKAGE_USERNAME }}
|
||||||
|
PACKAGE_TOKEN: ${{ secrets.GOVOPLAN_PACKAGE_TOKEN }}
|
||||||
|
run: |
|
||||||
|
set -euo pipefail
|
||||||
|
test -n "$PACKAGE_USERNAME"
|
||||||
|
test -n "$PACKAGE_TOKEN"
|
||||||
|
if [[ "$PUBLISH_PYPI" == 1 ]]; then
|
||||||
|
TWINE_USERNAME="$PACKAGE_USERNAME" TWINE_PASSWORD="$PACKAGE_TOKEN" \
|
||||||
|
python -m twine upload --non-interactive \
|
||||||
|
--repository-url https://git.add-ideas.de/api/packages/GovOPlaN/pypi \
|
||||||
|
dist/*.whl
|
||||||
|
else
|
||||||
|
echo "Exact wheel is already present; skipping immutable retry."
|
||||||
|
fi
|
||||||
|
shopt -s nullglob
|
||||||
|
webui_packages=(dist/*.tgz)
|
||||||
|
if (( ${#webui_packages[@]} )) && [[ "$PUBLISH_NPM" == 1 ]]; then
|
||||||
|
npmrc="$(mktemp)"
|
||||||
|
trap 'rm -f "$npmrc"' EXIT
|
||||||
|
chmod 600 "$npmrc"
|
||||||
|
printf '%s\n' \
|
||||||
|
'@govoplan:registry=https://git.add-ideas.de/api/packages/GovOPlaN/npm/' \
|
||||||
|
"//git.add-ideas.de/api/packages/GovOPlaN/npm/:_authToken=$PACKAGE_TOKEN" \
|
||||||
|
> "$npmrc"
|
||||||
|
NPM_CONFIG_USERCONFIG="$npmrc" npm publish "./${webui_packages[0]}" \
|
||||||
|
--ignore-scripts --access public \
|
||||||
|
--registry https://git.add-ideas.de/api/packages/GovOPlaN/npm/
|
||||||
|
elif (( ${#webui_packages[@]} )); then
|
||||||
|
echo "Exact WebUI package is already present; skipping immutable retry."
|
||||||
|
fi
|
||||||
@@ -149,6 +149,8 @@ webui/.module-test-build/
|
|||||||
webui/.policy-test-build/
|
webui/.policy-test-build/
|
||||||
webui/.template-preview-test-build/
|
webui/.template-preview-test-build/
|
||||||
webui/.import-test-build/
|
webui/.import-test-build/
|
||||||
|
webui/dist-conformance/
|
||||||
|
webui/test-results/
|
||||||
|
|
||||||
# Security audit reports
|
# Security audit reports
|
||||||
audit-reports/
|
audit-reports/
|
||||||
|
|||||||
@@ -45,6 +45,8 @@ tools/checks/check-focused.sh
|
|||||||
- Prefer `rg`, `sed`, and targeted tests over broad recursive scans or full builds.
|
- Prefer `rg`, `sed`, and targeted tests over broad recursive scans or full builds.
|
||||||
- Avoid DataGrid changes unless explicitly requested; it is intentionally brittle and has known deferred work.
|
- Avoid DataGrid changes unless explicitly requested; it is intentionally brittle and has known deferred work.
|
||||||
- Do not add module-to-module imports for optional integrations. Use core registry/capability/module metadata paths.
|
- Do not add module-to-module imports for optional integrations. Use core registry/capability/module metadata paths.
|
||||||
|
- Treat documentation as part of every behavior change. Update the owning module's manifest-driven `DocumentationTopic` contributions for each affected user and administrator workflow, setting, permission, limitation, and operational consequence. Feature modules own this content; `govoplan-docs` projects it and must not import feature internals.
|
||||||
|
- Keep a static user and administrator documentation baseline in every module manifest, even when richer configured-state topics come from `documentation_providers`. Run `/mnt/DATA/git/govoplan/tools/checks/check-manifest-shapes.py` after changing a manifest or module behavior.
|
||||||
- Treat Gitea issues as the canonical backlog and state log. Treat Gitea wiki pages as durable project context mirrored from repository and product docs. Use `docs/GITEA_ISSUES.md` for labels, templates, TODO import, wiki sync, and Codex issue updates.
|
- Treat Gitea issues as the canonical backlog and state log. Treat Gitea wiki pages as durable project context mirrored from repository and product docs. Use `docs/GITEA_ISSUES.md` for labels, templates, TODO import, wiki sync, and Codex issue updates.
|
||||||
- Do not keep generated WebUI test folders in git status; they should be ignored and removable.
|
- Do not keep generated WebUI test folders in git status; they should be ignored and removable.
|
||||||
- Do not start persistent dev servers unless the user asks.
|
- Do not start persistent dev servers unless the user asks.
|
||||||
|
|||||||
@@ -117,7 +117,7 @@ CI runs the `ci` profile in report-only mode and uploads `audit-reports/` as an
|
|||||||
artifact. Once the baseline is clean, set `SECURITY_AUDIT_FAIL_ON_FINDINGS=1`
|
artifact. Once the baseline is clean, set `SECURITY_AUDIT_FAIL_ON_FINDINGS=1`
|
||||||
or pass `--strict` locally to turn findings into a failing gate.
|
or pass `--strict` locally to turn findings into a failing gate.
|
||||||
|
|
||||||
`govoplan_core.devserver` enables the development bootstrap before loading settings. In dev, startup migrations create or upgrade the schema and the bootstrap creates the default development login if needed. Explicitly setting `DEV_BOOTSTRAP_ENABLED=false` disables this convenience. Production deployments should use migrations and managed database provisioning instead.
|
`govoplan_core.devserver` enables the development bootstrap before loading settings. In dev, startup migrations create or upgrade the schema and the bootstrap creates the default development login if needed. Explicitly setting `DEV_BOOTSTRAP_ENABLED=false` disables this convenience. Production deployments use the separate, expiring single-use flow exposed by `python -m govoplan_core.commands.first_admin`; it cannot enable or consume development bootstrap credentials.
|
||||||
|
|
||||||
To verify the effective runtime paths and bootstrap behavior without starting uvicorn, run the smoke mode:
|
To verify the effective runtime paths and bootstrap behavior without starting uvicorn, run the smoke mode:
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,23 @@
|
|||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
from importlib.util import module_from_spec, spec_from_file_location
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
|
||||||
|
_path = (
|
||||||
|
Path(__file__).resolve().parents[1]
|
||||||
|
/ "versions"
|
||||||
|
/ "a36d8e4f9b12_german_reference_locale.py"
|
||||||
|
)
|
||||||
|
_spec = spec_from_file_location("govoplan_german_reference_locale_migration", _path)
|
||||||
|
if _spec is None or _spec.loader is None:
|
||||||
|
raise RuntimeError(f"Unable to load migration implementation from {_path}")
|
||||||
|
_module = module_from_spec(_spec)
|
||||||
|
_spec.loader.exec_module(_module)
|
||||||
|
|
||||||
|
revision = _module.revision
|
||||||
|
down_revision = _module.down_revision
|
||||||
|
branch_labels = _module.branch_labels
|
||||||
|
depends_on = _module.depends_on
|
||||||
|
upgrade = _module.upgrade
|
||||||
|
downgrade = _module.downgrade
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
from importlib.util import module_from_spec, spec_from_file_location
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
|
||||||
|
_path = (
|
||||||
|
Path(__file__).resolve().parents[1]
|
||||||
|
/ "versions"
|
||||||
|
/ "b47e6f809a13_data_subject_requests.py"
|
||||||
|
)
|
||||||
|
_spec = spec_from_file_location("govoplan_data_subject_requests_migration", _path)
|
||||||
|
if _spec is None or _spec.loader is None:
|
||||||
|
raise RuntimeError(f"Unable to load migration implementation from {_path}")
|
||||||
|
_module = module_from_spec(_spec)
|
||||||
|
_spec.loader.exec_module(_module)
|
||||||
|
|
||||||
|
revision = _module.revision
|
||||||
|
down_revision = _module.down_revision
|
||||||
|
branch_labels = _module.branch_labels
|
||||||
|
depends_on = _module.depends_on
|
||||||
|
upgrade = _module.upgrade
|
||||||
|
downgrade = _module.downgrade
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
"""development-track wrapper for runtime coordination and recovery."""
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
from importlib.util import module_from_spec, spec_from_file_location
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
|
||||||
|
_path = (
|
||||||
|
Path(__file__).resolve().parents[1]
|
||||||
|
/ "versions"
|
||||||
|
/ "e14b8c2d6f90_runtime_coordination_recovery.py"
|
||||||
|
)
|
||||||
|
_spec = spec_from_file_location("govoplan_runtime_coordination_migration", _path)
|
||||||
|
if _spec is None or _spec.loader is None:
|
||||||
|
raise RuntimeError(f"Unable to load runtime coordination migration from {_path}")
|
||||||
|
_migration = module_from_spec(_spec)
|
||||||
|
_spec.loader.exec_module(_migration)
|
||||||
|
|
||||||
|
revision = _migration.revision
|
||||||
|
down_revision = _migration.down_revision
|
||||||
|
branch_labels = _migration.branch_labels
|
||||||
|
depends_on = _migration.depends_on
|
||||||
|
upgrade = _migration.upgrade
|
||||||
|
downgrade = _migration.downgrade
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
from importlib.util import module_from_spec, spec_from_file_location
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
|
||||||
|
_path = (
|
||||||
|
Path(__file__).resolve().parents[1]
|
||||||
|
/ "versions"
|
||||||
|
/ "f25c9d3e7a01_first_admin_enrollment.py"
|
||||||
|
)
|
||||||
|
_spec = spec_from_file_location("govoplan_first_admin_enrollment_migration", _path)
|
||||||
|
if _spec is None or _spec.loader is None:
|
||||||
|
raise RuntimeError(f"Unable to load migration implementation from {_path}")
|
||||||
|
_module = module_from_spec(_spec)
|
||||||
|
_spec.loader.exec_module(_module)
|
||||||
|
|
||||||
|
revision = _module.revision
|
||||||
|
down_revision = _module.down_revision
|
||||||
|
branch_labels = _module.branch_labels
|
||||||
|
depends_on = _module.depends_on
|
||||||
|
upgrade = _module.upgrade
|
||||||
|
downgrade = _module.downgrade
|
||||||
@@ -12,7 +12,10 @@ except ModuleNotFoundError as exc:
|
|||||||
raise
|
raise
|
||||||
from govoplan_core.admin import models as core_admin_models # noqa: F401 - populate core admin metadata
|
from govoplan_core.admin import models as core_admin_models # noqa: F401 - populate core admin metadata
|
||||||
from govoplan_core.core import change_sequence as core_change_sequence_models # noqa: F401 - populate core metadata
|
from govoplan_core.core import change_sequence as core_change_sequence_models # noqa: F401 - populate core metadata
|
||||||
|
from govoplan_core.core import first_admin as core_first_admin_models # noqa: F401 - populate core metadata
|
||||||
from govoplan_core.core import ownership as core_ownership_models # noqa: F401 - populate core metadata
|
from govoplan_core.core import ownership as core_ownership_models # noqa: F401 - populate core metadata
|
||||||
|
from govoplan_core.core import recovery as core_recovery_models # noqa: F401 - populate core metadata
|
||||||
|
from govoplan_core.core import runtime_coordination as core_runtime_models # noqa: F401 - populate core metadata
|
||||||
from govoplan_core.security import credential_envelopes as core_credential_models # noqa: F401 - populate core metadata
|
from govoplan_core.security import credential_envelopes as core_credential_models # noqa: F401 - populate core metadata
|
||||||
from govoplan_core.core.migrations import migration_metadata_plan
|
from govoplan_core.core.migrations import migration_metadata_plan
|
||||||
from govoplan_core.db.base import Base
|
from govoplan_core.db.base import Base
|
||||||
|
|||||||
@@ -0,0 +1,44 @@
|
|||||||
|
"""adopt German as the untouched system reference locale
|
||||||
|
|
||||||
|
Revision ID: a36d8e4f9b12
|
||||||
|
Revises: f25c9d3e7a01
|
||||||
|
Create Date: 2026-08-05 00:00:00.000000
|
||||||
|
"""
|
||||||
|
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
from alembic import op
|
||||||
|
import sqlalchemy as sa
|
||||||
|
|
||||||
|
|
||||||
|
revision = "a36d8e4f9b12"
|
||||||
|
down_revision = "f25c9d3e7a01"
|
||||||
|
branch_labels = None
|
||||||
|
depends_on = None
|
||||||
|
|
||||||
|
|
||||||
|
def upgrade() -> None:
|
||||||
|
bind = op.get_bind()
|
||||||
|
if "core_system_settings" not in set(sa.inspect(bind).get_table_names()):
|
||||||
|
return
|
||||||
|
|
||||||
|
settings = sa.table(
|
||||||
|
"core_system_settings",
|
||||||
|
sa.column("id", sa.String),
|
||||||
|
sa.column("default_locale", sa.String),
|
||||||
|
sa.column("created_at", sa.DateTime(timezone=True)),
|
||||||
|
sa.column("updated_at", sa.DateTime(timezone=True)),
|
||||||
|
)
|
||||||
|
bind.execute(
|
||||||
|
settings.update()
|
||||||
|
.where(settings.c.id == "global")
|
||||||
|
.where(settings.c.default_locale == "en")
|
||||||
|
.where(settings.c.created_at == settings.c.updated_at)
|
||||||
|
.values(default_locale="de", updated_at=sa.func.now())
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def downgrade() -> None:
|
||||||
|
# Locale selection is user-visible state. A downgrade must not overwrite a
|
||||||
|
# German value that may have been selected explicitly after this migration.
|
||||||
|
pass
|
||||||
@@ -0,0 +1,77 @@
|
|||||||
|
"""add governed data-subject request workflow
|
||||||
|
|
||||||
|
Revision ID: b47e6f809a13
|
||||||
|
Revises: a36d8e4f9b12
|
||||||
|
Create Date: 2026-08-07 00:00:00.000000
|
||||||
|
"""
|
||||||
|
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
from alembic import op
|
||||||
|
import sqlalchemy as sa
|
||||||
|
|
||||||
|
|
||||||
|
revision = "b47e6f809a13"
|
||||||
|
down_revision = "a36d8e4f9b12"
|
||||||
|
branch_labels = None
|
||||||
|
depends_on = None
|
||||||
|
|
||||||
|
|
||||||
|
def upgrade() -> None:
|
||||||
|
inspector = sa.inspect(op.get_bind())
|
||||||
|
if "core_data_subject_requests" in inspector.get_table_names():
|
||||||
|
return
|
||||||
|
op.create_table(
|
||||||
|
"core_data_subject_requests",
|
||||||
|
sa.Column("id", sa.String(length=36), nullable=False),
|
||||||
|
sa.Column("tenant_id", sa.String(length=36), nullable=False),
|
||||||
|
sa.Column("reference", sa.String(length=120), nullable=False),
|
||||||
|
sa.Column("request_kind", sa.String(length=30), nullable=False),
|
||||||
|
sa.Column("status", sa.String(length=30), nullable=False),
|
||||||
|
sa.Column("subject", sa.JSON(), nullable=False),
|
||||||
|
sa.Column("purpose", sa.String(length=1000), nullable=False),
|
||||||
|
sa.Column("legal_basis", sa.String(length=1000), nullable=True),
|
||||||
|
sa.Column("due_at", sa.DateTime(timezone=True), nullable=True),
|
||||||
|
sa.Column("requested_by_account_id", sa.String(length=36), nullable=False),
|
||||||
|
sa.Column("search_result", sa.JSON(), nullable=False),
|
||||||
|
sa.Column("erasure_plan", sa.JSON(), nullable=False),
|
||||||
|
sa.Column("execution_result", sa.JSON(), nullable=False),
|
||||||
|
sa.Column("coverage", sa.JSON(), nullable=False),
|
||||||
|
sa.Column("evidence_sha256", sa.String(length=64), nullable=True),
|
||||||
|
sa.Column("resource_revision", sa.Integer(), nullable=False),
|
||||||
|
sa.Column("completed_at", sa.DateTime(timezone=True), nullable=True),
|
||||||
|
sa.Column("notes", sa.Text(), nullable=True),
|
||||||
|
sa.Column("created_at", sa.DateTime(timezone=True), nullable=False),
|
||||||
|
sa.Column("updated_at", sa.DateTime(timezone=True), nullable=False),
|
||||||
|
sa.PrimaryKeyConstraint("id", name=op.f("pk_core_data_subject_requests")),
|
||||||
|
)
|
||||||
|
op.create_index(
|
||||||
|
op.f("ix_core_data_subject_requests_tenant_id"),
|
||||||
|
"core_data_subject_requests",
|
||||||
|
["tenant_id"],
|
||||||
|
unique=False,
|
||||||
|
)
|
||||||
|
op.create_index(
|
||||||
|
op.f("ix_core_data_subject_requests_status"),
|
||||||
|
"core_data_subject_requests",
|
||||||
|
["status"],
|
||||||
|
unique=False,
|
||||||
|
)
|
||||||
|
op.create_index(
|
||||||
|
op.f("ix_core_data_subject_requests_due_at"),
|
||||||
|
"core_data_subject_requests",
|
||||||
|
["due_at"],
|
||||||
|
unique=False,
|
||||||
|
)
|
||||||
|
op.create_index(
|
||||||
|
"ix_core_data_subject_requests_tenant_status",
|
||||||
|
"core_data_subject_requests",
|
||||||
|
["tenant_id", "status"],
|
||||||
|
unique=False,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def downgrade() -> None:
|
||||||
|
inspector = sa.inspect(op.get_bind())
|
||||||
|
if "core_data_subject_requests" in inspector.get_table_names():
|
||||||
|
op.drop_table("core_data_subject_requests")
|
||||||
@@ -0,0 +1,232 @@
|
|||||||
|
"""add runtime coordination and recovery evidence
|
||||||
|
|
||||||
|
Revision ID: e14b8c2d6f90
|
||||||
|
Revises: d03a7b9c1e5f
|
||||||
|
Create Date: 2026-08-01 00:00:00.000000
|
||||||
|
"""
|
||||||
|
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
from alembic import op
|
||||||
|
import sqlalchemy as sa
|
||||||
|
|
||||||
|
|
||||||
|
revision = "e14b8c2d6f90"
|
||||||
|
down_revision = "d03a7b9c1e5f"
|
||||||
|
branch_labels = None
|
||||||
|
depends_on = None
|
||||||
|
|
||||||
|
|
||||||
|
def upgrade() -> None:
|
||||||
|
inspector = sa.inspect(op.get_bind())
|
||||||
|
tables = set(inspector.get_table_names())
|
||||||
|
if "core_runtime_nodes" not in tables:
|
||||||
|
op.create_table(
|
||||||
|
"core_runtime_nodes",
|
||||||
|
sa.Column("id", sa.String(length=36), nullable=False),
|
||||||
|
sa.Column("installation_id", sa.String(length=100), nullable=False),
|
||||||
|
sa.Column("node_id", sa.String(length=200), nullable=False),
|
||||||
|
sa.Column("incarnation", sa.String(length=36), nullable=False),
|
||||||
|
sa.Column("role", sa.String(length=40), nullable=False),
|
||||||
|
sa.Column("software_version", sa.String(length=80), nullable=False),
|
||||||
|
sa.Column("composition_hash", sa.String(length=64), nullable=False),
|
||||||
|
sa.Column("queues", sa.JSON(), nullable=False),
|
||||||
|
sa.Column("state", sa.String(length=30), nullable=False),
|
||||||
|
sa.Column("started_at", sa.DateTime(timezone=True), nullable=False),
|
||||||
|
sa.Column("last_heartbeat_at", sa.DateTime(timezone=True), nullable=False),
|
||||||
|
sa.Column("drain_requested_at", sa.DateTime(timezone=True), nullable=True),
|
||||||
|
sa.Column("drain_reason", sa.String(length=500), nullable=True),
|
||||||
|
sa.Column("stopped_at", sa.DateTime(timezone=True), nullable=True),
|
||||||
|
sa.Column("metadata", sa.JSON(), nullable=False),
|
||||||
|
sa.Column("created_at", sa.DateTime(timezone=True), nullable=False),
|
||||||
|
sa.Column("updated_at", sa.DateTime(timezone=True), nullable=False),
|
||||||
|
sa.PrimaryKeyConstraint("id", name=op.f("pk_core_runtime_nodes")),
|
||||||
|
sa.UniqueConstraint(
|
||||||
|
"installation_id",
|
||||||
|
"node_id",
|
||||||
|
name="uq_core_runtime_node_installation_node",
|
||||||
|
),
|
||||||
|
)
|
||||||
|
for column in (
|
||||||
|
"installation_id",
|
||||||
|
"node_id",
|
||||||
|
"incarnation",
|
||||||
|
"role",
|
||||||
|
"composition_hash",
|
||||||
|
"state",
|
||||||
|
):
|
||||||
|
op.create_index(
|
||||||
|
op.f(f"ix_core_runtime_nodes_{column}"),
|
||||||
|
"core_runtime_nodes",
|
||||||
|
[column],
|
||||||
|
unique=False,
|
||||||
|
)
|
||||||
|
op.create_index(
|
||||||
|
"ix_core_runtime_nodes_installation_state_heartbeat",
|
||||||
|
"core_runtime_nodes",
|
||||||
|
["installation_id", "state", "last_heartbeat_at"],
|
||||||
|
unique=False,
|
||||||
|
)
|
||||||
|
|
||||||
|
if "core_distributed_leases" not in tables:
|
||||||
|
op.create_table(
|
||||||
|
"core_distributed_leases",
|
||||||
|
sa.Column("id", sa.String(length=36), nullable=False),
|
||||||
|
sa.Column("installation_id", sa.String(length=100), nullable=False),
|
||||||
|
sa.Column("resource_key", sa.String(length=255), nullable=False),
|
||||||
|
sa.Column("holder_node_id", sa.String(length=200), nullable=True),
|
||||||
|
sa.Column("holder_incarnation", sa.String(length=36), nullable=True),
|
||||||
|
sa.Column("fencing_token", sa.BigInteger(), nullable=False),
|
||||||
|
sa.Column("acquired_at", sa.DateTime(timezone=True), nullable=True),
|
||||||
|
sa.Column("renewed_at", sa.DateTime(timezone=True), nullable=True),
|
||||||
|
sa.Column("expires_at", sa.DateTime(timezone=True), nullable=False),
|
||||||
|
sa.Column("metadata", sa.JSON(), nullable=False),
|
||||||
|
sa.Column("created_at", sa.DateTime(timezone=True), nullable=False),
|
||||||
|
sa.Column("updated_at", sa.DateTime(timezone=True), nullable=False),
|
||||||
|
sa.PrimaryKeyConstraint("id", name=op.f("pk_core_distributed_leases")),
|
||||||
|
sa.UniqueConstraint(
|
||||||
|
"installation_id",
|
||||||
|
"resource_key",
|
||||||
|
name="uq_core_distributed_lease_resource",
|
||||||
|
),
|
||||||
|
)
|
||||||
|
for column in (
|
||||||
|
"installation_id",
|
||||||
|
"resource_key",
|
||||||
|
"holder_node_id",
|
||||||
|
"holder_incarnation",
|
||||||
|
):
|
||||||
|
op.create_index(
|
||||||
|
op.f(f"ix_core_distributed_leases_{column}"),
|
||||||
|
"core_distributed_leases",
|
||||||
|
[column],
|
||||||
|
unique=False,
|
||||||
|
)
|
||||||
|
op.create_index(
|
||||||
|
"ix_core_distributed_leases_expiry",
|
||||||
|
"core_distributed_leases",
|
||||||
|
["installation_id", "expires_at"],
|
||||||
|
unique=False,
|
||||||
|
)
|
||||||
|
|
||||||
|
if "core_recovery_operations" not in tables:
|
||||||
|
op.create_table(
|
||||||
|
"core_recovery_operations",
|
||||||
|
sa.Column("id", sa.String(length=36), nullable=False),
|
||||||
|
sa.Column("installation_id", sa.String(length=100), nullable=False),
|
||||||
|
sa.Column("module_id", sa.String(length=100), nullable=False),
|
||||||
|
sa.Column("operation_type", sa.String(length=100), nullable=False),
|
||||||
|
sa.Column("resource_type", sa.String(length=100), nullable=True),
|
||||||
|
sa.Column("resource_id", sa.String(length=255), nullable=True),
|
||||||
|
sa.Column("mode", sa.String(length=40), nullable=False),
|
||||||
|
sa.Column("status", sa.String(length=40), nullable=False),
|
||||||
|
sa.Column("idempotency_key", sa.String(length=200), nullable=False),
|
||||||
|
sa.Column("request_sha256", sa.String(length=64), nullable=False),
|
||||||
|
sa.Column("plan", sa.JSON(), nullable=False),
|
||||||
|
sa.Column("backup_reference", sa.String(length=1000), nullable=True),
|
||||||
|
sa.Column("approval_reference", sa.String(length=1000), nullable=True),
|
||||||
|
sa.Column("lease_resource_key", sa.String(length=255), nullable=True),
|
||||||
|
sa.Column("holder_node_id", sa.String(length=200), nullable=True),
|
||||||
|
sa.Column("holder_incarnation", sa.String(length=36), nullable=True),
|
||||||
|
sa.Column("fencing_token", sa.BigInteger(), nullable=True),
|
||||||
|
sa.Column("checkpoint_count", sa.Integer(), nullable=False),
|
||||||
|
sa.Column("evidence_head_sha256", sa.String(length=64), nullable=True),
|
||||||
|
sa.Column("failure_summary", sa.Text(), nullable=True),
|
||||||
|
sa.Column("started_at", sa.DateTime(timezone=True), nullable=True),
|
||||||
|
sa.Column("completed_at", sa.DateTime(timezone=True), nullable=True),
|
||||||
|
sa.Column("recovery_started_at", sa.DateTime(timezone=True), nullable=True),
|
||||||
|
sa.Column("recovered_at", sa.DateTime(timezone=True), nullable=True),
|
||||||
|
sa.Column("revision", sa.Integer(), nullable=False),
|
||||||
|
sa.Column("metadata", sa.JSON(), nullable=False),
|
||||||
|
sa.Column("created_at", sa.DateTime(timezone=True), nullable=False),
|
||||||
|
sa.Column("updated_at", sa.DateTime(timezone=True), nullable=False),
|
||||||
|
sa.PrimaryKeyConstraint("id", name=op.f("pk_core_recovery_operations")),
|
||||||
|
sa.UniqueConstraint(
|
||||||
|
"installation_id",
|
||||||
|
"module_id",
|
||||||
|
"idempotency_key",
|
||||||
|
name="uq_core_recovery_operation_idempotency",
|
||||||
|
),
|
||||||
|
)
|
||||||
|
for column in (
|
||||||
|
"installation_id",
|
||||||
|
"module_id",
|
||||||
|
"operation_type",
|
||||||
|
"resource_type",
|
||||||
|
"resource_id",
|
||||||
|
"mode",
|
||||||
|
"status",
|
||||||
|
):
|
||||||
|
op.create_index(
|
||||||
|
op.f(f"ix_core_recovery_operations_{column}"),
|
||||||
|
"core_recovery_operations",
|
||||||
|
[column],
|
||||||
|
unique=False,
|
||||||
|
)
|
||||||
|
op.create_index(
|
||||||
|
"ix_core_recovery_operations_status_updated",
|
||||||
|
"core_recovery_operations",
|
||||||
|
["installation_id", "status", "updated_at"],
|
||||||
|
unique=False,
|
||||||
|
)
|
||||||
|
op.create_index(
|
||||||
|
"ix_core_recovery_operations_resource",
|
||||||
|
"core_recovery_operations",
|
||||||
|
["module_id", "resource_type", "resource_id"],
|
||||||
|
unique=False,
|
||||||
|
)
|
||||||
|
|
||||||
|
if "core_recovery_checkpoints" not in tables:
|
||||||
|
op.create_table(
|
||||||
|
"core_recovery_checkpoints",
|
||||||
|
sa.Column("id", sa.String(length=36), nullable=False),
|
||||||
|
sa.Column("operation_id", sa.String(length=36), nullable=False),
|
||||||
|
sa.Column("sequence", sa.Integer(), nullable=False),
|
||||||
|
sa.Column("status", sa.String(length=40), nullable=False),
|
||||||
|
sa.Column("kind", sa.String(length=80), nullable=False),
|
||||||
|
sa.Column("summary", sa.Text(), nullable=False),
|
||||||
|
sa.Column("evidence", sa.JSON(), nullable=False),
|
||||||
|
sa.Column("previous_sha256", sa.String(length=64), nullable=True),
|
||||||
|
sa.Column("checkpoint_sha256", sa.String(length=64), nullable=False),
|
||||||
|
sa.Column("created_at", sa.DateTime(timezone=True), nullable=False),
|
||||||
|
sa.ForeignKeyConstraint(
|
||||||
|
["operation_id"],
|
||||||
|
["core_recovery_operations.id"],
|
||||||
|
name=op.f(
|
||||||
|
"fk_core_recovery_checkpoints_operation_id_core_recovery_operations"
|
||||||
|
),
|
||||||
|
ondelete="CASCADE",
|
||||||
|
),
|
||||||
|
sa.PrimaryKeyConstraint("id", name=op.f("pk_core_recovery_checkpoints")),
|
||||||
|
sa.UniqueConstraint(
|
||||||
|
"operation_id",
|
||||||
|
"sequence",
|
||||||
|
name="uq_core_recovery_checkpoint_sequence",
|
||||||
|
),
|
||||||
|
)
|
||||||
|
for column in ("operation_id", "status", "checkpoint_sha256"):
|
||||||
|
op.create_index(
|
||||||
|
op.f(f"ix_core_recovery_checkpoints_{column}"),
|
||||||
|
"core_recovery_checkpoints",
|
||||||
|
[column],
|
||||||
|
unique=False,
|
||||||
|
)
|
||||||
|
op.create_index(
|
||||||
|
"ix_core_recovery_checkpoints_operation_created",
|
||||||
|
"core_recovery_checkpoints",
|
||||||
|
["operation_id", "created_at"],
|
||||||
|
unique=False,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def downgrade() -> None:
|
||||||
|
inspector = sa.inspect(op.get_bind())
|
||||||
|
tables = set(inspector.get_table_names())
|
||||||
|
for table in (
|
||||||
|
"core_recovery_checkpoints",
|
||||||
|
"core_recovery_operations",
|
||||||
|
"core_distributed_leases",
|
||||||
|
"core_runtime_nodes",
|
||||||
|
):
|
||||||
|
if table in tables:
|
||||||
|
op.drop_table(table)
|
||||||
@@ -0,0 +1,110 @@
|
|||||||
|
"""add controlled first-administrator enrollment evidence
|
||||||
|
|
||||||
|
Revision ID: f25c9d3e7a01
|
||||||
|
Revises: e14b8c2d6f90
|
||||||
|
Create Date: 2026-08-04 00:00:00.000000
|
||||||
|
"""
|
||||||
|
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
from alembic import op
|
||||||
|
import sqlalchemy as sa
|
||||||
|
|
||||||
|
|
||||||
|
revision = "f25c9d3e7a01"
|
||||||
|
down_revision = "e14b8c2d6f90"
|
||||||
|
branch_labels = None
|
||||||
|
depends_on = None
|
||||||
|
|
||||||
|
|
||||||
|
def upgrade() -> None:
|
||||||
|
inspector = sa.inspect(op.get_bind())
|
||||||
|
tables = set(inspector.get_table_names())
|
||||||
|
if "core_first_admin_enrollments" not in tables:
|
||||||
|
op.create_table(
|
||||||
|
"core_first_admin_enrollments",
|
||||||
|
sa.Column("installation_id", sa.String(length=100), nullable=False),
|
||||||
|
sa.Column("state", sa.String(length=24), nullable=False),
|
||||||
|
sa.Column("generation", sa.Integer(), nullable=False),
|
||||||
|
sa.Column("token_sha256", sa.String(length=64), nullable=True),
|
||||||
|
sa.Column("token_fingerprint", sa.String(length=16), nullable=True),
|
||||||
|
sa.Column("issued_at", sa.DateTime(timezone=True), nullable=True),
|
||||||
|
sa.Column("expires_at", sa.DateTime(timezone=True), nullable=True),
|
||||||
|
sa.Column("consumed_at", sa.DateTime(timezone=True), nullable=True),
|
||||||
|
sa.Column("consumed_account_id", sa.String(length=36), nullable=True),
|
||||||
|
sa.Column("consumed_membership_id", sa.String(length=36), nullable=True),
|
||||||
|
sa.Column("consumed_tenant_id", sa.String(length=36), nullable=True),
|
||||||
|
sa.Column("consumed_email", sa.String(length=320), nullable=True),
|
||||||
|
sa.Column("consumed_display_name", sa.String(length=255), nullable=True),
|
||||||
|
sa.Column("consumed_request_sha256", sa.String(length=64), nullable=True),
|
||||||
|
sa.Column("issue_reason", sa.String(length=500), nullable=True),
|
||||||
|
sa.Column("event_count", sa.Integer(), nullable=False),
|
||||||
|
sa.Column("evidence_head_sha256", sa.String(length=64), nullable=True),
|
||||||
|
sa.Column("created_at", sa.DateTime(timezone=True), nullable=False),
|
||||||
|
sa.Column("updated_at", sa.DateTime(timezone=True), nullable=False),
|
||||||
|
sa.PrimaryKeyConstraint(
|
||||||
|
"installation_id",
|
||||||
|
name=op.f("pk_core_first_admin_enrollments"),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
op.create_index(
|
||||||
|
op.f("ix_core_first_admin_enrollments_state"),
|
||||||
|
"core_first_admin_enrollments",
|
||||||
|
["state"],
|
||||||
|
unique=False,
|
||||||
|
)
|
||||||
|
op.create_index(
|
||||||
|
op.f("ix_core_first_admin_enrollments_expires_at"),
|
||||||
|
"core_first_admin_enrollments",
|
||||||
|
["expires_at"],
|
||||||
|
unique=False,
|
||||||
|
)
|
||||||
|
|
||||||
|
inspector = sa.inspect(op.get_bind())
|
||||||
|
tables = set(inspector.get_table_names())
|
||||||
|
if "core_first_admin_enrollment_events" not in tables:
|
||||||
|
op.create_table(
|
||||||
|
"core_first_admin_enrollment_events",
|
||||||
|
sa.Column("id", sa.String(length=36), nullable=False),
|
||||||
|
sa.Column("installation_id", sa.String(length=100), nullable=False),
|
||||||
|
sa.Column("sequence", sa.Integer(), nullable=False),
|
||||||
|
sa.Column("event_type", sa.String(length=80), nullable=False),
|
||||||
|
sa.Column("generation", sa.Integer(), nullable=False),
|
||||||
|
sa.Column("evidence", sa.JSON(), nullable=False),
|
||||||
|
sa.Column("previous_sha256", sa.String(length=64), nullable=True),
|
||||||
|
sa.Column("event_sha256", sa.String(length=64), nullable=False),
|
||||||
|
sa.Column("created_at", sa.DateTime(timezone=True), nullable=False),
|
||||||
|
sa.ForeignKeyConstraint(
|
||||||
|
["installation_id"],
|
||||||
|
["core_first_admin_enrollments.installation_id"],
|
||||||
|
name=op.f(
|
||||||
|
"fk_core_first_admin_enrollment_events_installation_id_core_first_admin_enrollments"
|
||||||
|
),
|
||||||
|
ondelete="CASCADE",
|
||||||
|
),
|
||||||
|
sa.PrimaryKeyConstraint(
|
||||||
|
"id",
|
||||||
|
name=op.f("pk_core_first_admin_enrollment_events"),
|
||||||
|
),
|
||||||
|
sa.UniqueConstraint(
|
||||||
|
"installation_id",
|
||||||
|
"sequence",
|
||||||
|
name="uq_core_first_admin_enrollment_event_sequence",
|
||||||
|
),
|
||||||
|
)
|
||||||
|
for column in ("installation_id", "event_type", "event_sha256"):
|
||||||
|
op.create_index(
|
||||||
|
op.f(f"ix_core_first_admin_enrollment_events_{column}"),
|
||||||
|
"core_first_admin_enrollment_events",
|
||||||
|
[column],
|
||||||
|
unique=False,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def downgrade() -> None:
|
||||||
|
inspector = sa.inspect(op.get_bind())
|
||||||
|
tables = set(inspector.get_table_names())
|
||||||
|
if "core_first_admin_enrollment_events" in tables:
|
||||||
|
op.drop_table("core_first_admin_enrollment_events")
|
||||||
|
if "core_first_admin_enrollments" in tables:
|
||||||
|
op.drop_table("core_first_admin_enrollments")
|
||||||
@@ -47,6 +47,9 @@ Recommended fields:
|
|||||||
irreversible
|
irreversible
|
||||||
- expected effects
|
- expected effects
|
||||||
- idempotency key strategy
|
- idempotency key strategy
|
||||||
|
- recovery mode: atomic, compensating, snapshot restore, forward recovery, or
|
||||||
|
irreversible
|
||||||
|
- concrete verification steps which prove whether the effect occurred
|
||||||
- audit event names
|
- audit event names
|
||||||
- preview provider
|
- preview provider
|
||||||
|
|
||||||
@@ -89,16 +92,45 @@ The runner should execute an action plan as follows:
|
|||||||
4. Run permission and policy checks.
|
4. Run permission and policy checks.
|
||||||
5. Generate a consequence preview.
|
5. Generate a consequence preview.
|
||||||
6. Reserve or verify the idempotency key.
|
6. Reserve or verify the idempotency key.
|
||||||
7. Execute the owning module capability.
|
7. Create a durable recovery operation and acquire its execution fence.
|
||||||
8. Record observed effects.
|
8. Persist dispatch evidence before a non-atomic provider call.
|
||||||
9. Emit events and audit records.
|
9. Execute the owning module capability.
|
||||||
10. Mark the command complete, retryable, quarantined, or requiring manual
|
10. Verify the provider result and every announced effect using the action's
|
||||||
|
declared recovery checks.
|
||||||
|
11. Commit the local projection and verified recovery checkpoint together.
|
||||||
|
12. Emit events and audit records.
|
||||||
|
13. Mark the command complete, retryable, quarantined, or requiring manual
|
||||||
intervention.
|
intervention.
|
||||||
|
|
||||||
The runner must never advance workflow state past a required side effect unless
|
The runner must never advance workflow state past a required side effect unless
|
||||||
the action definition explicitly allows asynchronous completion and the pending
|
the action definition explicitly allows asynchronous completion and the pending
|
||||||
state is visible.
|
state is visible.
|
||||||
|
|
||||||
|
For external and asynchronous effects, providers must preserve the distinction
|
||||||
|
between:
|
||||||
|
|
||||||
|
1. requested intent;
|
||||||
|
2. approved intent;
|
||||||
|
3. dispatched command;
|
||||||
|
4. possibly executed but unconfirmed outcome;
|
||||||
|
5. confirmed observed effect;
|
||||||
|
6. reconciled, corrected, or compensated outcome.
|
||||||
|
|
||||||
|
An API timeout after dispatch is not a failed effect and must not be retried as
|
||||||
|
an ordinary process failure or a fresh command. The runner records an unknown
|
||||||
|
outcome, releases its execution authority, and blocks continuation until an
|
||||||
|
operator or provider reconciliation proves either that the effect occurred or
|
||||||
|
that it is absent.
|
||||||
|
|
||||||
|
`ActionDefinition.recovery_mode` and `recovery_verification` are part of the
|
||||||
|
provider contract. The default is conservative forward recovery with explicit
|
||||||
|
provider-result and effect verification. Atomic mode is valid only when the
|
||||||
|
provider effect and its local projection share the same database transaction.
|
||||||
|
The actor context should retain the real identity/account,
|
||||||
|
represented function or party, delegation or power, and mandate/jurisdiction
|
||||||
|
references when applicable. Domain modules remain responsible for deciding
|
||||||
|
which of those references are required for their action.
|
||||||
|
|
||||||
## Failure States
|
## Failure States
|
||||||
|
|
||||||
Automation should use explicit failure states:
|
Automation should use explicit failure states:
|
||||||
|
|||||||
@@ -49,6 +49,15 @@ The broad writable root reduces approval churn. The explicit project trust entri
|
|||||||
|
|
||||||
Each active repository has an `AGENTS.md` file. These files define ownership, module boundaries, and focused commands for Codex. Keep durable project conventions there instead of repeating them in every prompt.
|
Each active repository has an `AGENTS.md` file. These files define ownership, module boundaries, and focused commands for Codex. Keep durable project conventions there instead of repeating them in every prompt.
|
||||||
|
|
||||||
|
Documentation is part of the completion criteria for every behavior change. The
|
||||||
|
owning module must update its manifest-driven `DocumentationTopic` contributions
|
||||||
|
for affected user and administrator workflows, settings, permissions,
|
||||||
|
limitations, and operational consequences. Feature documentation remains in the
|
||||||
|
feature module; the optional `govoplan-docs` module projects those contributions
|
||||||
|
without importing feature internals. Every module manifest must retain a static
|
||||||
|
user and administrator baseline even when runtime providers add configured-state
|
||||||
|
details.
|
||||||
|
|
||||||
Use `~/.codex/config.toml` for personal defaults, auth/runtime settings, writable roots, and trust decisions. Avoid checking in absolute-path writable roots or model preferences unless they are intentionally team-wide.
|
Use `~/.codex/config.toml` for personal defaults, auth/runtime settings, writable roots, and trust decisions. Avoid checking in absolute-path writable roots or model preferences unless they are intentionally team-wide.
|
||||||
|
|
||||||
Use Gitea issues as the canonical backlog and state log. See `docs/GITEA_ISSUES.md` for label setup, TODO import, and Codex issue update commands. Durable docs should describe stable behavior; changing work state belongs on the issue.
|
Use Gitea issues as the canonical backlog and state log. See `docs/GITEA_ISSUES.md` for label setup, TODO import, and Codex issue update commands. Durable docs should describe stable behavior; changing work state belongs on the issue.
|
||||||
@@ -81,5 +90,6 @@ PATH=/mnt/DATA/git/govoplan-core/webui/node_modules/.bin:/home/zemion/.nvm/versi
|
|||||||
- Avoid broad recursive scans and full builds unless the change warrants them.
|
- Avoid broad recursive scans and full builds unless the change warrants them.
|
||||||
- Keep generated build/test folders ignored.
|
- Keep generated build/test folders ignored.
|
||||||
- Keep optional module behavior behind core registry/capability/module metadata boundaries.
|
- Keep optional module behavior behind core registry/capability/module metadata boundaries.
|
||||||
|
- Run `tools/checks/check-manifest-shapes.py` after module behavior or manifest changes so user/admin documentation coverage remains complete.
|
||||||
- Create or update Gitea issues for TODOs, follow-ups, blockers, and feature requests instead of keeping local backlog files.
|
- Create or update Gitea issues for TODOs, follow-ups, blockers, and feature requests instead of keeping local backlog files.
|
||||||
- Do not start persistent dev servers unless the user asks.
|
- Do not start persistent dev servers unless the user asks.
|
||||||
|
|||||||
@@ -31,6 +31,7 @@ such as Redis degradation and language fallback are not compatibility paths.
|
|||||||
| Legacy tenant aliases in API response schemas | Preserves active-tenant response fields used by `0.1.x` clients. | Tagged `0.1.x` API window. | Remove at `0.2` with response-schema migration notes. |
|
| Legacy tenant aliases in API response schemas | Preserves active-tenant response fields used by `0.1.x` clients. | Tagged `0.1.x` API window. | Remove at `0.2` with response-schema migration notes. |
|
||||||
| Optional fields in Poll response references | Accepts providers built against the earlier Poll contract. | Tagged `0.1.x` runtime contract window. | Remove or require a new interface version at `0.2`. |
|
| Optional fields in Poll response references | Accepts providers built against the earlier Poll contract. | Tagged `0.1.x` runtime contract window. | Remove or require a new interface version at `0.2`. |
|
||||||
| Legacy single-tenant summary providers | Allows modules without the batch provider introduced in `0.1.x`. | Tagged `0.1.x` module contract window. | Remove at `0.2` after manifests advertise the batch provider contract. |
|
| Legacy single-tenant summary providers | Allows modules without the batch provider introduced in `0.1.x`. | Tagged `0.1.x` module contract window. | Remove at `0.2` after manifests advertise the batch provider contract. |
|
||||||
|
| WebUI `react-router-dom` build alias | Resolves tagged `0.1.x` module source imports to Core's single `react-router` runtime so one composition never loads two router contexts. | Tagged `0.1.x` WebUI source window. | Remove at `0.2` after every supported module tag imports `react-router` directly. |
|
||||||
|
|
||||||
## Removed Paths
|
## Removed Paths
|
||||||
|
|
||||||
|
|||||||
@@ -48,6 +48,35 @@ interface = how configured parts connect
|
|||||||
data = what the operator must provide for this deployment
|
data = what the operator must provide for this deployment
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## Package Classes
|
||||||
|
|
||||||
|
The same signed package mechanism supports several explicitly named classes:
|
||||||
|
|
||||||
|
| Class | Purpose |
|
||||||
|
| --- | --- |
|
||||||
|
| `reference` | Prove a bounded journey, degraded states, recovery, and target-environment acceptance. |
|
||||||
|
| `product` | Provide a reusable operating capability such as governed communication, service-to-decision, procurement/contracts, or governed BI. |
|
||||||
|
| `sector` | Specialize terminology, forms, rules, process baselines, controls, reports, and integrations for an institutional sector without forking modules. |
|
||||||
|
| `deployment` | Declare a supported infrastructure topology, operational assumptions, health gates, and recovery evidence. |
|
||||||
|
| `integration` | Declare external systems, provider bindings, source-authority modes, maturity, required health, and reconciliation behavior. |
|
||||||
|
|
||||||
|
Package class is metadata and validation context, not additional authority. A
|
||||||
|
sector package does not become a module and cannot write another module's
|
||||||
|
tables. Packages may extend other packages only through versioned fragments and
|
||||||
|
must preserve provenance and parent constraints.
|
||||||
|
|
||||||
|
The contract enforces class-specific evidence. Reference packages require
|
||||||
|
target, recovery, security, operations, accessibility, privacy, and
|
||||||
|
documentation evidence. Deployment and integration packages require their
|
||||||
|
corresponding target/recovery/operations evidence, while integration packages
|
||||||
|
also name provider authority and minimum-maturity expectations. Preflight
|
||||||
|
blocks a missing, incompatible, or unhealthy provider. A derived package may
|
||||||
|
tighten parent module, capability, and provider requirements but cannot remove
|
||||||
|
or loosen them. Every non-documentation claim made by reference, deployment, or
|
||||||
|
integration packages carries a `sha256:<digest>` binding. Repository checks
|
||||||
|
recompute those hashes, while signed package verification protects the declared
|
||||||
|
manifest during transport.
|
||||||
|
|
||||||
## Package Model
|
## Package Model
|
||||||
|
|
||||||
A configuration package should be a signed, portable manifest plus module-owned
|
A configuration package should be a signed, portable manifest plus module-owned
|
||||||
@@ -68,6 +97,9 @@ Required package metadata:
|
|||||||
- preflight checks and post-import health checks
|
- preflight checks and post-import health checks
|
||||||
- migration or transformation rules for older package versions
|
- migration or transformation rules for older package versions
|
||||||
- provenance, export source metadata, and signature metadata
|
- provenance, export source metadata, and signature metadata
|
||||||
|
- package class and optional parent package/version constraints
|
||||||
|
- source-authority bindings and provider-operation expectations for every
|
||||||
|
external integration used by the package
|
||||||
|
|
||||||
Portable configuration schemas follow `COMPATIBILITY_POLICY.md`: providers
|
Portable configuration schemas follow `COMPATIBILITY_POLICY.md`: providers
|
||||||
write only their current schema version and read that version plus the previous
|
write only their current schema version and read that version plus the previous
|
||||||
@@ -125,9 +157,48 @@ The initial implementation includes provider-neutral orchestration helpers:
|
|||||||
- `apply_configuration_package(...)`
|
- `apply_configuration_package(...)`
|
||||||
- `export_configuration_package(...)`
|
- `export_configuration_package(...)`
|
||||||
|
|
||||||
|
Portable fragments may bind deployment-specific operator input without placing
|
||||||
|
that value in the signed reusable definition. A payload value of
|
||||||
|
`{"$data": "requirement_key"}` references a key declared in the manifest's
|
||||||
|
`data_requirements`. Preflight fails before invoking the owning provider when a
|
||||||
|
reference is malformed, undeclared, or unresolved. Once supplied, Core replaces
|
||||||
|
the reference in memory and passes only the resolved fragment to the provider.
|
||||||
|
This mechanism is for deployment bindings and wording, not plaintext secrets:
|
||||||
|
credential-envelope or environment references remain the normal portable
|
||||||
|
boundary.
|
||||||
|
|
||||||
The first concrete provider is `govoplan_access.backend.configuration_provider`.
|
The first concrete provider is `govoplan_access.backend.configuration_provider`.
|
||||||
It supports access-owned `roles`, `groups`, and `group_role_assignments`
|
It supports access-owned `roles`, `groups`, and `group_role_assignments`
|
||||||
fragments and applies them idempotently.
|
fragments and applies them idempotently. Mail and Files also register providers
|
||||||
|
for deployment configuration: Mail owns receipt-bound SMTP profiles and Files
|
||||||
|
validates the deployment-owned managed-storage binding.
|
||||||
|
|
||||||
|
### Deployment capability receipt
|
||||||
|
|
||||||
|
The installer mounts a bounded, non-secret infrastructure receipt at the path
|
||||||
|
named by `GOVOPLAN_DEPLOYMENT_CAPABILITIES_PATH`. Core validates that document
|
||||||
|
once for configuration-package context and exposes typed capability and
|
||||||
|
post-install-task records to providers. Invalid receipts fail closed. Endpoint
|
||||||
|
metadata is sanitized, and secret fields may cross this boundary only as
|
||||||
|
`env:VARIABLE_NAME` references.
|
||||||
|
|
||||||
|
Feature providers remain responsible for their own semantics:
|
||||||
|
|
||||||
|
- Mail can derive host and port from `mail.smtp`, collect missing non-secret
|
||||||
|
transport fields, and bind an existing credential-envelope id. It never
|
||||||
|
accepts or exports a username, password, token, or decrypted credential.
|
||||||
|
- Files compares `files.storage` with the effective runtime backend, endpoint,
|
||||||
|
trust marker, bucket, and presence of referenced environment secrets. Storage
|
||||||
|
remains deployment-owned, so the provider reports `skip` when they agree and
|
||||||
|
blocks drift instead of rewriting process environment or storage credentials.
|
||||||
|
- A system-scoped Mail profile requires system configuration authority. Tenant
|
||||||
|
scope is the conservative default.
|
||||||
|
- Existing Mail configuration is preserved unless a reviewed fragment
|
||||||
|
explicitly selects `on_conflict: update`. Reapplying an unchanged fragment is
|
||||||
|
a no-op.
|
||||||
|
|
||||||
|
Ops projects the same Core-validated receipt. It must not maintain a second
|
||||||
|
parser with different validation or secret-handling rules.
|
||||||
|
|
||||||
The admin wizard backend starts with these routes:
|
The admin wizard backend starts with these routes:
|
||||||
|
|
||||||
@@ -151,6 +222,14 @@ The admin wizard backend starts with these routes:
|
|||||||
10. Store import provenance, package version, supplied non-secret metadata, and
|
10. Store import provenance, package version, supplied non-secret metadata, and
|
||||||
audit events.
|
audit events.
|
||||||
|
|
||||||
|
Provider applies may commit independently. Core therefore stops at the first
|
||||||
|
apply or health blocker and reports an explicit rollback state. A blocked
|
||||||
|
preflight or a no-op needs no recovery; a successful multi-provider mutation
|
||||||
|
retains the reviewed pre-apply database snapshot as its generic rollback path;
|
||||||
|
a later-provider failure is reported as a partial apply that requires snapshot
|
||||||
|
recovery or an explicitly supported module-owned compensation. The generic
|
||||||
|
wizard never claims atomic cross-module undo.
|
||||||
|
|
||||||
The wizard should display everything necessary and nothing unnecessary. Generic
|
The wizard should display everything necessary and nothing unnecessary. Generic
|
||||||
sections should cover package trust, dependency plan, required data, conflicts,
|
sections should cover package trust, dependency plan, required data, conflicts,
|
||||||
review, and result. Module-specific fields should appear only when the selected
|
review, and result. Module-specific fields should appear only when the selected
|
||||||
@@ -201,6 +280,11 @@ Exported packages should record provenance: source GovOPlaN version, module
|
|||||||
versions, exporter identity, timestamp, selected scope, redactions, and
|
versions, exporter identity, timestamp, selected scope, redactions, and
|
||||||
validation status.
|
validation status.
|
||||||
|
|
||||||
|
The orchestrator emits this provenance independently of provider payloads and
|
||||||
|
lists secret requirement keys as redacted without serializing their supplied
|
||||||
|
values. Providers still own the deeper rule that credentials, tokens, and
|
||||||
|
decrypted envelope contents must never appear in exported fragments.
|
||||||
|
|
||||||
## Catalogs And Trust
|
## Catalogs And Trust
|
||||||
|
|
||||||
Configuration catalogs should follow the existing module package catalog model:
|
Configuration catalogs should follow the existing module package catalog model:
|
||||||
|
|||||||
@@ -0,0 +1,73 @@
|
|||||||
|
# Contextual Help Contract
|
||||||
|
|
||||||
|
GovOPlaN exposes context-sensitive help through `F1` and the titlebar help
|
||||||
|
control. The shell resolves a stable help identity from the focused control,
|
||||||
|
its containing surface, and the current route. The Docs module then projects
|
||||||
|
the best visible user or administrator topic for that identity.
|
||||||
|
|
||||||
|
## Resolution Order
|
||||||
|
|
||||||
|
The WebUI resolves help in this order:
|
||||||
|
|
||||||
|
1. an explicit `helpContextId` or `data-help-context-id` on the focused item
|
||||||
|
2. the focused shared control's `interfaceId`, `helpTopicId`, and label key
|
||||||
|
3. a containing dialog, card, administration section, or page surface
|
||||||
|
4. the current registered route, including dynamic module routes
|
||||||
|
5. a stable route-derived fallback when no explicit identity is available
|
||||||
|
|
||||||
|
Focused field and action contexts retain the page context as
|
||||||
|
`fallback_context`. This lets Docs show a field-specific topic when one exists
|
||||||
|
and otherwise open the owning page or module documentation instead of a generic
|
||||||
|
help page.
|
||||||
|
|
||||||
|
## Documentation Lookup
|
||||||
|
|
||||||
|
Static `DocumentationTopic` contributions announce exact contexts through
|
||||||
|
`metadata.help_contexts`. Core publishes that catalogue with the enabled module
|
||||||
|
manifest, allowing the shell to link directly to an exact topic when possible.
|
||||||
|
Docs still performs the authoritative audience, permission, configured-state,
|
||||||
|
and documentation-type filtering.
|
||||||
|
|
||||||
|
Core also maps explicit route, navigation, settings, and View surface IDs to
|
||||||
|
the module's static user or administrator documentation baseline. This makes a
|
||||||
|
page association complete by default and gives every derived field/action
|
||||||
|
context a useful fallback. Exact `metadata.help_contexts` remain the preferred
|
||||||
|
authoring mechanism for consequential or unfamiliar controls.
|
||||||
|
|
||||||
|
When there is no exact topic, Docs resolves the page fallback and then the first
|
||||||
|
visible topic owned by the module. If Docs is unavailable, the shell opens the
|
||||||
|
hosted documentation with the same context parameters.
|
||||||
|
|
||||||
|
## Authoring Controls
|
||||||
|
|
||||||
|
Core shared controls expose stable help metadata. Prefer these props rather
|
||||||
|
than adding custom `F1` listeners:
|
||||||
|
|
||||||
|
- `interfaceId` identifies a durable UI surface or action.
|
||||||
|
- `helpContextId` identifies a documentation context when it differs from the
|
||||||
|
interface identity.
|
||||||
|
- `helpModuleId` identifies the documentation-owning module when a shared
|
||||||
|
control is embedded in another module's page.
|
||||||
|
- `helpTopicId` links directly to a module-owned documentation topic.
|
||||||
|
- translated label keys provide deterministic field identities for ordinary
|
||||||
|
`FormField`, `ToggleSwitch`, search, date/time, email, button, dialog, and card
|
||||||
|
controls.
|
||||||
|
- `TableActionGroup` action definitions carry the same identities so focused
|
||||||
|
row actions can resolve consequence-specific help.
|
||||||
|
- `PageLayout` owns the page help scope and documentation identity for ordinary
|
||||||
|
headed pages. `WorkspaceLayout` owns the full-canvas workspace scope and its
|
||||||
|
labelled primary/content panes; pages inside it use `PageLayout` in
|
||||||
|
`workspace` mode and retain their own route-level help identity.
|
||||||
|
|
||||||
|
Module routes, public routes, settings sections, and administration sections
|
||||||
|
may also declare `helpContextId` and `helpTopicId`. Each module must keep a
|
||||||
|
static user/admin documentation baseline and should list its important route,
|
||||||
|
workflow, setting, permission, and limitation identities in
|
||||||
|
`metadata.help_contexts`.
|
||||||
|
|
||||||
|
## Boundary
|
||||||
|
|
||||||
|
Help identities describe presentation context; they are not authorization
|
||||||
|
claims. Opening help never bypasses route or documentation permissions. Docs
|
||||||
|
owns documentation projection, feature modules own their content, and Core owns
|
||||||
|
focus capture, context resolution, and fallback routing.
|
||||||
@@ -36,7 +36,8 @@ the column remains stopped until the pointer crosses the same boundary again.
|
|||||||
|
|
||||||
## Persistence
|
## Persistence
|
||||||
|
|
||||||
Only the pixel layout resulting from an explicit user resize is persisted.
|
Only the pixel layout resulting from an explicit user resize is persisted,
|
||||||
|
together with the container width at which the user selected it.
|
||||||
Persisted widths are keyed by a signature containing column IDs, declared
|
Persisted widths are keyed by a signature containing column IDs, declared
|
||||||
widths and bounds, resize affordances, sticky placement, initial fit, and resize
|
widths and bounds, resize affordances, sticky placement, initial fit, and resize
|
||||||
behavior. A changed signature discards the old override and recomputes the
|
behavior. A changed signature discards the old override and recomputes the
|
||||||
@@ -44,8 +45,13 @@ declared layout.
|
|||||||
|
|
||||||
Container reconciliation is suspended while a pointer drag is active. On
|
Container reconciliation is suspended while a pointer drag is active. On
|
||||||
release, the already-rendered pixel layout becomes the persisted preference.
|
release, the already-rendered pixel layout becomes the persisted preference.
|
||||||
Reconciliation may grow it to prevent underflow, but never shrinks intentional
|
Reconciliation at that same container width never shrinks intentional user
|
||||||
user overflow, so there is no drag-end snap.
|
overflow, so there is no drag-end snap. If the surrounding layout later
|
||||||
|
contracts, persisted tracks may shrink toward their hard minima. The layout
|
||||||
|
retains only the amount of horizontal overflow deliberately created by the
|
||||||
|
user; an exact-cover layout therefore remains exact-cover at narrower widths.
|
||||||
|
Legacy snapshots from the former hard-pixel persistence contract are discarded
|
||||||
|
once and recomputed from the declared column layout.
|
||||||
|
|
||||||
## Regression Matrix
|
## Regression Matrix
|
||||||
|
|
||||||
@@ -56,6 +62,7 @@ user overflow, so there is no drag-end snap.
|
|||||||
- hard-minimum horizontal overflow;
|
- hard-minimum horizontal overflow;
|
||||||
- fixed-only cover grids;
|
- fixed-only cover grids;
|
||||||
- persisted overrides under growth and viewport pressure;
|
- persisted overrides under growth and viewport pressure;
|
||||||
|
- responsive contraction of persisted layouts without losing deliberate overflow;
|
||||||
- stale layout signatures;
|
- stale layout signatures;
|
||||||
- first and middle-column right-side compensation;
|
- first and middle-column right-side compensation;
|
||||||
- last-resizable-column overflow, underflow stop, and reverse-pointer boundary;
|
- last-resizable-column overflow, underflow stop, and reverse-pointer boundary;
|
||||||
|
|||||||
@@ -0,0 +1,91 @@
|
|||||||
|
# Data-Subject Request Contract
|
||||||
|
|
||||||
|
This document defines the provider-neutral workflow for access and erasure
|
||||||
|
requests. It is an operational control and evidence mechanism. It does not
|
||||||
|
replace legal review, identity verification, retention policy, or the
|
||||||
|
institution's statutory response process.
|
||||||
|
|
||||||
|
## Ownership
|
||||||
|
|
||||||
|
Core owns the request aggregate, lifecycle API, optimistic concurrency,
|
||||||
|
provider discovery, export manifest, execution orchestration, and audit event
|
||||||
|
names. Modules that store subject-related data own their search, explanation,
|
||||||
|
retention, and mutation behavior through a `privacy.dsar.<module>` capability.
|
||||||
|
Core never scans module tables or guesses how a foreign resource may be
|
||||||
|
erased.
|
||||||
|
|
||||||
|
Access owns the first provider. It finds tenant memberships plus safe account,
|
||||||
|
identity, assignment, API-key, and session metadata. It does not export secret
|
||||||
|
hashes, session tokens, IP addresses, or browser fingerprints. Tenant-local
|
||||||
|
membership data can be anonymized and authentication material can be revoked.
|
||||||
|
Global accounts and identities require manual system-level review because they
|
||||||
|
may serve more than one tenant.
|
||||||
|
|
||||||
|
## Lifecycle
|
||||||
|
|
||||||
|
1. A privacy officer records a verified selector, purpose, legal basis, due
|
||||||
|
date, and internal reference.
|
||||||
|
2. Search invokes every available tenant capability independently. A provider
|
||||||
|
failure is isolated and recorded; it cannot turn an incomplete search into
|
||||||
|
a successful one.
|
||||||
|
3. The JSON export contains the request, records, provider runs, coverage,
|
||||||
|
retention reasons, execution evidence, and a SHA-256 manifest digest.
|
||||||
|
4. An erasure request produces stable provider-owned actions. Immutable
|
||||||
|
evidence generates an explicit non-executable `retain` decision.
|
||||||
|
5. Execution accepts only selected executable actions from the current plan.
|
||||||
|
It requires `If-Match`, the current resource revision, the dedicated erase
|
||||||
|
permission, and the exact `ERASE <request-id>` confirmation phrase.
|
||||||
|
6. Provider execution is idempotent. Completed or unchanged effects remain
|
||||||
|
durable in the request's execution evidence.
|
||||||
|
|
||||||
|
The API is rooted at
|
||||||
|
`/api/v1/admin/privacy/data-subject-requests`. Access exposes the independent
|
||||||
|
permissions `access:privacy:read`, `access:privacy:manage`,
|
||||||
|
`access:privacy:export`, and `access:privacy:erase`; the built-in privacy
|
||||||
|
officer role contains all four.
|
||||||
|
|
||||||
|
## Provider Rules
|
||||||
|
|
||||||
|
A provider must:
|
||||||
|
|
||||||
|
- enforce tenant ownership for every record and action;
|
||||||
|
- return stable, unique resource and action identities;
|
||||||
|
- avoid credentials, hashes, tokens, unnecessary telemetry, and unrelated
|
||||||
|
third-party data;
|
||||||
|
- distinguish mutable personal data from immutable institutional evidence;
|
||||||
|
- state a retention reason for immutable evidence;
|
||||||
|
- propose manual review instead of an automatic action when authority is
|
||||||
|
ambiguous or a resource spans tenants;
|
||||||
|
- return exactly one execution result per requested action;
|
||||||
|
- make execution idempotent and avoid committing the caller's transaction;
|
||||||
|
- keep all actual mutations inside the owning module.
|
||||||
|
|
||||||
|
Each active module without a DSAR provider is listed in coverage. This is a
|
||||||
|
deliberate fail-visible state, not proof that the module stores personal data.
|
||||||
|
An institution may call an export complete only after it has reviewed both the
|
||||||
|
provider runs and that coverage list.
|
||||||
|
|
||||||
|
## Retention And Evidence
|
||||||
|
|
||||||
|
Erasure and retention are separate decisions. Stable object IDs, authorization
|
||||||
|
history, function incumbency, formal decisions, delivery evidence, and audit
|
||||||
|
records may remain necessary for accountability. Providers expose those items
|
||||||
|
with a concrete reason and Core prevents them from being selected as executable
|
||||||
|
actions. Policy may further restrict an action, but it must never silently
|
||||||
|
loosen a provider's retention decision.
|
||||||
|
|
||||||
|
All lifecycle mutations and exports produce tenant audit events. The request
|
||||||
|
stores an evidence digest after every revision. This digest detects accidental
|
||||||
|
or unauthorized mutation of the aggregate; it is not a digital signature or a
|
||||||
|
substitute for signed recovery evidence.
|
||||||
|
|
||||||
|
## Current Limits
|
||||||
|
|
||||||
|
- Access is the first native provider. Other enabled modules appear in the
|
||||||
|
coverage list until they add a provider or an explicit no-subject-data
|
||||||
|
declaration is standardized.
|
||||||
|
- Verification of the requester's identity and statutory deadline escalation
|
||||||
|
remain institutional workflows outside this API.
|
||||||
|
- Global account or identity erasure is deliberately manual.
|
||||||
|
- Exports are JSON. A human-readable signed response package remains a later
|
||||||
|
Reporting/Templates integration.
|
||||||
@@ -7,6 +7,16 @@ files.
|
|||||||
|
|
||||||
## Runtime Configuration Contract
|
## Runtime Configuration Contract
|
||||||
|
|
||||||
|
Worker and queue observability is provider-neutral. Runtime modules register a
|
||||||
|
bounded `RuntimeWorkStatusProviderRegistration` with Core; the Ops module
|
||||||
|
projects its sanitized status without importing Celery, Redis, or module job
|
||||||
|
implementations. Providers must use explicit `null` values for unsupported
|
||||||
|
queue depth, active/reserved work, failure count, and heartbeat evidence. An
|
||||||
|
unavailable metric must never be interpreted as zero or as proof of health.
|
||||||
|
The standard Core adapter reports the configured Celery/Redis runtime and
|
||||||
|
combines its bounded inspection result with registered worker heartbeat and
|
||||||
|
stale-threshold evidence.
|
||||||
|
|
||||||
Self-hosted installability follows the staged approach documented in
|
Self-hosted installability follows the staged approach documented in
|
||||||
`SELF_HOSTED_INSTALLABILITY.md`: generate an explicit env template, validate it,
|
`SELF_HOSTED_INSTALLABILITY.md`: generate an explicit env template, validate it,
|
||||||
run production-like rehearsal with Compose-backed dependencies, then use the
|
run production-like rehearsal with Compose-backed dependencies, then use the
|
||||||
@@ -36,7 +46,7 @@ set +a
|
|||||||
| Setting | Required outside dev | Purpose |
|
| Setting | Required outside dev | Purpose |
|
||||||
| --- | --- | --- |
|
| --- | --- | --- |
|
||||||
| `APP_ENV` | yes | Runtime profile. Use `prod`, `staging`, or a deployment-specific value outside local development. |
|
| `APP_ENV` | yes | Runtime profile. Use `prod`, `staging`, or a deployment-specific value outside local development. |
|
||||||
| `MASTER_KEY_B64` | yes | Fernet key or base64 encoded 32-byte key used for encrypted module secrets. Rotate through an explicit operator plan. |
|
| `MASTER_KEY_B64` | yes | Fernet key or base64 encoded 32-byte deployment root used for encrypted module secrets and, when enabled, the Encryption module's local server-envelope provider. Rotate only through an explicit provider-aware migration plan. |
|
||||||
| `DATABASE_URL` | yes | SQLAlchemy database URL for core and installed modules. SQLite is supported for dev/small installs; PostgreSQL is the preferred production target. |
|
| `DATABASE_URL` | yes | SQLAlchemy database URL for core and installed modules. SQLite is supported for dev/small installs; PostgreSQL is the preferred production target. |
|
||||||
| `ENABLED_MODULES` | yes | Comma-separated startup module set. Keep `tenancy,access` enabled; keep `admin` enabled for operator UI. |
|
| `ENABLED_MODULES` | yes | Comma-separated startup module set. Keep `tenancy,access` enabled; keep `admin` enabled for operator UI. |
|
||||||
|
|
||||||
@@ -57,6 +67,8 @@ PY
|
|||||||
| `GOVOPLAN_MIGRATION_TRACK` | `release` | Use the release track for normal runtime and deployments. Use `dev` only for fresh/disposable databases that intentionally replay detailed development migrations. |
|
| `GOVOPLAN_MIGRATION_TRACK` | `release` | Use the release track for normal runtime and deployments. Use `dev` only for fresh/disposable databases that intentionally replay detailed development migrations. |
|
||||||
| `DEV_AUTO_MIGRATE_ENABLED` | `true` | Dev convenience only. Production should run migration commands explicitly during deployment. |
|
| `DEV_AUTO_MIGRATE_ENABLED` | `true` | Dev convenience only. Production should run migration commands explicitly during deployment. |
|
||||||
| `DEV_BOOTSTRAP_ENABLED` | `false` | Dev bootstrap only. `govoplan_core.devserver` and `govoplan/tools/launch/launch-dev.sh` default it to `true`; use controlled first-admin creation outside dev. |
|
| `DEV_BOOTSTRAP_ENABLED` | `false` | Dev bootstrap only. `govoplan_core.devserver` and `govoplan/tools/launch/launch-dev.sh` default it to `true`; use controlled first-admin creation outside dev. |
|
||||||
|
| `FIRST_ADMIN_ENROLLMENT_TTL_SECONDS` | `1800` | Lifetime of a locally issued production enrollment credential. Allowed range: 60 seconds to 24 hours. |
|
||||||
|
| `FIRST_ADMIN_ENROLLMENT_FILE` | `/run/govoplan/first-admin-enrollment.json` | Local operator artifact. The command creates it with mode `0600` and never prints the secret. |
|
||||||
|
|
||||||
Operator rule: take a database backup before applying migrations or destructive
|
Operator rule: take a database backup before applying migrations or destructive
|
||||||
module retirement. For non-SQLite databases, configure deployment-specific
|
module retirement. For non-SQLite databases, configure deployment-specific
|
||||||
@@ -157,7 +169,8 @@ release evidence.
|
|||||||
| --- | --- | --- |
|
| --- | --- | --- |
|
||||||
| `REDIS_URL` | `redis://redis:6379/0` | Celery broker/result backend when async workers are enabled. |
|
| `REDIS_URL` | `redis://redis:6379/0` | Celery broker/result backend when async workers are enabled. |
|
||||||
| `CELERY_ENABLED` | `false` | Local/dev can send synchronously. Production campaign delivery should run workers and set this to `true`. |
|
| `CELERY_ENABLED` | `false` | Local/dev can send synchronously. Production campaign delivery should run workers and set this to `true`. |
|
||||||
| `CELERY_QUEUES` | `send_email,append_sent,notifications,calendar,dataflow,workflow,events,default` | Queue list expected by worker/process manager definitions. The `events` queue drains transactional platform events; `dataflow` drains trigger deliveries and schedules; `workflow` reconciles Workflow Engine instances and module standards. |
|
| `CELERY_QUEUES` | `send_email,append_sent,notifications,mail,calendar,dataflow,workflow,postbox,events,idm,default` | Queue list expected by worker/process manager definitions. Keep this aligned with every enabled module task route; Ops reports missing worker queue consumers. |
|
||||||
|
| `CELERY_VISIBILITY_TIMEOUT_SECONDS` | `3600` | Maximum time before Redis may redeliver work left unacknowledged by a lost worker. Set this above the longest supported task duration; changing it requires a worker-loss acceptance drill. |
|
||||||
| `PLATFORM_EVENT_OUTBOX_MAX_ATTEMPTS` | `8` | Failed durable consumer deliveries are quarantined after this many attempts. |
|
| `PLATFORM_EVENT_OUTBOX_MAX_ATTEMPTS` | `8` | Failed durable consumer deliveries are quarantined after this many attempts. |
|
||||||
| `PLATFORM_EVENT_OUTBOX_TERMINAL_RETENTION_DAYS` | `90` | Successful event envelopes older than this are removed by the daily retention task. Quarantined evidence is retained. |
|
| `PLATFORM_EVENT_OUTBOX_TERMINAL_RETENTION_DAYS` | `90` | Successful event envelopes older than this are removed by the daily retention task. Quarantined evidence is retained. |
|
||||||
|
|
||||||
@@ -165,7 +178,7 @@ Worker command:
|
|||||||
|
|
||||||
```bash
|
```bash
|
||||||
python -m celery -A govoplan_core.celery_app:celery worker \
|
python -m celery -A govoplan_core.celery_app:celery worker \
|
||||||
--queues send_email,append_sent,notifications,calendar,dataflow,events,default \
|
--queues send_email,append_sent,notifications,mail,calendar,dataflow,workflow,postbox,events,idm,default \
|
||||||
--loglevel INFO
|
--loglevel INFO
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -177,6 +190,13 @@ crashes, and expired worker leases:
|
|||||||
python -m celery -A govoplan_core.celery_app:celery beat --loglevel INFO
|
python -m celery -A govoplan_core.celery_app:celery beat --loglevel INFO
|
||||||
```
|
```
|
||||||
|
|
||||||
|
Before promoting a worker composition, run the repository worker-runtime drill
|
||||||
|
against the same Redis and Core build. It uses the bounded
|
||||||
|
`govoplan.worker.acceptance` task and records publish/consume, retry, warm
|
||||||
|
SIGTERM, and worker-loss redelivery evidence without accessing tenant data.
|
||||||
|
Production evidence must use the deployed queue configuration and a visibility
|
||||||
|
timeout that is longer than every supported business task.
|
||||||
|
|
||||||
### Storage
|
### Storage
|
||||||
|
|
||||||
| Setting | Default | Notes |
|
| Setting | Default | Notes |
|
||||||
@@ -268,12 +288,15 @@ through the same trusted address range.
|
|||||||
| --- | --- |
|
| --- | --- |
|
||||||
| `GOVOPLAN_MODULE_PACKAGE_CATALOG_URL` or `GOVOPLAN_MODULE_PACKAGE_CATALOG` | Module package catalog source. |
|
| `GOVOPLAN_MODULE_PACKAGE_CATALOG_URL` or `GOVOPLAN_MODULE_PACKAGE_CATALOG` | Module package catalog source. |
|
||||||
| `GOVOPLAN_MODULE_PACKAGE_CATALOG_TRUSTED_KEYS_FILE` | Preferred production keyring path. |
|
| `GOVOPLAN_MODULE_PACKAGE_CATALOG_TRUSTED_KEYS_FILE` | Preferred production keyring path. |
|
||||||
| `GOVOPLAN_MODULE_PACKAGE_CATALOG_APPROVED_CHANNEL` | Approved catalog channel, for example `stable`. |
|
| `GOVOPLAN_MODULE_PACKAGE_CATALOG_APPROVED_CHANNELS` | Comma-separated approved catalog channels, for example `stable`. The legacy singular name remains readable during migration. |
|
||||||
| `GOVOPLAN_LICENSE_TRUSTED_KEYS_FILE` | Trusted license issuer keyring path. |
|
| `GOVOPLAN_LICENSE_TRUSTED_KEYS_FILE` | Trusted license issuer keyring path. |
|
||||||
| `GOVOPLAN_LICENSE_ENFORCEMENT` | Enables license enforcement when set to `true`. |
|
| `GOVOPLAN_LICENSE_ENFORCEMENT` | Enables license enforcement when set to `true`. |
|
||||||
|
|
||||||
Trust roots are deployment-managed and should not be editable through the
|
Trust roots are deployment-managed and should not be editable through the
|
||||||
running WebUI.
|
running WebUI. When no catalog override is configured, the Admin package
|
||||||
|
directory uses GovOPlaN's public stable catalog and the trust anchor bundled
|
||||||
|
with the installed Core release. Production operators may still pin a newer or
|
||||||
|
institution-specific catalog/keyring explicitly with the settings above.
|
||||||
|
|
||||||
### Mail Test Credentials
|
### Mail Test Credentials
|
||||||
|
|
||||||
@@ -292,8 +315,34 @@ configuration, not the core runtime contract. Store them in a local ignored
|
|||||||
3. Build the WebUI from `webui/package.release.json` or deploy a prebuilt
|
3. Build the WebUI from `webui/package.release.json` or deploy a prebuilt
|
||||||
artifact from the same release tag.
|
artifact from the same release tag.
|
||||||
4. Run database migrations with the target `DATABASE_URL`.
|
4. Run database migrations with the target `DATABASE_URL`.
|
||||||
5. Create the first tenant and system owner through the controlled bootstrap or
|
5. Create the first tenant and system owner through the controlled bootstrap:
|
||||||
one-time admin command for the deployment.
|
|
||||||
|
```bash
|
||||||
|
python -m govoplan_core.commands.first_admin status
|
||||||
|
python -m govoplan_core.commands.first_admin issue \
|
||||||
|
--reason "initial production installation"
|
||||||
|
```
|
||||||
|
|
||||||
|
The issue command fails when an active system administrator already exists,
|
||||||
|
writes the random credential only to `FIRST_ADMIN_ENROLLMENT_FILE`, and does
|
||||||
|
not print it. Check `GET /api/v1/bootstrap/status`, then submit the account
|
||||||
|
and initial tenant fields to `POST /api/v1/bootstrap/first-admin` with the
|
||||||
|
secret in `X-GovOPlaN-Enrollment-Token`. The operation creates the protected
|
||||||
|
system owner and initial tenant-owner membership in one transaction and
|
||||||
|
retires the credential. A repeated identical request returns the same result
|
||||||
|
without creating another owner.
|
||||||
|
|
||||||
|
If the artifact is lost or expires before use, a local operator may rotate
|
||||||
|
it only while no durable system administrator exists:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
python -m govoplan_core.commands.first_admin recover \
|
||||||
|
--reason "expired installation handoff"
|
||||||
|
```
|
||||||
|
|
||||||
|
Issue and recovery write hash-chained Core evidence and an audit event. They
|
||||||
|
never enable or reuse `DEV_BOOTSTRAP_ENABLED`, `DEV_BOOTSTRAP_PASSWORD`, or
|
||||||
|
`DEV_BOOTSTRAP_API_KEY`.
|
||||||
6. Start the API service with `govoplan_core.server.app:app`.
|
6. Start the API service with `govoplan_core.server.app:app`.
|
||||||
7. Start workers when `CELERY_ENABLED=true`.
|
7. Start workers when `CELERY_ENABLED=true`.
|
||||||
8. Start the WebUI/reverse proxy and verify CORS/cookie settings.
|
8. Start the WebUI/reverse proxy and verify CORS/cookie settings.
|
||||||
@@ -343,7 +392,7 @@ the checked in `.env.example`. It runs:
|
|||||||
- explicit `ENABLED_MODULES`
|
- explicit `ENABLED_MODULES`
|
||||||
- explicit migrations and `--with-dev-data` bootstrap
|
- explicit migrations and `--with-dev-data` bootstrap
|
||||||
- API via the module-aware devserver
|
- API via the module-aware devserver
|
||||||
- a Celery worker for `send_email,append_sent,notifications,calendar,default`
|
- a Celery worker for `send_email,append_sent,notifications,mail,calendar,dataflow,workflow,postbox,events,idm,default`
|
||||||
- WebUI through the Vite dev server
|
- WebUI through the Vite dev server
|
||||||
- durable local files under `runtime/production-like/files`
|
- durable local files under `runtime/production-like/files`
|
||||||
|
|
||||||
@@ -423,6 +472,14 @@ SQLite's backup API; non-SQLite databases require
|
|||||||
`--database-backup-command`, `--database-restore-check-command`, and
|
`--database-backup-command`, `--database-restore-check-command`, and
|
||||||
`--database-restore-command`.
|
`--database-restore-command`.
|
||||||
|
|
||||||
|
Every non-dry run also owns the database-fenced
|
||||||
|
`core:module-lifecycle:deployment` recovery operation. The run record includes
|
||||||
|
its operation id and status. A supervised run reaches durable `succeeded` only
|
||||||
|
after restart and health verification. `recovery_required` or `outcome_unknown`
|
||||||
|
blocks another lifecycle mutation until the recorded operation is reconciled;
|
||||||
|
do not bypass this by deleting `install.lock`. See
|
||||||
|
[`MODULE_LIFECYCLE_RECOVERY.md`](MODULE_LIFECYCLE_RECOVERY.md).
|
||||||
|
|
||||||
Database hook commands receive:
|
Database hook commands receive:
|
||||||
|
|
||||||
- `GOVOPLAN_INSTALLER_RUN_DIR`
|
- `GOVOPLAN_INSTALLER_RUN_DIR`
|
||||||
@@ -462,7 +519,9 @@ Run the rollback drill before relying on installer automation in a new
|
|||||||
environment:
|
environment:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
/mnt/DATA/git/govoplan/tools/checks/module-installer-rollback-drill.py --format json
|
/mnt/DATA/git/govoplan/tools/checks/module-installer-rollback-drill.py \
|
||||||
|
--format json \
|
||||||
|
--evidence-path runtime/module-installer/restore-drill-evidence.json
|
||||||
```
|
```
|
||||||
|
|
||||||
The drill uses temporary SQLite databases and simulated package commands. It
|
The drill uses temporary SQLite databases and simulated package commands. It
|
||||||
@@ -483,7 +542,7 @@ checks, catalog trust, signing, keyring, replay, and license operation.
|
|||||||
## Operator Checklist
|
## Operator Checklist
|
||||||
|
|
||||||
- Runtime secrets are injected outside git.
|
- Runtime secrets are injected outside git.
|
||||||
- `MASTER_KEY_B64` is set and backed up securely.
|
- `MASTER_KEY_B64` is set and backed up securely; restores of locally encrypted content fail closed without the exact matching key.
|
||||||
- Database backup and restore commands are tested.
|
- Database backup and restore commands are tested.
|
||||||
- File/object storage is durable and backed up.
|
- File/object storage is durable and backed up.
|
||||||
- `CORS_ORIGINS` and cookie settings match the deployed WebUI origin.
|
- `CORS_ORIGINS` and cookie settings match the deployed WebUI origin.
|
||||||
|
|||||||
@@ -15,7 +15,19 @@ operator, and roadmap pages.
|
|||||||
| Policy decision DTOs and provenance | `POLICY_CONTRACTS.md` | Shared explain/provenance shape; module-specific policy docs should link here. |
|
| Policy decision DTOs and provenance | `POLICY_CONTRACTS.md` | Shared explain/provenance shape; module-specific policy docs should link here. |
|
||||||
| Events and audit trace context | `EVENTS_AND_AUDIT.md` | Event dispatch semantics and audit payload conventions. |
|
| Events and audit trace context | `EVENTS_AND_AUDIT.md` | Event dispatch semantics and audit payload conventions. |
|
||||||
| Action/effect automation layer | `ACTION_EFFECT_AUTOMATION_LAYER.md` | Action/effect contracts, consequence preview, runner semantics, and module boundary for automation. |
|
| Action/effect automation layer | `ACTION_EFFECT_AUTOMATION_LAYER.md` | Action/effect contracts, consequence preview, runner semantics, and module boundary for automation. |
|
||||||
|
| External references and integration maturity | `EXTERNAL_REFERENCES_AND_INTEGRATION_MATURITY.md` | Stable external identity and cumulative connector maturity; configured source authority is defined by the meta target architecture. |
|
||||||
|
| Institutional context and governed references | `INSTITUTIONAL_CONTEXT_CONTRACT.md` | Shared temporal, actor/representation, institution, mandate, service, party, decision, evidence, legal-basis, information-governance, presentation, and geo DTO/provider contracts. |
|
||||||
|
| Provider-neutral record filing | `RECORDS_FILING_CONTRACT.md` | Exact source-revision identity, current source authorization, idempotent filing, capability discovery, and ownership boundary. |
|
||||||
|
| Ticket routing and Case escalation | `TICKET_INTEGRATION_CONTRACTS.md` | Optional fail-open routing, replay-safe Case handoff, authorization, evidence, and ownership boundaries. |
|
||||||
|
| Temporal data read context | `TEMPORAL_DATA_CONTEXT.md` | Valid-time and recorded-time titlebar selection, HTTP/cache contract, security boundary, and module-adoption rule. |
|
||||||
|
| Cross-module information governance adoption | `INFORMATION_GOVERNANCE_ADOPTION.md` | Manifest evidence and enforcement rules for temporal browsing, purpose-aware access, retention, and institutional context. |
|
||||||
|
| Data-subject access and erasure requests | `DATA_SUBJECT_REQUESTS.md` | Provider-owned search and mutation, explicit coverage, governed export, retained evidence, permissions, and idempotent execution. |
|
||||||
|
| Context-sensitive F1 help | `CONTEXTUAL_HELP_CONTRACT.md` | Focus, route, module-manifest documentation contexts, Docs projection, and hosted fallback. |
|
||||||
|
| Semantic documentation subjects | `SEMANTIC_DOCUMENTATION_SUBJECTS.md` | Stable configured-artifact identity, safe provider discovery, revision review, authorization, and lifecycle semantics. |
|
||||||
|
| German localization and help quality gate | `LOCALIZATION_AND_HELP_QUALITY.md` | German reference locale, new-installation default, catalog completeness, automatic page associations, and explicit-help review priorities. |
|
||||||
| Postbox E2EE target architecture | `POSTBOX_E2EE_ARCHITECTURE.md` | Strategic encrypted postbox/mailbox model, key ownership, role mailbox semantics, and retraction limits. |
|
| Postbox E2EE target architecture | `POSTBOX_E2EE_ARCHITECTURE.md` | Strategic encrypted postbox/mailbox model, key ownership, role mailbox semantics, and retraction limits. |
|
||||||
|
| Shared state, runtime coordination, and recovery | `STATE_AND_RECOVERY_CONTRACT.md` | State profiles, object storage, node registration/drain, fenced leases, migration ordering, and recovery evidence. |
|
||||||
|
| Module lifecycle recovery | `MODULE_LIFECYCLE_RECOVERY.md` | Installer/live-graph recovery modes, deployment fence, evidence, retry blocking, and operator reconciliation. |
|
||||||
|
|
||||||
## Release And Operations
|
## Release And Operations
|
||||||
|
|
||||||
@@ -33,7 +45,11 @@ operator, and roadmap pages.
|
|||||||
| Topic | Canonical document | Notes |
|
| Topic | Canonical document | Notes |
|
||||||
| --- | --- | --- |
|
| --- | --- | --- |
|
||||||
| Product roadmap and module routing | `GOVOPLAN_MASTER_ROADMAP.md` | Product-level sequencing, implementation gates, issue routing, and missing-module decisions. |
|
| Product roadmap and module routing | `GOVOPLAN_MASTER_ROADMAP.md` | Product-level sequencing, implementation gates, issue routing, and missing-module decisions. |
|
||||||
|
| Stable platform ideas | `govoplan/docs/strategy/PLATFORM_CORE_IDEAS.md` | Cross-product thesis, canonical distinctions, product experience rule, maturity rule, and decision test. |
|
||||||
|
| Current cross-product reconciliation | `govoplan/docs/strategy/STRATEGY_STATUS.md` | The only current prose status source; generated evidence and Gitea remain authoritative inputs. |
|
||||||
|
| Institutional governance target | `govoplan/docs/architecture/INSTITUTIONAL_GOVERNANCE_TARGET_ARCHITECTURE.md` | Cross-product semantic layers, source-authority modes, candidate Mandates/Services/Parties/Decisions boundaries, and migration sequence. |
|
||||||
| UI/UX decisions | `UI_UX_DECISION_LEDGER.md` | Binding guided-UI decisions, open decisions, impact index, and review checklist. |
|
| UI/UX decisions | `UI_UX_DECISION_LEDGER.md` | Binding guided-UI decisions, open decisions, impact index, and review checklist. |
|
||||||
|
| Core interface migration | `INTERFACE_PATTERN_MIGRATION.md` | Core-owned settings, credential, retention, lifecycle, and shared-component evidence for the product pattern language. |
|
||||||
| Interface ethics and design doctrine | `INTERFACE_ETHICS_AND_DESIGN_DOCTRINE.md` | Product-level doctrine for context, decision, consequence, contestability, responsibility, and traceability. |
|
| Interface ethics and design doctrine | `INTERFACE_ETHICS_AND_DESIGN_DOCTRINE.md` | Product-level doctrine for context, decision, consequence, contestability, responsibility, and traceability. |
|
||||||
| Public-sector integration posture | `PUBLIC_SECTOR_INTEGRATION_STRATEGY.md` | Strategy index; executable target inventory lives in `govoplan-connectors`. |
|
| Public-sector integration posture | `PUBLIC_SECTOR_INTEGRATION_STRATEGY.md` | Strategy index; executable target inventory lives in `govoplan-connectors`. |
|
||||||
| Configuration packages | `CONFIGURATION_PACKAGES.md` | Package model, provider contract, import/export flow, and tracking slices. |
|
| Configuration packages | `CONFIGURATION_PACKAGES.md` | Package model, provider contract, import/export flow, and tracking slices. |
|
||||||
|
|||||||
@@ -0,0 +1,44 @@
|
|||||||
|
# Durable Recovery Operations
|
||||||
|
|
||||||
|
Modules must use `begin_durable_recovery_operation` for work whose effects can
|
||||||
|
outlive the caller's SQLAlchemy transaction. The helper commits the canonical
|
||||||
|
request hash, recovery plan, precondition evidence, running state, and lease
|
||||||
|
fence before the caller mutates object storage, a queue, a filesystem, or an
|
||||||
|
external provider.
|
||||||
|
|
||||||
|
Each later checkpoint is written through an independent database session. A
|
||||||
|
business-transaction rollback therefore cannot erase evidence of an earlier
|
||||||
|
effect. Successful completion requires concrete verification checks and a valid
|
||||||
|
hash chain. Compensation likewise records recovery-required, recovering, and
|
||||||
|
verified-recovered checkpoints rather than reporting an ordinary failure.
|
||||||
|
A definitive pre-effect or provider rejection records terminal `rejected`
|
||||||
|
evidence instead of being mislabeled as success, atomic rollback, or recovery
|
||||||
|
work.
|
||||||
|
|
||||||
|
If a runtime disappears, another runtime may claim the operation only after the
|
||||||
|
lease expires. The takeover records both fences. A stale compensatable operation
|
||||||
|
becomes recovery-required; a stale forward-only or irreversible external effect
|
||||||
|
becomes outcome-unknown; a database-only atomic operation is recorded failed
|
||||||
|
because its transaction rolled back. Takeover never re-executes the original
|
||||||
|
request automatically.
|
||||||
|
|
||||||
|
Evidence and metadata may contain opaque references, digests, counts, and
|
||||||
|
provider result codes. They must never contain credentials or resolved secrets.
|
||||||
|
Ops is the platform surface for unresolved operation status; owning modules must
|
||||||
|
provide the reconciliation action and business-level explanation.
|
||||||
|
|
||||||
|
Database-only operations must use the durable handle's atomic terminal methods
|
||||||
|
when their module rows and final recovery checkpoint belong to one invariant.
|
||||||
|
Those methods stage the terminal checkpoint and lease release in the caller's
|
||||||
|
SQLAlchemy transaction, then commit the domain rows and recovery evidence
|
||||||
|
together. A failed commit rolls both back and leaves the previously durable
|
||||||
|
`running` record available for stale-fence handling; modules must not commit
|
||||||
|
their domain state first and close an `atomic` recovery record afterwards.
|
||||||
|
|
||||||
|
An owning module may reconcile an `outcome_unknown` provider effect through the
|
||||||
|
claimed durable handle's `resolve_unknown` method. External evidence that the
|
||||||
|
effect occurred records verified success. Evidence that it did not occur moves
|
||||||
|
the operation through recovery-required and recovering to verified recovered,
|
||||||
|
so any later attempt must use a new deliberate idempotency key. The method does
|
||||||
|
not infer provider state and requires the same terminal verification structure
|
||||||
|
and hash-chain checks as ordinary completion.
|
||||||
@@ -35,6 +35,26 @@ Connectors must declare and document the maturity they actually implement.
|
|||||||
handling, deletion semantics, and observable failures. A link-only connector
|
handling, deletion semantics, and observable failures. A link-only connector
|
||||||
must not imply that GovOPlaN holds an authoritative copy.
|
must not imply that GovOPlaN holds an authoritative copy.
|
||||||
|
|
||||||
|
## Source Authority Is A Separate Dimension
|
||||||
|
|
||||||
|
Integration maturity states what an adapter is capable of doing. It does not
|
||||||
|
decide which system owns truth for a configured object or field group. A
|
||||||
|
binding separately selects one of the source-authority modes defined by the
|
||||||
|
[institutional governance target architecture](../../govoplan/docs/architecture/INSTITUTIONAL_GOVERNANCE_TARGET_ARCHITECTURE.md):
|
||||||
|
|
||||||
|
- `native_authoritative`
|
||||||
|
- `external_authoritative`
|
||||||
|
- `external_mirror`
|
||||||
|
- `governed_sync`
|
||||||
|
- `governance_overlay`
|
||||||
|
- `linked_reference`
|
||||||
|
|
||||||
|
A connector can therefore support `synchronize` while a tenant deliberately
|
||||||
|
uses it only as an external mirror. Conversely, a native GovOPlaN object may
|
||||||
|
retain link-only references to several external systems. Authority may be
|
||||||
|
narrowed by tenant, organization, service, object type, object, field group, or
|
||||||
|
process step and must be visible in provenance and configuration preflight.
|
||||||
|
|
||||||
## Domain Ownership
|
## Domain Ownership
|
||||||
|
|
||||||
- Domain modules own native GovOPlaN objects and their authorization.
|
- Domain modules own native GovOPlaN objects and their authorization.
|
||||||
|
|||||||
@@ -13,4 +13,4 @@ tools/gitea/gitea-sync-wiki.py --help
|
|||||||
|
|
||||||
Canonical documentation:
|
Canonical documentation:
|
||||||
|
|
||||||
- `/mnt/DATA/git/govoplan/docs/GITEA_ISSUES.md`
|
- `/mnt/DATA/git/govoplan/docs/project/GITEA_ISSUES.md`
|
||||||
|
|||||||
@@ -221,7 +221,8 @@ Admin lists use bounded container grids:
|
|||||||
- recipient import with column mapping;
|
- recipient import with column mapping;
|
||||||
- session/device revocation UI;
|
- session/device revocation UI;
|
||||||
- backup/restore, monitoring, and update procedures;
|
- backup/restore, monitoring, and update procedures;
|
||||||
- DSAR workflows and evidence bundle verifier;
|
- additional module providers and signed human-readable response packages for
|
||||||
|
the implemented DSAR workflow described in `DATA_SUBJECT_REQUESTS.md`;
|
||||||
- campaign ownership transfer workflow;
|
- campaign ownership transfer workflow;
|
||||||
- policy impact analysis before delete/disable/unshare/change;
|
- policy impact analysis before delete/disable/unshare/change;
|
||||||
- LDAP/OIDC/SAML provisioning;
|
- LDAP/OIDC/SAML provisioning;
|
||||||
|
|||||||
@@ -10,12 +10,15 @@ gates. Issues are the active backlog; this document is durable architecture
|
|||||||
planning context and should be mirrored to the Gitea wiki.
|
planning context and should be mirrored to the Gitea wiki.
|
||||||
|
|
||||||
The meta repository's
|
The meta repository's
|
||||||
[Connected Governance Platform Roadmap](https://git.add-ideas.de/GovOPlaN/govoplan/src/branch/main/docs/CONNECTED_GOVERNANCE_PLATFORM_ROADMAP.md)
|
[GovOPlaN Roadmap](https://git.add-ideas.de/GovOPlaN/govoplan/src/branch/main/docs/strategy/ROADMAP.md)
|
||||||
describes the corresponding cross-product stakeholder visions, configurable
|
describes the corresponding cross-product stakeholder visions, configurable
|
||||||
service and operating configurations, connected outcome stories, and
|
service and operating configurations, connected outcome stories, and
|
||||||
capability horizons. The selected five-stage delivery sequence and its gates
|
capability horizons. The selected five-stage delivery sequence and its gates
|
||||||
are in the meta repository's
|
are in the meta repository's
|
||||||
[Reference Journey Program](https://git.add-ideas.de/GovOPlaN/govoplan/src/branch/main/docs/REFERENCE_JOURNEY_PROGRAM.md).
|
[Reference Journey Program](https://git.add-ideas.de/GovOPlaN/govoplan/src/branch/main/docs/strategy/REFERENCE_JOURNEY_PROGRAM.md).
|
||||||
|
The semantic target, source-authority modes, and reconciliation with the
|
||||||
|
implemented platform are in the meta repository's
|
||||||
|
[Institutional Governance Target Architecture](https://git.add-ideas.de/GovOPlaN/govoplan/src/branch/main/docs/architecture/INSTITUTIONAL_GOVERNANCE_TARGET_ARCHITECTURE.md).
|
||||||
Those product documents are canonical; this Core roadmap remains their
|
Those product documents are canonical; this Core roadmap remains their
|
||||||
technical sequencing and module-routing companion.
|
technical sequencing and module-routing companion.
|
||||||
|
|
||||||
@@ -64,8 +67,9 @@ verify or reverse those effects.
|
|||||||
`INTERFACE_ETHICS_AND_DESIGN_DOCTRINE.md`.
|
`INTERFACE_ETHICS_AND_DESIGN_DOCTRINE.md`.
|
||||||
- Automation must use governed action/effect contracts, not hidden side
|
- Automation must use governed action/effect contracts, not hidden side
|
||||||
effects. The first automation layer is defined in
|
effects. The first automation layer is defined in
|
||||||
`ACTION_EFFECT_AUTOMATION_LAYER.md` and should start in `govoplan-workflow`
|
`ACTION_EFFECT_AUTOMATION_LAYER.md`; its first runner lives in
|
||||||
unless a separate automation module becomes justified.
|
`govoplan-workflow-engine`. Create a separate automation module only if the
|
||||||
|
scheduler/action runtime outgrows workflow coordination.
|
||||||
- Encrypted postboxes are a strategic target. Early postbox, access, and
|
- Encrypted postboxes are a strategic target. Early postbox, access, and
|
||||||
identity-trust contracts should stay compatible with the E2EE architecture in
|
identity-trust contracts should stay compatible with the E2EE architecture in
|
||||||
`POSTBOX_E2EE_ARCHITECTURE.md`.
|
`POSTBOX_E2EE_ARCHITECTURE.md`.
|
||||||
@@ -144,8 +148,9 @@ pattern exists.
|
|||||||
| Structured forms and validation | `govoplan-forms` |
|
| Structured forms and validation | `govoplan-forms` |
|
||||||
| Uploaded files and managed storage | `govoplan-files` |
|
| Uploaded files and managed storage | `govoplan-files` |
|
||||||
| Case record and lifecycle | `govoplan-cases` |
|
| Case record and lifecycle | `govoplan-cases` |
|
||||||
| Workflow transitions and automation | `govoplan-workflow` |
|
| Workflow runtime, transitions, and automation | `govoplan-workflow-engine` |
|
||||||
| Action/effect catalogue and automation runner | first `govoplan-workflow`; possible future `govoplan-automation` if it outgrows workflow |
|
| Workflow definition editing | optional `govoplan-workflow` |
|
||||||
|
| Action/effect catalogue and automation runner | first `govoplan-workflow-engine`; possible future `govoplan-automation` only if it outgrows workflow |
|
||||||
| Internal work queues and tasks | `govoplan-tasks` |
|
| Internal work queues and tasks | `govoplan-tasks` |
|
||||||
| Appointment proposals and booking | `govoplan-appointments`, `govoplan-calendar` |
|
| Appointment proposals and booking | `govoplan-appointments`, `govoplan-calendar` |
|
||||||
| Postbox, email, and notifications | `govoplan-postbox`, `govoplan-mail`, `govoplan-notifications` |
|
| Postbox, email, and notifications | `govoplan-postbox`, `govoplan-mail`, `govoplan-notifications` |
|
||||||
@@ -153,13 +158,18 @@ pattern exists.
|
|||||||
| Organizational structures, units, and functions | `govoplan-organizations` |
|
| Organizational structures, units, and functions | `govoplan-organizations` |
|
||||||
| Identity-to-function assignments and directory synchronization | `govoplan-idm` |
|
| Identity-to-function assignments and directory synchronization | `govoplan-idm` |
|
||||||
| Identity trust, device keys, and encrypted postbox key contracts | `govoplan-identity-trust`, `govoplan-access`, `govoplan-postbox` |
|
| Identity trust, device keys, and encrypted postbox key contracts | `govoplan-identity-trust`, `govoplan-access`, `govoplan-postbox` |
|
||||||
| Service directory/catalog | `govoplan-portal` |
|
| Service directory presentation | `govoplan-portal` |
|
||||||
|
| Versioned institutional service definition | shared service contract first; candidate `govoplan-services` after reuse proof |
|
||||||
|
| Mandate, jurisdiction, and institutional authority | shared mandate contract first; candidate `govoplan-mandates` after reuse proof |
|
||||||
|
| Procedure-local parties and representation | shared party contract first; candidate `govoplan-parties` after reuse proof |
|
||||||
|
| Formal institutional decisions | shared decision contract first; candidate `govoplan-decisions` after reuse proof |
|
||||||
| Permit/document generation | `govoplan-templates`, `govoplan-dms` |
|
| Permit/document generation | `govoplan-templates`, `govoplan-dms` |
|
||||||
| Payment capture and accounting handoff | `govoplan-payments`, `govoplan-ledger` |
|
| Payment capture and accounting handoff | `govoplan-payments`, `govoplan-ledger` |
|
||||||
| Authentication projection, roles, permissions, acting context | `govoplan-access` |
|
| Authentication projection, roles, permissions, acting context | `govoplan-access` |
|
||||||
| Tenants, policy, and audit | `govoplan-tenancy`, `govoplan-policy`, `govoplan-audit` |
|
| Tenants, policy, and audit | `govoplan-tenancy`, `govoplan-policy`, `govoplan-audit` |
|
||||||
| External software integration | `govoplan-connectors` |
|
| External software integration | `govoplan-connectors` |
|
||||||
| Recurring extraction and transformation | possible future `govoplan-datasources`, possible future `govoplan-dataflow` |
|
| Governed data/register catalogue | `govoplan-datasources` |
|
||||||
|
| Recurring extraction and transformation | `govoplan-dataflow` over Datasources and Connectors contracts |
|
||||||
| Reports, BI, and management visibility | `govoplan-reporting` |
|
| Reports, BI, and management visibility | `govoplan-reporting` |
|
||||||
|
|
||||||
## Configuration And Safety Target
|
## Configuration And Safety Target
|
||||||
@@ -204,8 +214,9 @@ an editor applies a high-impact configuration change.
|
|||||||
|
|
||||||
## Reference Journeys
|
## Reference Journeys
|
||||||
|
|
||||||
The active sequence is selected. Workflow remains deliberately deferred and is
|
The active sequence is selected. Workflow Engine and its optional editor are
|
||||||
not a dependency of these journeys.
|
now available foundations, but a reference journey does not depend on Workflow
|
||||||
|
unless its package explicitly composes and proves it.
|
||||||
|
|
||||||
### Journey 1: Campaign Demonstration Composition
|
### Journey 1: Campaign Demonstration Composition
|
||||||
|
|
||||||
@@ -256,9 +267,11 @@ The result must preserve official-key mappings, organizational and reporting
|
|||||||
date semantics, quality findings, quarantine/replay, transparent calculation,
|
date semantics, quality findings, quarantine/replay, transparent calculation,
|
||||||
and reproducible promotion between development, test, and production.
|
and reproducible promotion between development, test, and production.
|
||||||
|
|
||||||
Reporting consumes the product. Create `govoplan-datasources` or
|
Reporting consumes the product. Datasources owns the governed source and
|
||||||
`govoplan-dataflow` only after the concrete path proves repeated ownership that
|
materialization lifecycle; Dataflow owns typed transformation/run lineage;
|
||||||
does not belong to connectors, Reporting, or the producing domain module.
|
Connectors owns external transport. The concrete path must now prove those
|
||||||
|
implemented boundaries and expose any missing contracts instead of recreating
|
||||||
|
them inside Reporting or a producing domain module.
|
||||||
|
|
||||||
### Journey 5: Collaborative Document Lifecycle
|
### Journey 5: Collaborative Document Lifecycle
|
||||||
|
|
||||||
@@ -336,8 +349,9 @@ Create or refine in this order:
|
|||||||
access.
|
access.
|
||||||
4. `govoplan-cases`: case record, status, assignments, deadlines, and case
|
4. `govoplan-cases`: case record, status, assignments, deadlines, and case
|
||||||
evidence.
|
evidence.
|
||||||
5. `govoplan-workflow`: state machine, transitions, commands, and module
|
5. `govoplan-workflow-engine`: state machine, transitions, commands, module
|
||||||
handoff.
|
handoff, and resumable execution; optional `govoplan-workflow` supplies the
|
||||||
|
editor.
|
||||||
6. `govoplan-tasks`: work queues, assignments, due dates, and follow-ups.
|
6. `govoplan-tasks`: work queues, assignments, due dates, and follow-ups.
|
||||||
7. `govoplan-templates`: permit/decision document generation.
|
7. `govoplan-templates`: permit/decision document generation.
|
||||||
8. `govoplan-postbox`, `govoplan-mail`, `govoplan-notifications`: applicant and
|
8. `govoplan-postbox`, `govoplan-mail`, `govoplan-notifications`: applicant and
|
||||||
@@ -526,31 +540,34 @@ Refine:
|
|||||||
dashboard data.
|
dashboard data.
|
||||||
- `govoplan-search`: permissioned cross-module discovery.
|
- `govoplan-search`: permissioned cross-module discovery.
|
||||||
|
|
||||||
Create only when justified:
|
Refine the existing owners:
|
||||||
|
|
||||||
- `govoplan-datasources`: source catalog, connection profiles, schema discovery,
|
- `govoplan-datasources`: governed data/register catalog, live/cached/static
|
||||||
freshness, provenance.
|
sources, staging, immutable materializations, freshness, quality, legal and
|
||||||
- `govoplan-dataflow`: transformations, validation, lineage, scheduled runs,
|
organizational context, and provenance. Connector profiles and credentials
|
||||||
publication outputs.
|
remain in Connectors.
|
||||||
- `govoplan-projects`: only if OpenProject connectors and existing cases/tasks
|
- `govoplan-dataflow`: typed transformations, validation, lineage, manual,
|
||||||
cannot cover the required semantics.
|
scheduled and event-triggered runs, reusable definitions, and publication
|
||||||
|
outputs.
|
||||||
|
- `govoplan-projects`: native projects, portfolios, milestones, goals,
|
||||||
|
dependencies, capacity, outcomes, and external OpenProject references;
|
||||||
|
Connectors owns OpenProject transport and synchronization.
|
||||||
|
|
||||||
Reference journey: monthly data extraction, transformation, validation, approval,
|
Reference journey: monthly data extraction, transformation, validation, approval,
|
||||||
publication, and reporting.
|
publication, and reporting.
|
||||||
|
|
||||||
Recurring extraction/transformation should start as a configuration package
|
Recurring extraction/transformation should be delivered as a configuration
|
||||||
across connectors, files, workflow, reporting, and templates. The package should
|
package across Connectors, Datasources, Dataflow, Workflow Engine, Reporting,
|
||||||
register sources, declare schemas, define mapping/validation versions, schedule
|
Files, and Templates. The package should register sources, declare schemas,
|
||||||
runs, produce previewable diffs, write governed outputs, and preserve lineage,
|
define mapping/validation versions, schedule runs, produce previewable diffs,
|
||||||
hashes, operator actions, and audit evidence. Create `govoplan-datasources` or
|
write governed outputs, and preserve lineage, hashes, operator actions, and
|
||||||
`govoplan-dataflow` only after this work exposes repeated contracts that do not
|
audit evidence.
|
||||||
belong to existing modules.
|
|
||||||
|
|
||||||
Exit criteria:
|
Exit criteria:
|
||||||
|
|
||||||
- connector catalog exists before building many adapters
|
- connector catalog exists before building many adapters
|
||||||
- dataflow is created only after recurring transformation becomes product
|
- datasource and dataflow ownership remains provider-neutral and is proved by
|
||||||
behavior
|
the recurring transformation package
|
||||||
- reporting consumes governed sources with provenance
|
- reporting consumes governed sources with provenance
|
||||||
|
|
||||||
## Implementation Gates
|
## Implementation Gates
|
||||||
@@ -591,23 +608,25 @@ in the capability waves:
|
|||||||
4. Implement one data-backed Templates/Reporting path and safe HIS-style deep
|
4. Implement one data-backed Templates/Reporting path and safe HIS-style deep
|
||||||
launch.
|
launch.
|
||||||
5. Extend that concrete source into one governed university analytical data
|
5. Extend that concrete source into one governed university analytical data
|
||||||
product before generalizing data-source or dataflow ownership.
|
product and use it to harden the existing Datasources/Dataflow ownership,
|
||||||
|
quality, lineage, and promotion contracts.
|
||||||
6. Implement Files-backed DMS versions and one provider-neutral collaborative
|
6. Implement Files-backed DMS versions and one provider-neutral collaborative
|
||||||
editing lifecycle, then connect Records handoff.
|
editing lifecycle, then connect Records handoff.
|
||||||
7. Maintain already integrated Calendar/Scheduling/Poll and other foundations;
|
7. Maintain already integrated Calendar/Scheduling/Poll and other foundations;
|
||||||
activate another capability cluster only when the current journey needs it
|
activate another capability cluster only when the current journey needs it
|
||||||
or the product roadmap explicitly reprioritizes it.
|
or the product roadmap explicitly reprioritizes it.
|
||||||
8. Resume Workflow only by explicit product decision and constrain it with
|
8. Extend Workflow Engine and the optional editor only through stable actions
|
||||||
stable actions from one demonstrated package.
|
and one demonstrated package at a time.
|
||||||
|
|
||||||
## Deliberate Deferrals
|
## Deliberate Deferrals
|
||||||
|
|
||||||
Defer these until a reference journey proves the need:
|
Defer these until a reference journey proves the need:
|
||||||
|
|
||||||
- full ERP replacement
|
- full ERP replacement
|
||||||
- native project management beyond connector support
|
- unsupported breadth in native project management before the Projects/OpenProject
|
||||||
- an unbounded general-purpose dataflow platform; the bounded governed BI
|
boundary is proved in a reference journey
|
||||||
reference journey is selected
|
- unbounded Dataflow operators or execution engines without golden-flow,
|
||||||
|
quality, lineage, resource-limit, and recovery evidence
|
||||||
- every possible public-sector protocol adapter
|
- every possible public-sector protocol adapter
|
||||||
- rich LMS behavior beyond training administration
|
- rich LMS behavior beyond training administration
|
||||||
- full qualified digital signing/trust services beyond the identity-trust and
|
- full qualified digital signing/trust services beyond the identity-trust and
|
||||||
@@ -630,26 +649,26 @@ repositories or to explicit missing-module decisions.
|
|||||||
| Fully UI-managed configuration with safety controls | `govoplan-admin`, `govoplan-core`, `govoplan-policy`, `govoplan-access`, `govoplan-audit` | `GovOPlaN/govoplan-core#218` |
|
| Fully UI-managed configuration with safety controls | `govoplan-admin`, `govoplan-core`, `govoplan-policy`, `govoplan-access`, `govoplan-audit` | `GovOPlaN/govoplan-core#218` |
|
||||||
| Access as a module | `govoplan-access` | `GovOPlaN/govoplan-access#7` |
|
| Access as a module | `govoplan-access` | `GovOPlaN/govoplan-access#7` |
|
||||||
| Interface ethics and decision-consequence doctrine | `govoplan-core` plus all UI-owning modules | `GovOPlaN/govoplan-core#227` |
|
| Interface ethics and decision-consequence doctrine | `govoplan-core` plus all UI-owning modules | `GovOPlaN/govoplan-core#227` |
|
||||||
| Action/effect automation layer | first `govoplan-workflow`; possible future `govoplan-automation` | `GovOPlaN/govoplan-workflow#1` |
|
| Action/effect automation layer | `govoplan-workflow-engine`; possible future `govoplan-automation` only after boundary proof | `GovOPlaN/govoplan-workflow#1` |
|
||||||
| E2EE role/function postbox architecture | `govoplan-postbox`, `govoplan-identity-trust`, `govoplan-access`, `govoplan-policy`, `govoplan-audit` | `GovOPlaN/govoplan-postbox#15`, `GovOPlaN/govoplan-identity-trust#1` |
|
| E2EE role/function postbox architecture | `govoplan-postbox`, `govoplan-identity-trust`, `govoplan-access`, `govoplan-policy`, `govoplan-audit` | `GovOPlaN/govoplan-postbox#15`, `GovOPlaN/govoplan-identity-trust#1` |
|
||||||
| Identity, account, function, role, right semantic model | `govoplan-access` | `GovOPlaN/govoplan-access#9` |
|
| Identity, account, function, role, right semantic model | `govoplan-access` | `GovOPlaN/govoplan-access#9` |
|
||||||
| Role-based service directory/catalog | `govoplan-portal` | `GovOPlaN/govoplan-portal#1` |
|
| Role-based service directory presentation | `govoplan-portal`; reusable service definition is a shared contract and candidate `govoplan-services` | `GovOPlaN/govoplan-portal#1` |
|
||||||
| Unified inbox across tasks, postbox, notifications, and portal | `govoplan-core` coordination plus owning modules | `GovOPlaN/govoplan-tasks#1`, `GovOPlaN/govoplan-notifications#1` |
|
| Unified inbox across tasks, postbox, notifications, and portal | `govoplan-core` coordination plus owning modules | `GovOPlaN/govoplan-tasks#1`, `GovOPlaN/govoplan-notifications#1` |
|
||||||
| OpenProject API / project management connector | `govoplan-connectors` | `GovOPlaN/govoplan-connectors#1` |
|
| OpenProject API / project management connector | `govoplan-connectors` | `GovOPlaN/govoplan-connectors#1` |
|
||||||
| Native project-management module decision | connector-first through `govoplan-connectors`; no native project module yet | `GovOPlaN/govoplan-core#196`, `GovOPlaN/govoplan-connectors#1` |
|
| Native project-management module | `govoplan-projects`; OpenProject transport remains connector-owned | `GovOPlaN/govoplan-projects#1`, `GovOPlaN/govoplan-connectors#12` |
|
||||||
| Datasources for databases, CSV, files, APIs | no repository yet; start with connectors/files/reporting and create `govoplan-datasources` only after the first package proves shared source-catalog ownership | `GovOPlaN/govoplan-core#197` |
|
| Datasources for databases, CSV, files, APIs | `govoplan-datasources`, with external protocol and credential ownership in Connectors | `GovOPlaN/govoplan-datasources#1` |
|
||||||
| Dataflow for pipelines, BI, publication | no repository yet; start with workflow/reporting/connectors and create `govoplan-dataflow` only after repeated pipeline/lineage contracts emerge | `GovOPlaN/govoplan-core#198` |
|
| Dataflow for pipelines, BI, publication | `govoplan-dataflow` over Datasources and module-owned providers | `GovOPlaN/govoplan-dataflow#1` |
|
||||||
| Monthly datasource and transformation workflows | first as configuration package across connectors, files, workflow, reporting, and templates | `GovOPlaN/govoplan-core#216` |
|
| Monthly datasource and transformation workflows | configuration package across Connectors, Datasources, Dataflow, Workflow Engine, Reporting, Files, and Templates | `GovOPlaN/govoplan#8`, `GovOPlaN/govoplan-dataflow#17` |
|
||||||
| Templates for letters, emails, forms, reports | `govoplan-templates`, separate from reporting | `GovOPlaN/govoplan-core#190`, `GovOPlaN/govoplan-templates#1` |
|
| Templates for letters, emails, forms, reports | `govoplan-templates`, separate from reporting | `GovOPlaN/govoplan-core#190`, `GovOPlaN/govoplan-templates#1` |
|
||||||
| Reporting and BI | `govoplan-reporting`, separate from templates | `GovOPlaN/govoplan-core#190`, `GovOPlaN/govoplan-reporting#1` |
|
| Reporting and BI | `govoplan-reporting`, separate from templates | `GovOPlaN/govoplan-core#190`, `GovOPlaN/govoplan-reporting#1` |
|
||||||
| File connectors: Nextcloud, Seafile, SMB, NFS | `govoplan-files` | `GovOPlaN/govoplan-files#15` |
|
| File connectors: Nextcloud, Seafile, SMB, NFS | `govoplan-files` | `GovOPlaN/govoplan-files#15` |
|
||||||
| Public-sector software integration catalogue | `govoplan-connectors` with core strategy index | `GovOPlaN/govoplan-core#191`, `GovOPlaN/govoplan-connectors#2` |
|
| Public-sector software integration catalogue | `govoplan-connectors` with core strategy index | `GovOPlaN/govoplan-core#191`, `GovOPlaN/govoplan-connectors#2` |
|
||||||
| Public-sector integration landscape catalogue | `govoplan-connectors` with core tracking | `GovOPlaN/govoplan-core#215` |
|
| Public-sector integration landscape catalogue | `govoplan-connectors` with core tracking | `GovOPlaN/govoplan-core#215` |
|
||||||
| Cases module concept | `govoplan-cases` | `GovOPlaN/govoplan-core#174` |
|
| Cases module concept | `govoplan-cases` | `GovOPlaN/govoplan-core#174` |
|
||||||
| Workflow module concept | `govoplan-workflow` | `GovOPlaN/govoplan-core#175` |
|
| Workflow runtime/editor split | `govoplan-workflow-engine` runtime plus optional `govoplan-workflow` editor | `GovOPlaN/govoplan-workflow#12`, `GovOPlaN/govoplan-workflow#13` |
|
||||||
| Connectors module concept | `govoplan-connectors` | `GovOPlaN/govoplan-core#176` |
|
| Connectors module concept | `govoplan-connectors` | `GovOPlaN/govoplan-core#176` |
|
||||||
| Adrema-style address and distribution-list management | `govoplan-addresses` | `GovOPlaN/govoplan-addresses#1` |
|
| Adrema-style address and distribution-list management | `govoplan-addresses` | `GovOPlaN/govoplan-addresses#1` |
|
||||||
| Consume sources and become a governed source | `govoplan-connectors` plus possible future `govoplan-dataflow` | `GovOPlaN/govoplan-connectors#3`, `GovOPlaN/govoplan-core#198` |
|
| Consume sources and become a governed source | Connectors acquires, Datasources governs/materializes, Dataflow transforms/publishes | `GovOPlaN/govoplan-connectors#3`, `GovOPlaN/govoplan-datasources#3` |
|
||||||
| Governed connector configuration, dry-run, and simulation runtime | `govoplan-connectors` | `GovOPlaN/govoplan-connectors#6` |
|
| Governed connector configuration, dry-run, and simulation runtime | `govoplan-connectors` | `GovOPlaN/govoplan-connectors#6` |
|
||||||
| Terminfindung and meeting scheduling polls | `govoplan-scheduling`; calendar primitives remain in calendar | `GovOPlaN/govoplan-core#193`, `GovOPlaN/govoplan-scheduling#1` |
|
| Terminfindung and meeting scheduling polls | `govoplan-scheduling`; calendar primitives remain in calendar | `GovOPlaN/govoplan-core#193`, `GovOPlaN/govoplan-scheduling#1` |
|
||||||
| Terminplaner and calendar primitives | `govoplan-calendar` | `GovOPlaN/govoplan-core#193`, `GovOPlaN/govoplan-calendar#1` |
|
| Terminplaner and calendar primitives | `govoplan-calendar` | `GovOPlaN/govoplan-core#193`, `GovOPlaN/govoplan-calendar#1` |
|
||||||
@@ -671,27 +690,23 @@ repositories or to explicit missing-module decisions.
|
|||||||
Boundary rationale lives in `MODULE_ARCHITECTURE.md`. Current decisions:
|
Boundary rationale lives in `MODULE_ARCHITECTURE.md`. Current decisions:
|
||||||
|
|
||||||
- templates and reporting are separate modules
|
- templates and reporting are separate modules
|
||||||
- RSS/source consume-publish starts in connectors; datasources/dataflow are not
|
- RSS/source consume-publish starts in Connectors; governed source identity and
|
||||||
repositories yet
|
snapshots belong to Datasources and transformations belong to Dataflow
|
||||||
- calendar, scheduling, and appointments are three separate modules
|
- calendar, scheduling, and appointments are three separate modules
|
||||||
- forms definitions and forms runtime are separate responsibilities
|
- forms definitions and forms runtime are separate responsibilities
|
||||||
- OpenDesk is an integration profile across modules, not a monolithic module
|
- OpenDesk is an integration profile across modules, not a monolithic module
|
||||||
- OpenProject is connector-first; no native projects module yet
|
- OpenProject transport is connector-owned; native portfolio/project semantics
|
||||||
|
belong to Projects
|
||||||
- public-sector integration strategy stays in core; executable catalogue work
|
- public-sector integration strategy stays in core; executable catalogue work
|
||||||
lives in connectors
|
lives in connectors
|
||||||
- encrypted postbox and identity-trust are strategic contracts, not mail-module
|
- encrypted postbox and identity-trust are strategic contracts, not mail-module
|
||||||
behavior
|
behavior
|
||||||
- automation starts as workflow-owned action/effect execution and may split into
|
- automation starts in Workflow Engine and may split into a dedicated module
|
||||||
a dedicated module only after the runner becomes broader than workflow
|
only after the runner becomes broader than workflow
|
||||||
|
- Mandates, Services, Parties, and Decisions begin as shared semantic contracts;
|
||||||
The following modules are intentionally not created yet:
|
create repositories only after independent persistence, lifecycle, security,
|
||||||
|
and multiple-consumer evidence passes the repository threshold in the
|
||||||
- `govoplan-datasources`
|
institutional governance target architecture
|
||||||
- `govoplan-dataflow`
|
|
||||||
- `govoplan-projects`
|
|
||||||
|
|
||||||
Create a repository only after a concrete implementation package proves that
|
|
||||||
existing connector, files, reporting, workflow, or task ownership is too narrow.
|
|
||||||
|
|
||||||
Core keeps the strategy index in
|
Core keeps the strategy index in
|
||||||
`PUBLIC_SECTOR_INTEGRATION_STRATEGY.md`: integration postures, default
|
`PUBLIC_SECTOR_INTEGRATION_STRATEGY.md`: integration postures, default
|
||||||
|
|||||||
@@ -0,0 +1,131 @@
|
|||||||
|
# Information Governance Adoption
|
||||||
|
|
||||||
|
## Platform Rule
|
||||||
|
|
||||||
|
Temporal browsing, purpose-aware access, retention, and institutional context
|
||||||
|
are platform-wide information-governance dimensions. Every module receives the
|
||||||
|
same contract by default. A module may claim `partial` or `enforced` only with
|
||||||
|
repository-owned object scope, evidence, and limitations; it may claim
|
||||||
|
`not_applicable` only when the dimension genuinely does not apply.
|
||||||
|
|
||||||
|
Historical business data is always authorized under the current security
|
||||||
|
state. No module may use a historical permission, membership, role, function
|
||||||
|
assignment, or policy projection to weaken present-day access.
|
||||||
|
|
||||||
|
Platform-wide adoption is tracked in
|
||||||
|
[GovOPlaN #40](https://git.add-ideas.de/GovOPlaN/govoplan/issues/40), with
|
||||||
|
temporal reads detailed in
|
||||||
|
[GovOPlaN #39](https://git.add-ideas.de/GovOPlaN/govoplan/issues/39).
|
||||||
|
|
||||||
|
## Manifest Declaration
|
||||||
|
|
||||||
|
`ModuleManifest.information_governance` publishes four dimensions:
|
||||||
|
|
||||||
|
- `temporal_browsing`;
|
||||||
|
- `purpose_aware_access`;
|
||||||
|
- `retention`;
|
||||||
|
- `institutional_context`.
|
||||||
|
|
||||||
|
Each dimension declares:
|
||||||
|
|
||||||
|
- adoption: `not_applicable`, `contract_only`, `partial`, or `enforced`;
|
||||||
|
- object types covered;
|
||||||
|
- repository-local test/documentation evidence;
|
||||||
|
- the remaining limitation for `contract_only` or `partial`.
|
||||||
|
|
||||||
|
The default is intentionally `contract_only`. It applies the platform rule
|
||||||
|
without pretending that existing domain queries and effects already enforce
|
||||||
|
it. `reference_ready`, `supported`, and `lts` modules cannot retain an
|
||||||
|
applicable dimension below `enforced`.
|
||||||
|
|
||||||
|
## Read Contract
|
||||||
|
|
||||||
|
For every persistent domain object, the owner classifies the read:
|
||||||
|
|
||||||
|
1. **Current-only:** historical semantics do not exist and the API says so.
|
||||||
|
2. **Valid-time:** select facts effective now or at the requested instant.
|
||||||
|
3. **Bitemporal:** additionally select only revisions known by `recorded_at`.
|
||||||
|
4. **All-validity:** return effective revisions in a bounded history view.
|
||||||
|
|
||||||
|
The Core temporal middleware supplies the request context. Owners apply it in
|
||||||
|
repositories or query helpers, include it in cache keys, return evaluated
|
||||||
|
context, and test current/at/all plus recorded-time boundaries. Search,
|
||||||
|
reporting, exports, selectors, counts, and drill-through must use the same
|
||||||
|
projection as the owning list/detail API.
|
||||||
|
|
||||||
|
## Purpose-Aware Access Contract
|
||||||
|
|
||||||
|
Permission establishes a technical action ceiling. Purpose-aware access asks
|
||||||
|
whether this actor, represented capacity, case/work item, legal basis, and
|
||||||
|
declared use may access this object now.
|
||||||
|
|
||||||
|
- A client-supplied purpose is an assertion, never authority by itself.
|
||||||
|
- The owner or Policy capability validates the purpose and returns explainable
|
||||||
|
provenance.
|
||||||
|
- Sensitive access can require case assignment, mandate, reason capture,
|
||||||
|
approval, or break-glass evidence.
|
||||||
|
- Search, selectors, reporting, exports, background jobs, and connectors apply
|
||||||
|
the same decision.
|
||||||
|
- Audit records the validated purpose identifier and decision reference, not
|
||||||
|
unnecessary content.
|
||||||
|
|
||||||
|
## Retention Contract
|
||||||
|
|
||||||
|
Every persistent object declares an owner, retention class or policy reference,
|
||||||
|
trigger, start instant, hold behavior, review/disposition action, and evidence.
|
||||||
|
Retention is not a generic timestamp deletion job.
|
||||||
|
|
||||||
|
- Domain owners enumerate and execute their own effects through a typed
|
||||||
|
retention provider.
|
||||||
|
- Policy resolves inherited ceilings and simulation.
|
||||||
|
- Records owns record disposition; Files owns byte/object effects; Audit owns
|
||||||
|
audit-detail behavior; external providers declare their own effect and
|
||||||
|
recovery semantics.
|
||||||
|
- Dry-run, legal hold, exact revision, idempotency, outcome unknown,
|
||||||
|
reconciliation, correction, and destruction evidence are mandatory for
|
||||||
|
consequential removal.
|
||||||
|
|
||||||
|
## Institutional Context Contract
|
||||||
|
|
||||||
|
Consequential objects and effects carry the relevant tenant, institution,
|
||||||
|
organization unit, function, mandate/jurisdiction, service/case/work item,
|
||||||
|
party/representation, decision, and record references. Context is minimized to
|
||||||
|
what the operation needs. Organizational membership is not itself permission
|
||||||
|
or mandate.
|
||||||
|
|
||||||
|
Events, automation intents, audit evidence, records, and external effects retain
|
||||||
|
the same governed context envelope or an exact reference to it. Consumers must
|
||||||
|
not reconstruct authority later from mutable current structures.
|
||||||
|
|
||||||
|
## Adoption Order
|
||||||
|
|
||||||
|
1. Inventory every domain list/detail/search/export/effect and classify all
|
||||||
|
four dimensions.
|
||||||
|
2. Migrate institutional owners first: Access, IDM, Organizations, Mandates,
|
||||||
|
Services, Parties, Cases, Approvals, Committee, Decisions, Voting, and
|
||||||
|
Records.
|
||||||
|
3. Migrate communication and content: Addresses, Distribution Lists, Campaign,
|
||||||
|
Postbox, Mail, Calendar, Files, Templates, and Forms Runtime.
|
||||||
|
4. Migrate data projections: Connectors, Datasources, Dataflow, Reporting,
|
||||||
|
Search, Risk Compliance, and Dashboard.
|
||||||
|
5. Migrate workflow/task/background/provider operations and prove that no
|
||||||
|
asynchronous path drops context.
|
||||||
|
6. Advance manifest claims only after owner tests and browser/reference-journey
|
||||||
|
evidence pass.
|
||||||
|
|
||||||
|
The generated platform inventory reports adoption counts and module details.
|
||||||
|
Gitea tracks individual migrations; the declaration is evidence and a maturity
|
||||||
|
gate, not a substitute for implementation.
|
||||||
|
|
||||||
|
## Definition Of Enforced
|
||||||
|
|
||||||
|
A dimension is `enforced` only when:
|
||||||
|
|
||||||
|
- all declared object types and public reads/effects use it;
|
||||||
|
- list/detail/count/search/export/worker behavior is consistent;
|
||||||
|
- cache and pagination semantics cannot cross contexts;
|
||||||
|
- absence, invalid values, and inaccessible referenced context fail safely;
|
||||||
|
- tests cover current, historical, unauthorized, replay, and module-absence
|
||||||
|
combinations appropriate to the dimension;
|
||||||
|
- user/admin documentation explains behavior and limitations;
|
||||||
|
- the manifest cites those tests and docs.
|
||||||
@@ -0,0 +1,162 @@
|
|||||||
|
# Institutional Context And Governed References
|
||||||
|
|
||||||
|
GovOPlaN consequential work must retain enough context to answer who acted,
|
||||||
|
for whom, through which function, under which mandate and jurisdiction, using
|
||||||
|
which rule and evidence versions, and with which requested and observed effect.
|
||||||
|
The shared contract lives in `govoplan_core.core.institutional`.
|
||||||
|
|
||||||
|
Core owns reference shapes and provider protocols only. It does not own shared
|
||||||
|
Mandate, Service, Party, Decision, evidence, or geography tables. Domain modules
|
||||||
|
own persistence and authorization; optional capabilities resolve the references.
|
||||||
|
Interactive reads use the separate platform temporal-data context documented in
|
||||||
|
`TEMPORAL_DATA_CONTEXT.md`; it never changes current authorization or supplies
|
||||||
|
mutation dates.
|
||||||
|
|
||||||
|
## Envelope
|
||||||
|
|
||||||
|
`GovernedContextEnvelope` version 1 carries:
|
||||||
|
|
||||||
|
- a tenant and `TemporalRevision` with validity, recording, supersession, and
|
||||||
|
change reason;
|
||||||
|
- the real account or service account and represented account, function,
|
||||||
|
procedure party, assignment, delegation/power, and mandate;
|
||||||
|
- institution, organization unit, function, task, mandate, jurisdiction,
|
||||||
|
service, case, party, work item, workflow, approval, decision, and record
|
||||||
|
references;
|
||||||
|
- versioned legal bases and evidence references;
|
||||||
|
- information classification, purposes, retention/holds, minimization, and
|
||||||
|
disclosure state;
|
||||||
|
- external-source authority, maturity, freshness, health, and conflict state;
|
||||||
|
- language, accessibility, channel, explanation, and availability references.
|
||||||
|
|
||||||
|
Every institutional reference includes the owner module, tenant, stable object
|
||||||
|
identity, optional version/effective instant, and a protected display label.
|
||||||
|
Cross-tenant references are rejected. Safe serialization omits labels,
|
||||||
|
inspection URLs, formal reasoning, operative results, and conditions unless a
|
||||||
|
caller explicitly requests the protected projection.
|
||||||
|
|
||||||
|
## Semantic Providers
|
||||||
|
|
||||||
|
The first provider-neutral capabilities are:
|
||||||
|
|
||||||
|
- `mandates.resolver`: resolve competence for a task/authority type at an
|
||||||
|
effective instant and return the governing Mandate definition and evidence;
|
||||||
|
- `services.definitions`: obtain versioned institutional service definitions;
|
||||||
|
- `parties.resolver`: obtain effective procedure-local parties and powers of
|
||||||
|
representation without copying Identity or Organizations subjects; and
|
||||||
|
- `decisions.registry`: record and retrieve formal Decisions under optimistic
|
||||||
|
revision control.
|
||||||
|
|
||||||
|
The Mandate, Service, Party/representation, and Decision DTOs have strict
|
||||||
|
mapping round-trips so they can cross capability, event, package, and storage
|
||||||
|
boundaries without shared ORM models. Their lifecycle states are explicit:
|
||||||
|
Mandates distinguish draft/active/suspended/replaced/retired, Services retain
|
||||||
|
publication state, Parties retain effective representation and revocation, and
|
||||||
|
Decisions retain correction, revocation, and supersession references.
|
||||||
|
|
||||||
|
The DTOs are a repository threshold, not a mandate to create four modules.
|
||||||
|
Independent persistence, lifecycle, security/operations behavior, release
|
||||||
|
reason, reuse, and tests are still required before extraction.
|
||||||
|
|
||||||
|
Mandate resolution is deterministic: Core filters candidates by tenant,
|
||||||
|
effective interval, active state, task and authority type, stable
|
||||||
|
organization/function identity, jurisdiction coverage, and subject type. A
|
||||||
|
result is competent only when exactly one matching Mandate remains and it has
|
||||||
|
no unresolved conflicts. Evidence from matching definitions is deduplicated
|
||||||
|
and retained in the explanation result. `revise_mandate_definition` applies
|
||||||
|
optimistic concurrency and the allowed activation, suspension, replacement,
|
||||||
|
and retirement transitions while leaving the previous revision immutable.
|
||||||
|
|
||||||
|
`revise_formal_decision` provides the equivalent lifecycle primitive for
|
||||||
|
formal outcomes. Every accepted transition requires a new recorded revision
|
||||||
|
and change reason, links `supersedes_ref` to the prior version, updates the
|
||||||
|
authority envelope to the new version, and records explicit correction or
|
||||||
|
revocation provenance. Terminal and backward transitions fail closed. Each
|
||||||
|
Decision also records whether responsibility was human, human-reviewed
|
||||||
|
automation, or an automated service account acting under mandate. Automation
|
||||||
|
preparation/recommendation references remain inspectable without being
|
||||||
|
mistaken for the responsible outcome.
|
||||||
|
|
||||||
|
Procedure-party corrections use `revise_procedure_party`: the stable party
|
||||||
|
identity is retained, a new revision and reason are required, stale writes are
|
||||||
|
rejected, and revoked/expired/superseded assignments are terminal.
|
||||||
|
`revoke_party_representation` separately records when a limited power ceased
|
||||||
|
to authorize actions. This allows consuming procedures to evaluate historical
|
||||||
|
delivery or representation authority without rewriting Identity,
|
||||||
|
Organizations, or Addresses records.
|
||||||
|
|
||||||
|
Service templates and package/tenant specializations use
|
||||||
|
`derive_service_restriction`. The derived definition retains an explicit
|
||||||
|
parent-version reference, cannot extend the parent's validity, audience,
|
||||||
|
channels, or publication ceiling, and cannot remove inherited prerequisites,
|
||||||
|
required evidence, legal bases, or bindings. This is the fail-closed semantic
|
||||||
|
rule; configuration-package signature and provenance checks remain the package
|
||||||
|
transport rule.
|
||||||
|
|
||||||
|
`ServiceAvailabilityRequirement` represents module, capability, mandate,
|
||||||
|
policy, connector, maintenance, audience, and configuration prerequisites with
|
||||||
|
an explicit unavailable-or-hidden failure mode and explanation reference. The
|
||||||
|
optional `services.availability` evaluator returns policy-scoped boolean
|
||||||
|
assessments, reason codes, and evidence. Unknown consequential requirements
|
||||||
|
fail closed; a reference itself never grants access.
|
||||||
|
|
||||||
|
## Service Launch
|
||||||
|
|
||||||
|
`ServiceLaunchRequest` and `ServiceLaunchResult` define the owner-neutral
|
||||||
|
boundary between Portal entry and a case, form, or workflow runtime effect.
|
||||||
|
The request carries the exact published Service definition, exact selected
|
||||||
|
binding, tenant, acting identity, timezone-aware request time, bounded
|
||||||
|
parameters, and idempotency key. The result must retain that exact Service and
|
||||||
|
binding, a same-tenant target reference, optional same-tenant evidence, and
|
||||||
|
only a relative or credential-free HTTP(S) destination.
|
||||||
|
|
||||||
|
`service_launch_capability(kind)` maps bindings to owner capabilities:
|
||||||
|
|
||||||
|
- `case` -> `cases.service_launcher`
|
||||||
|
- `form` -> `forms_runtime.service_launcher`
|
||||||
|
- `workflow` -> `workflow_engine.service_launcher`
|
||||||
|
|
||||||
|
`FormDefinition`, `FormFieldDefinition`, and `forms.definitions` provide the
|
||||||
|
owner-neutral exact-schema boundary used by Forms Runtime. Definitions carry an
|
||||||
|
exact tenant/revision, field types/options/constraints/defaults, publication,
|
||||||
|
draft, attachment, signature, policy, and handoff requirements. Forms owns
|
||||||
|
those immutable definitions; Forms Runtime persists instances and validation
|
||||||
|
evidence. A form Service binding uses `<form-id>/<revision>` and the launcher
|
||||||
|
rejects missing, superseded, unpublished, cross-tenant, or invalid definitions.
|
||||||
|
|
||||||
|
Portal may discover and invoke those capabilities but cannot write owner
|
||||||
|
tables. The owner must revalidate its definition/binding and current
|
||||||
|
authorization, produce its normal audit/event state, and make replay after an
|
||||||
|
ambiguous response safe. If the capability is absent, the service is
|
||||||
|
explainably unavailable. URL-only entries pass through the same launch-time
|
||||||
|
availability check and destination validation. Forms Runtime now supplies the
|
||||||
|
definition-aware form launcher when both Forms and Forms Runtime are active;
|
||||||
|
otherwise Portal continues to fail closed.
|
||||||
|
|
||||||
|
## Propagation
|
||||||
|
|
||||||
|
`PlatformEvent`, `ActionExecutionRequest`, and `AuditEvent` can carry the
|
||||||
|
envelope. Audit persistence stores only its safe projection; platform-event
|
||||||
|
outbox serialization preserves it across asynchronous delivery. A module must
|
||||||
|
not invent a parallel context dictionary when the shared fields apply.
|
||||||
|
|
||||||
|
## First Proof
|
||||||
|
|
||||||
|
Committee's `committee.decision_path` capability is the first bounded proof. It
|
||||||
|
requires one effective, conflict-free Mandate covering the organization unit
|
||||||
|
function, and jurisdiction, an approval reference, fact evidence, versioned legal bases,
|
||||||
|
operative result, and reasoning. It emits a reconstructable `FormalDecision`,
|
||||||
|
including requested/observed effects and information governance. If a Decision
|
||||||
|
registry is installed it persists there; Committee does not take ownership of
|
||||||
|
the generic Decision lifecycle.
|
||||||
|
|
||||||
|
## Compatibility And Security
|
||||||
|
|
||||||
|
- Contract version changes follow Core compatibility policy.
|
||||||
|
- Unknown tenant or reference-kind combinations fail closed.
|
||||||
|
- Datetimes that affect authority must be timezone-aware.
|
||||||
|
- Protected labels, reasoning, evidence inspection links, and source details
|
||||||
|
remain subject to the owning module's access policy.
|
||||||
|
- References do not grant access to their targets.
|
||||||
|
- Evidence and audit payloads must contain stable references/checksums, not
|
||||||
|
plaintext secrets.
|
||||||
@@ -0,0 +1,53 @@
|
|||||||
|
# Core Interface Pattern Migration
|
||||||
|
|
||||||
|
This document records the Core-owned part of the product-wide interface
|
||||||
|
pattern-language rollout. The normative product grammar and complete route
|
||||||
|
inventory live in the `govoplan` meta repository. Core owns reusable behavior;
|
||||||
|
domain modules own their compositions.
|
||||||
|
|
||||||
|
## Core Surfaces
|
||||||
|
|
||||||
|
| Surface | Pattern | Consequence and provenance contract | Evidence |
|
||||||
|
| --- | --- | --- | --- |
|
||||||
|
| User settings | Two-zone settings workspace with typed controls and unsaved-change protection | Save actions distinguish busy, unchanged, and test-in-progress states; contextual help resolves through Docs or the hosted fallback | `SettingsPage.tsx`, `test-core-interface-patterns.mjs` |
|
||||||
|
| Reusable credentials | Repeated administration with an adaptive create/edit dialog, optional password generator, and destructive confirmation | Secret values are write-only; generated candidates use the browser cryptographic API without a weak fallback and do not replace the field until explicitly confirmed; scope/permission blockers name the required action, responsible actor, and destination; unavailable row actions remain keyboard-explainable | `CredentialEnvelopeManager.tsx`, shared `PasswordField`, `PasswordGeneratorDialog`, `ActionBlockerHint`, `Button`, `TableActionGroup`, and `ConfirmDialog` |
|
||||||
|
| Retention policy | Effective-policy editor with inherited source paths and typed, narrowing-only controls | Parent locks and missing write authority are explicit; the save action distinguishes locks, missing target, loading, clean draft, and active save | `RetentionPolicyManagement.tsx`, policy logic tests, `test-core-interface-patterns.mjs` |
|
||||||
|
| Module lifecycle | Guided operator projection over durable installer-queue evidence | Preflight, handoff, progress, stale evidence, recovery, and rollback consequences remain visible | Admin module lifecycle tests and the Core installer-queue contract |
|
||||||
|
| Shared page frame | Domain-neutral headed page layout used by Core and optional modules | Standalone, workspace, and embedded modes make inset and scroll ownership explicit; sticky heading, rich descriptions, route actions, notices, loading, narrow-layout collapse, and contextual-help identity are centralized; composite administration workspaces may delegate the visible heading to their contributed panel while retaining the same frame; `AdminPageLayout` composes the contract | `PageLayout.tsx`, `page-layout.test.tsx`, Core Settings, Access administration, Docs, Mail bounce processing, Dashboard, Ops, Campaign, and `check-shared-webui-layouts.py` |
|
||||||
|
| Full-canvas workspace | Navigation/content and list/detail canvases that own pane geometry and scrolling | Navigation and split variants, primary-pane width, pane-owned or contained scrolling, responsive stacking or navigation collapse, pane labels, and contextual-help identity are centralized without encoding domain navigation | `WorkspaceLayout.tsx`, `workspace-layout.test.tsx`, Core Settings, Access administration, Docs, Organizations, Campaign, Templates, Approvals, and `check-shared-webui-layouts.py`; the raw-workspace exception baseline is empty |
|
||||||
|
| Full-height module frame | Outer module landmark and viewport/container sizing | `WorkspaceFrame` centralizes surface, overflow, box sizing, accessible naming, help identity, and application-viewport height so modules do not copy the `100vh - shell` frame | `WorkspaceFrame.tsx`, `layout-primitives.test.tsx`, Dataflow, Workflow, Datasources, Distribution Lists, Notifications, Tasks, Scheduling, Forms, Portal, Projects, Records, and Reporting |
|
||||||
|
| Responsive action toolbar | Domain-neutral action and filter grouping for pages, workspaces, editors, and overlays | Density, surface, grouping, flexible space, accessible naming, toolbar help identity, and responsive wrapping are centralized while modules retain action wording, authority, and consequence | `ActionToolbar.tsx`, `layout-primitives.test.tsx`, WYSIWYG, Calendar, Files, Forms, Templates, and the product-wide primitive check |
|
||||||
|
| Semantic page and pane action bars | Overview, collection, detail, editor, and workspace intent declared independently from frame geometry; full-canvas panes add workspace/collection/detail/editor scope | Core renders leading Reload from a guarded descriptor; editor persistence owns clean, dirty, invalid, saving, failed, and conflict feedback plus guarded Discard and far-right Save; destructive actions occupy an explicit named boundary; read-only surfaces do not invent Save | `PageActionBar.tsx`, `WorkspaceActionBar.tsx`, `PAGE_LAYOUT_USAGE_GUIDELINES.md`, component and browser conformance, every headed page and full-canvas workspace, and the discovery-based `check-shared-webui-layouts.py` |
|
||||||
|
| Catalogue and state composition | Search/filter bars, selectable navigation lists, count badges, and empty/blocked/error panels | Width, surface, wrap, selection geometry, title/description truncation, numeric emphasis, state sizing, tone and action placement are centralized; modules retain query behavior, object state and consequences | `FilterBar.tsx`, `SelectionList.tsx`, `CountBadge.tsx`, `StatePanel.tsx`, `layout-primitives.test.tsx`, and list/detail modules across Cases, Committee, Dataflow, Forms, Notifications, Portal, Postbox, Projects, Records, Reporting, Tasks, Templates, and Workflow |
|
||||||
|
| Content and form grids | Equal-column content, field, and native-form geometry | Explicit 1–4 columns, standard gaps, item spans, alignment, and named narrow/workspace/standard/wide collapse points replace generic and module-prefixed copies; unequal domain tracks remain local | `ContentGrid.tsx`, `layout-primitives.test.tsx`, Core dashboard/settings/mail, Calendar dialogs, Forms editor, Datasources, Postbox, Campaign, administration surfaces, and the product-wide primitive check |
|
||||||
|
| Content sections | Repeated editor/detail section surfaces | Border, surface, compact/default density, stacked flow and block rhythm are centralized without encoding section contents | `ContentSection.tsx`, `layout-primitives.test.tsx`, Datasources, Distribution Lists, Templates, Dataflow, and Workflow |
|
||||||
|
| Form sections | Reusable heading/description/action/content grouping inside forms | Plain, separated, and panel variants centralize hierarchy and narrow action placement without moving validation, permissions, values, or domain wording into Core | `FormSection.tsx`, `layout-primitives.test.tsx`, Addresses contact editing, and Quick Access preferences |
|
||||||
|
| Metric groups and drill-downs | Reusable responsive grouping around metric cards with an explicit optional detail affordance | Fixed one-to-five and auto-fit columns, minimum card widths, density, block/inset/zero spacing, and named collapse points replace the product-wide `metric-grid` class and cross-module dashboard overrides; typed link or in-page drill-downs name their destination while summary-only, non-enumerable, derived, or privacy-suppressed values remain inert | `MetricGrid.tsx`, `MetricCard.tsx`, `metric-card.test.tsx`, `layout-primitives.test.tsx`, Core and Dashboard summaries, administration, Campaign, Ops, Files, Search, and dashboard widgets |
|
||||||
|
| Description lists | Semantic property and fact presentation | Stacked and inline variants, one-to-five list columns, density, term width, wrapping, and responsive collapse replace both `admin-details-grid` and `detail-list`; `DescriptionItem` preserves native `dt`/`dd` anatomy | `DescriptionList.tsx`, `layout-primitives.test.tsx`, Access and Tenancy administration, Audit, Policy, Campaign reports/imports, Docs, Settings, Ops, and Reporting |
|
||||||
|
| Dialog anatomy | Shared outer dialog plus composable body and footer regions | Size and administration variants, body padding, descriptions, notices, fixed action wrapping, native form flow, and section grouping are centralized; focus trapping and stack lifecycle remain unchanged | `Dialog.tsx`, `DialogAnatomy.tsx`, `dialog-focus.test.tsx`, `layout-primitives.test.tsx`, Addresses, Calendar, Records, Datasources, Distribution Lists, Files, and Templates |
|
||||||
|
| Definition-editor visuals | Reusable graph palette, canvas chrome, node icon/port geometry, empty overlay and floating activity state | Core owns visual and responsive anatomy while node/edge types, validation, execution, provenance and workflow semantics remain in Dataflow or Workflow | `DefinitionPalette.tsx`, `DefinitionNodeIcon.tsx`, `FloatingStatus.tsx`, shared definition styles, Dataflow and Workflow structure/build checks |
|
||||||
|
| Shared configuration primitives | Cross-module component contract | Dialog focus, blocker structure, disabled-action focus, route/page/field/action F1 help, unsaved changes, confirmation, loading, alerts, problem lists, and policy provenance are centralized | Core component tests, `CONTEXTUAL_HELP_CONTRACT.md`, and module-permutation build |
|
||||||
|
|
||||||
|
## Boundary
|
||||||
|
|
||||||
|
Files and Mail are the first two external consumers of the layered
|
||||||
|
server/credential/policy pattern. Their own repositories retain provider
|
||||||
|
discovery, transport behavior, authorization, and migration evidence. Remaining
|
||||||
|
module surfaces are tracked by bounded module-owned issues under GovOPlaN #11;
|
||||||
|
they are not reasons to add sibling-private behavior to Core.
|
||||||
|
|
||||||
|
Raw JSON remains permitted only for diagnostics, expert inspection,
|
||||||
|
interchange, or conflict evidence. It is not a primary Core configuration
|
||||||
|
editor.
|
||||||
|
|
||||||
|
New headed pages use `PageLayout`; full-canvas modules use `WorkspaceFrame`
|
||||||
|
and, where applicable, `WorkspaceLayout`, so Core owns the frame and pane
|
||||||
|
scrolling. Module CSS continues to own unequal domain content layout, never the
|
||||||
|
shared page, workspace, toolbar, state, list, filter, metric, section, or graph
|
||||||
|
chrome. Retired copies and module-local component definitions are rejected by
|
||||||
|
`check-shared-webui-primitives.py`. That check also requires standard dialog
|
||||||
|
widths to use `Dialog size` and keeps every remaining domain-specific width in
|
||||||
|
a reviewed, decrease-only exception baseline. The companion layout check now
|
||||||
|
has zero raw page-frame and zero raw workspace exceptions, discovers semantic
|
||||||
|
consumers without a hand-maintained route list, requires semantic action bars
|
||||||
|
on `WorkspaceFrame` routes, and rejects ad-hoc panel-header toolbars.
|
||||||
@@ -0,0 +1,118 @@
|
|||||||
|
# Localization And Contextual Help Quality
|
||||||
|
|
||||||
|
## Reference Language
|
||||||
|
|
||||||
|
German (`de`) is GovOPlaN's first-class reference target. Every translation key
|
||||||
|
used by a shipped WebUI must exist in German and English. German completeness is
|
||||||
|
a release gate; English remains the source-code fallback language so existing
|
||||||
|
literal labels and external developer APIs do not change semantics.
|
||||||
|
|
||||||
|
New installations and tenants default to German. Existing system, tenant, and
|
||||||
|
user preferences are preserved. The available-language and policy model can
|
||||||
|
still select another default or disable a package at the relevant scope.
|
||||||
|
|
||||||
|
Explicit high-risk help content and browser acceptance are tracked in
|
||||||
|
[Core #284](https://git.add-ideas.de/GovOPlaN/govoplan-core/issues/284).
|
||||||
|
|
||||||
|
The platform inventory recognizes both inline locale objects and generated
|
||||||
|
catalogs declared as `const de` / `const en`. Its strict mode requires both
|
||||||
|
locales and reports `de` explicitly as the reference locale.
|
||||||
|
|
||||||
|
## Structured Documentation Localization
|
||||||
|
|
||||||
|
`DocumentationTopic.translations` continues to own localized title, summary,
|
||||||
|
and body prose. Topics whose metadata contains rendered prose opt into the
|
||||||
|
separate `structured_translation_version="1"` contract and provide a complete
|
||||||
|
same-shape value for each translated metadata key in
|
||||||
|
`structured_translations`. Version 1 covers workflow prerequisites, steps,
|
||||||
|
outcome, result and verification; reference fields; limitations, constraints,
|
||||||
|
consequences and consequence classes; and the other rendered explanation
|
||||||
|
fields declared by Core.
|
||||||
|
|
||||||
|
The registry rejects an unversioned translation, an unsupported contract
|
||||||
|
version, missing structured keys, changed object keys or list lengths, empty
|
||||||
|
translated strings, and changed non-text values. Stable field IDs, routes,
|
||||||
|
permission scopes, and other technical leaves therefore remain structurally
|
||||||
|
bound to the source metadata. The Docs module overlays only a validated locale
|
||||||
|
at response time and reports the selected structured locale separately from the
|
||||||
|
title/body locale. Missing structured translations fall back to source content
|
||||||
|
and remain visible in public coverage until the owning module adopts the
|
||||||
|
contract.
|
||||||
|
|
||||||
|
## Help Resolution
|
||||||
|
|
||||||
|
Every focusable field and action receives a stable derived F1 identity from the
|
||||||
|
shared shell, even when the component has no dedicated help text. Resolution
|
||||||
|
falls back from field/action to dialog or page and then to the module's visible
|
||||||
|
documentation baseline.
|
||||||
|
|
||||||
|
Backend manifests publish explicit topic associations first. Core additionally
|
||||||
|
associates declared route, navigation, settings, and View surface IDs with the
|
||||||
|
module's static user or administrator documentation baseline. Feature modules
|
||||||
|
should still add exact `metadata.help_contexts` entries for consequential,
|
||||||
|
unfamiliar, policy-controlled, destructive, security-sensitive, or legally
|
||||||
|
meaningful fields and actions.
|
||||||
|
|
||||||
|
The shared retention-policy editor exposes explicit contexts for each stored
|
||||||
|
data category, audit-detail control, lower-level override switch, target
|
||||||
|
selector, reload, and save action. The Policy module owns the matching German
|
||||||
|
administrator guidance. Retention execution surfaces use separate contexts for
|
||||||
|
dry-run, destructive apply, confirmation, and outcome review so F1 opens the
|
||||||
|
consequence and recovery guidance closest to the focused control.
|
||||||
|
Shared controls may set `helpModuleId` when their documentation owner differs
|
||||||
|
from the containing page; the retention editor uses this to resolve Policy help
|
||||||
|
from both administration and Campaign surfaces.
|
||||||
|
|
||||||
|
The shared reusable-credential manager keeps Access as its documentation owner
|
||||||
|
and publishes exact contexts for credential kind, secret replacement/removal,
|
||||||
|
module and server restrictions, lower-scope visibility, activation, save, and
|
||||||
|
irreversible deletion. This ensures F1 explains secret custody and the effect on
|
||||||
|
dependent connections from system, tenant, group, user, and personal surfaces.
|
||||||
|
|
||||||
|
The source inventory treats literal `helpContextId` and
|
||||||
|
`data-help-context-id` declarations as authored help associations, including a
|
||||||
|
native control nested in `FormField`. Dynamic context expressions remain
|
||||||
|
separate evidence and generic derived fallbacks remain in the richer-help
|
||||||
|
candidate queue.
|
||||||
|
|
||||||
|
The generated `help_review_candidates` list is therefore a content-depth queue,
|
||||||
|
not a list of controls on which F1 cannot work. It should prioritize:
|
||||||
|
|
||||||
|
1. effect, deletion, delivery, retention, disclosure, encryption, and recovery;
|
||||||
|
2. identity, representation, mandate, institutional context, and purpose;
|
||||||
|
3. valid-time versus recorded-time selection;
|
||||||
|
4. provider authority, synchronization, conflict, and outcome unknown;
|
||||||
|
5. fields whose consequences are not evident from their label.
|
||||||
|
|
||||||
|
The shared browser conformance journey mounts the production Help menu and
|
||||||
|
resolver. It proves that F1 uses the focused control rather than only the page,
|
||||||
|
maps an exact retention action to Policy-owned administrator documentation,
|
||||||
|
retains the page context as fallback for derived actions, exposes an accessible
|
||||||
|
modal at narrow widths, closes with Escape, and restores focus to the triggering
|
||||||
|
control. Module journeys should add their own exact high-risk mappings; they do
|
||||||
|
not need to reimplement the keyboard or dialog mechanics.
|
||||||
|
|
||||||
|
## Verification
|
||||||
|
|
||||||
|
```bash
|
||||||
|
cd /mnt/DATA/git/govoplan
|
||||||
|
/mnt/DATA/git/govoplan/.venv/bin/python \
|
||||||
|
tools/inventory/platform-interface-inventory.py \
|
||||||
|
--strict --strict-declarations --strict-endpoints
|
||||||
|
```
|
||||||
|
|
||||||
|
The check must report:
|
||||||
|
|
||||||
|
- reference locale `de` present and complete;
|
||||||
|
- no used key missing from `de` or `en`;
|
||||||
|
- every field has a resolvable F1 context;
|
||||||
|
- no duplicate stable IDs;
|
||||||
|
- no undeclared public WebUI surface;
|
||||||
|
- no stale runtime route or endpoint declaration.
|
||||||
|
|
||||||
|
Browser acceptance is part of the focused workspace gate and can be run alone:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
cd /mnt/DATA/git/govoplan-core/webui
|
||||||
|
npm run test:conformance
|
||||||
|
```
|
||||||
+320
-7
@@ -13,6 +13,10 @@ Policy decision, source provenance, and explain-response contracts are tracked
|
|||||||
in [`POLICY_CONTRACTS.md`](POLICY_CONTRACTS.md).
|
in [`POLICY_CONTRACTS.md`](POLICY_CONTRACTS.md).
|
||||||
The experimental remote WebUI bundle loading design is tracked in
|
The experimental remote WebUI bundle loading design is tracked in
|
||||||
[`REMOTE_WEBUI_BUNDLES.md`](REMOTE_WEBUI_BUNDLES.md).
|
[`REMOTE_WEBUI_BUNDLES.md`](REMOTE_WEBUI_BUNDLES.md).
|
||||||
|
The cross-product semantic layers, source-authority modes, and candidate
|
||||||
|
Mandates, Services, Parties, and Decisions boundaries are canonical in the
|
||||||
|
meta repository's
|
||||||
|
[`INSTITUTIONAL_GOVERNANCE_TARGET_ARCHITECTURE.md`](../../govoplan/docs/architecture/INSTITUTIONAL_GOVERNANCE_TARGET_ARCHITECTURE.md).
|
||||||
|
|
||||||
## Layer Model
|
## Layer Model
|
||||||
|
|
||||||
@@ -24,6 +28,36 @@ The experimental remote WebUI bundle loading design is tracked in
|
|||||||
| Business modules | Public-sector workflows | campaigns, cases, forms, approvals, appointments |
|
| Business modules | Public-sector workflows | campaigns, cases, forms, approvals, appointments |
|
||||||
| Connector modules | External system integration | FIT-Connect, XÖV/XTA, DMS/eAkte, ERP, IDM |
|
| Connector modules | External system integration | FIT-Connect, XÖV/XTA, DMS/eAkte, ERP, IDM |
|
||||||
|
|
||||||
|
This table is the technical composition model. The product portfolio uses a
|
||||||
|
more detailed institutional layer model, but it does not change dependency
|
||||||
|
direction: Core provides contracts and composition; modules own semantics;
|
||||||
|
packages compose modules.
|
||||||
|
|
||||||
|
## Institutional Semantic Boundaries
|
||||||
|
|
||||||
|
Cross-module references must keep these answers distinct:
|
||||||
|
|
||||||
|
- Organizations owns where structures, units, and functions exist.
|
||||||
|
- Identity owns who a subject is; Access owns accounts, roles, permissions,
|
||||||
|
and authorization decisions; IDM owns effective function assignments.
|
||||||
|
- A Mandates capability will answer why a unit or function is competent for a
|
||||||
|
task, jurisdiction, subject, or period. It must not become another RBAC
|
||||||
|
system.
|
||||||
|
- A Services capability will own versioned institutional service definitions;
|
||||||
|
Portal presents and starts them.
|
||||||
|
- A Parties capability will own procedure-local participant roles,
|
||||||
|
representation, and delivery authority; it must reference rather than copy
|
||||||
|
Identity, Organizations, and Addresses subjects.
|
||||||
|
- A Decisions capability will own formal institutional outcomes and their
|
||||||
|
authority, facts, rules, reasoning, effects, correction, and review.
|
||||||
|
Approvals owns review gates, Committee owns deliberation/votes, and Workflow
|
||||||
|
Engine owns coordination.
|
||||||
|
|
||||||
|
Start each missing concept as a versioned DTO/provider contract used by a
|
||||||
|
bounded journey. A repository is justified only when the concept gains
|
||||||
|
independent persistence, lifecycle, security/operations behavior, release
|
||||||
|
reason, and reuse. Core must not store these domain objects.
|
||||||
|
|
||||||
## Kernel Responsibilities
|
## Kernel Responsibilities
|
||||||
|
|
||||||
The kernel target owns:
|
The kernel target owns:
|
||||||
@@ -98,6 +132,11 @@ The following contracts are the baseline API that modules can rely on:
|
|||||||
- navigation metadata contract
|
- navigation metadata contract
|
||||||
- command/event envelope contract
|
- command/event envelope contract
|
||||||
- policy decision and source provenance contract in `govoplan_core.core.policy`
|
- policy decision and source provenance contract in `govoplan_core.core.policy`
|
||||||
|
- external object reference and integration-maturity contract in
|
||||||
|
`govoplan_core.core.external_references`
|
||||||
|
- action/effect preview and execution contract in
|
||||||
|
`govoplan_core.core.automation`
|
||||||
|
- workflow definition contribution and runtime-worker contracts
|
||||||
|
|
||||||
Changes to these contracts must be versioned or accompanied by compatibility shims.
|
Changes to these contracts must be versioned or accompanied by compatibility shims.
|
||||||
|
|
||||||
@@ -115,6 +154,30 @@ may extend the kernel by adding explicit contracts, but existing contracts must
|
|||||||
remain source-compatible through the 0.1.x split line unless a migration shim
|
remain source-compatible through the 0.1.x split line unless a migration shim
|
||||||
and deprecation note are provided.
|
and deprecation note are provided.
|
||||||
|
|
||||||
|
### Architecture Metadata
|
||||||
|
|
||||||
|
`ModuleManifest.architecture` is the backward-compatible, versioned product-
|
||||||
|
portfolio declaration for:
|
||||||
|
|
||||||
|
- module kind and institutional architecture layer;
|
||||||
|
- evidence-backed maturity claim (`concept`, `scaffold`, `vertical_slice`,
|
||||||
|
`reference_ready`, `supported`, or `lts`);
|
||||||
|
- owned and explicitly non-owned concepts;
|
||||||
|
- supported source-authority modes;
|
||||||
|
- reference packages, tested providers, and known limits;
|
||||||
|
- migration, upgrade, recovery, security, operations, and documentation
|
||||||
|
evidence references.
|
||||||
|
|
||||||
|
Core validates the claim and all provider references during registry startup.
|
||||||
|
`reference_ready`, `supported`, and `lts` claims require a named reference
|
||||||
|
package and the cumulative evidence set; target-tested providers additionally
|
||||||
|
require provider evidence. A supported module with migrations must include
|
||||||
|
migration evidence. Signed release catalogs retain and revalidate the
|
||||||
|
declaration. The meta manifest check validates repository evidence paths and
|
||||||
|
provides an opt-in `--require-architecture` rollout gate. Platform metadata,
|
||||||
|
Docs, and Ops project the same declaration. A module cannot make itself
|
||||||
|
supported solely by changing its maturity string.
|
||||||
|
|
||||||
Known access-related capability names are defined in
|
Known access-related capability names are defined in
|
||||||
`govoplan_core.core.access`, including:
|
`govoplan_core.core.access`, including:
|
||||||
|
|
||||||
@@ -144,12 +207,41 @@ Other stable runtime capabilities currently include:
|
|||||||
|
|
||||||
- `identity.directory` and `identity.search`
|
- `identity.directory` and `identity.search`
|
||||||
- `organizations.directory`
|
- `organizations.directory`
|
||||||
- `idm.directory`
|
- `idm.directory`, `idm.function_assignments`, `idm.relationships`, and
|
||||||
- `calendar.outbox` and `calendar.scheduling`
|
`idm.assignment_lifecycle`
|
||||||
|
- `calendar.outbox`, `calendar.scheduling`, `calendar.invitations`, and
|
||||||
|
`calendar.externalProfiles`
|
||||||
- `poll.scheduling`
|
- `poll.scheduling`
|
||||||
- `notifications.dispatch`
|
- `notifications.dispatch`
|
||||||
|
- `application_status.projection`
|
||||||
|
- `payments.requests`
|
||||||
- `workflow.definitionContributions` and `workflow.runtimeWorker`
|
- `workflow.definitionContributions` and `workflow.runtimeWorker`
|
||||||
|
|
||||||
|
`calendar.scheduling` keeps workflow modules independent of Calendar-owned
|
||||||
|
models and transport adapters. Consumers may create tentative events, promote
|
||||||
|
the selected event in place, and release unused events idempotently. The
|
||||||
|
provider returns bounded external-delivery and outbox references so consumers
|
||||||
|
can retain retry state without copying Calendar's synchronization internals.
|
||||||
|
|
||||||
|
`application_status.projection` lets a presentation module resolve the tenant
|
||||||
|
and display or request access to an owner-supplied, deliberately bounded
|
||||||
|
applicant-status view. The provider retains policy, authorization, token, and
|
||||||
|
record ownership; consumers must not query provider tables or enlarge the
|
||||||
|
projection.
|
||||||
|
|
||||||
|
`payments.requests` carries replay-safe payment obligations and evidence-bound
|
||||||
|
manual reconciliation across module boundaries. Procedure modules identify the
|
||||||
|
source Case or Workflow in the command and retain the returned payment ID;
|
||||||
|
Payments remains authoritative for amount, currency, state, transaction
|
||||||
|
reference, and reconciliation evidence. Ledger, invoice, and external payment
|
||||||
|
providers remain separate follow-on contracts.
|
||||||
|
|
||||||
|
The provider-neutral `idm.relationships` contract carries tenant-scoped typed
|
||||||
|
groups, effective-dated identity relationships, and explicit membership
|
||||||
|
decisions. It deliberately does not expose IDM persistence models or imply an
|
||||||
|
Access permission. Consumers can retain source revisions and inclusion or
|
||||||
|
exclusion provenance while remaining optional-module safe.
|
||||||
|
|
||||||
Modules contribute reusable process baselines through
|
Modules contribute reusable process baselines through
|
||||||
`ModuleManifest.workflow_definitions`. Each contribution pins its origin module
|
`ModuleManifest.workflow_definitions`. Each contribution pins its origin module
|
||||||
and version, stable key, schema and content hash, native graph/BPMN content,
|
and version, stable key, schema and content hash, native graph/BPMN content,
|
||||||
@@ -180,11 +272,52 @@ intended for SemVer major-version lines. Missing optional interfaces are
|
|||||||
allowed, but an installed provider with an incompatible version blocks
|
allowed, but an installed provider with an incompatible version blocks
|
||||||
activation because the integration would otherwise bind to an unsafe API.
|
activation because the integration would otherwise bind to an unsafe API.
|
||||||
|
|
||||||
|
### Source Authority And Provider Operations
|
||||||
|
|
||||||
|
Integration maturity and configured authority are independent. The existing
|
||||||
|
external-reference maturity ladder describes whether an adapter can discover,
|
||||||
|
link, search, read, publish, synchronize, migrate, or replace. A binding must
|
||||||
|
also state whether GovOPlaN is native authoritative, the external system is
|
||||||
|
authoritative, GovOPlaN keeps a mirror, both sides use governed sync, GovOPlaN
|
||||||
|
adds only a governance overlay, or the object is link-only.
|
||||||
|
|
||||||
|
`ModuleManifest.external_providers` composes existing contracts rather than
|
||||||
|
replacing them. Each declaration describes owned object/field groups, authority modes,
|
||||||
|
operations, revisions, freshness, health, limits, idempotency, conflicts,
|
||||||
|
outcome-unknown handling, evidence, correction/compensation, reconciliation,
|
||||||
|
outage behavior, classification, purpose, retention, and secret requirements.
|
||||||
|
Core owns the typed declaration and validation. Connectors and domain modules
|
||||||
|
own the actual protocol and domain behavior; configuration packages select the
|
||||||
|
effective mode and block missing/incompatible/unhealthy providers; Docs and Ops
|
||||||
|
explain the result. Effect-capable declarations fail validation unless their
|
||||||
|
retry, concurrency, outcome-unknown, correction, reconciliation, evidence,
|
||||||
|
audit, timeout, outage, classification, purpose, retention, and secret behavior
|
||||||
|
is explicit.
|
||||||
|
|
||||||
|
Declarations are release-time capability claims. Configured state is projected
|
||||||
|
separately through `ModuleManifest.external_provider_state_providers`. A state
|
||||||
|
provider receives a bounded tenant context and returns one sanitized observation
|
||||||
|
per configured binding: stable binding reference, effective authority mode,
|
||||||
|
active/configured state, health, freshness, conflict, recovery readiness,
|
||||||
|
observation/last-success time, and scalar metrics. Core validates and aggregates
|
||||||
|
those observations, isolates provider failures, and never accepts URLs,
|
||||||
|
credentials, or arbitrary nested metadata as runtime-state fields. Docs removes
|
||||||
|
binding-level detail from ordinary-user projections; Ops may show the full
|
||||||
|
sanitized operator projection.
|
||||||
|
|
||||||
|
Configuration-package preflight selects the exact requested binding from this
|
||||||
|
runtime state before evaluating authority, health, freshness, and recovery. A
|
||||||
|
healthy sibling binding therefore cannot mask an unhealthy required binding.
|
||||||
|
Providers with multiple configurations must use non-secret, stable references
|
||||||
|
such as `calendar:sync-source:<id>`.
|
||||||
|
|
||||||
Current named interfaces, generated from the source manifests by the workspace
|
Current named interfaces, generated from the source manifests by the workspace
|
||||||
contract checks, are:
|
contract checks, are:
|
||||||
|
|
||||||
- `addresses.contact_writer`, `addresses.lookup`, `addresses.recipient_source`
|
- `addresses.contact_point_resolution`, `addresses.contact_writer`,
|
||||||
- `calendar.outbox`, `calendar.scheduling`
|
`addresses.lookup`, `addresses.recipient_source`
|
||||||
|
- `calendar.external_profiles`, `calendar.invitations`, `calendar.outbox`,
|
||||||
|
`calendar.scheduling`
|
||||||
- `campaigns.access`, `campaigns.delivery_tasks`,
|
- `campaigns.access`, `campaigns.delivery_tasks`,
|
||||||
`campaigns.mail_policy_context`, `campaigns.policy_context`,
|
`campaigns.mail_policy_context`, `campaigns.policy_context`,
|
||||||
`campaigns.retention`
|
`campaigns.retention`
|
||||||
@@ -193,6 +326,8 @@ contract checks, are:
|
|||||||
- `files.access`, `files.campaign_attachments`
|
- `files.access`, `files.campaign_attachments`
|
||||||
- `mail.campaign_delivery`
|
- `mail.campaign_delivery`
|
||||||
- `notifications.dispatch`
|
- `notifications.dispatch`
|
||||||
|
- `application_status.projection`
|
||||||
|
- `payments.requests`
|
||||||
- `poll.availability_matrix`, `poll.option_selection`,
|
- `poll.availability_matrix`, `poll.option_selection`,
|
||||||
`poll.response_collection`, `poll.signed_participation`,
|
`poll.response_collection`, `poll.signed_participation`,
|
||||||
`poll.workflow_context`
|
`poll.workflow_context`
|
||||||
@@ -593,6 +728,46 @@ Rules:
|
|||||||
one migration run, and do not switch a database between tracks unless it is a
|
one migration run, and do not switch a database between tracks unless it is a
|
||||||
disposable development database.
|
disposable development database.
|
||||||
|
|
||||||
|
### Shared State And Runtime Ordering
|
||||||
|
|
||||||
|
Multi-host application roles use the `shared` state profile. In that profile,
|
||||||
|
PostgreSQL, Redis, a stable installation identifier, and S3-compatible object
|
||||||
|
storage are mandatory. Module durable artifacts must use Core's object-storage
|
||||||
|
contract and module-owned opaque key namespaces; node-local paths are limited
|
||||||
|
to temporary materialization. Same-host replicas may use the `host-shared`
|
||||||
|
profile and one shared volume.
|
||||||
|
|
||||||
|
Only the migration command mutates schema. PostgreSQL migration runs acquire a
|
||||||
|
deployment-wide advisory lock before module pre-tasks, Alembic, and post-tasks.
|
||||||
|
API, worker, and scheduler roles wait for exact configured migration heads and
|
||||||
|
fail closed instead of applying migrations during startup.
|
||||||
|
|
||||||
|
Runtime roles register identity, software/module composition, queues, heartbeat,
|
||||||
|
and drain state in PostgreSQL. Singleton work must use a distributed lease and
|
||||||
|
validate its monotonically increasing fencing token at the consequential
|
||||||
|
commit. See `STATE_AND_RECOVERY_CONTRACT.md` for the complete contract.
|
||||||
|
|
||||||
|
### Recovery Evidence
|
||||||
|
|
||||||
|
Operations spanning transactions, object storage, queues, or external systems
|
||||||
|
must choose an explicit Core recovery mode: atomic, compensation,
|
||||||
|
snapshot-restore, forward-recovery, or irreversible. Plans require verification
|
||||||
|
steps and mode-specific recovery material. Use idempotency keys, append-only
|
||||||
|
evidence checkpoints, and a runtime fence where work may race across nodes.
|
||||||
|
|
||||||
|
The recovery ledger is a shared primitive, not automatic coverage. A module may
|
||||||
|
claim its guarantees only after its operation records preconditions before side
|
||||||
|
effects, transitions partial/unknown outcomes honestly, and records verified
|
||||||
|
completion or recovery. Plaintext secrets must never enter recovery metadata or
|
||||||
|
evidence.
|
||||||
|
|
||||||
|
For a conclusive external result, modules may commit their local success
|
||||||
|
projection and the verified terminal checkpoint in one database transaction via
|
||||||
|
`DurableRecoveryOperation.commit_verified_success`. This does not make the
|
||||||
|
external provider effect atomic. It prevents a local `succeeded` state from
|
||||||
|
becoming authoritative when the recovery evidence chain is damaged or the
|
||||||
|
terminal checkpoint cannot commit.
|
||||||
|
|
||||||
## Install, Uninstall, And Catalogs
|
## Install, Uninstall, And Catalogs
|
||||||
|
|
||||||
Core owns the install plan, signed catalog validation, license entitlement
|
Core owns the install plan, signed catalog validation, license entitlement
|
||||||
@@ -682,12 +857,34 @@ the shared loading and retryable error state around route rendering. The
|
|||||||
initial static import closure and largest asynchronous chunk are enforced by
|
initial static import closure and largest asynchronous chunk are enforced by
|
||||||
the budgets documented in [WEBUI_BUNDLE_BUDGETS.md](WEBUI_BUNDLE_BUDGETS.md).
|
the budgets documented in [WEBUI_BUNDLE_BUDGETS.md](WEBUI_BUNDLE_BUDGETS.md).
|
||||||
|
|
||||||
|
Every public platform interface has a stable declaration identity. Backend
|
||||||
|
routes, capabilities, interfaces, search providers/sources, permissions,
|
||||||
|
frontend routes/navigation, and View surfaces derive that identity from typed
|
||||||
|
`ModuleManifest` values. Typed WebUI capabilities declare IDs for settings,
|
||||||
|
admin sections, widgets, search contexts, and extension actions. Shared form
|
||||||
|
and action controls accept `interfaceId` and `helpTopicId`; use module-namespaced
|
||||||
|
values when another contract, documentation topic, or automated check must
|
||||||
|
refer to the control across source changes. The static inventory assigns a
|
||||||
|
line-independent source anchor when an explicit ID is absent and reports that
|
||||||
|
fact for later review.
|
||||||
|
|
||||||
|
Core exposes the sanitized runtime declaration set at
|
||||||
|
`GET /api/v1/platform/interface-catalog`. The endpoint is read-only, requires
|
||||||
|
`admin:module:read` or `system:settings:read`, and includes only modules
|
||||||
|
effective in the caller's active tenant context. It never serializes factories,
|
||||||
|
credentials, executable callbacks, or mutable module state. Registry validation
|
||||||
|
rejects conflicting declaration IDs before startup.
|
||||||
|
|
||||||
WebUI modules receive only the core route context:
|
WebUI modules receive only the core route context:
|
||||||
|
|
||||||
- `settings`
|
- `settings`
|
||||||
- `auth`
|
- `auth`
|
||||||
|
|
||||||
A module should call its own API client and module-owned backend routes. Shared API helpers should live in core only when they are truly platform-level concerns.
|
A module should call its own API client and module-owned backend routes. Shared API helpers should live in core only when they are truly platform-level concerns.
|
||||||
|
For ordinary JSON mutations, use Core's `apiPostJson` and `apiPatchJson`
|
||||||
|
helpers. They preserve the shared authentication, CSRF, error, and request
|
||||||
|
invalidation behavior while leaving endpoint types and feature semantics in the
|
||||||
|
owning module.
|
||||||
|
|
||||||
Modules can also contribute named UI capabilities for explicit extension
|
Modules can also contribute named UI capabilities for explicit extension
|
||||||
points. Capability values must be narrow, typed contracts, not imports from a
|
points. Capability values must be narrow, typed contracts, not imports from a
|
||||||
@@ -870,6 +1067,16 @@ Decision: templates and reporting are separate modules.
|
|||||||
and export targets
|
and export targets
|
||||||
- report permissions, report execution history, generated report evidence, and
|
- report permissions, report execution history, generated report evidence, and
|
||||||
report-specific retention inputs
|
report-specific retention inputs
|
||||||
|
|
||||||
|
Cross-module reports use Core's versioned
|
||||||
|
`reporting.report_provider.<provider-id>` contract. Source modules own
|
||||||
|
authorization, parameters, source revisions, effective scope, result schema,
|
||||||
|
and privacy transforms; Reporting owns discovery, validation, governed
|
||||||
|
execution, provenance, export history, and the global `/reports` route. The
|
||||||
|
optional `policy.reporting_governance` capability can only tighten execution,
|
||||||
|
retention, export, and re-identification-risk handling. Reporting exposes
|
||||||
|
`reporting.retention` so the Policy-owned retention run can minimize expired
|
||||||
|
provider results without importing Reporting models.
|
||||||
- downstream export handoff to files, dataflow, connectors, or publication
|
- downstream export handoff to files, dataflow, connectors, or publication
|
||||||
surfaces
|
surfaces
|
||||||
|
|
||||||
@@ -962,7 +1169,7 @@ from workflow semantics.
|
|||||||
- form definitions, schemas, validation rules, field visibility rules,
|
- form definitions, schemas, validation rules, field visibility rules,
|
||||||
localization, versioning, admin editing, and reusable form package fragments
|
localization, versioning, admin editing, and reusable form package fragments
|
||||||
|
|
||||||
`govoplan-forms-runtime` owns, when implemented:
|
`govoplan-forms-runtime` owns:
|
||||||
|
|
||||||
- public/internal submissions, drafts, submitted values, validation evidence,
|
- public/internal submissions, drafts, submitted values, validation evidence,
|
||||||
attachment references, submission receipts, and handoff events
|
attachment references, submission receipts, and handoff events
|
||||||
@@ -975,6 +1182,16 @@ Boundary:
|
|||||||
- Reporting/dataflow may consume submitted data through governed DTOs or
|
- Reporting/dataflow may consume submitted data through governed DTOs or
|
||||||
source lifecycle contracts.
|
source lifecycle contracts.
|
||||||
|
|
||||||
|
Implemented contract:
|
||||||
|
|
||||||
|
- Core owns the provider-neutral `FormDefinition`/`FormFieldDefinition` DTOs.
|
||||||
|
- Forms persists immutable exact definitions and provides `forms.definitions`.
|
||||||
|
- Forms Runtime resolves that capability, persists revisioned instances and
|
||||||
|
events, validates draft/final values, and provides
|
||||||
|
`forms_runtime.service_launcher`.
|
||||||
|
- Portal delegates exact `<form-id>/<revision>` bindings and never writes either
|
||||||
|
owner's tables.
|
||||||
|
|
||||||
### OpenDesk Integration Profile
|
### OpenDesk Integration Profile
|
||||||
|
|
||||||
Tracking: `govoplan-core#195`, `govoplan-connectors#5`,
|
Tracking: `govoplan-core#195`, `govoplan-connectors#5`,
|
||||||
@@ -1063,6 +1280,61 @@ devserver, development bootstrap, background worker registry, and migration
|
|||||||
metadata plan all read the saved desired state from `system_settings` before
|
metadata plan all read the saved desired state from `system_settings` before
|
||||||
building their module registry.
|
building their module registry.
|
||||||
|
|
||||||
|
### Tenant entitlement and personal visibility
|
||||||
|
|
||||||
|
Deployment activation remains process-wide: one installed and active registry
|
||||||
|
is shared by every tenant served by that process. Tenant module selection is a
|
||||||
|
separate entitlement document in `core_scopes.settings.module_entitlements`:
|
||||||
|
|
||||||
|
- a system policy marks each installed module `unavailable`, `available`, or
|
||||||
|
`forced` for one tenant;
|
||||||
|
- the tenant selection may enable or disable only available modules;
|
||||||
|
- protected platform modules, forced modules, and transitive dependencies stay
|
||||||
|
effective;
|
||||||
|
- malformed explicit entitlement fails closed to protected modules, while an
|
||||||
|
absent document preserves the pre-entitlement behavior for upgraded tenants;
|
||||||
|
- an optimistic revision prevents concurrent system and tenant administrators
|
||||||
|
from silently replacing each other's changes.
|
||||||
|
|
||||||
|
The authenticated platform metadata and module route guard intersect global
|
||||||
|
runtime activation with the active tenant's effective entitlement. Entitlement
|
||||||
|
does not grant a permission. Access authorization must still allow every API
|
||||||
|
operation and resource.
|
||||||
|
|
||||||
|
The same boundary applies outside authenticated request handling:
|
||||||
|
|
||||||
|
- capability factories retain their owning module, and tenant-scoped capability
|
||||||
|
lookup treats a provider that is unavailable to the tenant as absent;
|
||||||
|
- workers partition scheduled scans by tenant before claiming rows;
|
||||||
|
- new work is rejected while a module is unavailable, while already accepted
|
||||||
|
durable work remains in provider-owned storage and is reported as
|
||||||
|
`operator_action_required` instead of being dropped or executed;
|
||||||
|
- Workflow, Dataflow, event consumers, reconciliation jobs, and external-effect
|
||||||
|
outboxes run inside a tenant execution context, so their optional capability
|
||||||
|
calls inherit the same provider checks;
|
||||||
|
- public signed-link modules declare a `public_tenant_resolver`; valid token
|
||||||
|
context is resolved before the route runs and the module entitlement is then
|
||||||
|
enforced without requiring an authenticated principal.
|
||||||
|
|
||||||
|
Entitlement resolution uses a bounded process-local cache. A local policy
|
||||||
|
mutation invalidates its tenant entry immediately; changes made by another node
|
||||||
|
become authoritative after `TENANT_MODULE_ENTITLEMENT_CACHE_TTL_SECONDS`
|
||||||
|
(five seconds by default). This is a bounded staleness optimization, not an
|
||||||
|
authorization grant: a cache miss or resolution failure fails closed.
|
||||||
|
|
||||||
|
Users and groups do not own another module-runtime state. Every WebUI module
|
||||||
|
already contributes a root `<module>.module` View surface, so personal and
|
||||||
|
group module visibility is expressed through Views. View policy controls who
|
||||||
|
may select, assign, edit, derive, or workflow-activate those projections;
|
||||||
|
required View assignments can retain required UI. Thus tenant entitlement owns
|
||||||
|
operational availability, Views own presentation, and Access owns authority.
|
||||||
|
|
||||||
|
Capability-style modules such as Encryption must keep activation separate from
|
||||||
|
domain data state. Making Encryption effective only exposes its capability and
|
||||||
|
administration surfaces. Encrypting, rekeying, decrypting, or migrating data is
|
||||||
|
an explicit versioned protection-policy operation owned by Encryption and the
|
||||||
|
module that owns the data.
|
||||||
|
|
||||||
Hot enable/disable is a core design principle for every module:
|
Hot enable/disable is a core design principle for every module:
|
||||||
|
|
||||||
- Core keeps one mutable active `PlatformRegistry` object and swaps its manifest
|
- Core keeps one mutable active `PlatformRegistry` object and swaps its manifest
|
||||||
@@ -1128,8 +1400,10 @@ The package install-plan API records operator intent only:
|
|||||||
- `GET /api/v1/admin/system/modules/package-catalog` reads approved package
|
- `GET /api/v1/admin/system/modules/package-catalog` reads approved package
|
||||||
references from `GOVOPLAN_MODULE_PACKAGE_CATALOG` so operators can add known
|
references from `GOVOPLAN_MODULE_PACKAGE_CATALOG` so operators can add known
|
||||||
module refs to the install plan without typing them manually. The endpoint
|
module refs to the install plan without typing them manually. The endpoint
|
||||||
also reports catalog validity, channel, signature, trust state, and the
|
also reports catalog validity, channel, signature, trust state, source and
|
||||||
configured path.
|
artifact provenance, release availability, configuration requirements, and
|
||||||
|
per-entry compatibility/blocker state. Withdrawn entries are visible for
|
||||||
|
diagnosis but cannot be planned.
|
||||||
- `POST /api/v1/admin/system/modules/install-plan/catalog/{module_id}` saves
|
- `POST /api/v1/admin/system/modules/install-plan/catalog/{module_id}` saves
|
||||||
a planned install or update row from a validated catalog entry. Installed
|
a planned install or update row from a validated catalog entry. Installed
|
||||||
modules are planned as updates. Catalog signature and approved-channel policy
|
modules are planned as updates. Catalog signature and approved-channel policy
|
||||||
@@ -1170,6 +1444,11 @@ The package install-plan API records operator intent only:
|
|||||||
default; successful uninstalls are removed from saved startup state by default.
|
default; successful uninstalls are removed from saved startup state by default.
|
||||||
Use `--no-activate-installed-modules` or
|
Use `--no-activate-installed-modules` or
|
||||||
`--keep-uninstalled-modules-in-desired` only for staged rollout workflows.
|
`--keep-uninstalled-modules-in-desired` only for staged rollout workflows.
|
||||||
|
- Every non-dry installer and live active-graph mutation acquires the
|
||||||
|
deployment-wide `core:module-lifecycle:deployment` lease and records a Core
|
||||||
|
recovery operation. Unresolved effects block later lifecycle changes. The
|
||||||
|
operation modes and operator reconciliation contract are defined in
|
||||||
|
`MODULE_LIFECYCLE_RECOVERY.md`.
|
||||||
- `govoplan-module-installer --supervise --migrate --health-url http://127.0.0.1:8000/health --restart-command '<restart govoplan server>'`
|
- `govoplan-module-installer --supervise --migrate --health-url http://127.0.0.1:8000/health --restart-command '<restart govoplan server>'`
|
||||||
is the preferred disruptive-change path. It applies the plan, optionally runs
|
is the preferred disruptive-change path. It applies the plan, optionally runs
|
||||||
migrations in a fresh Python process after a fresh-process manifest
|
migrations in a fresh Python process after a fresh-process manifest
|
||||||
@@ -1219,6 +1498,13 @@ the same restart/health set after restoring package and database snapshots.
|
|||||||
The installer preflight is intentionally conservative:
|
The installer preflight is intentionally conservative:
|
||||||
|
|
||||||
- maintenance mode must be active;
|
- maintenance mode must be active;
|
||||||
|
- the `shared` state profile blocks in-place package mutation; clustered
|
||||||
|
installations must roll one verified immutable module composition across all
|
||||||
|
replicas;
|
||||||
|
- official runtime images carry the full verified package profile, while the
|
||||||
|
desired module graph controls activation and tenant/View/Policy contracts
|
||||||
|
control availability and presentation; package lifecycle must not be reused
|
||||||
|
as a tenant or user visibility switch;
|
||||||
- installed module manifests must be compatible with the supported manifest
|
- installed module manifests must be compatible with the supported manifest
|
||||||
contract and current core version;
|
contract and current core version;
|
||||||
- uninstalling `tenancy`, `access`, or `admin` is blocked;
|
- uninstalling `tenancy`, `access`, or `admin` is blocked;
|
||||||
@@ -1319,6 +1605,33 @@ The first implementation is a platform access gate. It does not replace
|
|||||||
database backups, process supervision, migration checks, or external load
|
database backups, process supervision, migration checks, or external load
|
||||||
balancer maintenance pages.
|
balancer maintenance pages.
|
||||||
|
|
||||||
|
## Connector Runtime Contract
|
||||||
|
|
||||||
|
Core defines provider-neutral connector preview and diagnostic primitives in
|
||||||
|
`govoplan_core.core.connector_runtime`. The contract keeps optional modules
|
||||||
|
decoupled: Connectors owns transport, endpoint discovery, retries, and protocol
|
||||||
|
health; the consuming domain module owns mappings, validation, reconciliation,
|
||||||
|
and mutations of its records.
|
||||||
|
|
||||||
|
Every dry run is bounded and identifies the source revision, source fingerprint,
|
||||||
|
immutable input hash, effects, and redacted diagnostics. Its summary must match
|
||||||
|
the returned effect list exactly. An apply token is usable only when the preview
|
||||||
|
is complete, current, conflict-free, and contains no error diagnostic. Endpoint
|
||||||
|
URLs never contain credentials; only credential-envelope references cross the
|
||||||
|
contract. Provider-specific details belong in sanitized provenance rather than
|
||||||
|
in a shared domain schema.
|
||||||
|
|
||||||
|
## Semantic Documentation Subject Contract
|
||||||
|
|
||||||
|
Optional modules expose configured artifacts that can be documented through
|
||||||
|
the module-scoped `documentation.semantic_subjects.<module_id>` capability.
|
||||||
|
Core supplies stable tenant-scoped references, typed nested anchors, safe
|
||||||
|
localized descriptors, revision/fingerprint review signals, and explicit
|
||||||
|
availability states. Providers remain responsible for authorization and do not
|
||||||
|
expose configuration payloads or credentials. Docs discovers the capability
|
||||||
|
and owns authored content; it does not import feature internals. See
|
||||||
|
`SEMANTIC_DOCUMENTATION_SUBJECTS.md` for the contract and adoption rules.
|
||||||
|
|
||||||
## Build And Verification
|
## Build And Verification
|
||||||
|
|
||||||
Backend verification from core:
|
Backend verification from core:
|
||||||
|
|||||||
@@ -0,0 +1,66 @@
|
|||||||
|
# Module Lifecycle Recovery
|
||||||
|
|
||||||
|
## Migration Revision Namespace
|
||||||
|
|
||||||
|
All enabled module migration directories are assembled into one Alembic graph. Revision IDs are therefore global across Core and every module even though each module owns a separate `migrations/versions` directory. Core validates literal revision declarations before constructing the graph and rejects duplicates with both file paths. A module must assign a new globally unique revision ID; reusing another module's ID can otherwise make Alembic treat an unrelated schema change as already applied or report an ancestor/head overlap.
|
||||||
|
|
||||||
|
When correcting a collision that has already reached a database, first verify the schema objects that identify which migration actually ran. Rename the unapplied migration, or transactionally translate the corresponding `alembic_version` row when the applied owner is unambiguous. Never add both colliding IDs as heads or blindly stamp the database.
|
||||||
|
|
||||||
|
Package changes and live module-graph changes use Core's durable recovery
|
||||||
|
ledger. The local `install.lock` still prevents duplicate work in one runtime
|
||||||
|
directory; the database lease `core:module-lifecycle:deployment` is the
|
||||||
|
deployment-wide authority across API, installer, worker, and scheduler nodes.
|
||||||
|
|
||||||
|
## Declared Boundaries
|
||||||
|
|
||||||
|
| Operation | Recovery mode | Completion condition |
|
||||||
|
| --- | --- | --- |
|
||||||
|
| `module-lifecycle.pre-migration` | compensation | package, WebUI, manifest, and desired-graph evidence match |
|
||||||
|
| `module-lifecycle.post-migration` | forward recovery | migration tasks, manifests, desired graph, restart, and health are verified |
|
||||||
|
| `module-retirement.destroy-data` | snapshot restore | a hashed, restore-checked backup exists and retirement state is verified |
|
||||||
|
| `module-runtime.apply-graph` | compensation | hooks, capability contexts, active graph, and workflow contributions match |
|
||||||
|
|
||||||
|
The installer prepares the recovery operation before it captures the database
|
||||||
|
snapshot. A full database restore therefore retains the prepared operation and
|
||||||
|
its fence instead of erasing the fact that a mutation was attempted. Backup
|
||||||
|
artifacts are hashed and sized before any package, migration, or retirement
|
||||||
|
effect starts.
|
||||||
|
|
||||||
|
Every command boundary records the command source and canonical hashes of the
|
||||||
|
redacted command/result records. Credentials, database URLs, command output,
|
||||||
|
and package-registry secrets are never copied into recovery evidence.
|
||||||
|
|
||||||
|
## Failure And Retry Rules
|
||||||
|
|
||||||
|
- A conclusive failure before effects is terminal `failed`.
|
||||||
|
- A command or compensatable effect that started but did not complete is
|
||||||
|
`recovery_required`.
|
||||||
|
- A lost or unexpected outcome after a migration/external boundary is
|
||||||
|
`outcome_unknown`.
|
||||||
|
- A verified package/database rollback becomes `recovered`.
|
||||||
|
- A supervised install becomes `succeeded` only after restart and all configured
|
||||||
|
health probes succeed.
|
||||||
|
|
||||||
|
An unresolved lifecycle operation blocks every later lifecycle mutation on the
|
||||||
|
same deployment fence, even after its execution lease is released. Operators
|
||||||
|
must inspect the checkpoint chain and run record, restore or complete the
|
||||||
|
declared recovery path, and explicitly reconcile the operation. A new install
|
||||||
|
must not be used as an implicit retry.
|
||||||
|
|
||||||
|
Live graph changes use the same fence. A non-migrating hook or registry failure
|
||||||
|
restores the prior in-process graph and records verified compensation. A failure
|
||||||
|
after migrations begin remains unresolved because restoring the process-local
|
||||||
|
registry does not reverse database schema effects.
|
||||||
|
|
||||||
|
## Operator Evidence
|
||||||
|
|
||||||
|
The installer run record contains the recovery operation id, mode, plan hash,
|
||||||
|
and current lifecycle status. The Ops recovery view is authoritative for the
|
||||||
|
durable state and evidence-chain result. Keep both the run directory and the
|
||||||
|
state-service backup evidence until the operation is terminal and the normal
|
||||||
|
retention policy permits removal.
|
||||||
|
|
||||||
|
Run the module installer rollback drill and recovery-runtime test matrix before
|
||||||
|
enabling lifecycle mutation in a new deployment. Shared-state deployments must
|
||||||
|
still use immutable release images; the ledger does not make in-place package
|
||||||
|
mutation across replicas safe.
|
||||||
@@ -0,0 +1,158 @@
|
|||||||
|
# Page Layout and Action Guidelines
|
||||||
|
|
||||||
|
This document defines the binding composition grammar for headed GovOPlaN
|
||||||
|
pages. Core owns the reusable anatomy; each module owns its domain actions,
|
||||||
|
wording, authorization, consequences, and data state.
|
||||||
|
|
||||||
|
## Required Page Frame
|
||||||
|
|
||||||
|
- Use `PageLayout` for every headed standalone, workspace, or embedded page.
|
||||||
|
- Declare exactly one semantic `archetype`; do not infer page intent from the
|
||||||
|
`mode`, which controls geometry and scroll ownership only.
|
||||||
|
- Use `WorkspaceFrame` for a full-height module surface and
|
||||||
|
`WorkspaceLayout` only where navigation/content or list/detail panes are
|
||||||
|
genuinely part of the interaction.
|
||||||
|
- Put page-wide feedback in `PageLayout` notices. Use `DismissibleAlert` for a
|
||||||
|
recoverable warning or failure and `StatePanel` when the entire surface is
|
||||||
|
loading, empty, unavailable, or blocked.
|
||||||
|
- Do not reproduce shared page padding, heading, toolbar, form-grid, section,
|
||||||
|
table, dialog, or breakpoint CSS in a module.
|
||||||
|
|
||||||
|
## Product Side Rail
|
||||||
|
|
||||||
|
Module manifests contribute stable navigation surface identifiers, labels,
|
||||||
|
paths, icons, and default order. Core owns the side-rail composition and the
|
||||||
|
shared `NavigationPreferenceEditor`; modules must not fork this editor or
|
||||||
|
persist their own rail ordering.
|
||||||
|
|
||||||
|
Navigation preferences are layered in this order: module defaults, system,
|
||||||
|
tenant, then user. Each higher layer may reorder or change visibility. System
|
||||||
|
and tenant administrators may lock an entry visible; a lower layer can still
|
||||||
|
move that entry, but cannot hide it. Personal preferences cannot create locks.
|
||||||
|
An unset preference inherits the complete lower layer, while “Use inherited
|
||||||
|
order” removes the current layer rather than copying its values. Unknown item
|
||||||
|
identifiers remain harmless so uninstalling, disabling, or later reinstalling
|
||||||
|
a module does not corrupt the rail.
|
||||||
|
|
||||||
|
The platform module response projects module, system, and tenant layer states
|
||||||
|
alongside the effective user state. Editors must initialize from the layer
|
||||||
|
immediately below the scope they edit, so a system or tenant administrator's
|
||||||
|
personal preference is never promoted accidentally. Preference saves refresh
|
||||||
|
the platform module projection. View policy, permissions, and tenant module
|
||||||
|
entitlements remain independent final visibility gates; changing rail
|
||||||
|
preferences never grants access.
|
||||||
|
|
||||||
|
## Semantic Page Archetypes
|
||||||
|
|
||||||
|
| Archetype | Use when |
|
||||||
|
| --- | --- |
|
||||||
|
| `overview` | The page summarizes health, metrics, or several peer areas without owning one primary collection or draft. |
|
||||||
|
| `collection` | The primary object is a searchable/listable collection and Create, when available, applies to that collection. |
|
||||||
|
| `detail` | The page primarily presents one record, report, or immutable projection. |
|
||||||
|
| `editor` | The page owns one explicit draft with Save and Discard behavior. |
|
||||||
|
| `workspace` | The page coordinates several panes, stages, or task-local operations that cannot honestly be reduced to one record or draft. |
|
||||||
|
|
||||||
|
The archetype remains stable for the current interaction. A page may switch
|
||||||
|
from `overview` to `editor` when the user explicitly enters configuration
|
||||||
|
mode. It must not call a page an editor merely because a dialog or an inline
|
||||||
|
filter is editable.
|
||||||
|
|
||||||
|
## Page Action Rules
|
||||||
|
|
||||||
|
Pass one `PageActionBar` to the `PageLayout` `actions` slot. Full-canvas
|
||||||
|
workspaces use the same contract through `WorkspaceActionBar`, with an explicit
|
||||||
|
`workspace`, `collection-pane`, `detail-pane`, or `editor-pane` scope. The
|
||||||
|
variant makes the surface's intent inspectable and preserves the same keyboard
|
||||||
|
and visual order across modules. `ActionToolbar` remains the lower-level
|
||||||
|
component for section-local controls; it is not a substitute for a semantic
|
||||||
|
page or pane action bar.
|
||||||
|
|
||||||
|
| Page kind | Leading group | Trailing group |
|
||||||
|
| --- | --- | --- |
|
||||||
|
| Overview | Reload when refreshable, then context | Help, then ordinary primary actions |
|
||||||
|
| Collection | Reload when refreshable, then collection context such as export | Help, then Create at the far right |
|
||||||
|
| Detail | Reload when refreshable, then object context | Help, ordinary primary actions, then a separated destructive group |
|
||||||
|
| Editor | Reload only when refresh is a distinct safe operation, then context | Dirty state, Help, ordinary primary actions, separated destructive actions, Discard, then Save at the far right |
|
||||||
|
| Workspace | Reload when the coordinated projection can become stale, then task context | Help, ordinary primary actions, then a separated destructive group |
|
||||||
|
|
||||||
|
Reload means re-fetch or re-evaluate the current surface. A page declaring
|
||||||
|
`refreshable` must provide it, and a non-refreshable page must not use Reload as
|
||||||
|
a synonym for Cancel, Reset, or Discard. Reload never silently destroys a dirty
|
||||||
|
draft. Create is a collection-wide action and is not duplicated in a
|
||||||
|
persistent side panel. Save is present only where the page owns an editable
|
||||||
|
draft; a read-only detail page must not display a disabled or inert Save merely
|
||||||
|
to fill the slot.
|
||||||
|
|
||||||
|
Editor bars always keep Discard and Save visible. Their required `state`
|
||||||
|
projection is one of `clean`, `dirty`, `invalid`, `saving`, `save-failed`, or
|
||||||
|
`conflict`, and the central component announces it through a live status label.
|
||||||
|
Clean and saving states disable both persistence actions; invalid disables Save
|
||||||
|
while retaining Discard. Failed saves and conflicts keep the draft recoverable
|
||||||
|
and allow an authorized retry after the module has shown the owning error or
|
||||||
|
conflict evidence. A module may add a more specific validation, policy, or
|
||||||
|
permission blocker. The editor must register its draft with
|
||||||
|
`useUnsavedDraftGuard` (or a shared hook that uses the same registration
|
||||||
|
contract), so browser unload, route navigation, section changes, Reload, and
|
||||||
|
the explicit Discard path cannot silently lose work.
|
||||||
|
|
||||||
|
Reload is rendered by Core from a descriptor rather than passed as arbitrary
|
||||||
|
button markup. It can project `current`, `stale`, `reloading`, or
|
||||||
|
`reload-failed`; `loading` is the shorthand for `reloading`. A failed refresh
|
||||||
|
must preserve usable loaded data, expose its stale/failure state, and leave
|
||||||
|
Reload available for recovery. Reload goes through the same unsaved-navigation
|
||||||
|
guard as route changes.
|
||||||
|
|
||||||
|
Destructive page actions use `destructiveActions`; never put a danger action in
|
||||||
|
`contextActions` or the ordinary primary group. Core renders a persistent
|
||||||
|
visual and semantic boundary before this group. In an editor it precedes the
|
||||||
|
Discard/Save pair, keeping Save in the final keyboard and visual position.
|
||||||
|
|
||||||
|
`PageActionBar` controls non-editor placement and owns the standard editor
|
||||||
|
persistence buttons. Other actions continue to use central
|
||||||
|
`Button`, `IconButton`, or `TableActionGroup` components. When an action is
|
||||||
|
visible but unavailable because of permission, target, policy, state, or
|
||||||
|
validation, keep it in its stable slot and supply `disabledReason`. Do not
|
||||||
|
silently hide a normally applicable action.
|
||||||
|
|
||||||
|
## Forms and Dialogs
|
||||||
|
|
||||||
|
- Compose forms from `FormLayout`/`FormGrid`, `FormSection`, and `FormField`.
|
||||||
|
- Use `FieldLabel` through `FormField` for every field that is not genuinely
|
||||||
|
self-explanatory; record justified omissions in the owning UI ledger.
|
||||||
|
- Use `Dialog`, `DialogForm`, `DialogSection`, and `DialogActions` for modal
|
||||||
|
work. A dialog can be domain-specific while its anatomy remains central.
|
||||||
|
- Use `useUnsavedDraftGuard` for explicit Discard and guarded navigation on an
|
||||||
|
editable page or dialog.
|
||||||
|
- Explain irreversible or operationally consequential actions before the
|
||||||
|
commit button, including reversibility and durable evidence.
|
||||||
|
|
||||||
|
## Collections and Details
|
||||||
|
|
||||||
|
- Use `FilterBar` for collection query controls and `DataGrid` for tabular
|
||||||
|
collections. Keep a single ordered `TableActionGroup` action set per table.
|
||||||
|
- Use `MetricGrid`/`MetricCard` for summary measures, `Card` or
|
||||||
|
`ContentSection` for logical sections, and `DescriptionList` for labelled
|
||||||
|
facts.
|
||||||
|
- Add a `MetricCard.drilldown` only when the displayed measure has a useful,
|
||||||
|
authorized underlying collection or detail. Name the destination explicitly
|
||||||
|
(for example, “Review failed deliveries”) and preserve the current scope and
|
||||||
|
filters in its `href` or action. The card itself remains non-interactive so
|
||||||
|
the action is visible and keyboard-predictable. Derived, privacy-suppressed,
|
||||||
|
non-enumerable, or purely informational aggregates remain plain metrics;
|
||||||
|
when an ordinarily available drill-down is temporarily blocked, keep its
|
||||||
|
action and provide `disabledReason`.
|
||||||
|
- Preserve loaded data after a refresh failure and mark it stale; offer Reload
|
||||||
|
as the recovery action. Distinguish initial loading, empty, unavailable,
|
||||||
|
permission-blocked, conflict, success, and retry states.
|
||||||
|
|
||||||
|
## Review Evidence
|
||||||
|
|
||||||
|
Every new or changed page or workspace pane must have structural evidence for
|
||||||
|
its frame, semantic archetype/scope and slot order, refresh declaration, shared
|
||||||
|
component usage, stable disabled actions, dirty guard, destructive boundary,
|
||||||
|
and module-owned help identity. Type checks enforce conditional Reload and
|
||||||
|
editor persistence props. The product check discovers all consumers, rejects
|
||||||
|
undeclared archetypes and `ActionToolbar` panel-header copies, and requires
|
||||||
|
semantic actions for every `WorkspaceFrame` route. Browser conformance confirms
|
||||||
|
keyboard order, lifecycle changes, accessibility, destructive separation,
|
||||||
|
narrow wrapping, and screenshot geometry.
|
||||||
@@ -14,6 +14,7 @@ consistent while each module still owns its domain rules.
|
|||||||
| Governance defaults | `govoplan-admin` plus `govoplan-access` materializer | admin settings, governance template routes, access materialization capability | System governance can block tenant-local groups, roles, and API keys. |
|
| Governance defaults | `govoplan-admin` plus `govoplan-access` materializer | admin settings, governance template routes, access materialization capability | System governance can block tenant-local groups, roles, and API keys. |
|
||||||
| Delegation and ownership policy | access/campaign/mail/files modules | capability checks and owner-scoped APIs | Source provenance should use this contract when policies become externally explainable. |
|
| Delegation and ownership policy | access/campaign/mail/files modules | capability checks and owner-scoped APIs | Source provenance should use this contract when policies become externally explainable. |
|
||||||
| Definition governance | `govoplan-policy` | capability `policy.definitionGovernance` | Resolves view, edit, run/start, reuse, derive, and automate for system, tenant, group, and user Dataflow/Workflow definitions. |
|
| Definition governance | `govoplan-policy` | capability `policy.definitionGovernance` | Resolves view, edit, run/start, reuse, derive, and automate for system, tenant, group, and user Dataflow/Workflow definitions. |
|
||||||
|
| Function assignment governance | `govoplan-policy` | capability `policy.functionAssignmentGovernance` | Returns current review steps, delegation depth/validity ceilings, and explicit timed-escalation targets consumed by IDM. |
|
||||||
|
|
||||||
## Policy Decision
|
## Policy Decision
|
||||||
|
|
||||||
@@ -126,6 +127,43 @@ When the capability is absent, modules must not silently emulate cross-scope
|
|||||||
inheritance. Their conservative fallback is limited to local tenant
|
inheritance. Their conservative fallback is limited to local tenant
|
||||||
definitions and disables reuse, derivation, and automation.
|
definitions and disables reuse, derivation, and automation.
|
||||||
|
|
||||||
|
## Function Assignment Delegation And Escalation
|
||||||
|
|
||||||
|
`FunctionAssignmentGovernanceDecision` is the versioned cross-module contract
|
||||||
|
for request/grant review. In addition to the required holder, authority, and
|
||||||
|
recipient steps, it returns `delegation_allowed`,
|
||||||
|
`maximum_delegation_depth`, `maximum_delegated_validity_days`, and typed
|
||||||
|
`FunctionAssignmentEscalationRule` entries. Each escalation entry binds one
|
||||||
|
review step to an exact target function and timeout.
|
||||||
|
|
||||||
|
The decision is a current ceiling, not durable authorization. IDM must recheck
|
||||||
|
the complete assignment-source chain and all recorded decisions before final
|
||||||
|
application. An elapsed timeout creates explicit state and evidence; it must
|
||||||
|
never be interpreted as approval or as permission to silently substitute an
|
||||||
|
approver. Missing providers, malformed rules, invalid chains, or tightened
|
||||||
|
limits fail closed with an explainable reason.
|
||||||
|
|
||||||
|
## Bounded Impact-Subject Providers
|
||||||
|
|
||||||
|
Policy impact previews discover optional subject providers through capability
|
||||||
|
names beginning with `policy.impactSubjects.`. The suffix is the stable
|
||||||
|
provider ID; for example, Views contributes `policy.impactSubjects.views`.
|
||||||
|
Providers implement `PolicyImpactSubjectProvider` and receive a
|
||||||
|
`PolicyImpactPopulationRequest` containing the active tenant, policy family,
|
||||||
|
an explicit selector, actor scopes, detail-disclosure decision, and a limit of
|
||||||
|
at most 500. They return `PolicyImpactSubjectBatch` with unique opaque subject
|
||||||
|
references and an explicit `complete`, `sampled`, `truncated`, or `unavailable`
|
||||||
|
state. An unavailable batch must explain the gap, and a total may never be
|
||||||
|
smaller than the returned subject count.
|
||||||
|
|
||||||
|
Core does not scan module data or evaluate domain policy. The owning module
|
||||||
|
selects and permission-filters its candidates; Policy compares the current and
|
||||||
|
proposed decisions and controls response disclosure. A caller must select one
|
||||||
|
or more provider populations explicitly. This preserves optional-module
|
||||||
|
boundaries and prevents a seemingly harmless preview from becoming an
|
||||||
|
unbounded platform query. Providers must not include credentials, secrets, or
|
||||||
|
unfiltered cross-tenant labels in subject attributes.
|
||||||
|
|
||||||
## Frontend Contract
|
## Frontend Contract
|
||||||
|
|
||||||
Policy UIs must:
|
Policy UIs must:
|
||||||
@@ -138,6 +176,9 @@ Policy UIs must:
|
|||||||
lower-level limit to `false`
|
lower-level limit to `false`
|
||||||
- avoid sending locked fields or re-enable attempts in save payloads
|
- avoid sending locked fields or re-enable attempts in save payloads
|
||||||
- show inherited values separately from local overrides
|
- show inherited values separately from local overrides
|
||||||
|
- require a current impact preview before enabling a governed high-impact save,
|
||||||
|
preserve its proposal hash on commit, and explain incomplete population
|
||||||
|
coverage rather than presenting unavailable providers as zero impact
|
||||||
|
|
||||||
The core WebUI helper `privacyRetentionParentAllowsField()` centralizes the
|
The core WebUI helper `privacyRetentionParentAllowsField()` centralizes the
|
||||||
field-lock decision used by the retention editor and its lightweight module
|
field-lock decision used by the retention editor and its lightweight module
|
||||||
|
|||||||
@@ -1,9 +1,12 @@
|
|||||||
# Postbox End-To-End Encryption Architecture
|
# Postbox End-To-End Encryption Architecture
|
||||||
|
|
||||||
This document records the strategic encryption target for GovOPlaN postboxes.
|
This document records the encryption boundary for GovOPlaN postboxes. Postbox
|
||||||
It does not require the first postbox implementation to ship full E2EE, but it
|
now implements the server-side contracts for three selectable profiles:
|
||||||
defines the architecture so early data models and APIs do not make the stronger
|
unencrypted content, institution-managed server envelopes, and externally
|
||||||
model impossible.
|
produced E2EE envelopes. The E2EE contract is operational—the server rejects
|
||||||
|
plaintext and retains ciphertext, signed manifests, wrapped keys, and digest
|
||||||
|
evidence—but a reviewed browser/device client and private-key custody provider
|
||||||
|
remain separately deployed responsibilities.
|
||||||
|
|
||||||
The core principle is that a postbox can become a trusted administrative
|
The core principle is that a postbox can become a trusted administrative
|
||||||
communication channel without requiring the server to see plaintext content.
|
communication channel without requiring the server to see plaintext content.
|
||||||
@@ -35,6 +38,54 @@ Algorithm choices should remain replaceable behind a crypto profile. The first
|
|||||||
profile should prefer standard, reviewed primitives such as HPKE for key
|
profile should prefer standard, reviewed primitives such as HPKE for key
|
||||||
wrapping and AEAD encryption for content.
|
wrapping and AEAD encryption for content.
|
||||||
|
|
||||||
|
## Product Profiles And Default
|
||||||
|
|
||||||
|
The content-protection policy is configurable per exact Postbox or immutable
|
||||||
|
template revision:
|
||||||
|
|
||||||
|
- `server_envelope_v1` is the recommended default. An institution-selected
|
||||||
|
Encryption vault controls server-readable envelopes and their migration
|
||||||
|
evidence. It is not end-to-end encryption.
|
||||||
|
- `external_e2ee_v1` is server-blind. An approved client or producer supplies
|
||||||
|
the ciphertext reference, signed manifest, wrapped recipient keys, key epoch,
|
||||||
|
and SHA-256 plaintext digest. GovOPlaN has no private key that can decrypt it.
|
||||||
|
- `plaintext_v1` stores clear content for institutions that explicitly choose
|
||||||
|
that boundary.
|
||||||
|
|
||||||
|
Operational metadata—including subject, routing, participants,
|
||||||
|
classifications, timestamps, attachment references, receipts, and retention
|
||||||
|
state—remains visible under every profile. Administrators therefore choose a
|
||||||
|
content-protection boundary, not a metadata-anonymity profile.
|
||||||
|
|
||||||
|
The standard policy grants new incumbents history since assignment, uses key
|
||||||
|
rewrapping for ordinary rotation and content re-encryption after compromise,
|
||||||
|
requires two-person institutional recovery and dual-control hand-over,
|
||||||
|
emergency, export, and destruction, requires strong external identity, and
|
||||||
|
limits vacancy escalation to metadata. Deployments may select other policy
|
||||||
|
values rather than inheriting a decision from GovOPlaN.
|
||||||
|
|
||||||
|
## Governed Profile Changes
|
||||||
|
|
||||||
|
A profile transition applies to new messages immediately and increments the
|
||||||
|
Postbox key epoch. Retained history can remain under the previous profile or be
|
||||||
|
migrated. The transition ledger records source and target profiles/vaults,
|
||||||
|
authority route, consent and key-holder evidence, quorum, reason, immutable
|
||||||
|
configuration snapshot, per-message source and target digest, and outcome.
|
||||||
|
|
||||||
|
Plaintext and managed-envelope migrations can use the server-side Encryption
|
||||||
|
capability. Managed decrypt, export, and re-encryption operations also create
|
||||||
|
Encryption migration records so old envelopes are disposed of through the
|
||||||
|
governed provider contract. Any transition to or from E2EE pauses each retained
|
||||||
|
message for an approved client transform. The client must return plaintext or
|
||||||
|
ciphertext as appropriate, plus evidence and the original content digest;
|
||||||
|
Postbox verifies digest continuity before changing the stored representation.
|
||||||
|
Leaving E2EE requires user-consent evidence, while changing managed history
|
||||||
|
requires institutional key-holder evidence. Dual control can require both.
|
||||||
|
|
||||||
|
This transition mechanism cannot revoke plaintext already decrypted, copied,
|
||||||
|
printed, or exported. Administrators must explicitly acknowledge that residual
|
||||||
|
disclosure before a transition is accepted.
|
||||||
|
|
||||||
## Identity And Device Keys
|
## Identity And Device Keys
|
||||||
|
|
||||||
The platform should distinguish:
|
The platform should distinguish:
|
||||||
|
|||||||
@@ -141,6 +141,73 @@ connector or module issue.
|
|||||||
- Owner/priority: `govoplan-mail`, `govoplan-calendar`,
|
- Owner/priority: `govoplan-mail`, `govoplan-calendar`,
|
||||||
`govoplan-connectors`, Wave 1/2.
|
`govoplan-connectors`, Wave 1/2.
|
||||||
|
|
||||||
|
#### Collaboration-suite boundary and hand-offs
|
||||||
|
|
||||||
|
Collaboration remains connector-first. The product named below never changes
|
||||||
|
which GovOPlaN module owns the administrative meaning of the work:
|
||||||
|
|
||||||
|
| External family | Initial posture | GovOPlaN semantic owner | Connector-owned boundary |
|
||||||
|
| --- | --- | --- | --- |
|
||||||
|
| Collabora Online, OnlyOffice, Nextcloud Office | Link an externally edited document and its editing session; import a governed rendition only when required | DMS owns document/version, lock, review, approval, retention, and collaboration-session evidence; Files owns stored bytes | Discovery, endpoint health, WOPI/vendor session exchange, callbacks, and provider object references |
|
||||||
|
| Matrix, Mattermost, Rocket.Chat, Nextcloud Talk | Create or link a room/thread for a governed work context; do not mirror all conversation history by default | The initiating Case, Workflow, or Task owns the work-context link and disposition; DMS/Records own retained evidence deliberately captured from it | Room/thread creation, membership synchronization, webhook/event normalization, and stable external links |
|
||||||
|
| Jitsi and BigBlueButton | Provision or link a conference for an existing appointment/event | Appointments owns booking intent; Calendar owns event, attendee, invitation, and time semantics | Conference provisioning, join/moderator references, provider lifecycle, and bounded attendance/result callbacks |
|
||||||
|
| OpenProject and comparable project suites | Link first, then publish or synchronize selected work packages | Tasks owns GovOPlaN task state; Workflow owns orchestration; Cases own case state and evidence references | Project/work-package lookup, publish/synchronize transport, webhooks, version tokens, and external URLs |
|
||||||
|
| Cross-suite activity streams | Consume normalized, bounded events only for an authorized work context | The receiving module decides whether an event changes state or becomes evidence; Audit records the GovOPlaN operation | Provider subscriptions, cursor/checkpoint handling, signature validation, event normalization, and replay protection |
|
||||||
|
|
||||||
|
Native collaboration behavior is justified only when GovOPlaN must own the
|
||||||
|
semantic state, authorization decision, audit evidence, retention/legal-hold
|
||||||
|
rule, or configuration-package fragment. Endpoint profiles, tokens, health,
|
||||||
|
protocol clients, provider IDs, retries, and webhook transport remain in
|
||||||
|
Connectors (or the owning protocol connector). A feature module consumes a
|
||||||
|
Core capability/DTO and must still start and fail explicitly when that optional
|
||||||
|
connector is absent; it never imports a provider client.
|
||||||
|
|
||||||
|
The minimum hand-off sequences are:
|
||||||
|
|
||||||
|
1. **Appointment to conference:** Appointments confirms the booking intent;
|
||||||
|
Calendar creates or updates the event and invitations; an optional
|
||||||
|
conference connector provisions the room idempotently and returns an
|
||||||
|
opaque join reference. Calendar stores that reference with the event, not
|
||||||
|
the provider credential.
|
||||||
|
2. **Case or Workflow to collaborative document:** the initiating module asks
|
||||||
|
DMS for a governed document/session; DMS requests an optional office-suite
|
||||||
|
connector session and retains version, lock, approval, and callback
|
||||||
|
evidence. The Case/Workflow keeps only the DMS reference.
|
||||||
|
3. **Case, Workflow, or Task to chat:** the semantic owner requests a room or
|
||||||
|
thread with an idempotency key and bounded membership intent. The connector
|
||||||
|
returns an external reference; capturing messages as evidence requires an
|
||||||
|
explicit DMS/Records action and policy decision.
|
||||||
|
4. **Task or Workflow to project suite:** Tasks supplies the task payload and
|
||||||
|
Workflow supplies correlation; the OpenProject connector publishes or
|
||||||
|
reconciles the work package and returns versioned external-reference and
|
||||||
|
retry/conflict evidence. Neither consumer writes connector tables.
|
||||||
|
|
||||||
|
Every executable collaboration connector must pass the common connector
|
||||||
|
contract checks plus a provider-focused minimum proof:
|
||||||
|
|
||||||
|
- optional-module startup and partial compositions work without the provider;
|
||||||
|
- profile health uses secret references and redacts credentials and remote
|
||||||
|
response bodies;
|
||||||
|
- tenant/resource authorization is checked before discovery, provisioning,
|
||||||
|
lookup, synchronization, or evidence capture;
|
||||||
|
- dry-run/simulation performs no remote mutation and explains unsupported
|
||||||
|
operations;
|
||||||
|
- create/publish calls are idempotent, retries preserve the same external
|
||||||
|
reference, and outcome-unknown or version conflicts remain reconcilable;
|
||||||
|
- callbacks/webhooks verify authenticity, tenant/profile binding, replay
|
||||||
|
protection, and bounded payloads;
|
||||||
|
- disable/retire behavior revokes new use while preserving non-secret audit and
|
||||||
|
external-reference evidence;
|
||||||
|
- Collabora/OnlyOffice prove discovery plus one non-production editing-session
|
||||||
|
round trip; Matrix/Mattermost/Rocket.Chat prove room lookup/create plus one
|
||||||
|
authenticated bounded event; Jitsi/BigBlueButton prove conference
|
||||||
|
provision/cancel; OpenProject proves project/work-package lookup, idempotent
|
||||||
|
publish, and conflict handling.
|
||||||
|
|
||||||
|
These are connector acceptance tests, not a claim that those connectors are
|
||||||
|
already implemented. Their implementation state remains in the owning
|
||||||
|
connector issues and catalogue.
|
||||||
|
|
||||||
### Payment And Public Cashier Systems
|
### Payment And Public Cashier Systems
|
||||||
|
|
||||||
- Strategy: integrate/export/import; keep the payment provider or cashier as
|
- Strategy: integrate/export/import; keep the payment provider or cashier as
|
||||||
@@ -175,8 +242,10 @@ connector or module issue.
|
|||||||
queries, untraceable manual transformations.
|
queries, untraceable manual transformations.
|
||||||
- MVP test path: publish one report/export as a governed file plus RSS/Atom
|
- MVP test path: publish one report/export as a governed file plus RSS/Atom
|
||||||
entry with checksum, timestamp, and permission check.
|
entry with checksum, timestamp, and permission check.
|
||||||
- Owner/priority: `govoplan-reporting`, `govoplan-connectors`, possible future
|
- Owner/priority: `govoplan-reporting`, `govoplan-connectors`,
|
||||||
`govoplan-datasources`/`govoplan-dataflow`, Wave 2.
|
`govoplan-datasources`, and `govoplan-dataflow`, Wave 2. Reporting owns
|
||||||
|
presentation/publication, Connectors owns transport, Datasources owns the
|
||||||
|
governed source/materialization catalogue, and Dataflow owns transformations.
|
||||||
|
|
||||||
### Public-Sector Protocols And Registries
|
### Public-Sector Protocols And Registries
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,94 @@
|
|||||||
|
# Records Filing Contract
|
||||||
|
|
||||||
|
Core exposes a small provider-neutral contract for filing exact source
|
||||||
|
revisions into an institutional record. Core does not own records semantics,
|
||||||
|
source-object authorization, or source bytes. `govoplan-records` owns filing
|
||||||
|
orchestration and chronology; each source module owns resolution of its exact
|
||||||
|
revision.
|
||||||
|
|
||||||
|
## Capability Names
|
||||||
|
|
||||||
|
- `records.filing` is supplied by the enabled Records module.
|
||||||
|
- `records.source.<module>` is supplied by an enabled source module, for
|
||||||
|
example `records.source.files` or `records.source.cases`.
|
||||||
|
- `records.archive.<provider>` is supplied by an enabled archive-transfer
|
||||||
|
adapter. Discovery does not imply conformance or current health.
|
||||||
|
|
||||||
|
Callers discover capabilities through the module registry. They must not
|
||||||
|
import optional source-module internals.
|
||||||
|
|
||||||
|
## Exact Source Identity
|
||||||
|
|
||||||
|
`RecordSourceLocator` identifies one tenant, source module, resource type,
|
||||||
|
resource ID, and immutable source revision. A source provider must:
|
||||||
|
|
||||||
|
1. reject cross-tenant resolution;
|
||||||
|
2. require a non-empty purpose;
|
||||||
|
3. re-evaluate the caller's current module and object authorization;
|
||||||
|
4. resolve exactly the requested revision, never a mutable "current" alias;
|
||||||
|
5. return safe display/provenance metadata and a SHA-256 digest when the source
|
||||||
|
has stable bytes or a canonical snapshot;
|
||||||
|
6. fail closed when the revision is missing, quarantined, corrupt, or no longer
|
||||||
|
authorized.
|
||||||
|
|
||||||
|
Historical Records browsing never revives historical access rights. The
|
||||||
|
source's current authorization decision remains authoritative when filing.
|
||||||
|
|
||||||
|
## Filing Semantics
|
||||||
|
|
||||||
|
`RecordFilingRequest` binds the exact source to a record, purpose, filing
|
||||||
|
reason, relationship, institutional context, and idempotency key. Records must
|
||||||
|
persist source identity and resolution evidence together with the filing actor,
|
||||||
|
represented capacity, valid time, recorded time, and immutable chronology.
|
||||||
|
|
||||||
|
An idempotency key may replay only an identical request. A conflicting reuse
|
||||||
|
must fail. Filing does not transfer ownership of source content and must not
|
||||||
|
silently copy mutable source state.
|
||||||
|
|
||||||
|
## Versioning
|
||||||
|
|
||||||
|
The Python DTOs and protocols live in `govoplan_core.core.records`. The
|
||||||
|
manifest interface `records.filing` starts at `1.0.0`. Incompatible DTO or
|
||||||
|
behavior changes require a new interface version and release impact analysis;
|
||||||
|
additional optional metadata remains backward compatible.
|
||||||
|
|
||||||
|
## Initial Providers
|
||||||
|
|
||||||
|
- Files resolves an exact managed `FileVersion`, verifies current Files access
|
||||||
|
and blob integrity, and returns its stored content digest.
|
||||||
|
- Cases resolves an exact immutable case revision after current case access and
|
||||||
|
returns a digest of the canonical revision snapshot.
|
||||||
|
|
||||||
|
Provider-specific selection UI belongs to the source module. The generic
|
||||||
|
Records dialog remains a diagnostic/manual fallback for exact identifiers.
|
||||||
|
|
||||||
|
## Archive Transfer Boundary
|
||||||
|
|
||||||
|
`RecordTransferPackage` binds a stable package ID, record revision, provider
|
||||||
|
profile, canonical manifest, and manifest SHA-256. An archive provider exposes
|
||||||
|
`RecordArchiveProviderState` before dispatch and accepts only a
|
||||||
|
`RecordArchiveTransferRequest` for a declared healthy profile. Its receipt must
|
||||||
|
identify the same package and provider and return one bounded outcome:
|
||||||
|
`accepted`, `rejected`, or `outcome_unknown`.
|
||||||
|
|
||||||
|
An unknown outcome is never retry-safe. Callers must retain the intent and
|
||||||
|
reconcile it against the provider before another effect. Provider state also
|
||||||
|
declares authority mode, freshness, limitations, and whether the provider is a
|
||||||
|
simulation. Credentials, transport configuration, archive-specific package
|
||||||
|
schemas, and custody semantics remain provider-owned.
|
||||||
|
|
||||||
|
Records includes `records.archive.simulation` to prove package and receipt
|
||||||
|
handling. The simulation is explicitly non-conformant, transfers no custody,
|
||||||
|
and cannot be used as evidence of an archive handoff. A real provider requires
|
||||||
|
a selected target/profile, provider-specific recovery declaration, and target
|
||||||
|
test evidence.
|
||||||
|
|
||||||
|
## Form Evidence Boundary
|
||||||
|
|
||||||
|
Form attachments use the separate provider-neutral contract in
|
||||||
|
`govoplan_core.core.form_evidence`. Forms Runtime requests short-lived,
|
||||||
|
purpose-bound upload grants and re-inspects the exact provider-owned evidence
|
||||||
|
before final submission. The provider keeps byte storage, quarantine,
|
||||||
|
classification, and retention ownership; Forms Runtime stores only immutable
|
||||||
|
evidence references and bounded verification results. This contract is not an
|
||||||
|
alternative path for Records filing or archive custody.
|
||||||
@@ -197,6 +197,13 @@ If both file and URL are set, the URL wins. The cache is used when a remote
|
|||||||
fetch fails, so an operator can still inspect the last known catalog. A cached
|
fetch fails, so an operator can still inspect the last known catalog. A cached
|
||||||
catalog must still pass signature, freshness, channel, and replay validation.
|
catalog must still pass signature, freshness, channel, and replay validation.
|
||||||
|
|
||||||
|
If neither source is configured, the Admin package directory discovers the
|
||||||
|
official public stable catalog at
|
||||||
|
`https://govoplan.add-ideas.de/catalogs/v1/channels/stable.json`. Core verifies
|
||||||
|
that fallback against the public key pinned in the installed Core package. An
|
||||||
|
explicit deployment catalog always takes precedence; a configured source that
|
||||||
|
is unavailable or invalid fails closed instead of silently falling back.
|
||||||
|
|
||||||
An official catalog is a JSON object with:
|
An official catalog is a JSON object with:
|
||||||
|
|
||||||
- `catalog_version`
|
- `catalog_version`
|
||||||
@@ -212,6 +219,14 @@ Each module entry can declare:
|
|||||||
|
|
||||||
- backend package name and pinned install reference
|
- backend package name and pinned install reference
|
||||||
- WebUI package name and pinned install reference
|
- WebUI package name and pinned install reference
|
||||||
|
- `artifact_integrity` for each package, including the HTTPS registry URL,
|
||||||
|
filename, byte size, SHA-256, package identity, source tag, and source commit
|
||||||
|
- `source`, binding the repository and immutable tag/commit identity, with
|
||||||
|
optional HTTPS repository and revision links
|
||||||
|
- `availability`, either `available` or `withdrawn`; a withdrawn entry must
|
||||||
|
carry an operator-readable `availability_reason` and cannot be planned
|
||||||
|
- `configuration_requirements` and an optional HTTPS `release_notes_url` for
|
||||||
|
prerequisites and release-specific operator guidance
|
||||||
- display metadata and tags
|
- display metadata and tags
|
||||||
- `license_features`, the feature entitlements required to plan that install
|
- `license_features`, the feature entitlements required to plan that install
|
||||||
- `dependencies` and `optional_dependencies`, the module ids expected in the
|
- `dependencies` and `optional_dependencies`, the module ids expected in the
|
||||||
@@ -239,6 +254,12 @@ Each module entry can declare:
|
|||||||
- `requires_interfaces`, named interface contracts and version ranges required
|
- `requires_interfaces`, named interface contracts and version ranges required
|
||||||
by this module
|
by this module
|
||||||
|
|
||||||
|
Core validates these fields before exposing the directory. Admin derives a
|
||||||
|
read-only catalog state from the installed package set, catalog dependency
|
||||||
|
closure, named-interface providers, current-version window, availability, and
|
||||||
|
generic license policy. This is an early operator diagnostic; trusted installer
|
||||||
|
preflight remains the authoritative mutation gate.
|
||||||
|
|
||||||
The signature is Ed25519 over canonical JSON with both `signature` and
|
The signature is Ed25519 over canonical JSON with both `signature` and
|
||||||
`signatures` removed. Core accepts the legacy single `signature` field and the
|
`signatures` removed. Core accepts the legacy single `signature` field and the
|
||||||
new `signatures` array.
|
new `signatures` array.
|
||||||
@@ -302,6 +323,12 @@ Catalog provenance changes preflight severity:
|
|||||||
plans, so operators can still use offline or emergency package refs
|
plans, so operators can still use offline or emergency package refs
|
||||||
- valid-catalog warnings, such as intentionally unsigned local catalogs when
|
- valid-catalog warnings, such as intentionally unsigned local catalogs when
|
||||||
signature enforcement is disabled, remain warnings
|
signature enforcement is disabled, remain warnings
|
||||||
|
- a saved catalog plan must match the currently validated entry exactly;
|
||||||
|
altered package refs, artifact identities, channel, sequence, trust state, or
|
||||||
|
signing-key identity block the run and require replanning
|
||||||
|
- a trusted remote artifact is downloaded before mutation into a private
|
||||||
|
SHA-256-addressed installer cache, checked for exact size and digest, and
|
||||||
|
passed to `pip` or npm only as that verified local file
|
||||||
- selected catalog entries with unsatisfied non-optional named interface ranges
|
- selected catalog entries with unsatisfied non-optional named interface ranges
|
||||||
block activation before the installer runs
|
block activation before the installer runs
|
||||||
- selected catalog entries whose target dependencies are neither installed nor
|
- selected catalog entries whose target dependencies are neither installed nor
|
||||||
@@ -519,6 +546,11 @@ Catalog entries can require license features:
|
|||||||
Core checks those requirements against an offline license file before allowing
|
Core checks those requirements against an offline license file before allowing
|
||||||
the entry into the install plan.
|
the entry into the install plan.
|
||||||
|
|
||||||
|
Official open-source GovOPlaN entries do not declare license features. The
|
||||||
|
license contract remains generic for external catalogs, deployment presets,
|
||||||
|
configuration/package directories, and support offerings; it gates only an
|
||||||
|
entry that explicitly asks for a feature.
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
GOVOPLAN_LICENSE_FILE=/srv/govoplan/license.json
|
GOVOPLAN_LICENSE_FILE=/srv/govoplan/license.json
|
||||||
GOVOPLAN_LICENSE_ENFORCEMENT=true
|
GOVOPLAN_LICENSE_ENFORCEMENT=true
|
||||||
|
|||||||
@@ -0,0 +1,26 @@
|
|||||||
|
# Search event indexing contract
|
||||||
|
|
||||||
|
Core defines, but does not implement, the optional Search indexing boundary.
|
||||||
|
Feature modules register `SearchSourceProvider` implementations for bounded
|
||||||
|
backfills and live authorization checks. A provider may additionally implement
|
||||||
|
`SearchEventSourceProvider` to translate a committed `PlatformEvent` into one
|
||||||
|
or more authoritative `SearchIndexChange` values.
|
||||||
|
|
||||||
|
When the Search index-writer capability is active, the platform event worker
|
||||||
|
uses the durable consumer identity `search.indexing.v1`. It accepts only public
|
||||||
|
and internal events, passes the outbox delivery key to each event-capable
|
||||||
|
source, and then advances a bounded batch of queued index changes in the same
|
||||||
|
worker transaction. Stable change IDs make delivery replay idempotent.
|
||||||
|
|
||||||
|
The boundary has three non-negotiable rules:
|
||||||
|
|
||||||
|
- a source may emit changes only for its registered module, provider, resource
|
||||||
|
type, and event tenant;
|
||||||
|
- Search validates every upsert document before queueing it and rejects secret
|
||||||
|
metadata keys;
|
||||||
|
- an index ACL is only a candidate filter. Resources marked for authorization
|
||||||
|
recheck are returned only after the owning source explicitly allows the
|
||||||
|
current principal at query time.
|
||||||
|
|
||||||
|
Search and its worker remain optional. Core-only startup and feature-module
|
||||||
|
operation do not require the Search package.
|
||||||
@@ -12,4 +12,4 @@ tools/checks/security-audit/run.sh --mode full --scope govoplan
|
|||||||
|
|
||||||
Canonical documentation:
|
Canonical documentation:
|
||||||
|
|
||||||
- `/mnt/DATA/git/govoplan/docs/SECURITY_AUDIT.md`
|
- `/mnt/DATA/git/govoplan/docs/operations/SECURITY_AUDIT.md`
|
||||||
|
|||||||
@@ -0,0 +1,118 @@
|
|||||||
|
# Semantic Documentation Subjects
|
||||||
|
|
||||||
|
## Purpose And Ownership
|
||||||
|
|
||||||
|
The semantic-documentation subject contract lets an optional module expose the
|
||||||
|
configured artifacts that administrators may document: for example a form, a
|
||||||
|
form field, a workflow, or a workflow state. It is a discovery and resolution
|
||||||
|
contract, not a second configuration API.
|
||||||
|
|
||||||
|
The module that owns an artifact also owns its subject provider, authorization,
|
||||||
|
identity, revision, route, and lifecycle semantics. Docs may discover those
|
||||||
|
providers through Core and attach authored documentation to their stable
|
||||||
|
references. Docs must not import the feature module, read its tables, or copy
|
||||||
|
configuration content into a generic index.
|
||||||
|
|
||||||
|
This contract is additive to manifest `DocumentationTopic` contributions and
|
||||||
|
configured-state `documentation_providers`. Every providing module must retain
|
||||||
|
static user and administrator documentation baselines. The baselines explain
|
||||||
|
the feature even when the provider is disabled, unavailable, or has no
|
||||||
|
configured subjects.
|
||||||
|
|
||||||
|
## Identity And Versioning
|
||||||
|
|
||||||
|
`SemanticDocumentationSubjectReference` identifies a subject with:
|
||||||
|
|
||||||
|
- owning module and tenant;
|
||||||
|
- a module-defined subject kind and stable identifier;
|
||||||
|
- an optional typed nested anchor, such as `field/registration-number`;
|
||||||
|
- the revision and canonical fingerprint observed when documentation was
|
||||||
|
authored or reviewed.
|
||||||
|
|
||||||
|
The `stable_key` derives only from identity. A rename or configuration revision
|
||||||
|
therefore does not detach existing documentation. A nested anchor has its own
|
||||||
|
identity so a field can be documented independently from its form.
|
||||||
|
|
||||||
|
Providers must resolve an old reference as one of:
|
||||||
|
|
||||||
|
- `available`: the observed revision/fingerprint is still current;
|
||||||
|
- `changed`: the same stable subject has changed and may need review;
|
||||||
|
- `superseded`: another stable reference replaced it;
|
||||||
|
- `missing`: the subject was removed or is no longer resolvable;
|
||||||
|
- `temporarily_unavailable`: the provider cannot currently determine state.
|
||||||
|
|
||||||
|
Absence is not authorization. A provider returns `None` when the principal may
|
||||||
|
not learn whether a subject exists. Core also rejects cross-tenant list and
|
||||||
|
resolution requests before calling a provider.
|
||||||
|
|
||||||
|
## Safe Projection
|
||||||
|
|
||||||
|
Descriptors contain only bounded, explicit presentation fields: localized
|
||||||
|
labels and descriptions, breadcrumbs, a local route, audience,
|
||||||
|
classification, and required scopes. They must not contain credentials,
|
||||||
|
personal data, arbitrary provider metadata, configuration payloads, or the
|
||||||
|
authored documentation itself. Routes are application-local and are still
|
||||||
|
subject to normal route authorization.
|
||||||
|
|
||||||
|
The fingerprint is a review signal, not a concurrency token or a content hash
|
||||||
|
that callers may use to reconstruct configuration. Providers should calculate
|
||||||
|
it from the smallest canonical JSON projection whose semantic changes require
|
||||||
|
documentation review. Volatile timestamps and secrets must be excluded.
|
||||||
|
|
||||||
|
## Provider Registration
|
||||||
|
|
||||||
|
A provider is registered under its exact module-scoped capability name:
|
||||||
|
|
||||||
|
```python
|
||||||
|
from govoplan_core.core.modules import CapabilityDocumentation
|
||||||
|
from govoplan_core.core.semantic_documentation import (
|
||||||
|
SEMANTIC_DOCUMENTATION_SUBJECT_CONTRACT_VERSION,
|
||||||
|
semantic_documentation_subject_capability,
|
||||||
|
)
|
||||||
|
|
||||||
|
capability = semantic_documentation_subject_capability("forms")
|
||||||
|
|
||||||
|
manifest = ModuleManifest(
|
||||||
|
id="forms",
|
||||||
|
# ...
|
||||||
|
capability_factories={capability: build_semantic_subject_provider},
|
||||||
|
capability_documentation={
|
||||||
|
capability: CapabilityDocumentation(
|
||||||
|
label="Form semantic subjects",
|
||||||
|
summary="Lists authorized configured forms and fields for Docs.",
|
||||||
|
contract_version=SEMANTIC_DOCUMENTATION_SUBJECT_CONTRACT_VERSION,
|
||||||
|
documentation_types=("admin", "user"),
|
||||||
|
)
|
||||||
|
},
|
||||||
|
documentation=(admin_baseline, user_baseline),
|
||||||
|
)
|
||||||
|
```
|
||||||
|
|
||||||
|
The capability is `documentation.semantic_subjects.<module_id>`. Registry
|
||||||
|
validation rejects a mismatched owner, missing capability documentation, a
|
||||||
|
wrong contract version, or missing static baselines.
|
||||||
|
|
||||||
|
`list_semantic_documentation_subjects` performs authorized, paginated discovery
|
||||||
|
across installed providers. `resolve_semantic_documentation_subject` targets
|
||||||
|
one owner without loading another feature module. Providers must apply the
|
||||||
|
current tenant and principal on every call and must not infer visibility from a
|
||||||
|
previous list result.
|
||||||
|
|
||||||
|
## Lifecycle And Integration Rules
|
||||||
|
|
||||||
|
- Keep subject and anchor identifiers stable across display-name and route
|
||||||
|
changes.
|
||||||
|
- Return `superseded` only with the replacement reference; do not silently
|
||||||
|
rewrite stored references.
|
||||||
|
- Return a reason code for missing or temporarily unavailable subjects without
|
||||||
|
exposing sensitive detail.
|
||||||
|
- Reauthorize both discovery and resolution. Stored documentation references
|
||||||
|
confer no access to a live artifact.
|
||||||
|
- Treat a changed fingerprint as a request for editorial review. It does not
|
||||||
|
automatically invalidate or publish authored documentation.
|
||||||
|
- Removing a feature module leaves references resolvable as provider
|
||||||
|
unavailable. Docs can preserve history without importing the module.
|
||||||
|
|
||||||
|
Forms, Workflow, and later modules should implement their subject providers in
|
||||||
|
their own repositories. Docs owns the authored semantic-documentation records,
|
||||||
|
review workflow, and projection UI.
|
||||||
@@ -0,0 +1,162 @@
|
|||||||
|
# State And Recovery Contract
|
||||||
|
|
||||||
|
## State Profiles
|
||||||
|
|
||||||
|
Core accepts three runtime state profiles:
|
||||||
|
|
||||||
|
| Profile | Runtime placement | Durable storage |
|
||||||
|
| --- | --- | --- |
|
||||||
|
| `local` | One development process set | Local filesystem is permitted. |
|
||||||
|
| `host-shared` | Replicas on one host | One host-shared volume plus PostgreSQL and Redis. |
|
||||||
|
| `shared` | Independent hosts | PostgreSQL, Redis, and S3-compatible object storage. |
|
||||||
|
|
||||||
|
All replicas in one installation use one stable
|
||||||
|
`GOVOPLAN_INSTALLATION_ID`, one immutable module composition, and identical
|
||||||
|
database, broker, encryption-key, and object-storage bindings. Core rejects
|
||||||
|
replicas with the `local` profile and rejects `shared` without PostgreSQL,
|
||||||
|
Redis, S3, and a non-default installation identifier.
|
||||||
|
|
||||||
|
`FILE_STORAGE_S3_ENDPOINT_TRUSTED=true` is an explicit deployment trust
|
||||||
|
declaration for a clean HTTPS S3 origin. It does not authorize a
|
||||||
|
user-controlled connector endpoint and it is separate from installer-managed
|
||||||
|
Garage's exact endpoint trust.
|
||||||
|
|
||||||
|
## Object Storage
|
||||||
|
|
||||||
|
`govoplan_core.core.object_storage` is the shared backend contract for durable
|
||||||
|
module artifacts. It provides bounded read/write/list/stat/delete operations
|
||||||
|
for local and S3-compatible storage. Modules own their object-key namespace and
|
||||||
|
business metadata; Core does not interpret module files.
|
||||||
|
|
||||||
|
`stat` and `list_objects` return object size plus a UTC `modified_at` value when
|
||||||
|
the backend can prove it. Reconciliation and retention code may use that value
|
||||||
|
for conservative grace periods, but must treat a missing timestamp as
|
||||||
|
ineligible for automatic deletion rather than guessing an age.
|
||||||
|
|
||||||
|
Rules for modules:
|
||||||
|
|
||||||
|
- Store only opaque object keys in business records, never local absolute
|
||||||
|
paths.
|
||||||
|
- Use node-local directories only for temporary materialization.
|
||||||
|
- Verify expected size and digest before consuming consequential artifacts.
|
||||||
|
- If object creation precedes database commit, compensate successfully created
|
||||||
|
objects on failure.
|
||||||
|
- If object deletion fails, retain the database reference and report a retryable
|
||||||
|
failure rather than claiming deletion.
|
||||||
|
- Define an orphan-inventory strategy for hard process loss between object
|
||||||
|
creation and metadata commit.
|
||||||
|
|
||||||
|
The Files module delegates its backend implementation to this Core contract.
|
||||||
|
Campaign generated EML artifacts use a Campaign-owned object prefix and are
|
||||||
|
read by workers through the same shared backend.
|
||||||
|
|
||||||
|
## Runtime Nodes And Leases
|
||||||
|
|
||||||
|
API and worker incarnations register in `core_runtime_nodes` with role,
|
||||||
|
software version, module-composition hash, queues, start time, and heartbeat.
|
||||||
|
The registration identity includes a process incarnation so a stale process
|
||||||
|
cannot update a replacement's row.
|
||||||
|
|
||||||
|
Worker metadata also records the orchestrator pool and declared concurrency.
|
||||||
|
Every Celery prefork child disposes the SQLAlchemy pool inherited from its
|
||||||
|
parent and creates a process-local pool before handling work. Deployment
|
||||||
|
rendering must therefore budget one database pool for the worker parent and
|
||||||
|
each child. Ops compares active queue ownership, software versions, and the
|
||||||
|
order-independent module-composition hash with the graph loaded by the API.
|
||||||
|
|
||||||
|
Drain is durable operator intent:
|
||||||
|
|
||||||
|
- an API enters not-ready state after observing drain;
|
||||||
|
- a worker cancels queue consumers after observing drain;
|
||||||
|
- cancellation returns an eligible draining node to active state;
|
||||||
|
- clean shutdown marks the matching incarnation stopped.
|
||||||
|
|
||||||
|
Coordination loss also fails closed. An API reports
|
||||||
|
`coordination_unavailable` from `/health/ready` until a heartbeat succeeds
|
||||||
|
again. A worker cancels its local queue consumers on any heartbeat or database
|
||||||
|
failure and only resumes them after its existing incarnation heartbeats
|
||||||
|
successfully. It never re-registers from the heartbeat path, so a stale worker
|
||||||
|
cannot reclaim a node identity from its replacement.
|
||||||
|
|
||||||
|
`core_distributed_leases` provides installation/resource uniqueness, expiry,
|
||||||
|
holder incarnation, and monotonically increasing fencing tokens. Lease expiry
|
||||||
|
does not make an old process harmless by itself: code performing an effect must
|
||||||
|
assert its exact fence before commit. `govoplan_core.commands.fenced_run`
|
||||||
|
renews a lease around a subprocess and terminates the child when the lease is
|
||||||
|
lost. The deployment profiles use it for the singleton scheduler.
|
||||||
|
|
||||||
|
## Migration Ordering
|
||||||
|
|
||||||
|
Only `govoplan_core.commands.init_db` mutates schema. On PostgreSQL it acquires
|
||||||
|
a deterministic installation/track advisory lock before pre-migration tasks,
|
||||||
|
Alembic, and post-migration tasks. The lock is session-scoped and therefore
|
||||||
|
released if the migration process dies.
|
||||||
|
|
||||||
|
Runtime roles run `govoplan_core.commands.wait_for_database`. It waits until
|
||||||
|
the database has exactly the configured, dependency-resolved Core/module
|
||||||
|
Alembic heads and never upgrades schema. Cross-module `depends_on` revisions
|
||||||
|
therefore do not leave runtime roles waiting for a branch marker Alembic has
|
||||||
|
correctly consumed. This permits a migration Job and runtime Deployments to be
|
||||||
|
submitted together while keeping startup fail-closed.
|
||||||
|
|
||||||
|
Runtime coordination records the installed `govoplan-core` distribution
|
||||||
|
version for API, worker and scheduler roles. FastAPI/OpenAPI metadata versions
|
||||||
|
are presentation metadata and must not be used as deployable software identity;
|
||||||
|
mixing the two would create a false version-skew readiness failure.
|
||||||
|
|
||||||
|
## Recovery Ledger
|
||||||
|
|
||||||
|
`govoplan_core.core.recovery` provides a durable operation and evidence
|
||||||
|
contract. Recovery modes are:
|
||||||
|
|
||||||
|
- `atomic`: one database transaction, no external effect;
|
||||||
|
- `compensation`: explicit inverse actions;
|
||||||
|
- `snapshot_restore`: separately verified backup reference;
|
||||||
|
- `forward_recovery`: repair/resume the current version;
|
||||||
|
- `irreversible`: explicit approval, no automated recovery claim.
|
||||||
|
|
||||||
|
Every plan requires verification steps. Mode-specific evidence is mandatory.
|
||||||
|
Operations bind an idempotency key to a canonical request hash, may bind a
|
||||||
|
runtime fencing token, and emit append-only hash-chained checkpoints. Backup
|
||||||
|
and approval references are part of the hashed plan evidence. Every low-level
|
||||||
|
state transition and checkpoint append revalidates the operation's recorded
|
||||||
|
fence while holding the operation row lock. Plaintext secrets are rejected
|
||||||
|
from metadata and evidence.
|
||||||
|
|
||||||
|
The state machine makes partial and uncertain outcomes visible. A non-atomic
|
||||||
|
running operation cannot transition directly to ordinary failure, and success
|
||||||
|
or recovery requires explicit verified checks. Ops projects states requiring
|
||||||
|
attention, but module behavior gains this guarantee only after it adopts the
|
||||||
|
ledger around its own side effects.
|
||||||
|
|
||||||
|
## Recovery Boundary
|
||||||
|
|
||||||
|
Application/configuration rollback and database rollback are not equivalent.
|
||||||
|
Once an incompatible migration starts, old code may be unsafe even if its image
|
||||||
|
is available. Deployment automation must switch to forward recovery unless a
|
||||||
|
coordinated and verified database/object/key backup is restored.
|
||||||
|
|
||||||
|
Core does not create production database backups. The deployment owner must
|
||||||
|
provide backup, retention, encryption, restore verification, and recovery-point
|
||||||
|
coordination for PostgreSQL, object storage, and encryption keys. The canonical
|
||||||
|
operator procedure is documented in
|
||||||
|
`govoplan/docs/operations/RECOVERY_AND_ROLLBACK_GUARANTEES.md`.
|
||||||
|
|
||||||
|
## Verification
|
||||||
|
|
||||||
|
Focused contracts are covered by:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
/mnt/DATA/git/govoplan/.venv/bin/python -m pytest -q \
|
||||||
|
tests/test_object_storage.py \
|
||||||
|
tests/test_runtime_coordination.py \
|
||||||
|
tests/test_runtime_agents.py \
|
||||||
|
tests/test_fenced_run.py \
|
||||||
|
tests/test_migration_lock.py \
|
||||||
|
tests/test_wait_for_database.py \
|
||||||
|
tests/test_recovery_guarantees.py
|
||||||
|
```
|
||||||
|
|
||||||
|
Production acceptance additionally requires multi-node failure and coordinated
|
||||||
|
restore drills against the actual PostgreSQL, Redis, object-store, ingress, and
|
||||||
|
secret-provider topology.
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
# Tabular Source Preview Contract
|
||||||
|
|
||||||
|
Core defines provider-neutral DTOs for optional tabular source providers. A
|
||||||
|
source declares whether it is live, cached, file-backed, or static; its schema
|
||||||
|
and immutable fingerprint; structured health; and the exact projection,
|
||||||
|
pagination, filter, aggregation, and sorting operations that the provider can
|
||||||
|
push down. Consumers must not infer pushdown support from a provider name.
|
||||||
|
|
||||||
|
Every preview request carries independent row, byte, and elapsed-time budgets.
|
||||||
|
A provider may tighten these values but must return its effective limits,
|
||||||
|
returned byte count, elapsed milliseconds, truncation state, and structured
|
||||||
|
diagnostics. Equivalent fields on the Datasources read request and result
|
||||||
|
preserve that evidence when a live source is consumed through the catalogue.
|
||||||
|
A row that cannot fit within the byte budget fails explicitly rather than
|
||||||
|
leaking a partial value. Timeout, stale fingerprint, unavailable source, and
|
||||||
|
authorization failures remain distinct provider-neutral errors.
|
||||||
|
|
||||||
|
Connector health and preview diagnostics must contain no credentials, endpoint
|
||||||
|
userinfo, row values, or unbounded remote error bodies. A Datasource origin
|
||||||
|
preserves this contract so registration and staging do not erase source mode,
|
||||||
|
health, pushdown, or preview-limit evidence.
|
||||||
@@ -0,0 +1,28 @@
|
|||||||
|
# Template And Generated Artifact Capability Contracts
|
||||||
|
|
||||||
|
Core defines provider-neutral contracts for optional template libraries and
|
||||||
|
generated artifact storage. Core does not render templates or store generated
|
||||||
|
files itself.
|
||||||
|
|
||||||
|
## Templates
|
||||||
|
|
||||||
|
- `templates.catalog` lists typed, versioned template references and checks a
|
||||||
|
consumer's available fields, usage, and output format.
|
||||||
|
- `templates.renderer` accepts a `TemplateRenderRequest` containing pinned
|
||||||
|
input data and returns immutable render evidence plus an artifact reference.
|
||||||
|
|
||||||
|
The DTOs contain identifiers, hashes, plain mappings, and scalar metadata. They
|
||||||
|
do not expose Template ORM models or require Campaign, Distribution Lists,
|
||||||
|
Addresses, Reporting, Forms, or Mail.
|
||||||
|
|
||||||
|
## Generated Artifacts
|
||||||
|
|
||||||
|
`files.artifact_store` accepts a `ManagedArtifactWriteRequest` and returns a
|
||||||
|
`ManagedArtifactRef`. Producers supply bytes, a safe filename/content type,
|
||||||
|
idempotency key, and non-secret provenance. Files owns path normalization,
|
||||||
|
authorization, versions, storage, and download behavior.
|
||||||
|
|
||||||
|
Consumers must discover both contracts through the module registry and degrade
|
||||||
|
only the unavailable path. A template renderer may return a bounded download
|
||||||
|
when Files is absent. A caller must not infer successful external delivery from
|
||||||
|
successful rendering or artifact persistence.
|
||||||
@@ -0,0 +1,68 @@
|
|||||||
|
# Temporal Data Context
|
||||||
|
|
||||||
|
GovOPlaN exposes one read context for data validity and system knowledge. The
|
||||||
|
calendar control in the authenticated titlebar applies that context to
|
||||||
|
supported list and detail reads for the current account and tenant.
|
||||||
|
|
||||||
|
## Two Independent Axes
|
||||||
|
|
||||||
|
- **Valid time** answers when a fact applied in the represented domain.
|
||||||
|
- **Recorded time** answers what the system had recorded by a particular
|
||||||
|
instant.
|
||||||
|
|
||||||
|
The default is data valid now under the latest recorded state. `At time`
|
||||||
|
selects a valid-time instant. `All` removes the valid-time interval filter but
|
||||||
|
still uses the selected recorded state. The optional recorded-state cutoff can
|
||||||
|
be combined with any valid-time mode, which keeps correction history distinct
|
||||||
|
from changes in real-world validity.
|
||||||
|
|
||||||
|
An interval is half open: `valid_from <= instant < valid_to`. A revision belongs
|
||||||
|
to a recorded-state snapshot when `recorded_at <= cutoff` and it was not
|
||||||
|
superseded at or before that cutoff.
|
||||||
|
|
||||||
|
## Security And Mutation Rules
|
||||||
|
|
||||||
|
The temporal data context is a read projection, not an authorization context.
|
||||||
|
Authentication, permissions, active delegations, tenant boundaries, module
|
||||||
|
policy, and maintenance controls are always evaluated under current security
|
||||||
|
state. A historical projection never restores an expired permission.
|
||||||
|
|
||||||
|
The context also does not supply mutation dates. Writes continue to target the
|
||||||
|
current lifecycle revision and must carry their explicit valid/effective dates,
|
||||||
|
expected revision, reason, and evidence where the owning contract requires
|
||||||
|
them. A screen showing historical data must not silently turn a normal edit
|
||||||
|
into a historical correction.
|
||||||
|
|
||||||
|
## HTTP Contract
|
||||||
|
|
||||||
|
Core accepts these request headers:
|
||||||
|
|
||||||
|
| Header | Meaning |
|
||||||
|
| --- | --- |
|
||||||
|
| `X-Govoplan-Validity-Mode` | `current`, `at`, or `all` |
|
||||||
|
| `X-Govoplan-Valid-At` | Timezone-aware ISO 8601 instant required by `at` |
|
||||||
|
| `X-Govoplan-Recorded-At` | Optional timezone-aware system-knowledge cutoff |
|
||||||
|
|
||||||
|
Invalid or naive timestamps fail with HTTP 400. Responses expose the resolved
|
||||||
|
mode and evaluated instant. Conditional JSON responses vary by all three
|
||||||
|
request headers, and the shared WebUI API client includes them in request
|
||||||
|
deduplication and conditional-cache keys.
|
||||||
|
|
||||||
|
## Module Adoption
|
||||||
|
|
||||||
|
Revision-owning modules apply
|
||||||
|
`govoplan_core.db.temporal.apply_temporal_revision_filter` only to read queries
|
||||||
|
that are meant to follow the platform context. Explicit version references and
|
||||||
|
explicit resolver `effective_at` arguments take precedence. Current-row
|
||||||
|
lookups used for optimistic concurrency, authorization, routing, effects, or
|
||||||
|
other mutations must remain explicit and context-independent.
|
||||||
|
|
||||||
|
The initial bitemporal adoption covers Decisions, Mandates, Parties, and
|
||||||
|
Services. Their immutable revisions have indexed valid, recorded, and
|
||||||
|
superseded timestamps. Modules with effective-dated security records or
|
||||||
|
recorded-only revision histories require separate display-query adoption so
|
||||||
|
the global selector cannot affect current authorization or execution.
|
||||||
|
|
||||||
|
The WebUI selection is stored in session storage per account and tenant. A
|
||||||
|
change remounts the active module route so existing page loaders issue a fresh
|
||||||
|
request. Returning both axes to their defaults removes the stored selection.
|
||||||
@@ -0,0 +1,56 @@
|
|||||||
|
# WebUI Theme Contract
|
||||||
|
|
||||||
|
GovOPlaN supports `system`, `light`, and `dark` as persisted user preferences.
|
||||||
|
`system` follows `prefers-color-scheme` live; it is not resolved permanently at
|
||||||
|
save time. Core applies the resolved mode through `data-theme` on the document
|
||||||
|
root and exposes the selected preference through `data-theme-preference`.
|
||||||
|
Each user may also choose a validated `default`, `civic_blue`, `forest`, or
|
||||||
|
`plum` accent palette. Core applies it through `data-palette`; every module
|
||||||
|
inherits the result through semantic tokens without module-specific CSS.
|
||||||
|
|
||||||
|
## Ownership
|
||||||
|
|
||||||
|
- Core owns semantic CSS tokens, native `color-scheme`, preference persistence,
|
||||||
|
the Settings selector, and the shared shell.
|
||||||
|
- Modules consume semantic tokens such as `--surface`, `--text`, `--line`, and
|
||||||
|
the status token families. They may define domain aliases whose values resolve
|
||||||
|
to shared tokens.
|
||||||
|
- Palette defaults form a provenance chain: system, tenant, then an explicit
|
||||||
|
user choice. Invalid stored values are ignored. Reset means inheritance and
|
||||||
|
does not copy the current parent value into the child scope.
|
||||||
|
- A policy lock is separate from the default. A system lock wins over every
|
||||||
|
child scope; otherwise a tenant lock suppresses a personal override. The
|
||||||
|
authenticated profile reports the effective palette, source, inherited
|
||||||
|
palette, and lock state.
|
||||||
|
- Advanced personal overrides are a separately governed surface. The system
|
||||||
|
must opt in, a tenant may inherit or block that decision, and palette locks
|
||||||
|
always suppress overrides. Changing either policy requires
|
||||||
|
`admin:policies:write` in addition to the owning settings permission.
|
||||||
|
|
||||||
|
## Palette safety and scope
|
||||||
|
|
||||||
|
The Settings preview shows the chosen or inherited accent in every applicable
|
||||||
|
light/dark preview before Save. Presets are checked for WCAG AA contrast in the
|
||||||
|
theme contract. When policy permits, the shared advanced editor can atomically
|
||||||
|
override accent, surface, and semantic status pairs for both modes. Every
|
||||||
|
foreground/background pair must meet WCAG AA contrast, and success,
|
||||||
|
information, warning, and danger colors must remain distinct. Invalid stored
|
||||||
|
documents fail closed and are not partially applied.
|
||||||
|
|
||||||
|
Import and export use the exact versioned JSON schema `schema_version: "1"`.
|
||||||
|
Both `light` and `dark` must contain every supported token exactly once as a
|
||||||
|
six-digit hex value. Import changes only the local draft; Save persists the
|
||||||
|
whole document. Removing overrides returns to palette and policy inheritance.
|
||||||
|
The system default is disabled so upgrades do not unexpectedly admit arbitrary
|
||||||
|
branding. Tenant `null` means inherit, `false` blocks, and `true` is accepted
|
||||||
|
only while the system permits overrides.
|
||||||
|
|
||||||
|
Do not introduce fixed foreground/background colors in a module merely to make
|
||||||
|
one mode look correct. Add or reuse a semantic Core token, then define both
|
||||||
|
light and dark values. Bitmap content and externally authored HTML are exempt,
|
||||||
|
but their surrounding controls must still use the shared tokens.
|
||||||
|
|
||||||
|
`npm run test:theme-contract` verifies root mode/palette behavior, preset and
|
||||||
|
custom-override validation/application, and representative
|
||||||
|
Campaign, Calendar, Files, and Mail token consumption. The check runs before a
|
||||||
|
production WebUI build.
|
||||||
@@ -0,0 +1,59 @@
|
|||||||
|
# Ticket Integration Capability Contracts
|
||||||
|
|
||||||
|
Core owns two narrow, optional contracts that let the Tickets module compose
|
||||||
|
with policy and formal-procedure modules without importing either one. Tickets
|
||||||
|
remains the authority for operational ticket identity, lifecycle, assignment,
|
||||||
|
comments, links, and immutable history.
|
||||||
|
|
||||||
|
## Capability Names
|
||||||
|
|
||||||
|
- `tickets.routing` optionally supplies a `TicketRoutingProvider`.
|
||||||
|
- `tickets.case_escalation` optionally supplies a
|
||||||
|
`TicketCaseEscalationProvider`.
|
||||||
|
|
||||||
|
Both contracts are version 1 and are defined in
|
||||||
|
`govoplan_core.core.tickets`. Registry helpers return `None` when a capability
|
||||||
|
is absent or has the wrong shape, so optional-module absence is normal runtime
|
||||||
|
state rather than a startup failure.
|
||||||
|
|
||||||
|
## Routing
|
||||||
|
|
||||||
|
Tickets sends a bounded, tenant-scoped `TicketRoutingRequest` containing the
|
||||||
|
ticket reference, type, priority, title, receive time, optional queue hint, and
|
||||||
|
non-secret attributes. The provider returns its identity and may return a queue
|
||||||
|
reference, timezone-aware service target, human-readable explanation, and
|
||||||
|
bounded metadata.
|
||||||
|
|
||||||
|
The provider is advisory. Tickets snapshots any returned queue and target into
|
||||||
|
its own record and history. An absent provider, a no-match plan, or an absent
|
||||||
|
queue must not prevent ticket intake; authorized staff can route manually.
|
||||||
|
Providers must not persist a second ticket lifecycle.
|
||||||
|
|
||||||
|
## Case Escalation
|
||||||
|
|
||||||
|
Tickets sends a `TicketCaseEscalationCommand` with stable tenant, ticket, and
|
||||||
|
display references, the requested Case type, actor-visible handoff note,
|
||||||
|
timezone-aware occurrence time, and an idempotency key. The provider returns a
|
||||||
|
stable Case identifier, number, bounded application-relative URL, replay flag,
|
||||||
|
and bounded metadata.
|
||||||
|
|
||||||
|
Providers must:
|
||||||
|
|
||||||
|
- recheck tenant and Case-creation authorization;
|
||||||
|
- reject an absent or inactive requested Case type;
|
||||||
|
- make identical retries resolve the same Case;
|
||||||
|
- preserve the Ticket reference in governed Case context; and
|
||||||
|
- return only an application-relative path, never an untrusted external URL.
|
||||||
|
|
||||||
|
Tickets records the result and its own escalation evidence. Cases remains the
|
||||||
|
authority for the formal procedure; Tickets remains the authority for the
|
||||||
|
operational request. Creating a Case does not merge or silently close either
|
||||||
|
lifecycle.
|
||||||
|
|
||||||
|
## Failure And Transaction Semantics
|
||||||
|
|
||||||
|
Capability calls receive the caller's active persistence session so a concrete
|
||||||
|
provider can participate in the same unit of work. Authorization and validation
|
||||||
|
errors fail the requested routing/escalation mutation explicitly. The caller
|
||||||
|
must still apply its own permission checks, tenant boundary, replay protection,
|
||||||
|
and immutable evidence rules.
|
||||||
@@ -50,6 +50,15 @@ contestability, responsibility, and traceability at the point of action.
|
|||||||
| UX-024 | Explicit `Discard` actions and dirty in-application navigation use the shared `UnsavedChangesProvider` dialog. A page registers save/discard behavior with `useUnsavedDraftGuard`; its Discard button calls `requestDiscard`, and route changes use `useGuardedNavigate` or `requestNavigation`. | Accepted | All create/edit surfaces |
|
| UX-024 | Explicit `Discard` actions and dirty in-application navigation use the shared `UnsavedChangesProvider` dialog. A page registers save/discard behavior with `useUnsavedDraftGuard`; its Discard button calls `requestDiscard`, and route changes use `useGuardedNavigate` or `requestNavigation`. | Accepted | All create/edit surfaces |
|
||||||
| UX-025 | `window.alert` and the global `alert` function are prohibited. A narrowly necessary exception requires product-owner authorization and an entry in the alert exception register before implementation. | Accepted | All WebUI code |
|
| UX-025 | `window.alert` and the global `alert` function are prohibited. A narrowly necessary exception requires product-owner authorization and an entry in the alert exception register before implementation. | Accepted | All WebUI code |
|
||||||
| UX-026 | A table defines one stable ordered action set. A row-level unavailable action remains in its normal position and is disabled, preferably with `disabledReason`; structurally irrelevant actions are omitted for the entire table. Empty rows reserve the same slots so their Add action stays in the normal left-most action position. | Accepted | All structured tables |
|
| UX-026 | A table defines one stable ordered action set. A row-level unavailable action remains in its normal position and is disabled, preferably with `disabledReason`; structurally irrelevant actions are omitted for the entire table. Empty rows reserve the same slots so their Add action stays in the normal left-most action position. | Accepted | All structured tables |
|
||||||
|
| UX-027 | The platform icon rail keeps its brand header and utility footer visible. Only the module-navigation region scrolls when installed and permitted modules exceed the available viewport height. | Accepted | Core WebUI shell |
|
||||||
|
| UX-028 | Maintenance and offline states use their established textual warning banners centered in the titlebar. They must not recolor the shell or add decorative status icons. Global search is a right-side command, so warnings do not replace its trigger or overlay. | Accepted | Core WebUI shell |
|
||||||
|
| UX-029 | Recoverable page and module errors use the central compact `DismissibleAlert` presentation with an explicit recovery action where one exists. Full-height workspaces must overlay page feedback instead of allowing an alert to become a stretched workspace row. | Accepted | Core and module WebUIs |
|
||||||
|
| UX-030 | At narrow widths, the titlebar uses separate context and command rows. Context selectors remain horizontally reachable, search retains its compact trigger, and language/help/notification/account commands remain fixed icon controls without overlap. Shared content padding contracts so domain workspaces retain usable width. | Accepted | Core WebUI shell and all module workspaces |
|
||||||
|
| UX-031 | Public controls and extension contributions use stable, module-namespaced interface identities. Shared controls expose `interfaceId` and `helpTopicId`; generated source anchors are inventory evidence, not a substitute for an explicit ID when documentation, policy, or automation refers to the control. | Accepted | Core and module WebUIs |
|
||||||
|
| UX-032 | `F1` resolves help from the focused field or action, then its dialog/section/page and registered route. Focused contexts retain the page fallback; Docs applies audience and permission filtering and falls back to visible module documentation. | Accepted | Core shell, Docs, and all module WebUIs |
|
||||||
|
| UX-033 | Global search is the left-most titlebar command, immediately before language selection. Its icon, `F3`, and `Ctrl`/`Cmd`+`K` all open the same permission-aware search overlay; the titlebar does not reserve a persistent query field. | Accepted | Core shell and Search WebUI |
|
||||||
|
| UX-034 | Every headed `PageLayout` declares one of `overview`, `collection`, `detail`, `editor`, or `workspace` independently from its standalone/workspace/embedded geometry. Its actions use the matching semantic `PageActionBar`: a refreshable page must provide Reload in the leading slot; collections keep Create far right; read-only pages do not invent Save. | Accepted | Core and all module WebUIs |
|
||||||
|
| UX-035 | Editor action bars expose clean, dirty, and saving state; always retain Discard immediately before the far-right Save; centrally disable both while clean or saving; and participate in the unsaved-change navigation guard. Danger actions occupy the explicit separated destructive group after ordinary actions and before editor persistence. | Accepted | Core and all module WebUIs |
|
||||||
|
|
||||||
## Confirmed Implementation Decisions
|
## Confirmed Implementation Decisions
|
||||||
|
|
||||||
@@ -156,14 +165,19 @@ Decision: the WebUI shell exposes a small, stable appearance contract based on
|
|||||||
shared CSS tokens and persisted user preference selection.
|
shared CSS tokens and persisted user preference selection.
|
||||||
|
|
||||||
- Core applies `system`, `light`, and `dark` preferences at the document root.
|
- Core applies `system`, `light`, and `dark` preferences at the document root.
|
||||||
|
- Core applies validated user accent presets through `data-palette`; palette
|
||||||
|
values change semantic tokens globally and never require module CSS changes.
|
||||||
- Core owns shared tokens such as `--bg`, `--bar`, `--panel`, `--surface`,
|
- Core owns shared tokens such as `--bg`, `--bar`, `--panel`, `--surface`,
|
||||||
`--line`, `--line-dark`, `--text`, `--text-strong`, `--muted`, semantic
|
`--line`, `--line-dark`, `--text`, `--text-strong`, `--muted`, semantic
|
||||||
status colors, radii, shadows, and disabled-control colors.
|
status colors, radii, shadows, and disabled-control colors.
|
||||||
- Modules must style new UI with these tokens and shared controls. Module-local
|
- Modules must style new UI with these tokens and shared controls. Module-local
|
||||||
CSS may tune layout and spacing, but it must not introduce a separate
|
CSS may tune layout and spacing, but it must not introduce a separate
|
||||||
appearance system.
|
appearance system.
|
||||||
- Appearance controls live in user settings first. Tenant defaults and policy
|
- Appearance controls live in user settings. A personal palette wins over
|
||||||
enforcement can be added later without changing the token contract.
|
unlocked tenant and system defaults; system and tenant locks take precedence.
|
||||||
|
Advanced personal token overrides additionally require system opt-in and may
|
||||||
|
be narrowed by tenant policy. Their versioned import/export document is
|
||||||
|
validated and applied all-or-nothing in both light and dark modes.
|
||||||
- Visual preview in settings is illustrative; it must reflect token families,
|
- Visual preview in settings is illustrative; it must reflect token families,
|
||||||
not become a second theme implementation.
|
not become a second theme implementation.
|
||||||
|
|
||||||
@@ -223,6 +237,10 @@ instead of reproducing their behavior.
|
|||||||
- `help` content is contextual guidance, not the accessible name. The persisted
|
- `help` content is contextual guidance, not the accessible name. The persisted
|
||||||
`show_inline_help_hints` user preference hides only the `InlineHelp` marker by
|
`show_inline_help_hints` user preference hides only the `InlineHelp` marker by
|
||||||
applying `ui-hide-help-hints` at the document root.
|
applying `ui-hide-help-hints` at the document root.
|
||||||
|
- Shared action-bearing components accept an optional disabled reason. In
|
||||||
|
particular, `MailServerSettingsPanel` forwards protocol-specific test
|
||||||
|
blockers into the shared focusable disabled-action tooltip; modules provide
|
||||||
|
the domain-specific required field, permission, or in-progress reason.
|
||||||
- A dirty editor registers once with `useUnsavedDraftGuard`. An explicit
|
- A dirty editor registers once with `useUnsavedDraftGuard`. An explicit
|
||||||
Discard button calls `useUnsavedChanges().requestDiscard(afterResolve)`; SPA
|
Discard button calls `useUnsavedChanges().requestDiscard(afterResolve)`; SPA
|
||||||
navigation uses `useGuardedNavigate` or `requestNavigation`. Both paths show
|
navigation uses `useGuardedNavigate` or `requestNavigation`. Both paths show
|
||||||
@@ -272,7 +290,7 @@ UI documentation until a central cross-repository audit is available.
|
|||||||
|
|
||||||
| Core scope | Why `FieldLabel` is omitted | Accessible/context label source |
|
| Core scope | Why `FieldLabel` is omitted | Accessible/context label source |
|
||||||
| --- | --- | --- |
|
| --- | --- | --- |
|
||||||
| `PasswordField`, `ColorPickerField`, `DateField`, `TimeField`, and `DateTimeField` input internals | These are label-neutral composite primitives and are placed inside `FormField`/`FieldLabel` by the consuming form. Rendering another label inside the primitive would duplicate it. | Enclosing label; a direct consumer must pass an accessible name and record that direct composition here. |
|
| `PasswordField`, `ColorPickerField`, `DateField`, `TimeField`, and `DateTimeField` input internals | These are label-neutral composite primitives and are placed inside `FormField`/`FieldLabel` by the consuming form. Rendering another label inside the primitive would duplicate it. `PasswordField` may opt into the shared cryptographic generator; the candidate dialog is subordinate to the enclosing field and commits only through its explicit Use action. | Enclosing label; a direct consumer must pass an accessible name and record that direct composition here. |
|
||||||
| `ToggleSwitch` native checkbox | The shared component already renders its visible text through `FieldLabel`; the native input must not render a second label. | The enclosing native label and derived `aria-label`. |
|
| `ToggleSwitch` native checkbox | The shared component already renders its visible text through `FieldLabel`; the native input must not render a second label. | The enclosing native label and derived `aria-label`. |
|
||||||
| `FileDropZone` hidden file input | The input is an implementation detail of the labelled keyboard-operable drop target. | Drop target text and `inputLabel`/`aria-label`. |
|
| `FileDropZone` hidden file input | The input is an implementation detail of the labelled keyboard-operable drop target. | Drop target text and `inputLabel`/`aria-label`. |
|
||||||
| `AdminSelectionList` and `DataGrid` list-filter checkboxes | Each option is self-explanatory and already enclosed by its visible option label. | Enclosing native option label. |
|
| `AdminSelectionList` and `DataGrid` list-filter checkboxes | Each option is self-explanatory and already enclosed by its visible option label. | Enclosing native option label. |
|
||||||
@@ -303,14 +321,14 @@ converted or reviewed.
|
|||||||
|
|
||||||
| Surface | Repository | UX State | Next Action |
|
| Surface | Repository | UX State | Next Action |
|
||||||
| --- | --- | --- | --- |
|
| --- | --- | --- | --- |
|
||||||
| File connector settings | `govoplan-files` | First adaptive modal slice started: connections and credentials now use full-state create/edit forms with conditional fields, advanced panels, and blocker primitives. Wizard shell is retained for later assisted setup. Central policy card still needs a layered editor. | Finish provider discovery/test-in-flow, then convert policy editing. |
|
| File connector settings | `govoplan-files` | Migrated to the shared adaptive server/credential/policy pattern with provider discovery, typed controls, actionable blockers, consequence-aware removal, and module-owned verification evidence. | Continue only through bounded Files-owned follow-ups. |
|
||||||
| Mail server settings | `govoplan-mail` / `govoplan-core` | Uses the shared server/credential model visually, but create/edit still needs the same adaptive pattern as files. | Migrate to adaptive server/credential/policy dialogs, with optional assisted wizard later. |
|
| Mail server settings | `govoplan-mail` / `govoplan-core` | Migrated to the same layered profile/server/credential/policy pattern, including focused connection tests, unsaved-state handling, contextual help, and permission/target blockers. | Continue only through bounded Mail-owned follow-ups. |
|
||||||
| Connector policy/effective rows | `govoplan-core`, module UIs | Effective-policy direction exists, but many editors still expose broad option sets. | Put effective value first, move overrides into modal, and explain blocked edits. |
|
| Connector policy/effective rows | `govoplan-core`, module UIs | Effective-policy direction exists, but many editors still expose broad option sets. | Put effective value first, move overrides into modal, and explain blocked edits. |
|
||||||
| Admin module management | `govoplan-admin` | Has preflight concepts, but operational choices are still technical and dense. | Convert install/uninstall/package changes to operator wizards. |
|
| Admin module management | `govoplan-admin` | Has preflight concepts, but operational choices are still technical and dense. | Convert install/uninstall/package changes to operator wizards. |
|
||||||
| Configuration packages | `govoplan-admin` | Catalog/import work exists, but package editing can still drift toward technical fields. | Add guided import/review/problem-list flow. |
|
| Configuration packages | `govoplan-admin` | Catalog/import work exists, but package editing can still drift toward technical fields. | Add guided import/review/problem-list flow. |
|
||||||
| Retention and privacy | `govoplan-core` | Functional editor exists; consequence language and provenance can be stronger. | Layer advanced retention options and add review for broad changes. |
|
| Retention and privacy | `govoplan-core` | Typed effective-policy editor exposes source paths, narrowing semantics, platform locks, permission/target blockers, and explicit clean/loading/save states. | Broader governed-change review remains module-owned where a policy change requires approval. |
|
||||||
| API keys | `govoplan-access` / admin UI | Security-sensitive creation needs least-privilege guidance. | Add scoped creation wizard with expiry/owner review. |
|
| API keys | `govoplan-access` / admin UI | Security-sensitive creation needs least-privilege guidance. | Add scoped creation wizard with expiry/owner review. |
|
||||||
| User settings | `govoplan-core` | Preferences persistence exists; interface navigation issue was fixed earlier, but the surface still needs UX review. | Keep simple sections, remove double-click traps, and add quiet explanations. |
|
| User settings | `govoplan-core` | Simple typed sections use unsaved-change guards, quiet result feedback, contextual help, explicit busy/clean disabled-action reasons, and an effective appearance source. Palette selection and light/dark preview are shared with system and tenant administration. | Keep bounded; new contributed sections must satisfy the checklist. |
|
||||||
|
|
||||||
## Impact Index
|
## Impact Index
|
||||||
|
|
||||||
@@ -326,7 +344,7 @@ converted or reviewed.
|
|||||||
| Automation/workflow commands | Hidden side effects would undermine accountability. | Action/effect preview, system-actor display, command record, retry/quarantine/manual states, and audit links. |
|
| Automation/workflow commands | Hidden side effects would undermine accountability. | Action/effect preview, system-actor display, command record, retry/quarantine/manual states, and audit links. |
|
||||||
| Postbox and encrypted communication | Retraction and access can be misunderstood. | Honest key-fetch/decryption state, expiry limits, recipient/device access provenance, and delivery evidence. |
|
| Postbox and encrypted communication | Retraction and access can be misunderstood. | Honest key-fetch/decryption state, expiry limits, recipient/device access provenance, and delivery evidence. |
|
||||||
| API keys | Security-sensitive creation and scope selection. | Scoped creation wizard, least-privilege suggestions, clear expiry/owner explanation. |
|
| API keys | Security-sensitive creation and scope selection. | Scoped creation wizard, least-privilege suggestions, clear expiry/owner explanation. |
|
||||||
| User settings | Needs clarity and persistence across profile/interface/preferences. | Simple settings sections with immediate feedback and no double-click navigation traps. |
|
| User settings | Needs clarity and persistence across profile/interface/preferences. | Simple settings sections with immediate feedback, explicit inherit/reset semantics, effective-source provenance, and no double-click navigation traps. |
|
||||||
|
|
||||||
## Review Checklist
|
## Review Checklist
|
||||||
|
|
||||||
@@ -339,6 +357,11 @@ Every new or changed admin/configuration surface should answer:
|
|||||||
- Does the screen explain disabled actions and failed validation in plain
|
- Does the screen explain disabled actions and failed validation in plain
|
||||||
language?
|
language?
|
||||||
- Does it say who can fix a blocker and where?
|
- Does it say who can fix a blocker and where?
|
||||||
|
- Does a module-localized blocker pass its translated row labels through the
|
||||||
|
shared `ActionBlockerHint` contract instead of reproducing the component?
|
||||||
|
- Does longer field or blocker guidance use a stable `DocumentationHelpLink`
|
||||||
|
topic/context reference, with hosted fallback when the optional Docs module
|
||||||
|
is absent?
|
||||||
- Does it reuse existing core patterns for wizard steps, problem lists, modals,
|
- Does it reuse existing core patterns for wizard steps, problem lists, modals,
|
||||||
help, and review?
|
help, and review?
|
||||||
- Is there a review or preflight step before broad, destructive, or risky
|
- Is there a review or preflight step before broad, destructive, or risky
|
||||||
|
|||||||
@@ -0,0 +1,12 @@
|
|||||||
|
# WebUI Module Package Layout
|
||||||
|
|
||||||
|
Core discovers a module contribution from `src/module.ts` when `node_modules`
|
||||||
|
links directly to a module's `webui` package. Tagged release dependencies are
|
||||||
|
installed from repository-root packages and expose the same contribution at
|
||||||
|
`webui/src/module.ts`. The Vite registry accepts both layouts and imports the
|
||||||
|
contribution descriptor directly so route-level lazy loading is preserved.
|
||||||
|
|
||||||
|
A release package is invalid if neither entry exists. The module-permutation CI
|
||||||
|
matrix builds source-linked and installed release compositions; it must not fall
|
||||||
|
back to a package root barrel because that would eagerly pull module pages into
|
||||||
|
the shell bundle.
|
||||||
File diff suppressed because it is too large
Load Diff
+5
-3
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
|||||||
|
|
||||||
[project]
|
[project]
|
||||||
name = "govoplan-core"
|
name = "govoplan-core"
|
||||||
version = "0.1.14"
|
version = "0.1.38"
|
||||||
description = "Reusable GovOPlaN platform core, access, tenancy, and RBAC components."
|
description = "Reusable GovOPlaN platform core, access, tenancy, and RBAC components."
|
||||||
readme = "README.md"
|
readme = "README.md"
|
||||||
requires-python = ">=3.12"
|
requires-python = ">=3.12"
|
||||||
@@ -15,17 +15,18 @@ dependencies = [
|
|||||||
"fastapi>=0.139,<1",
|
"fastapi>=0.139,<1",
|
||||||
"pydantic>=2,<3",
|
"pydantic>=2,<3",
|
||||||
"pydantic-settings>=2,<3",
|
"pydantic-settings>=2,<3",
|
||||||
"cryptography>=48.0.1,<50",
|
"cryptography>=50.0.0,<51",
|
||||||
"celery>=5,<6",
|
"celery>=5,<6",
|
||||||
"redis>=5,<6",
|
"redis>=5,<6",
|
||||||
"alembic>=1,<2",
|
"alembic>=1,<2",
|
||||||
|
"boto3>=1.34,<2",
|
||||||
]
|
]
|
||||||
|
|
||||||
[tool.setuptools.packages.find]
|
[tool.setuptools.packages.find]
|
||||||
where = ["src"]
|
where = ["src"]
|
||||||
|
|
||||||
[tool.setuptools.package-data]
|
[tool.setuptools.package-data]
|
||||||
govoplan_core = ["py.typed"]
|
govoplan_core = ["py.typed", "resources/*.json"]
|
||||||
|
|
||||||
[tool.setuptools.data-files]
|
[tool.setuptools.data-files]
|
||||||
"govoplan_core_runtime" = ["alembic.ini"]
|
"govoplan_core_runtime" = ["alembic.ini"]
|
||||||
@@ -36,6 +37,7 @@ govoplan_core = ["py.typed"]
|
|||||||
[project.scripts]
|
[project.scripts]
|
||||||
govoplan-config = "govoplan_core.commands.config:main"
|
govoplan-config = "govoplan_core.commands.config:main"
|
||||||
govoplan-devserver = "govoplan_core.devserver:main"
|
govoplan-devserver = "govoplan_core.devserver:main"
|
||||||
|
govoplan-first-admin = "govoplan_core.commands.first_admin:main"
|
||||||
govoplan-module-install-plan = "govoplan_core.commands.module_install_plan:main"
|
govoplan-module-install-plan = "govoplan_core.commands.module_install_plan:main"
|
||||||
govoplan-module-installer = "govoplan_core.commands.module_installer:main"
|
govoplan-module-installer = "govoplan_core.commands.module_installer:main"
|
||||||
|
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ class SystemSettings(Base, TimestampMixin):
|
|||||||
__tablename__ = "core_system_settings"
|
__tablename__ = "core_system_settings"
|
||||||
|
|
||||||
id: Mapped[str] = mapped_column(String(36), primary_key=True, default="global")
|
id: Mapped[str] = mapped_column(String(36), primary_key=True, default="global")
|
||||||
default_locale: Mapped[str] = mapped_column(String(20), default="en", nullable=False)
|
default_locale: Mapped[str] = mapped_column(String(20), default="de", nullable=False)
|
||||||
allow_tenant_custom_groups: Mapped[bool] = mapped_column(Boolean, default=True, nullable=False)
|
allow_tenant_custom_groups: Mapped[bool] = mapped_column(Boolean, default=True, nullable=False)
|
||||||
allow_tenant_custom_roles: Mapped[bool] = mapped_column(Boolean, default=True, nullable=False)
|
allow_tenant_custom_roles: Mapped[bool] = mapped_column(Boolean, default=True, nullable=False)
|
||||||
allow_tenant_api_keys: Mapped[bool] = mapped_column(Boolean, default=True, nullable=False)
|
allow_tenant_api_keys: Mapped[bool] = mapped_column(Boolean, default=True, nullable=False)
|
||||||
@@ -20,4 +20,3 @@ class SystemSettings(Base, TimestampMixin):
|
|||||||
|
|
||||||
|
|
||||||
__all__ = ["SystemSettings"]
|
__all__ = ["SystemSettings"]
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,9 @@ from __future__ import annotations
|
|||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from typing import Any, Literal
|
from typing import Any, Literal
|
||||||
|
|
||||||
from pydantic import BaseModel, ConfigDict, Field
|
from pydantic import BaseModel, ConfigDict, Field, model_validator
|
||||||
|
|
||||||
|
from govoplan_core.core.appearance import normalize_appearance_overrides
|
||||||
|
|
||||||
|
|
||||||
class AuditLogItemResponse(BaseModel):
|
class AuditLogItemResponse(BaseModel):
|
||||||
@@ -73,12 +75,18 @@ class SwitchTenantRequest(BaseModel):
|
|||||||
tenant_id: str
|
tenant_id: str
|
||||||
|
|
||||||
|
|
||||||
|
class SwitchActingContextRequest(BaseModel):
|
||||||
|
model_config = ConfigDict(extra="forbid")
|
||||||
|
|
||||||
|
assignment_id: str | None = Field(default=None, max_length=36)
|
||||||
|
|
||||||
|
|
||||||
class TenantInfo(BaseModel):
|
class TenantInfo(BaseModel):
|
||||||
id: str
|
id: str
|
||||||
slug: str
|
slug: str
|
||||||
name: str
|
name: str
|
||||||
is_active: bool = True
|
is_active: bool = True
|
||||||
default_locale: str = "en"
|
default_locale: str = "de"
|
||||||
enabled_language_codes: list[str] = Field(default_factory=list)
|
enabled_language_codes: list[str] = Field(default_factory=list)
|
||||||
|
|
||||||
|
|
||||||
@@ -87,6 +95,45 @@ class TenantMembershipInfo(TenantInfo):
|
|||||||
is_active: bool = True
|
is_active: bool = True
|
||||||
|
|
||||||
|
|
||||||
|
class NavigationPreferencesPayload(BaseModel):
|
||||||
|
model_config = ConfigDict(extra="forbid")
|
||||||
|
|
||||||
|
contract_version: Literal["1"] = "1"
|
||||||
|
order: list[str] = Field(default_factory=list, max_length=256)
|
||||||
|
hidden: list[str] = Field(default_factory=list, max_length=256)
|
||||||
|
locked: list[str] = Field(default_factory=list, max_length=256)
|
||||||
|
|
||||||
|
|
||||||
|
class AppearanceModeOverrides(BaseModel):
|
||||||
|
model_config = ConfigDict(extra="forbid")
|
||||||
|
|
||||||
|
accent: str
|
||||||
|
accent_foreground: str
|
||||||
|
surface: str
|
||||||
|
surface_foreground: str
|
||||||
|
success: str
|
||||||
|
success_foreground: str
|
||||||
|
info: str
|
||||||
|
info_foreground: str
|
||||||
|
warning: str
|
||||||
|
warning_foreground: str
|
||||||
|
danger: str
|
||||||
|
danger_foreground: str
|
||||||
|
|
||||||
|
|
||||||
|
class AppearanceOverridesDocument(BaseModel):
|
||||||
|
model_config = ConfigDict(extra="forbid")
|
||||||
|
|
||||||
|
schema_version: Literal["1"] = "1"
|
||||||
|
light: AppearanceModeOverrides
|
||||||
|
dark: AppearanceModeOverrides
|
||||||
|
|
||||||
|
@model_validator(mode="after")
|
||||||
|
def validate_accessibility(self) -> "AppearanceOverridesDocument":
|
||||||
|
normalize_appearance_overrides(self.model_dump(mode="json"))
|
||||||
|
return self
|
||||||
|
|
||||||
|
|
||||||
class UserUiPreferences(BaseModel):
|
class UserUiPreferences(BaseModel):
|
||||||
model_config = ConfigDict(extra="ignore")
|
model_config = ConfigDict(extra="ignore")
|
||||||
|
|
||||||
@@ -95,6 +142,20 @@ class UserUiPreferences(BaseModel):
|
|||||||
reduce_motion: bool = False
|
reduce_motion: bool = False
|
||||||
sticky_section_sidebars: bool = True
|
sticky_section_sidebars: bool = True
|
||||||
theme: Literal["system", "light", "dark"] = "system"
|
theme: Literal["system", "light", "dark"] = "system"
|
||||||
|
palette: Literal["default", "civic_blue", "forest", "plum"] | None = None
|
||||||
|
appearance_overrides: AppearanceOverridesDocument | None = None
|
||||||
|
navigation: NavigationPreferencesPayload | None = None
|
||||||
|
|
||||||
|
|
||||||
|
class EffectiveAppearanceInfo(BaseModel):
|
||||||
|
palette: Literal["default", "civic_blue", "forest", "plum"] = "default"
|
||||||
|
source: Literal["user", "tenant", "system", "tenant_lock", "system_lock"] = "system"
|
||||||
|
locked: bool = False
|
||||||
|
system_default_palette: Literal["default", "civic_blue", "forest", "plum"] = "default"
|
||||||
|
tenant_default_palette: Literal["default", "civic_blue", "forest", "plum"] | None = None
|
||||||
|
inherited_palette: Literal["default", "civic_blue", "forest", "plum"] = "default"
|
||||||
|
custom_overrides: AppearanceOverridesDocument | None = None
|
||||||
|
custom_overrides_allowed: bool = False
|
||||||
|
|
||||||
|
|
||||||
class UserInfo(BaseModel):
|
class UserInfo(BaseModel):
|
||||||
@@ -110,6 +171,7 @@ class UserInfo(BaseModel):
|
|||||||
preferred_language: str | None = None
|
preferred_language: str | None = None
|
||||||
enabled_language_codes: list[str] = Field(default_factory=list)
|
enabled_language_codes: list[str] = Field(default_factory=list)
|
||||||
ui_preferences: UserUiPreferences = Field(default_factory=UserUiPreferences)
|
ui_preferences: UserUiPreferences = Field(default_factory=UserUiPreferences)
|
||||||
|
appearance: EffectiveAppearanceInfo = Field(default_factory=EffectiveAppearanceInfo)
|
||||||
|
|
||||||
|
|
||||||
class AuthSessionUserInfo(BaseModel):
|
class AuthSessionUserInfo(BaseModel):
|
||||||
@@ -178,6 +240,7 @@ class PrincipalContextInfo(BaseModel):
|
|||||||
api_key_id: str | None = None
|
api_key_id: str | None = None
|
||||||
session_id: str | None = None
|
session_id: str | None = None
|
||||||
service_account_id: str | None = None
|
service_account_id: str | None = None
|
||||||
|
acting_assignment_id: str | None = None
|
||||||
acting_for_account_id: str | None = None
|
acting_for_account_id: str | None = None
|
||||||
email: str | None = None
|
email: str | None = None
|
||||||
display_name: str | None = None
|
display_name: str | None = None
|
||||||
@@ -203,7 +266,7 @@ class AuthProfileResponse(BaseModel):
|
|||||||
active_tenant: TenantInfo
|
active_tenant: TenantInfo
|
||||||
available_languages: list[LanguageInfo] = Field(default_factory=list)
|
available_languages: list[LanguageInfo] = Field(default_factory=list)
|
||||||
enabled_language_codes: list[str] = Field(default_factory=list)
|
enabled_language_codes: list[str] = Field(default_factory=list)
|
||||||
default_language: str = "en"
|
default_language: str = "de"
|
||||||
profile_loaded: bool = True
|
profile_loaded: bool = True
|
||||||
|
|
||||||
|
|
||||||
@@ -232,7 +295,7 @@ class LoginResponse(BaseModel):
|
|||||||
principal: PrincipalContextInfo | None = None
|
principal: PrincipalContextInfo | None = None
|
||||||
available_languages: list[LanguageInfo] = Field(default_factory=list)
|
available_languages: list[LanguageInfo] = Field(default_factory=list)
|
||||||
enabled_language_codes: list[str] = Field(default_factory=list)
|
enabled_language_codes: list[str] = Field(default_factory=list)
|
||||||
default_language: str = "en"
|
default_language: str = "de"
|
||||||
profile_loaded: bool = True
|
profile_loaded: bool = True
|
||||||
roles_loaded: bool = True
|
roles_loaded: bool = True
|
||||||
groups_loaded: bool = True
|
groups_loaded: bool = True
|
||||||
@@ -250,7 +313,7 @@ class MeResponse(BaseModel):
|
|||||||
principal: PrincipalContextInfo | None = None
|
principal: PrincipalContextInfo | None = None
|
||||||
available_languages: list[LanguageInfo] = Field(default_factory=list)
|
available_languages: list[LanguageInfo] = Field(default_factory=list)
|
||||||
enabled_language_codes: list[str] = Field(default_factory=list)
|
enabled_language_codes: list[str] = Field(default_factory=list)
|
||||||
default_language: str = "en"
|
default_language: str = "de"
|
||||||
profile_loaded: bool = True
|
profile_loaded: bool = True
|
||||||
roles_loaded: bool = True
|
roles_loaded: bool = True
|
||||||
groups_loaded: bool = True
|
groups_loaded: bool = True
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ from govoplan_core.core.events import (
|
|||||||
normalize_trace_id,
|
normalize_trace_id,
|
||||||
emit_platform_event,
|
emit_platform_event,
|
||||||
)
|
)
|
||||||
|
from govoplan_core.core.institutional import GovernedContextEnvelope
|
||||||
from govoplan_core.core.runtime import get_registry
|
from govoplan_core.core.runtime import get_registry
|
||||||
from govoplan_core.privacy.retention import sanitize_audit_details_for_policy
|
from govoplan_core.privacy.retention import sanitize_audit_details_for_policy
|
||||||
from govoplan_core.security.redaction import redact_secret_values
|
from govoplan_core.security.redaction import redact_secret_values
|
||||||
@@ -176,6 +177,16 @@ def _publish_audit_platform_event(
|
|||||||
item: AuditRecordRef,
|
item: AuditRecordRef,
|
||||||
) -> None:
|
) -> None:
|
||||||
trace = _compact_trace(item.details.get("_trace") if isinstance(item.details, Mapping) else None)
|
trace = _compact_trace(item.details.get("_trace") if isinstance(item.details, Mapping) else None)
|
||||||
|
raw_context = (
|
||||||
|
item.details.get("_institutional_context")
|
||||||
|
if isinstance(item.details, Mapping)
|
||||||
|
else None
|
||||||
|
)
|
||||||
|
institutional_context = (
|
||||||
|
GovernedContextEnvelope.from_mapping(raw_context)
|
||||||
|
if isinstance(raw_context, Mapping)
|
||||||
|
else None
|
||||||
|
)
|
||||||
emit_platform_event(
|
emit_platform_event(
|
||||||
session,
|
session,
|
||||||
PlatformEvent(
|
PlatformEvent(
|
||||||
@@ -194,6 +205,7 @@ def _publish_audit_platform_event(
|
|||||||
tenant=EventTenantRef(id=item.tenant_id) if item.tenant_id else None,
|
tenant=EventTenantRef(id=item.tenant_id) if item.tenant_id else None,
|
||||||
resource=EventObjectRef(type=item.object_type, id=item.object_id) if item.object_type else None,
|
resource=EventObjectRef(type=item.object_type, id=item.object_id) if item.object_type else None,
|
||||||
classification="internal",
|
classification="internal",
|
||||||
|
institutional_context=institutional_context,
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -211,6 +223,7 @@ def audit_event(
|
|||||||
details: dict[str, Any] | None = None,
|
details: dict[str, Any] | None = None,
|
||||||
correlation_id: str | None = None,
|
correlation_id: str | None = None,
|
||||||
causation_id: str | None = None,
|
causation_id: str | None = None,
|
||||||
|
institutional_context: GovernedContextEnvelope | None = None,
|
||||||
commit: bool = False,
|
commit: bool = False,
|
||||||
) -> AuditRecordRef:
|
) -> AuditRecordRef:
|
||||||
"""Persist one audit event.
|
"""Persist one audit event.
|
||||||
@@ -223,8 +236,17 @@ def audit_event(
|
|||||||
if scope not in {"tenant", "system"}:
|
if scope not in {"tenant", "system"}:
|
||||||
raise ValueError(f"Unsupported audit scope: {scope}")
|
raise ValueError(f"Unsupported audit scope: {scope}")
|
||||||
|
|
||||||
|
if (
|
||||||
|
institutional_context is not None
|
||||||
|
and tenant_id is not None
|
||||||
|
and institutional_context.tenant_id != tenant_id
|
||||||
|
):
|
||||||
|
raise ValueError("Audit institutional context belongs to another tenant")
|
||||||
|
raw_details = dict(details or {})
|
||||||
|
if institutional_context is not None:
|
||||||
|
raw_details["_institutional_context"] = institutional_context.to_dict()
|
||||||
traced_details, trace = _trace_details(
|
traced_details, trace = _trace_details(
|
||||||
_sanitize_details(details or {}),
|
_sanitize_details(raw_details),
|
||||||
correlation_id=correlation_id,
|
correlation_id=correlation_id,
|
||||||
causation_id=causation_id,
|
causation_id=causation_id,
|
||||||
)
|
)
|
||||||
@@ -242,6 +264,7 @@ def audit_event(
|
|||||||
api_key_id=api_key_id,
|
api_key_id=api_key_id,
|
||||||
resource_type=object_type,
|
resource_type=object_type,
|
||||||
resource_id=object_id,
|
resource_id=object_id,
|
||||||
|
institutional_context=institutional_context,
|
||||||
details=stored_details,
|
details=stored_details,
|
||||||
))
|
))
|
||||||
record_change(
|
record_change(
|
||||||
@@ -273,6 +296,7 @@ def audit_from_principal(
|
|||||||
details: dict[str, Any] | None = None,
|
details: dict[str, Any] | None = None,
|
||||||
correlation_id: str | None = None,
|
correlation_id: str | None = None,
|
||||||
causation_id: str | None = None,
|
causation_id: str | None = None,
|
||||||
|
institutional_context: GovernedContextEnvelope | None = None,
|
||||||
commit: bool = False,
|
commit: bool = False,
|
||||||
) -> AuditRecordRef:
|
) -> AuditRecordRef:
|
||||||
return audit_event(
|
return audit_event(
|
||||||
@@ -287,5 +311,6 @@ def audit_from_principal(
|
|||||||
details=details,
|
details=details,
|
||||||
correlation_id=correlation_id,
|
correlation_id=correlation_id,
|
||||||
causation_id=causation_id,
|
causation_id=causation_id,
|
||||||
|
institutional_context=institutional_context,
|
||||||
commit=commit,
|
commit=commit,
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -81,6 +81,10 @@ class ApiPrincipal:
|
|||||||
def acting_for_account_id(self) -> str | None:
|
def acting_for_account_id(self) -> str | None:
|
||||||
return self.principal.acting_for_account_id
|
return self.principal.acting_for_account_id
|
||||||
|
|
||||||
|
@property
|
||||||
|
def acting_assignment_id(self) -> str | None:
|
||||||
|
return self.principal.acting_assignment_id
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def auth_method(self) -> str:
|
def auth_method(self) -> str:
|
||||||
return self.principal.auth_method
|
return self.principal.auth_method
|
||||||
@@ -131,6 +135,9 @@ def get_api_principal(
|
|||||||
authorization: str | None = Header(default=None),
|
authorization: str | None = Header(default=None),
|
||||||
x_api_key: str | None = Header(default=None, alias="X-API-Key"),
|
x_api_key: str | None = Header(default=None, alias="X-API-Key"),
|
||||||
) -> ApiPrincipal:
|
) -> ApiPrincipal:
|
||||||
|
cached = getattr(request.state, "govoplan_api_principal", None)
|
||||||
|
if isinstance(cached, ApiPrincipal):
|
||||||
|
return cached
|
||||||
principal = _api_principal_provider_from_request(request).resolve_api_principal(
|
principal = _api_principal_provider_from_request(request).resolve_api_principal(
|
||||||
request,
|
request,
|
||||||
session,
|
session,
|
||||||
@@ -139,6 +146,7 @@ def get_api_principal(
|
|||||||
)
|
)
|
||||||
if not isinstance(principal, ApiPrincipal):
|
if not isinstance(principal, ApiPrincipal):
|
||||||
raise HTTPException(status_code=status.HTTP_500_INTERNAL_SERVER_ERROR, detail="Invalid API principal")
|
raise HTTPException(status_code=status.HTTP_500_INTERNAL_SERVER_ERROR, detail="Invalid API principal")
|
||||||
|
request.state.govoplan_api_principal = principal
|
||||||
return principal
|
return principal
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
+1060
-155
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,199 @@
|
|||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
import argparse
|
||||||
|
from importlib.metadata import PackageNotFoundError, version
|
||||||
|
import signal
|
||||||
|
import subprocess
|
||||||
|
import sys
|
||||||
|
import threading
|
||||||
|
import time
|
||||||
|
from typing import Sequence
|
||||||
|
|
||||||
|
from govoplan_core.core.runtime_coordination import (
|
||||||
|
LeaseClaim,
|
||||||
|
acquire_lease,
|
||||||
|
release_lease,
|
||||||
|
renew_lease,
|
||||||
|
runtime_identity,
|
||||||
|
)
|
||||||
|
from govoplan_core.db.session import configure_database, get_database
|
||||||
|
from govoplan_core.settings import settings
|
||||||
|
|
||||||
|
|
||||||
|
def build_parser() -> argparse.ArgumentParser:
|
||||||
|
parser = argparse.ArgumentParser(
|
||||||
|
description="Run one process while holding a database-fenced deployment lease."
|
||||||
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
"--resource", required=True, help="Stable cluster-wide lease key."
|
||||||
|
)
|
||||||
|
parser.add_argument("--ttl-seconds", type=int, default=60)
|
||||||
|
parser.add_argument("--renew-seconds", type=int, default=15)
|
||||||
|
parser.add_argument("--wait-seconds", type=int, default=0)
|
||||||
|
parser.add_argument("command", nargs=argparse.REMAINDER)
|
||||||
|
return parser
|
||||||
|
|
||||||
|
|
||||||
|
def main(argv: Sequence[str] | None = None) -> int:
|
||||||
|
args = build_parser().parse_args(argv)
|
||||||
|
command = list(args.command)
|
||||||
|
if command and command[0] == "--":
|
||||||
|
command.pop(0)
|
||||||
|
if not command:
|
||||||
|
raise SystemExit("fenced-run requires a command after --")
|
||||||
|
if args.ttl_seconds < 10:
|
||||||
|
raise SystemExit("--ttl-seconds must be at least 10")
|
||||||
|
if args.renew_seconds < 2 or args.renew_seconds * 2 >= args.ttl_seconds:
|
||||||
|
raise SystemExit("--renew-seconds must be less than half the lease TTL")
|
||||||
|
configure_database(settings.database_url)
|
||||||
|
identity = runtime_identity(
|
||||||
|
settings,
|
||||||
|
software_version=_core_version(),
|
||||||
|
role=str(settings.runtime_role or "deployment"),
|
||||||
|
)
|
||||||
|
claim = _wait_for_lease(
|
||||||
|
resource=args.resource,
|
||||||
|
identity=identity,
|
||||||
|
ttl_seconds=args.ttl_seconds,
|
||||||
|
wait_seconds=max(0, args.wait_seconds),
|
||||||
|
)
|
||||||
|
if claim is None:
|
||||||
|
print(
|
||||||
|
f"lease unavailable: {args.resource}",
|
||||||
|
file=sys.stderr,
|
||||||
|
)
|
||||||
|
return 75
|
||||||
|
|
||||||
|
process = subprocess.Popen(command) # noqa: S603 - argv is an operator-owned container command
|
||||||
|
stop = threading.Event()
|
||||||
|
fence_lost = threading.Event()
|
||||||
|
renewer = threading.Thread(
|
||||||
|
target=_renew_loop,
|
||||||
|
kwargs={
|
||||||
|
"claim": claim,
|
||||||
|
"ttl_seconds": args.ttl_seconds,
|
||||||
|
"renew_seconds": args.renew_seconds,
|
||||||
|
"stop": stop,
|
||||||
|
"fence_lost": fence_lost,
|
||||||
|
"process": process,
|
||||||
|
},
|
||||||
|
daemon=True,
|
||||||
|
name=f"govoplan-fence:{args.resource}",
|
||||||
|
)
|
||||||
|
renewer.start()
|
||||||
|
previous_handlers = _forward_signals(process)
|
||||||
|
try:
|
||||||
|
return_code = process.wait()
|
||||||
|
finally:
|
||||||
|
stop.set()
|
||||||
|
renewer.join(timeout=args.renew_seconds + 2)
|
||||||
|
_restore_signals(previous_handlers)
|
||||||
|
_release(claim)
|
||||||
|
if fence_lost.is_set():
|
||||||
|
return 74
|
||||||
|
return int(return_code)
|
||||||
|
|
||||||
|
|
||||||
|
def _wait_for_lease(
|
||||||
|
*,
|
||||||
|
resource: str,
|
||||||
|
identity,
|
||||||
|
ttl_seconds: int,
|
||||||
|
wait_seconds: int,
|
||||||
|
) -> LeaseClaim | None:
|
||||||
|
deadline = time.monotonic() + wait_seconds
|
||||||
|
while True:
|
||||||
|
with get_database().SessionLocal() as session:
|
||||||
|
claim = acquire_lease(
|
||||||
|
session,
|
||||||
|
installation_id=identity.installation_id,
|
||||||
|
resource_key=resource,
|
||||||
|
holder_node_id=identity.node_id,
|
||||||
|
holder_incarnation=identity.incarnation,
|
||||||
|
ttl_seconds=ttl_seconds,
|
||||||
|
metadata={"role": identity.role},
|
||||||
|
)
|
||||||
|
session.commit()
|
||||||
|
if claim is not None or time.monotonic() >= deadline:
|
||||||
|
return claim
|
||||||
|
time.sleep(min(2, max(0.1, deadline - time.monotonic())))
|
||||||
|
|
||||||
|
|
||||||
|
def _renew_loop(
|
||||||
|
*,
|
||||||
|
claim: LeaseClaim,
|
||||||
|
ttl_seconds: int,
|
||||||
|
renew_seconds: int,
|
||||||
|
stop: threading.Event,
|
||||||
|
fence_lost: threading.Event,
|
||||||
|
process: subprocess.Popen[bytes],
|
||||||
|
) -> None:
|
||||||
|
active_claim = claim
|
||||||
|
while not stop.wait(renew_seconds):
|
||||||
|
try:
|
||||||
|
with get_database().SessionLocal() as session:
|
||||||
|
active_claim = renew_lease(
|
||||||
|
session,
|
||||||
|
active_claim,
|
||||||
|
ttl_seconds=ttl_seconds,
|
||||||
|
)
|
||||||
|
session.commit()
|
||||||
|
except Exception: # noqa: BLE001 - any renewal failure loses authority
|
||||||
|
fence_lost.set()
|
||||||
|
_terminate_process(process)
|
||||||
|
return
|
||||||
|
|
||||||
|
|
||||||
|
def _terminate_process(
|
||||||
|
process: subprocess.Popen[bytes],
|
||||||
|
*,
|
||||||
|
timeout_seconds: float = 5.0,
|
||||||
|
) -> None:
|
||||||
|
if process.poll() is not None:
|
||||||
|
return
|
||||||
|
process.terminate()
|
||||||
|
try:
|
||||||
|
process.wait(timeout=timeout_seconds)
|
||||||
|
except subprocess.TimeoutExpired:
|
||||||
|
process.kill()
|
||||||
|
process.wait(timeout=timeout_seconds)
|
||||||
|
|
||||||
|
|
||||||
|
def _release(claim: LeaseClaim) -> None:
|
||||||
|
try:
|
||||||
|
with get_database().SessionLocal() as session:
|
||||||
|
release_lease(session, claim)
|
||||||
|
session.commit()
|
||||||
|
except Exception: # noqa: BLE001 - authority is already lost; release is best effort
|
||||||
|
return
|
||||||
|
|
||||||
|
|
||||||
|
def _forward_signals(
|
||||||
|
process: subprocess.Popen[bytes],
|
||||||
|
) -> dict[int, signal.Handlers]:
|
||||||
|
previous: dict[int, signal.Handlers] = {}
|
||||||
|
|
||||||
|
def forward(signum, _frame) -> None:
|
||||||
|
if process.poll() is None:
|
||||||
|
process.send_signal(signum)
|
||||||
|
|
||||||
|
for signum in (signal.SIGTERM, signal.SIGINT):
|
||||||
|
previous[signum] = signal.getsignal(signum)
|
||||||
|
signal.signal(signum, forward)
|
||||||
|
return previous
|
||||||
|
|
||||||
|
|
||||||
|
def _restore_signals(previous: dict[int, signal.Handlers]) -> None:
|
||||||
|
for signum, handler in previous.items():
|
||||||
|
signal.signal(signum, handler)
|
||||||
|
|
||||||
|
|
||||||
|
def _core_version() -> str:
|
||||||
|
try:
|
||||||
|
return version("govoplan-core")
|
||||||
|
except PackageNotFoundError:
|
||||||
|
return "development"
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
raise SystemExit(main())
|
||||||
@@ -0,0 +1,233 @@
|
|||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
import argparse
|
||||||
|
import json
|
||||||
|
import os
|
||||||
|
from pathlib import Path
|
||||||
|
import stat
|
||||||
|
from typing import Any
|
||||||
|
|
||||||
|
from govoplan_core.core.access import (
|
||||||
|
CAPABILITY_ACCESS_FIRST_ADMIN_PROVISIONER,
|
||||||
|
FirstAdminProvisioner,
|
||||||
|
)
|
||||||
|
from govoplan_core.core.first_admin import (
|
||||||
|
FirstAdminEnrollmentError,
|
||||||
|
first_admin_enrollment_status,
|
||||||
|
issue_first_admin_credential,
|
||||||
|
)
|
||||||
|
from govoplan_core.core.module_management import (
|
||||||
|
load_startup_enabled_modules,
|
||||||
|
startup_candidate_module_ids,
|
||||||
|
)
|
||||||
|
from govoplan_core.core.modules import ModuleContext
|
||||||
|
from govoplan_core.core.runtime import configure_runtime
|
||||||
|
from govoplan_core.db.session import configure_database, get_database
|
||||||
|
from govoplan_core.server.registry import (
|
||||||
|
available_module_manifests,
|
||||||
|
build_platform_registry,
|
||||||
|
)
|
||||||
|
from govoplan_core.settings import settings
|
||||||
|
|
||||||
|
|
||||||
|
def main() -> None:
|
||||||
|
parser = argparse.ArgumentParser(
|
||||||
|
description="Manage the single-use production first-administrator credential",
|
||||||
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
"command",
|
||||||
|
choices=("status", "issue", "recover"),
|
||||||
|
help="Inspect readiness, issue the initial credential, or rotate lost/expired material.",
|
||||||
|
)
|
||||||
|
parser.add_argument("--database-url", default=settings.database_url)
|
||||||
|
parser.add_argument("--installation-id", default=settings.installation_id)
|
||||||
|
parser.add_argument(
|
||||||
|
"--output",
|
||||||
|
type=Path,
|
||||||
|
default=Path(settings.first_admin_enrollment_file),
|
||||||
|
help="Root-readable/equivalent JSON credential artifact.",
|
||||||
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
"--ttl-seconds",
|
||||||
|
type=int,
|
||||||
|
default=settings.first_admin_enrollment_ttl_seconds,
|
||||||
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
"--reason",
|
||||||
|
default=None,
|
||||||
|
help="Audited local-operator reason for issue or recovery.",
|
||||||
|
)
|
||||||
|
args = parser.parse_args()
|
||||||
|
|
||||||
|
configure_database(args.database_url)
|
||||||
|
provisioner = _configure_first_admin_provisioner()
|
||||||
|
with get_database().SessionLocal() as session:
|
||||||
|
if args.command == "status":
|
||||||
|
enrollment = first_admin_enrollment_status(
|
||||||
|
session,
|
||||||
|
installation_id=args.installation_id,
|
||||||
|
provisioner=provisioner,
|
||||||
|
)
|
||||||
|
print(
|
||||||
|
json.dumps(
|
||||||
|
{
|
||||||
|
"installation_id": args.installation_id,
|
||||||
|
"enrollment_required": enrollment.enrollment_required,
|
||||||
|
"credential_active": enrollment.credential_active,
|
||||||
|
"state": enrollment.state,
|
||||||
|
"generation": enrollment.generation,
|
||||||
|
"expires_at": (
|
||||||
|
enrollment.expires_at.isoformat()
|
||||||
|
if enrollment.expires_at is not None
|
||||||
|
else None
|
||||||
|
),
|
||||||
|
"readiness": enrollment.readiness,
|
||||||
|
},
|
||||||
|
indent=2,
|
||||||
|
sort_keys=True,
|
||||||
|
)
|
||||||
|
)
|
||||||
|
return
|
||||||
|
|
||||||
|
reason = args.reason or (
|
||||||
|
"initial production administrator enrollment"
|
||||||
|
if args.command == "issue"
|
||||||
|
else "local operator recovery of first-administrator enrollment"
|
||||||
|
)
|
||||||
|
try:
|
||||||
|
credential = issue_first_admin_credential(
|
||||||
|
session,
|
||||||
|
installation_id=args.installation_id,
|
||||||
|
provisioner=provisioner,
|
||||||
|
ttl_seconds=args.ttl_seconds,
|
||||||
|
reason=reason,
|
||||||
|
replace_active=args.command == "recover",
|
||||||
|
)
|
||||||
|
payload = {
|
||||||
|
"schema_version": 1,
|
||||||
|
"installation_id": args.installation_id,
|
||||||
|
"endpoint": "/api/v1/bootstrap/first-admin",
|
||||||
|
"header": "X-GovOPlaN-Enrollment-Token",
|
||||||
|
"enrollment_token": credential.secret,
|
||||||
|
"fingerprint": credential.fingerprint,
|
||||||
|
"generation": credential.generation,
|
||||||
|
"expires_at": credential.expires_at.isoformat(),
|
||||||
|
}
|
||||||
|
previous = _secure_file_snapshot(args.output)
|
||||||
|
_write_private_json(args.output, payload)
|
||||||
|
try:
|
||||||
|
session.commit()
|
||||||
|
except Exception:
|
||||||
|
session.rollback()
|
||||||
|
_restore_secure_file(args.output, previous)
|
||||||
|
raise
|
||||||
|
except FirstAdminEnrollmentError as exc:
|
||||||
|
session.rollback()
|
||||||
|
parser.error(str(exc))
|
||||||
|
|
||||||
|
print(f"First-administrator credential written to {args.output}")
|
||||||
|
print(f"Fingerprint: {credential.fingerprint}")
|
||||||
|
print(f"Expires: {credential.expires_at.isoformat()}")
|
||||||
|
print("The secret was not printed. Read it from the restricted artifact on the host.")
|
||||||
|
|
||||||
|
|
||||||
|
def _configure_first_admin_provisioner() -> FirstAdminProvisioner:
|
||||||
|
raw_enabled = load_startup_enabled_modules(settings.enabled_modules)
|
||||||
|
candidates = startup_candidate_module_ids(settings.enabled_modules, raw_enabled)
|
||||||
|
available = available_module_manifests(
|
||||||
|
enabled_modules=candidates,
|
||||||
|
ignore_load_errors=True,
|
||||||
|
)
|
||||||
|
enabled = load_startup_enabled_modules(
|
||||||
|
settings.enabled_modules,
|
||||||
|
available=available,
|
||||||
|
)
|
||||||
|
registry = build_platform_registry(enabled)
|
||||||
|
context = ModuleContext(registry=registry, settings=settings)
|
||||||
|
registry.configure_capability_context(context)
|
||||||
|
configure_runtime(context)
|
||||||
|
if not registry.has_capability(CAPABILITY_ACCESS_FIRST_ADMIN_PROVISIONER):
|
||||||
|
raise RuntimeError(
|
||||||
|
"Install and enable the Access module before issuing a first-administrator credential."
|
||||||
|
)
|
||||||
|
capability = registry.require_capability(CAPABILITY_ACCESS_FIRST_ADMIN_PROVISIONER)
|
||||||
|
if not isinstance(capability, FirstAdminProvisioner):
|
||||||
|
raise RuntimeError("The Access first-administrator capability is invalid.")
|
||||||
|
return capability
|
||||||
|
|
||||||
|
|
||||||
|
def _secure_file_snapshot(path: Path) -> tuple[bytes, int] | None:
|
||||||
|
try:
|
||||||
|
metadata = path.lstat()
|
||||||
|
except FileNotFoundError:
|
||||||
|
return None
|
||||||
|
if not stat.S_ISREG(metadata.st_mode):
|
||||||
|
raise RuntimeError(f"Refusing to replace non-regular credential artifact: {path}")
|
||||||
|
if metadata.st_uid != os.geteuid():
|
||||||
|
raise RuntimeError(f"Credential artifact is not owned by the current operator: {path}")
|
||||||
|
if stat.S_IMODE(metadata.st_mode) & 0o077:
|
||||||
|
raise RuntimeError(f"Credential artifact permissions are too broad: {path}")
|
||||||
|
return path.read_bytes(), stat.S_IMODE(metadata.st_mode)
|
||||||
|
|
||||||
|
|
||||||
|
def _write_private_json(path: Path, payload: dict[str, Any]) -> None:
|
||||||
|
path.parent.mkdir(mode=0o700, parents=True, exist_ok=True)
|
||||||
|
temporary = path.with_name(f".{path.name}.{os.getpid()}.tmp")
|
||||||
|
flags = os.O_WRONLY | os.O_CREAT | os.O_EXCL
|
||||||
|
if hasattr(os, "O_NOFOLLOW"):
|
||||||
|
flags |= os.O_NOFOLLOW
|
||||||
|
descriptor = os.open(temporary, flags, 0o600)
|
||||||
|
try:
|
||||||
|
with os.fdopen(descriptor, "w", encoding="utf-8") as stream:
|
||||||
|
json.dump(payload, stream, indent=2, sort_keys=True)
|
||||||
|
stream.write("\n")
|
||||||
|
stream.flush()
|
||||||
|
os.fsync(stream.fileno())
|
||||||
|
os.replace(temporary, path)
|
||||||
|
os.chmod(path, 0o600)
|
||||||
|
_fsync_directory(path.parent)
|
||||||
|
except Exception:
|
||||||
|
try:
|
||||||
|
temporary.unlink()
|
||||||
|
except FileNotFoundError:
|
||||||
|
pass
|
||||||
|
raise
|
||||||
|
|
||||||
|
|
||||||
|
def _restore_secure_file(path: Path, snapshot: tuple[bytes, int] | None) -> None:
|
||||||
|
if snapshot is None:
|
||||||
|
try:
|
||||||
|
path.unlink()
|
||||||
|
except FileNotFoundError:
|
||||||
|
return
|
||||||
|
return
|
||||||
|
content, mode = snapshot
|
||||||
|
temporary = path.with_name(f".{path.name}.{os.getpid()}.restore")
|
||||||
|
descriptor = os.open(temporary, os.O_WRONLY | os.O_CREAT | os.O_EXCL, 0o600)
|
||||||
|
try:
|
||||||
|
with os.fdopen(descriptor, "wb") as stream:
|
||||||
|
stream.write(content)
|
||||||
|
stream.flush()
|
||||||
|
os.fsync(stream.fileno())
|
||||||
|
os.replace(temporary, path)
|
||||||
|
os.chmod(path, mode)
|
||||||
|
_fsync_directory(path.parent)
|
||||||
|
finally:
|
||||||
|
try:
|
||||||
|
temporary.unlink()
|
||||||
|
except FileNotFoundError:
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
def _fsync_directory(path: Path) -> None:
|
||||||
|
if not hasattr(os, "O_DIRECTORY"):
|
||||||
|
return
|
||||||
|
descriptor = os.open(path, os.O_RDONLY | os.O_DIRECTORY)
|
||||||
|
try:
|
||||||
|
os.fsync(descriptor)
|
||||||
|
finally:
|
||||||
|
os.close(descriptor)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
@@ -12,6 +12,7 @@ from govoplan_core.db.migrations import (
|
|||||||
migrate_database,
|
migrate_database,
|
||||||
run_registered_module_migration_tasks,
|
run_registered_module_migration_tasks,
|
||||||
)
|
)
|
||||||
|
from govoplan_core.db.migration_lock import deployment_migration_lock
|
||||||
from govoplan_core.db.session import configure_database, get_database
|
from govoplan_core.db.session import configure_database, get_database
|
||||||
from govoplan_core.settings import settings
|
from govoplan_core.settings import settings
|
||||||
|
|
||||||
@@ -28,6 +29,12 @@ def main() -> None:
|
|||||||
parser.add_argument("--enabled-module", action="append", default=[], help="Target enabled module id used to discover module migrations; may be repeated.")
|
parser.add_argument("--enabled-module", action="append", default=[], help="Target enabled module id used to discover module migrations; may be repeated.")
|
||||||
parser.add_argument("--migration-module", action="append", default=[], help="Module id whose migration heads should be upgraded in this order before final heads.")
|
parser.add_argument("--migration-module", action="append", default=[], help="Module id whose migration heads should be upgraded in this order before final heads.")
|
||||||
parser.add_argument("--migration-task-record-output", type=Path, help="Write executed module migration task records to this JSON file.")
|
parser.add_argument("--migration-task-record-output", type=Path, help="Write executed module migration task records to this JSON file.")
|
||||||
|
parser.add_argument(
|
||||||
|
"--migration-lock-timeout-seconds",
|
||||||
|
type=float,
|
||||||
|
default=900.0,
|
||||||
|
help="Maximum wait for the deployment-wide PostgreSQL advisory lock.",
|
||||||
|
)
|
||||||
parser.add_argument("--with-dev-data", action="store_true", help="Create default tenant/user/roles and a development API key")
|
parser.add_argument("--with-dev-data", action="store_true", help="Create default tenant/user/roles and a development API key")
|
||||||
parser.add_argument("--dev-api-key", default=settings.dev_bootstrap_api_key, help="Development API key secret to create")
|
parser.add_argument("--dev-api-key", default=settings.dev_bootstrap_api_key, help="Development API key secret to create")
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
@@ -37,26 +44,32 @@ def main() -> None:
|
|||||||
migration_order = tuple(args.migration_module) if args.migration_module else None
|
migration_order = tuple(args.migration_module) if args.migration_module else None
|
||||||
task_records: list[dict[str, object]] = []
|
task_records: list[dict[str, object]] = []
|
||||||
try:
|
try:
|
||||||
_run_migration_tasks(
|
with deployment_migration_lock(
|
||||||
task_records,
|
args.database_url,
|
||||||
database_url=args.database_url,
|
installation_id=settings.installation_id,
|
||||||
enabled_modules=enabled_modules,
|
|
||||||
migration_order=migration_order,
|
|
||||||
phases=PRE_MIGRATION_TASK_PHASES,
|
|
||||||
)
|
|
||||||
migration = migrate_database(
|
|
||||||
database_url=args.database_url,
|
|
||||||
enabled_modules=enabled_modules,
|
|
||||||
migration_module_order=migration_order,
|
|
||||||
migration_track=args.migration_track,
|
migration_track=args.migration_track,
|
||||||
)
|
timeout_seconds=args.migration_lock_timeout_seconds,
|
||||||
_run_migration_tasks(
|
):
|
||||||
task_records,
|
_run_migration_tasks(
|
||||||
database_url=args.database_url,
|
task_records,
|
||||||
enabled_modules=enabled_modules,
|
database_url=args.database_url,
|
||||||
migration_order=migration_order,
|
enabled_modules=enabled_modules,
|
||||||
phases=POST_MIGRATION_TASK_PHASES,
|
migration_order=migration_order,
|
||||||
)
|
phases=PRE_MIGRATION_TASK_PHASES,
|
||||||
|
)
|
||||||
|
migration = migrate_database(
|
||||||
|
database_url=args.database_url,
|
||||||
|
enabled_modules=enabled_modules,
|
||||||
|
migration_module_order=migration_order,
|
||||||
|
migration_track=args.migration_track,
|
||||||
|
)
|
||||||
|
_run_migration_tasks(
|
||||||
|
task_records,
|
||||||
|
database_url=args.database_url,
|
||||||
|
enabled_modules=enabled_modules,
|
||||||
|
migration_order=migration_order,
|
||||||
|
phases=POST_MIGRATION_TASK_PHASES,
|
||||||
|
)
|
||||||
finally:
|
finally:
|
||||||
if args.migration_task_record_output:
|
if args.migration_task_record_output:
|
||||||
args.migration_task_record_output.parent.mkdir(parents=True, exist_ok=True)
|
args.migration_task_record_output.parent.mkdir(parents=True, exist_ok=True)
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
import argparse
|
import argparse
|
||||||
|
from importlib.metadata import PackageNotFoundError, version
|
||||||
import json
|
import json
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
import sys
|
import sys
|
||||||
@@ -33,6 +34,10 @@ from govoplan_core.core.module_installer_notifications import (
|
|||||||
installer_notification_priority,
|
installer_notification_priority,
|
||||||
installer_notification_subject,
|
installer_notification_subject,
|
||||||
)
|
)
|
||||||
|
from govoplan_core.core.runtime_coordination import (
|
||||||
|
bind_process_runtime_identity,
|
||||||
|
runtime_identity,
|
||||||
|
)
|
||||||
from govoplan_core.core.module_license import issue_module_license, module_license_diagnostics
|
from govoplan_core.core.module_license import issue_module_license, module_license_diagnostics
|
||||||
from govoplan_core.core.module_package_catalog import sign_module_package_catalog, validate_module_package_catalog
|
from govoplan_core.core.module_package_catalog import sign_module_package_catalog, validate_module_package_catalog
|
||||||
from govoplan_core.core.module_management import (
|
from govoplan_core.core.module_management import (
|
||||||
@@ -107,11 +112,27 @@ def _build_parser() -> argparse.ArgumentParser:
|
|||||||
def main() -> int:
|
def main() -> int:
|
||||||
args = _build_parser().parse_args()
|
args = _build_parser().parse_args()
|
||||||
runtime_dir = args.runtime_dir or default_installer_runtime_dir(args.database_url)
|
runtime_dir = args.runtime_dir or default_installer_runtime_dir(args.database_url)
|
||||||
|
bind_process_runtime_identity(
|
||||||
|
runtime_identity(
|
||||||
|
settings,
|
||||||
|
software_version=_core_version(),
|
||||||
|
role="installer",
|
||||||
|
)
|
||||||
|
)
|
||||||
try:
|
try:
|
||||||
return _dispatch_command(args=args, runtime_dir=runtime_dir)
|
return _dispatch_command(args=args, runtime_dir=runtime_dir)
|
||||||
except ModuleInstallerError as exc:
|
except ModuleInstallerError as exc:
|
||||||
print(f"error: {exc}", file=sys.stderr)
|
print(f"error: {exc}", file=sys.stderr)
|
||||||
return 1
|
return 1
|
||||||
|
finally:
|
||||||
|
bind_process_runtime_identity(None)
|
||||||
|
|
||||||
|
|
||||||
|
def _core_version() -> str:
|
||||||
|
try:
|
||||||
|
return version("govoplan-core")
|
||||||
|
except PackageNotFoundError:
|
||||||
|
return "development"
|
||||||
|
|
||||||
|
|
||||||
def _dispatch_command(*, args: argparse.Namespace, runtime_dir: Path) -> int:
|
def _dispatch_command(*, args: argparse.Namespace, runtime_dir: Path) -> int:
|
||||||
|
|||||||
@@ -0,0 +1,61 @@
|
|||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
import argparse
|
||||||
|
import sys
|
||||||
|
import time
|
||||||
|
|
||||||
|
from govoplan_core.db.migrations import (
|
||||||
|
configured_migration_heads,
|
||||||
|
database_migration_heads,
|
||||||
|
)
|
||||||
|
from govoplan_core.settings import settings
|
||||||
|
|
||||||
|
|
||||||
|
def build_parser() -> argparse.ArgumentParser:
|
||||||
|
parser = argparse.ArgumentParser(
|
||||||
|
description="Wait until the database is at this release's migration heads."
|
||||||
|
)
|
||||||
|
parser.add_argument("--database-url", default=settings.database_url)
|
||||||
|
parser.add_argument(
|
||||||
|
"--migration-track",
|
||||||
|
default=settings.migration_track,
|
||||||
|
choices=("release", "dev"),
|
||||||
|
)
|
||||||
|
parser.add_argument("--timeout-seconds", type=float, default=900.0)
|
||||||
|
parser.add_argument("--poll-seconds", type=float, default=2.0)
|
||||||
|
return parser
|
||||||
|
|
||||||
|
|
||||||
|
def main(argv: list[str] | None = None) -> int:
|
||||||
|
args = build_parser().parse_args(argv)
|
||||||
|
if args.timeout_seconds < 0 or args.poll_seconds <= 0:
|
||||||
|
raise SystemExit("timeouts must be non-negative and polling must be positive")
|
||||||
|
expected = configured_migration_heads(
|
||||||
|
args.database_url,
|
||||||
|
migration_track=args.migration_track,
|
||||||
|
)
|
||||||
|
deadline = time.monotonic() + args.timeout_seconds
|
||||||
|
last_error = ""
|
||||||
|
while True:
|
||||||
|
try:
|
||||||
|
actual = database_migration_heads(args.database_url)
|
||||||
|
if actual == expected:
|
||||||
|
print("Database migration heads are ready: " + ",".join(actual))
|
||||||
|
return 0
|
||||||
|
last_error = (
|
||||||
|
f"database heads={','.join(actual) or '<none>'}; "
|
||||||
|
f"expected={','.join(expected) or '<none>'}"
|
||||||
|
)
|
||||||
|
except Exception as exc: # noqa: BLE001 - connection may become ready later
|
||||||
|
last_error = f"{type(exc).__name__}: {exc}"
|
||||||
|
if time.monotonic() >= deadline:
|
||||||
|
print(
|
||||||
|
"Database did not reach configured migration heads: " + last_error,
|
||||||
|
file=sys.stderr,
|
||||||
|
)
|
||||||
|
return 75
|
||||||
|
time.sleep(min(args.poll_seconds, max(0.05, deadline - time.monotonic())))
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
raise SystemExit(main())
|
||||||
@@ -6,6 +6,7 @@ from datetime import datetime
|
|||||||
from typing import Literal, Protocol, cast, runtime_checkable
|
from typing import Literal, Protocol, cast, runtime_checkable
|
||||||
|
|
||||||
from govoplan_core.core.modules import AccessDecision
|
from govoplan_core.core.modules import AccessDecision
|
||||||
|
from govoplan_core.core.institutional import GovernedContextEnvelope
|
||||||
|
|
||||||
|
|
||||||
ACCESS_MODULE_ID = "access"
|
ACCESS_MODULE_ID = "access"
|
||||||
@@ -20,8 +21,13 @@ CAPABILITY_ACCESS_RESOURCE_ACCESS = "access.resourceAccess"
|
|||||||
CAPABILITY_ACCESS_SEMANTIC_DIRECTORY = "access.semanticDirectory"
|
CAPABILITY_ACCESS_SEMANTIC_DIRECTORY = "access.semanticDirectory"
|
||||||
CAPABILITY_ACCESS_EXPLANATION = "access.explanation"
|
CAPABILITY_ACCESS_EXPLANATION = "access.explanation"
|
||||||
CAPABILITY_ACCESS_TENANT_PROVISIONER = "access.tenantProvisioner"
|
CAPABILITY_ACCESS_TENANT_PROVISIONER = "access.tenantProvisioner"
|
||||||
|
CAPABILITY_ACCESS_FIRST_ADMIN_PROVISIONER = "access.firstAdminProvisioner"
|
||||||
CAPABILITY_ACCESS_ADMINISTRATION = "access.administration"
|
CAPABILITY_ACCESS_ADMINISTRATION = "access.administration"
|
||||||
CAPABILITY_ACCESS_GOVERNANCE_MATERIALIZER = "access.governanceMaterializer"
|
CAPABILITY_ACCESS_GOVERNANCE_MATERIALIZER = "access.governanceMaterializer"
|
||||||
|
CAPABILITY_ACCESS_GOVERNANCE_PROJECTION_V1 = "access.governanceProjection.v1"
|
||||||
|
CAPABILITY_POLICY_ACCESS_EXPLANATION_SUBJECTS = (
|
||||||
|
"policy.access_explanation_subjects"
|
||||||
|
)
|
||||||
CAPABILITY_TENANCY_TENANT_RESOLVER = "tenancy.tenantResolver"
|
CAPABILITY_TENANCY_TENANT_RESOLVER = "tenancy.tenantResolver"
|
||||||
CAPABILITY_AUDIT_SINK = "audit.sink"
|
CAPABILITY_AUDIT_SINK = "audit.sink"
|
||||||
CAPABILITY_AUDIT_RECORDER = "audit.recorder"
|
CAPABILITY_AUDIT_RECORDER = "audit.recorder"
|
||||||
@@ -44,8 +50,10 @@ ACCESS_CAPABILITY_NAMES = frozenset(
|
|||||||
CAPABILITY_ACCESS_SEMANTIC_DIRECTORY,
|
CAPABILITY_ACCESS_SEMANTIC_DIRECTORY,
|
||||||
CAPABILITY_ACCESS_EXPLANATION,
|
CAPABILITY_ACCESS_EXPLANATION,
|
||||||
CAPABILITY_ACCESS_TENANT_PROVISIONER,
|
CAPABILITY_ACCESS_TENANT_PROVISIONER,
|
||||||
|
CAPABILITY_ACCESS_FIRST_ADMIN_PROVISIONER,
|
||||||
CAPABILITY_ACCESS_ADMINISTRATION,
|
CAPABILITY_ACCESS_ADMINISTRATION,
|
||||||
CAPABILITY_ACCESS_GOVERNANCE_MATERIALIZER,
|
CAPABILITY_ACCESS_GOVERNANCE_MATERIALIZER,
|
||||||
|
CAPABILITY_ACCESS_GOVERNANCE_PROJECTION_V1,
|
||||||
CAPABILITY_TENANCY_TENANT_RESOLVER,
|
CAPABILITY_TENANCY_TENANT_RESOLVER,
|
||||||
CAPABILITY_AUDIT_SINK,
|
CAPABILITY_AUDIT_SINK,
|
||||||
CAPABILITY_AUDIT_RECORDER,
|
CAPABILITY_AUDIT_RECORDER,
|
||||||
@@ -125,6 +133,7 @@ class PrincipalRef:
|
|||||||
api_key_id: str | None = None
|
api_key_id: str | None = None
|
||||||
session_id: str | None = None
|
session_id: str | None = None
|
||||||
service_account_id: str | None = None
|
service_account_id: str | None = None
|
||||||
|
acting_assignment_id: str | None = None
|
||||||
acting_for_account_id: str | None = None
|
acting_for_account_id: str | None = None
|
||||||
email: str | None = None
|
email: str | None = None
|
||||||
display_name: str | None = None
|
display_name: str | None = None
|
||||||
@@ -144,6 +153,7 @@ class PrincipalRef:
|
|||||||
"api_key_id": self.api_key_id,
|
"api_key_id": self.api_key_id,
|
||||||
"session_id": self.session_id,
|
"session_id": self.session_id,
|
||||||
"service_account_id": self.service_account_id,
|
"service_account_id": self.service_account_id,
|
||||||
|
"acting_assignment_id": self.acting_assignment_id,
|
||||||
"acting_for_account_id": self.acting_for_account_id,
|
"acting_for_account_id": self.acting_for_account_id,
|
||||||
"email": self.email,
|
"email": self.email,
|
||||||
"display_name": self.display_name,
|
"display_name": self.display_name,
|
||||||
@@ -165,12 +175,22 @@ class PrincipalRef:
|
|||||||
api_key_id=_optional_str(value.get("api_key_id")),
|
api_key_id=_optional_str(value.get("api_key_id")),
|
||||||
session_id=_optional_str(value.get("session_id")),
|
session_id=_optional_str(value.get("session_id")),
|
||||||
service_account_id=_optional_str(value.get("service_account_id")),
|
service_account_id=_optional_str(value.get("service_account_id")),
|
||||||
|
acting_assignment_id=_optional_str(value.get("acting_assignment_id")),
|
||||||
acting_for_account_id=_optional_str(value.get("acting_for_account_id")),
|
acting_for_account_id=_optional_str(value.get("acting_for_account_id")),
|
||||||
email=_optional_str(value.get("email")),
|
email=_optional_str(value.get("email")),
|
||||||
display_name=_optional_str(value.get("display_name")),
|
display_name=_optional_str(value.get("display_name")),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass(frozen=True, slots=True)
|
||||||
|
class AccessExplanationSubjectDecision:
|
||||||
|
allow_other_users: bool
|
||||||
|
reason: str
|
||||||
|
source: str
|
||||||
|
required_scope: str | None = None
|
||||||
|
provenance: Mapping[str, object] = field(default_factory=dict)
|
||||||
|
|
||||||
|
|
||||||
def _optional_str(value: object | None) -> str | None:
|
def _optional_str(value: object | None) -> str | None:
|
||||||
return str(value) if value is not None else None
|
return str(value) if value is not None else None
|
||||||
|
|
||||||
@@ -338,6 +358,19 @@ class DevelopmentBootstrapRef:
|
|||||||
created_api_key: CreatedApiKeyRef | None = None
|
created_api_key: CreatedApiKeyRef | None = None
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass(frozen=True, slots=True)
|
||||||
|
class FirstSystemAdministratorRef:
|
||||||
|
account_id: str
|
||||||
|
email: str
|
||||||
|
display_name: str | None = None
|
||||||
|
membership_id: str | None = None
|
||||||
|
tenant_id: str | None = None
|
||||||
|
|
||||||
|
|
||||||
|
class FirstAdminProvisioningError(RuntimeError):
|
||||||
|
"""Safe, user-facing rejection from the Access enrollment boundary."""
|
||||||
|
|
||||||
|
|
||||||
@dataclass(frozen=True, slots=True)
|
@dataclass(frozen=True, slots=True)
|
||||||
class TenantContextSwitchRef:
|
class TenantContextSwitchRef:
|
||||||
account_id: str
|
account_id: str
|
||||||
@@ -359,6 +392,82 @@ class GovernanceTemplateMaterialization:
|
|||||||
required: bool = False
|
required: bool = False
|
||||||
|
|
||||||
|
|
||||||
|
GovernanceProjectionOperation = Literal["upsert", "remove"]
|
||||||
|
GovernanceProjectionStatus = Literal[
|
||||||
|
"created",
|
||||||
|
"updated",
|
||||||
|
"unchanged",
|
||||||
|
"removed",
|
||||||
|
"absent",
|
||||||
|
"blocked",
|
||||||
|
"failed",
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass(frozen=True, slots=True)
|
||||||
|
class GovernanceProjectionCommand:
|
||||||
|
"""Stable Access-owned input for one governance assignment projection."""
|
||||||
|
|
||||||
|
assignment_id: str
|
||||||
|
operation: GovernanceProjectionOperation
|
||||||
|
template: GovernanceTemplateMaterialization
|
||||||
|
provenance: Mapping[str, str] = field(default_factory=dict)
|
||||||
|
|
||||||
|
def __post_init__(self) -> None:
|
||||||
|
if not self.assignment_id or len(self.assignment_id) > 255:
|
||||||
|
raise ValueError("Governance projection assignment ids must contain at most 255 characters.")
|
||||||
|
if len(self.provenance) > 20:
|
||||||
|
raise ValueError("Governance projection provenance supports at most 20 entries.")
|
||||||
|
for key, value in self.provenance.items():
|
||||||
|
if not key or len(key) > 100 or len(value) > 500:
|
||||||
|
raise ValueError("Governance projection provenance entries exceed their bounds.")
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass(frozen=True, slots=True)
|
||||||
|
class GovernanceProjectionBatch:
|
||||||
|
"""Versioned, bounded reconciliation request independent of Admin internals."""
|
||||||
|
|
||||||
|
operation_id: str
|
||||||
|
commands: tuple[GovernanceProjectionCommand, ...]
|
||||||
|
version: Literal["1"] = "1"
|
||||||
|
dry_run: bool = False
|
||||||
|
|
||||||
|
def __post_init__(self) -> None:
|
||||||
|
if not self.operation_id or len(self.operation_id) > 255:
|
||||||
|
raise ValueError("Governance projection operation ids must contain at most 255 characters.")
|
||||||
|
if not self.commands or len(self.commands) > 500:
|
||||||
|
raise ValueError("Governance projection batches must contain between 1 and 500 commands.")
|
||||||
|
assignment_ids = [command.assignment_id for command in self.commands]
|
||||||
|
if len(assignment_ids) != len(set(assignment_ids)):
|
||||||
|
raise ValueError("Governance projection assignment ids must be unique within a batch.")
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass(frozen=True, slots=True)
|
||||||
|
class GovernanceProjectionOutcome:
|
||||||
|
assignment_id: str
|
||||||
|
template_id: str
|
||||||
|
tenant_id: str
|
||||||
|
kind: Literal["group", "role"]
|
||||||
|
operation: GovernanceProjectionOperation
|
||||||
|
status: GovernanceProjectionStatus
|
||||||
|
resource_id: str | None = None
|
||||||
|
blocker_codes: tuple[str, ...] = ()
|
||||||
|
message: str | None = None
|
||||||
|
provenance: Mapping[str, str] = field(default_factory=dict)
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass(frozen=True, slots=True)
|
||||||
|
class GovernanceProjectionResult:
|
||||||
|
operation_id: str
|
||||||
|
outcomes: tuple[GovernanceProjectionOutcome, ...]
|
||||||
|
version: Literal["1"] = "1"
|
||||||
|
dry_run: bool = False
|
||||||
|
|
||||||
|
@property
|
||||||
|
def blocked(self) -> tuple[GovernanceProjectionOutcome, ...]:
|
||||||
|
return tuple(item for item in self.outcomes if item.status in {"blocked", "failed"})
|
||||||
|
|
||||||
|
|
||||||
@dataclass(frozen=True, slots=True)
|
@dataclass(frozen=True, slots=True)
|
||||||
class AuditEvent:
|
class AuditEvent:
|
||||||
event_type: str
|
event_type: str
|
||||||
@@ -374,6 +483,7 @@ class AuditEvent:
|
|||||||
occurred_at: datetime | None = None
|
occurred_at: datetime | None = None
|
||||||
correlation_id: str | None = None
|
correlation_id: str | None = None
|
||||||
causation_id: str | None = None
|
causation_id: str | None = None
|
||||||
|
institutional_context: GovernedContextEnvelope | None = None
|
||||||
details: Mapping[str, object] = field(default_factory=dict)
|
details: Mapping[str, object] = field(default_factory=dict)
|
||||||
|
|
||||||
|
|
||||||
@@ -544,6 +654,18 @@ class AccessExplanationService(Protocol):
|
|||||||
...
|
...
|
||||||
|
|
||||||
|
|
||||||
|
@runtime_checkable
|
||||||
|
class AccessExplanationSubjectPolicy(Protocol):
|
||||||
|
def decide_subject_selection(
|
||||||
|
self,
|
||||||
|
session: object,
|
||||||
|
principal: PrincipalRef,
|
||||||
|
*,
|
||||||
|
tenant_id: str,
|
||||||
|
) -> AccessExplanationSubjectDecision:
|
||||||
|
...
|
||||||
|
|
||||||
|
|
||||||
@runtime_checkable
|
@runtime_checkable
|
||||||
class TenantAccessProvisioner(Protocol):
|
class TenantAccessProvisioner(Protocol):
|
||||||
def ensure_default_roles(self, session: object, tenant: object | None = None) -> Mapping[str, object]:
|
def ensure_default_roles(self, session: object, tenant: object | None = None) -> Mapping[str, object]:
|
||||||
@@ -574,6 +696,25 @@ class TenantAccessProvisioner(Protocol):
|
|||||||
...
|
...
|
||||||
|
|
||||||
|
|
||||||
|
@runtime_checkable
|
||||||
|
class FirstAdminProvisioner(Protocol):
|
||||||
|
"""Narrow Access boundary used only by the production bootstrap flow."""
|
||||||
|
|
||||||
|
def has_durable_system_administrator(self, session: object) -> bool:
|
||||||
|
...
|
||||||
|
|
||||||
|
def create_first_system_administrator(
|
||||||
|
self,
|
||||||
|
session: object,
|
||||||
|
*,
|
||||||
|
tenant: object,
|
||||||
|
email: str,
|
||||||
|
display_name: str | None,
|
||||||
|
password: str,
|
||||||
|
) -> FirstSystemAdministratorRef:
|
||||||
|
...
|
||||||
|
|
||||||
|
|
||||||
@runtime_checkable
|
@runtime_checkable
|
||||||
class AccessAdministration(Protocol):
|
class AccessAdministration(Protocol):
|
||||||
def tenant_counts(self, session: object, tenant_id: str) -> Mapping[str, int]:
|
def tenant_counts(self, session: object, tenant_id: str) -> Mapping[str, int]:
|
||||||
@@ -630,6 +771,18 @@ class AccessGovernanceMaterializer(Protocol):
|
|||||||
...
|
...
|
||||||
|
|
||||||
|
|
||||||
|
@runtime_checkable
|
||||||
|
class AccessGovernanceProjectionV1(Protocol):
|
||||||
|
"""Bulk reconciliation boundary for Admin-owned governance assignments."""
|
||||||
|
|
||||||
|
def reconcile(
|
||||||
|
self,
|
||||||
|
session: object,
|
||||||
|
batch: GovernanceProjectionBatch,
|
||||||
|
) -> GovernanceProjectionResult:
|
||||||
|
...
|
||||||
|
|
||||||
|
|
||||||
@runtime_checkable
|
@runtime_checkable
|
||||||
class AuditSink(Protocol):
|
class AuditSink(Protocol):
|
||||||
def record(self, event: AuditEvent) -> None:
|
def record(self, event: AuditEvent) -> None:
|
||||||
|
|||||||
@@ -0,0 +1,223 @@
|
|||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
from dataclasses import dataclass
|
||||||
|
import re
|
||||||
|
from typing import Any, Literal, Mapping
|
||||||
|
|
||||||
|
|
||||||
|
AppearancePalette = Literal["default", "civic_blue", "forest", "plum"]
|
||||||
|
AppearanceSource = Literal["user", "tenant", "system", "tenant_lock", "system_lock"]
|
||||||
|
|
||||||
|
APPEARANCE_PALETTES: tuple[AppearancePalette, ...] = ("default", "civic_blue", "forest", "plum")
|
||||||
|
APPEARANCE_SETTINGS_KEY = "appearance"
|
||||||
|
APPEARANCE_OVERRIDE_SCHEMA_VERSION = "1"
|
||||||
|
APPEARANCE_OVERRIDE_TOKENS: tuple[str, ...] = (
|
||||||
|
"accent", "accent_foreground", "surface", "surface_foreground",
|
||||||
|
"success", "success_foreground", "info", "info_foreground",
|
||||||
|
"warning", "warning_foreground", "danger", "danger_foreground",
|
||||||
|
)
|
||||||
|
_STATUS_TOKENS = ("success", "info", "warning", "danger")
|
||||||
|
_HEX_COLOR = re.compile(r"^#[0-9a-fA-F]{6}$")
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass(frozen=True, slots=True)
|
||||||
|
class EffectiveAppearance:
|
||||||
|
palette: AppearancePalette
|
||||||
|
source: AppearanceSource
|
||||||
|
locked: bool
|
||||||
|
system_default_palette: AppearancePalette
|
||||||
|
tenant_default_palette: AppearancePalette | None
|
||||||
|
inherited_palette: AppearancePalette
|
||||||
|
custom_overrides: dict[str, object] | None = None
|
||||||
|
custom_overrides_allowed: bool = False
|
||||||
|
|
||||||
|
def as_dict(self) -> dict[str, object]:
|
||||||
|
return {
|
||||||
|
"palette": self.palette,
|
||||||
|
"source": self.source,
|
||||||
|
"locked": self.locked,
|
||||||
|
"system_default_palette": self.system_default_palette,
|
||||||
|
"tenant_default_palette": self.tenant_default_palette,
|
||||||
|
"inherited_palette": self.inherited_palette,
|
||||||
|
"custom_overrides": self.custom_overrides,
|
||||||
|
"custom_overrides_allowed": self.custom_overrides_allowed,
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
def normalize_appearance_palette(value: object, *, fallback: AppearancePalette | None = None) -> AppearancePalette | None:
|
||||||
|
normalized = str(value or "").strip().lower()
|
||||||
|
return normalized if normalized in APPEARANCE_PALETTES else fallback # type: ignore[return-value]
|
||||||
|
|
||||||
|
|
||||||
|
def appearance_settings(settings: Mapping[str, Any] | None) -> tuple[AppearancePalette | None, bool]:
|
||||||
|
raw = settings.get(APPEARANCE_SETTINGS_KEY) if isinstance(settings, Mapping) else None
|
||||||
|
if not isinstance(raw, Mapping):
|
||||||
|
return None, False
|
||||||
|
return normalize_appearance_palette(raw.get("default_palette")), raw.get("palette_locked") is True
|
||||||
|
|
||||||
|
|
||||||
|
def appearance_custom_overrides_policy(settings: Mapping[str, Any] | None) -> bool | None:
|
||||||
|
raw = settings.get(APPEARANCE_SETTINGS_KEY) if isinstance(settings, Mapping) else None
|
||||||
|
if not isinstance(raw, Mapping) or "allow_custom_overrides" not in raw:
|
||||||
|
return None
|
||||||
|
return raw.get("allow_custom_overrides") is True
|
||||||
|
|
||||||
|
|
||||||
|
def update_appearance_custom_overrides_policy(
|
||||||
|
settings: Mapping[str, Any] | None,
|
||||||
|
*,
|
||||||
|
allowed: bool | None,
|
||||||
|
) -> dict[str, Any]:
|
||||||
|
updated = dict(settings or {})
|
||||||
|
appearance = dict(updated.get(APPEARANCE_SETTINGS_KEY) or {}) if isinstance(updated.get(APPEARANCE_SETTINGS_KEY), Mapping) else {}
|
||||||
|
if allowed is None:
|
||||||
|
appearance.pop("allow_custom_overrides", None)
|
||||||
|
else:
|
||||||
|
appearance["allow_custom_overrides"] = allowed
|
||||||
|
if appearance:
|
||||||
|
updated[APPEARANCE_SETTINGS_KEY] = appearance
|
||||||
|
else:
|
||||||
|
updated.pop(APPEARANCE_SETTINGS_KEY, None)
|
||||||
|
return updated
|
||||||
|
|
||||||
|
|
||||||
|
def normalize_appearance_overrides(value: object) -> dict[str, object] | None:
|
||||||
|
"""Validate and canonicalize the versioned, all-or-nothing color contract."""
|
||||||
|
|
||||||
|
if value is None:
|
||||||
|
return None
|
||||||
|
if not isinstance(value, Mapping):
|
||||||
|
raise ValueError("Appearance overrides must be an object.")
|
||||||
|
if set(value) != {"schema_version", "light", "dark"}:
|
||||||
|
raise ValueError("Appearance overrides must contain only schema_version, light, and dark.")
|
||||||
|
if str(value.get("schema_version")) != APPEARANCE_OVERRIDE_SCHEMA_VERSION:
|
||||||
|
raise ValueError("Unsupported appearance override schema version.")
|
||||||
|
normalized: dict[str, object] = {"schema_version": APPEARANCE_OVERRIDE_SCHEMA_VERSION}
|
||||||
|
for mode in ("light", "dark"):
|
||||||
|
raw_mode = value.get(mode)
|
||||||
|
if not isinstance(raw_mode, Mapping) or set(raw_mode) != set(APPEARANCE_OVERRIDE_TOKENS):
|
||||||
|
raise ValueError(f"Appearance override mode {mode} must define every supported token exactly once.")
|
||||||
|
colors: dict[str, str] = {}
|
||||||
|
for token in APPEARANCE_OVERRIDE_TOKENS:
|
||||||
|
color = str(raw_mode.get(token) or "").strip().lower()
|
||||||
|
if not _HEX_COLOR.fullmatch(color):
|
||||||
|
raise ValueError(f"Appearance override {mode}.{token} must be a six-digit hexadecimal color.")
|
||||||
|
colors[token] = color
|
||||||
|
_validate_mode_accessibility(mode, colors)
|
||||||
|
normalized[mode] = colors
|
||||||
|
return normalized
|
||||||
|
|
||||||
|
|
||||||
|
def _validate_mode_accessibility(mode: str, colors: Mapping[str, str]) -> None:
|
||||||
|
pairs = (
|
||||||
|
("accent", "accent_foreground"), ("surface", "surface_foreground"),
|
||||||
|
("success", "success_foreground"), ("info", "info_foreground"),
|
||||||
|
("warning", "warning_foreground"), ("danger", "danger_foreground"),
|
||||||
|
)
|
||||||
|
for background, foreground in pairs:
|
||||||
|
if _contrast_ratio(colors[background], colors[foreground]) < 4.5:
|
||||||
|
raise ValueError(f"Appearance override {mode}.{foreground} must have WCAG AA contrast against {mode}.{background}.")
|
||||||
|
status_colors = [colors[token] for token in _STATUS_TOKENS]
|
||||||
|
for index, first in enumerate(status_colors):
|
||||||
|
for second in status_colors[index + 1:]:
|
||||||
|
if _rgb_distance(first, second) < 12:
|
||||||
|
raise ValueError(f"Appearance override status colors in {mode} must remain visibly distinct.")
|
||||||
|
|
||||||
|
|
||||||
|
def _relative_luminance(color: str) -> float:
|
||||||
|
channels = [int(color[index:index + 2], 16) / 255 for index in (1, 3, 5)]
|
||||||
|
linear = [channel / 12.92 if channel <= 0.04045 else ((channel + 0.055) / 1.055) ** 2.4 for channel in channels]
|
||||||
|
return 0.2126 * linear[0] + 0.7152 * linear[1] + 0.0722 * linear[2]
|
||||||
|
|
||||||
|
|
||||||
|
def _contrast_ratio(first: str, second: str) -> float:
|
||||||
|
high, low = sorted((_relative_luminance(first), _relative_luminance(second)), reverse=True)
|
||||||
|
return (high + 0.05) / (low + 0.05)
|
||||||
|
|
||||||
|
|
||||||
|
def _rgb_distance(first: str, second: str) -> float:
|
||||||
|
first_channels = [int(first[index:index + 2], 16) for index in (1, 3, 5)]
|
||||||
|
second_channels = [int(second[index:index + 2], 16) for index in (1, 3, 5)]
|
||||||
|
return sum((left - right) ** 2 for left, right in zip(first_channels, second_channels, strict=True)) ** 0.5
|
||||||
|
|
||||||
|
|
||||||
|
def update_appearance_settings(
|
||||||
|
settings: Mapping[str, Any] | None,
|
||||||
|
*,
|
||||||
|
default_palette: AppearancePalette | None,
|
||||||
|
palette_locked: bool,
|
||||||
|
) -> dict[str, Any]:
|
||||||
|
updated = dict(settings or {})
|
||||||
|
appearance = dict(updated.get(APPEARANCE_SETTINGS_KEY) or {}) if isinstance(updated.get(APPEARANCE_SETTINGS_KEY), Mapping) else {}
|
||||||
|
if default_palette is None:
|
||||||
|
appearance.pop("default_palette", None)
|
||||||
|
else:
|
||||||
|
normalized = normalize_appearance_palette(default_palette)
|
||||||
|
if normalized is None:
|
||||||
|
raise ValueError("Unsupported appearance palette.")
|
||||||
|
appearance["default_palette"] = normalized
|
||||||
|
if palette_locked:
|
||||||
|
appearance["palette_locked"] = True
|
||||||
|
else:
|
||||||
|
appearance.pop("palette_locked", None)
|
||||||
|
if appearance:
|
||||||
|
updated[APPEARANCE_SETTINGS_KEY] = appearance
|
||||||
|
else:
|
||||||
|
updated.pop(APPEARANCE_SETTINGS_KEY, None)
|
||||||
|
return updated
|
||||||
|
|
||||||
|
|
||||||
|
def resolve_effective_appearance(
|
||||||
|
*,
|
||||||
|
system_settings: Mapping[str, Any] | None,
|
||||||
|
tenant_settings: Mapping[str, Any] | None,
|
||||||
|
user_settings: Mapping[str, Any] | None,
|
||||||
|
) -> EffectiveAppearance:
|
||||||
|
system_palette, system_locked = appearance_settings(system_settings)
|
||||||
|
system_palette = system_palette or "default"
|
||||||
|
tenant_palette, tenant_locked = appearance_settings(tenant_settings)
|
||||||
|
inherited_palette = tenant_palette or system_palette
|
||||||
|
raw_ui = user_settings.get("ui") if isinstance(user_settings, Mapping) else None
|
||||||
|
user_palette = normalize_appearance_palette(raw_ui.get("palette")) if isinstance(raw_ui, Mapping) else None
|
||||||
|
system_custom_policy = appearance_custom_overrides_policy(system_settings) is True
|
||||||
|
tenant_custom_policy = appearance_custom_overrides_policy(tenant_settings)
|
||||||
|
custom_overrides_allowed = system_custom_policy and tenant_custom_policy is not False and not system_locked and not tenant_locked
|
||||||
|
try:
|
||||||
|
custom_overrides = normalize_appearance_overrides(raw_ui.get("appearance_overrides")) if isinstance(raw_ui, Mapping) else None
|
||||||
|
except ValueError:
|
||||||
|
custom_overrides = None
|
||||||
|
if not custom_overrides_allowed:
|
||||||
|
custom_overrides = None
|
||||||
|
|
||||||
|
if system_locked:
|
||||||
|
return EffectiveAppearance(system_palette, "system_lock", True, system_palette, tenant_palette, system_palette)
|
||||||
|
if tenant_locked:
|
||||||
|
return EffectiveAppearance(inherited_palette, "tenant_lock", True, system_palette, tenant_palette, inherited_palette)
|
||||||
|
return EffectiveAppearance(
|
||||||
|
user_palette or inherited_palette,
|
||||||
|
"user" if user_palette else "tenant" if tenant_palette else "system",
|
||||||
|
False,
|
||||||
|
system_palette,
|
||||||
|
tenant_palette,
|
||||||
|
inherited_palette,
|
||||||
|
custom_overrides,
|
||||||
|
custom_overrides_allowed,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
__all__ = [
|
||||||
|
"APPEARANCE_PALETTES",
|
||||||
|
"APPEARANCE_SETTINGS_KEY",
|
||||||
|
"APPEARANCE_OVERRIDE_SCHEMA_VERSION",
|
||||||
|
"APPEARANCE_OVERRIDE_TOKENS",
|
||||||
|
"AppearancePalette",
|
||||||
|
"AppearanceSource",
|
||||||
|
"EffectiveAppearance",
|
||||||
|
"appearance_settings",
|
||||||
|
"appearance_custom_overrides_policy",
|
||||||
|
"normalize_appearance_overrides",
|
||||||
|
"normalize_appearance_palette",
|
||||||
|
"resolve_effective_appearance",
|
||||||
|
"update_appearance_settings",
|
||||||
|
"update_appearance_custom_overrides_policy",
|
||||||
|
]
|
||||||
@@ -0,0 +1,81 @@
|
|||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
from collections.abc import Mapping
|
||||||
|
from datetime import datetime
|
||||||
|
from typing import Protocol, runtime_checkable
|
||||||
|
|
||||||
|
|
||||||
|
CAPABILITY_APPLICATION_STATUS_PROJECTION = "application_status.projection"
|
||||||
|
|
||||||
|
|
||||||
|
@runtime_checkable
|
||||||
|
class ApplicationStatusProjectionProvider(Protocol):
|
||||||
|
"""Bounded applicant-status access without exposing the owning module's data."""
|
||||||
|
|
||||||
|
def tenant_id_for_tracking_id(
|
||||||
|
self,
|
||||||
|
session: object,
|
||||||
|
*,
|
||||||
|
tracking_id: str,
|
||||||
|
) -> str | None:
|
||||||
|
...
|
||||||
|
|
||||||
|
def public_access_challenge(
|
||||||
|
self,
|
||||||
|
session: object,
|
||||||
|
*,
|
||||||
|
tracking_id: str,
|
||||||
|
) -> Mapping[str, object]:
|
||||||
|
...
|
||||||
|
|
||||||
|
def get_authenticated_projection(
|
||||||
|
self,
|
||||||
|
session: object,
|
||||||
|
principal: object,
|
||||||
|
*,
|
||||||
|
tracking_id: str,
|
||||||
|
observed_at: datetime,
|
||||||
|
) -> Mapping[str, object]:
|
||||||
|
...
|
||||||
|
|
||||||
|
def get_public_projection(
|
||||||
|
self,
|
||||||
|
session: object,
|
||||||
|
*,
|
||||||
|
tracking_id: str,
|
||||||
|
token: str | None,
|
||||||
|
observed_at: datetime,
|
||||||
|
) -> Mapping[str, object]:
|
||||||
|
...
|
||||||
|
|
||||||
|
def request_email_link(
|
||||||
|
self,
|
||||||
|
session: object,
|
||||||
|
*,
|
||||||
|
tracking_id: str,
|
||||||
|
email: str,
|
||||||
|
requested_at: datetime,
|
||||||
|
) -> bool:
|
||||||
|
...
|
||||||
|
|
||||||
|
|
||||||
|
def application_status_projection_provider(
|
||||||
|
registry: object | None,
|
||||||
|
) -> ApplicationStatusProjectionProvider | None:
|
||||||
|
if registry is None or not hasattr(registry, "has_capability"):
|
||||||
|
return None
|
||||||
|
if not registry.has_capability(CAPABILITY_APPLICATION_STATUS_PROJECTION):
|
||||||
|
return None
|
||||||
|
capability = registry.capability(CAPABILITY_APPLICATION_STATUS_PROJECTION)
|
||||||
|
return (
|
||||||
|
capability
|
||||||
|
if isinstance(capability, ApplicationStatusProjectionProvider)
|
||||||
|
else None
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
__all__ = [
|
||||||
|
"ApplicationStatusProjectionProvider",
|
||||||
|
"CAPABILITY_APPLICATION_STATUS_PROJECTION",
|
||||||
|
"application_status_projection_provider",
|
||||||
|
]
|
||||||
@@ -0,0 +1,207 @@
|
|||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
from collections.abc import Mapping
|
||||||
|
from dataclasses import dataclass, field
|
||||||
|
from datetime import datetime
|
||||||
|
from typing import Protocol, runtime_checkable
|
||||||
|
|
||||||
|
|
||||||
|
CAPABILITY_APPROVAL_REQUESTS = "approvals.requests"
|
||||||
|
|
||||||
|
|
||||||
|
class ApprovalCapabilityError(ValueError):
|
||||||
|
"""Stable error raised by Approval capability implementations."""
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass(frozen=True, slots=True)
|
||||||
|
class ApprovalActorSelector:
|
||||||
|
kind: str
|
||||||
|
value: str
|
||||||
|
label: str | None = None
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass(frozen=True, slots=True)
|
||||||
|
class ApprovalStepDefinition:
|
||||||
|
key: str
|
||||||
|
label: str
|
||||||
|
selectors: tuple[ApprovalActorSelector, ...]
|
||||||
|
required_approvals: int = 1
|
||||||
|
rejection_policy: str = "fail_fast"
|
||||||
|
due_at: datetime | None = None
|
||||||
|
signature_required: bool = False
|
||||||
|
forbidden_evidence_roles: tuple[str, ...] = ()
|
||||||
|
metadata: Mapping[str, object] = field(default_factory=dict)
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass(frozen=True, slots=True)
|
||||||
|
class ApprovalRequestCreateCommand:
|
||||||
|
title: str
|
||||||
|
subject_module: str
|
||||||
|
subject_type: str
|
||||||
|
subject_id: str
|
||||||
|
subject_version: str | None
|
||||||
|
subject_digest: str
|
||||||
|
steps: tuple[ApprovalStepDefinition, ...]
|
||||||
|
description: str | None = None
|
||||||
|
separation_of_duties: bool = True
|
||||||
|
unique_actors_across_steps: bool = False
|
||||||
|
expires_at: datetime | None = None
|
||||||
|
policy_refs: tuple[str, ...] = ()
|
||||||
|
evidence_actors: Mapping[str, tuple[str, ...]] = field(default_factory=dict)
|
||||||
|
template_id: str | None = None
|
||||||
|
template_revision: int | None = None
|
||||||
|
metadata: Mapping[str, object] = field(default_factory=dict)
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass(frozen=True, slots=True)
|
||||||
|
class ApprovalTemplateCreateCommand:
|
||||||
|
key: str
|
||||||
|
title: str
|
||||||
|
steps: tuple[ApprovalStepDefinition, ...]
|
||||||
|
description: str | None = None
|
||||||
|
separation_of_duties: bool = True
|
||||||
|
unique_actors_across_steps: bool = False
|
||||||
|
metadata: Mapping[str, object] = field(default_factory=dict)
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass(frozen=True, slots=True)
|
||||||
|
class ApprovalTemplateRef:
|
||||||
|
id: str
|
||||||
|
key: str
|
||||||
|
revision: int
|
||||||
|
state: str
|
||||||
|
content_sha256: str
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass(frozen=True, slots=True)
|
||||||
|
class ApprovalDecisionCommand:
|
||||||
|
outcome: str
|
||||||
|
reason: str
|
||||||
|
expected_revision: int
|
||||||
|
idempotency_key: str
|
||||||
|
delegated_for_account_id: str | None = None
|
||||||
|
signature_ref: Mapping[str, object] | None = None
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass(frozen=True, slots=True)
|
||||||
|
class ApprovalRequestRef:
|
||||||
|
id: str
|
||||||
|
revision: int
|
||||||
|
state: str
|
||||||
|
current_step_key: str | None = None
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass(frozen=True, slots=True)
|
||||||
|
class ApprovalDecisionReceipt:
|
||||||
|
request_id: str
|
||||||
|
revision: int
|
||||||
|
state: str
|
||||||
|
step_key: str
|
||||||
|
outcome: str
|
||||||
|
actor_id: str
|
||||||
|
recorded_at: datetime
|
||||||
|
receipt_sha256: str
|
||||||
|
authority_provenance: Mapping[str, object] = field(default_factory=dict)
|
||||||
|
replayed: bool = False
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass(frozen=True, slots=True)
|
||||||
|
class ApprovalCheck:
|
||||||
|
request_id: str
|
||||||
|
revision: int
|
||||||
|
state: str
|
||||||
|
approved: bool
|
||||||
|
subject_module: str
|
||||||
|
subject_type: str
|
||||||
|
subject_id: str
|
||||||
|
subject_version: str | None
|
||||||
|
subject_digest: str
|
||||||
|
completed_at: datetime | None = None
|
||||||
|
|
||||||
|
|
||||||
|
@runtime_checkable
|
||||||
|
class ApprovalRequestProvider(Protocol):
|
||||||
|
def create_template(
|
||||||
|
self,
|
||||||
|
session: object,
|
||||||
|
principal: object,
|
||||||
|
*,
|
||||||
|
command: ApprovalTemplateCreateCommand,
|
||||||
|
idempotency_key: str,
|
||||||
|
) -> ApprovalTemplateRef: ...
|
||||||
|
|
||||||
|
def revise_template(
|
||||||
|
self,
|
||||||
|
session: object,
|
||||||
|
principal: object,
|
||||||
|
*,
|
||||||
|
template_id: str,
|
||||||
|
command: ApprovalTemplateCreateCommand,
|
||||||
|
expected_revision: int,
|
||||||
|
idempotency_key: str,
|
||||||
|
) -> ApprovalTemplateRef: ...
|
||||||
|
|
||||||
|
def publish_template(
|
||||||
|
self,
|
||||||
|
session: object,
|
||||||
|
principal: object,
|
||||||
|
*,
|
||||||
|
template_id: str,
|
||||||
|
expected_revision: int,
|
||||||
|
idempotency_key: str,
|
||||||
|
) -> ApprovalTemplateRef: ...
|
||||||
|
|
||||||
|
def create_request(
|
||||||
|
self,
|
||||||
|
session: object,
|
||||||
|
principal: object,
|
||||||
|
*,
|
||||||
|
command: ApprovalRequestCreateCommand,
|
||||||
|
idempotency_key: str,
|
||||||
|
) -> ApprovalRequestRef: ...
|
||||||
|
|
||||||
|
def get_request(
|
||||||
|
self,
|
||||||
|
session: object,
|
||||||
|
principal: object,
|
||||||
|
*,
|
||||||
|
request_id: str,
|
||||||
|
) -> Mapping[str, object] | None: ...
|
||||||
|
|
||||||
|
def decide(
|
||||||
|
self,
|
||||||
|
session: object,
|
||||||
|
principal: object,
|
||||||
|
*,
|
||||||
|
request_id: str,
|
||||||
|
command: ApprovalDecisionCommand,
|
||||||
|
) -> ApprovalDecisionReceipt: ...
|
||||||
|
|
||||||
|
def check_approved(
|
||||||
|
self,
|
||||||
|
session: object,
|
||||||
|
principal: object,
|
||||||
|
*,
|
||||||
|
request_id: str,
|
||||||
|
subject_module: str,
|
||||||
|
subject_type: str,
|
||||||
|
subject_id: str,
|
||||||
|
subject_version: str | None,
|
||||||
|
subject_digest: str,
|
||||||
|
) -> ApprovalCheck: ...
|
||||||
|
|
||||||
|
|
||||||
|
__all__ = [
|
||||||
|
"ApprovalActorSelector",
|
||||||
|
"ApprovalCapabilityError",
|
||||||
|
"ApprovalCheck",
|
||||||
|
"ApprovalDecisionCommand",
|
||||||
|
"ApprovalDecisionReceipt",
|
||||||
|
"ApprovalRequestCreateCommand",
|
||||||
|
"ApprovalRequestProvider",
|
||||||
|
"ApprovalRequestRef",
|
||||||
|
"ApprovalStepDefinition",
|
||||||
|
"ApprovalTemplateCreateCommand",
|
||||||
|
"ApprovalTemplateRef",
|
||||||
|
"CAPABILITY_APPROVAL_REQUESTS",
|
||||||
|
]
|
||||||
@@ -8,6 +8,7 @@ from typing import Literal, Protocol, runtime_checkable
|
|||||||
from govoplan_core.core.access import (
|
from govoplan_core.core.access import (
|
||||||
CAPABILITY_AUTH_AUTOMATION_PRINCIPAL_PROVIDER,
|
CAPABILITY_AUTH_AUTOMATION_PRINCIPAL_PROVIDER,
|
||||||
)
|
)
|
||||||
|
from govoplan_core.core.institutional import GovernedContextEnvelope
|
||||||
|
|
||||||
AutomationInvocationKind = Literal[
|
AutomationInvocationKind = Literal[
|
||||||
"manual",
|
"manual",
|
||||||
@@ -30,6 +31,13 @@ ActionReversibility = Literal[
|
|||||||
"corrective_only",
|
"corrective_only",
|
||||||
"irreversible",
|
"irreversible",
|
||||||
]
|
]
|
||||||
|
ActionRecoveryMode = Literal[
|
||||||
|
"atomic",
|
||||||
|
"compensation",
|
||||||
|
"snapshot_restore",
|
||||||
|
"forward_recovery",
|
||||||
|
"irreversible",
|
||||||
|
]
|
||||||
ActionExecutionState = Literal[
|
ActionExecutionState = Literal[
|
||||||
"pending",
|
"pending",
|
||||||
"running",
|
"running",
|
||||||
@@ -86,6 +94,10 @@ class ActionDefinition:
|
|||||||
idempotency_strategy: str = "caller_supplied"
|
idempotency_strategy: str = "caller_supplied"
|
||||||
audit_event_types: tuple[str, ...] = ()
|
audit_event_types: tuple[str, ...] = ()
|
||||||
preview_required: bool = True
|
preview_required: bool = True
|
||||||
|
recovery_mode: ActionRecoveryMode = "forward_recovery"
|
||||||
|
recovery_verification: tuple[str, ...] = (
|
||||||
|
"verify the provider result and every announced effect before continuation",
|
||||||
|
)
|
||||||
contract_version: str = ACTION_EFFECT_CONTRACT_VERSION
|
contract_version: str = ACTION_EFFECT_CONTRACT_VERSION
|
||||||
|
|
||||||
def __post_init__(self) -> None:
|
def __post_init__(self) -> None:
|
||||||
@@ -95,12 +107,24 @@ class ActionDefinition:
|
|||||||
_require_text(self.description, "Action description")
|
_require_text(self.description, "Action description")
|
||||||
_require_text(self.input_schema_ref, "Action input schema reference")
|
_require_text(self.input_schema_ref, "Action input schema reference")
|
||||||
_require_text(self.idempotency_strategy, "Action idempotency strategy")
|
_require_text(self.idempotency_strategy, "Action idempotency strategy")
|
||||||
|
if self.recovery_mode not in {
|
||||||
|
"atomic",
|
||||||
|
"compensation",
|
||||||
|
"snapshot_restore",
|
||||||
|
"forward_recovery",
|
||||||
|
"irreversible",
|
||||||
|
}:
|
||||||
|
raise ValueError("Action recovery mode is not supported")
|
||||||
if any(not value.strip() for value in self.required_scopes):
|
if any(not value.strip() for value in self.required_scopes):
|
||||||
raise ValueError("Action scopes must not be empty")
|
raise ValueError("Action scopes must not be empty")
|
||||||
if any(not value.strip() for value in self.required_capabilities):
|
if any(not value.strip() for value in self.required_capabilities):
|
||||||
raise ValueError("Action capabilities must not be empty")
|
raise ValueError("Action capabilities must not be empty")
|
||||||
if any(not value.strip() for value in self.expected_effect_keys):
|
if any(not value.strip() for value in self.expected_effect_keys):
|
||||||
raise ValueError("Expected effect keys must not be empty")
|
raise ValueError("Expected effect keys must not be empty")
|
||||||
|
if not self.recovery_verification or any(
|
||||||
|
not value.strip() for value in self.recovery_verification
|
||||||
|
):
|
||||||
|
raise ValueError("Actions must declare recovery verification steps")
|
||||||
|
|
||||||
|
|
||||||
@dataclass(frozen=True, slots=True)
|
@dataclass(frozen=True, slots=True)
|
||||||
@@ -110,6 +134,7 @@ class ActionExecutionRequest:
|
|||||||
input: Mapping[str, object]
|
input: Mapping[str, object]
|
||||||
idempotency_key: str
|
idempotency_key: str
|
||||||
invocation: AutomationInvocation
|
invocation: AutomationInvocation
|
||||||
|
institutional_context: GovernedContextEnvelope | None = None
|
||||||
actor_ref: str | None = None
|
actor_ref: str | None = None
|
||||||
preview_ref: str | None = None
|
preview_ref: str | None = None
|
||||||
metadata: Mapping[str, object] = field(default_factory=dict)
|
metadata: Mapping[str, object] = field(default_factory=dict)
|
||||||
@@ -382,6 +407,7 @@ __all__ = [
|
|||||||
"AutomationPrincipalResolution",
|
"AutomationPrincipalResolution",
|
||||||
"AutomationSubjectKind",
|
"AutomationSubjectKind",
|
||||||
"ActionPreview",
|
"ActionPreview",
|
||||||
|
"ActionRecoveryMode",
|
||||||
"ActionReversibility",
|
"ActionReversibility",
|
||||||
"ActionRiskLevel",
|
"ActionRiskLevel",
|
||||||
"EffectDefinition",
|
"EffectDefinition",
|
||||||
|
|||||||
@@ -8,6 +8,8 @@ from typing import Protocol, runtime_checkable
|
|||||||
|
|
||||||
CAPABILITY_CALENDAR_SCHEDULING = "calendar.scheduling"
|
CAPABILITY_CALENDAR_SCHEDULING = "calendar.scheduling"
|
||||||
CAPABILITY_CALENDAR_OUTBOX = "calendar.outbox"
|
CAPABILITY_CALENDAR_OUTBOX = "calendar.outbox"
|
||||||
|
CAPABILITY_CALENDAR_INVITATIONS = "calendar.invitations"
|
||||||
|
CAPABILITY_CALENDAR_EXTERNAL_PROFILES = "calendar.externalProfiles"
|
||||||
CALENDAR_AVAILABILITY_READ_SCOPE = "calendar:availability:read"
|
CALENDAR_AVAILABILITY_READ_SCOPE = "calendar:availability:read"
|
||||||
CALENDAR_EVENT_WRITE_SCOPE = "calendar:event:write"
|
CALENDAR_EVENT_WRITE_SCOPE = "calendar:event:write"
|
||||||
|
|
||||||
@@ -43,6 +45,103 @@ class CalendarEventRef:
|
|||||||
outbox_operation_id: str | None = None
|
outbox_operation_id: str | None = None
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass(frozen=True, slots=True)
|
||||||
|
class CalendarEventReleaseRef:
|
||||||
|
event_id: str
|
||||||
|
accepted: bool = True
|
||||||
|
already_released: bool = False
|
||||||
|
external_state: str = "local_released"
|
||||||
|
outbox_operation_id: str | None = None
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass(frozen=True, slots=True)
|
||||||
|
class CalendarInvitationAttendeeRequest:
|
||||||
|
address: str
|
||||||
|
name: str | None = None
|
||||||
|
role: str = "REQ-PARTICIPANT"
|
||||||
|
participation_status: str = "NEEDS-ACTION"
|
||||||
|
rsvp: bool = True
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass(frozen=True, slots=True)
|
||||||
|
class CalendarInvitationRequest:
|
||||||
|
correlation_id: str
|
||||||
|
source_module: str
|
||||||
|
source_resource_type: str
|
||||||
|
source_resource_id: str | None
|
||||||
|
summary: str
|
||||||
|
start_at: datetime
|
||||||
|
attendees: tuple[CalendarInvitationAttendeeRequest, ...]
|
||||||
|
calendar_id: str | None = None
|
||||||
|
description: str | None = None
|
||||||
|
location: str | None = None
|
||||||
|
end_at: datetime | None = None
|
||||||
|
timezone: str | None = None
|
||||||
|
organizer: Mapping[str, object] | None = None
|
||||||
|
classification: str = "PUBLIC"
|
||||||
|
categories: tuple[str, ...] = ()
|
||||||
|
metadata: Mapping[str, object] = field(default_factory=dict)
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass(frozen=True, slots=True)
|
||||||
|
class CalendarInvitationRef:
|
||||||
|
event_id: str
|
||||||
|
calendar_id: str
|
||||||
|
uid: str
|
||||||
|
correlation_id: str
|
||||||
|
source_module: str
|
||||||
|
source_resource_type: str
|
||||||
|
source_resource_id: str | None
|
||||||
|
attendees: tuple[Mapping[str, object], ...] = ()
|
||||||
|
external_state: str = "local"
|
||||||
|
outbox_operation_id: str | None = None
|
||||||
|
reply_ingress: str = "capability"
|
||||||
|
recurrence_supported: bool = False
|
||||||
|
degraded_reasons: tuple[str, ...] = ()
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass(frozen=True, slots=True)
|
||||||
|
class CalendarInvitationCalendarRef:
|
||||||
|
id: str
|
||||||
|
name: str
|
||||||
|
color: str | None = None
|
||||||
|
timezone: str = "UTC"
|
||||||
|
source_kind: str = "local"
|
||||||
|
writable: bool = True
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass(frozen=True, slots=True)
|
||||||
|
class CalendarExternalProfileRequest:
|
||||||
|
"""Connector-neutral request for a Calendar-owned external profile."""
|
||||||
|
|
||||||
|
profile_kind: str
|
||||||
|
calendar_id: str
|
||||||
|
endpoint_url: str
|
||||||
|
display_name: str | None = None
|
||||||
|
auth_type: str = "none"
|
||||||
|
username: str | None = None
|
||||||
|
credential_ref: str | None = None
|
||||||
|
sync_enabled: bool = True
|
||||||
|
sync_interval_seconds: int = 900
|
||||||
|
sync_direction: str = "two_way"
|
||||||
|
conflict_policy: str = "etag"
|
||||||
|
connector_profile_ref: str | None = None
|
||||||
|
identity_mapping_ref: str | None = None
|
||||||
|
resource_calendar_ref: str | None = None
|
||||||
|
metadata: Mapping[str, object] = field(default_factory=dict)
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass(frozen=True, slots=True)
|
||||||
|
class CalendarExternalProfileRef:
|
||||||
|
source_id: str
|
||||||
|
calendar_id: str
|
||||||
|
profile_kind: str
|
||||||
|
transport_kind: str
|
||||||
|
connector_profile_ref: str | None = None
|
||||||
|
identity_mapping_ref: str | None = None
|
||||||
|
resource_calendar_ref: str | None = None
|
||||||
|
|
||||||
|
|
||||||
@runtime_checkable
|
@runtime_checkable
|
||||||
class CalendarSchedulingProvider(Protocol):
|
class CalendarSchedulingProvider(Protocol):
|
||||||
def list_freebusy(
|
def list_freebusy(
|
||||||
@@ -66,6 +165,27 @@ class CalendarSchedulingProvider(Protocol):
|
|||||||
) -> CalendarEventRef:
|
) -> CalendarEventRef:
|
||||||
...
|
...
|
||||||
|
|
||||||
|
def promote_event(
|
||||||
|
self,
|
||||||
|
session: object,
|
||||||
|
*,
|
||||||
|
tenant_id: str,
|
||||||
|
user_id: str | None,
|
||||||
|
event_id: str,
|
||||||
|
request: CalendarEventRequest,
|
||||||
|
) -> CalendarEventRef:
|
||||||
|
...
|
||||||
|
|
||||||
|
def release_event(
|
||||||
|
self,
|
||||||
|
session: object,
|
||||||
|
*,
|
||||||
|
tenant_id: str,
|
||||||
|
user_id: str | None,
|
||||||
|
event_id: str,
|
||||||
|
) -> CalendarEventReleaseRef:
|
||||||
|
...
|
||||||
|
|
||||||
|
|
||||||
@runtime_checkable
|
@runtime_checkable
|
||||||
class CalendarOutboxProvider(Protocol):
|
class CalendarOutboxProvider(Protocol):
|
||||||
@@ -80,6 +200,108 @@ class CalendarOutboxProvider(Protocol):
|
|||||||
) -> Mapping[str, object]:
|
) -> Mapping[str, object]:
|
||||||
...
|
...
|
||||||
|
|
||||||
|
|
||||||
|
@runtime_checkable
|
||||||
|
class CalendarInvitationProvider(Protocol):
|
||||||
|
"""Correlation-aware invitation boundary for Campaign and Mail adapters."""
|
||||||
|
|
||||||
|
def list_calendars(
|
||||||
|
self,
|
||||||
|
session: object,
|
||||||
|
*,
|
||||||
|
tenant_id: str,
|
||||||
|
user_id: str | None = None,
|
||||||
|
group_ids: Sequence[str] = (),
|
||||||
|
can_admin: bool = False,
|
||||||
|
) -> Sequence[CalendarInvitationCalendarRef]:
|
||||||
|
...
|
||||||
|
|
||||||
|
def render_invitation(self, request: CalendarInvitationRequest) -> str:
|
||||||
|
...
|
||||||
|
|
||||||
|
def upsert_invitation(
|
||||||
|
self,
|
||||||
|
session: object,
|
||||||
|
*,
|
||||||
|
tenant_id: str,
|
||||||
|
user_id: str | None,
|
||||||
|
request: CalendarInvitationRequest,
|
||||||
|
) -> CalendarInvitationRef:
|
||||||
|
...
|
||||||
|
|
||||||
|
def get_invitation(
|
||||||
|
self,
|
||||||
|
session: object,
|
||||||
|
*,
|
||||||
|
tenant_id: str,
|
||||||
|
correlation_id: str,
|
||||||
|
) -> CalendarInvitationRef | None:
|
||||||
|
...
|
||||||
|
|
||||||
|
def get_invitations(
|
||||||
|
self,
|
||||||
|
session: object,
|
||||||
|
*,
|
||||||
|
tenant_id: str,
|
||||||
|
correlation_ids: Sequence[str],
|
||||||
|
) -> Mapping[str, CalendarInvitationRef]:
|
||||||
|
...
|
||||||
|
|
||||||
|
def summarize_invitations(
|
||||||
|
self,
|
||||||
|
session: object,
|
||||||
|
*,
|
||||||
|
tenant_id: str,
|
||||||
|
source_module: str,
|
||||||
|
source_resource_type: str,
|
||||||
|
source_resource_id: str | None,
|
||||||
|
) -> Mapping[str, object]:
|
||||||
|
...
|
||||||
|
|
||||||
|
def record_response(
|
||||||
|
self,
|
||||||
|
session: object,
|
||||||
|
*,
|
||||||
|
tenant_id: str,
|
||||||
|
attendee_address: str,
|
||||||
|
participation_status: str,
|
||||||
|
correlation_id: str | None = None,
|
||||||
|
uid: str | None = None,
|
||||||
|
responded_at: datetime | None = None,
|
||||||
|
evidence: Mapping[str, object] | None = None,
|
||||||
|
) -> CalendarInvitationRef:
|
||||||
|
...
|
||||||
|
|
||||||
|
def record_icalendar_reply(
|
||||||
|
self,
|
||||||
|
session: object,
|
||||||
|
*,
|
||||||
|
tenant_id: str,
|
||||||
|
icalendar: str,
|
||||||
|
received_at: datetime | None = None,
|
||||||
|
evidence: Mapping[str, object] | None = None,
|
||||||
|
) -> Sequence[CalendarInvitationRef]:
|
||||||
|
...
|
||||||
|
|
||||||
|
|
||||||
|
@runtime_checkable
|
||||||
|
class CalendarExternalProfileProvider(Protocol):
|
||||||
|
"""Optional connector route for Calendar-owned groupware adapters."""
|
||||||
|
|
||||||
|
def supported_profiles(self) -> Sequence[Mapping[str, object]]:
|
||||||
|
...
|
||||||
|
|
||||||
|
def configure_profile(
|
||||||
|
self,
|
||||||
|
session: object,
|
||||||
|
*,
|
||||||
|
tenant_id: str,
|
||||||
|
user_id: str | None,
|
||||||
|
request: CalendarExternalProfileRequest,
|
||||||
|
) -> CalendarExternalProfileRef:
|
||||||
|
...
|
||||||
|
|
||||||
|
|
||||||
def calendar_scheduling_provider(registry: object | None) -> CalendarSchedulingProvider | None:
|
def calendar_scheduling_provider(registry: object | None) -> CalendarSchedulingProvider | None:
|
||||||
if registry is None or not hasattr(registry, "has_capability"):
|
if registry is None or not hasattr(registry, "has_capability"):
|
||||||
return None
|
return None
|
||||||
@@ -96,3 +318,29 @@ def calendar_outbox_provider(registry: object | None) -> CalendarOutboxProvider
|
|||||||
return None
|
return None
|
||||||
capability = registry.capability(CAPABILITY_CALENDAR_OUTBOX)
|
capability = registry.capability(CAPABILITY_CALENDAR_OUTBOX)
|
||||||
return capability if isinstance(capability, CalendarOutboxProvider) else None
|
return capability if isinstance(capability, CalendarOutboxProvider) else None
|
||||||
|
|
||||||
|
|
||||||
|
def calendar_invitation_provider(
|
||||||
|
registry: object | None,
|
||||||
|
) -> CalendarInvitationProvider | None:
|
||||||
|
if registry is None or not hasattr(registry, "has_capability"):
|
||||||
|
return None
|
||||||
|
if not registry.has_capability(CAPABILITY_CALENDAR_INVITATIONS):
|
||||||
|
return None
|
||||||
|
capability = registry.capability(CAPABILITY_CALENDAR_INVITATIONS)
|
||||||
|
return capability if isinstance(capability, CalendarInvitationProvider) else None
|
||||||
|
|
||||||
|
|
||||||
|
def calendar_external_profile_provider(
|
||||||
|
registry: object | None,
|
||||||
|
) -> CalendarExternalProfileProvider | None:
|
||||||
|
if registry is None or not hasattr(registry, "has_capability"):
|
||||||
|
return None
|
||||||
|
if not registry.has_capability(CAPABILITY_CALENDAR_EXTERNAL_PROFILES):
|
||||||
|
return None
|
||||||
|
capability = registry.capability(CAPABILITY_CALENDAR_EXTERNAL_PROFILES)
|
||||||
|
return (
|
||||||
|
capability
|
||||||
|
if isinstance(capability, CalendarExternalProfileProvider)
|
||||||
|
else None
|
||||||
|
)
|
||||||
|
|||||||
@@ -3,14 +3,29 @@ from __future__ import annotations
|
|||||||
from collections.abc import Callable, Iterable, Mapping
|
from collections.abc import Callable, Iterable, Mapping
|
||||||
from dataclasses import dataclass, field
|
from dataclasses import dataclass, field
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from typing import Protocol, runtime_checkable
|
from typing import Literal, Protocol, runtime_checkable
|
||||||
|
|
||||||
|
|
||||||
CAPABILITY_CAMPAIGNS_MAIL_POLICY_CONTEXT = "campaigns.mailPolicyContext"
|
CAPABILITY_CAMPAIGNS_MAIL_POLICY_CONTEXT = "campaigns.mailPolicyContext"
|
||||||
CAPABILITY_CAMPAIGNS_ACCESS = "campaigns.access"
|
CAPABILITY_CAMPAIGNS_ACCESS = "campaigns.access"
|
||||||
CAPABILITY_CAMPAIGNS_POLICY_CONTEXT = "campaigns.policyContext"
|
CAPABILITY_CAMPAIGNS_POLICY_CONTEXT = "campaigns.policyContext"
|
||||||
CAPABILITY_CAMPAIGNS_DELIVERY_TASKS = "campaigns.deliveryTasks"
|
CAPABILITY_CAMPAIGNS_DELIVERY_TASKS = "campaigns.deliveryTasks"
|
||||||
|
CAPABILITY_CAMPAIGNS_SCHEDULES = "campaigns.schedules"
|
||||||
CAPABILITY_CAMPAIGNS_RETENTION = "campaigns.retention"
|
CAPABILITY_CAMPAIGNS_RETENTION = "campaigns.retention"
|
||||||
|
CAPABILITY_CAMPAIGNS_WORK_ORCHESTRATION = "campaigns.workOrchestration"
|
||||||
|
|
||||||
|
CampaignWorkAssigneeKind = Literal[
|
||||||
|
"account",
|
||||||
|
"group",
|
||||||
|
"organization_function",
|
||||||
|
]
|
||||||
|
CampaignWorkHandoffStatus = Literal[
|
||||||
|
"open",
|
||||||
|
"in_progress",
|
||||||
|
"completed",
|
||||||
|
"rejected",
|
||||||
|
"cancelled",
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
@dataclass(frozen=True, slots=True)
|
@dataclass(frozen=True, slots=True)
|
||||||
@@ -31,6 +46,88 @@ class CampaignPolicyContext:
|
|||||||
settings: Mapping[str, object] = field(default_factory=dict)
|
settings: Mapping[str, object] = field(default_factory=dict)
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass(frozen=True, slots=True)
|
||||||
|
class CampaignWorkHandoffRequest:
|
||||||
|
"""Typed request used by Workflow to open accountable Campaign work."""
|
||||||
|
|
||||||
|
tenant_id: str
|
||||||
|
idempotency_key: str
|
||||||
|
purpose: str
|
||||||
|
assignee_kind: CampaignWorkAssigneeKind
|
||||||
|
assignee_id: str
|
||||||
|
campaign_id: str | None = None
|
||||||
|
create_external_id: str | None = None
|
||||||
|
create_name: str | None = None
|
||||||
|
create_description: str | None = None
|
||||||
|
expected_campaign_revision: int | None = None
|
||||||
|
due_at: datetime | None = None
|
||||||
|
mirror_to_tasks: bool = True
|
||||||
|
correlation_id: str | None = None
|
||||||
|
workflow_instance_id: str | None = None
|
||||||
|
workflow_step_id: str | None = None
|
||||||
|
|
||||||
|
def __post_init__(self) -> None:
|
||||||
|
for value, label in (
|
||||||
|
(self.tenant_id, "Campaign hand-off tenant"),
|
||||||
|
(self.idempotency_key, "Campaign hand-off idempotency key"),
|
||||||
|
(self.purpose, "Campaign hand-off purpose"),
|
||||||
|
(self.assignee_id, "Campaign hand-off assignee"),
|
||||||
|
):
|
||||||
|
if not value.strip():
|
||||||
|
raise ValueError(f"{label} is required")
|
||||||
|
references_existing = bool(self.campaign_id and self.campaign_id.strip())
|
||||||
|
creates_new = bool(
|
||||||
|
self.create_external_id
|
||||||
|
and self.create_external_id.strip()
|
||||||
|
and self.create_name
|
||||||
|
and self.create_name.strip()
|
||||||
|
)
|
||||||
|
if references_existing == creates_new:
|
||||||
|
raise ValueError(
|
||||||
|
"Campaign hand-offs must either reference one campaign or "
|
||||||
|
"declare one new campaign."
|
||||||
|
)
|
||||||
|
if self.expected_campaign_revision is not None and (
|
||||||
|
self.expected_campaign_revision < 1
|
||||||
|
):
|
||||||
|
raise ValueError("Expected Campaign revisions start at one")
|
||||||
|
if self.due_at is not None and self.due_at.tzinfo is None:
|
||||||
|
raise ValueError("Campaign hand-off due dates require a timezone")
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass(frozen=True, slots=True)
|
||||||
|
class CampaignWorkHandoffRef:
|
||||||
|
"""Stable, revision-bearing reference returned to the Workflow instance."""
|
||||||
|
|
||||||
|
tenant_id: str
|
||||||
|
campaign_id: str
|
||||||
|
campaign_version_id: str
|
||||||
|
campaign_revision: int
|
||||||
|
assignment_id: str
|
||||||
|
assignment_revision: int
|
||||||
|
status: CampaignWorkHandoffStatus
|
||||||
|
action_url: str
|
||||||
|
campaign_ref: str
|
||||||
|
assignment_ref: str
|
||||||
|
event_type: str = "campaign.work.changed"
|
||||||
|
replayed: bool = False
|
||||||
|
optional_capabilities: Mapping[str, bool] = field(default_factory=dict)
|
||||||
|
provenance: Mapping[str, object] = field(default_factory=dict)
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass(frozen=True, slots=True)
|
||||||
|
class CampaignWorkHandoffInspection:
|
||||||
|
"""Current authorization and revision check before Workflow continuation."""
|
||||||
|
|
||||||
|
allowed: bool
|
||||||
|
status: CampaignWorkHandoffStatus | None = None
|
||||||
|
assignment_revision: int | None = None
|
||||||
|
action_url: str | None = None
|
||||||
|
assignment_ref: str | None = None
|
||||||
|
reason: str | None = None
|
||||||
|
provenance: Mapping[str, object] = field(default_factory=dict)
|
||||||
|
|
||||||
|
|
||||||
@runtime_checkable
|
@runtime_checkable
|
||||||
class CampaignMailPolicyContextProvider(Protocol):
|
class CampaignMailPolicyContextProvider(Protocol):
|
||||||
def get_campaign_mail_policy_context(
|
def get_campaign_mail_policy_context(
|
||||||
@@ -95,6 +192,9 @@ class CampaignPolicyContextProvider(Protocol):
|
|||||||
|
|
||||||
@runtime_checkable
|
@runtime_checkable
|
||||||
class CampaignDeliveryTaskProvider(Protocol):
|
class CampaignDeliveryTaskProvider(Protocol):
|
||||||
|
def tenant_id_for_job(self, session: object, *, job_id: str) -> str | None:
|
||||||
|
...
|
||||||
|
|
||||||
def send_campaign_job(self, session: object, *, job_id: str, enqueue_imap_task: bool = True) -> Mapping[str, object]:
|
def send_campaign_job(self, session: object, *, job_id: str, enqueue_imap_task: bool = True) -> Mapping[str, object]:
|
||||||
...
|
...
|
||||||
|
|
||||||
@@ -102,6 +202,21 @@ class CampaignDeliveryTaskProvider(Protocol):
|
|||||||
...
|
...
|
||||||
|
|
||||||
|
|
||||||
|
@runtime_checkable
|
||||||
|
class CampaignScheduleProvider(Protocol):
|
||||||
|
"""Durable boundary for due manual drafts and governed autonomous occurrences."""
|
||||||
|
|
||||||
|
def dispatch_due(
|
||||||
|
self,
|
||||||
|
session: object,
|
||||||
|
*,
|
||||||
|
tenant_id: str | None = None,
|
||||||
|
now: datetime | None = None,
|
||||||
|
limit: int = 50,
|
||||||
|
) -> Mapping[str, object]:
|
||||||
|
...
|
||||||
|
|
||||||
|
|
||||||
@runtime_checkable
|
@runtime_checkable
|
||||||
class CampaignRetentionProvider(Protocol):
|
class CampaignRetentionProvider(Protocol):
|
||||||
def apply_retention(
|
def apply_retention(
|
||||||
@@ -113,3 +228,45 @@ class CampaignRetentionProvider(Protocol):
|
|||||||
policy_for_campaign_id: Callable[[str | None], object],
|
policy_for_campaign_id: Callable[[str | None], object],
|
||||||
) -> Mapping[str, Mapping[str, int]]:
|
) -> Mapping[str, Mapping[str, int]]:
|
||||||
...
|
...
|
||||||
|
|
||||||
|
|
||||||
|
@runtime_checkable
|
||||||
|
class CampaignWorkOrchestrationProvider(Protocol):
|
||||||
|
"""Optional Campaign boundary for durable Workflow-owned hand-offs."""
|
||||||
|
|
||||||
|
def prepare_handoff(
|
||||||
|
self,
|
||||||
|
session: object,
|
||||||
|
principal: object,
|
||||||
|
*,
|
||||||
|
request: CampaignWorkHandoffRequest,
|
||||||
|
) -> CampaignWorkHandoffRef:
|
||||||
|
...
|
||||||
|
|
||||||
|
def inspect_handoff(
|
||||||
|
self,
|
||||||
|
session: object,
|
||||||
|
principal: object,
|
||||||
|
*,
|
||||||
|
tenant_id: str,
|
||||||
|
assignment_id: str,
|
||||||
|
expected_revision: int | None = None,
|
||||||
|
) -> CampaignWorkHandoffInspection:
|
||||||
|
...
|
||||||
|
|
||||||
|
|
||||||
|
def campaign_work_orchestration_provider(
|
||||||
|
registry: object | None,
|
||||||
|
) -> CampaignWorkOrchestrationProvider | None:
|
||||||
|
if (
|
||||||
|
registry is None
|
||||||
|
or not hasattr(registry, "has_capability")
|
||||||
|
or not registry.has_capability(CAPABILITY_CAMPAIGNS_WORK_ORCHESTRATION)
|
||||||
|
):
|
||||||
|
return None
|
||||||
|
capability = registry.capability(CAPABILITY_CAMPAIGNS_WORK_ORCHESTRATION)
|
||||||
|
return (
|
||||||
|
capability
|
||||||
|
if isinstance(capability, CampaignWorkOrchestrationProvider)
|
||||||
|
else None
|
||||||
|
)
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,226 @@
|
|||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
from collections import Counter
|
||||||
|
from collections.abc import Mapping
|
||||||
|
from dataclasses import dataclass, field
|
||||||
|
from datetime import datetime
|
||||||
|
from typing import Literal, Protocol, runtime_checkable
|
||||||
|
from urllib.parse import urlsplit
|
||||||
|
|
||||||
|
|
||||||
|
CONNECTOR_RUNTIME_CONTRACT_VERSION = "1.0"
|
||||||
|
|
||||||
|
ConnectorDiagnosticSeverity = Literal["info", "warning", "error"]
|
||||||
|
ConnectorDiagnosticStage = Literal[
|
||||||
|
"configuration",
|
||||||
|
"authentication",
|
||||||
|
"discovery",
|
||||||
|
"read",
|
||||||
|
"mapping",
|
||||||
|
"planning",
|
||||||
|
"apply",
|
||||||
|
"reconciliation",
|
||||||
|
]
|
||||||
|
ConnectorEffectKind = Literal[
|
||||||
|
"create",
|
||||||
|
"update",
|
||||||
|
"delete",
|
||||||
|
"conflict",
|
||||||
|
"unchanged",
|
||||||
|
"ignored",
|
||||||
|
]
|
||||||
|
ConnectorOutcomeState = Literal[
|
||||||
|
"preview",
|
||||||
|
"accepted",
|
||||||
|
"rejected",
|
||||||
|
"outcome_unknown",
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
|
class ConnectorContractError(ValueError):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass(frozen=True, slots=True)
|
||||||
|
class ConnectorEndpoint:
|
||||||
|
"""Sanitized endpoint identity. Credentials never belong in this value."""
|
||||||
|
|
||||||
|
url: str
|
||||||
|
credential_ref: str | None = None
|
||||||
|
tls_mode: Literal["required", "start_tls", "system", "disabled"] = "required"
|
||||||
|
options: Mapping[str, object] = field(default_factory=dict)
|
||||||
|
|
||||||
|
def __post_init__(self) -> None:
|
||||||
|
normalized = self.url.strip()
|
||||||
|
parsed = urlsplit(normalized)
|
||||||
|
if not parsed.scheme or not parsed.hostname:
|
||||||
|
raise ConnectorContractError("Connector endpoints require an absolute URL.")
|
||||||
|
if parsed.username is not None or parsed.password is not None:
|
||||||
|
raise ConnectorContractError(
|
||||||
|
"Connector endpoint URLs must not contain credentials."
|
||||||
|
)
|
||||||
|
object.__setattr__(self, "url", normalized)
|
||||||
|
if self.credential_ref is not None:
|
||||||
|
credential_ref = self.credential_ref.strip()
|
||||||
|
if not credential_ref:
|
||||||
|
raise ConnectorContractError("Credential references cannot be blank.")
|
||||||
|
object.__setattr__(self, "credential_ref", credential_ref)
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass(frozen=True, slots=True)
|
||||||
|
class ConnectorDiagnostic:
|
||||||
|
severity: ConnectorDiagnosticSeverity
|
||||||
|
code: str
|
||||||
|
message: str
|
||||||
|
stage: ConnectorDiagnosticStage
|
||||||
|
retryable: bool = False
|
||||||
|
source_ref: str | None = None
|
||||||
|
object_ref: str | None = None
|
||||||
|
details: Mapping[str, object] = field(default_factory=dict)
|
||||||
|
|
||||||
|
def __post_init__(self) -> None:
|
||||||
|
if not self.code.strip() or len(self.code) > 120:
|
||||||
|
raise ConnectorContractError(
|
||||||
|
"Connector diagnostic codes must contain 1 to 120 characters."
|
||||||
|
)
|
||||||
|
if not self.message.strip():
|
||||||
|
raise ConnectorContractError("Connector diagnostic messages cannot be blank.")
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass(frozen=True, slots=True)
|
||||||
|
class ConnectorEffectPreview:
|
||||||
|
effect: ConnectorEffectKind
|
||||||
|
source_object_ref: str
|
||||||
|
target_object_ref: str | None = None
|
||||||
|
changed_fields: tuple[str, ...] = ()
|
||||||
|
sample: Mapping[str, object] = field(default_factory=dict)
|
||||||
|
reason_code: str | None = None
|
||||||
|
outcome: ConnectorOutcomeState = "preview"
|
||||||
|
revision: str | None = None
|
||||||
|
|
||||||
|
def __post_init__(self) -> None:
|
||||||
|
if not self.source_object_ref.strip():
|
||||||
|
raise ConnectorContractError("Preview effects require a source object reference.")
|
||||||
|
if self.outcome != "preview":
|
||||||
|
raise ConnectorContractError("Dry-run effects must retain the preview outcome.")
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass(frozen=True, slots=True)
|
||||||
|
class ConnectorEffectSummary:
|
||||||
|
creates: int = 0
|
||||||
|
updates: int = 0
|
||||||
|
deletes: int = 0
|
||||||
|
conflicts: int = 0
|
||||||
|
unchanged: int = 0
|
||||||
|
ignored: int = 0
|
||||||
|
|
||||||
|
@property
|
||||||
|
def total(self) -> int:
|
||||||
|
return (
|
||||||
|
self.creates
|
||||||
|
+ self.updates
|
||||||
|
+ self.deletes
|
||||||
|
+ self.conflicts
|
||||||
|
+ self.unchanged
|
||||||
|
+ self.ignored
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass(frozen=True, slots=True)
|
||||||
|
class ConnectorDryRunRequest:
|
||||||
|
tenant_id: str
|
||||||
|
source_ref: str
|
||||||
|
force_full: bool = False
|
||||||
|
max_items: int = 1_000
|
||||||
|
expected_source_revision: str | None = None
|
||||||
|
context: Mapping[str, object] = field(default_factory=dict)
|
||||||
|
|
||||||
|
def __post_init__(self) -> None:
|
||||||
|
if not self.tenant_id.strip() or not self.source_ref.strip():
|
||||||
|
raise ConnectorContractError("Dry runs require tenant and source references.")
|
||||||
|
if not 1 <= self.max_items <= 10_000:
|
||||||
|
raise ConnectorContractError("Dry-run max_items must be between 1 and 10000.")
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass(frozen=True, slots=True)
|
||||||
|
class ConnectorDryRunResult:
|
||||||
|
contract_version: str
|
||||||
|
source_ref: str
|
||||||
|
source_revision: str
|
||||||
|
source_fingerprint: str
|
||||||
|
input_hash: str
|
||||||
|
generated_at: datetime
|
||||||
|
summary: ConnectorEffectSummary
|
||||||
|
effects: tuple[ConnectorEffectPreview, ...] = ()
|
||||||
|
diagnostics: tuple[ConnectorDiagnostic, ...] = ()
|
||||||
|
truncated: bool = False
|
||||||
|
stale: bool = False
|
||||||
|
apply_token: str | None = None
|
||||||
|
provenance: Mapping[str, object] = field(default_factory=dict)
|
||||||
|
|
||||||
|
def __post_init__(self) -> None:
|
||||||
|
if self.contract_version != CONNECTOR_RUNTIME_CONTRACT_VERSION:
|
||||||
|
raise ConnectorContractError(
|
||||||
|
f"Unsupported connector contract version: {self.contract_version!r}."
|
||||||
|
)
|
||||||
|
for name in ("source_ref", "source_revision", "source_fingerprint", "input_hash"):
|
||||||
|
if not str(getattr(self, name)).strip():
|
||||||
|
raise ConnectorContractError(f"Dry-run {name} cannot be blank.")
|
||||||
|
if self.summary.total != len(self.effects):
|
||||||
|
raise ConnectorContractError(
|
||||||
|
"Dry-run summary counts must match the returned effect list."
|
||||||
|
)
|
||||||
|
|
||||||
|
@property
|
||||||
|
def can_apply(self) -> bool:
|
||||||
|
return (
|
||||||
|
self.apply_token is not None
|
||||||
|
and not self.truncated
|
||||||
|
and not self.stale
|
||||||
|
and self.summary.conflicts == 0
|
||||||
|
and not any(item.severity == "error" for item in self.diagnostics)
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def summarize_connector_effects(
|
||||||
|
effects: tuple[ConnectorEffectPreview, ...],
|
||||||
|
) -> ConnectorEffectSummary:
|
||||||
|
counts = Counter(item.effect for item in effects)
|
||||||
|
return ConnectorEffectSummary(
|
||||||
|
creates=counts["create"],
|
||||||
|
updates=counts["update"],
|
||||||
|
deletes=counts["delete"],
|
||||||
|
conflicts=counts["conflict"],
|
||||||
|
unchanged=counts["unchanged"],
|
||||||
|
ignored=counts["ignored"],
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@runtime_checkable
|
||||||
|
class ConnectorDryRunProvider(Protocol):
|
||||||
|
def preview(
|
||||||
|
self,
|
||||||
|
session: object,
|
||||||
|
principal: object,
|
||||||
|
*,
|
||||||
|
request: ConnectorDryRunRequest,
|
||||||
|
) -> ConnectorDryRunResult:
|
||||||
|
...
|
||||||
|
|
||||||
|
|
||||||
|
__all__ = [
|
||||||
|
"CONNECTOR_RUNTIME_CONTRACT_VERSION",
|
||||||
|
"ConnectorContractError",
|
||||||
|
"ConnectorDiagnostic",
|
||||||
|
"ConnectorDiagnosticSeverity",
|
||||||
|
"ConnectorDiagnosticStage",
|
||||||
|
"ConnectorDryRunProvider",
|
||||||
|
"ConnectorDryRunRequest",
|
||||||
|
"ConnectorDryRunResult",
|
||||||
|
"ConnectorEffectKind",
|
||||||
|
"ConnectorEffectPreview",
|
||||||
|
"ConnectorEffectSummary",
|
||||||
|
"ConnectorEndpoint",
|
||||||
|
"ConnectorOutcomeState",
|
||||||
|
"summarize_connector_effects",
|
||||||
|
]
|
||||||
@@ -0,0 +1,191 @@
|
|||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
from collections.abc import Mapping
|
||||||
|
from dataclasses import dataclass, field
|
||||||
|
from datetime import datetime
|
||||||
|
from typing import Literal, Protocol, runtime_checkable
|
||||||
|
|
||||||
|
from govoplan_core.core.distribution_lists import (
|
||||||
|
DistributionChannel,
|
||||||
|
DistributionExplanation,
|
||||||
|
DistributionOutcome,
|
||||||
|
DistributionSourceReference,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
CAPABILITY_ADDRESSES_CONTACT_POINT_RESOLUTION = "addresses.contact_point_resolution"
|
||||||
|
CONTACT_POINT_CONTRACT_VERSION = "1.0"
|
||||||
|
|
||||||
|
ContactPointFallbackRule = Literal["none", "primary", "any"]
|
||||||
|
PostalAddressFormat = Literal["domestic", "international"]
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass(frozen=True, slots=True)
|
||||||
|
class ContactPointResolutionRequest:
|
||||||
|
tenant_id: str
|
||||||
|
subject: DistributionSourceReference
|
||||||
|
effective_at: datetime
|
||||||
|
purpose: str | None = None
|
||||||
|
requested_channels: tuple[DistributionChannel, ...] = ()
|
||||||
|
address_purpose: str | None = None
|
||||||
|
fallback_rule: ContactPointFallbackRule = "primary"
|
||||||
|
locale: str | None = None
|
||||||
|
postal_format: PostalAddressFormat = "domestic"
|
||||||
|
context: Mapping[str, object] = field(default_factory=dict)
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass(frozen=True, slots=True)
|
||||||
|
class ContactPointCandidate:
|
||||||
|
channel: DistributionChannel
|
||||||
|
target: str
|
||||||
|
target_key: str
|
||||||
|
status: DistributionOutcome
|
||||||
|
contact_point_id: str | None = None
|
||||||
|
address_purpose: str | None = None
|
||||||
|
locale: str | None = None
|
||||||
|
preferred: bool = False
|
||||||
|
preference_rank: int | None = None
|
||||||
|
reason_code: str | None = None
|
||||||
|
explanation: str | None = None
|
||||||
|
source: DistributionSourceReference | None = None
|
||||||
|
source_revision: str | None = None
|
||||||
|
preference_revision: str | None = None
|
||||||
|
consent_revision: str | None = None
|
||||||
|
value: Mapping[str, object] = field(default_factory=dict)
|
||||||
|
provenance: Mapping[str, object] = field(default_factory=dict)
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass(frozen=True, slots=True)
|
||||||
|
class ContactPointResolution:
|
||||||
|
contract_version: str
|
||||||
|
subject: DistributionSourceReference
|
||||||
|
status: DistributionOutcome
|
||||||
|
contact_id: str | None = None
|
||||||
|
display_name: str | None = None
|
||||||
|
candidates: tuple[ContactPointCandidate, ...] = ()
|
||||||
|
excluded: tuple[ContactPointCandidate, ...] = ()
|
||||||
|
explanations: tuple[DistributionExplanation, ...] = ()
|
||||||
|
source_revision: str | None = None
|
||||||
|
source_fingerprint: str | None = None
|
||||||
|
provenance: Mapping[str, object] = field(default_factory=dict)
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass(frozen=True, slots=True)
|
||||||
|
class ContactPointSourceRequest:
|
||||||
|
tenant_id: str
|
||||||
|
source_id: str
|
||||||
|
effective_at: datetime
|
||||||
|
purpose: str | None = None
|
||||||
|
requested_channels: tuple[DistributionChannel, ...] = ()
|
||||||
|
address_purpose: str | None = None
|
||||||
|
fallback_rule: ContactPointFallbackRule = "primary"
|
||||||
|
locale: str | None = None
|
||||||
|
postal_format: PostalAddressFormat = "domestic"
|
||||||
|
max_items: int = 5_000
|
||||||
|
context: Mapping[str, object] = field(default_factory=dict)
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass(frozen=True, slots=True)
|
||||||
|
class ContactPointSourcePreview:
|
||||||
|
contract_version: str
|
||||||
|
source: DistributionSourceReference
|
||||||
|
request: ContactPointSourceRequest
|
||||||
|
resolutions: tuple[ContactPointResolution, ...]
|
||||||
|
total_count: int
|
||||||
|
usable_count: int
|
||||||
|
excluded_count: int
|
||||||
|
offset: int
|
||||||
|
limit: int
|
||||||
|
has_more: bool
|
||||||
|
source_revision: str
|
||||||
|
source_fingerprint: str
|
||||||
|
generated_at: datetime
|
||||||
|
provenance: Mapping[str, object] = field(default_factory=dict)
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass(frozen=True, slots=True)
|
||||||
|
class ContactPointSnapshotRef:
|
||||||
|
id: str
|
||||||
|
tenant_id: str
|
||||||
|
contract_version: str
|
||||||
|
source: DistributionSourceReference
|
||||||
|
request: ContactPointSourceRequest
|
||||||
|
resolutions: tuple[ContactPointResolution, ...]
|
||||||
|
recipient_count: int
|
||||||
|
excluded_count: int
|
||||||
|
source_revision: str
|
||||||
|
source_fingerprint: str
|
||||||
|
snapshot_hash: str
|
||||||
|
generated_at: datetime
|
||||||
|
provenance: Mapping[str, object] = field(default_factory=dict)
|
||||||
|
|
||||||
|
|
||||||
|
@runtime_checkable
|
||||||
|
class ContactPointResolutionProvider(Protocol):
|
||||||
|
def resolve_contact_points(
|
||||||
|
self,
|
||||||
|
session: object,
|
||||||
|
principal: object,
|
||||||
|
*,
|
||||||
|
request: ContactPointResolutionRequest,
|
||||||
|
) -> ContactPointResolution:
|
||||||
|
...
|
||||||
|
|
||||||
|
def preview_source(
|
||||||
|
self,
|
||||||
|
session: object,
|
||||||
|
principal: object,
|
||||||
|
*,
|
||||||
|
request: ContactPointSourceRequest,
|
||||||
|
offset: int = 0,
|
||||||
|
limit: int = 100,
|
||||||
|
) -> ContactPointSourcePreview:
|
||||||
|
...
|
||||||
|
|
||||||
|
def freeze_source(
|
||||||
|
self,
|
||||||
|
session: object,
|
||||||
|
principal: object,
|
||||||
|
*,
|
||||||
|
request: ContactPointSourceRequest,
|
||||||
|
) -> ContactPointSnapshotRef:
|
||||||
|
...
|
||||||
|
|
||||||
|
def get_snapshot(
|
||||||
|
self,
|
||||||
|
session: object,
|
||||||
|
principal: object,
|
||||||
|
*,
|
||||||
|
snapshot_id: str,
|
||||||
|
) -> ContactPointSnapshotRef | None:
|
||||||
|
...
|
||||||
|
|
||||||
|
|
||||||
|
def contact_point_resolution_provider(
|
||||||
|
registry: object | None,
|
||||||
|
) -> ContactPointResolutionProvider | None:
|
||||||
|
if (
|
||||||
|
registry is None
|
||||||
|
or not hasattr(registry, "has_capability")
|
||||||
|
or not hasattr(registry, "capability")
|
||||||
|
or not registry.has_capability(CAPABILITY_ADDRESSES_CONTACT_POINT_RESOLUTION)
|
||||||
|
):
|
||||||
|
return None
|
||||||
|
capability = registry.capability(CAPABILITY_ADDRESSES_CONTACT_POINT_RESOLUTION)
|
||||||
|
return capability if isinstance(capability, ContactPointResolutionProvider) else None
|
||||||
|
|
||||||
|
|
||||||
|
__all__ = [
|
||||||
|
"CAPABILITY_ADDRESSES_CONTACT_POINT_RESOLUTION",
|
||||||
|
"CONTACT_POINT_CONTRACT_VERSION",
|
||||||
|
"ContactPointCandidate",
|
||||||
|
"ContactPointFallbackRule",
|
||||||
|
"ContactPointResolution",
|
||||||
|
"ContactPointResolutionProvider",
|
||||||
|
"ContactPointResolutionRequest",
|
||||||
|
"ContactPointSnapshotRef",
|
||||||
|
"ContactPointSourcePreview",
|
||||||
|
"ContactPointSourceRequest",
|
||||||
|
"PostalAddressFormat",
|
||||||
|
"contact_point_resolution_provider",
|
||||||
|
]
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
from collections.abc import Mapping
|
from collections.abc import Mapping, Sequence
|
||||||
from dataclasses import dataclass, field
|
from dataclasses import dataclass, field
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from typing import Protocol, runtime_checkable
|
from typing import Protocol, runtime_checkable
|
||||||
@@ -12,6 +12,7 @@ from govoplan_core.core.events import PlatformEvent
|
|||||||
CAPABILITY_DATAFLOW_RUN_LIFECYCLE = "dataflow.runLifecycle"
|
CAPABILITY_DATAFLOW_RUN_LIFECYCLE = "dataflow.runLifecycle"
|
||||||
CAPABILITY_DATAFLOW_RUN_WORKER = "dataflow.runWorker"
|
CAPABILITY_DATAFLOW_RUN_WORKER = "dataflow.runWorker"
|
||||||
CAPABILITY_DATAFLOW_TRIGGER_DISPATCHER = "dataflow.triggerDispatcher"
|
CAPABILITY_DATAFLOW_TRIGGER_DISPATCHER = "dataflow.triggerDispatcher"
|
||||||
|
CAPABILITY_DATAFLOW_DATASET_OUTPUT = "dataflow.dataset_output"
|
||||||
|
|
||||||
|
|
||||||
class DataflowRunError(ValueError):
|
class DataflowRunError(ValueError):
|
||||||
@@ -30,6 +31,67 @@ class DataflowRunUnavailableError(DataflowRunError):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass(frozen=True, slots=True)
|
||||||
|
class DataflowDatasetDescriptor:
|
||||||
|
pipeline_ref: str
|
||||||
|
name: str
|
||||||
|
revision: int
|
||||||
|
definition_hash: str
|
||||||
|
status: str
|
||||||
|
description: str | None = None
|
||||||
|
updated_at: datetime | None = None
|
||||||
|
parameters: Mapping[str, object] = field(default_factory=dict)
|
||||||
|
provenance: Mapping[str, object] = field(default_factory=dict)
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass(frozen=True, slots=True)
|
||||||
|
class DataflowDatasetRequest:
|
||||||
|
pipeline_ref: str
|
||||||
|
revision: int
|
||||||
|
parameters: Mapping[str, object] = field(default_factory=dict)
|
||||||
|
row_limit: int = 500
|
||||||
|
expected_definition_hash: str | None = None
|
||||||
|
expected_source_fingerprints: tuple[Mapping[str, object], ...] = ()
|
||||||
|
run_ref: str | None = None
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass(frozen=True, slots=True)
|
||||||
|
class DataflowDatasetResult:
|
||||||
|
pipeline_ref: str
|
||||||
|
revision: int
|
||||||
|
definition_hash: str
|
||||||
|
rows: tuple[Mapping[str, object], ...]
|
||||||
|
total_rows: int
|
||||||
|
truncated: bool
|
||||||
|
output_hash: str
|
||||||
|
executor_version: str
|
||||||
|
run_ref: str | None = None
|
||||||
|
source_fingerprints: tuple[Mapping[str, object], ...] = ()
|
||||||
|
diagnostics: tuple[Mapping[str, object], ...] = ()
|
||||||
|
generated_at: datetime | None = None
|
||||||
|
provenance: Mapping[str, object] = field(default_factory=dict)
|
||||||
|
|
||||||
|
|
||||||
|
@runtime_checkable
|
||||||
|
class DataflowDatasetOutputProvider(Protocol):
|
||||||
|
def list_outputs(
|
||||||
|
self,
|
||||||
|
session: object,
|
||||||
|
principal: object,
|
||||||
|
*,
|
||||||
|
query: str = "",
|
||||||
|
limit: int = 100,
|
||||||
|
) -> Sequence[DataflowDatasetDescriptor]: ...
|
||||||
|
|
||||||
|
def read_output(
|
||||||
|
self,
|
||||||
|
session: object,
|
||||||
|
principal: object,
|
||||||
|
*,
|
||||||
|
request: DataflowDatasetRequest,
|
||||||
|
) -> DataflowDatasetResult: ...
|
||||||
|
|
||||||
|
|
||||||
@dataclass(frozen=True, slots=True)
|
@dataclass(frozen=True, slots=True)
|
||||||
class DataflowPublicationTarget:
|
class DataflowPublicationTarget:
|
||||||
target_datasource_ref: str | None = None
|
target_datasource_ref: str | None = None
|
||||||
@@ -117,6 +179,7 @@ class DataflowTriggerDispatcher(Protocol):
|
|||||||
self,
|
self,
|
||||||
session: object,
|
session: object,
|
||||||
*,
|
*,
|
||||||
|
tenant_id: str | None = None,
|
||||||
now: datetime | None = None,
|
now: datetime | None = None,
|
||||||
limit: int = 50,
|
limit: int = 50,
|
||||||
) -> Mapping[str, object]:
|
) -> Mapping[str, object]:
|
||||||
@@ -143,6 +206,7 @@ class DataflowRunWorker(Protocol):
|
|||||||
self,
|
self,
|
||||||
session: object,
|
session: object,
|
||||||
*,
|
*,
|
||||||
|
tenant_id: str | None = None,
|
||||||
now: datetime | None = None,
|
now: datetime | None = None,
|
||||||
limit: int = 10,
|
limit: int = 10,
|
||||||
worker_id: str | None = None,
|
worker_id: str | None = None,
|
||||||
@@ -153,6 +217,7 @@ class DataflowRunWorker(Protocol):
|
|||||||
self,
|
self,
|
||||||
session: object,
|
session: object,
|
||||||
*,
|
*,
|
||||||
|
tenant_id: str | None = None,
|
||||||
now: datetime | None = None,
|
now: datetime | None = None,
|
||||||
limit: int = 500,
|
limit: int = 500,
|
||||||
) -> Mapping[str, object]:
|
) -> Mapping[str, object]:
|
||||||
@@ -184,6 +249,13 @@ def dataflow_trigger_dispatcher(
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def dataflow_dataset_output(
|
||||||
|
registry: object | None,
|
||||||
|
) -> DataflowDatasetOutputProvider | None:
|
||||||
|
capability = _capability(registry, CAPABILITY_DATAFLOW_DATASET_OUTPUT)
|
||||||
|
return capability if isinstance(capability, DataflowDatasetOutputProvider) else None
|
||||||
|
|
||||||
|
|
||||||
def _capability(registry: object | None, name: str) -> object | None:
|
def _capability(registry: object | None, name: str) -> object | None:
|
||||||
if (
|
if (
|
||||||
registry is None
|
registry is None
|
||||||
@@ -199,6 +271,11 @@ __all__ = [
|
|||||||
"CAPABILITY_DATAFLOW_RUN_LIFECYCLE",
|
"CAPABILITY_DATAFLOW_RUN_LIFECYCLE",
|
||||||
"CAPABILITY_DATAFLOW_RUN_WORKER",
|
"CAPABILITY_DATAFLOW_RUN_WORKER",
|
||||||
"CAPABILITY_DATAFLOW_TRIGGER_DISPATCHER",
|
"CAPABILITY_DATAFLOW_TRIGGER_DISPATCHER",
|
||||||
|
"CAPABILITY_DATAFLOW_DATASET_OUTPUT",
|
||||||
|
"DataflowDatasetDescriptor",
|
||||||
|
"DataflowDatasetOutputProvider",
|
||||||
|
"DataflowDatasetRequest",
|
||||||
|
"DataflowDatasetResult",
|
||||||
"DataflowPublicationTarget",
|
"DataflowPublicationTarget",
|
||||||
"DataflowRunConflictError",
|
"DataflowRunConflictError",
|
||||||
"DataflowRunDescriptor",
|
"DataflowRunDescriptor",
|
||||||
@@ -212,4 +289,5 @@ __all__ = [
|
|||||||
"dataflow_run_lifecycle",
|
"dataflow_run_lifecycle",
|
||||||
"dataflow_run_worker",
|
"dataflow_run_worker",
|
||||||
"dataflow_trigger_dispatcher",
|
"dataflow_trigger_dispatcher",
|
||||||
|
"dataflow_dataset_output",
|
||||||
]
|
]
|
||||||
|
|||||||
@@ -5,11 +5,27 @@ from dataclasses import dataclass, field
|
|||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from typing import Literal, Protocol, runtime_checkable
|
from typing import Literal, Protocol, runtime_checkable
|
||||||
|
|
||||||
|
from govoplan_core.core.access import PrincipalRef
|
||||||
|
from govoplan_core.core.external_references import (
|
||||||
|
SOURCE_AUTHORITY_MODES,
|
||||||
|
SourceAuthorityMode,
|
||||||
|
)
|
||||||
|
from govoplan_core.core.tabular_sources import (
|
||||||
|
DEFAULT_PREVIEW_BYTES,
|
||||||
|
DEFAULT_PREVIEW_TIMEOUT_MS,
|
||||||
|
TabularPreviewDiagnostic,
|
||||||
|
TabularPushdown,
|
||||||
|
TabularSourceHealth,
|
||||||
|
TabularSourceMode,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
CAPABILITY_DATASOURCE_CATALOGUE = "datasources.catalogue"
|
CAPABILITY_DATASOURCE_CATALOGUE = "datasources.catalogue"
|
||||||
CAPABILITY_DATASOURCE_LIFECYCLE = "datasources.lifecycle"
|
CAPABILITY_DATASOURCE_LIFECYCLE = "datasources.lifecycle"
|
||||||
CAPABILITY_DATASOURCE_PUBLICATION = "datasources.publication"
|
CAPABILITY_DATASOURCE_PUBLICATION = "datasources.publication"
|
||||||
CAPABILITY_DATASOURCE_ORIGINS = "connectors.datasourceOrigins"
|
CAPABILITY_DATASOURCE_ORIGINS = "connectors.datasourceOrigins"
|
||||||
|
CAPABILITY_DATASOURCE_ARTIFACT_BACKENDS = "datasources.artifactBackends"
|
||||||
|
CAPABILITY_POLICY_DATASOURCE_VISIBILITY = "policy.datasourceVisibility"
|
||||||
|
|
||||||
DatasourceMode = Literal["live", "cached", "static"]
|
DatasourceMode = Literal["live", "cached", "static"]
|
||||||
DatasourceKind = Literal[
|
DatasourceKind = Literal[
|
||||||
@@ -24,6 +40,12 @@ DatasourceKind = Literal[
|
|||||||
]
|
]
|
||||||
DatasourceShape = Literal["tabular", "document", "binary", "directory", "stream"]
|
DatasourceShape = Literal["tabular", "document", "binary", "directory", "stream"]
|
||||||
DatasourceConsistency = Literal["current", "live", "frozen"]
|
DatasourceConsistency = Literal["current", "live", "frozen"]
|
||||||
|
DatasourceVisibilityAction = Literal["discover", "read"]
|
||||||
|
DatasourcePublicationStatus = Literal[
|
||||||
|
"published",
|
||||||
|
"published_with_warnings",
|
||||||
|
"review_required",
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
class DatasourceError(ValueError):
|
class DatasourceError(ValueError):
|
||||||
@@ -51,6 +73,187 @@ class DatasourceField:
|
|||||||
name: str
|
name: str
|
||||||
data_type: str
|
data_type: str
|
||||||
nullable: bool = True
|
nullable: bool = True
|
||||||
|
classification: str = "internal"
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass(frozen=True, slots=True)
|
||||||
|
class DatasourceGovernance:
|
||||||
|
"""Provider-neutral governance facts attached to a datasource revision."""
|
||||||
|
|
||||||
|
owner_ref: str | None = None
|
||||||
|
steward_ref: str | None = None
|
||||||
|
responsible_organization_ref: str | None = None
|
||||||
|
responsible_function_ref: str | None = None
|
||||||
|
authoritative_source_ref: str | None = None
|
||||||
|
authority_mode: SourceAuthorityMode = "linked_reference"
|
||||||
|
legal_basis_refs: tuple[str, ...] = ()
|
||||||
|
purposes: tuple[str, ...] = ()
|
||||||
|
semantic_definition: str | None = None
|
||||||
|
schema_owner_ref: str | None = None
|
||||||
|
official_keys: tuple[str, ...] = ()
|
||||||
|
classification: str = "internal"
|
||||||
|
privacy_profile_ref: str | None = None
|
||||||
|
retention_policy_ref: str | None = None
|
||||||
|
access_policy_ref: str | None = None
|
||||||
|
visibility_policy: Mapping[str, object] = field(default_factory=dict)
|
||||||
|
hold_refs: tuple[str, ...] = ()
|
||||||
|
publication_state: str = "draft"
|
||||||
|
transfer_agreement_ref: str | None = None
|
||||||
|
freshness_policy: Mapping[str, object] = field(default_factory=dict)
|
||||||
|
quality_policy: Mapping[str, object] = field(default_factory=dict)
|
||||||
|
approval_policy: Mapping[str, object] = field(default_factory=dict)
|
||||||
|
retention_policy: Mapping[str, object] = field(default_factory=dict)
|
||||||
|
known_limits: tuple[str, ...] = ()
|
||||||
|
correction_procedure_ref: str | None = None
|
||||||
|
affected_refs: tuple[str, ...] = ()
|
||||||
|
dependency_refs: tuple[str, ...] = ()
|
||||||
|
|
||||||
|
def __post_init__(self) -> None:
|
||||||
|
if self.authority_mode not in SOURCE_AUTHORITY_MODES:
|
||||||
|
raise DatasourceValidationError(
|
||||||
|
f"Unsupported datasource authority mode: {self.authority_mode!r}."
|
||||||
|
)
|
||||||
|
if not self.classification.strip():
|
||||||
|
raise DatasourceValidationError("Datasource classification is required.")
|
||||||
|
if not self.publication_state.strip():
|
||||||
|
raise DatasourceValidationError("Datasource publication state is required.")
|
||||||
|
for field_name in (
|
||||||
|
"legal_basis_refs",
|
||||||
|
"purposes",
|
||||||
|
"official_keys",
|
||||||
|
"hold_refs",
|
||||||
|
"known_limits",
|
||||||
|
"affected_refs",
|
||||||
|
"dependency_refs",
|
||||||
|
):
|
||||||
|
values = getattr(self, field_name)
|
||||||
|
if any(not value.strip() for value in values):
|
||||||
|
raise DatasourceValidationError(
|
||||||
|
f"Datasource governance {field_name} cannot contain empty values."
|
||||||
|
)
|
||||||
|
if len(values) != len(set(values)):
|
||||||
|
raise DatasourceValidationError(
|
||||||
|
f"Datasource governance {field_name} cannot contain duplicates."
|
||||||
|
)
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def from_mapping(cls, value: Mapping[str, object] | None) -> "DatasourceGovernance":
|
||||||
|
source = value or {}
|
||||||
|
return cls(
|
||||||
|
owner_ref=_optional_governance_text(source.get("owner_ref")),
|
||||||
|
steward_ref=_optional_governance_text(source.get("steward_ref")),
|
||||||
|
responsible_organization_ref=_optional_governance_text(
|
||||||
|
source.get("responsible_organization_ref")
|
||||||
|
),
|
||||||
|
responsible_function_ref=_optional_governance_text(
|
||||||
|
source.get("responsible_function_ref")
|
||||||
|
),
|
||||||
|
authoritative_source_ref=_optional_governance_text(
|
||||||
|
source.get("authoritative_source_ref")
|
||||||
|
),
|
||||||
|
authority_mode=str(
|
||||||
|
source.get("authority_mode") or "linked_reference"
|
||||||
|
), # type: ignore[arg-type]
|
||||||
|
legal_basis_refs=_governance_texts(source.get("legal_basis_refs")),
|
||||||
|
purposes=_governance_texts(source.get("purposes")),
|
||||||
|
semantic_definition=_optional_governance_text(
|
||||||
|
source.get("semantic_definition")
|
||||||
|
),
|
||||||
|
schema_owner_ref=_optional_governance_text(source.get("schema_owner_ref")),
|
||||||
|
official_keys=_governance_texts(source.get("official_keys")),
|
||||||
|
classification=str(source.get("classification") or "internal"),
|
||||||
|
privacy_profile_ref=_optional_governance_text(
|
||||||
|
source.get("privacy_profile_ref")
|
||||||
|
),
|
||||||
|
retention_policy_ref=_optional_governance_text(
|
||||||
|
source.get("retention_policy_ref")
|
||||||
|
),
|
||||||
|
access_policy_ref=_optional_governance_text(
|
||||||
|
source.get("access_policy_ref")
|
||||||
|
),
|
||||||
|
visibility_policy=_governance_mapping(
|
||||||
|
source.get("visibility_policy")
|
||||||
|
),
|
||||||
|
hold_refs=_governance_texts(source.get("hold_refs")),
|
||||||
|
publication_state=str(source.get("publication_state") or "draft"),
|
||||||
|
transfer_agreement_ref=_optional_governance_text(
|
||||||
|
source.get("transfer_agreement_ref")
|
||||||
|
),
|
||||||
|
freshness_policy=_governance_mapping(source.get("freshness_policy")),
|
||||||
|
quality_policy=_governance_mapping(source.get("quality_policy")),
|
||||||
|
approval_policy=_governance_mapping(source.get("approval_policy")),
|
||||||
|
retention_policy=_governance_mapping(source.get("retention_policy")),
|
||||||
|
known_limits=_governance_texts(source.get("known_limits")),
|
||||||
|
correction_procedure_ref=_optional_governance_text(
|
||||||
|
source.get("correction_procedure_ref")
|
||||||
|
),
|
||||||
|
affected_refs=_governance_texts(source.get("affected_refs")),
|
||||||
|
dependency_refs=_governance_texts(source.get("dependency_refs")),
|
||||||
|
)
|
||||||
|
|
||||||
|
def to_dict(self) -> dict[str, object]:
|
||||||
|
return {
|
||||||
|
"owner_ref": self.owner_ref,
|
||||||
|
"steward_ref": self.steward_ref,
|
||||||
|
"responsible_organization_ref": self.responsible_organization_ref,
|
||||||
|
"responsible_function_ref": self.responsible_function_ref,
|
||||||
|
"authoritative_source_ref": self.authoritative_source_ref,
|
||||||
|
"authority_mode": self.authority_mode,
|
||||||
|
"legal_basis_refs": list(self.legal_basis_refs),
|
||||||
|
"purposes": list(self.purposes),
|
||||||
|
"semantic_definition": self.semantic_definition,
|
||||||
|
"schema_owner_ref": self.schema_owner_ref,
|
||||||
|
"official_keys": list(self.official_keys),
|
||||||
|
"classification": self.classification,
|
||||||
|
"privacy_profile_ref": self.privacy_profile_ref,
|
||||||
|
"retention_policy_ref": self.retention_policy_ref,
|
||||||
|
"access_policy_ref": self.access_policy_ref,
|
||||||
|
"visibility_policy": dict(self.visibility_policy),
|
||||||
|
"hold_refs": list(self.hold_refs),
|
||||||
|
"publication_state": self.publication_state,
|
||||||
|
"transfer_agreement_ref": self.transfer_agreement_ref,
|
||||||
|
"freshness_policy": dict(self.freshness_policy),
|
||||||
|
"quality_policy": dict(self.quality_policy),
|
||||||
|
"approval_policy": dict(self.approval_policy),
|
||||||
|
"retention_policy": dict(self.retention_policy),
|
||||||
|
"known_limits": list(self.known_limits),
|
||||||
|
"correction_procedure_ref": self.correction_procedure_ref,
|
||||||
|
"affected_refs": list(self.affected_refs),
|
||||||
|
"dependency_refs": list(self.dependency_refs),
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass(frozen=True, slots=True)
|
||||||
|
class DatasourceVisibilityPolicyRequest:
|
||||||
|
tenant_id: str
|
||||||
|
datasource_ref: str
|
||||||
|
principal: PrincipalRef
|
||||||
|
action: DatasourceVisibilityAction
|
||||||
|
classification: str = "internal"
|
||||||
|
policy_ref: str | None = None
|
||||||
|
consistency: DatasourceConsistency = "current"
|
||||||
|
materialization_ref: str | None = None
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass(frozen=True, slots=True)
|
||||||
|
class DatasourceVisibilityPolicyDecision:
|
||||||
|
allowed: bool
|
||||||
|
reason: str | None = None
|
||||||
|
policies: tuple[Mapping[str, object], ...] = ()
|
||||||
|
decision_ref: str | None = None
|
||||||
|
provenance: Mapping[str, object] = field(default_factory=dict)
|
||||||
|
|
||||||
|
|
||||||
|
@runtime_checkable
|
||||||
|
class DatasourceVisibilityPolicyProvider(Protocol):
|
||||||
|
"""Optionally tighten Datasources-owned local visibility policy."""
|
||||||
|
|
||||||
|
def decide_datasource_visibility(
|
||||||
|
self,
|
||||||
|
session: object,
|
||||||
|
*,
|
||||||
|
request: DatasourceVisibilityPolicyRequest,
|
||||||
|
) -> DatasourceVisibilityPolicyDecision: ...
|
||||||
|
|
||||||
|
|
||||||
@dataclass(frozen=True, slots=True)
|
@dataclass(frozen=True, slots=True)
|
||||||
@@ -75,6 +278,7 @@ class DatasourceDescriptor:
|
|||||||
capabilities: tuple[str, ...] = ("read",)
|
capabilities: tuple[str, ...] = ("read",)
|
||||||
provenance: Mapping[str, object] = field(default_factory=dict)
|
provenance: Mapping[str, object] = field(default_factory=dict)
|
||||||
metadata: Mapping[str, object] = field(default_factory=dict)
|
metadata: Mapping[str, object] = field(default_factory=dict)
|
||||||
|
governance: DatasourceGovernance = field(default_factory=DatasourceGovernance)
|
||||||
|
|
||||||
|
|
||||||
@dataclass(frozen=True, slots=True)
|
@dataclass(frozen=True, slots=True)
|
||||||
@@ -91,8 +295,11 @@ class DatasourceMaterialization:
|
|||||||
frozen_label: str | None = None
|
frozen_label: str | None = None
|
||||||
source_timestamp: datetime | None = None
|
source_timestamp: datetime | None = None
|
||||||
created_at: datetime | None = None
|
created_at: datetime | None = None
|
||||||
|
disposed_at: datetime | None = None
|
||||||
|
disposition: Mapping[str, object] = field(default_factory=dict)
|
||||||
provenance: Mapping[str, object] = field(default_factory=dict)
|
provenance: Mapping[str, object] = field(default_factory=dict)
|
||||||
metadata: Mapping[str, object] = field(default_factory=dict)
|
metadata: Mapping[str, object] = field(default_factory=dict)
|
||||||
|
governance: DatasourceGovernance = field(default_factory=DatasourceGovernance)
|
||||||
|
|
||||||
|
|
||||||
@dataclass(frozen=True, slots=True)
|
@dataclass(frozen=True, slots=True)
|
||||||
@@ -110,11 +317,13 @@ class DatasourceStage:
|
|||||||
row_count: int | None = None
|
row_count: int | None = None
|
||||||
byte_count: int | None = None
|
byte_count: int | None = None
|
||||||
validation: Mapping[str, object] = field(default_factory=dict)
|
validation: Mapping[str, object] = field(default_factory=dict)
|
||||||
|
approval: Mapping[str, object] = field(default_factory=dict)
|
||||||
created_at: datetime | None = None
|
created_at: datetime | None = None
|
||||||
promoted_at: datetime | None = None
|
promoted_at: datetime | None = None
|
||||||
promoted_materialization_ref: str | None = None
|
promoted_materialization_ref: str | None = None
|
||||||
provenance: Mapping[str, object] = field(default_factory=dict)
|
provenance: Mapping[str, object] = field(default_factory=dict)
|
||||||
metadata: Mapping[str, object] = field(default_factory=dict)
|
metadata: Mapping[str, object] = field(default_factory=dict)
|
||||||
|
governance: DatasourceGovernance = field(default_factory=DatasourceGovernance)
|
||||||
|
|
||||||
|
|
||||||
@dataclass(frozen=True, slots=True)
|
@dataclass(frozen=True, slots=True)
|
||||||
@@ -126,6 +335,8 @@ class DatasourceReadRequest:
|
|||||||
offset: int = 0
|
offset: int = 0
|
||||||
columns: tuple[str, ...] = ()
|
columns: tuple[str, ...] = ()
|
||||||
expected_fingerprint: str | None = None
|
expected_fingerprint: str | None = None
|
||||||
|
max_bytes: int = DEFAULT_PREVIEW_BYTES
|
||||||
|
timeout_ms: int = DEFAULT_PREVIEW_TIMEOUT_MS
|
||||||
|
|
||||||
|
|
||||||
@dataclass(frozen=True, slots=True)
|
@dataclass(frozen=True, slots=True)
|
||||||
@@ -135,6 +346,12 @@ class DatasourceReadResult:
|
|||||||
total_rows: int
|
total_rows: int
|
||||||
truncated: bool
|
truncated: bool
|
||||||
materialization: DatasourceMaterialization | None = None
|
materialization: DatasourceMaterialization | None = None
|
||||||
|
returned_bytes: int = 0
|
||||||
|
elapsed_ms: int = 0
|
||||||
|
effective_row_limit: int = 0
|
||||||
|
effective_byte_limit: int = 0
|
||||||
|
effective_timeout_ms: int = 0
|
||||||
|
diagnostics: tuple[TabularPreviewDiagnostic, ...] = ()
|
||||||
|
|
||||||
|
|
||||||
@dataclass(frozen=True, slots=True)
|
@dataclass(frozen=True, slots=True)
|
||||||
@@ -151,6 +368,67 @@ class DatasourceStageInput:
|
|||||||
provider_ref: str | None = None
|
provider_ref: str | None = None
|
||||||
provenance: Mapping[str, object] = field(default_factory=dict)
|
provenance: Mapping[str, object] = field(default_factory=dict)
|
||||||
metadata: Mapping[str, object] = field(default_factory=dict)
|
metadata: Mapping[str, object] = field(default_factory=dict)
|
||||||
|
governance: DatasourceGovernance | None = None
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass(frozen=True, slots=True)
|
||||||
|
class DatasourceArtifactReference:
|
||||||
|
"""Immutable provider-neutral reference to a durable tabular payload.
|
||||||
|
|
||||||
|
The producer owns creation of the payload. Datasources pins its locator,
|
||||||
|
checksum and declared shape without importing the artifact-owning module;
|
||||||
|
a configured payload backend verifies integrity and provides bounded reads.
|
||||||
|
"""
|
||||||
|
|
||||||
|
backend: str
|
||||||
|
locator: str
|
||||||
|
checksum: str
|
||||||
|
row_count: int
|
||||||
|
byte_count: int
|
||||||
|
schema: tuple[DatasourceField, ...]
|
||||||
|
fingerprint: str
|
||||||
|
media_type: str = "application/x-ndjson"
|
||||||
|
checkpoint: Mapping[str, object] = field(default_factory=dict)
|
||||||
|
metadata: Mapping[str, object] = field(default_factory=dict)
|
||||||
|
validation: Mapping[str, object] = field(default_factory=dict)
|
||||||
|
|
||||||
|
|
||||||
|
@runtime_checkable
|
||||||
|
class DatasourceArtifactBackend(Protocol):
|
||||||
|
"""Storage-module boundary for immutable artifact-backed tabular data."""
|
||||||
|
|
||||||
|
backend: str
|
||||||
|
|
||||||
|
def verify(
|
||||||
|
self,
|
||||||
|
session: object,
|
||||||
|
*,
|
||||||
|
tenant_id: str,
|
||||||
|
artifact: DatasourceArtifactReference,
|
||||||
|
) -> None: ...
|
||||||
|
|
||||||
|
def read_rows(
|
||||||
|
self,
|
||||||
|
session: object,
|
||||||
|
*,
|
||||||
|
tenant_id: str,
|
||||||
|
artifact: DatasourceArtifactReference,
|
||||||
|
offset: int,
|
||||||
|
limit: int,
|
||||||
|
) -> Sequence[Mapping[str, object]]: ...
|
||||||
|
|
||||||
|
def delete(
|
||||||
|
self,
|
||||||
|
session: object,
|
||||||
|
*,
|
||||||
|
tenant_id: str,
|
||||||
|
artifact: DatasourceArtifactReference,
|
||||||
|
) -> None: ...
|
||||||
|
|
||||||
|
|
||||||
|
@runtime_checkable
|
||||||
|
class DatasourceArtifactBackendProvider(Protocol):
|
||||||
|
def artifact_backends(self) -> Sequence[DatasourceArtifactBackend]: ...
|
||||||
|
|
||||||
|
|
||||||
@dataclass(frozen=True, slots=True)
|
@dataclass(frozen=True, slots=True)
|
||||||
@@ -158,7 +436,8 @@ class DatasourcePublicationRequest:
|
|||||||
producer_module: str
|
producer_module: str
|
||||||
producer_run_ref: str
|
producer_run_ref: str
|
||||||
idempotency_key: str
|
idempotency_key: str
|
||||||
rows: tuple[Mapping[str, object], ...]
|
rows: tuple[Mapping[str, object], ...] | None = None
|
||||||
|
artifact: DatasourceArtifactReference | None = None
|
||||||
target_datasource_ref: str | None = None
|
target_datasource_ref: str | None = None
|
||||||
name: str | None = None
|
name: str | None = None
|
||||||
source_name: str | None = None
|
source_name: str | None = None
|
||||||
@@ -169,12 +448,13 @@ class DatasourcePublicationRequest:
|
|||||||
source_timestamp: datetime | None = None
|
source_timestamp: datetime | None = None
|
||||||
provenance: Mapping[str, object] = field(default_factory=dict)
|
provenance: Mapping[str, object] = field(default_factory=dict)
|
||||||
metadata: Mapping[str, object] = field(default_factory=dict)
|
metadata: Mapping[str, object] = field(default_factory=dict)
|
||||||
|
governance: DatasourceGovernance | None = None
|
||||||
|
|
||||||
|
|
||||||
@dataclass(frozen=True, slots=True)
|
@dataclass(frozen=True, slots=True)
|
||||||
class DatasourcePublicationResult:
|
class DatasourcePublicationResult:
|
||||||
ref: str
|
ref: str
|
||||||
status: str
|
status: DatasourcePublicationStatus
|
||||||
datasource: DatasourceDescriptor
|
datasource: DatasourceDescriptor
|
||||||
materialization: DatasourceMaterialization
|
materialization: DatasourceMaterialization
|
||||||
replayed: bool = False
|
replayed: bool = False
|
||||||
@@ -198,6 +478,9 @@ class DatasourceOrigin:
|
|||||||
updated_at: datetime | None = None
|
updated_at: datetime | None = None
|
||||||
capabilities: tuple[str, ...] = ("read",)
|
capabilities: tuple[str, ...] = ("read",)
|
||||||
metadata: Mapping[str, object] = field(default_factory=dict)
|
metadata: Mapping[str, object] = field(default_factory=dict)
|
||||||
|
source_mode: TabularSourceMode = "cached"
|
||||||
|
pushdown: TabularPushdown = field(default_factory=TabularPushdown)
|
||||||
|
health: TabularSourceHealth = field(default_factory=TabularSourceHealth)
|
||||||
|
|
||||||
|
|
||||||
@dataclass(frozen=True, slots=True)
|
@dataclass(frozen=True, slots=True)
|
||||||
@@ -207,6 +490,8 @@ class DatasourceOriginReadRequest:
|
|||||||
offset: int = 0
|
offset: int = 0
|
||||||
columns: tuple[str, ...] = ()
|
columns: tuple[str, ...] = ()
|
||||||
expected_fingerprint: str | None = None
|
expected_fingerprint: str | None = None
|
||||||
|
max_bytes: int = DEFAULT_PREVIEW_BYTES
|
||||||
|
timeout_ms: int = DEFAULT_PREVIEW_TIMEOUT_MS
|
||||||
|
|
||||||
|
|
||||||
@dataclass(frozen=True, slots=True)
|
@dataclass(frozen=True, slots=True)
|
||||||
@@ -215,6 +500,12 @@ class DatasourceOriginReadResult:
|
|||||||
rows: tuple[Mapping[str, object], ...]
|
rows: tuple[Mapping[str, object], ...]
|
||||||
total_rows: int
|
total_rows: int
|
||||||
truncated: bool
|
truncated: bool
|
||||||
|
returned_bytes: int = 0
|
||||||
|
elapsed_ms: int = 0
|
||||||
|
effective_row_limit: int = 0
|
||||||
|
effective_byte_limit: int = 0
|
||||||
|
effective_timeout_ms: int = 0
|
||||||
|
diagnostics: tuple[TabularPreviewDiagnostic, ...] = ()
|
||||||
|
|
||||||
|
|
||||||
@runtime_checkable
|
@runtime_checkable
|
||||||
@@ -226,6 +517,13 @@ class DatasourceCatalogueProvider(Protocol):
|
|||||||
*,
|
*,
|
||||||
query: str = "",
|
query: str = "",
|
||||||
limit: int = 100,
|
limit: int = 100,
|
||||||
|
authority_mode: str | None = None,
|
||||||
|
classification: str | None = None,
|
||||||
|
publication_state: str | None = None,
|
||||||
|
owner_ref: str | None = None,
|
||||||
|
responsible_organization_ref: str | None = None,
|
||||||
|
affected_ref: str | None = None,
|
||||||
|
dependency_ref: str | None = None,
|
||||||
) -> Sequence[DatasourceDescriptor]:
|
) -> Sequence[DatasourceDescriptor]:
|
||||||
...
|
...
|
||||||
|
|
||||||
@@ -298,6 +596,17 @@ class DatasourceLifecycleProvider(Protocol):
|
|||||||
source_name: str,
|
source_name: str,
|
||||||
mode: DatasourceMode,
|
mode: DatasourceMode,
|
||||||
description: str | None = None,
|
description: str | None = None,
|
||||||
|
governance: DatasourceGovernance | None = None,
|
||||||
|
) -> DatasourceDescriptor:
|
||||||
|
...
|
||||||
|
|
||||||
|
def update_datasource_governance(
|
||||||
|
self,
|
||||||
|
session: object,
|
||||||
|
principal: object,
|
||||||
|
*,
|
||||||
|
datasource_ref: str,
|
||||||
|
governance: DatasourceGovernance,
|
||||||
) -> DatasourceDescriptor:
|
) -> DatasourceDescriptor:
|
||||||
...
|
...
|
||||||
|
|
||||||
@@ -378,6 +687,17 @@ def datasource_catalogue(registry: object | None) -> DatasourceCatalogueProvider
|
|||||||
return capability if isinstance(capability, DatasourceCatalogueProvider) else None
|
return capability if isinstance(capability, DatasourceCatalogueProvider) else None
|
||||||
|
|
||||||
|
|
||||||
|
def datasource_artifact_backend_provider(
|
||||||
|
registry: object | None,
|
||||||
|
) -> DatasourceArtifactBackendProvider | None:
|
||||||
|
capability = _capability(registry, CAPABILITY_DATASOURCE_ARTIFACT_BACKENDS)
|
||||||
|
return (
|
||||||
|
capability
|
||||||
|
if isinstance(capability, DatasourceArtifactBackendProvider)
|
||||||
|
else None
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def datasource_lifecycle(registry: object | None) -> DatasourceLifecycleProvider | None:
|
def datasource_lifecycle(registry: object | None) -> DatasourceLifecycleProvider | None:
|
||||||
capability = _capability(registry, CAPABILITY_DATASOURCE_LIFECYCLE)
|
capability = _capability(registry, CAPABILITY_DATASOURCE_LIFECYCLE)
|
||||||
return capability if isinstance(capability, DatasourceLifecycleProvider) else None
|
return capability if isinstance(capability, DatasourceLifecycleProvider) else None
|
||||||
@@ -395,6 +715,13 @@ def datasource_origins(registry: object | None) -> DatasourceOriginProvider | No
|
|||||||
return capability if isinstance(capability, DatasourceOriginProvider) else None
|
return capability if isinstance(capability, DatasourceOriginProvider) else None
|
||||||
|
|
||||||
|
|
||||||
|
def datasource_visibility_policy_provider(
|
||||||
|
registry: object | None,
|
||||||
|
) -> DatasourceVisibilityPolicyProvider | None:
|
||||||
|
capability = _capability(registry, CAPABILITY_POLICY_DATASOURCE_VISIBILITY)
|
||||||
|
return capability if isinstance(capability, DatasourceVisibilityPolicyProvider) else None
|
||||||
|
|
||||||
|
|
||||||
def _capability(registry: object | None, name: str) -> object | None:
|
def _capability(registry: object | None, name: str) -> object | None:
|
||||||
if (
|
if (
|
||||||
registry is None
|
registry is None
|
||||||
@@ -406,16 +733,42 @@ def _capability(registry: object | None, name: str) -> object | None:
|
|||||||
return registry.capability(name)
|
return registry.capability(name)
|
||||||
|
|
||||||
|
|
||||||
|
def _optional_governance_text(value: object) -> str | None:
|
||||||
|
if value is None:
|
||||||
|
return None
|
||||||
|
cleaned = str(value).strip()
|
||||||
|
return cleaned or None
|
||||||
|
|
||||||
|
|
||||||
|
def _governance_texts(value: object) -> tuple[str, ...]:
|
||||||
|
if not isinstance(value, Sequence) or isinstance(value, (str, bytes)):
|
||||||
|
return ()
|
||||||
|
return tuple(str(item).strip() for item in value)
|
||||||
|
|
||||||
|
|
||||||
|
def _governance_mapping(value: object) -> Mapping[str, object]:
|
||||||
|
if not isinstance(value, Mapping):
|
||||||
|
return {}
|
||||||
|
return {str(key): item for key, item in value.items()}
|
||||||
|
|
||||||
|
|
||||||
__all__ = [
|
__all__ = [
|
||||||
"CAPABILITY_DATASOURCE_CATALOGUE",
|
"CAPABILITY_DATASOURCE_CATALOGUE",
|
||||||
|
"CAPABILITY_DATASOURCE_ARTIFACT_BACKENDS",
|
||||||
"CAPABILITY_DATASOURCE_LIFECYCLE",
|
"CAPABILITY_DATASOURCE_LIFECYCLE",
|
||||||
"CAPABILITY_DATASOURCE_ORIGINS",
|
"CAPABILITY_DATASOURCE_ORIGINS",
|
||||||
|
"CAPABILITY_DATASOURCE_PUBLICATION",
|
||||||
|
"CAPABILITY_POLICY_DATASOURCE_VISIBILITY",
|
||||||
"DatasourceAccessError",
|
"DatasourceAccessError",
|
||||||
|
"DatasourceArtifactReference",
|
||||||
|
"DatasourceArtifactBackend",
|
||||||
|
"DatasourceArtifactBackendProvider",
|
||||||
"DatasourceCatalogueProvider",
|
"DatasourceCatalogueProvider",
|
||||||
"DatasourceConsistency",
|
"DatasourceConsistency",
|
||||||
"DatasourceDescriptor",
|
"DatasourceDescriptor",
|
||||||
"DatasourceError",
|
"DatasourceError",
|
||||||
"DatasourceField",
|
"DatasourceField",
|
||||||
|
"DatasourceGovernance",
|
||||||
"DatasourceKind",
|
"DatasourceKind",
|
||||||
"DatasourceLifecycleProvider",
|
"DatasourceLifecycleProvider",
|
||||||
"DatasourceMaterialization",
|
"DatasourceMaterialization",
|
||||||
@@ -425,6 +778,10 @@ __all__ = [
|
|||||||
"DatasourceOriginProvider",
|
"DatasourceOriginProvider",
|
||||||
"DatasourceOriginReadRequest",
|
"DatasourceOriginReadRequest",
|
||||||
"DatasourceOriginReadResult",
|
"DatasourceOriginReadResult",
|
||||||
|
"DatasourcePublicationProvider",
|
||||||
|
"DatasourcePublicationRequest",
|
||||||
|
"DatasourcePublicationResult",
|
||||||
|
"DatasourcePublicationStatus",
|
||||||
"DatasourceReadRequest",
|
"DatasourceReadRequest",
|
||||||
"DatasourceReadResult",
|
"DatasourceReadResult",
|
||||||
"DatasourceShape",
|
"DatasourceShape",
|
||||||
@@ -432,7 +789,14 @@ __all__ = [
|
|||||||
"DatasourceStageInput",
|
"DatasourceStageInput",
|
||||||
"DatasourceUnavailableError",
|
"DatasourceUnavailableError",
|
||||||
"DatasourceValidationError",
|
"DatasourceValidationError",
|
||||||
|
"DatasourceVisibilityAction",
|
||||||
|
"DatasourceVisibilityPolicyDecision",
|
||||||
|
"DatasourceVisibilityPolicyProvider",
|
||||||
|
"DatasourceVisibilityPolicyRequest",
|
||||||
"datasource_catalogue",
|
"datasource_catalogue",
|
||||||
|
"datasource_artifact_backend_provider",
|
||||||
"datasource_lifecycle",
|
"datasource_lifecycle",
|
||||||
"datasource_origins",
|
"datasource_origins",
|
||||||
|
"datasource_publication",
|
||||||
|
"datasource_visibility_policy_provider",
|
||||||
]
|
]
|
||||||
|
|||||||
@@ -0,0 +1,402 @@
|
|||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
from collections.abc import Mapping, Sequence
|
||||||
|
from dataclasses import dataclass, field
|
||||||
|
from datetime import datetime
|
||||||
|
from typing import Literal, Protocol, runtime_checkable
|
||||||
|
|
||||||
|
|
||||||
|
CAPABILITY_DISTRIBUTION_LIST_SOURCE = "dist_lists.source"
|
||||||
|
CAPABILITY_DISTRIBUTION_LIST_EXPAND = "dist_lists.expand"
|
||||||
|
CAPABILITY_DISTRIBUTION_LIST_WRITER = "dist_lists.writer"
|
||||||
|
CAPABILITY_RECIPIENT_CHANNEL_FACTS = "addresses.channel_facts"
|
||||||
|
CAPABILITY_POLICY_DISTRIBUTION_CHANNELS = "policy.distribution_channels"
|
||||||
|
|
||||||
|
DistributionDefinitionKind = Literal["static", "parameterized", "dynamic", "template"]
|
||||||
|
DistributionEntryMode = Literal["include", "exclude", "override"]
|
||||||
|
DistributionEntryKind = Literal[
|
||||||
|
"address_contact",
|
||||||
|
"address_list",
|
||||||
|
"address_email",
|
||||||
|
"raw_email",
|
||||||
|
"raw_postal_address",
|
||||||
|
"internal_mail",
|
||||||
|
"portal",
|
||||||
|
"idm_identity",
|
||||||
|
"idm_group",
|
||||||
|
"organization_unit",
|
||||||
|
"function",
|
||||||
|
"effective_function_incumbent",
|
||||||
|
"dataflow_result",
|
||||||
|
"distribution_list",
|
||||||
|
]
|
||||||
|
DistributionChannel = Literal["email", "postal", "internal_mail", "portal"]
|
||||||
|
DistributionOutcome = Literal[
|
||||||
|
"usable",
|
||||||
|
"unresolved",
|
||||||
|
"invalid",
|
||||||
|
"suppressed",
|
||||||
|
"ambiguous",
|
||||||
|
"duplicate",
|
||||||
|
"policy_blocked",
|
||||||
|
"provider_unavailable",
|
||||||
|
"stale",
|
||||||
|
]
|
||||||
|
DistributionExplanationSeverity = Literal["info", "warning", "error"]
|
||||||
|
|
||||||
|
|
||||||
|
class DistributionListError(ValueError):
|
||||||
|
"""Stable base error for provider-neutral distribution-list operations."""
|
||||||
|
|
||||||
|
|
||||||
|
class DistributionListNotFoundError(DistributionListError):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
class DistributionListConflictError(DistributionListError):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
class DistributionListUnavailableError(DistributionListError):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass(frozen=True, slots=True)
|
||||||
|
class DistributionSourceReference:
|
||||||
|
provider: str
|
||||||
|
resource_type: str
|
||||||
|
resource_id: str
|
||||||
|
revision: str | None = None
|
||||||
|
fingerprint: str | None = None
|
||||||
|
label: str | None = None
|
||||||
|
metadata: Mapping[str, object] = field(default_factory=dict)
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass(frozen=True, slots=True)
|
||||||
|
class DistributionExplanation:
|
||||||
|
code: str
|
||||||
|
message: str
|
||||||
|
severity: DistributionExplanationSeverity = "warning"
|
||||||
|
provider: str | None = None
|
||||||
|
source: DistributionSourceReference | None = None
|
||||||
|
provenance: Mapping[str, object] = field(default_factory=dict)
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass(frozen=True, slots=True)
|
||||||
|
class DistributionParameterDefinition:
|
||||||
|
key: str
|
||||||
|
value_type: Literal[
|
||||||
|
"string",
|
||||||
|
"integer",
|
||||||
|
"number",
|
||||||
|
"boolean",
|
||||||
|
"date",
|
||||||
|
"datetime",
|
||||||
|
"string_list",
|
||||||
|
]
|
||||||
|
label: str | None = None
|
||||||
|
required: bool = False
|
||||||
|
default: object | None = None
|
||||||
|
allowed_values: tuple[object, ...] = ()
|
||||||
|
minimum: float | None = None
|
||||||
|
maximum: float | None = None
|
||||||
|
pattern: str | None = None
|
||||||
|
description: str | None = None
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass(frozen=True, slots=True)
|
||||||
|
class DistributionListEntryRef:
|
||||||
|
id: str
|
||||||
|
kind: DistributionEntryKind
|
||||||
|
mode: DistributionEntryMode
|
||||||
|
source: DistributionSourceReference
|
||||||
|
label: str | None = None
|
||||||
|
purpose: str | None = None
|
||||||
|
requested_channels: tuple[DistributionChannel, ...] = ()
|
||||||
|
effective_from: datetime | None = None
|
||||||
|
effective_until: datetime | None = None
|
||||||
|
order: int = 0
|
||||||
|
configuration: Mapping[str, object] = field(default_factory=dict)
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass(frozen=True, slots=True)
|
||||||
|
class DistributionListSourceRef:
|
||||||
|
id: str
|
||||||
|
tenant_id: str
|
||||||
|
name: str
|
||||||
|
revision_id: str
|
||||||
|
revision: int
|
||||||
|
definition_hash: str
|
||||||
|
definition_kind: DistributionDefinitionKind = "static"
|
||||||
|
description: str | None = None
|
||||||
|
status: str = "active"
|
||||||
|
entry_count: int = 0
|
||||||
|
read_only: bool = False
|
||||||
|
stale: bool = False
|
||||||
|
parameters: tuple[DistributionParameterDefinition, ...] = ()
|
||||||
|
updated_at: datetime | None = None
|
||||||
|
provenance: Mapping[str, object] = field(default_factory=dict)
|
||||||
|
metadata: Mapping[str, object] = field(default_factory=dict)
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass(frozen=True, slots=True)
|
||||||
|
class DistributionExpansionLimits:
|
||||||
|
max_entries: int = 500
|
||||||
|
max_results: int = 5_000
|
||||||
|
max_depth: int = 8
|
||||||
|
max_provider_results: int = 2_000
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass(frozen=True, slots=True)
|
||||||
|
class DistributionExpansionRequest:
|
||||||
|
list_id: str
|
||||||
|
revision: int | None = None
|
||||||
|
effective_at: datetime | None = None
|
||||||
|
purpose: str | None = None
|
||||||
|
requested_channels: tuple[DistributionChannel, ...] = ()
|
||||||
|
parameters: Mapping[str, object] = field(default_factory=dict)
|
||||||
|
preview: bool = False
|
||||||
|
freeze: bool = False
|
||||||
|
idempotency_key: str | None = None
|
||||||
|
limits: DistributionExpansionLimits = field(
|
||||||
|
default_factory=DistributionExpansionLimits
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass(frozen=True, slots=True)
|
||||||
|
class DistributionChannelCandidate:
|
||||||
|
channel: DistributionChannel
|
||||||
|
target: str
|
||||||
|
target_key: str
|
||||||
|
status: DistributionOutcome = "usable"
|
||||||
|
contact_point_id: str | None = None
|
||||||
|
locale: str | None = None
|
||||||
|
preferred: bool = False
|
||||||
|
reason_code: str | None = None
|
||||||
|
explanation: str | None = None
|
||||||
|
source: DistributionSourceReference | None = None
|
||||||
|
decision_provenance: Mapping[str, object] = field(default_factory=dict)
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass(frozen=True, slots=True)
|
||||||
|
class DistributionRecipientRef:
|
||||||
|
recipient_key: str
|
||||||
|
display_name: str
|
||||||
|
status: DistributionOutcome
|
||||||
|
channels: tuple[DistributionChannelCandidate, ...] = ()
|
||||||
|
identity_id: str | None = None
|
||||||
|
account_id: str | None = None
|
||||||
|
contact_id: str | None = None
|
||||||
|
organization_unit_id: str | None = None
|
||||||
|
function_id: str | None = None
|
||||||
|
source_entry_ids: tuple[str, ...] = ()
|
||||||
|
explanations: tuple[DistributionExplanation, ...] = ()
|
||||||
|
attributes: Mapping[str, object] = field(default_factory=dict)
|
||||||
|
provenance: Mapping[str, object] = field(default_factory=dict)
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass(frozen=True, slots=True)
|
||||||
|
class DistributionProviderEvidence:
|
||||||
|
provider: str
|
||||||
|
source: DistributionSourceReference
|
||||||
|
actual_revision: str | None = None
|
||||||
|
actual_fingerprint: str | None = None
|
||||||
|
stale: bool = False
|
||||||
|
generated_at: datetime | None = None
|
||||||
|
details: Mapping[str, object] = field(default_factory=dict)
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass(frozen=True, slots=True)
|
||||||
|
class DistributionExpansionResult:
|
||||||
|
source: DistributionListSourceRef
|
||||||
|
request: DistributionExpansionRequest
|
||||||
|
recipients: tuple[DistributionRecipientRef, ...]
|
||||||
|
excluded: tuple[DistributionRecipientRef, ...] = ()
|
||||||
|
diagnostics: tuple[DistributionExplanation, ...] = ()
|
||||||
|
provider_evidence: tuple[DistributionProviderEvidence, ...] = ()
|
||||||
|
expansion_hash: str = ""
|
||||||
|
generated_at: datetime | None = None
|
||||||
|
snapshot_id: str | None = None
|
||||||
|
stale: bool = False
|
||||||
|
truncated: bool = False
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass(frozen=True, slots=True)
|
||||||
|
class DistributionSnapshotRef:
|
||||||
|
id: str
|
||||||
|
tenant_id: str
|
||||||
|
list_id: str
|
||||||
|
revision_id: str
|
||||||
|
revision: int
|
||||||
|
expansion_hash: str
|
||||||
|
generated_at: datetime
|
||||||
|
effective_at: datetime
|
||||||
|
recipient_count: int
|
||||||
|
excluded_count: int
|
||||||
|
stale: bool
|
||||||
|
truncated: bool
|
||||||
|
request: Mapping[str, object] = field(default_factory=dict)
|
||||||
|
recipients: tuple[DistributionRecipientRef, ...] = ()
|
||||||
|
excluded: tuple[DistributionRecipientRef, ...] = ()
|
||||||
|
diagnostics: tuple[DistributionExplanation, ...] = ()
|
||||||
|
provider_evidence: tuple[DistributionProviderEvidence, ...] = ()
|
||||||
|
provenance: Mapping[str, object] = field(default_factory=dict)
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass(frozen=True, slots=True)
|
||||||
|
class DistributionWriteDecision:
|
||||||
|
list_id: str | None
|
||||||
|
operation: str
|
||||||
|
allowed: bool
|
||||||
|
reason_code: str
|
||||||
|
explanation: str
|
||||||
|
read_only: bool = False
|
||||||
|
required_scopes: tuple[str, ...] = ()
|
||||||
|
provenance: Mapping[str, object] = field(default_factory=dict)
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass(frozen=True, slots=True)
|
||||||
|
class RecipientChannelFactsRequest:
|
||||||
|
tenant_id: str
|
||||||
|
source: DistributionSourceReference
|
||||||
|
recipient_key: str
|
||||||
|
effective_at: datetime
|
||||||
|
purpose: str | None = None
|
||||||
|
requested_channels: tuple[DistributionChannel, ...] = ()
|
||||||
|
context: Mapping[str, object] = field(default_factory=dict)
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass(frozen=True, slots=True)
|
||||||
|
class RecipientChannelFacts:
|
||||||
|
candidates: tuple[DistributionChannelCandidate, ...]
|
||||||
|
explanations: tuple[DistributionExplanation, ...] = ()
|
||||||
|
source_revision: str | None = None
|
||||||
|
source_fingerprint: str | None = None
|
||||||
|
provenance: Mapping[str, object] = field(default_factory=dict)
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass(frozen=True, slots=True)
|
||||||
|
class DistributionChannelPolicyRequest:
|
||||||
|
tenant_id: str
|
||||||
|
list_id: str
|
||||||
|
purpose: str | None
|
||||||
|
effective_at: datetime
|
||||||
|
recipient: DistributionRecipientRef
|
||||||
|
candidate: DistributionChannelCandidate
|
||||||
|
context: Mapping[str, object] = field(default_factory=dict)
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass(frozen=True, slots=True)
|
||||||
|
class DistributionChannelPolicyDecision:
|
||||||
|
allowed: bool
|
||||||
|
reason_code: str
|
||||||
|
explanation: str
|
||||||
|
source_path: tuple[Mapping[str, object], ...] = ()
|
||||||
|
requirements: tuple[str, ...] = ()
|
||||||
|
details: Mapping[str, object] = field(default_factory=dict)
|
||||||
|
|
||||||
|
|
||||||
|
@runtime_checkable
|
||||||
|
class DistributionListSourceProvider(Protocol):
|
||||||
|
def list_sources(
|
||||||
|
self,
|
||||||
|
session: object,
|
||||||
|
principal: object,
|
||||||
|
*,
|
||||||
|
query: str = "",
|
||||||
|
limit: int = 100,
|
||||||
|
) -> Sequence[DistributionListSourceRef]: ...
|
||||||
|
|
||||||
|
def get_source(
|
||||||
|
self,
|
||||||
|
session: object,
|
||||||
|
principal: object,
|
||||||
|
*,
|
||||||
|
list_id: str,
|
||||||
|
revision: int | None = None,
|
||||||
|
) -> DistributionListSourceRef | None: ...
|
||||||
|
|
||||||
|
|
||||||
|
@runtime_checkable
|
||||||
|
class DistributionListExpansionProvider(Protocol):
|
||||||
|
def expand(
|
||||||
|
self,
|
||||||
|
session: object,
|
||||||
|
principal: object,
|
||||||
|
*,
|
||||||
|
request: DistributionExpansionRequest,
|
||||||
|
) -> DistributionExpansionResult: ...
|
||||||
|
|
||||||
|
def get_snapshot(
|
||||||
|
self,
|
||||||
|
session: object,
|
||||||
|
principal: object,
|
||||||
|
*,
|
||||||
|
snapshot_id: str,
|
||||||
|
) -> DistributionSnapshotRef | None: ...
|
||||||
|
|
||||||
|
|
||||||
|
@runtime_checkable
|
||||||
|
class DistributionListWriter(Protocol):
|
||||||
|
def explain_write(
|
||||||
|
self,
|
||||||
|
session: object,
|
||||||
|
principal: object,
|
||||||
|
*,
|
||||||
|
list_id: str | None,
|
||||||
|
operation: str,
|
||||||
|
) -> DistributionWriteDecision: ...
|
||||||
|
|
||||||
|
|
||||||
|
@runtime_checkable
|
||||||
|
class RecipientChannelFactsProvider(Protocol):
|
||||||
|
def resolve_channel_facts(
|
||||||
|
self,
|
||||||
|
session: object,
|
||||||
|
principal: object,
|
||||||
|
*,
|
||||||
|
request: RecipientChannelFactsRequest,
|
||||||
|
) -> RecipientChannelFacts: ...
|
||||||
|
|
||||||
|
|
||||||
|
@runtime_checkable
|
||||||
|
class DistributionChannelPolicyProvider(Protocol):
|
||||||
|
def resolve_distribution_channel(
|
||||||
|
self,
|
||||||
|
session: object,
|
||||||
|
principal: object,
|
||||||
|
*,
|
||||||
|
request: DistributionChannelPolicyRequest,
|
||||||
|
) -> DistributionChannelPolicyDecision: ...
|
||||||
|
|
||||||
|
|
||||||
|
def distribution_list_source_provider(
|
||||||
|
registry: object | None,
|
||||||
|
) -> DistributionListSourceProvider | None:
|
||||||
|
capability = _capability(registry, CAPABILITY_DISTRIBUTION_LIST_SOURCE)
|
||||||
|
return capability if isinstance(capability, DistributionListSourceProvider) else None
|
||||||
|
|
||||||
|
|
||||||
|
def distribution_list_expansion_provider(
|
||||||
|
registry: object | None,
|
||||||
|
) -> DistributionListExpansionProvider | None:
|
||||||
|
capability = _capability(registry, CAPABILITY_DISTRIBUTION_LIST_EXPAND)
|
||||||
|
return (
|
||||||
|
capability
|
||||||
|
if isinstance(capability, DistributionListExpansionProvider)
|
||||||
|
else None
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def _capability(registry: object | None, name: str) -> object | None:
|
||||||
|
if (
|
||||||
|
registry is None
|
||||||
|
or not hasattr(registry, "has_capability")
|
||||||
|
or not hasattr(registry, "capability")
|
||||||
|
or not registry.has_capability(name)
|
||||||
|
):
|
||||||
|
return None
|
||||||
|
return registry.capability(name)
|
||||||
|
|
||||||
|
|
||||||
|
__all__ = [name for name in globals() if name.startswith("CAPABILITY_") or name.startswith("Distribution") or name.startswith("Recipient") or name.startswith("distribution_")]
|
||||||
@@ -0,0 +1,197 @@
|
|||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
from collections.abc import Mapping, Sequence
|
||||||
|
from dataclasses import dataclass, field
|
||||||
|
from datetime import datetime
|
||||||
|
from typing import Literal, Protocol, runtime_checkable
|
||||||
|
|
||||||
|
|
||||||
|
DSAR_CAPABILITY_PREFIX = "privacy.dsar."
|
||||||
|
|
||||||
|
DsarRequestKind = Literal["access", "erasure", "access_and_erasure"]
|
||||||
|
DsarActionKind = Literal[
|
||||||
|
"delete",
|
||||||
|
"anonymize",
|
||||||
|
"revoke",
|
||||||
|
"detach",
|
||||||
|
"retain",
|
||||||
|
"manual_review",
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass(frozen=True, slots=True)
|
||||||
|
class DsarSubjectRef:
|
||||||
|
account_id: str | None = None
|
||||||
|
identity_id: str | None = None
|
||||||
|
membership_id: str | None = None
|
||||||
|
email: str | None = None
|
||||||
|
external_references: Mapping[str, str] = field(default_factory=dict)
|
||||||
|
|
||||||
|
def has_selector(self) -> bool:
|
||||||
|
return bool(
|
||||||
|
self.account_id
|
||||||
|
or self.identity_id
|
||||||
|
or self.membership_id
|
||||||
|
or self.email
|
||||||
|
or self.external_references
|
||||||
|
)
|
||||||
|
|
||||||
|
def to_dict(self) -> dict[str, object]:
|
||||||
|
return {
|
||||||
|
"account_id": self.account_id,
|
||||||
|
"identity_id": self.identity_id,
|
||||||
|
"membership_id": self.membership_id,
|
||||||
|
"email": self.email,
|
||||||
|
"external_references": dict(self.external_references),
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass(frozen=True, slots=True)
|
||||||
|
class DsarRecordRef:
|
||||||
|
provider_id: str
|
||||||
|
module_id: str
|
||||||
|
resource_type: str
|
||||||
|
resource_id: str
|
||||||
|
category: str
|
||||||
|
title: str
|
||||||
|
data: Mapping[str, object] = field(default_factory=dict)
|
||||||
|
observed_at: datetime | None = None
|
||||||
|
immutable_evidence: bool = False
|
||||||
|
retention_reason: str | None = None
|
||||||
|
source_path: str | None = None
|
||||||
|
|
||||||
|
def to_dict(self) -> dict[str, object]:
|
||||||
|
return {
|
||||||
|
"provider_id": self.provider_id,
|
||||||
|
"module_id": self.module_id,
|
||||||
|
"resource_type": self.resource_type,
|
||||||
|
"resource_id": self.resource_id,
|
||||||
|
"category": self.category,
|
||||||
|
"title": self.title,
|
||||||
|
"data": dict(self.data),
|
||||||
|
"observed_at": self.observed_at.isoformat() if self.observed_at else None,
|
||||||
|
"immutable_evidence": self.immutable_evidence,
|
||||||
|
"retention_reason": self.retention_reason,
|
||||||
|
"source_path": self.source_path,
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass(frozen=True, slots=True)
|
||||||
|
class DsarErasureActionRef:
|
||||||
|
action_id: str
|
||||||
|
provider_id: str
|
||||||
|
module_id: str
|
||||||
|
kind: DsarActionKind
|
||||||
|
resource_type: str
|
||||||
|
resource_id: str
|
||||||
|
title: str
|
||||||
|
rationale: str
|
||||||
|
executable: bool
|
||||||
|
irreversible: bool = False
|
||||||
|
metadata: Mapping[str, object] = field(default_factory=dict)
|
||||||
|
|
||||||
|
def to_dict(self) -> dict[str, object]:
|
||||||
|
return {
|
||||||
|
"action_id": self.action_id,
|
||||||
|
"provider_id": self.provider_id,
|
||||||
|
"module_id": self.module_id,
|
||||||
|
"kind": self.kind,
|
||||||
|
"resource_type": self.resource_type,
|
||||||
|
"resource_id": self.resource_id,
|
||||||
|
"title": self.title,
|
||||||
|
"rationale": self.rationale,
|
||||||
|
"executable": self.executable,
|
||||||
|
"irreversible": self.irreversible,
|
||||||
|
"metadata": dict(self.metadata),
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass(frozen=True, slots=True)
|
||||||
|
class DsarExecutionResultRef:
|
||||||
|
action_id: str
|
||||||
|
status: Literal["executed", "unchanged", "failed", "blocked"]
|
||||||
|
summary: str
|
||||||
|
evidence: Mapping[str, object] = field(default_factory=dict)
|
||||||
|
|
||||||
|
def to_dict(self) -> dict[str, object]:
|
||||||
|
return {
|
||||||
|
"action_id": self.action_id,
|
||||||
|
"status": self.status,
|
||||||
|
"summary": self.summary,
|
||||||
|
"evidence": dict(self.evidence),
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@runtime_checkable
|
||||||
|
class DsarProvider(Protocol):
|
||||||
|
provider_id: str
|
||||||
|
module_id: str
|
||||||
|
|
||||||
|
def search_subject(
|
||||||
|
self,
|
||||||
|
session: object,
|
||||||
|
*,
|
||||||
|
tenant_id: str,
|
||||||
|
subject: DsarSubjectRef,
|
||||||
|
) -> Sequence[DsarRecordRef]: ...
|
||||||
|
|
||||||
|
def plan_erasure(
|
||||||
|
self,
|
||||||
|
session: object,
|
||||||
|
*,
|
||||||
|
tenant_id: str,
|
||||||
|
subject: DsarSubjectRef,
|
||||||
|
records: Sequence[DsarRecordRef],
|
||||||
|
) -> Sequence[DsarErasureActionRef]: ...
|
||||||
|
|
||||||
|
def execute_erasure(
|
||||||
|
self,
|
||||||
|
session: object,
|
||||||
|
*,
|
||||||
|
tenant_id: str,
|
||||||
|
subject: DsarSubjectRef,
|
||||||
|
actions: Sequence[DsarErasureActionRef],
|
||||||
|
request_id: str,
|
||||||
|
) -> Sequence[DsarExecutionResultRef]: ...
|
||||||
|
|
||||||
|
|
||||||
|
def dsar_capability_name(module_id: str) -> str:
|
||||||
|
normalized = module_id.strip().casefold()
|
||||||
|
if not normalized or not normalized.replace("_", "").isalnum():
|
||||||
|
raise ValueError("DSAR module id must be an identifier.")
|
||||||
|
return f"{DSAR_CAPABILITY_PREFIX}{normalized}"
|
||||||
|
|
||||||
|
|
||||||
|
def dsar_provider_names(registry: object | None) -> tuple[str, ...]:
|
||||||
|
if registry is None or not hasattr(registry, "capability_names"):
|
||||||
|
return ()
|
||||||
|
return tuple(
|
||||||
|
name
|
||||||
|
for name in registry.capability_names()
|
||||||
|
if name.startswith(DSAR_CAPABILITY_PREFIX)
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def dsar_provider(
|
||||||
|
registry: object,
|
||||||
|
capability_name: str,
|
||||||
|
) -> DsarProvider:
|
||||||
|
provider = registry.require_capability(capability_name)
|
||||||
|
if not isinstance(provider, DsarProvider):
|
||||||
|
raise TypeError(f"{capability_name} does not implement DsarProvider")
|
||||||
|
return provider
|
||||||
|
|
||||||
|
|
||||||
|
__all__ = [
|
||||||
|
"DSAR_CAPABILITY_PREFIX",
|
||||||
|
"DsarActionKind",
|
||||||
|
"DsarErasureActionRef",
|
||||||
|
"DsarExecutionResultRef",
|
||||||
|
"DsarProvider",
|
||||||
|
"DsarRecordRef",
|
||||||
|
"DsarRequestKind",
|
||||||
|
"DsarSubjectRef",
|
||||||
|
"dsar_capability_name",
|
||||||
|
"dsar_provider",
|
||||||
|
"dsar_provider_names",
|
||||||
|
]
|
||||||
File diff suppressed because it is too large
Load Diff
@@ -13,6 +13,8 @@ import uuid
|
|||||||
from sqlalchemy import event as sqlalchemy_event
|
from sqlalchemy import event as sqlalchemy_event
|
||||||
from sqlalchemy.orm import Session
|
from sqlalchemy.orm import Session
|
||||||
|
|
||||||
|
from govoplan_core.core.institutional import GovernedContextEnvelope
|
||||||
|
|
||||||
|
|
||||||
_TRACE_ID_RE = re.compile(r"^[A-Za-z0-9_.:-]{1,128}$")
|
_TRACE_ID_RE = re.compile(r"^[A-Za-z0-9_.:-]{1,128}$")
|
||||||
_CONSUMER_ID_RE = re.compile(r"^[a-z][a-z0-9_.:-]{0,127}$")
|
_CONSUMER_ID_RE = re.compile(r"^[a-z][a-z0-9_.:-]{0,127}$")
|
||||||
@@ -87,6 +89,7 @@ class PlatformEvent:
|
|||||||
subject: EventObjectRef | None = None
|
subject: EventObjectRef | None = None
|
||||||
resource: EventObjectRef | None = None
|
resource: EventObjectRef | None = None
|
||||||
classification: EventClassification = "internal"
|
classification: EventClassification = "internal"
|
||||||
|
institutional_context: GovernedContextEnvelope | None = None
|
||||||
|
|
||||||
def to_dict(self) -> dict[str, Any]:
|
def to_dict(self) -> dict[str, Any]:
|
||||||
return {
|
return {
|
||||||
@@ -102,6 +105,11 @@ class PlatformEvent:
|
|||||||
"subject": self.subject.to_dict() if self.subject else None,
|
"subject": self.subject.to_dict() if self.subject else None,
|
||||||
"resource": self.resource.to_dict() if self.resource else None,
|
"resource": self.resource.to_dict() if self.resource else None,
|
||||||
"classification": self.classification,
|
"classification": self.classification,
|
||||||
|
"institutional_context": (
|
||||||
|
self.institutional_context.to_dict()
|
||||||
|
if self.institutional_context is not None
|
||||||
|
else None
|
||||||
|
),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -174,6 +182,8 @@ class PlatformEventOutbox(Protocol):
|
|||||||
self,
|
self,
|
||||||
session: object,
|
session: object,
|
||||||
*,
|
*,
|
||||||
|
tenant_id: str | None = None,
|
||||||
|
tenantless_only: bool = False,
|
||||||
consumers: Sequence[DurableEventConsumer] = (),
|
consumers: Sequence[DurableEventConsumer] = (),
|
||||||
observer: EventHandler | None = None,
|
observer: EventHandler | None = None,
|
||||||
limit: int = 100,
|
limit: int = 100,
|
||||||
@@ -195,6 +205,8 @@ class PlatformEventOutbox(Protocol):
|
|||||||
self,
|
self,
|
||||||
session: object,
|
session: object,
|
||||||
*,
|
*,
|
||||||
|
tenant_id: str | None = None,
|
||||||
|
tenantless_only: bool = False,
|
||||||
before: datetime,
|
before: datetime,
|
||||||
limit: int = 500,
|
limit: int = 500,
|
||||||
) -> Mapping[str, int]:
|
) -> Mapping[str, int]:
|
||||||
@@ -254,6 +266,7 @@ def ensure_event_trace(event: PlatformEvent) -> PlatformEvent:
|
|||||||
subject=event.subject,
|
subject=event.subject,
|
||||||
resource=event.resource,
|
resource=event.resource,
|
||||||
classification=event.classification,
|
classification=event.classification,
|
||||||
|
institutional_context=event.institutional_context,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -17,6 +17,14 @@ IntegrationMaturity = Literal[
|
|||||||
"migrate",
|
"migrate",
|
||||||
"replace",
|
"replace",
|
||||||
]
|
]
|
||||||
|
SourceAuthorityMode = Literal[
|
||||||
|
"native_authoritative",
|
||||||
|
"external_authoritative",
|
||||||
|
"external_mirror",
|
||||||
|
"governed_sync",
|
||||||
|
"governance_overlay",
|
||||||
|
"linked_reference",
|
||||||
|
]
|
||||||
|
|
||||||
INTEGRATION_MATURITY_ORDER: tuple[IntegrationMaturity, ...] = (
|
INTEGRATION_MATURITY_ORDER: tuple[IntegrationMaturity, ...] = (
|
||||||
"discover",
|
"discover",
|
||||||
@@ -28,6 +36,14 @@ INTEGRATION_MATURITY_ORDER: tuple[IntegrationMaturity, ...] = (
|
|||||||
"migrate",
|
"migrate",
|
||||||
"replace",
|
"replace",
|
||||||
)
|
)
|
||||||
|
SOURCE_AUTHORITY_MODES: tuple[SourceAuthorityMode, ...] = (
|
||||||
|
"native_authoritative",
|
||||||
|
"external_authoritative",
|
||||||
|
"external_mirror",
|
||||||
|
"governed_sync",
|
||||||
|
"governance_overlay",
|
||||||
|
"linked_reference",
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class ExternalReferenceValidationError(ValueError):
|
class ExternalReferenceValidationError(ValueError):
|
||||||
@@ -42,6 +58,7 @@ class ExternalObjectReference:
|
|||||||
object_type: str
|
object_type: str
|
||||||
object_id: str
|
object_id: str
|
||||||
maturity: IntegrationMaturity = "link"
|
maturity: IntegrationMaturity = "link"
|
||||||
|
authority_mode: SourceAuthorityMode = "linked_reference"
|
||||||
connector_id: str | None = None
|
connector_id: str | None = None
|
||||||
canonical_url: str | None = None
|
canonical_url: str | None = None
|
||||||
version: str | None = None
|
version: str | None = None
|
||||||
@@ -65,6 +82,24 @@ class ExternalObjectReference:
|
|||||||
raise ExternalReferenceValidationError(
|
raise ExternalReferenceValidationError(
|
||||||
f"Unsupported integration maturity: {self.maturity!r}."
|
f"Unsupported integration maturity: {self.maturity!r}."
|
||||||
)
|
)
|
||||||
|
if self.authority_mode not in SOURCE_AUTHORITY_MODES:
|
||||||
|
raise ExternalReferenceValidationError(
|
||||||
|
f"Unsupported source-authority mode: {self.authority_mode!r}."
|
||||||
|
)
|
||||||
|
if (
|
||||||
|
self.authority_mode == "external_mirror"
|
||||||
|
and not self.supports("read")
|
||||||
|
):
|
||||||
|
raise ExternalReferenceValidationError(
|
||||||
|
"External-mirror references require read maturity or higher."
|
||||||
|
)
|
||||||
|
if (
|
||||||
|
self.authority_mode == "governed_sync"
|
||||||
|
and not self.supports("synchronize")
|
||||||
|
):
|
||||||
|
raise ExternalReferenceValidationError(
|
||||||
|
"Governed-sync references require synchronize maturity or higher."
|
||||||
|
)
|
||||||
if self.connector_id is not None:
|
if self.connector_id is not None:
|
||||||
connector_id = self.connector_id.strip()
|
connector_id = self.connector_id.strip()
|
||||||
if not connector_id:
|
if not connector_id:
|
||||||
@@ -94,6 +129,7 @@ class ExternalObjectReference:
|
|||||||
"object_type": self.object_type,
|
"object_type": self.object_type,
|
||||||
"object_id": self.object_id,
|
"object_id": self.object_id,
|
||||||
"maturity": self.maturity,
|
"maturity": self.maturity,
|
||||||
|
"authority_mode": self.authority_mode,
|
||||||
"connector_id": self.connector_id,
|
"connector_id": self.connector_id,
|
||||||
"canonical_url": self.canonical_url,
|
"canonical_url": self.canonical_url,
|
||||||
"version": self.version,
|
"version": self.version,
|
||||||
@@ -133,5 +169,7 @@ __all__ = [
|
|||||||
"ExternalReferenceValidationError",
|
"ExternalReferenceValidationError",
|
||||||
"INTEGRATION_MATURITY_ORDER",
|
"INTEGRATION_MATURITY_ORDER",
|
||||||
"IntegrationMaturity",
|
"IntegrationMaturity",
|
||||||
|
"SOURCE_AUTHORITY_MODES",
|
||||||
|
"SourceAuthorityMode",
|
||||||
"integration_maturity_rank",
|
"integration_maturity_rank",
|
||||||
]
|
]
|
||||||
|
|||||||
@@ -0,0 +1,122 @@
|
|||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
from collections.abc import Mapping
|
||||||
|
from dataclasses import dataclass, field
|
||||||
|
from datetime import datetime
|
||||||
|
from typing import Literal, Protocol, runtime_checkable
|
||||||
|
|
||||||
|
|
||||||
|
CAPABILITY_CONNECTORS_FEEDS = "connectors.feeds"
|
||||||
|
FeedFormat = Literal["rss", "atom"]
|
||||||
|
FeedVisibility = Literal["public", "tenant", "private"]
|
||||||
|
|
||||||
|
|
||||||
|
class FeedCapabilityError(ValueError):
|
||||||
|
"""Stable error raised by feed transport implementations."""
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass(frozen=True, slots=True)
|
||||||
|
class FeedEntry:
|
||||||
|
id: str
|
||||||
|
title: str
|
||||||
|
url: str | None = None
|
||||||
|
summary: str | None = None
|
||||||
|
content: str | None = None
|
||||||
|
author: str | None = None
|
||||||
|
published_at: datetime | None = None
|
||||||
|
updated_at: datetime | None = None
|
||||||
|
categories: tuple[str, ...] = ()
|
||||||
|
enclosures: tuple[Mapping[str, object], ...] = ()
|
||||||
|
visibility: FeedVisibility = "public"
|
||||||
|
metadata: Mapping[str, object] = field(default_factory=dict)
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass(frozen=True, slots=True)
|
||||||
|
class FeedDocument:
|
||||||
|
format: FeedFormat
|
||||||
|
title: str
|
||||||
|
source_url: str
|
||||||
|
entries: tuple[FeedEntry, ...]
|
||||||
|
description: str | None = None
|
||||||
|
home_url: str | None = None
|
||||||
|
language: str | None = None
|
||||||
|
updated_at: datetime | None = None
|
||||||
|
acquired_at: datetime | None = None
|
||||||
|
fresh_until: datetime | None = None
|
||||||
|
etag: str | None = None
|
||||||
|
last_modified: str | None = None
|
||||||
|
content_type: str | None = None
|
||||||
|
sha256: str = ""
|
||||||
|
metadata: Mapping[str, object] = field(default_factory=dict)
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass(frozen=True, slots=True)
|
||||||
|
class FeedRenderRequest:
|
||||||
|
format: FeedFormat
|
||||||
|
title: str
|
||||||
|
feed_url: str
|
||||||
|
home_url: str
|
||||||
|
entries: tuple[FeedEntry, ...]
|
||||||
|
description: str | None = None
|
||||||
|
language: str | None = None
|
||||||
|
allowed_visibilities: frozenset[FeedVisibility] = frozenset({"public"})
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass(frozen=True, slots=True)
|
||||||
|
class FeedRenderResult:
|
||||||
|
format: FeedFormat
|
||||||
|
content_type: str
|
||||||
|
body: bytes
|
||||||
|
included_entries: int
|
||||||
|
excluded_entries: int
|
||||||
|
|
||||||
|
|
||||||
|
@runtime_checkable
|
||||||
|
class FeedProvider(Protocol):
|
||||||
|
def fetch(
|
||||||
|
self,
|
||||||
|
url: str,
|
||||||
|
*,
|
||||||
|
timeout: float = 15,
|
||||||
|
max_entries: int = 2_000,
|
||||||
|
) -> FeedDocument:
|
||||||
|
...
|
||||||
|
|
||||||
|
def parse(
|
||||||
|
self,
|
||||||
|
content: bytes,
|
||||||
|
*,
|
||||||
|
source_url: str,
|
||||||
|
content_type: str | None = None,
|
||||||
|
max_entries: int = 2_000,
|
||||||
|
) -> FeedDocument:
|
||||||
|
...
|
||||||
|
|
||||||
|
def render(self, request: FeedRenderRequest) -> FeedRenderResult:
|
||||||
|
...
|
||||||
|
|
||||||
|
|
||||||
|
def feed_provider(registry: object | None) -> FeedProvider | None:
|
||||||
|
if (
|
||||||
|
registry is None
|
||||||
|
or not hasattr(registry, "has_capability")
|
||||||
|
or not hasattr(registry, "capability")
|
||||||
|
or not registry.has_capability(CAPABILITY_CONNECTORS_FEEDS)
|
||||||
|
):
|
||||||
|
return None
|
||||||
|
provider = registry.capability(CAPABILITY_CONNECTORS_FEEDS)
|
||||||
|
return provider if isinstance(provider, FeedProvider) else None
|
||||||
|
|
||||||
|
|
||||||
|
__all__ = [
|
||||||
|
"CAPABILITY_CONNECTORS_FEEDS",
|
||||||
|
"FeedCapabilityError",
|
||||||
|
"FeedDocument",
|
||||||
|
"FeedEntry",
|
||||||
|
"FeedFormat",
|
||||||
|
"FeedProvider",
|
||||||
|
"FeedRenderRequest",
|
||||||
|
"FeedRenderResult",
|
||||||
|
"FeedVisibility",
|
||||||
|
"feed_provider",
|
||||||
|
]
|
||||||
@@ -1,13 +1,228 @@
|
|||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
|
from collections.abc import Mapping
|
||||||
|
from dataclasses import dataclass, field
|
||||||
|
from datetime import datetime
|
||||||
from typing import Protocol, runtime_checkable
|
from typing import Protocol, runtime_checkable
|
||||||
|
|
||||||
from govoplan_core.core.access import ResourceAccessExplanationProvider
|
from govoplan_core.core.access import ResourceAccessExplanationProvider
|
||||||
|
|
||||||
|
|
||||||
CAPABILITY_FILES_ACCESS = "files.access"
|
CAPABILITY_FILES_ACCESS = "files.access"
|
||||||
|
CAPABILITY_FILES_ARTIFACT_STORE = "files.artifact_store"
|
||||||
|
CAPABILITY_FILES_POSTBOX_REFERENCES = "files.postbox_references"
|
||||||
|
CAPABILITY_FILES_TABULAR_CONTENT = "files.tabular_content"
|
||||||
|
|
||||||
|
|
||||||
|
class ManagedTabularFileError(ValueError):
|
||||||
|
"""Stable base error for exact-version managed tabular file access."""
|
||||||
|
|
||||||
|
|
||||||
|
class ManagedTabularFileNotFoundError(ManagedTabularFileError):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
class ManagedTabularFileAccessError(ManagedTabularFileError):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
class ManagedTabularFileUnavailableError(ManagedTabularFileError):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
class ManagedTabularFileValidationError(ManagedTabularFileError):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass(frozen=True, slots=True)
|
||||||
|
class ManagedTabularFile:
|
||||||
|
"""Authorized metadata for one immutable managed file version."""
|
||||||
|
|
||||||
|
file_asset_id: str
|
||||||
|
file_version_id: str
|
||||||
|
filename: str
|
||||||
|
display_path: str
|
||||||
|
content_type: str | None
|
||||||
|
size_bytes: int
|
||||||
|
sha256: str
|
||||||
|
updated_at: datetime | None = None
|
||||||
|
current_version: bool = True
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass(frozen=True, slots=True)
|
||||||
|
class ManagedTabularFileContent:
|
||||||
|
file: ManagedTabularFile
|
||||||
|
payload: bytes
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass(frozen=True, slots=True)
|
||||||
|
class ManagedArtifactWriteRequest:
|
||||||
|
filename: str
|
||||||
|
payload: bytes
|
||||||
|
content_type: str
|
||||||
|
folder: str = "Generated"
|
||||||
|
description: str | None = None
|
||||||
|
idempotency_key: str | None = None
|
||||||
|
metadata: Mapping[str, object] = field(default_factory=dict)
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass(frozen=True, slots=True)
|
||||||
|
class ManagedArtifactRef:
|
||||||
|
file_asset_id: str
|
||||||
|
file_version_id: str
|
||||||
|
filename: str
|
||||||
|
display_path: str
|
||||||
|
content_type: str
|
||||||
|
size_bytes: int
|
||||||
|
sha256: str
|
||||||
|
provenance: Mapping[str, object] = field(default_factory=dict)
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass(frozen=True, slots=True)
|
||||||
|
class PostboxFileReferenceRequest:
|
||||||
|
reference_type: str
|
||||||
|
reference_id: str
|
||||||
|
postbox_id: str
|
||||||
|
message_id: str
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass(frozen=True, slots=True)
|
||||||
|
class PostboxFileReferenceRef:
|
||||||
|
reference_type: str
|
||||||
|
reference_id: str
|
||||||
|
available: bool
|
||||||
|
reason_code: str
|
||||||
|
file_asset_id: str | None = None
|
||||||
|
file_version_id: str | None = None
|
||||||
|
filename: str | None = None
|
||||||
|
content_type: str | None = None
|
||||||
|
size_bytes: int | None = None
|
||||||
|
sha256: str | None = None
|
||||||
|
download_path: str | None = None
|
||||||
|
provenance: Mapping[str, object] = field(default_factory=dict)
|
||||||
|
|
||||||
|
|
||||||
@runtime_checkable
|
@runtime_checkable
|
||||||
class FileAccessProvider(ResourceAccessExplanationProvider, Protocol):
|
class FileAccessProvider(ResourceAccessExplanationProvider, Protocol):
|
||||||
"""Resource-level access explanation provider for Files-owned resources."""
|
"""Resource-level access explanation provider for Files-owned resources."""
|
||||||
|
|
||||||
|
|
||||||
|
@runtime_checkable
|
||||||
|
class ManagedArtifactStore(Protocol):
|
||||||
|
"""Store generated module artifacts without exposing Files internals."""
|
||||||
|
|
||||||
|
def store_artifact(
|
||||||
|
self,
|
||||||
|
session: object,
|
||||||
|
principal: object,
|
||||||
|
*,
|
||||||
|
request: ManagedArtifactWriteRequest,
|
||||||
|
) -> ManagedArtifactRef: ...
|
||||||
|
|
||||||
|
|
||||||
|
@runtime_checkable
|
||||||
|
class PostboxFileReferenceProvider(Protocol):
|
||||||
|
"""Resolve Files-owned references after Postbox and Files authorization."""
|
||||||
|
|
||||||
|
def resolve_postbox_references(
|
||||||
|
self,
|
||||||
|
session: object,
|
||||||
|
principal: object,
|
||||||
|
*,
|
||||||
|
tenant_id: str,
|
||||||
|
requests: tuple[PostboxFileReferenceRequest, ...],
|
||||||
|
) -> tuple[PostboxFileReferenceRef, ...]: ...
|
||||||
|
|
||||||
|
|
||||||
|
@runtime_checkable
|
||||||
|
class ManagedTabularFileProvider(Protocol):
|
||||||
|
"""List and open authorized CSV/XLSX content without exposing Files internals."""
|
||||||
|
|
||||||
|
def list_tabular_files(
|
||||||
|
self,
|
||||||
|
session: object,
|
||||||
|
principal: object,
|
||||||
|
*,
|
||||||
|
query: str = "",
|
||||||
|
limit: int = 100,
|
||||||
|
) -> tuple[ManagedTabularFile, ...]: ...
|
||||||
|
|
||||||
|
def get_tabular_file(
|
||||||
|
self,
|
||||||
|
session: object,
|
||||||
|
principal: object,
|
||||||
|
*,
|
||||||
|
file_asset_id: str,
|
||||||
|
file_version_id: str | None = None,
|
||||||
|
) -> ManagedTabularFile | None: ...
|
||||||
|
|
||||||
|
def read_tabular_file(
|
||||||
|
self,
|
||||||
|
session: object,
|
||||||
|
principal: object,
|
||||||
|
*,
|
||||||
|
file_asset_id: str,
|
||||||
|
file_version_id: str,
|
||||||
|
max_bytes: int,
|
||||||
|
) -> ManagedTabularFileContent: ...
|
||||||
|
|
||||||
|
|
||||||
|
def postbox_file_reference_provider(
|
||||||
|
registry: object | None,
|
||||||
|
) -> PostboxFileReferenceProvider | None:
|
||||||
|
if (
|
||||||
|
registry is None
|
||||||
|
or not hasattr(registry, "has_capability")
|
||||||
|
or not registry.has_capability(CAPABILITY_FILES_POSTBOX_REFERENCES)
|
||||||
|
):
|
||||||
|
return None
|
||||||
|
provider = registry.require_capability(CAPABILITY_FILES_POSTBOX_REFERENCES)
|
||||||
|
if not isinstance(provider, PostboxFileReferenceProvider):
|
||||||
|
raise TypeError(
|
||||||
|
"files.postbox_references provider does not implement "
|
||||||
|
"PostboxFileReferenceProvider"
|
||||||
|
)
|
||||||
|
return provider
|
||||||
|
|
||||||
|
|
||||||
|
def managed_tabular_file_provider(
|
||||||
|
registry: object | None,
|
||||||
|
) -> ManagedTabularFileProvider | None:
|
||||||
|
if (
|
||||||
|
registry is None
|
||||||
|
or not hasattr(registry, "has_capability")
|
||||||
|
or not registry.has_capability(CAPABILITY_FILES_TABULAR_CONTENT)
|
||||||
|
):
|
||||||
|
return None
|
||||||
|
provider = registry.require_capability(CAPABILITY_FILES_TABULAR_CONTENT)
|
||||||
|
if not isinstance(provider, ManagedTabularFileProvider):
|
||||||
|
raise TypeError(
|
||||||
|
"files.tabular_content provider does not implement "
|
||||||
|
"ManagedTabularFileProvider"
|
||||||
|
)
|
||||||
|
return provider
|
||||||
|
|
||||||
|
|
||||||
|
__all__ = [
|
||||||
|
"CAPABILITY_FILES_ACCESS",
|
||||||
|
"CAPABILITY_FILES_ARTIFACT_STORE",
|
||||||
|
"CAPABILITY_FILES_POSTBOX_REFERENCES",
|
||||||
|
"CAPABILITY_FILES_TABULAR_CONTENT",
|
||||||
|
"FileAccessProvider",
|
||||||
|
"ManagedArtifactRef",
|
||||||
|
"ManagedArtifactStore",
|
||||||
|
"ManagedArtifactWriteRequest",
|
||||||
|
"ManagedTabularFile",
|
||||||
|
"ManagedTabularFileAccessError",
|
||||||
|
"ManagedTabularFileContent",
|
||||||
|
"ManagedTabularFileError",
|
||||||
|
"ManagedTabularFileNotFoundError",
|
||||||
|
"ManagedTabularFileProvider",
|
||||||
|
"ManagedTabularFileUnavailableError",
|
||||||
|
"ManagedTabularFileValidationError",
|
||||||
|
"PostboxFileReferenceProvider",
|
||||||
|
"PostboxFileReferenceRef",
|
||||||
|
"PostboxFileReferenceRequest",
|
||||||
|
"managed_tabular_file_provider",
|
||||||
|
"postbox_file_reference_provider",
|
||||||
|
]
|
||||||
|
|||||||
@@ -0,0 +1,532 @@
|
|||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
from dataclasses import dataclass
|
||||||
|
from datetime import datetime, timedelta, timezone
|
||||||
|
from enum import StrEnum
|
||||||
|
import hashlib
|
||||||
|
import hmac
|
||||||
|
import json
|
||||||
|
import re
|
||||||
|
import secrets
|
||||||
|
from typing import Any
|
||||||
|
from uuid import uuid4
|
||||||
|
|
||||||
|
from sqlalchemy import DateTime, ForeignKey, Integer, JSON, String, UniqueConstraint, select
|
||||||
|
from sqlalchemy.exc import IntegrityError
|
||||||
|
from sqlalchemy.orm import Mapped, Session, mapped_column
|
||||||
|
|
||||||
|
from govoplan_core.audit.logging import audit_event
|
||||||
|
from govoplan_core.core.access import (
|
||||||
|
FirstAdminProvisioner,
|
||||||
|
FirstAdminProvisioningError,
|
||||||
|
FirstSystemAdministratorRef,
|
||||||
|
)
|
||||||
|
from govoplan_core.db.base import Base, TimestampMixin, utcnow
|
||||||
|
from govoplan_core.tenancy.scope import Tenant
|
||||||
|
|
||||||
|
|
||||||
|
_TENANT_SLUG_RE = re.compile(r"^[a-z0-9]+(?:-[a-z0-9]+)*$")
|
||||||
|
|
||||||
|
|
||||||
|
class FirstAdminEnrollmentState(StrEnum):
|
||||||
|
INACTIVE = "inactive"
|
||||||
|
ACTIVE = "active"
|
||||||
|
CONSUMED = "consumed"
|
||||||
|
REVOKED = "revoked"
|
||||||
|
|
||||||
|
|
||||||
|
class FirstAdminEnrollmentError(RuntimeError):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
class FirstAdminEnrollmentUnavailable(FirstAdminEnrollmentError):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
class FirstAdminEnrollmentCredentialError(FirstAdminEnrollmentError):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
class FirstAdminEnrollmentConflict(FirstAdminEnrollmentError):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
class FirstAdminEnrollment(Base, TimestampMixin):
|
||||||
|
__tablename__ = "core_first_admin_enrollments"
|
||||||
|
|
||||||
|
installation_id: Mapped[str] = mapped_column(String(100), primary_key=True)
|
||||||
|
state: Mapped[str] = mapped_column(
|
||||||
|
String(24),
|
||||||
|
default=FirstAdminEnrollmentState.INACTIVE.value,
|
||||||
|
nullable=False,
|
||||||
|
index=True,
|
||||||
|
)
|
||||||
|
generation: Mapped[int] = mapped_column(Integer, default=0, nullable=False)
|
||||||
|
token_sha256: Mapped[str | None] = mapped_column(String(64))
|
||||||
|
token_fingerprint: Mapped[str | None] = mapped_column(String(16))
|
||||||
|
issued_at: Mapped[datetime | None] = mapped_column(DateTime(timezone=True))
|
||||||
|
expires_at: Mapped[datetime | None] = mapped_column(DateTime(timezone=True), index=True)
|
||||||
|
consumed_at: Mapped[datetime | None] = mapped_column(DateTime(timezone=True))
|
||||||
|
consumed_account_id: Mapped[str | None] = mapped_column(String(36))
|
||||||
|
consumed_membership_id: Mapped[str | None] = mapped_column(String(36))
|
||||||
|
consumed_tenant_id: Mapped[str | None] = mapped_column(String(36))
|
||||||
|
consumed_email: Mapped[str | None] = mapped_column(String(320))
|
||||||
|
consumed_display_name: Mapped[str | None] = mapped_column(String(255))
|
||||||
|
consumed_request_sha256: Mapped[str | None] = mapped_column(String(64))
|
||||||
|
issue_reason: Mapped[str | None] = mapped_column(String(500))
|
||||||
|
event_count: Mapped[int] = mapped_column(Integer, default=0, nullable=False)
|
||||||
|
evidence_head_sha256: Mapped[str | None] = mapped_column(String(64))
|
||||||
|
|
||||||
|
|
||||||
|
class FirstAdminEnrollmentEvent(Base):
|
||||||
|
__tablename__ = "core_first_admin_enrollment_events"
|
||||||
|
__table_args__ = (
|
||||||
|
UniqueConstraint(
|
||||||
|
"installation_id",
|
||||||
|
"sequence",
|
||||||
|
name="uq_core_first_admin_enrollment_event_sequence",
|
||||||
|
),
|
||||||
|
)
|
||||||
|
|
||||||
|
id: Mapped[str] = mapped_column(
|
||||||
|
String(36),
|
||||||
|
primary_key=True,
|
||||||
|
default=lambda: str(uuid4()),
|
||||||
|
)
|
||||||
|
installation_id: Mapped[str] = mapped_column(
|
||||||
|
ForeignKey(
|
||||||
|
"core_first_admin_enrollments.installation_id",
|
||||||
|
ondelete="CASCADE",
|
||||||
|
),
|
||||||
|
nullable=False,
|
||||||
|
index=True,
|
||||||
|
)
|
||||||
|
sequence: Mapped[int] = mapped_column(Integer, nullable=False)
|
||||||
|
event_type: Mapped[str] = mapped_column(String(80), nullable=False, index=True)
|
||||||
|
generation: Mapped[int] = mapped_column(Integer, nullable=False)
|
||||||
|
evidence: Mapped[dict[str, Any]] = mapped_column(JSON, default=dict, nullable=False)
|
||||||
|
previous_sha256: Mapped[str | None] = mapped_column(String(64))
|
||||||
|
event_sha256: Mapped[str] = mapped_column(String(64), nullable=False, index=True)
|
||||||
|
created_at: Mapped[datetime] = mapped_column(
|
||||||
|
DateTime(timezone=True),
|
||||||
|
default=utcnow,
|
||||||
|
nullable=False,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass(frozen=True, slots=True)
|
||||||
|
class IssuedFirstAdminCredential:
|
||||||
|
secret: str
|
||||||
|
fingerprint: str
|
||||||
|
generation: int
|
||||||
|
expires_at: datetime
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass(frozen=True, slots=True)
|
||||||
|
class FirstAdminEnrollmentStatus:
|
||||||
|
enrollment_required: bool
|
||||||
|
credential_active: bool
|
||||||
|
state: str
|
||||||
|
generation: int
|
||||||
|
expires_at: datetime | None
|
||||||
|
completed_account_id: str | None
|
||||||
|
readiness: dict[str, bool]
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass(frozen=True, slots=True)
|
||||||
|
class FirstAdminEnrollmentResult:
|
||||||
|
administrator: FirstSystemAdministratorRef
|
||||||
|
replayed: bool
|
||||||
|
|
||||||
|
|
||||||
|
def issue_first_admin_credential(
|
||||||
|
session: Session,
|
||||||
|
*,
|
||||||
|
installation_id: str,
|
||||||
|
provisioner: FirstAdminProvisioner,
|
||||||
|
ttl_seconds: int,
|
||||||
|
reason: str,
|
||||||
|
replace_active: bool = False,
|
||||||
|
now: datetime | None = None,
|
||||||
|
) -> IssuedFirstAdminCredential:
|
||||||
|
current_time = _utc(now)
|
||||||
|
if ttl_seconds < 60 or ttl_seconds > 24 * 60 * 60:
|
||||||
|
raise ValueError("First-admin enrollment expiry must be between 60 seconds and 24 hours.")
|
||||||
|
if provisioner.has_durable_system_administrator(session):
|
||||||
|
raise FirstAdminEnrollmentUnavailable(
|
||||||
|
"A durable system administrator already exists. Bootstrap enrollment is disabled."
|
||||||
|
)
|
||||||
|
|
||||||
|
enrollment = _locked_enrollment(session, installation_id)
|
||||||
|
if (
|
||||||
|
enrollment.state == FirstAdminEnrollmentState.ACTIVE.value
|
||||||
|
and _is_future(enrollment.expires_at, current_time)
|
||||||
|
and not replace_active
|
||||||
|
):
|
||||||
|
raise FirstAdminEnrollmentConflict(
|
||||||
|
"An unexpired first-admin credential already exists. Use the recovery command to rotate it."
|
||||||
|
)
|
||||||
|
|
||||||
|
secret = secrets.token_urlsafe(48)
|
||||||
|
token_sha256 = _secret_sha256(secret)
|
||||||
|
fingerprint = token_sha256[:12]
|
||||||
|
expires_at = current_time + timedelta(seconds=ttl_seconds)
|
||||||
|
generation = enrollment.generation + 1
|
||||||
|
if enrollment.state == FirstAdminEnrollmentState.ACTIVE.value:
|
||||||
|
_append_event(
|
||||||
|
session,
|
||||||
|
enrollment,
|
||||||
|
event_type="credential_revoked",
|
||||||
|
generation=enrollment.generation,
|
||||||
|
created_at=current_time,
|
||||||
|
evidence={"reason": "local_operator_recovery"},
|
||||||
|
)
|
||||||
|
enrollment.state = FirstAdminEnrollmentState.ACTIVE.value
|
||||||
|
enrollment.generation = generation
|
||||||
|
enrollment.token_sha256 = token_sha256
|
||||||
|
enrollment.token_fingerprint = fingerprint
|
||||||
|
enrollment.issued_at = current_time
|
||||||
|
enrollment.expires_at = expires_at
|
||||||
|
enrollment.consumed_at = None
|
||||||
|
enrollment.consumed_account_id = None
|
||||||
|
enrollment.consumed_membership_id = None
|
||||||
|
enrollment.consumed_tenant_id = None
|
||||||
|
enrollment.consumed_email = None
|
||||||
|
enrollment.consumed_display_name = None
|
||||||
|
enrollment.consumed_request_sha256 = None
|
||||||
|
enrollment.issue_reason = _bounded_reason(reason)
|
||||||
|
session.add(enrollment)
|
||||||
|
_append_event(
|
||||||
|
session,
|
||||||
|
enrollment,
|
||||||
|
event_type="credential_issued",
|
||||||
|
generation=generation,
|
||||||
|
created_at=current_time,
|
||||||
|
evidence={
|
||||||
|
"fingerprint": fingerprint,
|
||||||
|
"expires_at": expires_at.isoformat(),
|
||||||
|
"reason": enrollment.issue_reason,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
audit_event(
|
||||||
|
session,
|
||||||
|
tenant_id=None,
|
||||||
|
scope="system",
|
||||||
|
action="access.first_admin_enrollment.issued",
|
||||||
|
object_type="first_admin_enrollment",
|
||||||
|
object_id=installation_id,
|
||||||
|
details={
|
||||||
|
"generation": generation,
|
||||||
|
"fingerprint": fingerprint,
|
||||||
|
"expires_at": expires_at.isoformat(),
|
||||||
|
"reason": enrollment.issue_reason,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
return IssuedFirstAdminCredential(
|
||||||
|
secret=secret,
|
||||||
|
fingerprint=fingerprint,
|
||||||
|
generation=generation,
|
||||||
|
expires_at=expires_at,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def first_admin_enrollment_status(
|
||||||
|
session: Session,
|
||||||
|
*,
|
||||||
|
installation_id: str,
|
||||||
|
provisioner: FirstAdminProvisioner,
|
||||||
|
now: datetime | None = None,
|
||||||
|
) -> FirstAdminEnrollmentStatus:
|
||||||
|
current_time = _utc(now)
|
||||||
|
administrator_exists = provisioner.has_durable_system_administrator(session)
|
||||||
|
enrollment = session.get(FirstAdminEnrollment, installation_id)
|
||||||
|
state = enrollment.state if enrollment is not None else FirstAdminEnrollmentState.INACTIVE.value
|
||||||
|
active = bool(
|
||||||
|
not administrator_exists
|
||||||
|
and enrollment is not None
|
||||||
|
and state == FirstAdminEnrollmentState.ACTIVE.value
|
||||||
|
and enrollment.token_sha256
|
||||||
|
and _is_future(enrollment.expires_at, current_time)
|
||||||
|
)
|
||||||
|
if (
|
||||||
|
not administrator_exists
|
||||||
|
and enrollment is not None
|
||||||
|
and state == FirstAdminEnrollmentState.ACTIVE.value
|
||||||
|
and not active
|
||||||
|
):
|
||||||
|
state = "expired"
|
||||||
|
return FirstAdminEnrollmentStatus(
|
||||||
|
enrollment_required=not administrator_exists,
|
||||||
|
credential_active=active,
|
||||||
|
state="completed" if administrator_exists else state,
|
||||||
|
generation=enrollment.generation if enrollment is not None else 0,
|
||||||
|
expires_at=enrollment.expires_at if enrollment is not None else None,
|
||||||
|
completed_account_id=(
|
||||||
|
enrollment.consumed_account_id if enrollment is not None else None
|
||||||
|
),
|
||||||
|
readiness={
|
||||||
|
"database": True,
|
||||||
|
"access_capability": True,
|
||||||
|
"administrator_absent": not administrator_exists,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def consume_first_admin_credential(
|
||||||
|
session: Session,
|
||||||
|
*,
|
||||||
|
installation_id: str,
|
||||||
|
provisioner: FirstAdminProvisioner,
|
||||||
|
secret: str,
|
||||||
|
email: str,
|
||||||
|
display_name: str | None,
|
||||||
|
password: str,
|
||||||
|
tenant_slug: str,
|
||||||
|
tenant_name: str,
|
||||||
|
now: datetime | None = None,
|
||||||
|
) -> FirstAdminEnrollmentResult:
|
||||||
|
current_time = _utc(now)
|
||||||
|
normalized_email = email.strip().casefold()
|
||||||
|
clean_display_name = display_name.strip() if display_name and display_name.strip() else None
|
||||||
|
clean_tenant_slug = tenant_slug.strip().casefold()
|
||||||
|
clean_tenant_name = tenant_name.strip()
|
||||||
|
if not normalized_email or "@" not in normalized_email:
|
||||||
|
raise FirstAdminEnrollmentConflict("Enter a valid administrator email address.")
|
||||||
|
if len(password) < 12:
|
||||||
|
raise FirstAdminEnrollmentConflict("The administrator password must contain at least 12 characters.")
|
||||||
|
if not _TENANT_SLUG_RE.fullmatch(clean_tenant_slug):
|
||||||
|
raise FirstAdminEnrollmentConflict(
|
||||||
|
"The initial tenant slug may contain lowercase letters, numbers, and single hyphens."
|
||||||
|
)
|
||||||
|
if not clean_tenant_name:
|
||||||
|
raise FirstAdminEnrollmentConflict("Enter a name for the initial tenant.")
|
||||||
|
|
||||||
|
request_sha256 = _request_sha256(
|
||||||
|
email=normalized_email,
|
||||||
|
display_name=clean_display_name,
|
||||||
|
tenant_slug=clean_tenant_slug,
|
||||||
|
tenant_name=clean_tenant_name,
|
||||||
|
)
|
||||||
|
supplied_sha256 = _secret_sha256(secret)
|
||||||
|
enrollment = session.execute(
|
||||||
|
select(FirstAdminEnrollment)
|
||||||
|
.where(FirstAdminEnrollment.installation_id == installation_id)
|
||||||
|
.with_for_update()
|
||||||
|
).scalar_one_or_none()
|
||||||
|
if enrollment is None:
|
||||||
|
raise FirstAdminEnrollmentCredentialError("First-admin enrollment is not active.")
|
||||||
|
|
||||||
|
if enrollment.state == FirstAdminEnrollmentState.CONSUMED.value:
|
||||||
|
if (
|
||||||
|
enrollment.token_sha256
|
||||||
|
and hmac.compare_digest(enrollment.token_sha256, supplied_sha256)
|
||||||
|
and enrollment.consumed_request_sha256 == request_sha256
|
||||||
|
and enrollment.consumed_account_id
|
||||||
|
and enrollment.consumed_email
|
||||||
|
):
|
||||||
|
return FirstAdminEnrollmentResult(
|
||||||
|
administrator=FirstSystemAdministratorRef(
|
||||||
|
account_id=enrollment.consumed_account_id,
|
||||||
|
email=enrollment.consumed_email,
|
||||||
|
display_name=enrollment.consumed_display_name,
|
||||||
|
membership_id=enrollment.consumed_membership_id,
|
||||||
|
tenant_id=enrollment.consumed_tenant_id,
|
||||||
|
),
|
||||||
|
replayed=True,
|
||||||
|
)
|
||||||
|
raise FirstAdminEnrollmentCredentialError("The first-admin credential has already been used.")
|
||||||
|
|
||||||
|
if enrollment.state != FirstAdminEnrollmentState.ACTIVE.value or not enrollment.token_sha256:
|
||||||
|
raise FirstAdminEnrollmentCredentialError("First-admin enrollment is not active.")
|
||||||
|
if not _is_future(enrollment.expires_at, current_time):
|
||||||
|
raise FirstAdminEnrollmentCredentialError(
|
||||||
|
"The first-admin credential has expired. A local operator must issue a replacement."
|
||||||
|
)
|
||||||
|
if not hmac.compare_digest(enrollment.token_sha256, supplied_sha256):
|
||||||
|
raise FirstAdminEnrollmentCredentialError("The first-admin credential is invalid.")
|
||||||
|
if provisioner.has_durable_system_administrator(session):
|
||||||
|
raise FirstAdminEnrollmentUnavailable(
|
||||||
|
"A durable system administrator already exists. Bootstrap enrollment is disabled."
|
||||||
|
)
|
||||||
|
|
||||||
|
tenant = session.execute(
|
||||||
|
select(Tenant).where(Tenant.slug == clean_tenant_slug).with_for_update()
|
||||||
|
).scalar_one_or_none()
|
||||||
|
if tenant is None:
|
||||||
|
tenant = Tenant(
|
||||||
|
slug=clean_tenant_slug,
|
||||||
|
name=clean_tenant_name,
|
||||||
|
default_locale="de",
|
||||||
|
settings={},
|
||||||
|
is_active=True,
|
||||||
|
)
|
||||||
|
session.add(tenant)
|
||||||
|
session.flush()
|
||||||
|
elif not tenant.is_active:
|
||||||
|
raise FirstAdminEnrollmentConflict("The selected initial tenant is inactive.")
|
||||||
|
|
||||||
|
try:
|
||||||
|
administrator = provisioner.create_first_system_administrator(
|
||||||
|
session,
|
||||||
|
tenant=tenant,
|
||||||
|
email=normalized_email,
|
||||||
|
display_name=clean_display_name,
|
||||||
|
password=password,
|
||||||
|
)
|
||||||
|
except FirstAdminProvisioningError as exc:
|
||||||
|
raise FirstAdminEnrollmentConflict(str(exc)) from exc
|
||||||
|
enrollment.state = FirstAdminEnrollmentState.CONSUMED.value
|
||||||
|
enrollment.consumed_at = current_time
|
||||||
|
enrollment.consumed_account_id = administrator.account_id
|
||||||
|
enrollment.consumed_membership_id = administrator.membership_id
|
||||||
|
enrollment.consumed_tenant_id = administrator.tenant_id
|
||||||
|
enrollment.consumed_email = administrator.email
|
||||||
|
enrollment.consumed_display_name = administrator.display_name
|
||||||
|
enrollment.consumed_request_sha256 = request_sha256
|
||||||
|
session.add(enrollment)
|
||||||
|
_append_event(
|
||||||
|
session,
|
||||||
|
enrollment,
|
||||||
|
event_type="administrator_created",
|
||||||
|
generation=enrollment.generation,
|
||||||
|
created_at=current_time,
|
||||||
|
evidence={
|
||||||
|
"account_id": administrator.account_id,
|
||||||
|
"membership_id": administrator.membership_id,
|
||||||
|
"tenant_id": administrator.tenant_id,
|
||||||
|
"email_sha256": hashlib.sha256(normalized_email.encode("utf-8")).hexdigest(),
|
||||||
|
},
|
||||||
|
)
|
||||||
|
audit_event(
|
||||||
|
session,
|
||||||
|
tenant_id=None,
|
||||||
|
scope="system",
|
||||||
|
action="access.first_admin_enrollment.completed",
|
||||||
|
object_type="access_account",
|
||||||
|
object_id=administrator.account_id,
|
||||||
|
details={
|
||||||
|
"generation": enrollment.generation,
|
||||||
|
"membership_id": administrator.membership_id,
|
||||||
|
"tenant_id": administrator.tenant_id,
|
||||||
|
"credential_invalidated": True,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
return FirstAdminEnrollmentResult(administrator=administrator, replayed=False)
|
||||||
|
|
||||||
|
|
||||||
|
def _locked_enrollment(session: Session, installation_id: str) -> FirstAdminEnrollment:
|
||||||
|
enrollment = session.execute(
|
||||||
|
select(FirstAdminEnrollment)
|
||||||
|
.where(FirstAdminEnrollment.installation_id == installation_id)
|
||||||
|
.with_for_update()
|
||||||
|
).scalar_one_or_none()
|
||||||
|
if enrollment is not None:
|
||||||
|
return enrollment
|
||||||
|
enrollment = FirstAdminEnrollment(installation_id=installation_id)
|
||||||
|
try:
|
||||||
|
with session.begin_nested():
|
||||||
|
session.add(enrollment)
|
||||||
|
session.flush()
|
||||||
|
except IntegrityError:
|
||||||
|
enrollment = session.execute(
|
||||||
|
select(FirstAdminEnrollment)
|
||||||
|
.where(FirstAdminEnrollment.installation_id == installation_id)
|
||||||
|
.with_for_update()
|
||||||
|
).scalar_one()
|
||||||
|
return enrollment
|
||||||
|
|
||||||
|
|
||||||
|
def _append_event(
|
||||||
|
session: Session,
|
||||||
|
enrollment: FirstAdminEnrollment,
|
||||||
|
*,
|
||||||
|
event_type: str,
|
||||||
|
generation: int,
|
||||||
|
created_at: datetime,
|
||||||
|
evidence: dict[str, Any],
|
||||||
|
) -> None:
|
||||||
|
sequence = enrollment.event_count + 1
|
||||||
|
payload = {
|
||||||
|
"installation_id": enrollment.installation_id,
|
||||||
|
"sequence": sequence,
|
||||||
|
"event_type": event_type,
|
||||||
|
"generation": generation,
|
||||||
|
"created_at": created_at.isoformat(),
|
||||||
|
"evidence": evidence,
|
||||||
|
"previous_sha256": enrollment.evidence_head_sha256,
|
||||||
|
}
|
||||||
|
event_sha256 = hashlib.sha256(
|
||||||
|
json.dumps(payload, sort_keys=True, separators=(",", ":")).encode("utf-8")
|
||||||
|
).hexdigest()
|
||||||
|
session.add(
|
||||||
|
FirstAdminEnrollmentEvent(
|
||||||
|
installation_id=enrollment.installation_id,
|
||||||
|
sequence=sequence,
|
||||||
|
event_type=event_type,
|
||||||
|
generation=generation,
|
||||||
|
evidence=evidence,
|
||||||
|
previous_sha256=enrollment.evidence_head_sha256,
|
||||||
|
event_sha256=event_sha256,
|
||||||
|
created_at=created_at,
|
||||||
|
)
|
||||||
|
)
|
||||||
|
enrollment.event_count = sequence
|
||||||
|
enrollment.evidence_head_sha256 = event_sha256
|
||||||
|
session.add(enrollment)
|
||||||
|
|
||||||
|
|
||||||
|
def _request_sha256(
|
||||||
|
*,
|
||||||
|
email: str,
|
||||||
|
display_name: str | None,
|
||||||
|
tenant_slug: str,
|
||||||
|
tenant_name: str,
|
||||||
|
) -> str:
|
||||||
|
payload = {
|
||||||
|
"email": email,
|
||||||
|
"display_name": display_name,
|
||||||
|
"tenant_slug": tenant_slug,
|
||||||
|
"tenant_name": tenant_name,
|
||||||
|
}
|
||||||
|
return hashlib.sha256(
|
||||||
|
json.dumps(payload, sort_keys=True, separators=(",", ":")).encode("utf-8")
|
||||||
|
).hexdigest()
|
||||||
|
|
||||||
|
|
||||||
|
def _secret_sha256(secret: str) -> str:
|
||||||
|
return hashlib.sha256(secret.encode("utf-8")).hexdigest()
|
||||||
|
|
||||||
|
|
||||||
|
def _utc(value: datetime | None) -> datetime:
|
||||||
|
candidate = value or datetime.now(timezone.utc)
|
||||||
|
if candidate.tzinfo is None:
|
||||||
|
return candidate.replace(tzinfo=timezone.utc)
|
||||||
|
return candidate.astimezone(timezone.utc)
|
||||||
|
|
||||||
|
|
||||||
|
def _is_future(value: datetime | None, now: datetime) -> bool:
|
||||||
|
return value is not None and _utc(value) > now
|
||||||
|
|
||||||
|
|
||||||
|
def _bounded_reason(value: str) -> str:
|
||||||
|
clean = value.strip()
|
||||||
|
if not clean:
|
||||||
|
raise ValueError("A local operator reason is required.")
|
||||||
|
return clean[:500]
|
||||||
|
|
||||||
|
|
||||||
|
__all__ = [
|
||||||
|
"FirstAdminEnrollment",
|
||||||
|
"FirstAdminEnrollmentConflict",
|
||||||
|
"FirstAdminEnrollmentCredentialError",
|
||||||
|
"FirstAdminEnrollmentError",
|
||||||
|
"FirstAdminEnrollmentEvent",
|
||||||
|
"FirstAdminEnrollmentResult",
|
||||||
|
"FirstAdminEnrollmentState",
|
||||||
|
"FirstAdminEnrollmentStatus",
|
||||||
|
"FirstAdminEnrollmentUnavailable",
|
||||||
|
"IssuedFirstAdminCredential",
|
||||||
|
"consume_first_admin_credential",
|
||||||
|
"first_admin_enrollment_status",
|
||||||
|
"issue_first_admin_credential",
|
||||||
|
]
|
||||||
@@ -0,0 +1,227 @@
|
|||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
from collections.abc import Mapping, Sequence
|
||||||
|
from dataclasses import dataclass, field
|
||||||
|
from datetime import datetime
|
||||||
|
from typing import Literal, Protocol, runtime_checkable
|
||||||
|
|
||||||
|
from govoplan_core.core.institutional import EvidenceReference, InstitutionalReference
|
||||||
|
|
||||||
|
|
||||||
|
CAPABILITY_FORM_EVIDENCE_PREFIX = "forms_runtime.evidence."
|
||||||
|
|
||||||
|
FormEvidenceState = Literal[
|
||||||
|
"accepted",
|
||||||
|
"pending",
|
||||||
|
"rejected",
|
||||||
|
"expired",
|
||||||
|
"revoked",
|
||||||
|
"unavailable",
|
||||||
|
]
|
||||||
|
|
||||||
|
_FORM_EVIDENCE_STATES = {
|
||||||
|
"accepted",
|
||||||
|
"pending",
|
||||||
|
"rejected",
|
||||||
|
"expired",
|
||||||
|
"revoked",
|
||||||
|
"unavailable",
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
class FormEvidenceContractError(ValueError):
|
||||||
|
"""Stable error for provider-neutral Form evidence operations."""
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass(frozen=True, slots=True)
|
||||||
|
class FormEvidenceGrantRequest:
|
||||||
|
"""Request a short-lived, purpose-bound grant from an evidence owner."""
|
||||||
|
|
||||||
|
tenant_id: str
|
||||||
|
instance_id: str
|
||||||
|
definition_ref: InstitutionalReference
|
||||||
|
evidence_kind: str
|
||||||
|
purpose: str
|
||||||
|
idempotency_key: str
|
||||||
|
expires_at: datetime
|
||||||
|
custodian_ref: str | None = None
|
||||||
|
max_size_bytes: int | None = None
|
||||||
|
allowed_content_types: tuple[str, ...] = ()
|
||||||
|
metadata: Mapping[str, object] = field(default_factory=dict)
|
||||||
|
|
||||||
|
def __post_init__(self) -> None:
|
||||||
|
_require_text(self.tenant_id, "Form evidence tenant")
|
||||||
|
_require_text(self.instance_id, "Form evidence instance")
|
||||||
|
_require_text(self.evidence_kind, "Form evidence kind")
|
||||||
|
_require_text(self.purpose, "Form evidence purpose")
|
||||||
|
_require_text(self.idempotency_key, "Form evidence idempotency key")
|
||||||
|
if (
|
||||||
|
self.definition_ref.kind != "form"
|
||||||
|
or self.definition_ref.tenant_id != self.tenant_id
|
||||||
|
or not self.definition_ref.version
|
||||||
|
):
|
||||||
|
raise FormEvidenceContractError(
|
||||||
|
"Form evidence grants require an exact same-tenant Form definition."
|
||||||
|
)
|
||||||
|
if self.expires_at.tzinfo is None or self.expires_at.utcoffset() is None:
|
||||||
|
raise FormEvidenceContractError(
|
||||||
|
"Form evidence grant expiry must include a timezone."
|
||||||
|
)
|
||||||
|
if self.max_size_bytes is not None and self.max_size_bytes <= 0:
|
||||||
|
raise FormEvidenceContractError(
|
||||||
|
"Form evidence grant size limits must be positive."
|
||||||
|
)
|
||||||
|
if any(not item.strip() for item in self.allowed_content_types):
|
||||||
|
raise FormEvidenceContractError(
|
||||||
|
"Form evidence content types cannot be empty."
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass(frozen=True, slots=True)
|
||||||
|
class FormEvidenceGrant:
|
||||||
|
provider_id: str
|
||||||
|
grant_id: str
|
||||||
|
upload_token: str | None
|
||||||
|
upload_url: str
|
||||||
|
expires_at: datetime
|
||||||
|
max_size_bytes: int
|
||||||
|
allowed_content_types: tuple[str, ...] = ()
|
||||||
|
replayed: bool = False
|
||||||
|
|
||||||
|
def __post_init__(self) -> None:
|
||||||
|
for value, label in (
|
||||||
|
(self.provider_id, "Form evidence provider"),
|
||||||
|
(self.grant_id, "Form evidence grant"),
|
||||||
|
(self.upload_url, "Form evidence upload URL"),
|
||||||
|
):
|
||||||
|
_require_text(value, label)
|
||||||
|
if self.upload_token is not None:
|
||||||
|
_require_text(self.upload_token, "Form evidence upload token")
|
||||||
|
if self.max_size_bytes <= 0:
|
||||||
|
raise FormEvidenceContractError(
|
||||||
|
"Form evidence grant size limits must be positive."
|
||||||
|
)
|
||||||
|
if self.expires_at.tzinfo is None or self.expires_at.utcoffset() is None:
|
||||||
|
raise FormEvidenceContractError(
|
||||||
|
"Form evidence grant expiry must include a timezone."
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass(frozen=True, slots=True)
|
||||||
|
class FormEvidenceInspectionRequest:
|
||||||
|
tenant_id: str
|
||||||
|
instance_id: str
|
||||||
|
definition_ref: InstitutionalReference
|
||||||
|
evidence: EvidenceReference
|
||||||
|
purpose: str
|
||||||
|
final: bool
|
||||||
|
|
||||||
|
def __post_init__(self) -> None:
|
||||||
|
_require_text(self.tenant_id, "Form evidence tenant")
|
||||||
|
_require_text(self.instance_id, "Form evidence instance")
|
||||||
|
_require_text(self.purpose, "Form evidence purpose")
|
||||||
|
if self.definition_ref.tenant_id != self.tenant_id:
|
||||||
|
raise FormEvidenceContractError(
|
||||||
|
"Form evidence inspection cannot cross tenants."
|
||||||
|
)
|
||||||
|
if self.evidence.tenant_id != self.tenant_id:
|
||||||
|
raise FormEvidenceContractError(
|
||||||
|
"Form evidence inspection cannot cross tenants."
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass(frozen=True, slots=True)
|
||||||
|
class FormEvidenceInspection:
|
||||||
|
provider_id: str
|
||||||
|
reference: EvidenceReference
|
||||||
|
state: FormEvidenceState
|
||||||
|
observed_at: datetime
|
||||||
|
retryable: bool = False
|
||||||
|
reason: str | None = None
|
||||||
|
metadata: Mapping[str, object] = field(default_factory=dict)
|
||||||
|
|
||||||
|
def __post_init__(self) -> None:
|
||||||
|
_require_text(self.provider_id, "Form evidence provider")
|
||||||
|
if self.state not in _FORM_EVIDENCE_STATES:
|
||||||
|
raise FormEvidenceContractError(
|
||||||
|
f"Unsupported Form evidence state: {self.state!r}."
|
||||||
|
)
|
||||||
|
if self.observed_at.tzinfo is None or self.observed_at.utcoffset() is None:
|
||||||
|
raise FormEvidenceContractError(
|
||||||
|
"Form evidence inspection time must include a timezone."
|
||||||
|
)
|
||||||
|
if self.state == "accepted" and self.retryable:
|
||||||
|
raise FormEvidenceContractError(
|
||||||
|
"Accepted Form evidence cannot require a retry."
|
||||||
|
)
|
||||||
|
|
||||||
|
@property
|
||||||
|
def accepted(self) -> bool:
|
||||||
|
return self.state == "accepted"
|
||||||
|
|
||||||
|
|
||||||
|
@runtime_checkable
|
||||||
|
class FormEvidenceProvider(Protocol):
|
||||||
|
provider_id: str
|
||||||
|
|
||||||
|
def supported_kinds(self) -> Sequence[str]: ...
|
||||||
|
|
||||||
|
def create_upload_grant(
|
||||||
|
self,
|
||||||
|
session: object,
|
||||||
|
principal: object,
|
||||||
|
*,
|
||||||
|
request: FormEvidenceGrantRequest,
|
||||||
|
) -> FormEvidenceGrant: ...
|
||||||
|
|
||||||
|
def inspect_evidence(
|
||||||
|
self,
|
||||||
|
session: object,
|
||||||
|
principal: object,
|
||||||
|
*,
|
||||||
|
request: FormEvidenceInspectionRequest,
|
||||||
|
) -> FormEvidenceInspection: ...
|
||||||
|
|
||||||
|
|
||||||
|
def form_evidence_capability(provider_id: str) -> str:
|
||||||
|
normalized = str(provider_id or "").strip().lower().replace("-", "_")
|
||||||
|
if not normalized or not normalized.replace("_", "").isalnum():
|
||||||
|
raise FormEvidenceContractError("Invalid Form evidence provider id.")
|
||||||
|
return f"{CAPABILITY_FORM_EVIDENCE_PREFIX}{normalized}"
|
||||||
|
|
||||||
|
|
||||||
|
def form_evidence_provider(
|
||||||
|
registry: object | None,
|
||||||
|
provider_id: str,
|
||||||
|
) -> FormEvidenceProvider | None:
|
||||||
|
capability_name = form_evidence_capability(provider_id)
|
||||||
|
if registry is None or not hasattr(registry, "has_capability"):
|
||||||
|
return None
|
||||||
|
if not registry.has_capability(capability_name):
|
||||||
|
return None
|
||||||
|
if hasattr(registry, "require_capability"):
|
||||||
|
provider = registry.require_capability(capability_name)
|
||||||
|
elif hasattr(registry, "capability"):
|
||||||
|
provider = registry.capability(capability_name)
|
||||||
|
else:
|
||||||
|
return None
|
||||||
|
return provider if isinstance(provider, FormEvidenceProvider) else None
|
||||||
|
|
||||||
|
|
||||||
|
def _require_text(value: str, label: str) -> None:
|
||||||
|
if not isinstance(value, str) or not value.strip():
|
||||||
|
raise FormEvidenceContractError(f"{label} is required.")
|
||||||
|
|
||||||
|
|
||||||
|
__all__ = [
|
||||||
|
"CAPABILITY_FORM_EVIDENCE_PREFIX",
|
||||||
|
"FormEvidenceContractError",
|
||||||
|
"FormEvidenceGrant",
|
||||||
|
"FormEvidenceGrantRequest",
|
||||||
|
"FormEvidenceInspection",
|
||||||
|
"FormEvidenceInspectionRequest",
|
||||||
|
"FormEvidenceProvider",
|
||||||
|
"FormEvidenceState",
|
||||||
|
"form_evidence_capability",
|
||||||
|
"form_evidence_provider",
|
||||||
|
]
|
||||||
@@ -0,0 +1,321 @@
|
|||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
from collections.abc import Mapping
|
||||||
|
from dataclasses import dataclass, field
|
||||||
|
from datetime import datetime
|
||||||
|
from typing import Literal, Protocol, runtime_checkable
|
||||||
|
|
||||||
|
|
||||||
|
CAPABILITY_IDENTITY_TRUST_DIRECTORY = "identity_trust.directory"
|
||||||
|
CAPABILITY_IDENTITY_TRUST_ASSURANCE = "identity_trust.assurance"
|
||||||
|
IDENTITY_TRUST_CONTRACT_VERSION = "1"
|
||||||
|
|
||||||
|
DeviceKeyPurpose = Literal["encryption", "signing", "encryption_and_signing"]
|
||||||
|
DeviceKeyStatus = Literal["active", "revoked", "expired"]
|
||||||
|
TrustSubjectKind = Literal[
|
||||||
|
"identity",
|
||||||
|
"account",
|
||||||
|
"function",
|
||||||
|
"postbox",
|
||||||
|
"external_recipient",
|
||||||
|
]
|
||||||
|
|
||||||
|
_PRIVATE_JWK_FIELDS = frozenset({"d", "p", "q", "dp", "dq", "qi", "oth", "k"})
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass(frozen=True, slots=True)
|
||||||
|
class DeviceKeyRegistration:
|
||||||
|
tenant_id: str
|
||||||
|
identity_id: str
|
||||||
|
account_id: str
|
||||||
|
device_id: str
|
||||||
|
key_id: str
|
||||||
|
algorithm: str
|
||||||
|
public_jwk: Mapping[str, object]
|
||||||
|
purpose: DeviceKeyPurpose = "encryption"
|
||||||
|
assurance_level: str = "software"
|
||||||
|
attestation_ref: str | None = None
|
||||||
|
expires_at: datetime | None = None
|
||||||
|
idempotency_key: str = ""
|
||||||
|
contract_version: str = IDENTITY_TRUST_CONTRACT_VERSION
|
||||||
|
|
||||||
|
def __post_init__(self) -> None:
|
||||||
|
_validate_contract(self.contract_version)
|
||||||
|
for label, value in (
|
||||||
|
("tenant id", self.tenant_id),
|
||||||
|
("identity id", self.identity_id),
|
||||||
|
("account id", self.account_id),
|
||||||
|
("device id", self.device_id),
|
||||||
|
("key id", self.key_id),
|
||||||
|
("algorithm", self.algorithm),
|
||||||
|
("idempotency key", self.idempotency_key),
|
||||||
|
):
|
||||||
|
_require_text(value, label)
|
||||||
|
if not self.public_jwk or _PRIVATE_JWK_FIELDS & set(self.public_jwk):
|
||||||
|
raise ValueError("Only a bounded public JWK may be registered")
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass(frozen=True, slots=True)
|
||||||
|
class DeviceKeyRef:
|
||||||
|
tenant_id: str
|
||||||
|
identity_id: str
|
||||||
|
account_id: str
|
||||||
|
device_id: str
|
||||||
|
key_id: str
|
||||||
|
algorithm: str
|
||||||
|
public_jwk: Mapping[str, object]
|
||||||
|
purpose: DeviceKeyPurpose
|
||||||
|
assurance_level: str
|
||||||
|
status: DeviceKeyStatus
|
||||||
|
epoch: int
|
||||||
|
registered_at: datetime
|
||||||
|
attestation_ref: str | None = None
|
||||||
|
expires_at: datetime | None = None
|
||||||
|
revoked_at: datetime | None = None
|
||||||
|
revocation_reason: str | None = None
|
||||||
|
provenance: Mapping[str, object] = field(default_factory=dict)
|
||||||
|
contract_version: str = IDENTITY_TRUST_CONTRACT_VERSION
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass(frozen=True, slots=True)
|
||||||
|
class KeyEpochRotationRequest:
|
||||||
|
tenant_id: str
|
||||||
|
subject_kind: TrustSubjectKind
|
||||||
|
subject_id: str
|
||||||
|
reason: str
|
||||||
|
access_decision_ref: str
|
||||||
|
idempotency_key: str
|
||||||
|
history_policy: str = "all_retained"
|
||||||
|
previous_epoch: int | None = None
|
||||||
|
contract_version: str = IDENTITY_TRUST_CONTRACT_VERSION
|
||||||
|
|
||||||
|
def __post_init__(self) -> None:
|
||||||
|
_validate_contract(self.contract_version)
|
||||||
|
for label, value in (
|
||||||
|
("tenant id", self.tenant_id),
|
||||||
|
("subject id", self.subject_id),
|
||||||
|
("reason", self.reason),
|
||||||
|
("access decision reference", self.access_decision_ref),
|
||||||
|
("idempotency key", self.idempotency_key),
|
||||||
|
):
|
||||||
|
_require_text(value, label)
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass(frozen=True, slots=True)
|
||||||
|
class KeyEpochRef:
|
||||||
|
tenant_id: str
|
||||||
|
subject_kind: TrustSubjectKind
|
||||||
|
subject_id: str
|
||||||
|
epoch: int
|
||||||
|
state: Literal["active", "superseded", "revoked"]
|
||||||
|
history_policy: str
|
||||||
|
effective_at: datetime
|
||||||
|
previous_epoch: int | None = None
|
||||||
|
reason: str | None = None
|
||||||
|
access_decision_ref: str | None = None
|
||||||
|
provenance: Mapping[str, object] = field(default_factory=dict)
|
||||||
|
contract_version: str = IDENTITY_TRUST_CONTRACT_VERSION
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass(frozen=True, slots=True)
|
||||||
|
class KeyAccessRequest:
|
||||||
|
tenant_id: str
|
||||||
|
account_id: str
|
||||||
|
device_key_id: str
|
||||||
|
subject_kind: TrustSubjectKind
|
||||||
|
subject_id: str
|
||||||
|
key_epoch: int
|
||||||
|
access_decision_ref: str
|
||||||
|
purpose: str
|
||||||
|
requested_at: datetime
|
||||||
|
function_assignment_id: str | None = None
|
||||||
|
delegation_id: str | None = None
|
||||||
|
resource_ref: str | None = None
|
||||||
|
contract_version: str = IDENTITY_TRUST_CONTRACT_VERSION
|
||||||
|
|
||||||
|
def __post_init__(self) -> None:
|
||||||
|
_validate_contract(self.contract_version)
|
||||||
|
if self.key_epoch < 1:
|
||||||
|
raise ValueError("Key epoch must be positive")
|
||||||
|
for label, value in (
|
||||||
|
("tenant id", self.tenant_id),
|
||||||
|
("account id", self.account_id),
|
||||||
|
("device key id", self.device_key_id),
|
||||||
|
("subject id", self.subject_id),
|
||||||
|
("access decision reference", self.access_decision_ref),
|
||||||
|
("purpose", self.purpose),
|
||||||
|
):
|
||||||
|
_require_text(value, label)
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass(frozen=True, slots=True)
|
||||||
|
class KeyAccessDecision:
|
||||||
|
allowed: bool
|
||||||
|
decision_ref: str
|
||||||
|
reason: str
|
||||||
|
device_key: DeviceKeyRef | None = None
|
||||||
|
epoch: KeyEpochRef | None = None
|
||||||
|
audit_event_ref: str | None = None
|
||||||
|
requirements: tuple[str, ...] = ()
|
||||||
|
provenance: Mapping[str, object] = field(default_factory=dict)
|
||||||
|
contract_version: str = IDENTITY_TRUST_CONTRACT_VERSION
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass(frozen=True, slots=True)
|
||||||
|
class AssuranceCheckRequest:
|
||||||
|
tenant_id: str
|
||||||
|
account_id: str
|
||||||
|
purpose: str
|
||||||
|
minimum_level: str
|
||||||
|
evidence_ref: str
|
||||||
|
evaluated_at: datetime
|
||||||
|
maximum_age_seconds: int = 300
|
||||||
|
device_key_id: str | None = None
|
||||||
|
contract_version: str = IDENTITY_TRUST_CONTRACT_VERSION
|
||||||
|
|
||||||
|
def __post_init__(self) -> None:
|
||||||
|
_validate_contract(self.contract_version)
|
||||||
|
if self.maximum_age_seconds < 1:
|
||||||
|
raise ValueError("Assurance maximum age must be positive")
|
||||||
|
for label, value in (
|
||||||
|
("tenant id", self.tenant_id),
|
||||||
|
("account id", self.account_id),
|
||||||
|
("purpose", self.purpose),
|
||||||
|
("minimum level", self.minimum_level),
|
||||||
|
("evidence reference", self.evidence_ref),
|
||||||
|
):
|
||||||
|
_require_text(value, label)
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass(frozen=True, slots=True)
|
||||||
|
class AssuranceDecision:
|
||||||
|
allowed: bool
|
||||||
|
reason: str
|
||||||
|
assurance_level: str | None = None
|
||||||
|
evidence_ref: str | None = None
|
||||||
|
verified_at: datetime | None = None
|
||||||
|
expires_at: datetime | None = None
|
||||||
|
provenance: Mapping[str, object] = field(default_factory=dict)
|
||||||
|
contract_version: str = IDENTITY_TRUST_CONTRACT_VERSION
|
||||||
|
|
||||||
|
|
||||||
|
@runtime_checkable
|
||||||
|
class IdentityTrustDirectory(Protocol):
|
||||||
|
def register_device_key(
|
||||||
|
self,
|
||||||
|
session: object,
|
||||||
|
principal: object,
|
||||||
|
*,
|
||||||
|
request: DeviceKeyRegistration,
|
||||||
|
) -> DeviceKeyRef: ...
|
||||||
|
|
||||||
|
def revoke_device_key(
|
||||||
|
self,
|
||||||
|
session: object,
|
||||||
|
principal: object,
|
||||||
|
*,
|
||||||
|
tenant_id: str,
|
||||||
|
key_id: str,
|
||||||
|
expected_epoch: int,
|
||||||
|
reason: str,
|
||||||
|
) -> DeviceKeyRef: ...
|
||||||
|
|
||||||
|
def list_device_keys(
|
||||||
|
self,
|
||||||
|
session: object,
|
||||||
|
principal: object,
|
||||||
|
*,
|
||||||
|
tenant_id: str,
|
||||||
|
account_id: str,
|
||||||
|
active_only: bool = True,
|
||||||
|
) -> tuple[DeviceKeyRef, ...]: ...
|
||||||
|
|
||||||
|
def rotate_epoch(
|
||||||
|
self,
|
||||||
|
session: object,
|
||||||
|
principal: object,
|
||||||
|
*,
|
||||||
|
request: KeyEpochRotationRequest,
|
||||||
|
) -> KeyEpochRef: ...
|
||||||
|
|
||||||
|
def resolve_epoch(
|
||||||
|
self,
|
||||||
|
session: object,
|
||||||
|
*,
|
||||||
|
tenant_id: str,
|
||||||
|
subject_kind: TrustSubjectKind,
|
||||||
|
subject_id: str,
|
||||||
|
epoch: int | None = None,
|
||||||
|
) -> KeyEpochRef | None: ...
|
||||||
|
|
||||||
|
def decide_key_access(
|
||||||
|
self,
|
||||||
|
session: object,
|
||||||
|
principal: object,
|
||||||
|
*,
|
||||||
|
request: KeyAccessRequest,
|
||||||
|
) -> KeyAccessDecision: ...
|
||||||
|
|
||||||
|
|
||||||
|
@runtime_checkable
|
||||||
|
class IdentityTrustAssurance(Protocol):
|
||||||
|
def verify_assurance(
|
||||||
|
self,
|
||||||
|
session: object,
|
||||||
|
principal: object,
|
||||||
|
*,
|
||||||
|
request: AssuranceCheckRequest,
|
||||||
|
) -> AssuranceDecision: ...
|
||||||
|
|
||||||
|
|
||||||
|
def identity_trust_directory(
|
||||||
|
registry: object | None,
|
||||||
|
) -> IdentityTrustDirectory | None:
|
||||||
|
capability = _capability(registry, CAPABILITY_IDENTITY_TRUST_DIRECTORY)
|
||||||
|
return capability if isinstance(capability, IdentityTrustDirectory) else None
|
||||||
|
|
||||||
|
|
||||||
|
def identity_trust_assurance(
|
||||||
|
registry: object | None,
|
||||||
|
) -> IdentityTrustAssurance | None:
|
||||||
|
capability = _capability(registry, CAPABILITY_IDENTITY_TRUST_ASSURANCE)
|
||||||
|
return capability if isinstance(capability, IdentityTrustAssurance) else None
|
||||||
|
|
||||||
|
|
||||||
|
def _capability(registry: object | None, name: str) -> object | None:
|
||||||
|
if (
|
||||||
|
registry is None
|
||||||
|
or not hasattr(registry, "has_capability")
|
||||||
|
or not hasattr(registry, "capability")
|
||||||
|
or not registry.has_capability(name)
|
||||||
|
):
|
||||||
|
return None
|
||||||
|
return registry.capability(name)
|
||||||
|
|
||||||
|
|
||||||
|
def _validate_contract(value: str) -> None:
|
||||||
|
if value != IDENTITY_TRUST_CONTRACT_VERSION:
|
||||||
|
raise ValueError("Unsupported identity-trust contract version")
|
||||||
|
|
||||||
|
|
||||||
|
def _require_text(value: str, label: str) -> None:
|
||||||
|
if not value.strip():
|
||||||
|
raise ValueError(f"{label.capitalize()} is required")
|
||||||
|
|
||||||
|
|
||||||
|
__all__ = [
|
||||||
|
"AssuranceCheckRequest",
|
||||||
|
"AssuranceDecision",
|
||||||
|
"CAPABILITY_IDENTITY_TRUST_ASSURANCE",
|
||||||
|
"CAPABILITY_IDENTITY_TRUST_DIRECTORY",
|
||||||
|
"DeviceKeyRef",
|
||||||
|
"DeviceKeyRegistration",
|
||||||
|
"IdentityTrustAssurance",
|
||||||
|
"IdentityTrustDirectory",
|
||||||
|
"KeyAccessDecision",
|
||||||
|
"KeyAccessRequest",
|
||||||
|
"KeyEpochRef",
|
||||||
|
"KeyEpochRotationRequest",
|
||||||
|
"identity_trust_assurance",
|
||||||
|
"identity_trust_directory",
|
||||||
|
]
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
from collections.abc import Mapping, Sequence
|
from collections.abc import Mapping, Sequence
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass, field
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from typing import Literal, Protocol, runtime_checkable
|
from typing import Literal, Protocol, runtime_checkable
|
||||||
|
|
||||||
@@ -10,9 +10,12 @@ IDM_MODULE_ID = "idm"
|
|||||||
CAPABILITY_IDM_DIRECTORY = "idm.directory"
|
CAPABILITY_IDM_DIRECTORY = "idm.directory"
|
||||||
CAPABILITY_IDM_FUNCTION_ASSIGNMENTS = "idm.function_assignments"
|
CAPABILITY_IDM_FUNCTION_ASSIGNMENTS = "idm.function_assignments"
|
||||||
CAPABILITY_IDM_ASSIGNMENT_LIFECYCLE = "idm.assignment_lifecycle"
|
CAPABILITY_IDM_ASSIGNMENT_LIFECYCLE = "idm.assignment_lifecycle"
|
||||||
|
CAPABILITY_IDM_RELATIONSHIPS = "idm.relationships"
|
||||||
|
|
||||||
IdmStatus = Literal["active", "inactive", "suspended"]
|
IdmStatus = Literal["active", "inactive", "suspended"]
|
||||||
OrganizationFunctionAssignmentSource = Literal["direct", "delegated", "acting_for", "directory", "governance", "system"]
|
OrganizationFunctionAssignmentSource = Literal["direct", "delegated", "acting_for", "directory", "governance", "system"]
|
||||||
|
TypedGroupStatus = Literal["active", "inactive"]
|
||||||
|
IdentityRelationshipStatus = Literal["active", "revoked"]
|
||||||
|
|
||||||
|
|
||||||
@dataclass(frozen=True, slots=True)
|
@dataclass(frozen=True, slots=True)
|
||||||
@@ -44,6 +47,78 @@ class OrganizationFunctionIncumbencyRef:
|
|||||||
return not self.assignments
|
return not self.assignments
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass(frozen=True, slots=True)
|
||||||
|
class TypedGroupRef:
|
||||||
|
"""Provider-neutral IDM group fact scoped to one tenant."""
|
||||||
|
|
||||||
|
id: str
|
||||||
|
tenant_id: str
|
||||||
|
key: str
|
||||||
|
name: str
|
||||||
|
group_type: str
|
||||||
|
description: str | None = None
|
||||||
|
status: TypedGroupStatus = "active"
|
||||||
|
source_provider: str = "local"
|
||||||
|
source_resource_type: str | None = None
|
||||||
|
source_resource_id: str | None = None
|
||||||
|
source_revision: str | None = None
|
||||||
|
properties: Mapping[str, object] = field(default_factory=dict)
|
||||||
|
provenance: Mapping[str, object] = field(default_factory=dict)
|
||||||
|
revision: int = 1
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass(frozen=True, slots=True)
|
||||||
|
class IdentityRelationshipRef:
|
||||||
|
"""An effective-dated relationship from an identity to a typed target."""
|
||||||
|
|
||||||
|
id: str
|
||||||
|
tenant_id: str
|
||||||
|
relationship_kind: str
|
||||||
|
subject_identity_id: str
|
||||||
|
target_group_id: str | None = None
|
||||||
|
related_identity_id: str | None = None
|
||||||
|
role: str | None = None
|
||||||
|
valid_from: datetime | None = None
|
||||||
|
valid_until: datetime | None = None
|
||||||
|
status: IdentityRelationshipStatus = "active"
|
||||||
|
revoked_at: datetime | None = None
|
||||||
|
revoked_by: str | None = None
|
||||||
|
revocation_reason: str | None = None
|
||||||
|
source_provider: str = "local"
|
||||||
|
source_resource_type: str | None = None
|
||||||
|
source_resource_id: str | None = None
|
||||||
|
source_revision: str | None = None
|
||||||
|
properties: Mapping[str, object] = field(default_factory=dict)
|
||||||
|
provenance: Mapping[str, object] = field(default_factory=dict)
|
||||||
|
revision: int = 1
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass(frozen=True, slots=True)
|
||||||
|
class IdentityRelationshipDecisionRef:
|
||||||
|
relationship: IdentityRelationshipRef
|
||||||
|
included: bool
|
||||||
|
code: str
|
||||||
|
explanation: str
|
||||||
|
identity_status: IdmStatus | None = None
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass(frozen=True, slots=True)
|
||||||
|
class TypedGroupMembershipResolutionRef:
|
||||||
|
group: TypedGroupRef
|
||||||
|
effective_at: datetime
|
||||||
|
decisions: tuple[IdentityRelationshipDecisionRef, ...] = ()
|
||||||
|
|
||||||
|
@property
|
||||||
|
def identity_ids(self) -> tuple[str, ...]:
|
||||||
|
return tuple(
|
||||||
|
dict.fromkeys(
|
||||||
|
item.relationship.subject_identity_id
|
||||||
|
for item in self.decisions
|
||||||
|
if item.included
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
@runtime_checkable
|
@runtime_checkable
|
||||||
class IdmDirectory(Protocol):
|
class IdmDirectory(Protocol):
|
||||||
def get_organization_function_assignment(self, assignment_id: str) -> OrganizationFunctionAssignmentRef | None:
|
def get_organization_function_assignment(self, assignment_id: str) -> OrganizationFunctionAssignmentRef | None:
|
||||||
@@ -109,6 +184,79 @@ class IdmFunctionAssignmentDirectory(Protocol):
|
|||||||
...
|
...
|
||||||
|
|
||||||
|
|
||||||
|
@runtime_checkable
|
||||||
|
class IdmRelationshipDirectory(Protocol):
|
||||||
|
"""Tenant-safe forward/reverse lookup for typed IDM relationships."""
|
||||||
|
|
||||||
|
def get_typed_group(
|
||||||
|
self,
|
||||||
|
group_id: str,
|
||||||
|
*,
|
||||||
|
tenant_id: str | None = None,
|
||||||
|
) -> TypedGroupRef | None:
|
||||||
|
...
|
||||||
|
|
||||||
|
def list_typed_groups(
|
||||||
|
self,
|
||||||
|
*,
|
||||||
|
tenant_id: str,
|
||||||
|
query: str | None = None,
|
||||||
|
group_types: Sequence[str] = (),
|
||||||
|
include_inactive: bool = False,
|
||||||
|
limit: int = 100,
|
||||||
|
) -> Sequence[TypedGroupRef]:
|
||||||
|
...
|
||||||
|
|
||||||
|
def identity_relationships_for_identity(
|
||||||
|
self,
|
||||||
|
identity_id: str,
|
||||||
|
*,
|
||||||
|
tenant_id: str,
|
||||||
|
effective_at: datetime | None = None,
|
||||||
|
relationship_kinds: Sequence[str] = (),
|
||||||
|
) -> Sequence[IdentityRelationshipRef]:
|
||||||
|
...
|
||||||
|
|
||||||
|
def identity_relationships_for_identities(
|
||||||
|
self,
|
||||||
|
identity_ids: Sequence[str],
|
||||||
|
*,
|
||||||
|
tenant_id: str,
|
||||||
|
effective_at: datetime | None = None,
|
||||||
|
relationship_kinds: Sequence[str] = (),
|
||||||
|
) -> Mapping[str, Sequence[IdentityRelationshipRef]]:
|
||||||
|
...
|
||||||
|
|
||||||
|
def identity_relationships_for_group(
|
||||||
|
self,
|
||||||
|
group_id: str,
|
||||||
|
*,
|
||||||
|
tenant_id: str,
|
||||||
|
effective_at: datetime | None = None,
|
||||||
|
relationship_kinds: Sequence[str] = (),
|
||||||
|
) -> Sequence[IdentityRelationshipRef]:
|
||||||
|
...
|
||||||
|
|
||||||
|
def identity_relationships_for_groups(
|
||||||
|
self,
|
||||||
|
group_ids: Sequence[str],
|
||||||
|
*,
|
||||||
|
tenant_id: str,
|
||||||
|
effective_at: datetime | None = None,
|
||||||
|
relationship_kinds: Sequence[str] = (),
|
||||||
|
) -> Mapping[str, Sequence[IdentityRelationshipRef]]:
|
||||||
|
...
|
||||||
|
|
||||||
|
def resolve_typed_group_memberships(
|
||||||
|
self,
|
||||||
|
group_ids: Sequence[str],
|
||||||
|
*,
|
||||||
|
tenant_id: str,
|
||||||
|
effective_at: datetime | None = None,
|
||||||
|
relationship_kinds: Sequence[str] = ("member",),
|
||||||
|
) -> Mapping[str, TypedGroupMembershipResolutionRef]:
|
||||||
|
...
|
||||||
|
|
||||||
@runtime_checkable
|
@runtime_checkable
|
||||||
class IdmAssignmentLifecycle(Protocol):
|
class IdmAssignmentLifecycle(Protocol):
|
||||||
"""Worker boundary for time-driven function-assignment transitions."""
|
"""Worker boundary for time-driven function-assignment transitions."""
|
||||||
|
|||||||
@@ -0,0 +1,236 @@
|
|||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
from dataclasses import dataclass, field
|
||||||
|
from typing import Literal, Mapping, cast
|
||||||
|
|
||||||
|
|
||||||
|
InformationGovernanceAdoption = Literal[
|
||||||
|
"not_applicable",
|
||||||
|
"contract_only",
|
||||||
|
"partial",
|
||||||
|
"enforced",
|
||||||
|
]
|
||||||
|
|
||||||
|
INFORMATION_GOVERNANCE_ADOPTION_ORDER: tuple[InformationGovernanceAdoption, ...] = (
|
||||||
|
"not_applicable",
|
||||||
|
"contract_only",
|
||||||
|
"partial",
|
||||||
|
"enforced",
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
class InformationGovernanceDeclarationError(ValueError):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass(frozen=True, slots=True)
|
||||||
|
class InformationGovernanceDimension:
|
||||||
|
"""Truthful module-level adoption claim for one cross-cutting dimension."""
|
||||||
|
|
||||||
|
adoption: InformationGovernanceAdoption = "contract_only"
|
||||||
|
object_types: tuple[str, ...] = ()
|
||||||
|
evidence: tuple[str, ...] = ()
|
||||||
|
limitation: str | None = None
|
||||||
|
|
||||||
|
def __post_init__(self) -> None:
|
||||||
|
if self.adoption not in INFORMATION_GOVERNANCE_ADOPTION_ORDER:
|
||||||
|
raise InformationGovernanceDeclarationError(
|
||||||
|
f"Unsupported information-governance adoption: {self.adoption!r}."
|
||||||
|
)
|
||||||
|
for field_name in ("object_types", "evidence"):
|
||||||
|
values = getattr(self, field_name)
|
||||||
|
if len(values) != len(set(values)) or any(not item.strip() for item in values):
|
||||||
|
raise InformationGovernanceDeclarationError(
|
||||||
|
f"Information-governance {field_name.replace('_', ' ')} must "
|
||||||
|
"contain unique non-empty values."
|
||||||
|
)
|
||||||
|
if self.adoption == "enforced" and not self.evidence:
|
||||||
|
raise InformationGovernanceDeclarationError(
|
||||||
|
"An enforced information-governance dimension requires evidence."
|
||||||
|
)
|
||||||
|
if self.adoption in {"partial", "enforced"} and not self.object_types:
|
||||||
|
raise InformationGovernanceDeclarationError(
|
||||||
|
"Partial and enforced information-governance dimensions must "
|
||||||
|
"name their covered object types."
|
||||||
|
)
|
||||||
|
if self.adoption == "not_applicable" and self.object_types:
|
||||||
|
raise InformationGovernanceDeclarationError(
|
||||||
|
"A non-applicable information-governance dimension cannot declare object types."
|
||||||
|
)
|
||||||
|
if self.adoption in {"contract_only", "partial"} and not str(
|
||||||
|
self.limitation or ""
|
||||||
|
).strip():
|
||||||
|
raise InformationGovernanceDeclarationError(
|
||||||
|
"Contract-only and partial adoption must state the current limitation."
|
||||||
|
)
|
||||||
|
|
||||||
|
def to_dict(self) -> dict[str, object]:
|
||||||
|
return {
|
||||||
|
"adoption": self.adoption,
|
||||||
|
"object_types": list(self.object_types),
|
||||||
|
"evidence": list(self.evidence),
|
||||||
|
"limitation": self.limitation,
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
def _contract_only_dimension() -> InformationGovernanceDimension:
|
||||||
|
return InformationGovernanceDimension(
|
||||||
|
adoption="contract_only",
|
||||||
|
limitation=(
|
||||||
|
"The platform contract applies, but module-specific adoption evidence "
|
||||||
|
"has not been declared."
|
||||||
|
),
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass(frozen=True, slots=True)
|
||||||
|
class ModuleInformationGovernance:
|
||||||
|
"""Cross-cutting data-use requirements and honest adoption evidence."""
|
||||||
|
|
||||||
|
temporal_browsing: InformationGovernanceDimension = field(
|
||||||
|
default_factory=_contract_only_dimension
|
||||||
|
)
|
||||||
|
purpose_aware_access: InformationGovernanceDimension = field(
|
||||||
|
default_factory=_contract_only_dimension
|
||||||
|
)
|
||||||
|
retention: InformationGovernanceDimension = field(
|
||||||
|
default_factory=_contract_only_dimension
|
||||||
|
)
|
||||||
|
institutional_context: InformationGovernanceDimension = field(
|
||||||
|
default_factory=_contract_only_dimension
|
||||||
|
)
|
||||||
|
current_authorization_for_historical_reads: bool = True
|
||||||
|
contract_version: str = "1"
|
||||||
|
|
||||||
|
def __post_init__(self) -> None:
|
||||||
|
if self.contract_version != "1":
|
||||||
|
raise InformationGovernanceDeclarationError(
|
||||||
|
"Unsupported module information-governance contract version."
|
||||||
|
)
|
||||||
|
if not self.current_authorization_for_historical_reads:
|
||||||
|
raise InformationGovernanceDeclarationError(
|
||||||
|
"Historical reads must always use current authorization."
|
||||||
|
)
|
||||||
|
for name, dimension in self.dimensions.items():
|
||||||
|
if not isinstance(dimension, InformationGovernanceDimension):
|
||||||
|
raise InformationGovernanceDeclarationError(
|
||||||
|
f"Information-governance dimension {name!r} has an invalid value."
|
||||||
|
)
|
||||||
|
|
||||||
|
@property
|
||||||
|
def dimensions(self) -> Mapping[str, InformationGovernanceDimension]:
|
||||||
|
return {
|
||||||
|
"temporal_browsing": self.temporal_browsing,
|
||||||
|
"purpose_aware_access": self.purpose_aware_access,
|
||||||
|
"retention": self.retention,
|
||||||
|
"institutional_context": self.institutional_context,
|
||||||
|
}
|
||||||
|
|
||||||
|
def to_dict(self) -> dict[str, object]:
|
||||||
|
return {
|
||||||
|
"contract_version": self.contract_version,
|
||||||
|
"current_authorization_for_historical_reads": (
|
||||||
|
self.current_authorization_for_historical_reads
|
||||||
|
),
|
||||||
|
"dimensions": {
|
||||||
|
name: dimension.to_dict()
|
||||||
|
for name, dimension in self.dimensions.items()
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
def information_governance_from_mapping(
|
||||||
|
value: Mapping[str, object],
|
||||||
|
) -> ModuleInformationGovernance:
|
||||||
|
raw_dimensions = value.get("dimensions")
|
||||||
|
if not isinstance(raw_dimensions, Mapping):
|
||||||
|
raise InformationGovernanceDeclarationError(
|
||||||
|
"Information-governance dimensions must be an object."
|
||||||
|
)
|
||||||
|
|
||||||
|
def dimension(name: str) -> InformationGovernanceDimension:
|
||||||
|
raw_dimension = raw_dimensions.get(name)
|
||||||
|
if not isinstance(raw_dimension, Mapping):
|
||||||
|
raise InformationGovernanceDeclarationError(
|
||||||
|
f"Information-governance dimension {name!r} must be an object."
|
||||||
|
)
|
||||||
|
|
||||||
|
def text_tuple(field_name: str) -> tuple[str, ...]:
|
||||||
|
raw_values = raw_dimension.get(field_name, ())
|
||||||
|
if not isinstance(raw_values, (list, tuple)):
|
||||||
|
raise InformationGovernanceDeclarationError(
|
||||||
|
f"Information-governance {name}.{field_name} must be a list."
|
||||||
|
)
|
||||||
|
if any(not isinstance(item, str) for item in raw_values):
|
||||||
|
raise InformationGovernanceDeclarationError(
|
||||||
|
f"Information-governance {name}.{field_name} must contain strings."
|
||||||
|
)
|
||||||
|
return tuple(raw_values)
|
||||||
|
|
||||||
|
raw_limitation = raw_dimension.get("limitation")
|
||||||
|
raw_adoption = raw_dimension.get("adoption") or "contract_only"
|
||||||
|
if not isinstance(raw_adoption, str):
|
||||||
|
raise InformationGovernanceDeclarationError(
|
||||||
|
f"Information-governance {name}.adoption must be a string."
|
||||||
|
)
|
||||||
|
if raw_limitation is not None and not isinstance(raw_limitation, str):
|
||||||
|
raise InformationGovernanceDeclarationError(
|
||||||
|
f"Information-governance {name}.limitation must be a string."
|
||||||
|
)
|
||||||
|
return InformationGovernanceDimension(
|
||||||
|
adoption=cast(
|
||||||
|
InformationGovernanceAdoption,
|
||||||
|
raw_adoption,
|
||||||
|
),
|
||||||
|
object_types=text_tuple("object_types"),
|
||||||
|
evidence=text_tuple("evidence"),
|
||||||
|
limitation=raw_limitation,
|
||||||
|
)
|
||||||
|
|
||||||
|
current_authorization = value.get(
|
||||||
|
"current_authorization_for_historical_reads",
|
||||||
|
True,
|
||||||
|
)
|
||||||
|
if not isinstance(current_authorization, bool):
|
||||||
|
raise InformationGovernanceDeclarationError(
|
||||||
|
"current_authorization_for_historical_reads must be boolean."
|
||||||
|
)
|
||||||
|
return ModuleInformationGovernance(
|
||||||
|
contract_version=str(value.get("contract_version") or "1"),
|
||||||
|
current_authorization_for_historical_reads=current_authorization,
|
||||||
|
temporal_browsing=dimension("temporal_browsing"),
|
||||||
|
purpose_aware_access=dimension("purpose_aware_access"),
|
||||||
|
retention=dimension("retention"),
|
||||||
|
institutional_context=dimension("institutional_context"),
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def information_governance_maturity_issues(
|
||||||
|
declaration: ModuleInformationGovernance,
|
||||||
|
*,
|
||||||
|
maturity: str | None,
|
||||||
|
) -> tuple[str, ...]:
|
||||||
|
if maturity not in {"reference_ready", "supported", "lts"}:
|
||||||
|
return ()
|
||||||
|
incomplete = [
|
||||||
|
name
|
||||||
|
for name, dimension in declaration.dimensions.items()
|
||||||
|
if dimension.adoption not in {"not_applicable", "enforced"}
|
||||||
|
]
|
||||||
|
if not incomplete:
|
||||||
|
return ()
|
||||||
|
return (
|
||||||
|
f"Maturity {maturity!r} requires enforced or explicitly non-applicable "
|
||||||
|
"information governance for: " + ", ".join(incomplete),
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
__all__ = [
|
||||||
|
"INFORMATION_GOVERNANCE_ADOPTION_ORDER",
|
||||||
|
"InformationGovernanceAdoption",
|
||||||
|
"InformationGovernanceDeclarationError",
|
||||||
|
"InformationGovernanceDimension",
|
||||||
|
"ModuleInformationGovernance",
|
||||||
|
"information_governance_from_mapping",
|
||||||
|
"information_governance_maturity_issues",
|
||||||
|
]
|
||||||
@@ -0,0 +1,363 @@
|
|||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
from collections.abc import Mapping
|
||||||
|
from dataclasses import dataclass
|
||||||
|
import json
|
||||||
|
import os
|
||||||
|
from pathlib import Path
|
||||||
|
import re
|
||||||
|
from typing import Any
|
||||||
|
|
||||||
|
|
||||||
|
DEPLOYMENT_CAPABILITIES_ENV = "GOVOPLAN_DEPLOYMENT_CAPABILITIES_PATH"
|
||||||
|
MAX_CAPABILITY_DOCUMENT_BYTES = 256 * 1024
|
||||||
|
CAPABILITY_STATES = frozenset(
|
||||||
|
{
|
||||||
|
"configured",
|
||||||
|
"available_unconfigured",
|
||||||
|
"externally_supplied",
|
||||||
|
"unavailable",
|
||||||
|
}
|
||||||
|
)
|
||||||
|
_ENV_REFERENCE_RE = re.compile(r"^env:[A-Za-z_][A-Za-z0-9_]*$")
|
||||||
|
|
||||||
|
|
||||||
|
class InfrastructureCapabilityReceiptError(ValueError):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass(frozen=True, slots=True)
|
||||||
|
class InfrastructureCapability:
|
||||||
|
id: str
|
||||||
|
label: str
|
||||||
|
state: str
|
||||||
|
source: str
|
||||||
|
detail: str
|
||||||
|
endpoint: Mapping[str, object]
|
||||||
|
secret_refs: tuple[str, ...]
|
||||||
|
dependent_modules: tuple[str, ...]
|
||||||
|
|
||||||
|
def to_dict(self) -> dict[str, object]:
|
||||||
|
return {
|
||||||
|
"id": self.id,
|
||||||
|
"label": self.label,
|
||||||
|
"state": self.state,
|
||||||
|
"source": self.source,
|
||||||
|
"detail": self.detail,
|
||||||
|
"endpoint": dict(self.endpoint),
|
||||||
|
"secret_refs": list(self.secret_refs),
|
||||||
|
"dependent_modules": list(self.dependent_modules),
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass(frozen=True, slots=True)
|
||||||
|
class InfrastructurePostInstallTask:
|
||||||
|
id: str
|
||||||
|
resume_key: str
|
||||||
|
capability_id: str
|
||||||
|
state: str
|
||||||
|
owner_module: str
|
||||||
|
summary: str
|
||||||
|
required_inputs: tuple[str, ...]
|
||||||
|
secret_boundary: str
|
||||||
|
|
||||||
|
def to_dict(self) -> dict[str, object]:
|
||||||
|
return {
|
||||||
|
"id": self.id,
|
||||||
|
"resume_key": self.resume_key,
|
||||||
|
"capability_id": self.capability_id,
|
||||||
|
"state": self.state,
|
||||||
|
"owner_module": self.owner_module,
|
||||||
|
"summary": self.summary,
|
||||||
|
"required_inputs": list(self.required_inputs),
|
||||||
|
"secret_boundary": self.secret_boundary,
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass(frozen=True, slots=True)
|
||||||
|
class InfrastructureCapabilityReceipt:
|
||||||
|
installation_id: str
|
||||||
|
profile: str
|
||||||
|
capabilities: tuple[InfrastructureCapability, ...]
|
||||||
|
post_install_tasks: tuple[InfrastructurePostInstallTask, ...]
|
||||||
|
schema_version: int = 1
|
||||||
|
|
||||||
|
def capability(self, capability_id: str) -> InfrastructureCapability | None:
|
||||||
|
return next(
|
||||||
|
(item for item in self.capabilities if item.id == capability_id),
|
||||||
|
None,
|
||||||
|
)
|
||||||
|
|
||||||
|
def tasks_for(
|
||||||
|
self,
|
||||||
|
*,
|
||||||
|
capability_id: str | None = None,
|
||||||
|
owner_module: str | None = None,
|
||||||
|
) -> tuple[InfrastructurePostInstallTask, ...]:
|
||||||
|
return tuple(
|
||||||
|
item
|
||||||
|
for item in self.post_install_tasks
|
||||||
|
if (capability_id is None or item.capability_id == capability_id)
|
||||||
|
and (owner_module is None or item.owner_module == owner_module)
|
||||||
|
)
|
||||||
|
|
||||||
|
def to_dict(self) -> dict[str, object]:
|
||||||
|
return {
|
||||||
|
"schema_version": self.schema_version,
|
||||||
|
"installation_id": self.installation_id,
|
||||||
|
"profile": self.profile,
|
||||||
|
"capabilities": [item.to_dict() for item in self.capabilities],
|
||||||
|
"post_install_tasks": [
|
||||||
|
item.to_dict() for item in self.post_install_tasks
|
||||||
|
],
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
def load_infrastructure_capability_receipt(
|
||||||
|
path: Path | str | None = None,
|
||||||
|
) -> InfrastructureCapabilityReceipt | None:
|
||||||
|
configured_path = path
|
||||||
|
if configured_path is None:
|
||||||
|
raw_path = os.getenv(DEPLOYMENT_CAPABILITIES_ENV, "").strip()
|
||||||
|
if not raw_path:
|
||||||
|
return None
|
||||||
|
configured_path = raw_path
|
||||||
|
return read_infrastructure_capability_receipt(Path(configured_path))
|
||||||
|
|
||||||
|
|
||||||
|
def read_infrastructure_capability_receipt(
|
||||||
|
path: Path,
|
||||||
|
) -> InfrastructureCapabilityReceipt:
|
||||||
|
if path.is_symlink() or not path.is_file():
|
||||||
|
raise InfrastructureCapabilityReceiptError(
|
||||||
|
"Deployment capability receipt is not a regular file."
|
||||||
|
)
|
||||||
|
try:
|
||||||
|
expected_size = path.stat().st_size
|
||||||
|
if expected_size > MAX_CAPABILITY_DOCUMENT_BYTES:
|
||||||
|
raise InfrastructureCapabilityReceiptError(
|
||||||
|
"Deployment capability receipt exceeds 256 KiB."
|
||||||
|
)
|
||||||
|
raw = path.read_bytes()
|
||||||
|
except OSError as exc:
|
||||||
|
raise InfrastructureCapabilityReceiptError(
|
||||||
|
"Deployment capability receipt could not be read."
|
||||||
|
) from exc
|
||||||
|
if len(raw) != expected_size:
|
||||||
|
raise InfrastructureCapabilityReceiptError(
|
||||||
|
"Deployment capability receipt changed while being read."
|
||||||
|
)
|
||||||
|
try:
|
||||||
|
payload = json.loads(raw.decode("utf-8"))
|
||||||
|
except (UnicodeDecodeError, json.JSONDecodeError) as exc:
|
||||||
|
raise InfrastructureCapabilityReceiptError(
|
||||||
|
"Deployment capability receipt is not valid UTF-8 JSON."
|
||||||
|
) from exc
|
||||||
|
return infrastructure_capability_receipt_from_mapping(payload)
|
||||||
|
|
||||||
|
|
||||||
|
def infrastructure_capability_receipt_from_mapping(
|
||||||
|
payload: object,
|
||||||
|
) -> InfrastructureCapabilityReceipt:
|
||||||
|
if (
|
||||||
|
not isinstance(payload, Mapping)
|
||||||
|
or type(payload.get("schema_version")) is not int
|
||||||
|
or payload.get("schema_version") != 1
|
||||||
|
):
|
||||||
|
raise InfrastructureCapabilityReceiptError(
|
||||||
|
"Deployment capability receipt has an unsupported schema."
|
||||||
|
)
|
||||||
|
raw_capabilities = payload.get("capabilities")
|
||||||
|
if not isinstance(raw_capabilities, list) or len(raw_capabilities) > 100:
|
||||||
|
raise InfrastructureCapabilityReceiptError(
|
||||||
|
"Deployment capability receipt has invalid capabilities."
|
||||||
|
)
|
||||||
|
capabilities = tuple(_capability(item) for item in raw_capabilities)
|
||||||
|
capability_ids = [item.id for item in capabilities]
|
||||||
|
if len(capability_ids) != len(set(capability_ids)):
|
||||||
|
raise InfrastructureCapabilityReceiptError(
|
||||||
|
"Deployment capability receipt repeats a capability id."
|
||||||
|
)
|
||||||
|
raw_tasks = payload.get("post_install_tasks", [])
|
||||||
|
if not isinstance(raw_tasks, list) or len(raw_tasks) > 100:
|
||||||
|
raise InfrastructureCapabilityReceiptError(
|
||||||
|
"Deployment capability receipt has invalid post-install tasks."
|
||||||
|
)
|
||||||
|
tasks = tuple(_task(item) for item in raw_tasks)
|
||||||
|
known_capability_ids = set(capability_ids)
|
||||||
|
if any(item.capability_id not in known_capability_ids for item in tasks):
|
||||||
|
raise InfrastructureCapabilityReceiptError(
|
||||||
|
"Deployment post-install task references an unknown capability."
|
||||||
|
)
|
||||||
|
return InfrastructureCapabilityReceipt(
|
||||||
|
installation_id=_required_text(payload, "installation_id", maximum=100),
|
||||||
|
profile=_required_text(payload, "profile", maximum=100),
|
||||||
|
capabilities=capabilities,
|
||||||
|
post_install_tasks=tasks,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def deployment_capability_status(
|
||||||
|
path: Path | str | None = None,
|
||||||
|
) -> dict[str, object]:
|
||||||
|
try:
|
||||||
|
receipt = load_infrastructure_capability_receipt(path)
|
||||||
|
except InfrastructureCapabilityReceiptError as exc:
|
||||||
|
return _unavailable_status(configured=True, error=str(exc))
|
||||||
|
if receipt is None:
|
||||||
|
return _unavailable_status(configured=False, error=None)
|
||||||
|
return {
|
||||||
|
"configured": True,
|
||||||
|
"available": True,
|
||||||
|
**receipt.to_dict(),
|
||||||
|
"error": None,
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
def _capability(value: object) -> InfrastructureCapability:
|
||||||
|
if not isinstance(value, Mapping):
|
||||||
|
raise InfrastructureCapabilityReceiptError(
|
||||||
|
"Deployment capability entries must be objects."
|
||||||
|
)
|
||||||
|
state = _required_text(value, "state", maximum=40)
|
||||||
|
if state not in CAPABILITY_STATES:
|
||||||
|
raise InfrastructureCapabilityReceiptError(
|
||||||
|
f"Deployment capability state is unsupported: {state!r}."
|
||||||
|
)
|
||||||
|
normalized_endpoint = _normalized_endpoint(value.get("endpoint", {}))
|
||||||
|
secret_refs = _string_list(value.get("secret_refs"), maximum_items=30)
|
||||||
|
if any(not _ENV_REFERENCE_RE.fullmatch(item) for item in secret_refs):
|
||||||
|
raise InfrastructureCapabilityReceiptError(
|
||||||
|
"Deployment capability secrets must use environment references."
|
||||||
|
)
|
||||||
|
return InfrastructureCapability(
|
||||||
|
id=_required_text(value, "id", maximum=120),
|
||||||
|
label=_required_text(value, "label", maximum=200),
|
||||||
|
state=state,
|
||||||
|
source=_required_text(value, "source", maximum=120),
|
||||||
|
detail=_required_text(value, "detail", maximum=1000),
|
||||||
|
endpoint=normalized_endpoint,
|
||||||
|
secret_refs=secret_refs,
|
||||||
|
dependent_modules=_string_list(
|
||||||
|
value.get("dependent_modules"),
|
||||||
|
maximum_items=100,
|
||||||
|
),
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def _normalized_endpoint(value: object) -> dict[str, object]:
|
||||||
|
if not isinstance(value, Mapping) or len(value) > 10:
|
||||||
|
raise InfrastructureCapabilityReceiptError(
|
||||||
|
"Deployment capability endpoint metadata is invalid."
|
||||||
|
)
|
||||||
|
endpoint: dict[str, object] = {}
|
||||||
|
for key, raw in value.items():
|
||||||
|
if not isinstance(key, str) or not key or len(key) > 50:
|
||||||
|
raise InfrastructureCapabilityReceiptError(
|
||||||
|
"Deployment capability endpoint key is invalid."
|
||||||
|
)
|
||||||
|
if any(
|
||||||
|
marker in key.casefold()
|
||||||
|
for marker in ("password", "secret", "token", "credential")
|
||||||
|
):
|
||||||
|
raise InfrastructureCapabilityReceiptError(
|
||||||
|
"Deployment capability endpoint metadata contains a secret field."
|
||||||
|
)
|
||||||
|
if key.casefold() == "port" and (
|
||||||
|
type(raw) is not int or not 1 <= raw <= 65535
|
||||||
|
):
|
||||||
|
raise InfrastructureCapabilityReceiptError(
|
||||||
|
"Deployment capability endpoint port is invalid."
|
||||||
|
)
|
||||||
|
if isinstance(raw, bool) or raw is None:
|
||||||
|
endpoint[key] = raw
|
||||||
|
elif isinstance(raw, int):
|
||||||
|
endpoint[key] = raw
|
||||||
|
elif isinstance(raw, str) and len(raw) <= 500:
|
||||||
|
endpoint[key] = raw
|
||||||
|
else:
|
||||||
|
raise InfrastructureCapabilityReceiptError(
|
||||||
|
"Deployment capability endpoint value is invalid."
|
||||||
|
)
|
||||||
|
return endpoint
|
||||||
|
|
||||||
|
|
||||||
|
def _task(value: object) -> InfrastructurePostInstallTask:
|
||||||
|
if not isinstance(value, Mapping):
|
||||||
|
raise InfrastructureCapabilityReceiptError(
|
||||||
|
"Deployment post-install task entries must be objects."
|
||||||
|
)
|
||||||
|
return InfrastructurePostInstallTask(
|
||||||
|
id=_required_text(value, "id", maximum=120),
|
||||||
|
resume_key=_required_text(value, "resume_key", maximum=240),
|
||||||
|
capability_id=_required_text(value, "capability_id", maximum=120),
|
||||||
|
state=_required_text(value, "state", maximum=40),
|
||||||
|
owner_module=_required_text(value, "owner_module", maximum=120),
|
||||||
|
summary=_required_text(value, "summary", maximum=1000),
|
||||||
|
required_inputs=_string_list(
|
||||||
|
value.get("required_inputs"),
|
||||||
|
maximum_items=30,
|
||||||
|
),
|
||||||
|
secret_boundary=_required_text(
|
||||||
|
value,
|
||||||
|
"secret_boundary",
|
||||||
|
maximum=120,
|
||||||
|
),
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def _required_text(
|
||||||
|
value: Mapping[str, Any],
|
||||||
|
key: str,
|
||||||
|
*,
|
||||||
|
maximum: int,
|
||||||
|
) -> str:
|
||||||
|
raw = value.get(key)
|
||||||
|
text = str(raw).strip() if raw is not None else ""
|
||||||
|
if not text or len(text) > maximum:
|
||||||
|
raise InfrastructureCapabilityReceiptError(
|
||||||
|
f"Deployment capability field {key!r} is invalid."
|
||||||
|
)
|
||||||
|
return text
|
||||||
|
|
||||||
|
|
||||||
|
def _string_list(value: object, *, maximum_items: int) -> tuple[str, ...]:
|
||||||
|
if not isinstance(value, list) or len(value) > maximum_items:
|
||||||
|
raise InfrastructureCapabilityReceiptError(
|
||||||
|
"Deployment capability list field is invalid."
|
||||||
|
)
|
||||||
|
result: list[str] = []
|
||||||
|
for item in value:
|
||||||
|
if not isinstance(item, str) or not item.strip() or len(item) > 500:
|
||||||
|
raise InfrastructureCapabilityReceiptError(
|
||||||
|
"Deployment capability list item is invalid."
|
||||||
|
)
|
||||||
|
result.append(item.strip())
|
||||||
|
return tuple(result)
|
||||||
|
|
||||||
|
|
||||||
|
def _unavailable_status(*, configured: bool, error: str | None) -> dict[str, object]:
|
||||||
|
return {
|
||||||
|
"configured": configured,
|
||||||
|
"available": False,
|
||||||
|
"schema_version": None,
|
||||||
|
"installation_id": None,
|
||||||
|
"profile": None,
|
||||||
|
"capabilities": [],
|
||||||
|
"post_install_tasks": [],
|
||||||
|
"error": error,
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
__all__ = [
|
||||||
|
"CAPABILITY_STATES",
|
||||||
|
"DEPLOYMENT_CAPABILITIES_ENV",
|
||||||
|
"InfrastructureCapability",
|
||||||
|
"InfrastructureCapabilityReceipt",
|
||||||
|
"InfrastructureCapabilityReceiptError",
|
||||||
|
"InfrastructurePostInstallTask",
|
||||||
|
"deployment_capability_status",
|
||||||
|
"infrastructure_capability_receipt_from_mapping",
|
||||||
|
"load_infrastructure_capability_receipt",
|
||||||
|
"read_infrastructure_capability_receipt",
|
||||||
|
]
|
||||||
@@ -90,7 +90,9 @@ class _ConfigIssueCollector:
|
|||||||
def add(self, level: ConfigIssueLevel, key: str, message: str, action: str) -> None:
|
def add(self, level: ConfigIssueLevel, key: str, message: str, action: str) -> None:
|
||||||
if self.strict and level == "warning":
|
if self.strict and level == "warning":
|
||||||
level = "error"
|
level = "error"
|
||||||
self.issues.append(ConfigIssue(level=level, key=key, message=message, action=action))
|
self.issues.append(
|
||||||
|
ConfigIssue(level=level, key=key, message=message, action=action)
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
_LOCAL_PROFILES = {"dev", "local", "local-dev", "test"}
|
_LOCAL_PROFILES = {"dev", "local", "local-dev", "test"}
|
||||||
@@ -120,9 +122,15 @@ def generate_master_key() -> str:
|
|||||||
return Fernet.generate_key().decode("ascii")
|
return Fernet.generate_key().decode("ascii")
|
||||||
|
|
||||||
|
|
||||||
def env_template(*, profile: str = "self-hosted", generate_secrets: bool = False) -> str:
|
def env_template(
|
||||||
|
*, profile: str = "self-hosted", generate_secrets: bool = False
|
||||||
|
) -> str:
|
||||||
clean_profile = normalize_install_profile(profile)
|
clean_profile = normalize_install_profile(profile)
|
||||||
master_key = generate_master_key() if generate_secrets else "<generate-with-govoplan-config-env-template-generate-secrets>"
|
master_key = (
|
||||||
|
generate_master_key()
|
||||||
|
if generate_secrets
|
||||||
|
else "<generate-with-govoplan-config-env-template-generate-secrets>"
|
||||||
|
)
|
||||||
if clean_profile == "production-like":
|
if clean_profile == "production-like":
|
||||||
return _production_like_env_template(master_key)
|
return _production_like_env_template(master_key)
|
||||||
return _self_hosted_env_template(master_key)
|
return _self_hosted_env_template(master_key)
|
||||||
@@ -144,14 +152,19 @@ def validate_runtime_configuration(
|
|||||||
_validate_async_and_auth_settings(env, runtime, collector)
|
_validate_async_and_auth_settings(env, runtime, collector)
|
||||||
_validate_cors_settings(env, runtime, collector)
|
_validate_cors_settings(env, runtime, collector)
|
||||||
_validate_file_storage_settings(env, runtime, collector)
|
_validate_file_storage_settings(env, runtime, collector)
|
||||||
|
_validate_shared_state_settings(env, collector)
|
||||||
_validate_outbound_connector_policy(env, runtime, collector)
|
_validate_outbound_connector_policy(env, runtime, collector)
|
||||||
_validate_module_catalog_trust(env, runtime, collector)
|
_validate_module_catalog_trust(env, runtime, collector)
|
||||||
return ConfigValidationResult(profile=runtime.name, issues=tuple(collector.issues))
|
return ConfigValidationResult(profile=runtime.name, issues=tuple(collector.issues))
|
||||||
|
|
||||||
|
|
||||||
def _runtime_profile(env: Mapping[str, str], *, profile: str | None) -> _RuntimeProfile:
|
def _runtime_profile(env: Mapping[str, str], *, profile: str | None) -> _RuntimeProfile:
|
||||||
clean_profile = normalize_install_profile(profile or env.get("GOVOPLAN_INSTALL_PROFILE") or env.get("APP_ENV"))
|
clean_profile = normalize_install_profile(
|
||||||
production = clean_profile in _PRODUCTION_PROFILES or env.get("APP_ENV", "").strip().lower() in {"prod", "production"}
|
profile or env.get("GOVOPLAN_INSTALL_PROFILE") or env.get("APP_ENV")
|
||||||
|
)
|
||||||
|
production = clean_profile in _PRODUCTION_PROFILES or env.get(
|
||||||
|
"APP_ENV", ""
|
||||||
|
).strip().lower() in {"prod", "production"}
|
||||||
production_like = production or clean_profile in _PRODUCTION_LIKE_PROFILES
|
production_like = production or clean_profile in _PRODUCTION_LIKE_PROFILES
|
||||||
return _RuntimeProfile(
|
return _RuntimeProfile(
|
||||||
name=clean_profile,
|
name=clean_profile,
|
||||||
@@ -161,86 +174,222 @@ def _runtime_profile(env: Mapping[str, str], *, profile: str | None) -> _Runtime
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def _validate_app_env(env: Mapping[str, str], runtime: _RuntimeProfile, collector: _ConfigIssueCollector) -> None:
|
def _validate_app_env(
|
||||||
|
env: Mapping[str, str], runtime: _RuntimeProfile, collector: _ConfigIssueCollector
|
||||||
|
) -> None:
|
||||||
app_env = _clean(env.get("APP_ENV"))
|
app_env = _clean(env.get("APP_ENV"))
|
||||||
if not app_env and runtime.production_like:
|
if not app_env and runtime.production_like:
|
||||||
collector.add("error", "APP_ENV", "APP_ENV is missing for a production-like install.", "Set APP_ENV=staging, APP_ENV=production, or another explicit deployment profile.")
|
collector.add(
|
||||||
|
"error",
|
||||||
|
"APP_ENV",
|
||||||
|
"APP_ENV is missing for a production-like install.",
|
||||||
|
"Set APP_ENV=staging, APP_ENV=production, or another explicit deployment profile.",
|
||||||
|
)
|
||||||
elif app_env.lower() in {"dev", "test", "local"} and runtime.production_like:
|
elif app_env.lower() in {"dev", "test", "local"} and runtime.production_like:
|
||||||
collector.add("error", "APP_ENV", f"APP_ENV={app_env!r} is not valid for profile {runtime.name!r}.", "Use APP_ENV=staging for production-like testing or APP_ENV=production for a real deployment.")
|
collector.add(
|
||||||
|
"error",
|
||||||
|
"APP_ENV",
|
||||||
|
f"APP_ENV={app_env!r} is not valid for profile {runtime.name!r}.",
|
||||||
|
"Use APP_ENV=staging for production-like testing or APP_ENV=production for a real deployment.",
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def _validate_database_settings(env: Mapping[str, str], runtime: _RuntimeProfile, collector: _ConfigIssueCollector) -> None:
|
def _validate_database_settings(
|
||||||
|
env: Mapping[str, str], runtime: _RuntimeProfile, collector: _ConfigIssueCollector
|
||||||
|
) -> None:
|
||||||
database_url = _clean(env.get("DATABASE_URL"))
|
database_url = _clean(env.get("DATABASE_URL"))
|
||||||
if not database_url:
|
if not database_url:
|
||||||
collector.add("error", "DATABASE_URL", "DATABASE_URL is missing.", "Set DATABASE_URL to the PostgreSQL SQLAlchemy URL used by the API and modules.")
|
collector.add(
|
||||||
|
"error",
|
||||||
|
"DATABASE_URL",
|
||||||
|
"DATABASE_URL is missing.",
|
||||||
|
"Set DATABASE_URL to the PostgreSQL SQLAlchemy URL used by the API and modules.",
|
||||||
|
)
|
||||||
return
|
return
|
||||||
backend = _database_backend(database_url)
|
backend = _database_backend(database_url)
|
||||||
if backend is None:
|
if backend is None:
|
||||||
collector.add("error", "DATABASE_URL", "DATABASE_URL is not a valid SQLAlchemy URL.", "Use a value like postgresql+psycopg://user:password@host:5432/database.")
|
collector.add(
|
||||||
|
"error",
|
||||||
|
"DATABASE_URL",
|
||||||
|
"DATABASE_URL is not a valid SQLAlchemy URL.",
|
||||||
|
"Use a value like postgresql+psycopg://user:password@host:5432/database.",
|
||||||
|
)
|
||||||
return
|
return
|
||||||
if backend == "sqlite" and runtime.production_like:
|
if backend == "sqlite" and runtime.production_like:
|
||||||
collector.add("error", "DATABASE_URL", "SQLite is only supported for disposable local development.", "Use PostgreSQL for production-like and self-hosted installs.")
|
collector.add(
|
||||||
|
"error",
|
||||||
|
"DATABASE_URL",
|
||||||
|
"SQLite is only supported for disposable local development.",
|
||||||
|
"Use PostgreSQL for production-like and self-hosted installs.",
|
||||||
|
)
|
||||||
elif backend != "postgresql" and runtime.production:
|
elif backend != "postgresql" and runtime.production:
|
||||||
collector.add("warning", "DATABASE_URL", f"Database backend {backend!r} is not the preferred production target.", "Use PostgreSQL unless this deployment has an explicit support decision.")
|
collector.add(
|
||||||
|
"warning",
|
||||||
|
"DATABASE_URL",
|
||||||
|
f"Database backend {backend!r} is not the preferred production target.",
|
||||||
|
"Use PostgreSQL unless this deployment has an explicit support decision.",
|
||||||
|
)
|
||||||
if backend == "postgresql" and not _clean(env.get("GOVOPLAN_DATABASE_URL_PGTOOLS")):
|
if backend == "postgresql" and not _clean(env.get("GOVOPLAN_DATABASE_URL_PGTOOLS")):
|
||||||
collector.add("warning", "GOVOPLAN_DATABASE_URL_PGTOOLS", "PostgreSQL backup/restore tools URL is missing.", "Set GOVOPLAN_DATABASE_URL_PGTOOLS to the same database without the SQLAlchemy driver marker, for example postgresql://user:password@host:5432/database.")
|
collector.add(
|
||||||
|
"warning",
|
||||||
|
"GOVOPLAN_DATABASE_URL_PGTOOLS",
|
||||||
|
"PostgreSQL backup/restore tools URL is missing.",
|
||||||
|
"Set GOVOPLAN_DATABASE_URL_PGTOOLS to the same database without the SQLAlchemy driver marker, for example postgresql://user:password@host:5432/database.",
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def _validate_master_key(env: Mapping[str, str], runtime: _RuntimeProfile, collector: _ConfigIssueCollector) -> None:
|
def _validate_master_key(
|
||||||
|
env: Mapping[str, str], runtime: _RuntimeProfile, collector: _ConfigIssueCollector
|
||||||
|
) -> None:
|
||||||
master_key = _clean(env.get("MASTER_KEY_B64"))
|
master_key = _clean(env.get("MASTER_KEY_B64"))
|
||||||
if not master_key and not runtime.local:
|
if not master_key and not runtime.local:
|
||||||
collector.add("error", "MASTER_KEY_B64", "MASTER_KEY_B64 is required outside local dev/test.", "Generate a Fernet key with `govoplan-config env-template --generate-secrets` or `python -c 'from cryptography.fernet import Fernet; print(Fernet.generate_key().decode())'` and store it in deployment secrets.")
|
collector.add(
|
||||||
|
"error",
|
||||||
|
"MASTER_KEY_B64",
|
||||||
|
"MASTER_KEY_B64 is required outside local dev/test.",
|
||||||
|
"Generate a Fernet key with `govoplan-config env-template --generate-secrets` or `python -c 'from cryptography.fernet import Fernet; print(Fernet.generate_key().decode())'` and store it in deployment secrets.",
|
||||||
|
)
|
||||||
return
|
return
|
||||||
if not master_key:
|
if not master_key:
|
||||||
return
|
return
|
||||||
error = _master_key_error(master_key)
|
error = _master_key_error(master_key)
|
||||||
if error:
|
if error:
|
||||||
collector.add("error", "MASTER_KEY_B64", error, "Replace MASTER_KEY_B64 with a Fernet key or base64-encoded 32-byte key.")
|
collector.add(
|
||||||
|
"error",
|
||||||
|
"MASTER_KEY_B64",
|
||||||
|
error,
|
||||||
|
"Replace MASTER_KEY_B64 with a Fernet key or base64-encoded 32-byte key.",
|
||||||
|
)
|
||||||
elif "change-me" in master_key.lower() or "generate" in master_key.lower():
|
elif "change-me" in master_key.lower() or "generate" in master_key.lower():
|
||||||
collector.add("error", "MASTER_KEY_B64", "MASTER_KEY_B64 still looks like a placeholder.", "Generate a real deployment key and store it outside git.")
|
collector.add(
|
||||||
|
"error",
|
||||||
|
"MASTER_KEY_B64",
|
||||||
|
"MASTER_KEY_B64 still looks like a placeholder.",
|
||||||
|
"Generate a real deployment key and store it outside git.",
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def _validate_enabled_modules(env: Mapping[str, str], runtime: _RuntimeProfile, collector: _ConfigIssueCollector) -> None:
|
def _validate_enabled_modules(
|
||||||
|
env: Mapping[str, str], runtime: _RuntimeProfile, collector: _ConfigIssueCollector
|
||||||
|
) -> None:
|
||||||
enabled_modules = _csv(env.get("ENABLED_MODULES"))
|
enabled_modules = _csv(env.get("ENABLED_MODULES"))
|
||||||
if not enabled_modules and runtime.production_like:
|
if not enabled_modules and runtime.production_like:
|
||||||
collector.add("error", "ENABLED_MODULES", "ENABLED_MODULES is missing.", "Set ENABLED_MODULES explicitly so startup module composition is intentional.")
|
collector.add(
|
||||||
|
"error",
|
||||||
|
"ENABLED_MODULES",
|
||||||
|
"ENABLED_MODULES is missing.",
|
||||||
|
"Set ENABLED_MODULES explicitly so startup module composition is intentional.",
|
||||||
|
)
|
||||||
elif "access" not in enabled_modules and runtime.production_like:
|
elif "access" not in enabled_modules and runtime.production_like:
|
||||||
collector.add("error", "ENABLED_MODULES", "The access module is not enabled.", "Include `access` unless this deployment has a replacement auth/principal provider.")
|
collector.add(
|
||||||
|
"error",
|
||||||
|
"ENABLED_MODULES",
|
||||||
|
"The access module is not enabled.",
|
||||||
|
"Include `access` unless this deployment has a replacement auth/principal provider.",
|
||||||
|
)
|
||||||
elif enabled_modules and "admin" not in enabled_modules and runtime.production_like:
|
elif enabled_modules and "admin" not in enabled_modules and runtime.production_like:
|
||||||
collector.add("warning", "ENABLED_MODULES", "The admin module is not enabled.", "Keep `admin` enabled for operator UI unless this is a deliberately headless install.")
|
collector.add(
|
||||||
|
"warning",
|
||||||
|
"ENABLED_MODULES",
|
||||||
|
"The admin module is not enabled.",
|
||||||
|
"Keep `admin` enabled for operator UI unless this is a deliberately headless install.",
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def _validate_async_and_auth_settings(env: Mapping[str, str], runtime: _RuntimeProfile, collector: _ConfigIssueCollector) -> None:
|
def _validate_async_and_auth_settings(
|
||||||
|
env: Mapping[str, str], runtime: _RuntimeProfile, collector: _ConfigIssueCollector
|
||||||
|
) -> None:
|
||||||
if _truthy(env.get("CELERY_ENABLED")) and not _clean(env.get("REDIS_URL")):
|
if _truthy(env.get("CELERY_ENABLED")) and not _clean(env.get("REDIS_URL")):
|
||||||
collector.add("error", "REDIS_URL", "CELERY_ENABLED=true but REDIS_URL is missing.", "Set REDIS_URL to the Redis broker/result backend used by workers.")
|
collector.add(
|
||||||
|
"error",
|
||||||
|
"REDIS_URL",
|
||||||
|
"CELERY_ENABLED=true but REDIS_URL is missing.",
|
||||||
|
"Set REDIS_URL to the Redis broker/result backend used by workers.",
|
||||||
|
)
|
||||||
if runtime.production and _truthy(env.get("DEV_BOOTSTRAP_ENABLED")):
|
if runtime.production and _truthy(env.get("DEV_BOOTSTRAP_ENABLED")):
|
||||||
collector.add("error", "DEV_BOOTSTRAP_ENABLED", "Development bootstrap is enabled in production.", "Set DEV_BOOTSTRAP_ENABLED=false and create first administrators through the controlled bootstrap path.")
|
collector.add(
|
||||||
|
"error",
|
||||||
|
"DEV_BOOTSTRAP_ENABLED",
|
||||||
|
"Development bootstrap is enabled in production.",
|
||||||
|
"Set DEV_BOOTSTRAP_ENABLED=false and create first administrators through the controlled bootstrap path.",
|
||||||
|
)
|
||||||
if runtime.production and not _truthy(env.get("AUTH_COOKIE_SECURE")):
|
if runtime.production and not _truthy(env.get("AUTH_COOKIE_SECURE")):
|
||||||
collector.add("error", "AUTH_COOKIE_SECURE", "Secure auth cookies are disabled for production.", "Set AUTH_COOKIE_SECURE=true behind HTTPS.")
|
collector.add(
|
||||||
|
"error",
|
||||||
|
"AUTH_COOKIE_SECURE",
|
||||||
|
"Secure auth cookies are disabled for production.",
|
||||||
|
"Set AUTH_COOKIE_SECURE=true behind HTTPS.",
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def _validate_cors_settings(env: Mapping[str, str], runtime: _RuntimeProfile, collector: _ConfigIssueCollector) -> None:
|
def _validate_cors_settings(
|
||||||
|
env: Mapping[str, str], runtime: _RuntimeProfile, collector: _ConfigIssueCollector
|
||||||
|
) -> None:
|
||||||
cors_origins = _csv(env.get("CORS_ORIGINS"))
|
cors_origins = _csv(env.get("CORS_ORIGINS"))
|
||||||
if runtime.production_like and not cors_origins:
|
if runtime.production_like and not cors_origins:
|
||||||
collector.add("error", "CORS_ORIGINS", "CORS_ORIGINS is missing.", "Set CORS_ORIGINS to the exact WebUI origin or origins.")
|
collector.add(
|
||||||
|
"error",
|
||||||
|
"CORS_ORIGINS",
|
||||||
|
"CORS_ORIGINS is missing.",
|
||||||
|
"Set CORS_ORIGINS to the exact WebUI origin or origins.",
|
||||||
|
)
|
||||||
elif "*" in cors_origins and runtime.production_like:
|
elif "*" in cors_origins and runtime.production_like:
|
||||||
collector.add("error", "CORS_ORIGINS", "Wildcard CORS is not allowed for production-like installs.", "Replace `*` with exact HTTPS/WebUI origins.")
|
collector.add(
|
||||||
|
"error",
|
||||||
|
"CORS_ORIGINS",
|
||||||
|
"Wildcard CORS is not allowed for production-like installs.",
|
||||||
|
"Replace `*` with exact HTTPS/WebUI origins.",
|
||||||
|
)
|
||||||
elif runtime.production and set(cors_origins) <= _DEFAULT_LOCAL_CORS:
|
elif runtime.production and set(cors_origins) <= _DEFAULT_LOCAL_CORS:
|
||||||
collector.add("warning", "CORS_ORIGINS", "CORS_ORIGINS still contains only local development origins.", "Set CORS_ORIGINS to the deployed WebUI origin.")
|
collector.add(
|
||||||
|
"warning",
|
||||||
|
"CORS_ORIGINS",
|
||||||
|
"CORS_ORIGINS still contains only local development origins.",
|
||||||
|
"Set CORS_ORIGINS to the deployed WebUI origin.",
|
||||||
|
)
|
||||||
trusted_hosts = _csv(env.get("GOVOPLAN_TRUSTED_HOSTS"))
|
trusted_hosts = _csv(env.get("GOVOPLAN_TRUSTED_HOSTS"))
|
||||||
if runtime.production_like and not trusted_hosts:
|
if runtime.production_like and not trusted_hosts:
|
||||||
collector.add("error", "GOVOPLAN_TRUSTED_HOSTS", "Trusted HTTP hosts are not configured.", "Set GOVOPLAN_TRUSTED_HOSTS to the exact API host names accepted by this deployment.")
|
collector.add(
|
||||||
|
"error",
|
||||||
|
"GOVOPLAN_TRUSTED_HOSTS",
|
||||||
|
"Trusted HTTP hosts are not configured.",
|
||||||
|
"Set GOVOPLAN_TRUSTED_HOSTS to the exact API host names accepted by this deployment.",
|
||||||
|
)
|
||||||
elif "*" in trusted_hosts and runtime.production_like:
|
elif "*" in trusted_hosts and runtime.production_like:
|
||||||
collector.add("error", "GOVOPLAN_TRUSTED_HOSTS", "Wildcard trusted hosts are not allowed for production-like installs.", "Replace `*` with exact host names or narrowly scoped `*.example.org` entries.")
|
collector.add(
|
||||||
|
"error",
|
||||||
|
"GOVOPLAN_TRUSTED_HOSTS",
|
||||||
|
"Wildcard trusted hosts are not allowed for production-like installs.",
|
||||||
|
"Replace `*` with exact host names or narrowly scoped `*.example.org` entries.",
|
||||||
|
)
|
||||||
forwarded_allow_ips = _csv(env.get("FORWARDED_ALLOW_IPS"))
|
forwarded_allow_ips = _csv(env.get("FORWARDED_ALLOW_IPS"))
|
||||||
if runtime.production_like and "*" in forwarded_allow_ips:
|
if runtime.production_like and "*" in forwarded_allow_ips:
|
||||||
collector.add("error", "FORWARDED_ALLOW_IPS", "Proxy headers must not be trusted from every address.", "Set FORWARDED_ALLOW_IPS to the reverse proxy address or network passed to Uvicorn.")
|
collector.add(
|
||||||
|
"error",
|
||||||
|
"FORWARDED_ALLOW_IPS",
|
||||||
|
"Proxy headers must not be trusted from every address.",
|
||||||
|
"Set FORWARDED_ALLOW_IPS to the reverse proxy address or network passed to Uvicorn.",
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def _validate_file_storage_settings(env: Mapping[str, str], runtime: _RuntimeProfile, collector: _ConfigIssueCollector) -> None:
|
def _validate_file_storage_settings(
|
||||||
|
env: Mapping[str, str], runtime: _RuntimeProfile, collector: _ConfigIssueCollector
|
||||||
|
) -> None:
|
||||||
storage_backend = _clean(env.get("FILE_STORAGE_BACKEND")) or "local"
|
storage_backend = _clean(env.get("FILE_STORAGE_BACKEND")) or "local"
|
||||||
deployment_managed_raw = _clean(env.get("FILE_STORAGE_S3_DEPLOYMENT_MANAGED")).lower()
|
deployment_managed_raw = _clean(
|
||||||
if deployment_managed_raw and deployment_managed_raw not in {"true", "false", "1", "0", "yes", "no", "on", "off"}:
|
env.get("FILE_STORAGE_S3_DEPLOYMENT_MANAGED")
|
||||||
|
).lower()
|
||||||
|
endpoint_trusted_raw = _clean(env.get("FILE_STORAGE_S3_ENDPOINT_TRUSTED")).lower()
|
||||||
|
if deployment_managed_raw and deployment_managed_raw not in {
|
||||||
|
"true",
|
||||||
|
"false",
|
||||||
|
"1",
|
||||||
|
"0",
|
||||||
|
"yes",
|
||||||
|
"no",
|
||||||
|
"on",
|
||||||
|
"off",
|
||||||
|
}:
|
||||||
collector.add(
|
collector.add(
|
||||||
"error",
|
"error",
|
||||||
"FILE_STORAGE_S3_DEPLOYMENT_MANAGED",
|
"FILE_STORAGE_S3_DEPLOYMENT_MANAGED",
|
||||||
@@ -248,13 +397,30 @@ def _validate_file_storage_settings(env: Mapping[str, str], runtime: _RuntimePro
|
|||||||
"Set FILE_STORAGE_S3_DEPLOYMENT_MANAGED=false, or let the supported installer manage Garage.",
|
"Set FILE_STORAGE_S3_DEPLOYMENT_MANAGED=false, or let the supported installer manage Garage.",
|
||||||
)
|
)
|
||||||
deployment_managed = _truthy(deployment_managed_raw)
|
deployment_managed = _truthy(deployment_managed_raw)
|
||||||
|
if endpoint_trusted_raw and endpoint_trusted_raw not in {
|
||||||
|
"true",
|
||||||
|
"false",
|
||||||
|
"1",
|
||||||
|
"0",
|
||||||
|
"yes",
|
||||||
|
"no",
|
||||||
|
"on",
|
||||||
|
"off",
|
||||||
|
}:
|
||||||
|
collector.add(
|
||||||
|
"error",
|
||||||
|
"FILE_STORAGE_S3_ENDPOINT_TRUSTED",
|
||||||
|
"External S3 endpoint trust must be an explicit boolean.",
|
||||||
|
"Set it only for a deployment-controlled HTTPS storage origin.",
|
||||||
|
)
|
||||||
|
endpoint_trusted = _truthy(endpoint_trusted_raw)
|
||||||
if storage_backend == "local":
|
if storage_backend == "local":
|
||||||
if deployment_managed:
|
if deployment_managed or endpoint_trusted:
|
||||||
collector.add(
|
collector.add(
|
||||||
"error",
|
"error",
|
||||||
"FILE_STORAGE_S3_DEPLOYMENT_MANAGED",
|
"FILE_STORAGE_S3_ENDPOINT_TRUSTED",
|
||||||
"Managed S3 trust cannot be enabled for local file storage.",
|
"S3 endpoint trust cannot be enabled for local file storage.",
|
||||||
"Set FILE_STORAGE_S3_DEPLOYMENT_MANAGED=false.",
|
"Disable both S3 trust settings while FILE_STORAGE_BACKEND=local.",
|
||||||
)
|
)
|
||||||
_validate_local_file_storage(env, runtime, collector)
|
_validate_local_file_storage(env, runtime, collector)
|
||||||
elif storage_backend == "s3":
|
elif storage_backend == "s3":
|
||||||
@@ -262,16 +428,34 @@ def _validate_file_storage_settings(env: Mapping[str, str], runtime: _RuntimePro
|
|||||||
env,
|
env,
|
||||||
collector,
|
collector,
|
||||||
deployment_managed=deployment_managed,
|
deployment_managed=deployment_managed,
|
||||||
|
endpoint_trusted=endpoint_trusted,
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
collector.add("error", "FILE_STORAGE_BACKEND", f"Unsupported FILE_STORAGE_BACKEND={storage_backend!r}.", "Use `local` or `s3`.")
|
collector.add(
|
||||||
|
"error",
|
||||||
|
"FILE_STORAGE_BACKEND",
|
||||||
|
f"Unsupported FILE_STORAGE_BACKEND={storage_backend!r}.",
|
||||||
|
"Use `local` or `s3`.",
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def _validate_local_file_storage(env: Mapping[str, str], runtime: _RuntimeProfile, collector: _ConfigIssueCollector) -> None:
|
def _validate_local_file_storage(
|
||||||
|
env: Mapping[str, str], runtime: _RuntimeProfile, collector: _ConfigIssueCollector
|
||||||
|
) -> None:
|
||||||
if not _clean(env.get("FILE_STORAGE_LOCAL_ROOT")) and runtime.production_like:
|
if not _clean(env.get("FILE_STORAGE_LOCAL_ROOT")) and runtime.production_like:
|
||||||
collector.add("error", "FILE_STORAGE_LOCAL_ROOT", "Local file storage root is missing.", "Set FILE_STORAGE_LOCAL_ROOT to a durable, backed-up path.")
|
collector.add(
|
||||||
|
"error",
|
||||||
|
"FILE_STORAGE_LOCAL_ROOT",
|
||||||
|
"Local file storage root is missing.",
|
||||||
|
"Set FILE_STORAGE_LOCAL_ROOT to a durable, backed-up path.",
|
||||||
|
)
|
||||||
elif runtime.production:
|
elif runtime.production:
|
||||||
collector.add("warning", "FILE_STORAGE_BACKEND", "Production is configured for local file storage.", "Confirm the path is durable and backed up, or use object storage once the deployment needs independent file scaling.")
|
collector.add(
|
||||||
|
"warning",
|
||||||
|
"FILE_STORAGE_BACKEND",
|
||||||
|
"Production is configured for local file storage.",
|
||||||
|
"Confirm the path is durable and backed up, or use object storage once the deployment needs independent file scaling.",
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def _validate_s3_file_storage(
|
def _validate_s3_file_storage(
|
||||||
@@ -279,10 +463,22 @@ def _validate_s3_file_storage(
|
|||||||
collector: _ConfigIssueCollector,
|
collector: _ConfigIssueCollector,
|
||||||
*,
|
*,
|
||||||
deployment_managed: bool,
|
deployment_managed: bool,
|
||||||
|
endpoint_trusted: bool,
|
||||||
) -> None:
|
) -> None:
|
||||||
for key in ("FILE_STORAGE_S3_ENDPOINT_URL", "FILE_STORAGE_S3_REGION", "FILE_STORAGE_S3_ACCESS_KEY_ID", "FILE_STORAGE_S3_SECRET_ACCESS_KEY", "FILE_STORAGE_S3_BUCKET"):
|
for key in (
|
||||||
|
"FILE_STORAGE_S3_ENDPOINT_URL",
|
||||||
|
"FILE_STORAGE_S3_REGION",
|
||||||
|
"FILE_STORAGE_S3_ACCESS_KEY_ID",
|
||||||
|
"FILE_STORAGE_S3_SECRET_ACCESS_KEY",
|
||||||
|
"FILE_STORAGE_S3_BUCKET",
|
||||||
|
):
|
||||||
if not _clean(env.get(key)):
|
if not _clean(env.get(key)):
|
||||||
collector.add("error", key, f"{key} is required when FILE_STORAGE_BACKEND=s3.", "Configure all FILE_STORAGE_S3_* settings through deployment secrets.")
|
collector.add(
|
||||||
|
"error",
|
||||||
|
key,
|
||||||
|
f"{key} is required when FILE_STORAGE_BACKEND=s3.",
|
||||||
|
"Configure all FILE_STORAGE_S3_* settings through deployment secrets.",
|
||||||
|
)
|
||||||
if (
|
if (
|
||||||
deployment_managed
|
deployment_managed
|
||||||
and _clean(env.get("FILE_STORAGE_S3_ENDPOINT_URL")) != "http://garage:3900"
|
and _clean(env.get("FILE_STORAGE_S3_ENDPOINT_URL")) != "http://garage:3900"
|
||||||
@@ -293,6 +489,126 @@ def _validate_s3_file_storage(
|
|||||||
"Installer-managed S3 trust is restricted to http://garage:3900.",
|
"Installer-managed S3 trust is restricted to http://garage:3900.",
|
||||||
"Use the exact managed Garage endpoint or disable FILE_STORAGE_S3_DEPLOYMENT_MANAGED.",
|
"Use the exact managed Garage endpoint or disable FILE_STORAGE_S3_DEPLOYMENT_MANAGED.",
|
||||||
)
|
)
|
||||||
|
if deployment_managed and endpoint_trusted:
|
||||||
|
collector.add(
|
||||||
|
"error",
|
||||||
|
"FILE_STORAGE_S3_ENDPOINT_TRUSTED",
|
||||||
|
"Managed Garage trust and external endpoint trust are mutually exclusive.",
|
||||||
|
"Use installer-managed Garage trust or one explicit external endpoint.",
|
||||||
|
)
|
||||||
|
if not deployment_managed and not endpoint_trusted:
|
||||||
|
collector.add(
|
||||||
|
"error",
|
||||||
|
"FILE_STORAGE_S3_ENDPOINT_TRUSTED",
|
||||||
|
"External S3 storage requires an explicit deployment trust decision.",
|
||||||
|
"Set FILE_STORAGE_S3_ENDPOINT_TRUSTED=true only for a deployment-controlled HTTPS origin.",
|
||||||
|
)
|
||||||
|
endpoint = _clean(env.get("FILE_STORAGE_S3_ENDPOINT_URL"))
|
||||||
|
if endpoint_trusted and not endpoint.lower().startswith("https://"):
|
||||||
|
collector.add(
|
||||||
|
"error",
|
||||||
|
"FILE_STORAGE_S3_ENDPOINT_URL",
|
||||||
|
"Deployment-trusted external S3 storage must use HTTPS.",
|
||||||
|
"Use an HTTPS storage origin with certificate verification.",
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def _validate_shared_state_settings(
|
||||||
|
env: Mapping[str, str],
|
||||||
|
collector: _ConfigIssueCollector,
|
||||||
|
) -> None:
|
||||||
|
state_profile = (_clean(env.get("GOVOPLAN_STATE_PROFILE")) or "local").lower()
|
||||||
|
if state_profile not in {"local", "host-shared", "shared"}:
|
||||||
|
collector.add(
|
||||||
|
"error",
|
||||||
|
"GOVOPLAN_STATE_PROFILE",
|
||||||
|
f"Unsupported state profile {state_profile!r}.",
|
||||||
|
"Use `local` for one process per role, `host-shared` for one Compose host, or `shared` for a multi-host stateless tier.",
|
||||||
|
)
|
||||||
|
return
|
||||||
|
try:
|
||||||
|
api_replicas = int(_clean(env.get("GOVOPLAN_EXPECTED_API_REPLICAS")) or "1")
|
||||||
|
worker_replicas = int(
|
||||||
|
_clean(env.get("GOVOPLAN_EXPECTED_WORKER_REPLICAS")) or "0"
|
||||||
|
)
|
||||||
|
except ValueError:
|
||||||
|
collector.add(
|
||||||
|
"error",
|
||||||
|
"GOVOPLAN_EXPECTED_API_REPLICAS",
|
||||||
|
"Expected replica counts must be integers.",
|
||||||
|
"Set GOVOPLAN_EXPECTED_API_REPLICAS and GOVOPLAN_EXPECTED_WORKER_REPLICAS to non-negative integers.",
|
||||||
|
)
|
||||||
|
return
|
||||||
|
if api_replicas < 1 or worker_replicas < 0:
|
||||||
|
collector.add(
|
||||||
|
"error",
|
||||||
|
"GOVOPLAN_EXPECTED_API_REPLICAS",
|
||||||
|
"Expected replica counts are outside their supported range.",
|
||||||
|
"Configure at least one API replica and zero or more worker replicas.",
|
||||||
|
)
|
||||||
|
if state_profile == "local":
|
||||||
|
if api_replicas > 1 or worker_replicas > 1:
|
||||||
|
collector.add(
|
||||||
|
"error",
|
||||||
|
"GOVOPLAN_STATE_PROFILE",
|
||||||
|
"A local-state profile cannot safely run replicated API or worker nodes.",
|
||||||
|
"Use `host-shared` with one shared host volume, or `shared` with PostgreSQL, Redis, and S3-compatible object storage.",
|
||||||
|
)
|
||||||
|
return
|
||||||
|
installation_id = _clean(env.get("GOVOPLAN_INSTALLATION_ID"))
|
||||||
|
if not installation_id or (
|
||||||
|
state_profile == "shared" and installation_id == "govoplan-local"
|
||||||
|
):
|
||||||
|
collector.add(
|
||||||
|
"error",
|
||||||
|
"GOVOPLAN_INSTALLATION_ID",
|
||||||
|
"Shared-state deployments require a stable installation identifier.",
|
||||||
|
"Set one immutable deployment-wide GOVOPLAN_INSTALLATION_ID on every node.",
|
||||||
|
)
|
||||||
|
if _database_backend(_clean(env.get("DATABASE_URL"))) != "postgresql":
|
||||||
|
collector.add(
|
||||||
|
"error",
|
||||||
|
"DATABASE_URL",
|
||||||
|
"Shared-state deployments require PostgreSQL.",
|
||||||
|
"Point every API, scheduler, and worker node at the same logical PostgreSQL service.",
|
||||||
|
)
|
||||||
|
if not _clean(env.get("REDIS_URL")):
|
||||||
|
collector.add(
|
||||||
|
"error",
|
||||||
|
"REDIS_URL",
|
||||||
|
"Shared-state deployments require a common Redis service.",
|
||||||
|
"Configure the same Redis endpoint for all API and worker nodes.",
|
||||||
|
)
|
||||||
|
if (
|
||||||
|
state_profile == "shared"
|
||||||
|
and (_clean(env.get("FILE_STORAGE_BACKEND")) or "local").lower() != "s3"
|
||||||
|
):
|
||||||
|
collector.add(
|
||||||
|
"error",
|
||||||
|
"FILE_STORAGE_BACKEND",
|
||||||
|
"Shared-state deployments cannot use node-local object storage.",
|
||||||
|
"Set FILE_STORAGE_BACKEND=s3 and configure one shared S3-compatible bucket.",
|
||||||
|
)
|
||||||
|
try:
|
||||||
|
heartbeat = int(_clean(env.get("GOVOPLAN_RUNTIME_HEARTBEAT_SECONDS")) or "15")
|
||||||
|
stale_after = int(
|
||||||
|
_clean(env.get("GOVOPLAN_RUNTIME_STALE_AFTER_SECONDS")) or "60"
|
||||||
|
)
|
||||||
|
except ValueError:
|
||||||
|
collector.add(
|
||||||
|
"error",
|
||||||
|
"GOVOPLAN_RUNTIME_HEARTBEAT_SECONDS",
|
||||||
|
"Runtime heartbeat and stale intervals must be integers.",
|
||||||
|
"Use a heartbeat interval shorter than one third of the stale interval.",
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
if heartbeat < 2 or stale_after < max(10, heartbeat * 3):
|
||||||
|
collector.add(
|
||||||
|
"error",
|
||||||
|
"GOVOPLAN_RUNTIME_STALE_AFTER_SECONDS",
|
||||||
|
"Runtime stale detection leaves insufficient room for missed heartbeats.",
|
||||||
|
"Set stale-after to at least three heartbeat intervals and at least ten seconds.",
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def _validate_outbound_connector_policy(
|
def _validate_outbound_connector_policy(
|
||||||
@@ -300,8 +616,19 @@ def _validate_outbound_connector_policy(
|
|||||||
runtime: _RuntimeProfile,
|
runtime: _RuntimeProfile,
|
||||||
collector: _ConfigIssueCollector,
|
collector: _ConfigIssueCollector,
|
||||||
) -> None:
|
) -> None:
|
||||||
private_networks = _clean(env.get("GOVOPLAN_CONNECTOR_ALLOW_PRIVATE_NETWORKS")).lower()
|
private_networks = _clean(
|
||||||
if runtime.production_like and private_networks not in {"true", "false", "1", "0", "yes", "no", "on", "off"}:
|
env.get("GOVOPLAN_CONNECTOR_ALLOW_PRIVATE_NETWORKS")
|
||||||
|
).lower()
|
||||||
|
if runtime.production_like and private_networks not in {
|
||||||
|
"true",
|
||||||
|
"false",
|
||||||
|
"1",
|
||||||
|
"0",
|
||||||
|
"yes",
|
||||||
|
"no",
|
||||||
|
"on",
|
||||||
|
"off",
|
||||||
|
}:
|
||||||
collector.add(
|
collector.add(
|
||||||
"error",
|
"error",
|
||||||
"GOVOPLAN_CONNECTOR_ALLOW_PRIVATE_NETWORKS",
|
"GOVOPLAN_CONNECTOR_ALLOW_PRIVATE_NETWORKS",
|
||||||
@@ -321,13 +648,21 @@ def _validate_outbound_connector_policy(
|
|||||||
except ValueError:
|
except ValueError:
|
||||||
parsed = 0
|
parsed = 0
|
||||||
if parsed <= 0:
|
if parsed <= 0:
|
||||||
collector.add("error", key, f"{key} must be a positive byte count.", "Use a positive integer byte limit.")
|
collector.add(
|
||||||
|
"error",
|
||||||
|
key,
|
||||||
|
f"{key} must be a positive byte count.",
|
||||||
|
"Use a positive integer byte limit.",
|
||||||
|
)
|
||||||
secret_env_names = [
|
secret_env_names = [
|
||||||
item.strip()
|
item.strip()
|
||||||
for item in env.get("GOVOPLAN_CONNECTOR_SECRET_ENV_ALLOWLIST", "").split(",")
|
for item in env.get("GOVOPLAN_CONNECTOR_SECRET_ENV_ALLOWLIST", "").split(",")
|
||||||
if item.strip()
|
if item.strip()
|
||||||
]
|
]
|
||||||
if any(re.fullmatch(r"[A-Za-z_][A-Za-z0-9_]*", item) is None for item in secret_env_names):
|
if any(
|
||||||
|
re.fullmatch(r"[A-Za-z_][A-Za-z0-9_]*", item) is None
|
||||||
|
for item in secret_env_names
|
||||||
|
):
|
||||||
collector.add(
|
collector.add(
|
||||||
"error",
|
"error",
|
||||||
"GOVOPLAN_CONNECTOR_SECRET_ENV_ALLOWLIST",
|
"GOVOPLAN_CONNECTOR_SECRET_ENV_ALLOWLIST",
|
||||||
@@ -348,14 +683,31 @@ def _validate_outbound_connector_policy(
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def _validate_module_catalog_trust(env: Mapping[str, str], runtime: _RuntimeProfile, collector: _ConfigIssueCollector) -> None:
|
def _validate_module_catalog_trust(
|
||||||
catalog_source = _clean(env.get("GOVOPLAN_MODULE_PACKAGE_CATALOG_URL")) or _clean(env.get("GOVOPLAN_MODULE_PACKAGE_CATALOG"))
|
env: Mapping[str, str], runtime: _RuntimeProfile, collector: _ConfigIssueCollector
|
||||||
|
) -> None:
|
||||||
|
catalog_source = _clean(env.get("GOVOPLAN_MODULE_PACKAGE_CATALOG_URL")) or _clean(
|
||||||
|
env.get("GOVOPLAN_MODULE_PACKAGE_CATALOG")
|
||||||
|
)
|
||||||
if not runtime.production or not catalog_source:
|
if not runtime.production or not catalog_source:
|
||||||
return
|
return
|
||||||
if not _clean(env.get("GOVOPLAN_MODULE_PACKAGE_CATALOG_TRUSTED_KEYS_FILE")):
|
if not _clean(env.get("GOVOPLAN_MODULE_PACKAGE_CATALOG_TRUSTED_KEYS_FILE")):
|
||||||
collector.add("error", "GOVOPLAN_MODULE_PACKAGE_CATALOG_TRUSTED_KEYS_FILE", "A module catalog source is configured without a trusted keyring file.", "Pin the published GovOPlaN catalog keyring locally and set GOVOPLAN_MODULE_PACKAGE_CATALOG_TRUSTED_KEYS_FILE.")
|
collector.add(
|
||||||
if not _clean(env.get("GOVOPLAN_MODULE_PACKAGE_CATALOG_APPROVED_CHANNEL")):
|
"error",
|
||||||
collector.add("error", "GOVOPLAN_MODULE_PACKAGE_CATALOG_APPROVED_CHANNEL", "A module catalog source is configured without an approved release channel.", "Set GOVOPLAN_MODULE_PACKAGE_CATALOG_APPROVED_CHANNEL=stable or another approved deployment channel.")
|
"GOVOPLAN_MODULE_PACKAGE_CATALOG_TRUSTED_KEYS_FILE",
|
||||||
|
"A module catalog source is configured without a trusted keyring file.",
|
||||||
|
"Pin the published GovOPlaN catalog keyring locally and set GOVOPLAN_MODULE_PACKAGE_CATALOG_TRUSTED_KEYS_FILE.",
|
||||||
|
)
|
||||||
|
if not (
|
||||||
|
_clean(env.get("GOVOPLAN_MODULE_PACKAGE_CATALOG_APPROVED_CHANNELS"))
|
||||||
|
or _clean(env.get("GOVOPLAN_MODULE_PACKAGE_CATALOG_APPROVED_CHANNEL"))
|
||||||
|
):
|
||||||
|
collector.add(
|
||||||
|
"error",
|
||||||
|
"GOVOPLAN_MODULE_PACKAGE_CATALOG_APPROVED_CHANNELS",
|
||||||
|
"A module catalog source is configured without an approved release channel.",
|
||||||
|
"Set GOVOPLAN_MODULE_PACKAGE_CATALOG_APPROVED_CHANNELS=stable or another approved deployment channel.",
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def _self_hosted_env_template(master_key: str) -> str:
|
def _self_hosted_env_template(master_key: str) -> str:
|
||||||
@@ -364,6 +716,13 @@ def _self_hosted_env_template(master_key: str) -> str:
|
|||||||
|
|
||||||
APP_ENV=production
|
APP_ENV=production
|
||||||
GOVOPLAN_INSTALL_PROFILE=self-hosted
|
GOVOPLAN_INSTALL_PROFILE=self-hosted
|
||||||
|
GOVOPLAN_INSTALLATION_ID=govoplan-production
|
||||||
|
GOVOPLAN_STATE_PROFILE=local
|
||||||
|
GOVOPLAN_RUNTIME_ROLE=api
|
||||||
|
GOVOPLAN_RUNTIME_HEARTBEAT_SECONDS=15
|
||||||
|
GOVOPLAN_RUNTIME_STALE_AFTER_SECONDS=60
|
||||||
|
GOVOPLAN_EXPECTED_API_REPLICAS=1
|
||||||
|
GOVOPLAN_EXPECTED_WORKER_REPLICAS=1
|
||||||
MASTER_KEY_B64={master_key}
|
MASTER_KEY_B64={master_key}
|
||||||
|
|
||||||
DATABASE_URL=postgresql+psycopg://govoplan:change-me@127.0.0.1:5432/govoplan
|
DATABASE_URL=postgresql+psycopg://govoplan:change-me@127.0.0.1:5432/govoplan
|
||||||
@@ -373,11 +732,13 @@ ENABLED_MODULES=tenancy,organizations,identity,access,admin,dashboard,policy,aud
|
|||||||
|
|
||||||
CELERY_ENABLED=true
|
CELERY_ENABLED=true
|
||||||
REDIS_URL=redis://127.0.0.1:6379/0
|
REDIS_URL=redis://127.0.0.1:6379/0
|
||||||
CELERY_QUEUES=send_email,append_sent,notifications,calendar,dataflow,workflow,events,default
|
CELERY_QUEUES=send_email,append_sent,notifications,mail,calendar,dataflow,workflow,postbox,events,idm,default
|
||||||
CALENDAR_OUTBOX_TERMINAL_RETENTION_DAYS=90
|
CALENDAR_OUTBOX_TERMINAL_RETENTION_DAYS=90
|
||||||
PLATFORM_EVENT_OUTBOX_MAX_ATTEMPTS=8
|
PLATFORM_EVENT_OUTBOX_MAX_ATTEMPTS=8
|
||||||
PLATFORM_EVENT_OUTBOX_TERMINAL_RETENTION_DAYS=90
|
PLATFORM_EVENT_OUTBOX_TERMINAL_RETENTION_DAYS=90
|
||||||
SCHEDULING_CANCELLATION_NOTICE_DAYS=30
|
SCHEDULING_CANCELLATION_NOTICE_DAYS=30
|
||||||
|
SCHEDULING_PUBLIC_SELF_ENROLLMENT_ENABLED=true
|
||||||
|
SCHEDULING_PUBLIC_SELF_ENROLLMENT_MAX_CAPACITY=10000
|
||||||
|
|
||||||
# Deployment-wide connector egress policy. Enable private networks only when
|
# Deployment-wide connector egress policy. Enable private networks only when
|
||||||
# this installation intentionally integrates with internal services.
|
# this installation intentionally integrates with internal services.
|
||||||
@@ -409,6 +770,7 @@ FILE_STORAGE_BACKEND=local
|
|||||||
FILE_STORAGE_LOCAL_ROOT=/var/lib/govoplan/files
|
FILE_STORAGE_LOCAL_ROOT=/var/lib/govoplan/files
|
||||||
FILE_STORAGE_LOCAL_FALLBACK_ROOTS=
|
FILE_STORAGE_LOCAL_FALLBACK_ROOTS=
|
||||||
FILE_STORAGE_S3_DEPLOYMENT_MANAGED=false
|
FILE_STORAGE_S3_DEPLOYMENT_MANAGED=false
|
||||||
|
FILE_STORAGE_S3_ENDPOINT_TRUSTED=false
|
||||||
FILE_ARCHIVE_MAX_ENTRIES=10000
|
FILE_ARCHIVE_MAX_ENTRIES=10000
|
||||||
FILE_ARCHIVE_MAX_EXPANDED_BYTES=2147483648
|
FILE_ARCHIVE_MAX_EXPANDED_BYTES=2147483648
|
||||||
FILE_ARCHIVE_MAX_EXPANSION_RATIO=100
|
FILE_ARCHIVE_MAX_EXPANSION_RATIO=100
|
||||||
@@ -420,7 +782,7 @@ DEV_MAILBOX_API_ENABLED=false
|
|||||||
|
|
||||||
GOVOPLAN_MODULE_PACKAGE_CATALOG_URL=https://govoplan.add-ideas.de/catalogs/v1/channels/stable.json
|
GOVOPLAN_MODULE_PACKAGE_CATALOG_URL=https://govoplan.add-ideas.de/catalogs/v1/channels/stable.json
|
||||||
GOVOPLAN_MODULE_PACKAGE_CATALOG_TRUSTED_KEYS_FILE=/etc/govoplan/catalog-keyring.json
|
GOVOPLAN_MODULE_PACKAGE_CATALOG_TRUSTED_KEYS_FILE=/etc/govoplan/catalog-keyring.json
|
||||||
GOVOPLAN_MODULE_PACKAGE_CATALOG_APPROVED_CHANNEL=stable
|
GOVOPLAN_MODULE_PACKAGE_CATALOG_APPROVED_CHANNELS=stable
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
@@ -430,6 +792,13 @@ def _production_like_env_template(master_key: str) -> str:
|
|||||||
|
|
||||||
APP_ENV=staging
|
APP_ENV=staging
|
||||||
GOVOPLAN_INSTALL_PROFILE=production-like
|
GOVOPLAN_INSTALL_PROFILE=production-like
|
||||||
|
GOVOPLAN_INSTALLATION_ID=govoplan-production-like
|
||||||
|
GOVOPLAN_STATE_PROFILE=local
|
||||||
|
GOVOPLAN_RUNTIME_ROLE=api
|
||||||
|
GOVOPLAN_RUNTIME_HEARTBEAT_SECONDS=15
|
||||||
|
GOVOPLAN_RUNTIME_STALE_AFTER_SECONDS=60
|
||||||
|
GOVOPLAN_EXPECTED_API_REPLICAS=1
|
||||||
|
GOVOPLAN_EXPECTED_WORKER_REPLICAS=1
|
||||||
MASTER_KEY_B64={master_key}
|
MASTER_KEY_B64={master_key}
|
||||||
|
|
||||||
GOVOPLAN_PRODUCTION_LIKE_POSTGRES_DB=govoplan
|
GOVOPLAN_PRODUCTION_LIKE_POSTGRES_DB=govoplan
|
||||||
@@ -446,11 +815,13 @@ DATABASE_URL=postgresql+psycopg://govoplan:govoplan-dev@127.0.0.1:55433/govoplan
|
|||||||
GOVOPLAN_DATABASE_URL_PGTOOLS=postgresql://govoplan:govoplan-dev@127.0.0.1:55433/govoplan
|
GOVOPLAN_DATABASE_URL_PGTOOLS=postgresql://govoplan:govoplan-dev@127.0.0.1:55433/govoplan
|
||||||
REDIS_URL=redis://127.0.0.1:56379/0
|
REDIS_URL=redis://127.0.0.1:56379/0
|
||||||
CELERY_ENABLED=true
|
CELERY_ENABLED=true
|
||||||
CELERY_QUEUES=send_email,append_sent,notifications,calendar,dataflow,workflow,events,default
|
CELERY_QUEUES=send_email,append_sent,notifications,mail,calendar,dataflow,workflow,postbox,events,idm,default
|
||||||
CALENDAR_OUTBOX_TERMINAL_RETENTION_DAYS=90
|
CALENDAR_OUTBOX_TERMINAL_RETENTION_DAYS=90
|
||||||
PLATFORM_EVENT_OUTBOX_MAX_ATTEMPTS=8
|
PLATFORM_EVENT_OUTBOX_MAX_ATTEMPTS=8
|
||||||
PLATFORM_EVENT_OUTBOX_TERMINAL_RETENTION_DAYS=90
|
PLATFORM_EVENT_OUTBOX_TERMINAL_RETENTION_DAYS=90
|
||||||
SCHEDULING_CANCELLATION_NOTICE_DAYS=30
|
SCHEDULING_CANCELLATION_NOTICE_DAYS=30
|
||||||
|
SCHEDULING_PUBLIC_SELF_ENROLLMENT_ENABLED=true
|
||||||
|
SCHEDULING_PUBLIC_SELF_ENROLLMENT_MAX_CAPACITY=10000
|
||||||
|
|
||||||
GOVOPLAN_CONNECTOR_ALLOW_PRIVATE_NETWORKS=true
|
GOVOPLAN_CONNECTOR_ALLOW_PRIVATE_NETWORKS=true
|
||||||
GOVOPLAN_CONNECTOR_MAX_STRUCTURED_RESPONSE_BYTES=16777216
|
GOVOPLAN_CONNECTOR_MAX_STRUCTURED_RESPONSE_BYTES=16777216
|
||||||
@@ -474,6 +845,7 @@ AUTH_COOKIE_SECURE=false
|
|||||||
FILE_STORAGE_BACKEND=local
|
FILE_STORAGE_BACKEND=local
|
||||||
FILE_STORAGE_LOCAL_ROOT=runtime/production-like/files
|
FILE_STORAGE_LOCAL_ROOT=runtime/production-like/files
|
||||||
FILE_STORAGE_S3_DEPLOYMENT_MANAGED=false
|
FILE_STORAGE_S3_DEPLOYMENT_MANAGED=false
|
||||||
|
FILE_STORAGE_S3_ENDPOINT_TRUSTED=false
|
||||||
FILE_ARCHIVE_MAX_ENTRIES=10000
|
FILE_ARCHIVE_MAX_ENTRIES=10000
|
||||||
FILE_ARCHIVE_MAX_EXPANDED_BYTES=2147483648
|
FILE_ARCHIVE_MAX_EXPANDED_BYTES=2147483648
|
||||||
FILE_ARCHIVE_MAX_EXPANSION_RATIO=100
|
FILE_ARCHIVE_MAX_EXPANSION_RATIO=100
|
||||||
@@ -488,7 +860,11 @@ def _clean(value: str | None) -> str:
|
|||||||
|
|
||||||
|
|
||||||
def _csv(value: str | None) -> tuple[str, ...]:
|
def _csv(value: str | None) -> tuple[str, ...]:
|
||||||
return tuple(dict.fromkeys(item.strip() for item in str(value or "").split(",") if item.strip()))
|
return tuple(
|
||||||
|
dict.fromkeys(
|
||||||
|
item.strip() for item in str(value or "").split(",") if item.strip()
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def _truthy(value: str | None) -> bool:
|
def _truthy(value: str | None) -> bool:
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -1,15 +1,32 @@
|
|||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
from collections.abc import Mapping, Sequence
|
from collections.abc import AsyncIterator, Mapping, Sequence
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
from threading import RLock
|
from threading import RLock
|
||||||
|
|
||||||
from fastapi import APIRouter, Depends, FastAPI, HTTPException, Request, status
|
from fastapi import APIRouter, Depends, FastAPI, Header, HTTPException, Request, status
|
||||||
|
from sqlalchemy.exc import SQLAlchemyError
|
||||||
|
from sqlalchemy.orm import Session
|
||||||
|
|
||||||
|
from govoplan_core.auth import ApiPrincipal, get_api_principal
|
||||||
from govoplan_core.core.module_management import ModuleManagementError, REQUIRED_PLATFORM_MODULES, plan_desired_enabled_modules
|
from govoplan_core.core.module_management import ModuleManagementError, REQUIRED_PLATFORM_MODULES, plan_desired_enabled_modules
|
||||||
|
from govoplan_core.core.module_entitlements import (
|
||||||
|
ModuleEntitlementResolutionError,
|
||||||
|
TenantModuleUnavailable,
|
||||||
|
tenant_execution_scope,
|
||||||
|
)
|
||||||
|
from govoplan_core.core.module_lifecycle_recovery import (
|
||||||
|
ModuleLifecycleRecovery,
|
||||||
|
begin_runtime_graph_recovery,
|
||||||
|
canonical_sha256,
|
||||||
|
)
|
||||||
from govoplan_core.core.modules import ModuleContext, ModuleManifest
|
from govoplan_core.core.modules import ModuleContext, ModuleManifest
|
||||||
from govoplan_core.core.registry import PlatformRegistry
|
from govoplan_core.core.registry import PlatformRegistry
|
||||||
from govoplan_core.core.runtime import configure_runtime
|
from govoplan_core.core.runtime import configure_runtime
|
||||||
|
from govoplan_core.core.workflows import (
|
||||||
|
workflow_definition_contribution_provider,
|
||||||
|
)
|
||||||
|
from govoplan_core.db.session import get_session
|
||||||
from govoplan_core.server.route_validation import validate_router_can_mount
|
from govoplan_core.server.route_validation import validate_router_can_mount
|
||||||
|
|
||||||
|
|
||||||
@@ -23,11 +40,74 @@ class ModuleLifecycleResult:
|
|||||||
|
|
||||||
|
|
||||||
def require_module_active(module_id: str):
|
def require_module_active(module_id: str):
|
||||||
def dependency(request: Request) -> None:
|
async def dependency(
|
||||||
|
request: Request,
|
||||||
|
session: Session = Depends(get_session),
|
||||||
|
authorization: str | None = Header(default=None),
|
||||||
|
x_api_key: str | None = Header(default=None, alias="X-API-Key"),
|
||||||
|
) -> AsyncIterator[None]:
|
||||||
registry = getattr(request.app.state, "govoplan_registry", None)
|
registry = getattr(request.app.state, "govoplan_registry", None)
|
||||||
if isinstance(registry, PlatformRegistry) and registry.has_module(module_id):
|
if not isinstance(registry, PlatformRegistry) or not registry.has_module(module_id):
|
||||||
return
|
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail=f"Module is disabled: {module_id}")
|
||||||
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail=f"Module is disabled: {module_id}")
|
|
||||||
|
tenant_id: str | None = None
|
||||||
|
if not authorization and not x_api_key and not request.cookies:
|
||||||
|
public_resolver = registry.public_tenant_resolver(module_id)
|
||||||
|
if public_resolver is not None:
|
||||||
|
tenant_id = public_resolver(request, session)
|
||||||
|
if tenant_id is None:
|
||||||
|
yield
|
||||||
|
return
|
||||||
|
else:
|
||||||
|
try:
|
||||||
|
principal = get_api_principal(
|
||||||
|
request,
|
||||||
|
session,
|
||||||
|
authorization=authorization,
|
||||||
|
x_api_key=x_api_key,
|
||||||
|
)
|
||||||
|
except HTTPException as exc:
|
||||||
|
if exc.status_code in {
|
||||||
|
status.HTTP_401_UNAUTHORIZED,
|
||||||
|
status.HTTP_403_FORBIDDEN,
|
||||||
|
}:
|
||||||
|
yield
|
||||||
|
return
|
||||||
|
raise
|
||||||
|
if (
|
||||||
|
not isinstance(principal, ApiPrincipal)
|
||||||
|
or principal.principal.tenant_id is None
|
||||||
|
):
|
||||||
|
yield
|
||||||
|
return
|
||||||
|
tenant_id = principal.principal.tenant_id
|
||||||
|
|
||||||
|
resolver = registry.tenant_entitlement_resolver()
|
||||||
|
try:
|
||||||
|
admission = resolver.require(
|
||||||
|
session,
|
||||||
|
tenant_id=tenant_id,
|
||||||
|
module_id=module_id,
|
||||||
|
work_state="interactive",
|
||||||
|
)
|
||||||
|
except TenantModuleUnavailable as exc:
|
||||||
|
raise HTTPException(
|
||||||
|
status_code=status.HTTP_404_NOT_FOUND,
|
||||||
|
detail=f"Module is unavailable in the active tenant: {module_id}",
|
||||||
|
) from exc
|
||||||
|
except (ModuleEntitlementResolutionError, RuntimeError, SQLAlchemyError) as exc:
|
||||||
|
raise HTTPException(
|
||||||
|
status_code=status.HTTP_503_SERVICE_UNAVAILABLE,
|
||||||
|
detail="Tenant module entitlement could not be resolved.",
|
||||||
|
) from exc
|
||||||
|
request.state.govoplan_module_admission = admission
|
||||||
|
with tenant_execution_scope(
|
||||||
|
resolver,
|
||||||
|
session,
|
||||||
|
tenant_id=tenant_id,
|
||||||
|
work_state="interactive",
|
||||||
|
):
|
||||||
|
yield
|
||||||
|
|
||||||
return dependency
|
return dependency
|
||||||
|
|
||||||
@@ -96,28 +176,110 @@ class ModuleLifecycleManager:
|
|||||||
next_set = set(plan.enabled_modules)
|
next_set = set(plan.enabled_modules)
|
||||||
activated = tuple(module_id for module_id in plan.enabled_modules if module_id not in previous_set)
|
activated = tuple(module_id for module_id in plan.enabled_modules if module_id not in previous_set)
|
||||||
deactivated = tuple(module_id for module_id in previous if module_id not in next_set)
|
deactivated = tuple(module_id for module_id in previous if module_id not in next_set)
|
||||||
|
graph_changes = bool(activated or deactivated)
|
||||||
|
recovery: ModuleLifecycleRecovery | None = None
|
||||||
|
if graph_changes or migrate:
|
||||||
|
from govoplan_core.db.session import get_database
|
||||||
|
|
||||||
if migrate:
|
with get_database().session() as recovery_session:
|
||||||
self._migrate(plan.enabled_modules)
|
recovery = begin_runtime_graph_recovery(
|
||||||
|
recovery_session,
|
||||||
|
previous_modules=previous,
|
||||||
|
requested_modules=plan.enabled_modules,
|
||||||
|
migrate=migrate,
|
||||||
|
)
|
||||||
|
|
||||||
mounted = tuple(module_id for module_id in plan.enabled_modules if self._mount_module_router(module_id))
|
old_manifests = {
|
||||||
|
manifest.id: manifest for manifest in self.registry.manifests()
|
||||||
|
}
|
||||||
|
try:
|
||||||
|
if recovery is not None:
|
||||||
|
recovery.checkpoint(
|
||||||
|
kind="runtime-graph-effect-started",
|
||||||
|
summary="Runtime module graph entered its mutation boundary",
|
||||||
|
evidence={
|
||||||
|
"activated_sha256": canonical_sha256(activated),
|
||||||
|
"deactivated_sha256": canonical_sha256(deactivated),
|
||||||
|
"migrate": migrate,
|
||||||
|
},
|
||||||
|
effect_started=True,
|
||||||
|
)
|
||||||
|
|
||||||
old_manifests = {manifest.id: manifest for manifest in self.registry.manifests()}
|
if migrate:
|
||||||
for module_id in deactivated:
|
self._migrate(plan.enabled_modules)
|
||||||
hook = old_manifests[module_id].on_deactivate
|
|
||||||
if hook is not None:
|
|
||||||
hook(self.context)
|
|
||||||
|
|
||||||
self.registry.replace(self.available_modules[module_id] for module_id in plan.enabled_modules)
|
mounted = tuple(module_id for module_id in plan.enabled_modules if self._mount_module_router(module_id))
|
||||||
self.configure_runtime()
|
|
||||||
|
|
||||||
for module_id in activated:
|
for module_id in deactivated:
|
||||||
hook = self.available_modules[module_id].on_activate
|
hook = old_manifests[module_id].on_deactivate
|
||||||
if hook is not None:
|
if hook is not None:
|
||||||
hook(self.context)
|
hook(self.context)
|
||||||
|
|
||||||
if self._app is not None:
|
self.registry.replace(self.available_modules[module_id] for module_id in plan.enabled_modules)
|
||||||
self._app.openapi_schema = None
|
self.configure_runtime()
|
||||||
|
|
||||||
|
for module_id in activated:
|
||||||
|
hook = self.available_modules[module_id].on_activate
|
||||||
|
if hook is not None:
|
||||||
|
hook(self.context)
|
||||||
|
|
||||||
|
reconciliation = self.reconcile_workflow_definitions()
|
||||||
|
|
||||||
|
if self._app is not None:
|
||||||
|
self._app.openapi_schema = None
|
||||||
|
|
||||||
|
if recovery is not None:
|
||||||
|
from govoplan_core.db.session import get_database
|
||||||
|
|
||||||
|
with get_database().session() as recovery_session:
|
||||||
|
recovery.succeed(
|
||||||
|
recovery_session,
|
||||||
|
evidence={
|
||||||
|
"active_graph_sha256": canonical_sha256(
|
||||||
|
self.active_module_ids()
|
||||||
|
),
|
||||||
|
"mounted_graph_sha256": canonical_sha256(
|
||||||
|
self.mounted_module_ids()
|
||||||
|
),
|
||||||
|
"workflow_reconciliation_sha256": canonical_sha256(
|
||||||
|
reconciliation
|
||||||
|
),
|
||||||
|
},
|
||||||
|
commit_projection=False,
|
||||||
|
)
|
||||||
|
except Exception as exc:
|
||||||
|
self.registry.replace(old_manifests.values())
|
||||||
|
self.configure_runtime()
|
||||||
|
if self._app is not None:
|
||||||
|
self._app.openapi_schema = None
|
||||||
|
if recovery is not None:
|
||||||
|
from govoplan_core.db.session import get_database
|
||||||
|
|
||||||
|
recovery.unresolved(
|
||||||
|
summary="Runtime graph mutation did not reach verified completion",
|
||||||
|
evidence={
|
||||||
|
"error_type": type(exc).__name__,
|
||||||
|
"previous_graph_sha256": canonical_sha256(previous),
|
||||||
|
"registry_restored": True,
|
||||||
|
"migrate": migrate,
|
||||||
|
},
|
||||||
|
outcome_unknown=migrate,
|
||||||
|
)
|
||||||
|
if not migrate:
|
||||||
|
with get_database().session() as recovery_session:
|
||||||
|
recovery.recovered(
|
||||||
|
recovery_session,
|
||||||
|
evidence={
|
||||||
|
"active_graph_sha256": canonical_sha256(
|
||||||
|
self.active_module_ids()
|
||||||
|
),
|
||||||
|
"previous_graph_restored": (
|
||||||
|
self.active_module_ids() == previous
|
||||||
|
),
|
||||||
|
},
|
||||||
|
summary="Previous runtime module graph was restored",
|
||||||
|
)
|
||||||
|
raise
|
||||||
|
|
||||||
return ModuleLifecycleResult(
|
return ModuleLifecycleResult(
|
||||||
enabled_modules=plan.enabled_modules,
|
enabled_modules=plan.enabled_modules,
|
||||||
@@ -127,6 +289,24 @@ class ModuleLifecycleManager:
|
|||||||
migrations_applied=migrate,
|
migrations_applied=migrate,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def reconcile_workflow_definitions(self) -> Mapping[str, object]:
|
||||||
|
if not any(
|
||||||
|
manifest.workflow_definitions for manifest in self.registry.manifests()
|
||||||
|
):
|
||||||
|
return {"skipped": True, "reason": "no_contributions"}
|
||||||
|
provider = workflow_definition_contribution_provider(self.registry)
|
||||||
|
if provider is None:
|
||||||
|
return {"skipped": True, "reason": "provider_unavailable"}
|
||||||
|
|
||||||
|
from govoplan_core.db.session import get_database
|
||||||
|
|
||||||
|
with get_database().session() as session:
|
||||||
|
result = provider.reconcile(session)
|
||||||
|
session.commit()
|
||||||
|
if self._app is not None:
|
||||||
|
self._app.state.govoplan_workflow_reconciliation = dict(result)
|
||||||
|
return dict(result)
|
||||||
|
|
||||||
def _mount_module_router(self, module_id: str) -> bool:
|
def _mount_module_router(self, module_id: str) -> bool:
|
||||||
if module_id in self._mounted_modules:
|
if module_id in self._mounted_modules:
|
||||||
return False
|
return False
|
||||||
|
|||||||
@@ -2,11 +2,14 @@ from __future__ import annotations
|
|||||||
|
|
||||||
from collections.abc import Mapping
|
from collections.abc import Mapping
|
||||||
from dataclasses import dataclass, field
|
from dataclasses import dataclass, field
|
||||||
|
from datetime import datetime
|
||||||
from typing import Protocol, runtime_checkable
|
from typing import Protocol, runtime_checkable
|
||||||
|
|
||||||
|
|
||||||
CAPABILITY_MAIL_DELIVERY_OUTBOX = "mail.delivery_outbox"
|
CAPABILITY_MAIL_DELIVERY_OUTBOX = "mail.delivery_outbox"
|
||||||
CAPABILITY_MAIL_NOTIFICATION_DELIVERY = "mail.notificationDelivery"
|
CAPABILITY_MAIL_NOTIFICATION_DELIVERY = "mail.notificationDelivery"
|
||||||
|
CAPABILITY_MAIL_BOUNCE_PROCESSING = "mail.bounce_processing"
|
||||||
|
CAPABILITY_MAIL_POSTBOX_BRIDGE = "mail.postbox_bridge"
|
||||||
|
|
||||||
|
|
||||||
@dataclass(frozen=True, slots=True)
|
@dataclass(frozen=True, slots=True)
|
||||||
@@ -36,7 +39,6 @@ class NotificationMailDeliveryProvider(Protocol):
|
|||||||
) -> Mapping[str, object]:
|
) -> Mapping[str, object]:
|
||||||
...
|
...
|
||||||
|
|
||||||
|
|
||||||
@runtime_checkable
|
@runtime_checkable
|
||||||
class MailDeliveryOutboxProvider(Protocol):
|
class MailDeliveryOutboxProvider(Protocol):
|
||||||
"""Stable worker boundary for Mail-owned external delivery effects."""
|
"""Stable worker boundary for Mail-owned external delivery effects."""
|
||||||
@@ -55,11 +57,99 @@ class MailDeliveryOutboxProvider(Protocol):
|
|||||||
self,
|
self,
|
||||||
session: object,
|
session: object,
|
||||||
*,
|
*,
|
||||||
|
tenant_id: str | None = None,
|
||||||
limit: int = 250,
|
limit: int = 250,
|
||||||
) -> Mapping[str, object]:
|
) -> Mapping[str, object]:
|
||||||
...
|
...
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass(frozen=True, slots=True)
|
||||||
|
class MailBounceObservationRef:
|
||||||
|
id: str
|
||||||
|
tenant_id: str
|
||||||
|
profile_id: str
|
||||||
|
folder: str
|
||||||
|
uid: str
|
||||||
|
original_message_id: str | None
|
||||||
|
command_id: str | None
|
||||||
|
recipient: str | None
|
||||||
|
action: str
|
||||||
|
status_code: str | None
|
||||||
|
diagnostic: str | None
|
||||||
|
permanent: bool
|
||||||
|
observed_at: datetime
|
||||||
|
matched: bool
|
||||||
|
evidence: Mapping[str, object] = field(default_factory=dict)
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass(frozen=True, slots=True)
|
||||||
|
class MailPostboxBridgeRequest:
|
||||||
|
tenant_id: str
|
||||||
|
target: object
|
||||||
|
profile_id: str
|
||||||
|
folder: str
|
||||||
|
uid: str
|
||||||
|
uidvalidity: str
|
||||||
|
raw_message: bytes
|
||||||
|
classification: str = "internal"
|
||||||
|
metadata: Mapping[str, object] = field(default_factory=dict)
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass(frozen=True, slots=True)
|
||||||
|
class MailPostboxBridgeResult:
|
||||||
|
postbox_id: str
|
||||||
|
message_id: str
|
||||||
|
delivery_id: str
|
||||||
|
duplicate: bool
|
||||||
|
source_digest: str
|
||||||
|
|
||||||
|
|
||||||
|
@runtime_checkable
|
||||||
|
class MailBounceProcessingProvider(Protocol):
|
||||||
|
"""Mail-owned DSN ingestion and durable correlation boundary."""
|
||||||
|
|
||||||
|
def process_raw_message(
|
||||||
|
self,
|
||||||
|
session: object,
|
||||||
|
*,
|
||||||
|
tenant_id: str,
|
||||||
|
profile_id: str,
|
||||||
|
folder: str,
|
||||||
|
uid: str,
|
||||||
|
raw_message: bytes,
|
||||||
|
) -> tuple[MailBounceObservationRef, ...]:
|
||||||
|
...
|
||||||
|
|
||||||
|
def scan_due(
|
||||||
|
self,
|
||||||
|
session: object,
|
||||||
|
*,
|
||||||
|
tenant_id: str | None = None,
|
||||||
|
limit: int = 100,
|
||||||
|
) -> Mapping[str, object]:
|
||||||
|
...
|
||||||
|
|
||||||
|
def observations_for_commands(
|
||||||
|
self,
|
||||||
|
session: object,
|
||||||
|
*,
|
||||||
|
tenant_id: str,
|
||||||
|
command_ids: tuple[str, ...],
|
||||||
|
) -> Mapping[str, tuple[MailBounceObservationRef, ...]]:
|
||||||
|
...
|
||||||
|
|
||||||
|
|
||||||
|
@runtime_checkable
|
||||||
|
class MailPostboxBridgeProvider(Protocol):
|
||||||
|
"""Translate one immutable Mail observation into Postbox delivery."""
|
||||||
|
|
||||||
|
def bridge_message(
|
||||||
|
self,
|
||||||
|
session: object,
|
||||||
|
request: MailPostboxBridgeRequest,
|
||||||
|
) -> MailPostboxBridgeResult: ...
|
||||||
|
|
||||||
|
|
||||||
def notification_mail_delivery_provider(
|
def notification_mail_delivery_provider(
|
||||||
registry: object | None,
|
registry: object | None,
|
||||||
) -> NotificationMailDeliveryProvider | None:
|
) -> NotificationMailDeliveryProvider | None:
|
||||||
@@ -76,3 +166,39 @@ def notification_mail_delivery_provider(
|
|||||||
"NotificationMailDeliveryProvider"
|
"NotificationMailDeliveryProvider"
|
||||||
)
|
)
|
||||||
return provider
|
return provider
|
||||||
|
|
||||||
|
|
||||||
|
def mail_bounce_processing_provider(
|
||||||
|
registry: object | None,
|
||||||
|
) -> MailBounceProcessingProvider | None:
|
||||||
|
if (
|
||||||
|
registry is None
|
||||||
|
or not hasattr(registry, "has_capability")
|
||||||
|
or not registry.has_capability(CAPABILITY_MAIL_BOUNCE_PROCESSING)
|
||||||
|
):
|
||||||
|
return None
|
||||||
|
provider = registry.require_capability(CAPABILITY_MAIL_BOUNCE_PROCESSING)
|
||||||
|
if not isinstance(provider, MailBounceProcessingProvider):
|
||||||
|
raise TypeError(
|
||||||
|
"mail.bounce_processing provider does not implement "
|
||||||
|
"MailBounceProcessingProvider"
|
||||||
|
)
|
||||||
|
return provider
|
||||||
|
|
||||||
|
|
||||||
|
def mail_postbox_bridge_provider(
|
||||||
|
registry: object | None,
|
||||||
|
) -> MailPostboxBridgeProvider | None:
|
||||||
|
if (
|
||||||
|
registry is None
|
||||||
|
or not hasattr(registry, "has_capability")
|
||||||
|
or not registry.has_capability(CAPABILITY_MAIL_POSTBOX_BRIDGE)
|
||||||
|
):
|
||||||
|
return None
|
||||||
|
provider = registry.require_capability(CAPABILITY_MAIL_POSTBOX_BRIDGE)
|
||||||
|
if not isinstance(provider, MailPostboxBridgeProvider):
|
||||||
|
raise TypeError(
|
||||||
|
"mail.postbox_bridge provider does not implement "
|
||||||
|
"MailPostboxBridgeProvider"
|
||||||
|
)
|
||||||
|
return provider
|
||||||
|
|||||||
@@ -0,0 +1,846 @@
|
|||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
from collections import OrderedDict
|
||||||
|
from collections.abc import Iterable, Iterator, Mapping
|
||||||
|
from contextlib import contextmanager
|
||||||
|
from contextvars import ContextVar
|
||||||
|
from dataclasses import dataclass
|
||||||
|
from threading import RLock
|
||||||
|
from time import monotonic
|
||||||
|
from typing import Any, Literal
|
||||||
|
|
||||||
|
from govoplan_core.core.modules import ModuleManifest
|
||||||
|
|
||||||
|
|
||||||
|
MODULE_ENTITLEMENTS_KEY = "module_entitlements"
|
||||||
|
MODULE_ENTITLEMENT_SCHEMA_VERSION = 1
|
||||||
|
TENANT_PROTECTED_MODULES = ("access", "admin")
|
||||||
|
|
||||||
|
|
||||||
|
class ModuleEntitlementError(ValueError):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
class ModuleEntitlementConflict(ModuleEntitlementError):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
class ModuleEntitlementResolutionError(ModuleEntitlementError):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
class TenantModuleUnavailable(ModuleEntitlementError):
|
||||||
|
def __init__(self, admission: "TenantModuleAdmission") -> None:
|
||||||
|
self.admission = admission
|
||||||
|
super().__init__(admission.reason)
|
||||||
|
|
||||||
|
|
||||||
|
class TenantModuleOperatorActionRequired(ModuleEntitlementError):
|
||||||
|
def __init__(self, admission: "TenantModuleAdmission") -> None:
|
||||||
|
self.admission = admission
|
||||||
|
super().__init__(admission.reason)
|
||||||
|
|
||||||
|
|
||||||
|
TenantWorkState = Literal["interactive", "new", "accepted"]
|
||||||
|
TenantAdmissionDisposition = Literal[
|
||||||
|
"allowed",
|
||||||
|
"rejected",
|
||||||
|
"operator_action_required",
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass(frozen=True, slots=True)
|
||||||
|
class TenantModuleItem:
|
||||||
|
id: str
|
||||||
|
name: str
|
||||||
|
dependencies: tuple[str, ...]
|
||||||
|
runtime_active: bool
|
||||||
|
availability: str
|
||||||
|
selected: bool
|
||||||
|
effective: bool
|
||||||
|
forced: bool
|
||||||
|
derived_dependency: bool
|
||||||
|
tenant_can_toggle: bool
|
||||||
|
reason: str | None = None
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass(frozen=True, slots=True)
|
||||||
|
class TenantModuleEntitlementState:
|
||||||
|
revision: int
|
||||||
|
configured: bool
|
||||||
|
available_modules: tuple[str, ...]
|
||||||
|
forced_modules: tuple[str, ...]
|
||||||
|
selected_modules: tuple[str, ...]
|
||||||
|
effective_modules: tuple[str, ...]
|
||||||
|
derived_dependencies: tuple[str, ...]
|
||||||
|
modules: tuple[TenantModuleItem, ...]
|
||||||
|
diagnostics: tuple[dict[str, str], ...] = ()
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass(frozen=True, slots=True)
|
||||||
|
class TenantModuleAdmission:
|
||||||
|
tenant_id: str
|
||||||
|
module_id: str
|
||||||
|
revision: int
|
||||||
|
work_state: TenantWorkState
|
||||||
|
allowed: bool
|
||||||
|
disposition: TenantAdmissionDisposition
|
||||||
|
reason: str
|
||||||
|
|
||||||
|
def payload(self) -> dict[str, object]:
|
||||||
|
return {
|
||||||
|
"tenant_id": self.tenant_id,
|
||||||
|
"module_id": self.module_id,
|
||||||
|
"entitlement_revision": self.revision,
|
||||||
|
"work_state": self.work_state,
|
||||||
|
"allowed": self.allowed,
|
||||||
|
"disposition": self.disposition,
|
||||||
|
"reason": self.reason,
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass(frozen=True, slots=True)
|
||||||
|
class _CachedTenantEntitlement:
|
||||||
|
expires_at: float
|
||||||
|
tenant_active: bool
|
||||||
|
state: TenantModuleEntitlementState
|
||||||
|
|
||||||
|
|
||||||
|
class TenantModuleEntitlementResolver:
|
||||||
|
"""Resolve tenant-effective modules with bounded process-local caching.
|
||||||
|
|
||||||
|
Cache entries are explicitly invalidated by local mutations and expire
|
||||||
|
quickly so changes made on another application node become authoritative
|
||||||
|
without requiring a database lookup for every capability call.
|
||||||
|
"""
|
||||||
|
|
||||||
|
def __init__(
|
||||||
|
self,
|
||||||
|
registry: object,
|
||||||
|
*,
|
||||||
|
ttl_seconds: float = 5.0,
|
||||||
|
max_entries: int = 2048,
|
||||||
|
) -> None:
|
||||||
|
self._registry = registry
|
||||||
|
self._ttl_seconds = max(0.0, min(float(ttl_seconds), 300.0))
|
||||||
|
self._max_entries = max(1, int(max_entries))
|
||||||
|
self._cache: OrderedDict[str, _CachedTenantEntitlement] = OrderedDict()
|
||||||
|
self._lock = RLock()
|
||||||
|
|
||||||
|
def resolve(
|
||||||
|
self,
|
||||||
|
session: object,
|
||||||
|
tenant_id: str,
|
||||||
|
) -> TenantModuleEntitlementState:
|
||||||
|
normalized_tenant_id = str(tenant_id or "").strip()
|
||||||
|
if not normalized_tenant_id:
|
||||||
|
raise ModuleEntitlementResolutionError("Tenant id is required")
|
||||||
|
|
||||||
|
cached = self._cached(normalized_tenant_id)
|
||||||
|
if cached is not None:
|
||||||
|
if not cached.tenant_active:
|
||||||
|
raise ModuleEntitlementResolutionError(
|
||||||
|
f"Tenant is inactive: {normalized_tenant_id}"
|
||||||
|
)
|
||||||
|
return cached.state
|
||||||
|
|
||||||
|
from govoplan_core.tenancy.scope import Tenant
|
||||||
|
|
||||||
|
getter = getattr(session, "get", None)
|
||||||
|
if not callable(getter):
|
||||||
|
raise ModuleEntitlementResolutionError(
|
||||||
|
"Tenant module entitlement resolution requires a database session"
|
||||||
|
)
|
||||||
|
tenant = getter(Tenant, normalized_tenant_id)
|
||||||
|
if tenant is None:
|
||||||
|
raise ModuleEntitlementResolutionError(
|
||||||
|
f"Tenant is unavailable: {normalized_tenant_id}"
|
||||||
|
)
|
||||||
|
state = self._state_from_settings(getattr(tenant, "settings", None))
|
||||||
|
tenant_active = bool(getattr(tenant, "is_active", False))
|
||||||
|
self._store(normalized_tenant_id, tenant_active=tenant_active, state=state)
|
||||||
|
if not tenant_active:
|
||||||
|
raise ModuleEntitlementResolutionError(
|
||||||
|
f"Tenant is inactive: {normalized_tenant_id}"
|
||||||
|
)
|
||||||
|
return state
|
||||||
|
|
||||||
|
def admission(
|
||||||
|
self,
|
||||||
|
session: object,
|
||||||
|
*,
|
||||||
|
tenant_id: str,
|
||||||
|
module_id: str,
|
||||||
|
work_state: TenantWorkState = "interactive",
|
||||||
|
) -> TenantModuleAdmission:
|
||||||
|
if work_state not in {"interactive", "new", "accepted"}:
|
||||||
|
raise ModuleEntitlementError(f"Unsupported tenant work state: {work_state}")
|
||||||
|
normalized_module_id = str(module_id or "").strip()
|
||||||
|
if not normalized_module_id:
|
||||||
|
raise ModuleEntitlementError("Module id is required")
|
||||||
|
state = self.resolve(session, tenant_id)
|
||||||
|
allowed = normalized_module_id in state.effective_modules
|
||||||
|
if allowed:
|
||||||
|
return TenantModuleAdmission(
|
||||||
|
tenant_id=str(tenant_id),
|
||||||
|
module_id=normalized_module_id,
|
||||||
|
revision=state.revision,
|
||||||
|
work_state=work_state,
|
||||||
|
allowed=True,
|
||||||
|
disposition="allowed",
|
||||||
|
reason="The module is effective for this tenant.",
|
||||||
|
)
|
||||||
|
accepted = work_state == "accepted"
|
||||||
|
return TenantModuleAdmission(
|
||||||
|
tenant_id=str(tenant_id),
|
||||||
|
module_id=normalized_module_id,
|
||||||
|
revision=state.revision,
|
||||||
|
work_state=work_state,
|
||||||
|
allowed=False,
|
||||||
|
disposition=(
|
||||||
|
"operator_action_required" if accepted else "rejected"
|
||||||
|
),
|
||||||
|
reason=(
|
||||||
|
"Accepted durable work was preserved because the owning module "
|
||||||
|
"is no longer effective for this tenant; an operator must resume "
|
||||||
|
"the module or resolve the work explicitly."
|
||||||
|
if accepted
|
||||||
|
else "The module is not effective for this tenant."
|
||||||
|
),
|
||||||
|
)
|
||||||
|
|
||||||
|
def require(
|
||||||
|
self,
|
||||||
|
session: object,
|
||||||
|
*,
|
||||||
|
tenant_id: str,
|
||||||
|
module_id: str,
|
||||||
|
work_state: TenantWorkState = "interactive",
|
||||||
|
) -> TenantModuleAdmission:
|
||||||
|
admission = self.admission(
|
||||||
|
session,
|
||||||
|
tenant_id=tenant_id,
|
||||||
|
module_id=module_id,
|
||||||
|
work_state=work_state,
|
||||||
|
)
|
||||||
|
if admission.allowed:
|
||||||
|
return admission
|
||||||
|
if admission.disposition == "operator_action_required":
|
||||||
|
raise TenantModuleOperatorActionRequired(admission)
|
||||||
|
raise TenantModuleUnavailable(admission)
|
||||||
|
|
||||||
|
def effective_tenant_ids(
|
||||||
|
self,
|
||||||
|
session: object,
|
||||||
|
*,
|
||||||
|
module_id: str,
|
||||||
|
) -> tuple[str, ...]:
|
||||||
|
"""Return active tenants that may admit new work for one module."""
|
||||||
|
|
||||||
|
return tuple(
|
||||||
|
admission.tenant_id
|
||||||
|
for admission in self.active_tenant_admissions(
|
||||||
|
session,
|
||||||
|
module_id=module_id,
|
||||||
|
work_state="new",
|
||||||
|
)
|
||||||
|
if admission.allowed
|
||||||
|
)
|
||||||
|
|
||||||
|
def active_tenant_admissions(
|
||||||
|
self,
|
||||||
|
session: object,
|
||||||
|
*,
|
||||||
|
module_id: str,
|
||||||
|
work_state: TenantWorkState = "new",
|
||||||
|
) -> tuple[TenantModuleAdmission, ...]:
|
||||||
|
"""Resolve one admission per active tenant with a single DB query."""
|
||||||
|
|
||||||
|
from govoplan_core.tenancy.scope import Tenant
|
||||||
|
|
||||||
|
query = getattr(session, "query", None)
|
||||||
|
if not callable(query):
|
||||||
|
raise ModuleEntitlementResolutionError(
|
||||||
|
"Tenant module entitlement resolution requires a database session"
|
||||||
|
)
|
||||||
|
tenants = (
|
||||||
|
query(Tenant)
|
||||||
|
.filter(Tenant.is_active.is_(True))
|
||||||
|
.order_by(Tenant.id.asc())
|
||||||
|
.all()
|
||||||
|
)
|
||||||
|
admissions: list[TenantModuleAdmission] = []
|
||||||
|
for tenant in tenants:
|
||||||
|
state = self._state_from_settings(getattr(tenant, "settings", None))
|
||||||
|
self._store(tenant.id, tenant_active=True, state=state)
|
||||||
|
allowed = module_id in state.effective_modules
|
||||||
|
accepted = work_state == "accepted"
|
||||||
|
admissions.append(
|
||||||
|
TenantModuleAdmission(
|
||||||
|
tenant_id=tenant.id,
|
||||||
|
module_id=module_id,
|
||||||
|
revision=state.revision,
|
||||||
|
work_state=work_state,
|
||||||
|
allowed=allowed,
|
||||||
|
disposition=(
|
||||||
|
"allowed"
|
||||||
|
if allowed
|
||||||
|
else "operator_action_required"
|
||||||
|
if accepted
|
||||||
|
else "rejected"
|
||||||
|
),
|
||||||
|
reason=(
|
||||||
|
"The module is effective for this tenant."
|
||||||
|
if allowed
|
||||||
|
else "Accepted durable work was preserved because the owning module is no longer effective for this tenant; an operator must resume the module or resolve the work explicitly."
|
||||||
|
if accepted
|
||||||
|
else "The module is not effective for this tenant."
|
||||||
|
),
|
||||||
|
)
|
||||||
|
)
|
||||||
|
return tuple(admissions)
|
||||||
|
|
||||||
|
def invalidate(self, tenant_id: str | None = None) -> None:
|
||||||
|
with self._lock:
|
||||||
|
if tenant_id is None:
|
||||||
|
self._cache.clear()
|
||||||
|
else:
|
||||||
|
self._cache.pop(str(tenant_id), None)
|
||||||
|
|
||||||
|
def _state_from_settings(
|
||||||
|
self,
|
||||||
|
settings: Mapping[str, object] | None,
|
||||||
|
) -> TenantModuleEntitlementState:
|
||||||
|
manifests_method = getattr(self._registry, "manifests", None)
|
||||||
|
if not callable(manifests_method):
|
||||||
|
raise ModuleEntitlementResolutionError(
|
||||||
|
"Tenant module entitlement resolver has no platform registry"
|
||||||
|
)
|
||||||
|
manifests = {manifest.id: manifest for manifest in manifests_method()}
|
||||||
|
return tenant_module_entitlement_state(
|
||||||
|
settings,
|
||||||
|
manifests,
|
||||||
|
runtime_active_modules=manifests,
|
||||||
|
)
|
||||||
|
|
||||||
|
def _cached(self, tenant_id: str) -> _CachedTenantEntitlement | None:
|
||||||
|
now = monotonic()
|
||||||
|
with self._lock:
|
||||||
|
cached = self._cache.get(tenant_id)
|
||||||
|
if cached is None:
|
||||||
|
return None
|
||||||
|
if cached.expires_at <= now:
|
||||||
|
self._cache.pop(tenant_id, None)
|
||||||
|
return None
|
||||||
|
self._cache.move_to_end(tenant_id)
|
||||||
|
return cached
|
||||||
|
|
||||||
|
def _store(
|
||||||
|
self,
|
||||||
|
tenant_id: str,
|
||||||
|
*,
|
||||||
|
tenant_active: bool,
|
||||||
|
state: TenantModuleEntitlementState,
|
||||||
|
) -> None:
|
||||||
|
if self._ttl_seconds <= 0:
|
||||||
|
return
|
||||||
|
with self._lock:
|
||||||
|
self._cache[str(tenant_id)] = _CachedTenantEntitlement(
|
||||||
|
expires_at=monotonic() + self._ttl_seconds,
|
||||||
|
tenant_active=tenant_active,
|
||||||
|
state=state,
|
||||||
|
)
|
||||||
|
self._cache.move_to_end(str(tenant_id))
|
||||||
|
while len(self._cache) > self._max_entries:
|
||||||
|
self._cache.popitem(last=False)
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass(frozen=True, slots=True)
|
||||||
|
class TenantExecutionContext:
|
||||||
|
resolver: TenantModuleEntitlementResolver
|
||||||
|
session: object
|
||||||
|
tenant_id: str
|
||||||
|
work_state: TenantWorkState
|
||||||
|
|
||||||
|
def require_module(self, module_id: str) -> TenantModuleAdmission:
|
||||||
|
return self.resolver.require(
|
||||||
|
self.session,
|
||||||
|
tenant_id=self.tenant_id,
|
||||||
|
module_id=module_id,
|
||||||
|
work_state=self.work_state,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
_TENANT_EXECUTION_CONTEXT: ContextVar[TenantExecutionContext | None] = ContextVar(
|
||||||
|
"govoplan_tenant_execution_context",
|
||||||
|
default=None,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def current_tenant_execution_context() -> TenantExecutionContext | None:
|
||||||
|
return _TENANT_EXECUTION_CONTEXT.get()
|
||||||
|
|
||||||
|
|
||||||
|
@contextmanager
|
||||||
|
def tenant_execution_scope(
|
||||||
|
resolver: TenantModuleEntitlementResolver,
|
||||||
|
session: object,
|
||||||
|
*,
|
||||||
|
tenant_id: str,
|
||||||
|
work_state: TenantWorkState = "interactive",
|
||||||
|
) -> Iterator[TenantExecutionContext]:
|
||||||
|
context = TenantExecutionContext(
|
||||||
|
resolver=resolver,
|
||||||
|
session=session,
|
||||||
|
tenant_id=str(tenant_id),
|
||||||
|
work_state=work_state,
|
||||||
|
)
|
||||||
|
token = _TENANT_EXECUTION_CONTEXT.set(context)
|
||||||
|
try:
|
||||||
|
yield context
|
||||||
|
finally:
|
||||||
|
_TENANT_EXECUTION_CONTEXT.reset(token)
|
||||||
|
|
||||||
|
|
||||||
|
def tenant_module_entitlement_state(
|
||||||
|
settings: Mapping[str, object] | None,
|
||||||
|
manifests: Mapping[str, ModuleManifest],
|
||||||
|
*,
|
||||||
|
runtime_active_modules: Iterable[str] | None = None,
|
||||||
|
protected_modules: Iterable[str] = TENANT_PROTECTED_MODULES,
|
||||||
|
) -> TenantModuleEntitlementState:
|
||||||
|
module_ids = tuple(sorted(manifests))
|
||||||
|
known = set(module_ids)
|
||||||
|
runtime_active = (
|
||||||
|
known
|
||||||
|
if runtime_active_modules is None
|
||||||
|
else known.intersection(_normalized_ids(runtime_active_modules))
|
||||||
|
)
|
||||||
|
protected = known.intersection(_normalized_ids(protected_modules))
|
||||||
|
raw_document = (settings or {}).get(MODULE_ENTITLEMENTS_KEY)
|
||||||
|
configured = isinstance(raw_document, Mapping)
|
||||||
|
diagnostics: list[dict[str, str]] = []
|
||||||
|
|
||||||
|
if not configured:
|
||||||
|
revision = 0
|
||||||
|
requested_available = set(known)
|
||||||
|
requested_forced = set(protected)
|
||||||
|
requested_selected = set(known)
|
||||||
|
else:
|
||||||
|
document = raw_document
|
||||||
|
revision = _revision(document.get("revision"), diagnostics)
|
||||||
|
system_policy = document.get("system_policy")
|
||||||
|
tenant_selection = document.get("tenant_selection")
|
||||||
|
if not isinstance(system_policy, Mapping) or not isinstance(
|
||||||
|
tenant_selection, Mapping
|
||||||
|
):
|
||||||
|
diagnostics.append(
|
||||||
|
_diagnostic(
|
||||||
|
"module_entitlements.invalid_document",
|
||||||
|
"The tenant module entitlement document is malformed and was restricted to protected modules.",
|
||||||
|
)
|
||||||
|
)
|
||||||
|
requested_available = set(protected)
|
||||||
|
requested_forced = set(protected)
|
||||||
|
requested_selected = set()
|
||||||
|
else:
|
||||||
|
requested_available = _configured_ids(
|
||||||
|
system_policy.get("available_modules"),
|
||||||
|
field="system_policy.available_modules",
|
||||||
|
known=known,
|
||||||
|
fallback=protected,
|
||||||
|
diagnostics=diagnostics,
|
||||||
|
)
|
||||||
|
requested_forced = _configured_ids(
|
||||||
|
system_policy.get("forced_modules"),
|
||||||
|
field="system_policy.forced_modules",
|
||||||
|
known=known,
|
||||||
|
fallback=protected,
|
||||||
|
diagnostics=diagnostics,
|
||||||
|
)
|
||||||
|
requested_selected = _configured_ids(
|
||||||
|
tenant_selection.get("enabled_modules"),
|
||||||
|
field="tenant_selection.enabled_modules",
|
||||||
|
known=known,
|
||||||
|
fallback=(),
|
||||||
|
diagnostics=diagnostics,
|
||||||
|
)
|
||||||
|
|
||||||
|
available, missing_available = _dependency_closure(
|
||||||
|
requested_available | requested_forced | protected,
|
||||||
|
manifests,
|
||||||
|
)
|
||||||
|
forced, missing_forced = _dependency_closure(
|
||||||
|
requested_forced | protected,
|
||||||
|
manifests,
|
||||||
|
)
|
||||||
|
selected = requested_selected.intersection(available)
|
||||||
|
effective_candidates, missing_selected = _dependency_closure(
|
||||||
|
selected | forced,
|
||||||
|
manifests,
|
||||||
|
)
|
||||||
|
effective_candidates.intersection_update(available)
|
||||||
|
effective = effective_candidates.intersection(runtime_active)
|
||||||
|
derived = effective_candidates - selected - forced
|
||||||
|
|
||||||
|
for module_id in sorted(
|
||||||
|
missing_available | missing_forced | missing_selected
|
||||||
|
):
|
||||||
|
diagnostics.append(
|
||||||
|
_diagnostic(
|
||||||
|
"module_entitlements.missing_dependency",
|
||||||
|
f"A selected module requires unavailable dependency {module_id}.",
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
items: list[TenantModuleItem] = []
|
||||||
|
for module_id in module_ids:
|
||||||
|
manifest = manifests[module_id]
|
||||||
|
is_available = module_id in available
|
||||||
|
is_forced = module_id in forced
|
||||||
|
is_selected = module_id in selected
|
||||||
|
is_derived = module_id in derived
|
||||||
|
is_runtime_active = module_id in runtime_active
|
||||||
|
is_effective = module_id in effective
|
||||||
|
reason: str | None = None
|
||||||
|
if not is_available:
|
||||||
|
reason = "Unavailable by system policy."
|
||||||
|
elif is_forced:
|
||||||
|
reason = "Required by system policy or a protected platform dependency."
|
||||||
|
elif is_derived:
|
||||||
|
reason = "Required by another selected module."
|
||||||
|
elif not is_runtime_active and (is_selected or is_forced):
|
||||||
|
reason = "Selected for this tenant, but the module is not active in the deployment."
|
||||||
|
items.append(
|
||||||
|
TenantModuleItem(
|
||||||
|
id=module_id,
|
||||||
|
name=manifest.name,
|
||||||
|
dependencies=tuple(manifest.dependencies),
|
||||||
|
runtime_active=is_runtime_active,
|
||||||
|
availability=(
|
||||||
|
"forced" if is_forced else "available" if is_available else "unavailable"
|
||||||
|
),
|
||||||
|
selected=is_selected,
|
||||||
|
effective=is_effective,
|
||||||
|
forced=is_forced,
|
||||||
|
derived_dependency=is_derived,
|
||||||
|
tenant_can_toggle=is_available and not is_forced and not is_derived,
|
||||||
|
reason=reason,
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
return TenantModuleEntitlementState(
|
||||||
|
revision=revision,
|
||||||
|
configured=configured,
|
||||||
|
available_modules=tuple(sorted(available)),
|
||||||
|
forced_modules=tuple(sorted(forced)),
|
||||||
|
selected_modules=tuple(sorted(selected)),
|
||||||
|
effective_modules=tuple(sorted(effective)),
|
||||||
|
derived_dependencies=tuple(sorted(derived)),
|
||||||
|
modules=tuple(items),
|
||||||
|
diagnostics=tuple(diagnostics),
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def update_system_tenant_module_policy(
|
||||||
|
settings: Mapping[str, object] | None,
|
||||||
|
manifests: Mapping[str, ModuleManifest],
|
||||||
|
*,
|
||||||
|
available_modules: Iterable[str],
|
||||||
|
forced_modules: Iterable[str],
|
||||||
|
enabled_modules: Iterable[str],
|
||||||
|
expected_revision: int | None,
|
||||||
|
runtime_active_modules: Iterable[str] | None = None,
|
||||||
|
protected_modules: Iterable[str] = TENANT_PROTECTED_MODULES,
|
||||||
|
) -> tuple[dict[str, object], TenantModuleEntitlementState]:
|
||||||
|
current = tenant_module_entitlement_state(
|
||||||
|
settings,
|
||||||
|
manifests,
|
||||||
|
runtime_active_modules=runtime_active_modules,
|
||||||
|
protected_modules=protected_modules,
|
||||||
|
)
|
||||||
|
_check_revision(current.revision, expected_revision)
|
||||||
|
known = set(manifests)
|
||||||
|
available_requested = _validated_requested_ids(
|
||||||
|
available_modules, known=known, field="available_modules"
|
||||||
|
)
|
||||||
|
forced_requested = _validated_requested_ids(
|
||||||
|
forced_modules, known=known, field="forced_modules"
|
||||||
|
)
|
||||||
|
enabled_requested = _validated_requested_ids(
|
||||||
|
enabled_modules, known=known, field="enabled_modules"
|
||||||
|
)
|
||||||
|
protected = known.intersection(_normalized_ids(protected_modules))
|
||||||
|
available, missing = _dependency_closure(
|
||||||
|
available_requested | forced_requested | protected,
|
||||||
|
manifests,
|
||||||
|
)
|
||||||
|
forced, forced_missing = _dependency_closure(
|
||||||
|
forced_requested | protected,
|
||||||
|
manifests,
|
||||||
|
)
|
||||||
|
if missing or forced_missing:
|
||||||
|
missing_text = ", ".join(sorted(missing | forced_missing))
|
||||||
|
raise ModuleEntitlementError(
|
||||||
|
f"Module policy references dependencies that are not installed: {missing_text}"
|
||||||
|
)
|
||||||
|
unavailable_enabled = enabled_requested - available
|
||||||
|
if unavailable_enabled:
|
||||||
|
raise ModuleEntitlementError(
|
||||||
|
"Tenant selection contains modules unavailable by system policy: "
|
||||||
|
+ ", ".join(sorted(unavailable_enabled))
|
||||||
|
)
|
||||||
|
_validate_enabled_dependencies(enabled_requested | forced, available, manifests)
|
||||||
|
updated = _write_document(
|
||||||
|
settings,
|
||||||
|
revision=current.revision + 1,
|
||||||
|
available_modules=available,
|
||||||
|
forced_modules=forced,
|
||||||
|
enabled_modules=enabled_requested,
|
||||||
|
)
|
||||||
|
return updated, tenant_module_entitlement_state(
|
||||||
|
updated,
|
||||||
|
manifests,
|
||||||
|
runtime_active_modules=runtime_active_modules,
|
||||||
|
protected_modules=protected_modules,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def update_tenant_module_selection(
|
||||||
|
settings: Mapping[str, object] | None,
|
||||||
|
manifests: Mapping[str, ModuleManifest],
|
||||||
|
*,
|
||||||
|
enabled_modules: Iterable[str],
|
||||||
|
expected_revision: int | None,
|
||||||
|
runtime_active_modules: Iterable[str] | None = None,
|
||||||
|
protected_modules: Iterable[str] = TENANT_PROTECTED_MODULES,
|
||||||
|
) -> tuple[dict[str, object], TenantModuleEntitlementState]:
|
||||||
|
current = tenant_module_entitlement_state(
|
||||||
|
settings,
|
||||||
|
manifests,
|
||||||
|
runtime_active_modules=runtime_active_modules,
|
||||||
|
protected_modules=protected_modules,
|
||||||
|
)
|
||||||
|
_check_revision(current.revision, expected_revision)
|
||||||
|
enabled = _validated_requested_ids(
|
||||||
|
enabled_modules,
|
||||||
|
known=set(manifests),
|
||||||
|
field="enabled_modules",
|
||||||
|
)
|
||||||
|
unavailable = enabled - set(current.available_modules)
|
||||||
|
if unavailable:
|
||||||
|
raise ModuleEntitlementError(
|
||||||
|
"Tenant selection contains modules unavailable by system policy: "
|
||||||
|
+ ", ".join(sorted(unavailable))
|
||||||
|
)
|
||||||
|
_validate_enabled_dependencies(
|
||||||
|
enabled | set(current.forced_modules),
|
||||||
|
set(current.available_modules),
|
||||||
|
manifests,
|
||||||
|
)
|
||||||
|
updated = _write_document(
|
||||||
|
settings,
|
||||||
|
revision=current.revision + 1,
|
||||||
|
available_modules=current.available_modules,
|
||||||
|
forced_modules=current.forced_modules,
|
||||||
|
enabled_modules=enabled,
|
||||||
|
)
|
||||||
|
return updated, tenant_module_entitlement_state(
|
||||||
|
updated,
|
||||||
|
manifests,
|
||||||
|
runtime_active_modules=runtime_active_modules,
|
||||||
|
protected_modules=protected_modules,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def module_entitlement_payload(
|
||||||
|
tenant_id: str,
|
||||||
|
state: TenantModuleEntitlementState,
|
||||||
|
) -> dict[str, Any]:
|
||||||
|
return {
|
||||||
|
"tenant_id": tenant_id,
|
||||||
|
"revision": state.revision,
|
||||||
|
"configured": state.configured,
|
||||||
|
"available_modules": list(state.available_modules),
|
||||||
|
"forced_modules": list(state.forced_modules),
|
||||||
|
"selected_modules": list(state.selected_modules),
|
||||||
|
"effective_modules": list(state.effective_modules),
|
||||||
|
"derived_dependencies": list(state.derived_dependencies),
|
||||||
|
"modules": [
|
||||||
|
{
|
||||||
|
"id": item.id,
|
||||||
|
"name": item.name,
|
||||||
|
"dependencies": list(item.dependencies),
|
||||||
|
"runtime_active": item.runtime_active,
|
||||||
|
"availability": item.availability,
|
||||||
|
"selected": item.selected,
|
||||||
|
"effective": item.effective,
|
||||||
|
"forced": item.forced,
|
||||||
|
"derived_dependency": item.derived_dependency,
|
||||||
|
"tenant_can_toggle": item.tenant_can_toggle,
|
||||||
|
"reason": item.reason,
|
||||||
|
}
|
||||||
|
for item in state.modules
|
||||||
|
],
|
||||||
|
"diagnostics": [dict(item) for item in state.diagnostics],
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
def _write_document(
|
||||||
|
settings: Mapping[str, object] | None,
|
||||||
|
*,
|
||||||
|
revision: int,
|
||||||
|
available_modules: Iterable[str],
|
||||||
|
forced_modules: Iterable[str],
|
||||||
|
enabled_modules: Iterable[str],
|
||||||
|
) -> dict[str, object]:
|
||||||
|
updated = dict(settings or {})
|
||||||
|
updated[MODULE_ENTITLEMENTS_KEY] = {
|
||||||
|
"schema_version": MODULE_ENTITLEMENT_SCHEMA_VERSION,
|
||||||
|
"revision": revision,
|
||||||
|
"system_policy": {
|
||||||
|
"available_modules": sorted(set(available_modules)),
|
||||||
|
"forced_modules": sorted(set(forced_modules)),
|
||||||
|
},
|
||||||
|
"tenant_selection": {
|
||||||
|
"enabled_modules": sorted(set(enabled_modules)),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
return updated
|
||||||
|
|
||||||
|
|
||||||
|
def _validate_enabled_dependencies(
|
||||||
|
enabled: set[str],
|
||||||
|
available: set[str],
|
||||||
|
manifests: Mapping[str, ModuleManifest],
|
||||||
|
) -> None:
|
||||||
|
closure, missing = _dependency_closure(enabled, manifests)
|
||||||
|
if missing:
|
||||||
|
raise ModuleEntitlementError(
|
||||||
|
"Selected modules require dependencies that are not installed: "
|
||||||
|
+ ", ".join(sorted(missing))
|
||||||
|
)
|
||||||
|
unavailable = closure - available
|
||||||
|
if unavailable:
|
||||||
|
raise ModuleEntitlementError(
|
||||||
|
"Selected modules require dependencies unavailable by system policy: "
|
||||||
|
+ ", ".join(sorted(unavailable))
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def _dependency_closure(
|
||||||
|
requested: Iterable[str],
|
||||||
|
manifests: Mapping[str, ModuleManifest],
|
||||||
|
) -> tuple[set[str], set[str]]:
|
||||||
|
closure: set[str] = set()
|
||||||
|
missing: set[str] = set()
|
||||||
|
pending = list(_normalized_ids(requested))
|
||||||
|
while pending:
|
||||||
|
module_id = pending.pop()
|
||||||
|
if module_id in closure:
|
||||||
|
continue
|
||||||
|
manifest = manifests.get(module_id)
|
||||||
|
if manifest is None:
|
||||||
|
missing.add(module_id)
|
||||||
|
continue
|
||||||
|
closure.add(module_id)
|
||||||
|
pending.extend(manifest.dependencies)
|
||||||
|
return closure, missing
|
||||||
|
|
||||||
|
|
||||||
|
def _configured_ids(
|
||||||
|
value: object,
|
||||||
|
*,
|
||||||
|
field: str,
|
||||||
|
known: set[str],
|
||||||
|
fallback: Iterable[str],
|
||||||
|
diagnostics: list[dict[str, str]],
|
||||||
|
) -> set[str]:
|
||||||
|
if not isinstance(value, list | tuple):
|
||||||
|
diagnostics.append(
|
||||||
|
_diagnostic(
|
||||||
|
"module_entitlements.invalid_field",
|
||||||
|
f"{field} is malformed and was evaluated with a restrictive fallback.",
|
||||||
|
)
|
||||||
|
)
|
||||||
|
return set(fallback)
|
||||||
|
values = _normalized_ids(value)
|
||||||
|
unknown = values - known
|
||||||
|
if unknown:
|
||||||
|
diagnostics.append(
|
||||||
|
_diagnostic(
|
||||||
|
"module_entitlements.unknown_module",
|
||||||
|
f"{field} references unknown modules: {', '.join(sorted(unknown))}.",
|
||||||
|
)
|
||||||
|
)
|
||||||
|
return values.intersection(known)
|
||||||
|
|
||||||
|
|
||||||
|
def _validated_requested_ids(
|
||||||
|
values: Iterable[str],
|
||||||
|
*,
|
||||||
|
known: set[str],
|
||||||
|
field: str,
|
||||||
|
) -> set[str]:
|
||||||
|
normalized = _normalized_ids(values)
|
||||||
|
unknown = normalized - known
|
||||||
|
if unknown:
|
||||||
|
raise ModuleEntitlementError(
|
||||||
|
f"{field} contains unknown modules: {', '.join(sorted(unknown))}"
|
||||||
|
)
|
||||||
|
return normalized
|
||||||
|
|
||||||
|
|
||||||
|
def _normalized_ids(values: Iterable[object]) -> set[str]:
|
||||||
|
return {
|
||||||
|
clean
|
||||||
|
for value in values
|
||||||
|
if (clean := str(value).strip())
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
def _revision(value: object, diagnostics: list[dict[str, str]]) -> int:
|
||||||
|
if isinstance(value, int) and value >= 0:
|
||||||
|
return value
|
||||||
|
diagnostics.append(
|
||||||
|
_diagnostic(
|
||||||
|
"module_entitlements.invalid_revision",
|
||||||
|
"The module entitlement revision is invalid; concurrent updates will require a reload.",
|
||||||
|
)
|
||||||
|
)
|
||||||
|
return 0
|
||||||
|
|
||||||
|
|
||||||
|
def _check_revision(current: int, expected: int | None) -> None:
|
||||||
|
if expected is not None and expected != current:
|
||||||
|
raise ModuleEntitlementConflict(
|
||||||
|
f"Module entitlement revision changed from {expected} to {current}; reload before saving."
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def _diagnostic(code: str, message: str) -> dict[str, str]:
|
||||||
|
return {"code": code, "message": message, "severity": "warning"}
|
||||||
|
|
||||||
|
|
||||||
|
__all__ = [
|
||||||
|
"MODULE_ENTITLEMENTS_KEY",
|
||||||
|
"MODULE_ENTITLEMENT_SCHEMA_VERSION",
|
||||||
|
"TENANT_PROTECTED_MODULES",
|
||||||
|
"ModuleEntitlementConflict",
|
||||||
|
"ModuleEntitlementError",
|
||||||
|
"ModuleEntitlementResolutionError",
|
||||||
|
"TenantExecutionContext",
|
||||||
|
"TenantModuleAdmission",
|
||||||
|
"TenantModuleEntitlementResolver",
|
||||||
|
"TenantModuleEntitlementState",
|
||||||
|
"TenantModuleItem",
|
||||||
|
"TenantModuleOperatorActionRequired",
|
||||||
|
"TenantModuleUnavailable",
|
||||||
|
"TenantWorkState",
|
||||||
|
"current_tenant_execution_context",
|
||||||
|
"module_entitlement_payload",
|
||||||
|
"tenant_execution_scope",
|
||||||
|
"tenant_module_entitlement_state",
|
||||||
|
"update_system_tenant_module_policy",
|
||||||
|
"update_tenant_module_selection",
|
||||||
|
]
|
||||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,457 @@
|
|||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
from dataclasses import dataclass
|
||||||
|
import hashlib
|
||||||
|
import json
|
||||||
|
from typing import Mapping, Sequence
|
||||||
|
from uuid import uuid4
|
||||||
|
|
||||||
|
from sqlalchemy.exc import SQLAlchemyError
|
||||||
|
from sqlalchemy.orm import Session, sessionmaker
|
||||||
|
|
||||||
|
from govoplan_core.core.recovery import (
|
||||||
|
RecoveryGuaranteeError,
|
||||||
|
RecoveryMode,
|
||||||
|
RecoveryOperation,
|
||||||
|
RecoveryPlan,
|
||||||
|
RecoveryStatus,
|
||||||
|
)
|
||||||
|
from govoplan_core.core.recovery_runtime import (
|
||||||
|
DurableRecoveryOperation,
|
||||||
|
RecoveryOperationBusy,
|
||||||
|
RecoveryOperationStateConflict,
|
||||||
|
begin_durable_recovery_operation,
|
||||||
|
claim_durable_recovery_operation,
|
||||||
|
)
|
||||||
|
from govoplan_core.core.runtime_coordination import process_runtime_identity
|
||||||
|
|
||||||
|
|
||||||
|
class ModuleLifecycleRecoveryError(RuntimeError):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass(frozen=True, slots=True)
|
||||||
|
class ModuleLifecycleRecoveryDeclaration:
|
||||||
|
operation_type: str
|
||||||
|
mode: RecoveryMode
|
||||||
|
resources: tuple[str, ...]
|
||||||
|
verification: tuple[str, ...]
|
||||||
|
|
||||||
|
|
||||||
|
MODULE_LIFECYCLE_RECOVERY_OPERATIONS = (
|
||||||
|
ModuleLifecycleRecoveryDeclaration(
|
||||||
|
operation_type="module-lifecycle.pre-migration",
|
||||||
|
mode=RecoveryMode.COMPENSATION,
|
||||||
|
resources=("postgresql", "package-environment", "webui-bundle", "filesystem"),
|
||||||
|
verification=(
|
||||||
|
"verify the canonical install plan and immutable package references",
|
||||||
|
"verify the package and WebUI snapshots before mutation",
|
||||||
|
"verify the installed manifests and desired module graph",
|
||||||
|
),
|
||||||
|
),
|
||||||
|
ModuleLifecycleRecoveryDeclaration(
|
||||||
|
operation_type="module-lifecycle.post-migration",
|
||||||
|
mode=RecoveryMode.FORWARD_RECOVERY,
|
||||||
|
resources=(
|
||||||
|
"postgresql",
|
||||||
|
"package-environment",
|
||||||
|
"webui-bundle",
|
||||||
|
"runtime-nodes",
|
||||||
|
),
|
||||||
|
verification=(
|
||||||
|
"verify the backup reference and migration execution evidence",
|
||||||
|
"verify migration heads and installed module manifests",
|
||||||
|
"verify the desired graph and runtime health before completion",
|
||||||
|
),
|
||||||
|
),
|
||||||
|
ModuleLifecycleRecoveryDeclaration(
|
||||||
|
operation_type="module-retirement.destroy-data",
|
||||||
|
mode=RecoveryMode.SNAPSHOT_RESTORE,
|
||||||
|
resources=("postgresql", "object-storage", "package-environment"),
|
||||||
|
verification=(
|
||||||
|
"verify the pinned backup artifact and restore-readiness evidence",
|
||||||
|
"verify the retirement provider result and remaining migration state",
|
||||||
|
"verify the installed manifests and desired module graph",
|
||||||
|
),
|
||||||
|
),
|
||||||
|
ModuleLifecycleRecoveryDeclaration(
|
||||||
|
operation_type="module-runtime.apply-graph",
|
||||||
|
mode=RecoveryMode.COMPENSATION,
|
||||||
|
resources=("postgresql", "runtime-nodes", "module-registry"),
|
||||||
|
verification=(
|
||||||
|
"verify the requested graph against available module contracts",
|
||||||
|
"verify activation and deactivation hooks completed",
|
||||||
|
"verify the active graph and workflow contribution reconciliation",
|
||||||
|
),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
_DECLARATIONS = {
|
||||||
|
item.operation_type: item for item in MODULE_LIFECYCLE_RECOVERY_OPERATIONS
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
def canonical_sha256(value: object) -> str:
|
||||||
|
encoded = json.dumps(
|
||||||
|
value,
|
||||||
|
sort_keys=True,
|
||||||
|
separators=(",", ":"),
|
||||||
|
ensure_ascii=True,
|
||||||
|
default=str,
|
||||||
|
).encode("utf-8")
|
||||||
|
return hashlib.sha256(encoded).hexdigest()
|
||||||
|
|
||||||
|
|
||||||
|
def lifecycle_session_factory(session: Session) -> sessionmaker[Session]:
|
||||||
|
bind = session.get_bind()
|
||||||
|
if bind is None:
|
||||||
|
raise ModuleLifecycleRecoveryError(
|
||||||
|
"Module lifecycle recovery requires a database bind"
|
||||||
|
)
|
||||||
|
return sessionmaker(bind=bind, expire_on_commit=False)
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass(slots=True)
|
||||||
|
class ModuleLifecycleRecovery:
|
||||||
|
operation: DurableRecoveryOperation | None
|
||||||
|
operation_id: str
|
||||||
|
operation_type: str
|
||||||
|
mode: RecoveryMode
|
||||||
|
plan_sha256: str
|
||||||
|
replayed: bool
|
||||||
|
effect_started: bool = False
|
||||||
|
|
||||||
|
def checkpoint(
|
||||||
|
self,
|
||||||
|
*,
|
||||||
|
kind: str,
|
||||||
|
summary: str,
|
||||||
|
evidence: Mapping[str, object],
|
||||||
|
effect_started: bool = False,
|
||||||
|
) -> None:
|
||||||
|
if self.operation is None:
|
||||||
|
return
|
||||||
|
self.effect_started = self.effect_started or effect_started
|
||||||
|
self.operation.checkpoint(
|
||||||
|
kind=kind,
|
||||||
|
summary=summary,
|
||||||
|
evidence={
|
||||||
|
**dict(evidence),
|
||||||
|
"effect_started": self.effect_started,
|
||||||
|
"plan_sha256": self.plan_sha256,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
||||||
|
def succeed(
|
||||||
|
self,
|
||||||
|
session: Session,
|
||||||
|
*,
|
||||||
|
evidence: Mapping[str, object],
|
||||||
|
commit_projection: bool,
|
||||||
|
) -> None:
|
||||||
|
if self.operation is None:
|
||||||
|
return
|
||||||
|
terminal = {
|
||||||
|
"verified": True,
|
||||||
|
"checks": {
|
||||||
|
**dict(evidence),
|
||||||
|
"plan_sha256": self.plan_sha256,
|
||||||
|
"effect_started": self.effect_started,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
if commit_projection:
|
||||||
|
self.operation.commit_verified_success(session, evidence=terminal)
|
||||||
|
else:
|
||||||
|
self.operation.succeed(evidence=terminal)
|
||||||
|
|
||||||
|
def unresolved(
|
||||||
|
self,
|
||||||
|
*,
|
||||||
|
summary: str,
|
||||||
|
evidence: Mapping[str, object],
|
||||||
|
outcome_unknown: bool,
|
||||||
|
) -> None:
|
||||||
|
if self.operation is None:
|
||||||
|
return
|
||||||
|
if not self.effect_started:
|
||||||
|
self.operation.fail(
|
||||||
|
summary=summary,
|
||||||
|
evidence={
|
||||||
|
"verified": True,
|
||||||
|
"checks": {
|
||||||
|
**dict(evidence),
|
||||||
|
"effect_started": False,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
)
|
||||||
|
return
|
||||||
|
self.operation.unresolved(
|
||||||
|
status=(
|
||||||
|
RecoveryStatus.OUTCOME_UNKNOWN
|
||||||
|
if outcome_unknown
|
||||||
|
else RecoveryStatus.RECOVERY_REQUIRED
|
||||||
|
),
|
||||||
|
summary=summary,
|
||||||
|
evidence={
|
||||||
|
**dict(evidence),
|
||||||
|
"effect_started": True,
|
||||||
|
"plan_sha256": self.plan_sha256,
|
||||||
|
},
|
||||||
|
failure_summary=(
|
||||||
|
"Inspect the installer run record and affected state services "
|
||||||
|
"before retrying or restoring"
|
||||||
|
),
|
||||||
|
)
|
||||||
|
|
||||||
|
def recovered(
|
||||||
|
self,
|
||||||
|
session: Session,
|
||||||
|
*,
|
||||||
|
evidence: Mapping[str, object],
|
||||||
|
summary: str,
|
||||||
|
) -> None:
|
||||||
|
state = session.get(RecoveryOperation, self.operation_id)
|
||||||
|
if state is None:
|
||||||
|
raise ModuleLifecycleRecoveryError(
|
||||||
|
"Module lifecycle recovery operation is unavailable"
|
||||||
|
)
|
||||||
|
if state.status == RecoveryStatus.RECOVERED.value:
|
||||||
|
return
|
||||||
|
try:
|
||||||
|
handle = claim_durable_recovery_operation(
|
||||||
|
lifecycle_session_factory(session),
|
||||||
|
identity=process_runtime_identity(),
|
||||||
|
operation_id=self.operation_id,
|
||||||
|
lease_ttl_seconds=900,
|
||||||
|
)
|
||||||
|
except RecoveryOperationStateConflict as exc:
|
||||||
|
if exc.status == RecoveryStatus.RECOVERED.value:
|
||||||
|
return
|
||||||
|
raise ModuleLifecycleRecoveryError(
|
||||||
|
f"Module lifecycle recovery is already {exc.status}"
|
||||||
|
) from exc
|
||||||
|
except (RecoveryOperationBusy, RecoveryGuaranteeError, RuntimeError) as exc:
|
||||||
|
raise ModuleLifecycleRecoveryError(
|
||||||
|
"Module lifecycle recovery authority is unavailable"
|
||||||
|
) from exc
|
||||||
|
session.expire_all()
|
||||||
|
state = session.get(RecoveryOperation, self.operation_id)
|
||||||
|
if state is None:
|
||||||
|
raise ModuleLifecycleRecoveryError(
|
||||||
|
"Module lifecycle recovery operation is unavailable"
|
||||||
|
)
|
||||||
|
recovery_evidence = {
|
||||||
|
"verified": True,
|
||||||
|
"checks": {
|
||||||
|
**dict(evidence),
|
||||||
|
"plan_sha256": self.plan_sha256,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
if state.status == RecoveryStatus.OUTCOME_UNKNOWN.value:
|
||||||
|
handle.resolve_unknown(
|
||||||
|
effect_occurred=False,
|
||||||
|
evidence=recovery_evidence,
|
||||||
|
summary=summary,
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
handle.compensate(
|
||||||
|
failure_summary=summary,
|
||||||
|
failure_evidence={
|
||||||
|
"effect_started": self.effect_started,
|
||||||
|
"plan_sha256": self.plan_sha256,
|
||||||
|
},
|
||||||
|
recovery_evidence=recovery_evidence,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def begin_module_installer_recovery(
|
||||||
|
session: Session,
|
||||||
|
*,
|
||||||
|
run_id: str,
|
||||||
|
plan: Sequence[Mapping[str, object]],
|
||||||
|
command_count: int,
|
||||||
|
migrate_database: bool,
|
||||||
|
destructive_retirement: bool,
|
||||||
|
snapshot_sha256: str | None,
|
||||||
|
backup_reference: str | None,
|
||||||
|
request_context_sha256: str,
|
||||||
|
) -> ModuleLifecycleRecovery:
|
||||||
|
operation_type = (
|
||||||
|
"module-retirement.destroy-data"
|
||||||
|
if destructive_retirement
|
||||||
|
else "module-lifecycle.post-migration"
|
||||||
|
if migrate_database
|
||||||
|
else "module-lifecycle.pre-migration"
|
||||||
|
)
|
||||||
|
declaration = _DECLARATIONS[operation_type]
|
||||||
|
plan_sha256 = canonical_sha256([dict(item) for item in plan])
|
||||||
|
recovery_plan = RecoveryPlan(
|
||||||
|
mode=declaration.mode,
|
||||||
|
preconditions=(
|
||||||
|
"maintenance mode and installer preflight are current",
|
||||||
|
"package references and the requested module graph are pinned",
|
||||||
|
"the deployment-wide module lifecycle fence is owned",
|
||||||
|
),
|
||||||
|
compensation_steps=(
|
||||||
|
"restore the Python and WebUI package snapshots",
|
||||||
|
"restore the prior desired module graph",
|
||||||
|
"verify installed manifests and runtime health",
|
||||||
|
)
|
||||||
|
if declaration.mode == RecoveryMode.COMPENSATION
|
||||||
|
else (),
|
||||||
|
forward_recovery_steps=(
|
||||||
|
"inspect migration task and command evidence",
|
||||||
|
"complete or repair migrations under the same deployment fence",
|
||||||
|
"verify migration heads, manifests, desired graph, and runtime health",
|
||||||
|
)
|
||||||
|
if declaration.mode == RecoveryMode.FORWARD_RECOVERY
|
||||||
|
else (),
|
||||||
|
verification_steps=declaration.verification,
|
||||||
|
backup_reference=(
|
||||||
|
backup_reference
|
||||||
|
if declaration.mode == RecoveryMode.SNAPSHOT_RESTORE
|
||||||
|
else None
|
||||||
|
),
|
||||||
|
)
|
||||||
|
if declaration.mode == RecoveryMode.SNAPSHOT_RESTORE and not backup_reference:
|
||||||
|
raise ModuleLifecycleRecoveryError(
|
||||||
|
"Destructive module retirement requires verified backup evidence"
|
||||||
|
)
|
||||||
|
session.commit()
|
||||||
|
try:
|
||||||
|
started = begin_durable_recovery_operation(
|
||||||
|
lifecycle_session_factory(session),
|
||||||
|
identity=process_runtime_identity(),
|
||||||
|
module_id="core",
|
||||||
|
operation_type=operation_type,
|
||||||
|
idempotency_key=f"module-installer:{run_id}",
|
||||||
|
request={
|
||||||
|
"run_id": run_id,
|
||||||
|
"plan_sha256": plan_sha256,
|
||||||
|
"command_count": command_count,
|
||||||
|
"migrate_database": migrate_database,
|
||||||
|
"destructive_retirement": destructive_retirement,
|
||||||
|
"snapshot_expected": True,
|
||||||
|
"request_context_sha256": request_context_sha256,
|
||||||
|
},
|
||||||
|
recovery_plan=recovery_plan,
|
||||||
|
precondition_evidence={
|
||||||
|
"plan_sha256": plan_sha256,
|
||||||
|
"snapshot_sha256": snapshot_sha256 or "pending",
|
||||||
|
"request_context_sha256": request_context_sha256,
|
||||||
|
"command_count": command_count,
|
||||||
|
"backup_reference_present": bool(backup_reference),
|
||||||
|
},
|
||||||
|
lease_resource_key="core:module-lifecycle:deployment",
|
||||||
|
lease_ttl_seconds=900,
|
||||||
|
resource_type="module_installer_run",
|
||||||
|
resource_id=run_id,
|
||||||
|
metadata={
|
||||||
|
"resources": list(declaration.resources),
|
||||||
|
"migrate_database": migrate_database,
|
||||||
|
"destructive_retirement": destructive_retirement,
|
||||||
|
},
|
||||||
|
block_unresolved_resource=True,
|
||||||
|
)
|
||||||
|
except RecoveryOperationBusy as exc:
|
||||||
|
raise ModuleLifecycleRecoveryError(
|
||||||
|
"Another runtime owns the deployment module lifecycle fence"
|
||||||
|
) from exc
|
||||||
|
except RecoveryOperationStateConflict as exc:
|
||||||
|
raise ModuleLifecycleRecoveryError(
|
||||||
|
f"Module installer recovery is already {exc.status}"
|
||||||
|
) from exc
|
||||||
|
except (RecoveryGuaranteeError, RuntimeError, SQLAlchemyError, ValueError) as exc:
|
||||||
|
raise ModuleLifecycleRecoveryError(
|
||||||
|
"The recovery ledger is unavailable; module mutation did not start"
|
||||||
|
) from exc
|
||||||
|
return ModuleLifecycleRecovery(
|
||||||
|
operation=started.operation,
|
||||||
|
operation_id=started.operation_id,
|
||||||
|
operation_type=operation_type,
|
||||||
|
mode=declaration.mode,
|
||||||
|
plan_sha256=plan_sha256,
|
||||||
|
replayed=started.replayed,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def begin_runtime_graph_recovery(
|
||||||
|
session: Session,
|
||||||
|
*,
|
||||||
|
previous_modules: Sequence[str],
|
||||||
|
requested_modules: Sequence[str],
|
||||||
|
migrate: bool,
|
||||||
|
) -> ModuleLifecycleRecovery:
|
||||||
|
declaration = _DECLARATIONS["module-runtime.apply-graph"]
|
||||||
|
plan = {
|
||||||
|
"previous_modules": sorted(set(previous_modules)),
|
||||||
|
"requested_modules": sorted(set(requested_modules)),
|
||||||
|
"migrate": migrate,
|
||||||
|
}
|
||||||
|
plan_sha256 = canonical_sha256(plan)
|
||||||
|
session.commit()
|
||||||
|
try:
|
||||||
|
started = begin_durable_recovery_operation(
|
||||||
|
lifecycle_session_factory(session),
|
||||||
|
identity=process_runtime_identity(),
|
||||||
|
module_id="core",
|
||||||
|
operation_type=declaration.operation_type,
|
||||||
|
idempotency_key=f"module-runtime:{uuid4()}",
|
||||||
|
request={**plan, "plan_sha256": plan_sha256},
|
||||||
|
recovery_plan=RecoveryPlan(
|
||||||
|
mode=declaration.mode,
|
||||||
|
preconditions=(
|
||||||
|
"the requested graph passed module contract validation",
|
||||||
|
"the deployment-wide module lifecycle fence is owned",
|
||||||
|
),
|
||||||
|
compensation_steps=(
|
||||||
|
"restore the previous in-process active registry",
|
||||||
|
"reconfigure capability contexts from the previous graph",
|
||||||
|
),
|
||||||
|
verification_steps=declaration.verification,
|
||||||
|
),
|
||||||
|
precondition_evidence={
|
||||||
|
"plan_sha256": plan_sha256,
|
||||||
|
"previous_graph_sha256": canonical_sha256(
|
||||||
|
sorted(set(previous_modules))
|
||||||
|
),
|
||||||
|
"requested_graph_sha256": canonical_sha256(
|
||||||
|
sorted(set(requested_modules))
|
||||||
|
),
|
||||||
|
},
|
||||||
|
lease_resource_key="core:module-lifecycle:deployment",
|
||||||
|
lease_ttl_seconds=300,
|
||||||
|
resource_type="module_runtime_graph",
|
||||||
|
resource_id=plan_sha256,
|
||||||
|
metadata={"resources": list(declaration.resources)},
|
||||||
|
block_unresolved_resource=True,
|
||||||
|
)
|
||||||
|
except (RecoveryOperationBusy, RecoveryOperationStateConflict) as exc:
|
||||||
|
raise ModuleLifecycleRecoveryError(
|
||||||
|
"Another lifecycle mutation is active or unresolved"
|
||||||
|
) from exc
|
||||||
|
except (RecoveryGuaranteeError, RuntimeError, SQLAlchemyError, ValueError) as exc:
|
||||||
|
raise ModuleLifecycleRecoveryError(
|
||||||
|
"The recovery ledger is unavailable; the active graph was unchanged"
|
||||||
|
) from exc
|
||||||
|
return ModuleLifecycleRecovery(
|
||||||
|
operation=started.operation,
|
||||||
|
operation_id=started.operation_id,
|
||||||
|
operation_type=declaration.operation_type,
|
||||||
|
mode=declaration.mode,
|
||||||
|
plan_sha256=plan_sha256,
|
||||||
|
replayed=started.replayed,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
__all__ = [
|
||||||
|
"MODULE_LIFECYCLE_RECOVERY_OPERATIONS",
|
||||||
|
"ModuleLifecycleRecovery",
|
||||||
|
"ModuleLifecycleRecoveryDeclaration",
|
||||||
|
"ModuleLifecycleRecoveryError",
|
||||||
|
"begin_module_installer_recovery",
|
||||||
|
"begin_runtime_graph_recovery",
|
||||||
|
"canonical_sha256",
|
||||||
|
"lifecycle_session_factory",
|
||||||
|
]
|
||||||
@@ -3,8 +3,10 @@ from __future__ import annotations
|
|||||||
import base64
|
import base64
|
||||||
import binascii
|
import binascii
|
||||||
from collections import defaultdict
|
from collections import defaultdict
|
||||||
|
from collections.abc import Mapping
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
from datetime import UTC, datetime
|
from datetime import UTC, datetime
|
||||||
|
from importlib.resources import files
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
@@ -16,9 +18,23 @@ from cryptography.hazmat.primitives import serialization
|
|||||||
from cryptography.hazmat.primitives.asymmetric.ed25519 import Ed25519PrivateKey, Ed25519PublicKey
|
from cryptography.hazmat.primitives.asymmetric.ed25519 import Ed25519PrivateKey, Ed25519PublicKey
|
||||||
|
|
||||||
from govoplan_core.core.versioning import format_version_range, version_range_is_valid, version_satisfies_range
|
from govoplan_core.core.versioning import format_version_range, version_range_is_valid, version_satisfies_range
|
||||||
|
from govoplan_core.core.information_governance import (
|
||||||
|
information_governance_from_mapping,
|
||||||
|
information_governance_maturity_issues,
|
||||||
|
)
|
||||||
|
from govoplan_core.core.provider_governance import (
|
||||||
|
external_provider_from_mapping,
|
||||||
|
module_architecture_from_mapping,
|
||||||
|
module_architecture_issues,
|
||||||
|
)
|
||||||
from govoplan_core.security.http_fetch import fetch_http_text, is_http_url
|
from govoplan_core.security.http_fetch import fetch_http_text, is_http_url
|
||||||
|
|
||||||
_INTERFACE_NAME_RE = re.compile(r"^[a-z][a-z0-9_]*(?:\.[a-z][a-z0-9_]*)+$")
|
_INTERFACE_NAME_RE = re.compile(r"^[a-z][a-z0-9_]*(?:\.[a-z][a-z0-9_]*)+$")
|
||||||
|
_SHA256_RE = re.compile(r"^[0-9a-f]{64}$")
|
||||||
|
_ARTIFACT_FILENAME_RE = re.compile(r"^[A-Za-z0-9][A-Za-z0-9._+!-]{0,255}$")
|
||||||
|
_SOURCE_REPOSITORY_RE = re.compile(r"^[A-Za-z0-9][A-Za-z0-9._/-]{0,254}$")
|
||||||
|
_SOURCE_REF_RE = re.compile(r"^[A-Za-z0-9][A-Za-z0-9._/+!-]{0,127}$")
|
||||||
|
_SOURCE_COMMIT_RE = re.compile(r"^(?:[0-9a-f]{40}|[0-9a-f]{64})$")
|
||||||
CATALOG_MIGRATION_SAFETY = ("automatic", "requires_review", "forward_only", "destructive")
|
CATALOG_MIGRATION_SAFETY = ("automatic", "requires_review", "forward_only", "destructive")
|
||||||
CATALOG_MIGRATION_TASK_PHASES = (
|
CATALOG_MIGRATION_TASK_PHASES = (
|
||||||
"pre_migration_check",
|
"pre_migration_check",
|
||||||
@@ -26,6 +42,8 @@ CATALOG_MIGRATION_TASK_PHASES = (
|
|||||||
"post_migration_backfill",
|
"post_migration_backfill",
|
||||||
"post_migration_verify",
|
"post_migration_verify",
|
||||||
)
|
)
|
||||||
|
OFFICIAL_MODULE_PACKAGE_CATALOG_URL = "https://govoplan.add-ideas.de/catalogs/v1/channels/stable.json"
|
||||||
|
OFFICIAL_MODULE_PACKAGE_CATALOG_CHANNEL = "stable"
|
||||||
|
|
||||||
|
|
||||||
@dataclass(frozen=True, slots=True)
|
@dataclass(frozen=True, slots=True)
|
||||||
@@ -91,6 +109,18 @@ def validate_module_package_catalog(
|
|||||||
return _valid_catalog_result(catalog_source, state)
|
return _valid_catalog_result(catalog_source, state)
|
||||||
|
|
||||||
|
|
||||||
|
def validate_official_module_package_catalog() -> dict[str, object]:
|
||||||
|
"""Read the public GovOPlaN directory against Core's pinned trust anchor."""
|
||||||
|
|
||||||
|
keyring = files("govoplan_core").joinpath("resources/catalog-keyring.json").read_text(encoding="utf-8")
|
||||||
|
return validate_module_package_catalog(
|
||||||
|
OFFICIAL_MODULE_PACKAGE_CATALOG_URL,
|
||||||
|
require_trusted=True,
|
||||||
|
approved_channels=(OFFICIAL_MODULE_PACKAGE_CATALOG_CHANNEL,),
|
||||||
|
trusted_keys=_parse_trusted_keys(keyring),
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def _catalog_validation_state(
|
def _catalog_validation_state(
|
||||||
source: Path | str | None,
|
source: Path | str | None,
|
||||||
*,
|
*,
|
||||||
@@ -238,7 +268,17 @@ def sign_module_package_catalog(
|
|||||||
|
|
||||||
|
|
||||||
def record_module_package_catalog_acceptance(validation: dict[str, object]) -> None:
|
def record_module_package_catalog_acceptance(validation: dict[str, object]) -> None:
|
||||||
state_path = _configured_sequence_state_path()
|
_record_catalog_acceptance(
|
||||||
|
validation,
|
||||||
|
state_path=_configured_sequence_state_path(),
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def _record_catalog_acceptance(
|
||||||
|
validation: dict[str, object],
|
||||||
|
*,
|
||||||
|
state_path: Path | None,
|
||||||
|
) -> None:
|
||||||
if state_path is None or validation.get("valid") is not True:
|
if state_path is None or validation.get("valid") is not True:
|
||||||
return
|
return
|
||||||
channel = validation.get("channel")
|
channel = validation.get("channel")
|
||||||
@@ -303,7 +343,10 @@ def _configured_require_signature() -> bool:
|
|||||||
|
|
||||||
|
|
||||||
def _configured_approved_channels() -> tuple[str, ...]:
|
def _configured_approved_channels() -> tuple[str, ...]:
|
||||||
value = os.getenv("GOVOPLAN_MODULE_PACKAGE_CATALOG_APPROVED_CHANNELS", "").strip()
|
value = (
|
||||||
|
os.getenv("GOVOPLAN_MODULE_PACKAGE_CATALOG_APPROVED_CHANNELS", "").strip()
|
||||||
|
or os.getenv("GOVOPLAN_MODULE_PACKAGE_CATALOG_APPROVED_CHANNEL", "").strip()
|
||||||
|
)
|
||||||
if not value:
|
if not value:
|
||||||
return ()
|
return ()
|
||||||
return tuple(item.strip() for item in value.split(",") if item.strip())
|
return tuple(item.strip() for item in value.split(",") if item.strip())
|
||||||
@@ -612,7 +655,115 @@ def _normalize_catalog_item(value: Any) -> dict[str, object]:
|
|||||||
"requires_interfaces": _normalize_catalog_interface_requirements(value.get("requires_interfaces"), module_id=module_id),
|
"requires_interfaces": _normalize_catalog_interface_requirements(value.get("requires_interfaces"), module_id=module_id),
|
||||||
"notes": _optional_str(value, "notes"),
|
"notes": _optional_str(value, "notes"),
|
||||||
"tags": _string_list(value.get("tags")),
|
"tags": _string_list(value.get("tags")),
|
||||||
|
"availability": _catalog_availability(value, module_id=module_id),
|
||||||
|
"availability_reason": _optional_str(value, "availability_reason"),
|
||||||
|
"configuration_requirements": _string_list(value.get("configuration_requirements")),
|
||||||
|
"permissions": _normalize_catalog_permissions(
|
||||||
|
value.get("permissions"),
|
||||||
|
module_id=module_id,
|
||||||
|
),
|
||||||
}
|
}
|
||||||
|
if item["availability"] == "withdrawn" and not item["availability_reason"]:
|
||||||
|
raise ValueError(
|
||||||
|
f"Withdrawn module package catalog entry {module_id!r} requires availability_reason."
|
||||||
|
)
|
||||||
|
release_notes_url = _optional_str(value, "release_notes_url")
|
||||||
|
if release_notes_url is not None:
|
||||||
|
item["release_notes_url"] = _catalog_https_url(
|
||||||
|
release_notes_url,
|
||||||
|
label=f"Module package catalog release_notes_url for {module_id!r}",
|
||||||
|
)
|
||||||
|
source = _normalize_catalog_source(value.get("source"), module_id=module_id)
|
||||||
|
if source:
|
||||||
|
item["source"] = source
|
||||||
|
raw_architecture = value.get("architecture")
|
||||||
|
architecture_maturity: str | None = None
|
||||||
|
if raw_architecture is not None:
|
||||||
|
if not isinstance(raw_architecture, Mapping):
|
||||||
|
raise ValueError(
|
||||||
|
f"Module package catalog architecture for {module_id!r} must be an object."
|
||||||
|
)
|
||||||
|
architecture = module_architecture_from_mapping(raw_architecture)
|
||||||
|
issues = module_architecture_issues(
|
||||||
|
architecture,
|
||||||
|
has_migrations=bool(item["migration_tasks"])
|
||||||
|
or bool(item["migration_notes"]),
|
||||||
|
)
|
||||||
|
if issues:
|
||||||
|
raise ValueError(
|
||||||
|
f"Module package catalog architecture for {module_id!r} is invalid: "
|
||||||
|
+ "; ".join(issues)
|
||||||
|
)
|
||||||
|
item["architecture"] = architecture.to_dict()
|
||||||
|
architecture_maturity = architecture.maturity
|
||||||
|
raw_information_governance = value.get("information_governance")
|
||||||
|
if raw_information_governance is not None:
|
||||||
|
if not isinstance(raw_information_governance, Mapping):
|
||||||
|
raise ValueError(
|
||||||
|
"Module package catalog information_governance for "
|
||||||
|
f"{module_id!r} must be an object."
|
||||||
|
)
|
||||||
|
information_governance = information_governance_from_mapping(
|
||||||
|
raw_information_governance
|
||||||
|
)
|
||||||
|
governance_issues = information_governance_maturity_issues(
|
||||||
|
information_governance,
|
||||||
|
maturity=architecture_maturity,
|
||||||
|
)
|
||||||
|
if governance_issues:
|
||||||
|
raise ValueError(
|
||||||
|
"Module package catalog information_governance for "
|
||||||
|
f"{module_id!r} is invalid: " + "; ".join(governance_issues)
|
||||||
|
)
|
||||||
|
item["information_governance"] = information_governance.to_dict()
|
||||||
|
raw_providers = value.get("external_providers")
|
||||||
|
if raw_providers is not None:
|
||||||
|
if not isinstance(raw_providers, list):
|
||||||
|
raise ValueError(
|
||||||
|
f"Module package catalog external_providers for {module_id!r} must be a list."
|
||||||
|
)
|
||||||
|
providers = []
|
||||||
|
seen_provider_ids: set[str] = set()
|
||||||
|
for raw_provider in raw_providers:
|
||||||
|
if not isinstance(raw_provider, Mapping):
|
||||||
|
raise ValueError(
|
||||||
|
f"Module package catalog external provider entries for {module_id!r} must be objects."
|
||||||
|
)
|
||||||
|
provider = external_provider_from_mapping(raw_provider)
|
||||||
|
if provider.module_id != module_id:
|
||||||
|
raise ValueError(
|
||||||
|
f"Module package catalog provider {provider.id!r} belongs to "
|
||||||
|
f"{provider.module_id!r}, not {module_id!r}."
|
||||||
|
)
|
||||||
|
if provider.id in seen_provider_ids:
|
||||||
|
raise ValueError(
|
||||||
|
f"Module package catalog has duplicate provider {provider.id!r}."
|
||||||
|
)
|
||||||
|
seen_provider_ids.add(provider.id)
|
||||||
|
providers.append(provider)
|
||||||
|
if providers and "architecture" not in item:
|
||||||
|
raise ValueError(
|
||||||
|
f"Module package catalog {module_id!r} declares external providers without architecture metadata."
|
||||||
|
)
|
||||||
|
if providers:
|
||||||
|
architecture_payload = item["architecture"]
|
||||||
|
if not isinstance(architecture_payload, Mapping):
|
||||||
|
raise ValueError(
|
||||||
|
f"Module package catalog {module_id!r} has invalid architecture metadata."
|
||||||
|
)
|
||||||
|
architecture_modes = set(
|
||||||
|
_string_list(architecture_payload.get("supported_authority_modes"))
|
||||||
|
)
|
||||||
|
provider_modes = {
|
||||||
|
mode for provider in providers for mode in provider.authority_modes
|
||||||
|
}
|
||||||
|
missing_modes = provider_modes - architecture_modes
|
||||||
|
if missing_modes:
|
||||||
|
raise ValueError(
|
||||||
|
f"Module package catalog {module_id!r} provider modes are missing from architecture metadata: "
|
||||||
|
+ ", ".join(sorted(missing_modes))
|
||||||
|
)
|
||||||
|
item["external_providers"] = [provider.to_dict() for provider in providers]
|
||||||
if not version_range_is_valid(
|
if not version_range_is_valid(
|
||||||
version_min=item["current_version_min"] if isinstance(item["current_version_min"], str) else None,
|
version_min=item["current_version_min"] if isinstance(item["current_version_min"], str) else None,
|
||||||
version_max_exclusive=item["current_version_max_exclusive"] if isinstance(item["current_version_max_exclusive"], str) else None,
|
version_max_exclusive=item["current_version_max_exclusive"] if isinstance(item["current_version_max_exclusive"], str) else None,
|
||||||
@@ -628,6 +779,170 @@ def _normalize_catalog_item(value: Any) -> dict[str, object]:
|
|||||||
return item
|
return item
|
||||||
|
|
||||||
|
|
||||||
|
def _catalog_availability(value: Mapping[str, object], *, module_id: str) -> str:
|
||||||
|
availability = str(value.get("availability") or "available").strip().lower()
|
||||||
|
if availability not in {"available", "withdrawn"}:
|
||||||
|
raise ValueError(
|
||||||
|
f"Unsupported catalog availability for {module_id!r}: {availability!r}."
|
||||||
|
)
|
||||||
|
return availability
|
||||||
|
|
||||||
|
|
||||||
|
def _normalize_catalog_permissions(
|
||||||
|
value: object,
|
||||||
|
*,
|
||||||
|
module_id: str,
|
||||||
|
) -> list[dict[str, object]]:
|
||||||
|
if value is None:
|
||||||
|
return []
|
||||||
|
if not isinstance(value, list):
|
||||||
|
raise ValueError(
|
||||||
|
f"Module package catalog permissions for {module_id!r} must be a list."
|
||||||
|
)
|
||||||
|
if len(value) > 1000:
|
||||||
|
raise ValueError(
|
||||||
|
f"Module package catalog permissions for {module_id!r} exceed 1000 entries."
|
||||||
|
)
|
||||||
|
normalized: list[dict[str, object]] = []
|
||||||
|
seen: set[str] = set()
|
||||||
|
for raw in value:
|
||||||
|
if not isinstance(raw, Mapping):
|
||||||
|
raise ValueError(
|
||||||
|
f"Module package catalog permission entries for {module_id!r} must be objects."
|
||||||
|
)
|
||||||
|
scope = _bounded_catalog_permission_text(
|
||||||
|
raw,
|
||||||
|
"scope",
|
||||||
|
module_id=module_id,
|
||||||
|
maximum=200,
|
||||||
|
)
|
||||||
|
if scope in seen:
|
||||||
|
raise ValueError(
|
||||||
|
f"Module package catalog entry {module_id!r} declares permission {scope!r} more than once."
|
||||||
|
)
|
||||||
|
seen.add(scope)
|
||||||
|
level = _bounded_catalog_permission_text(
|
||||||
|
raw,
|
||||||
|
"level",
|
||||||
|
module_id=module_id,
|
||||||
|
maximum=20,
|
||||||
|
)
|
||||||
|
if level not in {"system", "tenant"}:
|
||||||
|
raise ValueError(
|
||||||
|
f"Module package catalog permission {module_id!r}/{scope!r} has unsupported level {level!r}."
|
||||||
|
)
|
||||||
|
deprecated = raw.get("deprecated", False)
|
||||||
|
if not isinstance(deprecated, bool):
|
||||||
|
raise ValueError(
|
||||||
|
f"Module package catalog permission {module_id!r}/{scope!r} deprecated must be true or false."
|
||||||
|
)
|
||||||
|
normalized.append(
|
||||||
|
{
|
||||||
|
"scope": scope,
|
||||||
|
"label": _bounded_catalog_permission_text(
|
||||||
|
raw,
|
||||||
|
"label",
|
||||||
|
module_id=module_id,
|
||||||
|
maximum=200,
|
||||||
|
),
|
||||||
|
"description": _bounded_catalog_permission_text(
|
||||||
|
raw,
|
||||||
|
"description",
|
||||||
|
module_id=module_id,
|
||||||
|
maximum=1000,
|
||||||
|
),
|
||||||
|
"category": _bounded_catalog_permission_text(
|
||||||
|
raw,
|
||||||
|
"category",
|
||||||
|
module_id=module_id,
|
||||||
|
maximum=120,
|
||||||
|
),
|
||||||
|
"level": level,
|
||||||
|
"resource": _bounded_catalog_permission_text(
|
||||||
|
raw,
|
||||||
|
"resource",
|
||||||
|
module_id=module_id,
|
||||||
|
maximum=120,
|
||||||
|
),
|
||||||
|
"action": _bounded_catalog_permission_text(
|
||||||
|
raw,
|
||||||
|
"action",
|
||||||
|
module_id=module_id,
|
||||||
|
maximum=120,
|
||||||
|
),
|
||||||
|
"deprecated": deprecated,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
return normalized
|
||||||
|
|
||||||
|
|
||||||
|
def _bounded_catalog_permission_text(
|
||||||
|
value: Mapping[str, object],
|
||||||
|
key: str,
|
||||||
|
*,
|
||||||
|
module_id: str,
|
||||||
|
maximum: int,
|
||||||
|
) -> str:
|
||||||
|
text = _required_str(value, key)
|
||||||
|
if len(text) > maximum:
|
||||||
|
raise ValueError(
|
||||||
|
f"Module package catalog permission {key!r} for {module_id!r} exceeds {maximum} characters."
|
||||||
|
)
|
||||||
|
return text
|
||||||
|
|
||||||
|
|
||||||
|
def _normalize_catalog_source(
|
||||||
|
value: object,
|
||||||
|
*,
|
||||||
|
module_id: str,
|
||||||
|
) -> dict[str, object]:
|
||||||
|
if value is None:
|
||||||
|
return {}
|
||||||
|
if not isinstance(value, Mapping):
|
||||||
|
raise ValueError(
|
||||||
|
f"Module package catalog source for {module_id!r} must be an object."
|
||||||
|
)
|
||||||
|
repository = _required_str(value, "repository")
|
||||||
|
tag = _required_str(value, "tag")
|
||||||
|
commit = _required_str(value, "commit").lower()
|
||||||
|
if (
|
||||||
|
_SOURCE_REPOSITORY_RE.fullmatch(repository) is None
|
||||||
|
or repository.startswith("/")
|
||||||
|
or repository.endswith("/")
|
||||||
|
or ".." in repository.split("/")
|
||||||
|
):
|
||||||
|
raise ValueError(
|
||||||
|
f"Module package catalog source repository for {module_id!r} is invalid."
|
||||||
|
)
|
||||||
|
if _SOURCE_REF_RE.fullmatch(tag) is None or ".." in tag.split("/"):
|
||||||
|
raise ValueError(
|
||||||
|
f"Module package catalog source tag for {module_id!r} is invalid."
|
||||||
|
)
|
||||||
|
if _SOURCE_COMMIT_RE.fullmatch(commit) is None:
|
||||||
|
raise ValueError(
|
||||||
|
f"Module package catalog source commit for {module_id!r} is invalid."
|
||||||
|
)
|
||||||
|
source: dict[str, object] = {
|
||||||
|
"repository": repository,
|
||||||
|
"tag": tag,
|
||||||
|
"commit": commit,
|
||||||
|
}
|
||||||
|
for field in ("repository_url", "revision_url"):
|
||||||
|
url = _optional_str(value, field)
|
||||||
|
if url is not None:
|
||||||
|
source[field] = _catalog_https_url(
|
||||||
|
url,
|
||||||
|
label=f"Module package catalog source {field} for {module_id!r}",
|
||||||
|
)
|
||||||
|
return source
|
||||||
|
|
||||||
|
|
||||||
|
def _catalog_https_url(value: str, *, label: str) -> str:
|
||||||
|
if not is_http_url(value) or not value.startswith("https://"):
|
||||||
|
raise ValueError(f"{label} must use HTTPS.")
|
||||||
|
return value
|
||||||
|
|
||||||
|
|
||||||
def _catalog_migration_safety(value: Any, *, module_id: str) -> str:
|
def _catalog_migration_safety(value: Any, *, module_id: str) -> str:
|
||||||
if value is None:
|
if value is None:
|
||||||
return "automatic"
|
return "automatic"
|
||||||
@@ -698,14 +1013,14 @@ def _catalog_optional_positive_int(value: dict[str, Any], key: str, *, module_id
|
|||||||
return integer
|
return integer
|
||||||
|
|
||||||
|
|
||||||
def _required_str(value: dict[str, Any], key: str) -> str:
|
def _required_str(value: Mapping[str, Any], key: str) -> str:
|
||||||
item = _optional_str(value, key)
|
item = _optional_str(value, key)
|
||||||
if not item:
|
if not item:
|
||||||
raise ValueError(f"Module package catalog entry is missing {key!r}.")
|
raise ValueError(f"Module package catalog entry is missing {key!r}.")
|
||||||
return item
|
return item
|
||||||
|
|
||||||
|
|
||||||
def _optional_str(value: dict[str, Any], key: str) -> str | None:
|
def _optional_str(value: Mapping[str, Any], key: str) -> str | None:
|
||||||
item = value.get(key)
|
item = value.get(key)
|
||||||
if item is None:
|
if item is None:
|
||||||
return None
|
return None
|
||||||
@@ -861,20 +1176,40 @@ def _normalize_artifact_integrity(value: Any) -> dict[str, object]:
|
|||||||
continue
|
continue
|
||||||
if not isinstance(raw, dict):
|
if not isinstance(raw, dict):
|
||||||
raise ValueError(f"Module package catalog artifact_integrity.{key} must be an object.")
|
raise ValueError(f"Module package catalog artifact_integrity.{key} must be an object.")
|
||||||
clean = {
|
clean: dict[str, object] = {
|
||||||
field: text
|
field: text
|
||||||
for field in (
|
for field in (
|
||||||
"ref",
|
"ref",
|
||||||
"path",
|
"path",
|
||||||
"artifact_path",
|
"artifact_path",
|
||||||
|
"url",
|
||||||
|
"filename",
|
||||||
"sha256",
|
"sha256",
|
||||||
|
"integrity",
|
||||||
"sbom_url",
|
"sbom_url",
|
||||||
"provenance_url",
|
"provenance_url",
|
||||||
"registry_identity",
|
"registry_identity",
|
||||||
"git_ref",
|
"git_ref",
|
||||||
|
"source_commit",
|
||||||
)
|
)
|
||||||
if (text := _optional_str(raw, field))
|
if (text := _optional_str(raw, field))
|
||||||
}
|
}
|
||||||
|
url = clean.get("url")
|
||||||
|
if isinstance(url, str) and (not is_http_url(url) or not url.startswith("https://")):
|
||||||
|
raise ValueError(f"Module package catalog artifact_integrity.{key}.url must use HTTPS.")
|
||||||
|
filename = clean.get("filename")
|
||||||
|
if isinstance(filename, str) and _ARTIFACT_FILENAME_RE.fullmatch(filename) is None:
|
||||||
|
raise ValueError(f"Module package catalog artifact_integrity.{key}.filename is invalid.")
|
||||||
|
sha256 = clean.get("sha256")
|
||||||
|
if isinstance(sha256, str) and _SHA256_RE.fullmatch(sha256.lower()) is None:
|
||||||
|
raise ValueError(f"Module package catalog artifact_integrity.{key}.sha256 is invalid.")
|
||||||
|
if isinstance(sha256, str):
|
||||||
|
clean["sha256"] = sha256.lower()
|
||||||
|
size = raw.get("size")
|
||||||
|
if size is not None:
|
||||||
|
if not isinstance(size, int) or isinstance(size, bool) or size <= 0 or size > 512 * 1024 * 1024:
|
||||||
|
raise ValueError(f"Module package catalog artifact_integrity.{key}.size is invalid.")
|
||||||
|
clean["size"] = size
|
||||||
if clean:
|
if clean:
|
||||||
normalized[key] = clean
|
normalized[key] = clean
|
||||||
return normalized
|
return normalized
|
||||||
|
|||||||
@@ -1,23 +1,35 @@
|
|||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
from collections.abc import Callable, Iterable, Mapping, Sequence
|
from collections.abc import Callable, Iterable, Mapping, Sequence
|
||||||
from dataclasses import dataclass, field
|
from dataclasses import dataclass, field, replace
|
||||||
from typing import Any, Literal, Protocol, TYPE_CHECKING
|
from typing import Any, Literal, Protocol, TYPE_CHECKING
|
||||||
|
|
||||||
|
from govoplan_core.core.information_governance import ModuleInformationGovernance
|
||||||
from govoplan_core.core.ownership import OwnershipProviderRegistration
|
from govoplan_core.core.ownership import OwnershipProviderRegistration
|
||||||
|
from govoplan_core.core.provider_governance import (
|
||||||
|
ExternalProviderDeclaration,
|
||||||
|
ExternalProviderStateProviderRegistration,
|
||||||
|
ModuleArchitectureDeclaration,
|
||||||
|
)
|
||||||
from govoplan_core.core.views import ViewSurface
|
from govoplan_core.core.views import ViewSurface
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
from fastapi import APIRouter
|
from fastapi import APIRouter
|
||||||
|
from govoplan_core.core.operations import (
|
||||||
|
OperationalCheckProviderRegistration,
|
||||||
|
RuntimeWorkStatusProviderRegistration,
|
||||||
|
)
|
||||||
from govoplan_core.core.search import (
|
from govoplan_core.core.search import (
|
||||||
SearchProviderRegistration,
|
SearchProviderRegistration,
|
||||||
SearchSourceProviderRegistration,
|
SearchSourceProviderRegistration,
|
||||||
)
|
)
|
||||||
|
from govoplan_core.core.tasks import WorkItemProviderRegistration
|
||||||
from govoplan_core.core.workflows import WorkflowDefinitionContribution
|
from govoplan_core.core.workflows import WorkflowDefinitionContribution
|
||||||
|
|
||||||
|
|
||||||
SUPPORTED_MANIFEST_CONTRACT_VERSION = "1"
|
SUPPORTED_MANIFEST_CONTRACT_VERSION = "1"
|
||||||
SUPPORTED_FRONTEND_ASSET_MANIFEST_CONTRACT_VERSION = "1"
|
SUPPORTED_FRONTEND_ASSET_MANIFEST_CONTRACT_VERSION = "1"
|
||||||
|
SUPPORTED_PRESENTATION_CONTRACT_VERSION = "1"
|
||||||
|
|
||||||
PermissionLevel = Literal["system", "tenant"]
|
PermissionLevel = Literal["system", "tenant"]
|
||||||
SubjectType = Literal["account", "membership", "group", "service_account", "tenant"]
|
SubjectType = Literal["account", "membership", "group", "service_account", "tenant"]
|
||||||
@@ -27,7 +39,9 @@ MigrationTaskPhase = Literal[
|
|||||||
"post_migration_backfill",
|
"post_migration_backfill",
|
||||||
"post_migration_verify",
|
"post_migration_verify",
|
||||||
]
|
]
|
||||||
MigrationTaskSafety = Literal["automatic", "requires_review", "forward_only", "destructive"]
|
MigrationTaskSafety = Literal[
|
||||||
|
"automatic", "requires_review", "forward_only", "destructive"
|
||||||
|
]
|
||||||
MigrationTaskStatus = Literal["ok", "warning", "blocked", "skipped"]
|
MigrationTaskStatus = Literal["ok", "warning", "blocked", "skipped"]
|
||||||
|
|
||||||
|
|
||||||
@@ -68,8 +82,6 @@ class NavItem:
|
|||||||
surface_id: str | None = None
|
surface_id: str | None = None
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@dataclass(frozen=True, slots=True)
|
@dataclass(frozen=True, slots=True)
|
||||||
class FrontendRoute:
|
class FrontendRoute:
|
||||||
path: str
|
path: str
|
||||||
@@ -89,6 +101,43 @@ class PublicFrontendRoute:
|
|||||||
order: int = 100
|
order: int = 100
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass(frozen=True, slots=True)
|
||||||
|
class ProductAreaContribution:
|
||||||
|
"""Assign module-owned surfaces to a user-facing product area."""
|
||||||
|
|
||||||
|
id: str
|
||||||
|
module_id: str
|
||||||
|
label: str
|
||||||
|
icon: str
|
||||||
|
surface_ids: tuple[str, ...]
|
||||||
|
description: str | None = None
|
||||||
|
order: int = 100
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass(frozen=True, slots=True)
|
||||||
|
class QuickAccessTool:
|
||||||
|
"""Declare a versioned, bounded module-owned Quick Access tool."""
|
||||||
|
|
||||||
|
id: str
|
||||||
|
module_id: str
|
||||||
|
category_id: str
|
||||||
|
label: str
|
||||||
|
surface_id: str
|
||||||
|
icon: str
|
||||||
|
description: str | None = None
|
||||||
|
full_page_path: str | None = None
|
||||||
|
required_all: tuple[str, ...] = ()
|
||||||
|
required_any: tuple[str, ...] = ()
|
||||||
|
order: int = 100
|
||||||
|
default_enabled: bool = True
|
||||||
|
modes: tuple[str, ...] = ("browse",)
|
||||||
|
contract_version: str = "1"
|
||||||
|
availability: Literal["global", "active_object"] = "global"
|
||||||
|
accepted_reference_kinds: tuple[str, ...] = ()
|
||||||
|
returned_reference_kinds: tuple[str, ...] = ()
|
||||||
|
help_context_id: str | None = None
|
||||||
|
|
||||||
|
|
||||||
@dataclass(frozen=True, slots=True)
|
@dataclass(frozen=True, slots=True)
|
||||||
class FrontendModule:
|
class FrontendModule:
|
||||||
module_id: str
|
module_id: str
|
||||||
@@ -103,6 +152,8 @@ class FrontendModule:
|
|||||||
nav_items: tuple[NavItem, ...] = ()
|
nav_items: tuple[NavItem, ...] = ()
|
||||||
settings_routes: tuple[FrontendRoute, ...] = ()
|
settings_routes: tuple[FrontendRoute, ...] = ()
|
||||||
view_surfaces: tuple[ViewSurface, ...] = ()
|
view_surfaces: tuple[ViewSurface, ...] = ()
|
||||||
|
product_areas: tuple[ProductAreaContribution, ...] = ()
|
||||||
|
quick_access_tools: tuple[QuickAccessTool, ...] = ()
|
||||||
|
|
||||||
|
|
||||||
@dataclass(frozen=True, slots=True)
|
@dataclass(frozen=True, slots=True)
|
||||||
@@ -140,7 +191,9 @@ class ModuleMigrationTaskResult:
|
|||||||
details: Mapping[str, Any] = field(default_factory=dict)
|
details: Mapping[str, Any] = field(default_factory=dict)
|
||||||
|
|
||||||
|
|
||||||
ModuleMigrationTaskExecutor = Callable[[ModuleMigrationTaskContext], ModuleMigrationTaskResult | None]
|
ModuleMigrationTaskExecutor = Callable[
|
||||||
|
[ModuleMigrationTaskContext], ModuleMigrationTaskResult | None
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
@dataclass(frozen=True, slots=True)
|
@dataclass(frozen=True, slots=True)
|
||||||
@@ -197,7 +250,9 @@ class ModuleUninstallGuardResult:
|
|||||||
message: str
|
message: str
|
||||||
|
|
||||||
|
|
||||||
UninstallGuardProvider = Callable[[object | None, str], Iterable[ModuleUninstallGuardResult]]
|
UninstallGuardProvider = Callable[
|
||||||
|
[object | None, str], Iterable[ModuleUninstallGuardResult]
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
@dataclass(frozen=True, slots=True)
|
@dataclass(frozen=True, slots=True)
|
||||||
@@ -217,7 +272,9 @@ class ModuleContext:
|
|||||||
DocumentationLayer = Literal["always", "configured", "available", "evidence"]
|
DocumentationLayer = Literal["always", "configured", "available", "evidence"]
|
||||||
DocumentationLinkKind = Literal["runtime", "api", "repository", "wiki", "public"]
|
DocumentationLinkKind = Literal["runtime", "api", "repository", "wiki", "public"]
|
||||||
DocumentationType = Literal["admin", "user"]
|
DocumentationType = Literal["admin", "user"]
|
||||||
DocumentationConfigurationState = Literal["enabled", "disabled", "inherited", "unavailable"]
|
DocumentationConfigurationState = Literal[
|
||||||
|
"enabled", "disabled", "inherited", "unavailable"
|
||||||
|
]
|
||||||
DocumentationSourceKind = Literal[
|
DocumentationSourceKind = Literal[
|
||||||
"manifest",
|
"manifest",
|
||||||
"route",
|
"route",
|
||||||
@@ -232,6 +289,30 @@ DocumentationSourceState = Literal["configured", "disabled", "unavailable"]
|
|||||||
CapabilityStability = Literal["experimental", "stable", "deprecated"]
|
CapabilityStability = Literal["experimental", "stable", "deprecated"]
|
||||||
|
|
||||||
|
|
||||||
|
DOCUMENTATION_STRUCTURED_TRANSLATION_VERSION = "1"
|
||||||
|
DOCUMENTATION_LOCALIZABLE_METADATA_KEYS = frozenset(
|
||||||
|
{
|
||||||
|
"admin_explanation",
|
||||||
|
"consequence_classes",
|
||||||
|
"consequences",
|
||||||
|
"constraints",
|
||||||
|
"current_configuration",
|
||||||
|
"fields",
|
||||||
|
"limitations",
|
||||||
|
"operational_consequences",
|
||||||
|
"outcome",
|
||||||
|
"prerequisites",
|
||||||
|
"privacy_notes",
|
||||||
|
"purpose",
|
||||||
|
"result",
|
||||||
|
"steps",
|
||||||
|
"user_explanation",
|
||||||
|
"verification",
|
||||||
|
"when_used",
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
@dataclass(frozen=True, slots=True)
|
@dataclass(frozen=True, slots=True)
|
||||||
class DocumentationLink:
|
class DocumentationLink:
|
||||||
label: str
|
label: str
|
||||||
@@ -267,10 +348,142 @@ class DocumentationTopic:
|
|||||||
configuration_keys: tuple[str, ...] = ()
|
configuration_keys: tuple[str, ...] = ()
|
||||||
i18n_key: str | None = None
|
i18n_key: str | None = None
|
||||||
translations: Mapping[str, Mapping[str, str]] = field(default_factory=dict)
|
translations: Mapping[str, Mapping[str, str]] = field(default_factory=dict)
|
||||||
|
structured_translation_version: str | None = None
|
||||||
|
structured_translations: Mapping[str, Mapping[str, Any]] = field(
|
||||||
|
default_factory=dict
|
||||||
|
)
|
||||||
source_module_id: str | None = None
|
source_module_id: str | None = None
|
||||||
|
version_min: str | None = None
|
||||||
|
version_max_exclusive: str | None = None
|
||||||
metadata: Mapping[str, Any] = field(default_factory=dict)
|
metadata: Mapping[str, Any] = field(default_factory=dict)
|
||||||
|
|
||||||
|
|
||||||
|
def localizable_documentation_metadata_keys(
|
||||||
|
topic: DocumentationTopic,
|
||||||
|
) -> tuple[str, ...]:
|
||||||
|
"""Return structured metadata keys whose values are public prose."""
|
||||||
|
|
||||||
|
return tuple(
|
||||||
|
sorted(DOCUMENTATION_LOCALIZABLE_METADATA_KEYS.intersection(topic.metadata))
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def localized_documentation_metadata(
|
||||||
|
topic: DocumentationTopic,
|
||||||
|
locale: str,
|
||||||
|
) -> dict[str, Any]:
|
||||||
|
"""Overlay one validated structured translation onto source metadata."""
|
||||||
|
|
||||||
|
localized = dict(topic.metadata)
|
||||||
|
translation = topic.structured_translations.get(locale)
|
||||||
|
if translation:
|
||||||
|
localized.update(translation)
|
||||||
|
return localized
|
||||||
|
|
||||||
|
|
||||||
|
def documentation_structured_translation_issues(
|
||||||
|
topic: DocumentationTopic,
|
||||||
|
) -> tuple[str, ...]:
|
||||||
|
"""Validate the opt-in, versioned structured-documentation translation."""
|
||||||
|
|
||||||
|
version = topic.structured_translation_version
|
||||||
|
translations = topic.structured_translations
|
||||||
|
if version is None:
|
||||||
|
if translations:
|
||||||
|
return (
|
||||||
|
"structured_translations require structured_translation_version",
|
||||||
|
)
|
||||||
|
return ()
|
||||||
|
if version != DOCUMENTATION_STRUCTURED_TRANSLATION_VERSION:
|
||||||
|
return (
|
||||||
|
"unsupported structured_translation_version "
|
||||||
|
f"{version!r}; expected {DOCUMENTATION_STRUCTURED_TRANSLATION_VERSION!r}",
|
||||||
|
)
|
||||||
|
|
||||||
|
localizable_keys = set(localizable_documentation_metadata_keys(topic))
|
||||||
|
issues: list[str] = []
|
||||||
|
for locale, translation in translations.items():
|
||||||
|
if not locale.strip():
|
||||||
|
issues.append("structured translation locale must not be empty")
|
||||||
|
continue
|
||||||
|
translated_keys = set(translation)
|
||||||
|
for key in sorted(translated_keys - localizable_keys):
|
||||||
|
issues.append(
|
||||||
|
f"structured translation {locale!r} contains non-localizable or missing metadata key {key!r}"
|
||||||
|
)
|
||||||
|
for key in sorted(localizable_keys - translated_keys):
|
||||||
|
issues.append(
|
||||||
|
f"structured translation {locale!r} is missing metadata key {key!r}"
|
||||||
|
)
|
||||||
|
for key in sorted(localizable_keys & translated_keys):
|
||||||
|
issues.extend(
|
||||||
|
_structured_translation_shape_issues(
|
||||||
|
topic.metadata[key],
|
||||||
|
translation[key],
|
||||||
|
path=f"{locale}.{key}",
|
||||||
|
)
|
||||||
|
)
|
||||||
|
return tuple(issues)
|
||||||
|
|
||||||
|
|
||||||
|
def _structured_translation_shape_issues(
|
||||||
|
source: object,
|
||||||
|
translated: object,
|
||||||
|
*,
|
||||||
|
path: str,
|
||||||
|
) -> tuple[str, ...]:
|
||||||
|
if isinstance(source, str):
|
||||||
|
if not isinstance(translated, str) or not translated.strip():
|
||||||
|
return (f"structured translation {path} must be a non-empty string",)
|
||||||
|
return ()
|
||||||
|
if isinstance(source, Mapping):
|
||||||
|
if not isinstance(translated, Mapping):
|
||||||
|
return (f"structured translation {path} must preserve object shape",)
|
||||||
|
issues: list[str] = []
|
||||||
|
source_keys = {str(key) for key in source}
|
||||||
|
translated_keys = {str(key) for key in translated}
|
||||||
|
if source_keys != translated_keys:
|
||||||
|
issues.append(
|
||||||
|
f"structured translation {path} must preserve object keys"
|
||||||
|
)
|
||||||
|
return tuple(issues)
|
||||||
|
for key, value in source.items():
|
||||||
|
issues.extend(
|
||||||
|
_structured_translation_shape_issues(
|
||||||
|
value,
|
||||||
|
translated[key],
|
||||||
|
path=f"{path}.{key}",
|
||||||
|
)
|
||||||
|
)
|
||||||
|
return tuple(issues)
|
||||||
|
if isinstance(source, Sequence) and not isinstance(
|
||||||
|
source, (str, bytes, bytearray)
|
||||||
|
):
|
||||||
|
if not isinstance(translated, Sequence) or isinstance(
|
||||||
|
translated, (str, bytes, bytearray)
|
||||||
|
):
|
||||||
|
return (f"structured translation {path} must preserve list shape",)
|
||||||
|
if len(source) != len(translated):
|
||||||
|
return (f"structured translation {path} must preserve list length",)
|
||||||
|
issues: list[str] = []
|
||||||
|
for index, (source_item, translated_item) in enumerate(
|
||||||
|
zip(source, translated, strict=True)
|
||||||
|
):
|
||||||
|
issues.extend(
|
||||||
|
_structured_translation_shape_issues(
|
||||||
|
source_item,
|
||||||
|
translated_item,
|
||||||
|
path=f"{path}[{index}]",
|
||||||
|
)
|
||||||
|
)
|
||||||
|
return tuple(issues)
|
||||||
|
if translated != source:
|
||||||
|
return (
|
||||||
|
f"structured translation {path} must preserve non-text value {source!r}",
|
||||||
|
)
|
||||||
|
return ()
|
||||||
|
|
||||||
|
|
||||||
def user_workflow_scope_condition_issues(topic: DocumentationTopic) -> tuple[str, ...]:
|
def user_workflow_scope_condition_issues(topic: DocumentationTopic) -> tuple[str, ...]:
|
||||||
"""Return fail-closed authoring issues for a user-facing workflow topic.
|
"""Return fail-closed authoring issues for a user-facing workflow topic.
|
||||||
|
|
||||||
@@ -280,16 +493,23 @@ def user_workflow_scope_condition_issues(topic: DocumentationTopic) -> tuple[str
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
raw_kind = topic.metadata.get("kind")
|
raw_kind = topic.metadata.get("kind")
|
||||||
kind = raw_kind.strip().lower().replace("_", "-") if isinstance(raw_kind, str) else ""
|
kind = (
|
||||||
|
raw_kind.strip().lower().replace("_", "-") if isinstance(raw_kind, str) else ""
|
||||||
|
)
|
||||||
if kind != "workflow" or "user" not in topic.documentation_types:
|
if kind != "workflow" or "user" not in topic.documentation_types:
|
||||||
return ()
|
return ()
|
||||||
if not topic.conditions:
|
if not topic.conditions:
|
||||||
return ("user workflow topics must declare at least one scope-conditioned alternative",)
|
return (
|
||||||
|
"user workflow topics must declare at least one scope-conditioned alternative",
|
||||||
|
)
|
||||||
|
|
||||||
unscoped_alternatives = tuple(
|
unscoped_alternatives = tuple(
|
||||||
index
|
index
|
||||||
for index, condition in enumerate(topic.conditions, start=1)
|
for index, condition in enumerate(topic.conditions, start=1)
|
||||||
if not any(scope.strip() for scope in (*condition.required_scopes, *condition.any_scopes))
|
if not any(
|
||||||
|
scope.strip()
|
||||||
|
for scope in (*condition.required_scopes, *condition.any_scopes)
|
||||||
|
)
|
||||||
)
|
)
|
||||||
if not unscoped_alternatives:
|
if not unscoped_alternatives:
|
||||||
return ()
|
return ()
|
||||||
@@ -361,14 +581,11 @@ class CapabilityDocumentation:
|
|||||||
class ResourceAclProvider(Protocol):
|
class ResourceAclProvider(Protocol):
|
||||||
resource_type: str
|
resource_type: str
|
||||||
|
|
||||||
def can_read(self, principal: object, resource_id: str) -> bool:
|
def can_read(self, principal: object, resource_id: str) -> bool: ...
|
||||||
...
|
|
||||||
|
|
||||||
def can_write(self, principal: object, resource_id: str) -> bool:
|
def can_write(self, principal: object, resource_id: str) -> bool: ...
|
||||||
...
|
|
||||||
|
|
||||||
def explain(self, principal: object, resource_id: str) -> AccessDecision:
|
def explain(self, principal: object, resource_id: str) -> AccessDecision: ...
|
||||||
...
|
|
||||||
|
|
||||||
|
|
||||||
TenantSummaryProvider = Callable[[object, str], Mapping[str, int]]
|
TenantSummaryProvider = Callable[[object, str], Mapping[str, int]]
|
||||||
@@ -400,6 +617,7 @@ class DeleteVetoProviderRegistration:
|
|||||||
|
|
||||||
RouteFactory = Callable[[ModuleContext], "APIRouter"]
|
RouteFactory = Callable[[ModuleContext], "APIRouter"]
|
||||||
CapabilityFactory = Callable[[ModuleContext], object]
|
CapabilityFactory = Callable[[ModuleContext], object]
|
||||||
|
PublicTenantResolver = Callable[[object, object], str | None]
|
||||||
DocumentationProvider = Callable[[DocumentationContext], Iterable[DocumentationTopic]]
|
DocumentationProvider = Callable[[DocumentationContext], Iterable[DocumentationTopic]]
|
||||||
LifecycleHook = Callable[[ModuleContext], None]
|
LifecycleHook = Callable[[ModuleContext], None]
|
||||||
|
|
||||||
@@ -418,6 +636,7 @@ class ModuleManifest:
|
|||||||
permissions: tuple[PermissionDefinition, ...] = ()
|
permissions: tuple[PermissionDefinition, ...] = ()
|
||||||
role_templates: tuple[RoleTemplate, ...] = ()
|
role_templates: tuple[RoleTemplate, ...] = ()
|
||||||
route_factory: RouteFactory | None = None
|
route_factory: RouteFactory | None = None
|
||||||
|
public_tenant_resolver: PublicTenantResolver | None = None
|
||||||
migration_spec: MigrationSpec | None = None
|
migration_spec: MigrationSpec | None = None
|
||||||
nav_items: tuple[NavItem, ...] = ()
|
nav_items: tuple[NavItem, ...] = ()
|
||||||
frontend: FrontendModule | None = None
|
frontend: FrontendModule | None = None
|
||||||
@@ -425,12 +644,34 @@ class ModuleManifest:
|
|||||||
ownership_providers: tuple[OwnershipProviderRegistration, ...] = ()
|
ownership_providers: tuple[OwnershipProviderRegistration, ...] = ()
|
||||||
tenant_summary_providers: tuple[TenantSummaryProvider, ...] = ()
|
tenant_summary_providers: tuple[TenantSummaryProvider, ...] = ()
|
||||||
tenant_summary_batch_providers: tuple[TenantSummaryBatchProvider, ...] = ()
|
tenant_summary_batch_providers: tuple[TenantSummaryBatchProvider, ...] = ()
|
||||||
delete_veto_providers: Mapping[str, Sequence[DeleteVetoProvider]] = field(default_factory=dict)
|
delete_veto_providers: Mapping[str, Sequence[DeleteVetoProvider]] = field(
|
||||||
|
default_factory=dict
|
||||||
|
)
|
||||||
uninstall_guard_providers: tuple[UninstallGuardProvider, ...] = ()
|
uninstall_guard_providers: tuple[UninstallGuardProvider, ...] = ()
|
||||||
capability_factories: Mapping[str, CapabilityFactory] = field(default_factory=dict)
|
capability_factories: Mapping[str, CapabilityFactory] = field(default_factory=dict)
|
||||||
capability_documentation: Mapping[str, CapabilityDocumentation] = field(default_factory=dict)
|
capability_documentation: Mapping[str, CapabilityDocumentation] = field(
|
||||||
|
default_factory=dict
|
||||||
|
)
|
||||||
search_providers: tuple["SearchProviderRegistration", ...] = ()
|
search_providers: tuple["SearchProviderRegistration", ...] = ()
|
||||||
search_sources: tuple["SearchSourceProviderRegistration", ...] = ()
|
search_sources: tuple["SearchSourceProviderRegistration", ...] = ()
|
||||||
|
work_item_providers: tuple["WorkItemProviderRegistration", ...] = ()
|
||||||
|
operational_check_providers: tuple[
|
||||||
|
"OperationalCheckProviderRegistration",
|
||||||
|
...,
|
||||||
|
] = ()
|
||||||
|
runtime_work_status_providers: tuple[
|
||||||
|
"RuntimeWorkStatusProviderRegistration",
|
||||||
|
...,
|
||||||
|
] = ()
|
||||||
|
architecture: ModuleArchitectureDeclaration | None = None
|
||||||
|
information_governance: ModuleInformationGovernance = field(
|
||||||
|
default_factory=ModuleInformationGovernance
|
||||||
|
)
|
||||||
|
external_providers: tuple[ExternalProviderDeclaration, ...] = ()
|
||||||
|
external_provider_state_providers: tuple[
|
||||||
|
ExternalProviderStateProviderRegistration,
|
||||||
|
...,
|
||||||
|
] = ()
|
||||||
compatibility: ModuleCompatibility = field(default_factory=ModuleCompatibility)
|
compatibility: ModuleCompatibility = field(default_factory=ModuleCompatibility)
|
||||||
on_activate: LifecycleHook | None = None
|
on_activate: LifecycleHook | None = None
|
||||||
on_deactivate: LifecycleHook | None = None
|
on_deactivate: LifecycleHook | None = None
|
||||||
@@ -446,3 +687,53 @@ class ModuleManifest:
|
|||||||
# runtime module ID changes.
|
# runtime module ID changes.
|
||||||
permission_namespace: str | None = None
|
permission_namespace: str | None = None
|
||||||
workflow_definitions: tuple["WorkflowDefinitionContribution", ...] = ()
|
workflow_definitions: tuple["WorkflowDefinitionContribution", ...] = ()
|
||||||
|
|
||||||
|
|
||||||
|
def with_documentation_structured_translations(
|
||||||
|
manifest: ModuleManifest,
|
||||||
|
*,
|
||||||
|
locale: str,
|
||||||
|
translations: Mapping[str, Mapping[str, Any]],
|
||||||
|
) -> ModuleManifest:
|
||||||
|
"""Merge module-owned structured documentation translations by topic id.
|
||||||
|
|
||||||
|
The helper keeps feature prose in its owning module while giving every
|
||||||
|
manifest the same fail-closed merge behavior. Unknown topic ids and
|
||||||
|
incomplete or shape-changing locale maps are rejected immediately.
|
||||||
|
"""
|
||||||
|
|
||||||
|
locale = locale.strip()
|
||||||
|
if not locale:
|
||||||
|
raise ValueError("structured documentation locale must not be empty")
|
||||||
|
|
||||||
|
topics_by_id = {topic.id: topic for topic in manifest.documentation}
|
||||||
|
unknown_topic_ids = sorted(set(translations) - set(topics_by_id))
|
||||||
|
if unknown_topic_ids:
|
||||||
|
raise ValueError(
|
||||||
|
"structured documentation translations reference unknown topic ids: "
|
||||||
|
+ ", ".join(unknown_topic_ids)
|
||||||
|
)
|
||||||
|
|
||||||
|
localized_topics: list[DocumentationTopic] = []
|
||||||
|
for topic in manifest.documentation:
|
||||||
|
translation = translations.get(topic.id)
|
||||||
|
if translation is None:
|
||||||
|
localized_topics.append(topic)
|
||||||
|
continue
|
||||||
|
|
||||||
|
structured_translations = dict(topic.structured_translations)
|
||||||
|
structured_translations[locale] = translation
|
||||||
|
localized_topic = replace(
|
||||||
|
topic,
|
||||||
|
structured_translation_version=DOCUMENTATION_STRUCTURED_TRANSLATION_VERSION,
|
||||||
|
structured_translations=structured_translations,
|
||||||
|
)
|
||||||
|
issues = documentation_structured_translation_issues(localized_topic)
|
||||||
|
if issues:
|
||||||
|
raise ValueError(
|
||||||
|
f"invalid {locale!r} structured documentation translation for "
|
||||||
|
f"{topic.id!r}: {'; '.join(issues)}"
|
||||||
|
)
|
||||||
|
localized_topics.append(localized_topic)
|
||||||
|
|
||||||
|
return replace(manifest, documentation=tuple(localized_topics))
|
||||||
|
|||||||
@@ -0,0 +1,175 @@
|
|||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
from dataclasses import dataclass
|
||||||
|
from typing import Any, Iterable, Mapping
|
||||||
|
|
||||||
|
NAVIGATION_PREFERENCES_KEY = "navigation_preferences"
|
||||||
|
NAVIGATION_PREFERENCES_CONTRACT_VERSION = "1"
|
||||||
|
_MAX_ITEMS = 256
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass(frozen=True, slots=True)
|
||||||
|
class NavigationPreferences:
|
||||||
|
order: tuple[str, ...] = ()
|
||||||
|
hidden: tuple[str, ...] = ()
|
||||||
|
locked: tuple[str, ...] = ()
|
||||||
|
|
||||||
|
def as_dict(self) -> dict[str, object]:
|
||||||
|
return {
|
||||||
|
"contract_version": NAVIGATION_PREFERENCES_CONTRACT_VERSION,
|
||||||
|
"order": list(self.order),
|
||||||
|
"hidden": list(self.hidden),
|
||||||
|
"locked": list(self.locked),
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass(frozen=True, slots=True)
|
||||||
|
class EffectiveNavigationItem:
|
||||||
|
id: str
|
||||||
|
order: int
|
||||||
|
visible: bool
|
||||||
|
locked: bool
|
||||||
|
order_source: str
|
||||||
|
visibility_source: str
|
||||||
|
lock_source: str | None = None
|
||||||
|
|
||||||
|
def as_dict(self) -> dict[str, object]:
|
||||||
|
return {
|
||||||
|
"navigation_id": self.id,
|
||||||
|
"order": self.order,
|
||||||
|
"navigation_visible": self.visible,
|
||||||
|
"navigation_locked": self.locked,
|
||||||
|
"navigation_order_source": self.order_source,
|
||||||
|
"navigation_visibility_source": self.visibility_source,
|
||||||
|
"navigation_lock_source": self.lock_source,
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
def navigation_preferences_from_settings(
|
||||||
|
settings: object,
|
||||||
|
) -> NavigationPreferences | None:
|
||||||
|
if not isinstance(settings, Mapping):
|
||||||
|
return None
|
||||||
|
raw = settings.get(NAVIGATION_PREFERENCES_KEY)
|
||||||
|
if not isinstance(raw, Mapping):
|
||||||
|
return None
|
||||||
|
return navigation_preferences_from_mapping(raw)
|
||||||
|
|
||||||
|
|
||||||
|
def navigation_preferences_from_mapping(
|
||||||
|
raw: Mapping[str, Any],
|
||||||
|
) -> NavigationPreferences:
|
||||||
|
return NavigationPreferences(
|
||||||
|
order=_ids(raw.get("order")),
|
||||||
|
hidden=_ids(raw.get("hidden")),
|
||||||
|
locked=_ids(raw.get("locked")),
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def update_navigation_preferences(
|
||||||
|
settings: object,
|
||||||
|
preferences: NavigationPreferences | Mapping[str, Any] | None,
|
||||||
|
) -> dict[str, Any]:
|
||||||
|
updated = dict(settings) if isinstance(settings, Mapping) else {}
|
||||||
|
if preferences is None:
|
||||||
|
updated.pop(NAVIGATION_PREFERENCES_KEY, None)
|
||||||
|
else:
|
||||||
|
raw = preferences.as_dict() if isinstance(preferences, NavigationPreferences) else preferences
|
||||||
|
updated[NAVIGATION_PREFERENCES_KEY] = navigation_preferences_from_mapping(
|
||||||
|
raw
|
||||||
|
).as_dict()
|
||||||
|
return updated
|
||||||
|
|
||||||
|
|
||||||
|
def resolve_navigation_preferences(
|
||||||
|
item_ids: Iterable[str],
|
||||||
|
*,
|
||||||
|
system: NavigationPreferences | None = None,
|
||||||
|
tenant: NavigationPreferences | None = None,
|
||||||
|
user: NavigationPreferences | None = None,
|
||||||
|
) -> dict[str, EffectiveNavigationItem]:
|
||||||
|
ordered = list(dict.fromkeys(_clean_id(item_id) for item_id in item_ids))
|
||||||
|
ordered = [item_id for item_id in ordered if item_id]
|
||||||
|
available = set(ordered)
|
||||||
|
order_source = {item_id: "module" for item_id in ordered}
|
||||||
|
visibility = {item_id: True for item_id in ordered}
|
||||||
|
visibility_source = {item_id: "module" for item_id in ordered}
|
||||||
|
locks: dict[str, str] = {}
|
||||||
|
|
||||||
|
for source, preferences, may_lock in (
|
||||||
|
("system", system, True),
|
||||||
|
("tenant", tenant, True),
|
||||||
|
("user", user, False),
|
||||||
|
):
|
||||||
|
if preferences is None:
|
||||||
|
continue
|
||||||
|
requested_order = [item_id for item_id in preferences.order if item_id in available]
|
||||||
|
if requested_order:
|
||||||
|
requested = set(requested_order)
|
||||||
|
ordered = [*requested_order, *(item_id for item_id in ordered if item_id not in requested)]
|
||||||
|
for item_id in requested_order:
|
||||||
|
order_source[item_id] = source
|
||||||
|
|
||||||
|
requested_hidden = set(preferences.hidden).intersection(available)
|
||||||
|
for item_id in available:
|
||||||
|
if item_id in locks:
|
||||||
|
visibility[item_id] = True
|
||||||
|
visibility_source[item_id] = locks[item_id]
|
||||||
|
continue
|
||||||
|
visibility[item_id] = item_id not in requested_hidden
|
||||||
|
visibility_source[item_id] = source
|
||||||
|
|
||||||
|
if may_lock:
|
||||||
|
for item_id in preferences.locked:
|
||||||
|
if item_id not in available:
|
||||||
|
continue
|
||||||
|
locks[item_id] = source
|
||||||
|
visibility[item_id] = True
|
||||||
|
visibility_source[item_id] = source
|
||||||
|
|
||||||
|
return {
|
||||||
|
item_id: EffectiveNavigationItem(
|
||||||
|
id=item_id,
|
||||||
|
order=index,
|
||||||
|
visible=visibility[item_id],
|
||||||
|
locked=item_id in locks,
|
||||||
|
order_source=order_source[item_id],
|
||||||
|
visibility_source=visibility_source[item_id],
|
||||||
|
lock_source=locks.get(item_id),
|
||||||
|
)
|
||||||
|
for index, item_id in enumerate(ordered)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
def _ids(value: object) -> tuple[str, ...]:
|
||||||
|
if not isinstance(value, (list, tuple)):
|
||||||
|
return ()
|
||||||
|
cleaned = tuple(
|
||||||
|
dict.fromkeys(
|
||||||
|
item_id
|
||||||
|
for item in value[:_MAX_ITEMS]
|
||||||
|
if (item_id := _clean_id(item))
|
||||||
|
)
|
||||||
|
)
|
||||||
|
return cleaned
|
||||||
|
|
||||||
|
|
||||||
|
def _clean_id(value: object) -> str:
|
||||||
|
if not isinstance(value, str):
|
||||||
|
return ""
|
||||||
|
clean = value.strip()
|
||||||
|
if not clean or len(clean) > 255 or any(ord(character) < 32 for character in clean):
|
||||||
|
return ""
|
||||||
|
return clean
|
||||||
|
|
||||||
|
|
||||||
|
__all__ = [
|
||||||
|
"EffectiveNavigationItem",
|
||||||
|
"NAVIGATION_PREFERENCES_CONTRACT_VERSION",
|
||||||
|
"NAVIGATION_PREFERENCES_KEY",
|
||||||
|
"NavigationPreferences",
|
||||||
|
"navigation_preferences_from_mapping",
|
||||||
|
"navigation_preferences_from_settings",
|
||||||
|
"resolve_navigation_preferences",
|
||||||
|
"update_navigation_preferences",
|
||||||
|
]
|
||||||
@@ -33,6 +33,14 @@ class NotificationDispatchRequest:
|
|||||||
|
|
||||||
@runtime_checkable
|
@runtime_checkable
|
||||||
class NotificationDispatchProvider(Protocol):
|
class NotificationDispatchProvider(Protocol):
|
||||||
|
def tenant_id_for_notification(
|
||||||
|
self,
|
||||||
|
session: object,
|
||||||
|
*,
|
||||||
|
notification_id: str,
|
||||||
|
) -> str | None:
|
||||||
|
...
|
||||||
|
|
||||||
def enqueue_notification(
|
def enqueue_notification(
|
||||||
self,
|
self,
|
||||||
session: object,
|
session: object,
|
||||||
|
|||||||
@@ -0,0 +1,622 @@
|
|||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
from dataclasses import dataclass, field
|
||||||
|
from datetime import datetime, timezone
|
||||||
|
from heapq import nsmallest
|
||||||
|
import os
|
||||||
|
from pathlib import Path
|
||||||
|
import tempfile
|
||||||
|
from typing import Any, Iterable, Protocol
|
||||||
|
from urllib.parse import urlsplit
|
||||||
|
|
||||||
|
from govoplan_core.security.outbound_http import (
|
||||||
|
OutboundHttpError,
|
||||||
|
response_limit,
|
||||||
|
validate_unpinned_sdk_http_url,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
class StorageBackendError(RuntimeError):
|
||||||
|
"""Base error for the deployment-owned object-storage boundary."""
|
||||||
|
|
||||||
|
|
||||||
|
class StorageObjectMissing(StorageBackendError):
|
||||||
|
"""Raised when a referenced object no longer exists."""
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass(frozen=True, slots=True)
|
||||||
|
class StorageObjectInfo:
|
||||||
|
key: str
|
||||||
|
size_bytes: int
|
||||||
|
modified_at: datetime | None = None
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass(frozen=True, slots=True)
|
||||||
|
class StorageObjectPage:
|
||||||
|
objects: tuple[StorageObjectInfo, ...]
|
||||||
|
next_cursor: str | None = None
|
||||||
|
|
||||||
|
|
||||||
|
class StorageBackend(Protocol):
|
||||||
|
"""Shared byte-object storage used by modules without cross-module imports."""
|
||||||
|
|
||||||
|
name: str
|
||||||
|
|
||||||
|
def put_bytes(
|
||||||
|
self,
|
||||||
|
key: str,
|
||||||
|
data: bytes,
|
||||||
|
*,
|
||||||
|
content_type: str | None = None,
|
||||||
|
) -> None: ...
|
||||||
|
|
||||||
|
def get_bytes(self, key: str) -> bytes: ...
|
||||||
|
|
||||||
|
def iter_bytes(
|
||||||
|
self,
|
||||||
|
key: str,
|
||||||
|
*,
|
||||||
|
chunk_size: int = 1024 * 1024,
|
||||||
|
) -> Iterable[bytes]: ...
|
||||||
|
|
||||||
|
def delete(self, key: str) -> None: ...
|
||||||
|
|
||||||
|
def exists(self, key: str) -> bool: ...
|
||||||
|
|
||||||
|
def stat(self, key: str) -> StorageObjectInfo: ...
|
||||||
|
|
||||||
|
def list_objects(
|
||||||
|
self,
|
||||||
|
*,
|
||||||
|
prefix: str,
|
||||||
|
after: str | None = None,
|
||||||
|
limit: int = 500,
|
||||||
|
) -> StorageObjectPage: ...
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass(slots=True)
|
||||||
|
class LocalFilesystemStorageBackend:
|
||||||
|
root: Path
|
||||||
|
fallback_roots: tuple[Path, ...] = field(default_factory=tuple)
|
||||||
|
name: str = "local"
|
||||||
|
|
||||||
|
def __post_init__(self) -> None:
|
||||||
|
self.root = self.root.expanduser().resolve()
|
||||||
|
self.fallback_roots = tuple(
|
||||||
|
root.expanduser().resolve() for root in self.fallback_roots if root
|
||||||
|
)
|
||||||
|
self.root.mkdir(parents=True, exist_ok=True)
|
||||||
|
|
||||||
|
def _path_for_root(self, root: Path, key: str) -> Path:
|
||||||
|
normalized = normalize_storage_key(key)
|
||||||
|
path = (root / normalized).resolve()
|
||||||
|
if not path.is_relative_to(root):
|
||||||
|
raise StorageBackendError("Storage key escapes local storage root")
|
||||||
|
return path
|
||||||
|
|
||||||
|
def _path(self, key: str) -> Path:
|
||||||
|
return self._path_for_root(self.root, key)
|
||||||
|
|
||||||
|
def _readable_path(self, key: str) -> Path:
|
||||||
|
primary = self._path(key)
|
||||||
|
if primary.exists() and primary.is_file():
|
||||||
|
return primary
|
||||||
|
for root in self.fallback_roots:
|
||||||
|
candidate = self._path_for_root(root, key)
|
||||||
|
if candidate.exists() and candidate.is_file():
|
||||||
|
return candidate
|
||||||
|
raise StorageObjectMissing("Stored object does not exist")
|
||||||
|
|
||||||
|
def put_bytes(
|
||||||
|
self,
|
||||||
|
key: str,
|
||||||
|
data: bytes,
|
||||||
|
*,
|
||||||
|
content_type: str | None = None,
|
||||||
|
) -> None:
|
||||||
|
del content_type
|
||||||
|
path = self._path(key)
|
||||||
|
path.parent.mkdir(parents=True, exist_ok=True)
|
||||||
|
descriptor, temporary_name = tempfile.mkstemp(
|
||||||
|
prefix=f".{path.name}.",
|
||||||
|
suffix=".tmp",
|
||||||
|
dir=path.parent,
|
||||||
|
)
|
||||||
|
temporary = Path(temporary_name)
|
||||||
|
try:
|
||||||
|
os.fchmod(descriptor, 0o600)
|
||||||
|
with os.fdopen(descriptor, "wb") as stream:
|
||||||
|
descriptor = -1
|
||||||
|
stream.write(data)
|
||||||
|
stream.flush()
|
||||||
|
os.fsync(stream.fileno())
|
||||||
|
temporary.replace(path)
|
||||||
|
finally:
|
||||||
|
if descriptor >= 0:
|
||||||
|
os.close(descriptor)
|
||||||
|
temporary.unlink(missing_ok=True)
|
||||||
|
|
||||||
|
def get_bytes(self, key: str) -> bytes:
|
||||||
|
return self._readable_path(key).read_bytes()
|
||||||
|
|
||||||
|
def iter_bytes(
|
||||||
|
self,
|
||||||
|
key: str,
|
||||||
|
*,
|
||||||
|
chunk_size: int = 1024 * 1024,
|
||||||
|
) -> Iterable[bytes]:
|
||||||
|
path = self._readable_path(key)
|
||||||
|
with path.open("rb") as handle:
|
||||||
|
while True:
|
||||||
|
chunk = handle.read(chunk_size)
|
||||||
|
if not chunk:
|
||||||
|
break
|
||||||
|
yield chunk
|
||||||
|
|
||||||
|
def delete(self, key: str) -> None:
|
||||||
|
path = self._path(key)
|
||||||
|
if path.exists() and path.is_file():
|
||||||
|
path.unlink()
|
||||||
|
|
||||||
|
def exists(self, key: str) -> bool:
|
||||||
|
try:
|
||||||
|
self._readable_path(key)
|
||||||
|
except StorageObjectMissing:
|
||||||
|
return False
|
||||||
|
return True
|
||||||
|
|
||||||
|
def stat(self, key: str) -> StorageObjectInfo:
|
||||||
|
path = self._readable_path(key)
|
||||||
|
metadata = path.stat()
|
||||||
|
return StorageObjectInfo(
|
||||||
|
key=normalize_storage_key(key),
|
||||||
|
size_bytes=metadata.st_size,
|
||||||
|
modified_at=datetime.fromtimestamp(
|
||||||
|
metadata.st_mtime,
|
||||||
|
tz=timezone.utc,
|
||||||
|
),
|
||||||
|
)
|
||||||
|
|
||||||
|
def list_objects(
|
||||||
|
self,
|
||||||
|
*,
|
||||||
|
prefix: str,
|
||||||
|
after: str | None = None,
|
||||||
|
limit: int = 500,
|
||||||
|
) -> StorageObjectPage:
|
||||||
|
normalized_prefix = normalize_storage_prefix(prefix)
|
||||||
|
normalized_after = normalize_storage_key(after) if after else None
|
||||||
|
normalized_limit = max(1, min(int(limit), 5000))
|
||||||
|
|
||||||
|
def matching_objects() -> Iterable[StorageObjectInfo]:
|
||||||
|
for path in _iter_local_files(self.root):
|
||||||
|
key = path.relative_to(self.root).as_posix()
|
||||||
|
if not key.startswith(normalized_prefix) or (
|
||||||
|
normalized_after is not None and key <= normalized_after
|
||||||
|
):
|
||||||
|
continue
|
||||||
|
metadata = path.stat()
|
||||||
|
yield StorageObjectInfo(
|
||||||
|
key=key,
|
||||||
|
size_bytes=metadata.st_size,
|
||||||
|
modified_at=datetime.fromtimestamp(
|
||||||
|
metadata.st_mtime,
|
||||||
|
tz=timezone.utc,
|
||||||
|
),
|
||||||
|
)
|
||||||
|
|
||||||
|
candidates = nsmallest(
|
||||||
|
normalized_limit + 1,
|
||||||
|
matching_objects(),
|
||||||
|
key=lambda item: item.key,
|
||||||
|
)
|
||||||
|
has_more = len(candidates) > normalized_limit
|
||||||
|
page = tuple(candidates[:normalized_limit])
|
||||||
|
return StorageObjectPage(
|
||||||
|
objects=page,
|
||||||
|
next_cursor=page[-1].key if has_more and page else None,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass(slots=True)
|
||||||
|
class S3StorageBackend:
|
||||||
|
bucket: str
|
||||||
|
endpoint_url: str
|
||||||
|
region_name: str
|
||||||
|
access_key_id: str
|
||||||
|
secret_access_key: str
|
||||||
|
deployment_managed: bool = False
|
||||||
|
endpoint_trusted: bool = False
|
||||||
|
name: str = "s3"
|
||||||
|
_client: Any = field(default=None, init=False, repr=False)
|
||||||
|
|
||||||
|
@property
|
||||||
|
def client(self):
|
||||||
|
if self._client is not None:
|
||||||
|
return self._client
|
||||||
|
if self.deployment_managed:
|
||||||
|
endpoint_url = _deployment_managed_garage_endpoint(self.endpoint_url)
|
||||||
|
elif self.endpoint_trusted:
|
||||||
|
endpoint_url = _trusted_deployment_endpoint(self.endpoint_url)
|
||||||
|
else:
|
||||||
|
try:
|
||||||
|
endpoint_url = validate_unpinned_sdk_http_url(
|
||||||
|
self.endpoint_url,
|
||||||
|
label="Object storage S3 endpoint",
|
||||||
|
)
|
||||||
|
except OutboundHttpError as exc:
|
||||||
|
raise StorageBackendError(str(exc)) from exc
|
||||||
|
try:
|
||||||
|
import boto3
|
||||||
|
from botocore.config import Config
|
||||||
|
except ModuleNotFoundError as exc:
|
||||||
|
raise StorageBackendError(
|
||||||
|
"boto3 is required for the S3 storage backend"
|
||||||
|
) from exc
|
||||||
|
options: dict[str, object] = {
|
||||||
|
"endpoint_url": endpoint_url,
|
||||||
|
"region_name": self.region_name,
|
||||||
|
"aws_access_key_id": self.access_key_id,
|
||||||
|
"aws_secret_access_key": self.secret_access_key,
|
||||||
|
}
|
||||||
|
if self.deployment_managed:
|
||||||
|
options["config"] = Config(s3={"addressing_style": "path"})
|
||||||
|
self._client = boto3.client("s3", **options)
|
||||||
|
return self._client
|
||||||
|
|
||||||
|
def put_bytes(
|
||||||
|
self,
|
||||||
|
key: str,
|
||||||
|
data: bytes,
|
||||||
|
*,
|
||||||
|
content_type: str | None = None,
|
||||||
|
) -> None:
|
||||||
|
normalized = normalize_storage_key(key)
|
||||||
|
max_bytes = response_limit("file")
|
||||||
|
if len(data) > max_bytes:
|
||||||
|
raise StorageBackendError(
|
||||||
|
f"Stored object exceeds the deployment limit of {max_bytes} bytes"
|
||||||
|
)
|
||||||
|
kwargs: dict[str, object] = {
|
||||||
|
"Bucket": self.bucket,
|
||||||
|
"Key": normalized,
|
||||||
|
"Body": data,
|
||||||
|
}
|
||||||
|
if content_type:
|
||||||
|
kwargs["ContentType"] = content_type
|
||||||
|
try:
|
||||||
|
self.client.put_object(**kwargs)
|
||||||
|
except Exception as exc: # pragma: no cover - depends on S3 backend
|
||||||
|
raise StorageBackendError(str(exc)) from exc
|
||||||
|
|
||||||
|
def get_bytes(self, key: str) -> bytes:
|
||||||
|
normalized = normalize_storage_key(key)
|
||||||
|
try:
|
||||||
|
obj = self.client.get_object(
|
||||||
|
Bucket=self.bucket,
|
||||||
|
Key=normalized,
|
||||||
|
)
|
||||||
|
max_bytes = response_limit("file")
|
||||||
|
body = obj["Body"]
|
||||||
|
try:
|
||||||
|
_reject_declared_object_size(obj, max_bytes=max_bytes)
|
||||||
|
data = body.read(max_bytes + 1)
|
||||||
|
if len(data) > max_bytes:
|
||||||
|
raise StorageBackendError(
|
||||||
|
"Stored object exceeds the deployment limit of "
|
||||||
|
f"{max_bytes} bytes"
|
||||||
|
)
|
||||||
|
return data
|
||||||
|
finally:
|
||||||
|
if hasattr(body, "close"):
|
||||||
|
body.close()
|
||||||
|
except StorageBackendError:
|
||||||
|
raise
|
||||||
|
except Exception as exc: # pragma: no cover - depends on S3 backend
|
||||||
|
if _s3_missing_error(exc):
|
||||||
|
raise StorageObjectMissing("Stored object does not exist") from exc
|
||||||
|
raise StorageBackendError(str(exc)) from exc
|
||||||
|
|
||||||
|
def iter_bytes(
|
||||||
|
self,
|
||||||
|
key: str,
|
||||||
|
*,
|
||||||
|
chunk_size: int = 1024 * 1024,
|
||||||
|
) -> Iterable[bytes]:
|
||||||
|
normalized = normalize_storage_key(key)
|
||||||
|
try:
|
||||||
|
obj = self.client.get_object(
|
||||||
|
Bucket=self.bucket,
|
||||||
|
Key=normalized,
|
||||||
|
)
|
||||||
|
max_bytes = response_limit("file")
|
||||||
|
body = obj["Body"]
|
||||||
|
try:
|
||||||
|
_reject_declared_object_size(obj, max_bytes=max_bytes)
|
||||||
|
total = 0
|
||||||
|
while True:
|
||||||
|
chunk = body.read(chunk_size)
|
||||||
|
if not chunk:
|
||||||
|
break
|
||||||
|
total += len(chunk)
|
||||||
|
if total > max_bytes:
|
||||||
|
raise StorageBackendError(
|
||||||
|
"Stored object exceeds the deployment limit of "
|
||||||
|
f"{max_bytes} bytes"
|
||||||
|
)
|
||||||
|
yield chunk
|
||||||
|
finally:
|
||||||
|
if hasattr(body, "close"):
|
||||||
|
body.close()
|
||||||
|
except StorageBackendError:
|
||||||
|
raise
|
||||||
|
except Exception as exc: # pragma: no cover - depends on S3 backend
|
||||||
|
if _s3_missing_error(exc):
|
||||||
|
raise StorageObjectMissing("Stored object does not exist") from exc
|
||||||
|
raise StorageBackendError(str(exc)) from exc
|
||||||
|
|
||||||
|
def delete(self, key: str) -> None:
|
||||||
|
try:
|
||||||
|
self.client.delete_object(
|
||||||
|
Bucket=self.bucket,
|
||||||
|
Key=normalize_storage_key(key),
|
||||||
|
)
|
||||||
|
except Exception as exc: # pragma: no cover - depends on S3 backend
|
||||||
|
raise StorageBackendError(str(exc)) from exc
|
||||||
|
|
||||||
|
def exists(self, key: str) -> bool:
|
||||||
|
try:
|
||||||
|
self.client.head_object(
|
||||||
|
Bucket=self.bucket,
|
||||||
|
Key=normalize_storage_key(key),
|
||||||
|
)
|
||||||
|
return True
|
||||||
|
except Exception as exc:
|
||||||
|
if _s3_missing_error(exc):
|
||||||
|
return False
|
||||||
|
raise StorageBackendError(str(exc)) from exc
|
||||||
|
|
||||||
|
def stat(self, key: str) -> StorageObjectInfo:
|
||||||
|
normalized = normalize_storage_key(key)
|
||||||
|
try:
|
||||||
|
response = self.client.head_object(
|
||||||
|
Bucket=self.bucket,
|
||||||
|
Key=normalized,
|
||||||
|
)
|
||||||
|
except Exception as exc: # pragma: no cover - depends on S3 backend
|
||||||
|
if _s3_missing_error(exc):
|
||||||
|
raise StorageObjectMissing("Stored object does not exist") from exc
|
||||||
|
raise StorageBackendError(str(exc)) from exc
|
||||||
|
try:
|
||||||
|
size = int(response.get("ContentLength"))
|
||||||
|
except (AttributeError, TypeError, ValueError) as exc:
|
||||||
|
raise StorageBackendError(
|
||||||
|
"S3 object metadata did not include a valid size"
|
||||||
|
) from exc
|
||||||
|
return StorageObjectInfo(
|
||||||
|
key=normalized,
|
||||||
|
size_bytes=size,
|
||||||
|
modified_at=_storage_modified_at(response.get("LastModified")),
|
||||||
|
)
|
||||||
|
|
||||||
|
def list_objects(
|
||||||
|
self,
|
||||||
|
*,
|
||||||
|
prefix: str,
|
||||||
|
after: str | None = None,
|
||||||
|
limit: int = 500,
|
||||||
|
) -> StorageObjectPage:
|
||||||
|
normalized_prefix = normalize_storage_prefix(prefix)
|
||||||
|
normalized_limit = max(1, min(int(limit), 1000))
|
||||||
|
kwargs: dict[str, object] = {
|
||||||
|
"Bucket": self.bucket,
|
||||||
|
"Prefix": normalized_prefix,
|
||||||
|
"MaxKeys": normalized_limit,
|
||||||
|
}
|
||||||
|
if after:
|
||||||
|
kwargs["StartAfter"] = normalize_storage_key(after)
|
||||||
|
try:
|
||||||
|
response = self.client.list_objects_v2(**kwargs)
|
||||||
|
except Exception as exc: # pragma: no cover - depends on S3 backend
|
||||||
|
raise StorageBackendError(str(exc)) from exc
|
||||||
|
objects = tuple(
|
||||||
|
StorageObjectInfo(
|
||||||
|
key=str(item["Key"]),
|
||||||
|
size_bytes=int(item.get("Size") or 0),
|
||||||
|
modified_at=_storage_modified_at(item.get("LastModified")),
|
||||||
|
)
|
||||||
|
for item in response.get("Contents", ())
|
||||||
|
if isinstance(item, dict) and item.get("Key")
|
||||||
|
)
|
||||||
|
has_more = bool(response.get("IsTruncated"))
|
||||||
|
return StorageObjectPage(
|
||||||
|
objects=objects,
|
||||||
|
next_cursor=objects[-1].key if has_more and objects else None,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def _storage_modified_at(value: object) -> datetime | None:
|
||||||
|
if not isinstance(value, datetime):
|
||||||
|
return None
|
||||||
|
if value.tzinfo is None:
|
||||||
|
return value.replace(tzinfo=timezone.utc)
|
||||||
|
return value.astimezone(timezone.utc)
|
||||||
|
|
||||||
|
|
||||||
|
def configured_storage_backend(settings: object) -> StorageBackend:
|
||||||
|
"""Build the deployment-wide object store from Core settings.
|
||||||
|
|
||||||
|
Modules own their metadata and key namespaces. The deployment owns the
|
||||||
|
storage endpoint and credentials, so modules do not need to depend on the
|
||||||
|
Files package merely to persist opaque generated bytes.
|
||||||
|
"""
|
||||||
|
|
||||||
|
configured = (
|
||||||
|
str(getattr(settings, "file_storage_backend", "local") or "local")
|
||||||
|
.strip()
|
||||||
|
.lower()
|
||||||
|
)
|
||||||
|
if configured in {"local", "filesystem", "fs"}:
|
||||||
|
raw_fallbacks = str(
|
||||||
|
getattr(settings, "file_storage_local_fallback_roots", "") or ""
|
||||||
|
)
|
||||||
|
return LocalFilesystemStorageBackend(
|
||||||
|
Path(
|
||||||
|
str(
|
||||||
|
getattr(
|
||||||
|
settings,
|
||||||
|
"file_storage_local_root",
|
||||||
|
"runtime/files",
|
||||||
|
)
|
||||||
|
)
|
||||||
|
),
|
||||||
|
fallback_roots=tuple(
|
||||||
|
Path(item.strip()) for item in raw_fallbacks.split(",") if item.strip()
|
||||||
|
),
|
||||||
|
)
|
||||||
|
if configured in {"s3", "garage"}:
|
||||||
|
return S3StorageBackend(
|
||||||
|
bucket=str(
|
||||||
|
getattr(settings, "file_storage_s3_bucket", None)
|
||||||
|
or getattr(settings, "s3_bucket", "files")
|
||||||
|
),
|
||||||
|
endpoint_url=str(
|
||||||
|
getattr(settings, "file_storage_s3_endpoint_url", None)
|
||||||
|
or getattr(settings, "s3_endpoint_url", "")
|
||||||
|
),
|
||||||
|
region_name=str(
|
||||||
|
getattr(settings, "file_storage_s3_region", None)
|
||||||
|
or getattr(settings, "s3_region", "")
|
||||||
|
),
|
||||||
|
access_key_id=str(
|
||||||
|
getattr(settings, "file_storage_s3_access_key_id", None)
|
||||||
|
or getattr(settings, "s3_access_key_id", "")
|
||||||
|
),
|
||||||
|
secret_access_key=str(
|
||||||
|
getattr(
|
||||||
|
settings,
|
||||||
|
"file_storage_s3_secret_access_key",
|
||||||
|
None,
|
||||||
|
)
|
||||||
|
or getattr(settings, "s3_secret_access_key", "")
|
||||||
|
),
|
||||||
|
deployment_managed=bool(
|
||||||
|
getattr(
|
||||||
|
settings,
|
||||||
|
"file_storage_s3_deployment_managed",
|
||||||
|
False,
|
||||||
|
)
|
||||||
|
),
|
||||||
|
endpoint_trusted=bool(
|
||||||
|
getattr(
|
||||||
|
settings,
|
||||||
|
"file_storage_s3_endpoint_trusted",
|
||||||
|
False,
|
||||||
|
)
|
||||||
|
),
|
||||||
|
)
|
||||||
|
raise StorageBackendError(f"Unsupported object storage backend: {configured}")
|
||||||
|
|
||||||
|
|
||||||
|
def normalize_storage_key(value: str) -> str:
|
||||||
|
candidate = str(value or "").strip().replace("\\", "/")
|
||||||
|
parts = candidate.split("/")
|
||||||
|
if (
|
||||||
|
not candidate
|
||||||
|
or candidate.startswith("/")
|
||||||
|
or any(part in {"", ".", ".."} for part in parts)
|
||||||
|
or any(ord(character) < 32 for character in candidate)
|
||||||
|
):
|
||||||
|
raise StorageBackendError("Storage key is not a safe relative key")
|
||||||
|
return "/".join(parts)
|
||||||
|
|
||||||
|
|
||||||
|
def normalize_storage_prefix(value: str) -> str:
|
||||||
|
candidate = str(value or "").strip().replace("\\", "/")
|
||||||
|
if not candidate:
|
||||||
|
return ""
|
||||||
|
trailing_slash = candidate.endswith("/")
|
||||||
|
normalized = normalize_storage_key(candidate.rstrip("/"))
|
||||||
|
return normalized + ("/" if trailing_slash else "")
|
||||||
|
|
||||||
|
|
||||||
|
def _reject_declared_object_size(obj: object, *, max_bytes: int) -> None:
|
||||||
|
if not isinstance(obj, dict):
|
||||||
|
return
|
||||||
|
try:
|
||||||
|
declared_size = int(obj.get("ContentLength"))
|
||||||
|
except (TypeError, ValueError):
|
||||||
|
return
|
||||||
|
if declared_size > max_bytes:
|
||||||
|
raise StorageBackendError(
|
||||||
|
f"Stored object exceeds the deployment limit of {max_bytes} bytes"
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def _iter_local_files(root: Path):
|
||||||
|
for entry in sorted(root.iterdir(), key=lambda item: item.name):
|
||||||
|
if entry.is_symlink():
|
||||||
|
continue
|
||||||
|
if entry.is_dir():
|
||||||
|
yield from _iter_local_files(entry)
|
||||||
|
elif entry.is_file():
|
||||||
|
yield entry
|
||||||
|
|
||||||
|
|
||||||
|
def _s3_missing_error(exc: Exception) -> bool:
|
||||||
|
response = getattr(exc, "response", None)
|
||||||
|
if not isinstance(response, dict):
|
||||||
|
return False
|
||||||
|
error = response.get("Error")
|
||||||
|
metadata = response.get("ResponseMetadata")
|
||||||
|
code = str(error.get("Code") if isinstance(error, dict) else "")
|
||||||
|
status_code = metadata.get("HTTPStatusCode") if isinstance(metadata, dict) else None
|
||||||
|
return code in {"404", "NoSuchKey", "NotFound"} or status_code == 404
|
||||||
|
|
||||||
|
|
||||||
|
def _deployment_managed_garage_endpoint(value: str) -> str:
|
||||||
|
endpoint = str(value or "").strip()
|
||||||
|
if endpoint != "http://garage:3900":
|
||||||
|
raise StorageBackendError(
|
||||||
|
"Deployment-managed S3 trust is restricted to http://garage:3900"
|
||||||
|
)
|
||||||
|
return endpoint
|
||||||
|
|
||||||
|
|
||||||
|
def _trusted_deployment_endpoint(value: str) -> str:
|
||||||
|
endpoint = str(value or "").strip()
|
||||||
|
parsed = urlsplit(endpoint)
|
||||||
|
try:
|
||||||
|
parsed.port
|
||||||
|
except ValueError as exc:
|
||||||
|
raise StorageBackendError(
|
||||||
|
"Deployment-trusted S3 endpoint has an invalid port"
|
||||||
|
) from exc
|
||||||
|
if (
|
||||||
|
parsed.scheme.lower() != "https"
|
||||||
|
or not parsed.hostname
|
||||||
|
or parsed.username
|
||||||
|
or parsed.password
|
||||||
|
or parsed.query
|
||||||
|
or parsed.fragment
|
||||||
|
or parsed.path not in {"", "/"}
|
||||||
|
):
|
||||||
|
raise StorageBackendError(
|
||||||
|
"Deployment-trusted S3 endpoint must be an HTTPS origin without "
|
||||||
|
"credentials, query, fragment, or path"
|
||||||
|
)
|
||||||
|
return endpoint.rstrip("/")
|
||||||
|
|
||||||
|
|
||||||
|
__all__ = [
|
||||||
|
"LocalFilesystemStorageBackend",
|
||||||
|
"S3StorageBackend",
|
||||||
|
"StorageBackend",
|
||||||
|
"StorageBackendError",
|
||||||
|
"StorageObjectInfo",
|
||||||
|
"StorageObjectMissing",
|
||||||
|
"StorageObjectPage",
|
||||||
|
"configured_storage_backend",
|
||||||
|
"normalize_storage_key",
|
||||||
|
"normalize_storage_prefix",
|
||||||
|
]
|
||||||
@@ -0,0 +1,126 @@
|
|||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
from collections.abc import Callable, Mapping, Sequence
|
||||||
|
from dataclasses import dataclass, field
|
||||||
|
from datetime import datetime
|
||||||
|
from typing import Literal
|
||||||
|
|
||||||
|
|
||||||
|
OperationalCheckState = Literal["ok", "warning", "error", "inactive"]
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass(frozen=True, slots=True)
|
||||||
|
class OperationalCheck:
|
||||||
|
"""A bounded module-owned runtime check exposed through the Ops module."""
|
||||||
|
|
||||||
|
id: str
|
||||||
|
label: str
|
||||||
|
state: OperationalCheckState
|
||||||
|
detail: str
|
||||||
|
readiness_critical: bool = False
|
||||||
|
metrics: Mapping[str, object] = field(default_factory=dict)
|
||||||
|
|
||||||
|
def as_dict(self) -> dict[str, object]:
|
||||||
|
return {
|
||||||
|
"id": self.id,
|
||||||
|
"label": self.label,
|
||||||
|
"state": self.state,
|
||||||
|
"detail": self.detail,
|
||||||
|
"readiness_critical": self.readiness_critical,
|
||||||
|
"metrics": dict(self.metrics),
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
OperationalCheckProvider = Callable[[], OperationalCheck]
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass(frozen=True, slots=True)
|
||||||
|
class OperationalCheckProviderRegistration:
|
||||||
|
"""Register one independently executable operational check."""
|
||||||
|
|
||||||
|
module_id: str
|
||||||
|
check_id: str
|
||||||
|
provider: OperationalCheckProvider
|
||||||
|
cache_seconds: int = 60
|
||||||
|
|
||||||
|
|
||||||
|
RuntimeWorkState = Literal[
|
||||||
|
"disabled",
|
||||||
|
"unconfigured",
|
||||||
|
"starting",
|
||||||
|
"healthy",
|
||||||
|
"idle",
|
||||||
|
"busy",
|
||||||
|
"degraded",
|
||||||
|
"stale",
|
||||||
|
"unreachable",
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass(frozen=True, slots=True)
|
||||||
|
class RuntimeWorkStatusContext:
|
||||||
|
"""Sanitized process evidence supplied to a runtime-work provider."""
|
||||||
|
|
||||||
|
profile: str
|
||||||
|
observed_at: datetime
|
||||||
|
stale_after_seconds: int
|
||||||
|
runtime_nodes: Sequence[Mapping[str, object]] = ()
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass(frozen=True, slots=True)
|
||||||
|
class RuntimeWorkStatus:
|
||||||
|
"""Bounded worker/queue status with explicit unsupported metrics."""
|
||||||
|
|
||||||
|
provider_id: str
|
||||||
|
label: str
|
||||||
|
backend: str
|
||||||
|
enabled: bool
|
||||||
|
configured: bool
|
||||||
|
state: RuntimeWorkState
|
||||||
|
detail: str
|
||||||
|
observed_at: datetime
|
||||||
|
active_workers: int | None = None
|
||||||
|
last_heartbeat_at: datetime | None = None
|
||||||
|
queue_depths: Mapping[str, int | None] = field(default_factory=dict)
|
||||||
|
active_work: int | None = None
|
||||||
|
reserved_work: int | None = None
|
||||||
|
failures: int | None = None
|
||||||
|
stale_after_seconds: int | None = None
|
||||||
|
guidance: str = ""
|
||||||
|
|
||||||
|
def as_dict(self) -> dict[str, object]:
|
||||||
|
return {
|
||||||
|
"provider_id": self.provider_id,
|
||||||
|
"label": self.label,
|
||||||
|
"backend": self.backend,
|
||||||
|
"enabled": self.enabled,
|
||||||
|
"configured": self.configured,
|
||||||
|
"state": self.state,
|
||||||
|
"detail": self.detail,
|
||||||
|
"observed_at": self.observed_at.isoformat(),
|
||||||
|
"active_workers": self.active_workers,
|
||||||
|
"last_heartbeat_at": (
|
||||||
|
self.last_heartbeat_at.isoformat()
|
||||||
|
if self.last_heartbeat_at is not None
|
||||||
|
else None
|
||||||
|
),
|
||||||
|
"queue_depths": dict(self.queue_depths),
|
||||||
|
"active_work": self.active_work,
|
||||||
|
"reserved_work": self.reserved_work,
|
||||||
|
"failures": self.failures,
|
||||||
|
"stale_after_seconds": self.stale_after_seconds,
|
||||||
|
"guidance": self.guidance,
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
RuntimeWorkStatusProvider = Callable[[RuntimeWorkStatusContext], RuntimeWorkStatus]
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass(frozen=True, slots=True)
|
||||||
|
class RuntimeWorkStatusProviderRegistration:
|
||||||
|
"""Register one optional provider-neutral worker/queue observation."""
|
||||||
|
|
||||||
|
module_id: str
|
||||||
|
provider_id: str
|
||||||
|
provider: RuntimeWorkStatusProvider
|
||||||
|
cache_seconds: int = 15
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user