Source code for cadrumo.adapters.persistence.profile.apoderado
"""Encrypted persistence adapter for apoderado configuration.This module is the outward implementation of the application-owned``ApoderadoConfigurationRepository``. It owns the secure-envelope substrate,namespace contract, bucket key derivation, and translation of row-identityrefusals into the application error understood by the service.Core types::class:`~cadrumo.adapters.persistence.storage.envelope.contract.Envelope`,:class:`~cadrumo.core.classification.policies.SensitivityClass`."""from__future__importannotationsfromtypingimportTYPE_CHECKING,ClassVar,overridefrom....application.auth.apoderado_repositoryimportApoderadoConfigurationRepositoryfrom....application.auth.apoderado_serviceimport(ApoderadoConfiguration,ApoderadoConfigurationIdentityError,)from....core.classification.policiesimportSensitivityClassfrom....core.identity.bucketimportcanonical_bucket_idfrom..storage.envelope.contractimportEnvelopefrom..storage.envelope.secure_bound_repositoryimportSecureBoundRepositoryfrom..storage.errorsimportSecureObjectRowIdentityErrorfrom..storage.path_safetyimportsafe_repository_idfrom..storage.runtime_repositoryimportsecure_object_repository_for_bucketfrom..storage.secure_object_namespacesimportAUTH_APODERADO_CONFIGURATION_NAMESPACEifTYPE_CHECKING:from....core.configimportSettingsclass_ApoderadoSecureRepository(SecureBoundRepository[ApoderadoConfiguration]):"""Store apoderado configuration through the generic secure envelope port."""namespace:ClassVar[str]=AUTH_APODERADO_CONFIGURATION_NAMESPACE.namespacesensitivity:ClassVar[SensitivityClass]=AUTH_APODERADO_CONFIGURATION_NAMESPACE.sensitivityschema_version:ClassVar[int]=AUTH_APODERADO_CONFIGURATION_NAMESPACE.schema_versiondef__init__(self,*,bucket_id:str,settings:Settings)->None:"""Bind the generic secure repository to one already-canonical bucket."""self._bound_bucket_id=bucket_idsuper().__init__(objects=secure_object_repository_for_bucket(bucket_id,settings))@override@classmethoddefpayload_model(cls)->type[ApoderadoConfiguration]:"""Return the application configuration DTO wrapped by this adapter."""returnApoderadoConfiguration@overridedefextract_identifier(self,payload:ApoderadoConfiguration)->str:"""Return the safe secure-object key for ``payload``'s bucket."""returnsafe_repository_id(canonical_bucket_id(payload.bucket_id),context="bucket_id")@overridedef_translate_row_identity_error(self,error:SecureObjectRowIdentityError)->Exception:"""Translate a misfiled storage row into the application error."""returnApoderadoConfigurationIdentityError(translated_message="errors.integrity.integrity_apoderado_configuration_identity",context={"repository_bucket_id":self._bound_bucket_id,"storage_row_identity":"payload_key_mismatch",},)
[docs]classApoderadoConfigRepository(ApoderadoConfigurationRepository):"""Encrypted per-bucket adapter for apoderado configuration."""namespace:ClassVar[str]=AUTH_APODERADO_CONFIGURATION_NAMESPACE.namespacesensitivity:ClassVar[SensitivityClass]=AUTH_APODERADO_CONFIGURATION_NAMESPACE.sensitivityschema_version:ClassVar[int]=AUTH_APODERADO_CONFIGURATION_NAMESPACE.schema_versiondef__init__(self,*,bucket_id:str,settings:Settings)->None:"""Bind this application-facing adapter to one canonical bucket."""self._bound_bucket_id=canonical_bucket_id(bucket_id)self._safe_bucket_id=safe_repository_id(self._bound_bucket_id,context="bucket_id")self._repository=_ApoderadoSecureRepository(bucket_id=self._bound_bucket_id,settings=settings,)self._objects=self._repository.secure_object_repository
[docs]@classmethoddefpayload_model(cls)->type[ApoderadoConfiguration]:"""Return the application configuration DTO wrapped by this adapter."""returnApoderadoConfiguration
def_identified_envelope(self,payload:ApoderadoConfiguration,)->tuple[str,Envelope[ApoderadoConfiguration]]:"""Expose the generic envelope builder to focused storage tests."""returnself._repository._identified_envelope(payload)
[docs]defextract_identifier(self,payload:ApoderadoConfiguration)->str:"""Return the safe secure-object key for ``payload``'s bucket."""returnself._repository.extract_identifier(payload)
[docs]@overridedefload(self)->ApoderadoConfiguration|None:"""Load this bucket's configuration, or return ``None`` when absent."""returnself._repository.load(self._safe_bucket_id)
[docs]@overridedefsave(self,configuration:ApoderadoConfiguration)->None:"""Persist a configuration only when it names this bound bucket."""payload_bucket_id=canonical_bucket_id(configuration.bucket_id)ifpayload_bucket_id!=self._bound_bucket_id:raiseApoderadoConfigurationIdentityError(translated_message="errors.integrity.integrity_apoderado_configuration_identity",context={"bucket_id":payload_bucket_id,"repository_bucket_id":self._bound_bucket_id,},)self._repository.save(configuration)
[docs]@overridedefdelete(self)->bool:"""Delete this bucket's configuration, returning whether it existed."""returnself._repository.delete(self._safe_bucket_id)
[docs]defbuild_apoderado_config_repository(*,bucket_id:str,settings:Settings,)->ApoderadoConfigurationRepository:"""Build the concrete adapter for one explicitly routed bucket."""returnApoderadoConfigRepository(bucket_id=bucket_id,settings=settings)