Shared code: single-source the OIDC client; record the guest-state consolidation
- scripts/shared/oidc_client.py is the canonical OIDC client module; the dashboard and panel ship byte-identical copies (pinned by tests/test_oidc_sync.py in each repo). sync-oidc-module.sh re-copies + re-pins; check-oidc-sync.py is the pre-deploy gate; scripts/shared/test_oidc_client.py is the behaviour harness. - maintenance/shared-code-and-guest-state.md records the guest-state single-derivation design (portal serves state; panel/dashboard are pure shims), the deploy record with rollback tags, and the CI follow-up. - app-inventory.md: the three apps' tags refreshed to the 20261111 deploys; the stale 'admin panel = local/coop...' registry-path note corrected against the live API (all three live under code/).
This commit is contained in:
1 parent
206c3d5379
commit
23d2fc0eb2
7 files changed
+652
-8
No files matched your search
Executable
+109
@@ -0,0 +1,109 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Verify the OIDC client module is single-sourced and byte-identical.
|
||||
|
||||
Checks, in order, and exits non-zero naming every failure:
|
||||
|
||||
1. canonical ops-docs/scripts/shared/oidc_client.py
|
||||
== member-dashboard/app/oidc.py (byte-identical, sha256)
|
||||
== admin-panel/app/oidc.py (byte-identical, sha256)
|
||||
2. each repo's tests/test_oidc_sync.py pins the CANONICAL revision
|
||||
(so CI — which has no ops-docs checkout — still goes red when a repo
|
||||
copy is hand-edited).
|
||||
3. each repo's app/main.py calls oidc.configure(...) with THAT repo's
|
||||
identity literal (cookie name + salt preserved from the pre-consolidation
|
||||
apps, so existing sessions survive).
|
||||
|
||||
Run from anywhere: python3 ops-docs/scripts/check-oidc-sync.py
|
||||
This is the pre-deploy gate for either thin app; sync-oidc-module.sh runs it
|
||||
at the end of every sync.
|
||||
"""
|
||||
import hashlib
|
||||
import re
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
HERE = Path(__file__).resolve().parent # ops-docs/scripts
|
||||
REPOS = HERE.parent.parent # ~/repos
|
||||
|
||||
CANONICAL = HERE / "shared" / "oidc_client.py"
|
||||
|
||||
# repo name -> (copy path, pin-test path, main path, expected configure call)
|
||||
APPS = {
|
||||
"member-dashboard": (
|
||||
"app/oidc.py",
|
||||
"tests/test_oidc_sync.py",
|
||||
"app/main.py",
|
||||
'oidc.configure("member-dashboard", "member_oidc_session", '
|
||||
'"member-dashboard-oidc-session")',
|
||||
),
|
||||
"admin-panel": (
|
||||
"app/oidc.py",
|
||||
"tests/test_oidc_sync.py",
|
||||
"app/main.py",
|
||||
'oidc.configure("admin-panel", "admin_oidc_session", '
|
||||
'"admin-panel-oidc-session")',
|
||||
),
|
||||
}
|
||||
|
||||
|
||||
def sha256_file(p: Path) -> str:
|
||||
return hashlib.sha256(p.read_bytes()).hexdigest()
|
||||
|
||||
|
||||
def main() -> int:
|
||||
failures = []
|
||||
|
||||
if not CANONICAL.exists():
|
||||
print(f"FAIL canonical module missing: {CANONICAL}")
|
||||
return 1
|
||||
canon_sha = sha256_file(CANONICAL)
|
||||
print(f"canonical {CANONICAL.relative_to(REPOS)} sha256={canon_sha[:16]}…")
|
||||
|
||||
for repo, (copy_rel, pin_rel, main_rel, expected_configure) in APPS.items():
|
||||
repo_dir = REPOS / repo
|
||||
copy = repo_dir / copy_rel
|
||||
pin = repo_dir / pin_rel
|
||||
app_main = repo_dir / main_rel
|
||||
|
||||
if not copy.exists():
|
||||
failures.append(f"{repo}: copy missing: {copy}")
|
||||
continue
|
||||
copy_sha = sha256_file(copy)
|
||||
if copy_sha == canon_sha:
|
||||
print(f"ok - {repo}: {copy_rel} byte-identical to canonical "
|
||||
f"(sha256={copy_sha[:16]}…)")
|
||||
else:
|
||||
failures.append(
|
||||
f"{repo}: {copy_rel} DRIFTED from canonical\n"
|
||||
f" canonical sha256={canon_sha}\n"
|
||||
f" copy sha256={copy_sha}\n"
|
||||
f" fix: edit the canonical file and run "
|
||||
f"ops-docs/scripts/sync-oidc-module.sh — never hand-edit the copy.")
|
||||
|
||||
if pin.exists() and canon_sha in pin.read_text():
|
||||
print(f"ok - {repo}: pin test records this canonical revision")
|
||||
else:
|
||||
failures.append(
|
||||
f"{repo}: {pin_rel} does not pin canonical revision {canon_sha[:16]}… "
|
||||
f"(run sync-oidc-module.sh to re-pin)")
|
||||
|
||||
if app_main.exists() and expected_configure in app_main.read_text():
|
||||
print(f"ok - {repo}: main.py configures the app identity")
|
||||
else:
|
||||
failures.append(
|
||||
f"{repo}: {main_rel} does not call the expected identity literal:\n"
|
||||
f" {expected_configure}")
|
||||
|
||||
if failures:
|
||||
print()
|
||||
print(f"FAILED: {len(failures)} problem(s)")
|
||||
for f in failures:
|
||||
print(" - " + f)
|
||||
return 1
|
||||
print()
|
||||
print("oidc module sync: all copies byte-identical, pins current, identities wired")
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(main())
|
||||
Reference in new issue
Block a user