Source code for aeat.application.auth._operator_scope
"""Settings and active-profile storage scopes for auth operator services.This module uses :class:`Settings` to derive the auth operator configuration."""from__future__importannotationsfromcollections.abcimportIteratorfromcontextlibimportcontextmanager,nullcontextfrom...core.configimportLIVE_READ_TEST_OPT_IN_SETTINGS_FIELD,Settings,load_settings_AUTH_OPERATOR_SETTINGS_SCOPE_FIELDS=("aeat_local_storage_root","aeat_active_profile","aeat_secret_store_backend","aeat_secret_store_dir","aeat_secret_passphrase","aeat_auth_provider",LIVE_READ_TEST_OPT_IN_SETTINGS_FIELD,"aeat_certificate_path","aeat_certificate_password_secret","aeat_certificate_friendly_name","aeat_certificate_backend","aeat_cert_warn_days","aeat_cert_critical_days","aeat_clave_movil_dni_nie","aeat_clave_movil_dni_fecha","aeat_clave_movil_nie_soporte","aeat_clave_prefer_non_qr","aeat_clave_movil_timeout_ms",)
[docs]@contextmanagerdefauth_operator_settings_scope(settings:Settings|None)->Iterator[Settings]:"""Yield a :class:`Settings` for auth-operator probes. Uses the supplied settings when provided, otherwise loads from the default path. """from...core.configimportoverride_settingsifsettingsisNone:yieldload_settings()returnoverrides={field:getattr(settings,field)forfieldin_AUTH_OPERATOR_SETTINGS_SCOPE_FIELDSiffieldinsettings.model_fields_set}forroute_fieldin("aeat_local_storage_root","aeat_active_profile"):ifroute_fieldnotinoverrides:overrides[route_field]=getattr(load_settings(),route_field)withoverride_settings(**overrides)asscoped:yieldscoped
[docs]defactive_bucket_id_from_settings(settings:Settings)->str|None:"""Resolve the active bucket for ``settings`` without falling through to process globals."""from...coreimportread_pointeroverride=(settings.aeat_active_profileor"").strip()ifoverride:returnoverridepointer=read_pointer(settings.aeat_local_storage_root)returnpointer.bucket_idifpointerisnotNoneelseNone
[docs]@contextmanagerdefactive_profile_storage_span(settings:Settings|None=None):"""Return a storage context for the active profile, or a no-op when absent."""from...adapters.persistence.storageimporthas_active_bucket_sessionfrom..user_profileimportprofile_storage_sessionwithauth_operator_settings_scope(settings)asresolved_settings:bucket_id=active_bucket_id_from_settings(resolved_settings)ifbucket_idisNone:withnullcontext():yieldNonereturnifhas_active_bucket_session():withnullcontext():yieldbucket_idreturnwithprofile_storage_session(bucket_id)asactive:yieldactive