Skip to content

context

context

Bind a container's credential requests to one task and one credential set.

BrokerContext(scope, subject, credential_set) dataclass

Host-issued identity shared by token creation and the container's broker.

scope and subject identify the task's revocable grants. credential_set is the only credential namespace the task may use. None of these fields may come from an incoming credential request.

scope instance-attribute

subject instance-attribute

credential_set instance-attribute

__post_init__()

Refuse incomplete identities instead of falling back to shared credentials.

Source code in src/terok_sandbox/vault/context.py
def __post_init__(self) -> None:
    """Refuse incomplete identities instead of falling back to shared credentials."""
    if any(
        not isinstance(value, str) or not value.strip()
        for value in (self.scope, self.subject, self.credential_set)
    ):
        raise ValueError("Broker context requires nonempty scope, subject and credential_set")

matches(grant)

Return whether a live grant belongs to this container's authorization context.

Source code in src/terok_sandbox/vault/context.py
def matches(self, grant: Mapping[str, object]) -> bool:
    """Return whether a live grant belongs to this container's authorization context."""
    return (grant.get("scope"), grant.get("subject"), grant.get("credential_set")) == (
        self.scope,
        self.subject,
        self.credential_set,
    )