identity_resolver
identity_resolver
¶
Turn a container id into a task-aware ContainerIdentity.
Composes an injected ContainerInspector (container name +
OCI annotations, produced by whichever runtime backend the caller
plugged in) with a data-contract YAML lookup to produce
notification-ready identities. Clearance carries no Python-import
coupling to any orchestrator; the one that created the container
publishes a path annotation pointing at its own metadata file, and
the resolver reads .name from that file on each call.
.. rubric:: Annotation contract
Containers that want friendly task-name enrichment in clearance notifications set three OCI annotations at container creation:
ai.terok.project
Project identifier (required for task-aware labelling).
ai.terok.task
Task identifier within the project.
ai.terok.task_meta_path
Absolute path to a YAML file. The resolver reads the name
field and uses it as the display name. Missing / unreadable /
malformed files fall back silently to the container id.
Rename during a container's lifetime is preserved: the annotation carries the path, not the name, and the orchestrator updates the YAML in place. Each resolver call reads the current value.
ANNOTATION_PROJECT = 'ai.terok.project'
module-attribute
¶
ANNOTATION_TASK = 'ai.terok.task'
module-attribute
¶
ANNOTATION_TASK_META_PATH = 'ai.terok.task_meta_path'
module-attribute
¶
IdentityResolver(inspector)
¶
Compose a ContainerInspector lookup + task-meta YAML into an identity.
Callable: resolver(container_id) -> ContainerIdentity. Four
soft-fail paths, all returning a degraded identity that keeps the
notification pipeline usable:
- The inspector failed → empty
ContainerIdentity; the subscriber falls back to the raw container ID. - Container carries no terok annotations (a standalone container that happened to hit the firewall) → container-name-only.
ai.terok.task_meta_pathannotation absent → identity withouttask_name(project + task_id still present).task_meta_pathYAML unreadable / missing / malformed → same as above; the name field is left empty.
Configure the resolver with a ContainerInspector implementation.
The inspector is required (no default) so the caller owns the
runtime-selection decision — clearance is runtime-neutral and
must not reach for a specific backend itself. The notifier
entry point picks an appropriate implementation at startup
(terok-sandbox's create_container_inspector when available,
NullInspector otherwise).
Source code in src/terok_clearance/client/identity_resolver.py
__call__(container_id)
¶
Return the task-aware identity for container_id.