aeat.application.auth._acquisition_lock module¶
Crash-recoverable auth acquisition locks.
The lock protects live auth flows that can create external state,
especially Cl@ve Movil push petitions. It is intentionally
filesystem-backed so separate CLI processes share the same guard.
The lock file stores an AuthAcquisitionLockRecord and reports
operator-safe state through AuthAcquisitionLockStatus.
- class AuthAcquisitionLockState(*values)[source]¶
Bases:
StrEnumObservable states for the auth acquisition lock file.
- ABSENT¶
- HELD¶
- STALE¶
- CORRUPT¶
- class AuthAcquisitionLockRecord(**data)[source]¶
Bases:
BaseModelMetadata written into an auth acquisition lock file.
- Parameters:
- provider_kind: AuthProviderKind¶
- profile_name: str¶
- pid: int¶
- hostname: str¶
- created_at: datetime¶
- expires_at: datetime¶
- operation: str¶
- class AuthAcquisitionLockStatus(**data)[source]¶
Bases:
BaseModelSafe health/status view of an auth acquisition lock.
- Parameters:
state (AuthAcquisitionLockState)
path (Path)
record (AuthAcquisitionLockRecord | None)
reason (str | None)
recoverable (bool)
- state: AuthAcquisitionLockState¶
- path: Path¶
- record: AuthAcquisitionLockRecord | None¶
- reason: str | None¶
- recoverable: bool¶
- exception AuthAcquisitionLockedError(message=None, *, context=None, suggestion=None, translated_message=None)[source]¶
Bases:
AeatErrorRaised when another process is already acquiring AEAT auth.
- Parameters:
- Return type:
None
- code: ClassVar[ErrorCode]¶
- auth_acquisition_lock_path(settings, kind)[source]¶
Return the profile/provider-scoped lock path.
- Return type:
Path- Parameters:
settings (Settings)
kind (AuthProviderKind)
- inspect_auth_acquisition_lock(settings, kind, *, now=None)[source]¶
Describe the current acquisition-lock health without mutating it.
Returns an
AuthAcquisitionLockStatus.- Return type:
- Parameters:
settings (Settings)
kind (AuthProviderKind)
now (datetime | None)
- clear_auth_acquisition_lock(settings, kind, *, reason='operator-reset')[source]¶
Remove the acquisition lock and return the pre-reset status.
Returns an
AuthAcquisitionLockStatusreflecting the state observed immediately before the file was removed.- Return type:
- Parameters:
settings (Settings)
kind (AuthProviderKind)
reason (str)
- acquire_auth_acquisition_lock(settings, kind, *, ttl_seconds, operation='auth-login')[source]¶
Acquire a crash-recoverable auth lock or raise a typed conflict.
Yields an
AuthAcquisitionLockRecordwhile the lock is held.Stale/corrupt locks are removed automatically before a second atomic-create attempt. A live lock is never waited on or retried: callers fail early so they do not issue a duplicate Cl@ve petition.
- Return type:
- Parameters:
settings (Settings)
kind (AuthProviderKind)
ttl_seconds (int)
operation (str)
- auth_lock_ttl_seconds(settings, kind)[source]¶
Return the acquisition-lock TTL for a provider.
- Return type:
- Parameters:
settings (Settings)
kind (AuthProviderKind)