aeat.adapters.outbound.storage._google_drive module¶
Google Drive v3 adapters.outbound.storage.StorageProvider implementation.
Maps the adapters.outbound.storage.StorageProvider Protocol onto
the Drive API:
Each namespace is a folder directly under the operator-configured
aeat-vault/root. The root folder ID is required whenaeat_storage_provider_kind=google_driveand the vault folder is created lazily underaeat_google_drive_root_folder_id.Each object is a
files().create(...)upload withmimeType=application/octet-stream, named<hmac_prefix_8>--<label>.bin. The DriveappPropertiesfield carries the ownership marker, namespace, full object-key HMAC, and storedcontent_hashused to constructadapters.outbound.storage.ProviderObjectMetadata.Downloads use
files().get_media(fileId=...)and validate full SHA-256 payload hashes throughadapters.outbound.storage._integrity.verify_content_hash().HttpError status codes are mapped onto the typed
adapters.outbound.storage.OutboundStorageErrorhierarchy: 401/403 ->adapters.outbound.storage.OutboundStoragePermissionError, 404 ->adapters.outbound.storage.OutboundStorageNotFoundError, 409 ->adapters.outbound.storage.OutboundStorageConflictError, 429 ->adapters.outbound.storage.OutboundStorageQuotaError, 5xx ->adapters.outbound.storage.OutboundStorageUnavailableError, every other failure ->adapters.outbound.storage.OutboundStorageNetworkError.
The _service_factory() helper constructs the real Drive v3 resource
lazily so importing this module does not require google-api-python-client or
settings initialization.
- class GoogleDriveProvider(*, credentials, root_folder_id, vault_folder_name=None)[source]¶
Bases:
objectBytes-in / bytes-out
StorageProviderbacked by Google Drive v3.- put(namespace, object_key_hmac, payload, *, content_hash, label)[source]¶
Upload
payloadto Drive and returnProviderObjectMetadata.If a file for
object_key_hmacalready exists the existing Drive file is updated in-place (files().update); otherwise a new file is created (files().create) inside the namespace folder. TheappPropertiesfield on the Drive entry records the HMAC,content_hash, namespace, and ownership marker so subsequentgetanditer_objectscalls can resolve the entry without re-downloading the payload.- Parameters:
namespace (
str) – Logical bucket name; becomes a Drive sub-folder ofaeat-vault/.object_key_hmac (
str) – Full HMAC string that uniquely identifies the object. Only the first 8 characters are used in the Drive filename; the full value is stored inappProperties.payload (
bytes) – Raw bytes to upload. The provider is opaque to the content; encryption lives at a higher layer.content_hash (
str) – Vendor-prefixed digest string (e.g.sha256-<hex>). Stored inappPropertiesand verified onget.label (
str) – Human-readable filename component, sanitised to[A-Za-z0-9\\-_.]{1,64}.
- Return type:
- Returns:
ProviderObjectMetadatapopulated from the Drive API response.- Raises:
OutboundStorageValidationError – When
namespace,object_key_hmac, orcontent_hashare blank.OutboundStoragePermissionError – On HTTP 401 or 403 from Drive.
OutboundStorageQuotaError – On HTTP 429 from Drive.
OutboundStorageUnavailableError – On HTTP 5xx from Drive.
OutboundStorageNetworkError – On any other Drive API failure.
- get(namespace, object_key_hmac)[source]¶
Download the object, verify the stored hash, and return payload metadata.
Uses
files().get_mediato stream bytes. If the storedcontent_hashis asha256-<hex>string, the payload digest is recomputed after download and compared throughverify_content_hash(); a mismatch raisesadapters.outbound.storage.OutboundStorageIntegrityErrorbefore the payload is returned.- Parameters:
- Return type:
- Returns:
A two-tuple containing payload bytes and
ProviderObjectMetadata.- Raises:
OutboundStorageNotFoundError – When the namespace folder or object file is absent from Drive.
adapters.outbound.storage.OutboundStorageIntegrityError – When the downloaded payload does not match the stored SHA-256 digest.
OutboundStorageValidationError – When
namespaceorobject_key_hmacare blank.OutboundStoragePermissionError – On HTTP 401 or 403 from Drive.
OutboundStorageNetworkError – On any other Drive API failure or when
get_mediareturns a non-bytes value.
- delete(namespace, object_key_hmac)[source]¶
Permanently delete the Drive file for
object_key_hmac.Returns
Falseimmediately (without error) when the namespace folder or the object file does not exist; deleting a non-existent object is idempotent at the provider boundary.- Parameters:
- Return type:
- Returns:
Truewhen the file was found and deleted;Falsewhen the namespace or object was already absent.- Raises:
OutboundStorageValidationError – When
namespaceorobject_key_hmacare blank.OutboundStoragePermissionError – On HTTP 401 or 403 from Drive.
OutboundStorageNetworkError – On any other Drive API failure.
- iter_namespaces()[source]¶
Yield the name of every namespace folder directly under
aeat-vault/.Paginates through Drive’s
files().listusingnextPageToken. The namespace folder IDs are cached as a side effect so subsequent_resolve_namespace_foldercalls for yielded names skip the Drive lookup.- Yields:
Namespace name strings in Drive-returned order.
- Raises:
OutboundStoragePermissionError – On HTTP 401 or 403 from Drive.
OutboundStorageNetworkError – On any other Drive API failure.
- Return type:
- iter_objects(namespace)[source]¶
Yield metadata for every object in
namespace.Only files whose names end with
.binand contain--are yielded; Drive folders and unrelated files inside the namespace folder are silently skipped. The full HMAC is recovered fromappProperties.object_key_hmacwhen present, falling back to the filename prefix.- Parameters:
namespace (
str) – Logical bucket name.- Yields:
ProviderObjectMetadatarecords in Drive-returned order.- Raises:
OutboundStorageNotFoundError – When the namespace folder is absent from Drive.
OutboundStorageValidationError – When
namespaceis blank.OutboundStoragePermissionError – On HTTP 401 or 403 from Drive.
OutboundStorageNetworkError – On any other Drive API failure.
- Return type:
- probe(*, read_only=False)[source]¶
Assess Drive connectivity and write access, returning a
ProviderProbeReport.Checks, in order:
Service construction — verifies
google-api-python-clientcan be imported and credentials can build a Drive resource.Root folder existence — confirms
root_folder_idnames a non-trashed Drive folder.Sentinel round-trip (skipped when
read_only=True) — callsputthendeleteagainst a_probenamespace to confirm write access end-to-end.
The method never raises; every failure mode is encoded in the returned
ProviderProbeReport.- Parameters:
read_only (
bool) – WhenTrue, skip the sentinel write round-trip and reportwritable=Falseregardless of actual permissions.- Return type:
- Returns:
A
ProviderProbeReportwithreachable,writable,root_folder_present, and a human-readabledetailstring.