## What & why S-18c, the **final** slice of the S-18 (#19) split (after S-18a #142, S-18b #143). Defines the **RegisterRecord** objecttype — the schema S-19 (#20) will write canonical register records against on approval — and registers it in the Objecttypen API at startup. Closes #141 ### What - **Schema** (`infra/objecttypen-registerrecord/registerrecord.schema.json`): public-safe by construction — `id`, `status` (enum `INGEDIEND`/`INGESCHREVEN`), `reference` only, `additionalProperties: false`, `dataClassification: open`. Mirrors the BFF's `OpenbaarEntry` — **no `bsn`/`naam`** (ADR-0027). - **Registration**: a `registerrecord-init` compose one-shot (stdlib Python on the stack network) POSTs the objecttype + a **published** version over the API once Objecttypen is healthy. The Objecttypen `setup_configuration` (3.4.2) only provisions tokens — no declarative objecttype step — so this follows the ADR-0020 self-seed pattern. **Idempotent**: if a `RegisterRecord` with a version already exists it is a no-op. - **Wiring**: schema + `register.py` streamed into the external `rr-registerrecord-config` volume by `seed-config.sh registerrecord` (main) / bind-mounted (local); added to `SEED`, `CFG_VOLS`, and the CI log-dump. `registerrecord-init` is a one-shot (not in `WAIT_SVCS`). - **Smoke**: `verify-registerrecord` (`run-registerrecord-check.sh` + `registerrecord-check.py`) asserts the objecttype exists, has a **published** version, and that version's schema carries `id`/`status`/`reference`; added as a verify-stack step + a row in the #136 summary. - **ADR-0027**: records the public-safe schema decision (mirror the BFF public view, not the internal projection; API-seeded one-shot). The slice issue #141 flagged the schema as ADR-worthy, so no separate adr-proposal issue was opened. ## Verified locally (end to end, real compose) Seeded `rr-registerrecord-config`, brought Objecttypen up, ran `registerrecord-init` → `registered RegisterRecord <uuid> v1 (published)`. `make verify-registerrecord` → **OK — RegisterRecord v1 published, fields=['id', 'reference', 'status']**. Re-running the one-shot → **no-op** (idempotent). `docker compose config` clean on both files; schema + script + ci.yaml validated. ## Definition of Done - [x] Failing smoke committed first (`test(infra): …`, "no objecttype named RegisterRecord"); implementation makes it pass. - [x] Conventional Commits referencing #141. - [x] CI green (verify-stack registerrecord step — validated locally; runner already unstarved by #145). - [x] `docker compose up` reaches health (one-shot registers after Objecttypen healthy). - [x] Docs: ADR-0027 + demo note. - [x] Closed by the merging PR (`closes #141`). This closes out the S-18 (#19) split — Objecttypen (S-18a) + Objecten (S-18b) + RegisterRecord (S-18c) are all up. Next: **S-19 (#20)** — ACL writes the register record to Objecten on approval, against this schema. 🤖 Generated with [Claude Code](https://claude.com/claude-code)Reviewed-on: #146
67 lines
2.5 KiB
Python
67 lines
2.5 KiB
Python
#!/usr/bin/env python3
|
|
"""S-18c (#141): prove the RegisterRecord objecttype is registered + published in the Objecttypen API.
|
|
|
|
Assert the objecttype named "RegisterRecord" exists, has a **published** version, and that version's
|
|
jsonSchema carries the public-safe fields (id, status, reference) — i.e. registerrecord-init ran and
|
|
seeded the schema S-19 will write records against. Stdlib only so it runs in a bare python:3-slim
|
|
container on the compose network.
|
|
"""
|
|
import json
|
|
import os
|
|
import sys
|
|
import time
|
|
import urllib.error
|
|
import urllib.request
|
|
|
|
BASE = os.environ["OBJECTTYPEN"] # http://<ip>:8000
|
|
TOKEN = os.environ["OBJECTTYPEN_TOKEN"]
|
|
TIMEOUT = int(os.environ.get("REGISTERRECORD_TIMEOUT", "60"))
|
|
NAME = "RegisterRecord"
|
|
EXPECTED_FIELDS = {"id", "status", "reference"}
|
|
|
|
|
|
def get(path):
|
|
req = urllib.request.Request(f"{BASE}{path}", headers={"Authorization": f"Token {TOKEN}"})
|
|
with urllib.request.urlopen(req, timeout=10) as r:
|
|
return json.load(r)
|
|
|
|
|
|
def check():
|
|
"""Return (ok, detail). Raises on transport errors so the caller can retry."""
|
|
ots = get("/api/v2/objecttypes").get("results", [])
|
|
match = next((o for o in ots if o.get("name") == NAME), None)
|
|
if not match:
|
|
return False, f"no objecttype named {NAME!r} (have: {[o.get('name') for o in ots]})"
|
|
if not match.get("versions"):
|
|
return False, f"{NAME} exists but has no versions"
|
|
# The versions list holds URLs; fetch each to find a published one.
|
|
for ver_url in match["versions"]:
|
|
ver = get(ver_url[len(BASE):] if ver_url.startswith(BASE) else ver_url)
|
|
if ver.get("status") != "published":
|
|
continue
|
|
props = set((ver.get("jsonSchema") or {}).get("properties", {}))
|
|
if not EXPECTED_FIELDS <= props:
|
|
return False, f"published version missing fields: {EXPECTED_FIELDS - props}"
|
|
return True, f"{NAME} v{ver.get('version')} published, fields={sorted(props)}"
|
|
return False, f"{NAME} has versions but none are published"
|
|
|
|
|
|
def main():
|
|
deadline = time.time() + TIMEOUT
|
|
detail = "no attempt"
|
|
while time.time() < deadline:
|
|
try:
|
|
ok, detail = check()
|
|
if ok:
|
|
print(f"OK — {detail}")
|
|
return 0
|
|
except (urllib.error.URLError, ConnectionError, TimeoutError) as e:
|
|
detail = f"transport: {e}"
|
|
time.sleep(3)
|
|
print(f"FAIL — {detail}", file=sys.stderr)
|
|
return 1
|
|
|
|
|
|
if __name__ == "__main__":
|
|
sys.exit(main())
|