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 immutable profile_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 immutable profile_id (UUIDv4).

Return type:

str

Parameters:

profile_id (str)

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 the snapshot_id discriminator; the first segment is the immutable profile_id (UUIDv4).

Return type:

str

Parameters:
  • profile_id (str)

  • snapshot_id (str)

class UserProfileLifecycleRepository(*, bucket_id, objects=None)[source]

Bases: _BucketBoundRepository

Read and write live user-profile aggregates in the secure DB.

Rows use aeat.adapters.persistence.storage.USER_PROFILE_VALUE_NAMESPACE, wrap each UserProfileRecord in an Envelope, and persist through SecureObjectRepository.

Parameters:
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.

Parameters:

profile_id (str) – The immutable UUIDv4 identifying the profile.

Return type:

bool

Returns:

True when a record exists under that key, else False.

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 a UserProfileRecord, 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:

UserProfileRecord

Returns:

The decrypted UserProfileRecord carried by the envelope.

Raises:
save(record)[source]

Persist record as this bucket’s single live profile aggregate.

Wraps the UserProfileRecord in an encrypted Envelope (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 from record.profile_id. A profile bucket holds exactly one live profile record, so this overwrites any prior aggregate for the same profile_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 live UserProfileRecord aggregate to encrypt and store.

Return type:

None

iter_records()[source]

Yield every live UserProfileRecord from 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:

Iterable[UserProfileRecord]

delete(profile_id)[source]

Remove the live profile aggregate stored under profile_id.

Deletes the single live profile record keyed by profile_id from 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.

Parameters:

profile_id (str) – The immutable UUIDv4 identifying the profile.

Return type:

bool

Returns:

True when a record was deleted, False when no record was stored under that key.

class UserProfileSnapshotRepository(*, bucket_id, objects=None)[source]

Bases: _BucketBoundRepository

Read and write immutable filing-time profile snapshots in the secure DB.

Rows use aeat.adapters.persistence.storage.USER_PROFILE_SNAPSHOT_NAMESPACE, wrap each UserProfileSnapshot in an Envelope, and persist through SecureObjectRepository.

Parameters:
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.

Parameters:

snapshot_id (str) – The identifier of the snapshot, globally unique within this bucket.

Return type:

bool

Returns:

True when a snapshot exists under that key, else False.

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 and snapshot_id, validates it into a UserProfileSnapshot, 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:

UserProfileSnapshot

Returns:

The decrypted UserProfileSnapshot carried by the envelope.

Raises:
save(snapshot)[source]

Persist snapshot as an immutable filing-time snapshot.

A snapshot is the frozen profile state captured when a tax filing was prepared. Wraps the UserProfileSnapshot in an encrypted Envelope (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 and snapshot.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:

None