Source code for cadrumo.application.auth.certificate_secret_backend
"""Application-owned capability contract for named certificate secrets.Certificate authentication owns the policy around a named source: callersneed a bucket-scoped capability that can resolve, rotate, remove, and witness apassphrase without knowing how the secret is kept at rest. The encryptedstorage implementation is an outward adapter and is bound by each executablecomposition root below this contract.The application never receives a persistence record. Reads project either a``SecretStr`` or absence, and mutation retries use only the non-secret witnessand operation-id methods declared here."""from__future__importannotationsfromdatetimeimportdatetimefromtypingimportTYPE_CHECKING,ProtocolfrompydanticimportSecretStrifTYPE_CHECKING:from...core.configimportSettings
[docs]classCertificateSecretBackend(Protocol):"""Bucket-scoped capability for named certificate passphrases."""
[docs]defget(self,name:str)->SecretStr|None:"""Return the passphrase for ``name``, or ``None`` when it is absent."""...
[docs]defset(self,name:str,secret:SecretStr,*,operation_id:str|None=None,occurred_at:datetime|None=None,)->None:"""Persist or rotate one named passphrase."""...
[docs]defremove(self,name:str)->bool:"""Remove one named passphrase, returning whether it existed."""...
[docs]defmutation_operation_id(self,name:str)->str|None:"""Return the non-secret operation id attached to ``name``, if present."""...
[docs]defrequest_witness(self,name:str,secret:SecretStr)->str:"""Return a non-secret witness for an idempotent set/rotate retry."""...
[docs]classCertificateSecretBackendFactory(Protocol):"""Construct one certificate-secret capability for a routed bucket."""def__call__(self,*,bucket_id:str,settings:Settings)->CertificateSecretBackend:"""Return the capability bound to ``bucket_id`` and ``settings``."""...