aeat.application.user_profile._repository module¶
Secure-DB persistence for user-profile lifecycle records and filing snapshots.
Two registry-owned storage contracts govern this module:
aeat.adapters.persistence.storage.USER_PROFILE_VALUE_NAMESPACE— live profile aggregate keyed by the immutableprofile_id(a UUIDv4). There is exactly one live profile-value record per profile bucket.aeat.adapters.persistence.storage.USER_PROFILE_SNAPSHOT_NAMESPACE— immutable filing-time snapshots keyed by(profile_id, snapshot_id): a profile owns many filing snapshots.
Both namespace definitions provide the IDENTITY
SensitivityClass, schema version,
bucket-local scope, and object-key grammar. They ride the active-bucket
plumbing: every read and write resolves through a profile bucket so two
operators never share profile storage. snapshot_id is deterministic in
shape but globally unique within a bucket per new_profile_snapshot_id.
Records are stored as Envelope
objects encrypted at rest by
SecureObjectRepository.
- user_profile_value_object_key(profile_id)[source]¶
Return the secure-object key for a profile’s live aggregate.
The key shape is the object-key grammar declared by
aeat.adapters.persistence.storage.USER_PROFILE_VALUE_NAMESPACE. A profile bucket holds exactly one live profile-value record, so the key is single-segment: the immutableprofile_id(UUIDv4).
- user_profile_snapshot_object_key(profile_id, snapshot_id)[source]¶
Return the secure-object key for one of a profile’s filing snapshots.
The key shape is the object-key grammar declared by
aeat.adapters.persistence.storage.USER_PROFILE_SNAPSHOT_NAMESPACE. A profile owns many immutable filing snapshots, so the key retains thesnapshot_iddiscriminator; the first segment is the immutableprofile_id(UUIDv4).
- class UserProfileLifecycleRepository(*, bucket_id, objects=None)[source]¶
Bases:
_BucketBoundRepositoryRead and write live user-profile aggregates in the secure DB.
Rows use
aeat.adapters.persistence.storage.USER_PROFILE_VALUE_NAMESPACE, wrap eachUserProfileRecordin anEnvelope, and persist throughSecureObjectRepository.- Parameters:
bucket_id (str)
objects (SecureObjectRepository | None)
- property bucket_id: str¶
Return the logical profile bucket this repository is bound to.
A bucket is a named, isolated storage partition: every read and write addresses this bucket’s own database, so two operators never share profile storage. The value is the stripped, non-blank identifier supplied at construction.
- Returns:
The name of the bucket (storage partition) this repository operates against.
- exists(profile_id)[source]¶
Report whether a live profile aggregate is stored under
profile_id.Probes the secure-object backend for the single live profile-value record keyed by
profile_id(a UUIDv4) in this bucket, without decrypting or validating the payload.
- load(profile_id)[source]¶
Load and decrypt the live profile aggregate for
profile_id.Reads the encrypted
Envelope(the stored container that holds the encrypted payload plus its metadata) for the single live profile record in this bucket, validates it back into aUserProfileRecord, and enforces two storage-contract checks before returning the payload. First, the envelope’s classification (its declared sensitivity level) must match the level expected for profile data. Second, the schema version recorded on the envelope must not be newer than the version this code can read.- Parameters:
profile_id (
str) – The immutable UUIDv4 identifying the profile.- Return type:
- Returns:
The decrypted
UserProfileRecordcarried by the envelope.- Raises:
ProfileNotFoundError – No record is stored under
profile_idin this bucket.StoredProfileDriftError – The stored payload no longer validates against the current
UserProfileRecordschema.ClassificationError – The envelope’s classification differs from the level expected for profile data.
EnvelopeVersionError – The stored schema version is newer than this code can read.
- save(record)[source]¶
Persist
recordas this bucket’s single live profile aggregate.Wraps the
UserProfileRecordin an encryptedEnvelope(the stored container holding the encrypted payload plus its metadata) stamped with the current schema version, the write timestamp, and the sensitivity classification for profile data, then stores it under the key derived fromrecord.profile_id. A profile bucket holds exactly one live profile record, so this overwrites any prior aggregate for the sameprofile_id. Afterwards it clears the cached output language, because a write may have changed the active profile’s preferred language for command-line output.- Parameters:
record (
UserProfileRecord) – The liveUserProfileRecordaggregate to encrypt and store.- Return type:
- iter_records()[source]¶
Yield every live
UserProfileRecordfrom the secure-object backend.Walks the IDENTITY-class secure-object index for this bucket namespace and validates each row against the typed envelope at the configured schema version. The lifecycle service consumes this iterator to list live profiles without reaching for the repository’s private secure-object reference.
- Return type:
- delete(profile_id)[source]¶
Remove the live profile aggregate stored under
profile_id.Deletes the single live profile record keyed by
profile_idfrom this bucket. When a record was actually removed, it clears the cached output language, because the deleted profile may have governed the active profile’s preferred language for command-line output.
- class UserProfileSnapshotRepository(*, bucket_id, objects=None)[source]¶
Bases:
_BucketBoundRepositoryRead and write immutable filing-time profile snapshots in the secure DB.
Rows use
aeat.adapters.persistence.storage.USER_PROFILE_SNAPSHOT_NAMESPACE, wrap eachUserProfileSnapshotin anEnvelope, and persist throughSecureObjectRepository.- Parameters:
bucket_id (str)
objects (SecureObjectRepository | None)
- property bucket_id: str¶
Return the logical profile bucket this repository is bound to.
A bucket is a named, isolated storage partition: snapshot keys are scoped to this bucket, so every read and write addresses the bucket’s own database and no two operators share snapshot storage. The value is the stripped, non-blank identifier supplied at construction.
- Returns:
The name of the bucket (storage partition) this repository operates against.
- exists(snapshot_id)[source]¶
Report whether a filing-time snapshot is stored under
snapshot_id.Probes the secure-object backend for the immutable snapshot keyed by this bucket and
snapshot_id, without decrypting or validating the payload. A snapshot is the frozen profile state captured at the moment a tax filing was prepared; a profile owns many such snapshots.
- load(snapshot_id)[source]¶
Load and decrypt the filing-time snapshot for
snapshot_id.A snapshot is the frozen profile state captured when a tax filing was prepared. Reads the encrypted
Envelope(the stored container that holds the encrypted payload plus its metadata) for the immutable snapshot keyed by this bucket andsnapshot_id, validates it into aUserProfileSnapshot, and enforces two storage-contract checks before returning the payload. First, the envelope’s classification (its declared sensitivity level) must match the level expected for snapshot data. Second, the schema version recorded on the envelope must not be newer than the version this code can read.- Parameters:
snapshot_id (
str) – The identifier of the snapshot, globally unique within this bucket.- Return type:
- Returns:
The decrypted
UserProfileSnapshotcarried by the envelope.- Raises:
ProfileSnapshotNotFoundError – No snapshot is stored under
snapshot_idin this bucket.ClassificationError – The envelope’s classification differs from the level expected for snapshot data.
EnvelopeVersionError – The stored schema version is newer than this code can read.
- save(snapshot)[source]¶
Persist
snapshotas an immutable filing-time snapshot.A snapshot is the frozen profile state captured when a tax filing was prepared. Wraps the
UserProfileSnapshotin an encryptedEnvelope(the stored container holding the encrypted payload plus its metadata) stamped with the current schema version, the write timestamp, and the sensitivity classification for snapshot data, then stores it under the key derived from this bucket andsnapshot.snapshot_id. Snapshots never change once written, so each save adds a new entry to the many snapshots a profile owns rather than mutating live profile state.- Parameters:
snapshot (
UserProfileSnapshot) – The filing-time profile snapshot to encrypt and store.- Return type: