Source code for cadrumo.adapters.persistence.storage.runtime_readiness
"""Secure-storage runtime readiness vocabulary.The typed answer to "why can this process not serve profile-bound storage",and the refusal that carries it. Separated from :mod:`.runtime` because thetwo have different dependency shapes: the runtime INSPECTS the process --settings, routes, the live bucket session -- while this vocabulary is a closedenum, three frozen records, and one error builder over nothing but:mod:`core` and the storage error hierarchy.That difference is what makes the split load-bearing rather than cosmetic.:class:`~adapters.persistence.storage.sql.secure_objects.SecureObjectRepository` re-checkssession freshness on every operation and must raise the same refusal theruntime raises, so it needs this vocabulary -- but it emphatically does notneed the runtime aggregate, and the runtime constructs the repository. Holdingboth in one module made that a genuine cycle, which was hidden rather thanremoved by a deferred function-local import at each end. A deferred importpostpones a cycle: it survives as an evaluation-order hazard that surfaces asa partially-initialised module the moment an unrelated edit reorders imports.With the vocabulary in its own module both sides import it eagerly, at theseam where the dependency genuinely is, and the cycle is gone rather thandeferred."""from__future__importannotationsfromdatetimeimportdatetimefromenumimportStrEnumfrompydanticimportBaseModelfrom....core.modelsimportSTRICT_FROZEN_CONFIGas_STRICT_FROZENfrom.errorsimportStorageValidationError
[docs]classStorageRuntimeReadinessIssue(BaseModel):"""One reason the runtime is not ready for profile-bound storage."""model_config=_STRICT_FROZENcode:StorageRuntimeReadinessCode
[docs]classStorageRuntimeSession(BaseModel):"""Key-material-free projection of the active bucket session."""model_config=_STRICT_FROZENactive:boolidle_deadline:datetimesealed:boolexpired:bool
[docs]defreadiness_issue(*,code:StorageRuntimeReadinessCode)->StorageRuntimeReadinessIssue:"""Return one typed readiness issue for ``code``."""returnStorageRuntimeReadinessIssue(code=code)
[docs]defreadiness_error(readiness:StorageRuntimeReadiness)->StorageValidationError:"""Project typed readiness facts into the registered storage refusal. The refusal is locale-neutral: the operator-facing sentence comes from the translated message key, and the codes travel as structured context so a caller can tell WHICH unready state it met without parsing prose. """issue_codes=tuple(issue.code.valueforissueinreadiness.issues)returnStorageValidationError(context={"details":readiness.code.value,"readiness_code":readiness.code.value,"readiness_issue_codes":issue_codes,},translated_message="errors.storage.runtime.not_ready",)
[docs]defruntime_not_ready_error(code:StorageRuntimeReadinessCode)->StorageValidationError:"""Build a locale-neutral storage-runtime readiness failure for one code."""returnreadiness_error(StorageRuntimeReadiness(ready=False,code=code,issues=(StorageRuntimeReadinessIssue(code=code),),),)