Source code for aeat.adapters.persistence.storage.master_key._idle_timeout
"""Idle-timeout evaluation for `BucketSession`.Every CLI invocation runs `evaluate_idle(session, now, configured_minutes)`before granting access to the session. The configured value lives inthe bucket manifest (`ManifestKdfParams` is plaintext; `idle_lock_minutes` isread from the durable config profile. The default is15 minutes.The evaluator is a pure function over the session's idle deadline andthe supplied `now`; it never mutates the session. Mutation happensthrough `session.touch(now)` which the caller invokes on a successfulauthentication so the deadline rolls forward by the configured window.Returning a typed `IdleEvaluation` record (rather than a bare boolean)lets the CLI render an actionable "remaining N seconds" hint withoutre-deriving the math at the verb layer."""from__future__importannotationsfromdatetimeimportdatetime,timedeltafrompydanticimportBaseModel,Fieldfrom.....coreimportSTRICT_FROZEN_CONFIGas_STRICT_FROZENfrom..errorsimport(storage_validation_erroras_storage_validation_error,)from._bucket_sessionimportBucketSessionDEFAULT_IDLE_LOCK_MINUTES=15
[docs]classIdleEvaluation(BaseModel):"""Typed outcome of an idle-window evaluation."""model_config=_STRICT_FROZENexpired:boolremaining_seconds:int=Field(ge=0)
[docs]defevaluate_idle(*,session:BucketSession,now:datetime,configured_minutes:int=DEFAULT_IDLE_LOCK_MINUTES,)->IdleEvaluation:"""Evaluate the session's idle window without mutating it. Args: session: The session whose idle deadline to evaluate. now: UTC timestamp at which the evaluation runs. configured_minutes: Operator-configured idle-lock window in minutes (read from the bucket manifest). Defaults to `DEFAULT_IDLE_LOCK_MINUTES` (15). Strict positive integer; non-positive values raise. Returns: An :class:`IdleEvaluation` record carrying `expired` and the floor-truncated `remaining_seconds` until the deadline (zero when expired). Raises: StorageValidationError: When ``configured_minutes`` is not a strict positive integer. """ifconfigured_minutes<=0:raise_storage_validation_error("configured_minutes must be a strict positive integer")ifsession.sealed:returnIdleEvaluation(expired=True,remaining_seconds=0)deadline=session.idle_deadlineifnow>=deadline:returnIdleEvaluation(expired=True,remaining_seconds=0)delta:timedelta=deadline-nowreturnIdleEvaluation(expired=False,remaining_seconds=int(delta.total_seconds()))