aeat.adapters.outbound.aeat.auth._authenticator_persistence module

Certificate-auth persisted-session metadata and redacted diagnostics.

adapters.outbound.aeat.auth.AeatAuthenticator writes PersistedSessionMetadata into the encrypted adapters.outbound.aeat.auth._session_store.PersistedBrowserSession metadata mapping after capturing Playwright storage state. Resume paths use the metadata to validate the storage-state fingerprint, idle deadline, certificate thumbprint, and certificate subject before rebuilding the session.

The reason-code helpers reduce detailed invalidation causes to stable, non-sensitive strings carried through AeatLoginAssertionError.

AEAT_STORAGE_STATE_SCHEMA_VERSION: Final[int]

Schema version for certificate-auth PersistedSessionMetadata records.

class PersistedSessionMetadata(**data)[source]

Bases: BaseModel

Certificate-auth metadata stored inside the encrypted session envelope.

The fields bind a captured Playwright storage state to the certificate identity that produced it. HandshakeResult preserves the verified AEAT handshake details, while storage_state_sha256 lets resume checks reject metadata that no longer matches the encrypted storage-state payload.

Parameters:
schema_version: int
certificate_thumbprint: str
certificate_subject: str
certificate_nif: str
authenticated_at: datetime
idle_deadline: datetime
storage_state_sha256: str
handshake: HandshakeResult
persisted_session_reason_code(reason)[source]

Map a detailed persisted-session refusal reason to a non-sensitive code.

The mapping mirrors the certificate-auth resume gates and storage-state parsing checks so callers can log or translate the outcome without exposing certificate subjects, logical storage paths, or browser-session contents.

Return type:

str

Parameters:

reason (str)

persisted_session_reason_from_error(error)[source]

Extract the redacted persisted-session reason code from an auth error.

Returns the explicit context["reason"] value when AeatLoginAssertionError carries one, otherwise falls back to the generic persisted-session invalidation code.

Return type:

str

Parameters:

error (AeatLoginAssertionError)