Source code for cadrumo.application.auth.operator_scope_ports
"""Application-owned ports for operator auth storage scoping.Operator auth policy needs only a narrow bucket-path/lock surface and aread-only observation of the currently bound custody session. The concretefilesystem paths, lock records, and live session objects remain owned by theoutward persistence adapters; this module carries the translated records andthe capability bundle that application callers require."""from__future__importannotationsfromdataclassesimportdataclassfrompathlibimportPathfromtypingimportProtocolfrom...core.errors.hierarchyimportCadrumoError
[docs]@dataclass(frozen=True,slots=True)classOperatorScopeBucketPaths:"""The path facts required to lock one operator-auth bucket."""bucket_id:strbucket_dir:Path
[docs]@dataclass(frozen=True,slots=True)classOperatorScopeSession:"""The non-secret identity facts of the currently bound custody session."""bucket_id:strstorage_root:Path|None
[docs]classOperatorScopeStoragePort(Protocol):"""Resolve and lock a bucket without exposing persistence DTOs."""
[docs]defresolve(self,root:Path,bucket_id:str)->OperatorScopeBucketPaths:"""Resolve the bucket directory used by the auth mutation lock."""...
[docs]defacquire_lock(self,paths:OperatorScopeBucketPaths,*,wait_seconds:float)->None:"""Acquire the bucket lock or raise an application storage error."""...
[docs]defrelease_lock(self,paths:OperatorScopeBucketPaths)->None:"""Release the bucket lock owned by the current auth mutation."""...
[docs]classOperatorScopeSessionPort(Protocol):"""Observe and compare the live custody session for one auth operation."""
[docs]defcurrent(self)->OperatorScopeSession|None:"""Return the translated current session, if one is bound."""...
[docs]defserves_bucket(self,session:OperatorScopeSession|None,bucket_id:str)->bool:"""Return whether the supplied session serves the exact bucket."""...
[docs]@dataclass(frozen=True,slots=True)classOperatorScopePorts:"""Required outward capabilities for operator auth storage scope policy."""storage:OperatorScopeStoragePortsession:OperatorScopeSessionPort
[docs]classOperatorScopeStorageError(CadrumoError):"""Translated failure from bucket path or lock persistence."""def__init__(self,*,operation:str,bucket_id:str,failure_kind:str)->None:"""Carry only stable application-safe storage failure facts."""self.operation=operationself.bucket_id=bucket_idself.failure_kind=failure_kindsuper().__init__(f"operator auth storage operation {operation!r} failed")
[docs]classOperatorScopeSessionError(CadrumoError):"""Translated failure while observing the active custody session."""