flip_api.trusts_services.services.register_trust
Trust registration service — the single write path into the trust table.
Two callers:
POST /admin/trusts(trusts_services.admin_create_trust) for one-off admin-driven registrations from the UI.flip_api.scripts.register_trustCLI, invoked once per trust by the deploy Makefile’sregister-trusttarget (the trust’s name comes from its kit file; the hub keeps no trust list of its own).
Both produce the same on-disk state: one Trust row with api_key_hash
set, one FLKitSlot assigned, plaintext api/internal-service keys returned
once for distribution to the trust host (then unrecoverable).
Exceptions
Base for trust registration failures. |
|
Caller supplied a blank trust name. |
|
Caller supplied a blank (or missing) trust code — code is required. |
|
A trust with the given name already exists. |
|
The FL kit slot pool is exhausted. |
Classes
Result of a successful registration — the only place plaintext keys exist. |
Functions
|
Atomically register a trust: mint keys, claim an FL kit slot, insert the row. |
Module Contents
- exception flip_api.trusts_services.services.register_trust.TrustRegistrationError
Bases:
ExceptionBase for trust registration failures.
- exception flip_api.trusts_services.services.register_trust.EmptyTrustNameError
Bases:
TrustRegistrationErrorCaller supplied a blank trust name.
- exception flip_api.trusts_services.services.register_trust.EmptyTrustCodeError
Bases:
TrustRegistrationErrorCaller supplied a blank (or missing) trust code — code is required.
- exception flip_api.trusts_services.services.register_trust.DuplicateTrustError
Bases:
TrustRegistrationErrorA trust with the given name already exists.
- exception flip_api.trusts_services.services.register_trust.NoFreeKitSlotError
Bases:
TrustRegistrationErrorThe FL kit slot pool is exhausted.
- class flip_api.trusts_services.services.register_trust.RegisteredTrust
Result of a successful registration — the only place plaintext keys exist.
Plaintext
trust_api_keyandtrust_internal_service_keyare returned exactly once: the hub stores only the api-key’s SHA-256 hash, and the internal-service key is never persisted hub-side.- fl_kit_slot: flip_api.db.models.main_models.FLKitSlot
- trust_api_key: str
- trust_internal_service_key: str
- flip_api.trusts_services.services.register_trust.register_trust(name: str, code: str | None, region: str | None, session: sqlmodel.Session, audit_user_id: uuid.UUID | None = None) RegisteredTrust
Atomically register a trust: mint keys, claim an FL kit slot, insert the row.
- Parameters:
name (str) – Friendly display name (any non-empty string after strip).
code (str | None) – Short code (e.g.
GSTT). Required — must be non-empty after strip. Names are arbitrary/non-unique, so the code is the stable short handle used in kit filenames and operator tooling.region (str | None) – Optional NHS region.
session (Session) – SQLModel session; the function commits before returning.
audit_user_id (UUID | None) – Cognito sub of the authenticated admin from the UI path, or
Nonefor the deploy-CLI path (which runs under operator IAM, not a FLIP user). Stamped on thetrusts_auditrow written in the same transaction as the trust insert.
- Returns:
The persisted trust, its assigned FL kit slot, and the plaintext api / internal-service keys (returned once — discard from memory immediately after handing them to the operator).
- Return type:
- Raises:
EmptyTrustNameError –
name.strip()is empty.EmptyTrustCodeError –
codeis missing or empty after strip.DuplicateTrustError – A trust with this name already exists.
NoFreeKitSlotError – The
fl_kit_slotpool has no unassigned rows.