aeat.application.auth._certificate_sources module¶
Named multi-certificate source registry for the certificate auth provider.
A gestor managing several taxpayers typically holds several PKCS#12
certificates — their own personal certificate plus one apoderado
certificate per represented entity. Before this module, the certificate
auth provider carried exactly one certificate path
(certificate_path), configured through
aeat config auth configure --provider certificate --file PATH: adopting
a different certificate meant re-running that command and losing track of
the previous path.
This module adds a named registry
(certificate_sources) on top of the existing
single-path field:
register_certificate_source() adds
or re-points a named source,
list_certificate_sources()
enumerates them,
select_certificate_source() marks
one active and mirrors its path onto certificate_path (so every existing
consumer — the backend health probe, live login preconditions, auth status /
auth test — keeps reading the one field it already knows about), and
remove_certificate_source() retires
a registered source.
Rotation hooks (invalidating cached state when the active certificate changes on disk), a filesystem-fallback loader, external keyring/1Password backends, and service-account impersonation UX are explicitly out of scope for this module; see GitHub issue #591.
See also
AuthStatePersisted local auth selection embedded in workflow state; carries the
certificate_sourcesregistry andcertificate_pathmirror this module maintains.configure_operator_auth()Configures the active auth provider; this module manages certificate sources within the certificate provider.
- exception CertificateSourceNoActiveBucketError[source]¶
Bases:
ExceptionRaised when a certificate-source mutation runs before an active profile bucket exists.
- exception CertificateSourceNotFoundError[source]¶
Bases:
KeyErrorRaised when a requested certificate source name is not registered.
- register_certificate_source(state, *, name, certificate_path, friendly_name=None)[source]¶
Register (or re-point) a named certificate source in
state.Adding a source with a
namethat already exists overwrites itscertificate_path/friendly_nameand refreshesregistered_atrather than erroring — re-registration is the supported way to point an existing name at a renewed certificate file. Registering a source never changes which source is active; callselect_certificate_source()explicitly to activate it.Returns the updated
WorkflowState.- Return type:
- Parameters:
state (WorkflowState)
name (str)
certificate_path (Path)
friendly_name (str | None)
- list_certificate_sources(state)[source]¶
Return every registered
CertificateSourceRecord.- Return type:
- Parameters:
state (WorkflowState)
- active_certificate_source(state)[source]¶
Return the active
CertificateSourceRecord, if any.- Return type:
- Parameters:
state (WorkflowState)
- select_certificate_source(state, *, name)[source]¶
Mark the certificate source
nameactive and mirror its path ontocertificate_path.Every other registered source stays registered but inactive. The provider selection (
AuthState.provider) is left untouched: selecting a certificate source is orthogonal to choosing which auth provider is active, so an operator may register and select sources ahead of switching--provider certificateon.- Raises:
CertificateSourceNotFoundError – When
nameis not registered.- Parameters:
state (WorkflowState)
name (str)
- Return type:
Returns the updated
WorkflowState.- Return type:
- Parameters:
state (WorkflowState)
name (str)
- remove_certificate_source(state, *, name)[source]¶
Remove the certificate source
namefrom the registry.When
nameis the active source, the active selection is cleared (active_certificate_sourcebecomesNone);certificate_pathis left as-is, matching the pre-existing single-certificate contract where clearing the path is a distinctauth clearoperation.Returns a
(state, removed)tuple;removedisFalsewhennamewas not registered (a no-op, not an error).- Return type:
- Parameters:
state (WorkflowState)
name (str)