aeat.adapters.outbound.storage._factory module

get_storage_provider() factory keyed on ProviderKind.

The factory is the single entry point upper layers (sync coordinator, CLI commands, application services) call to obtain a adapters.outbound.storage.StorageProvider configured for the active profile. core.config.Settings drives the choice:

Composition order:

  1. Resolve the active profile via adapters.outbound.google._active_profile.resolve_active_profile().

  2. Read settings via load_settings().

  3. Dispatch on ProviderKind. LOCAL_FILESYSTEM builds a adapters.outbound.storage._local.LocalFileSystemProvider rooted at aeat_local_storage_root / profile; GOOGLE_DRIVE calls build_google_credentials(), which reads the profile’s persisted GoogleCredentialSourceSelection (a missing selection defaults to OAUTH_DESKTOP, preserving the existing default byte-for-byte) and dispatches to either the OAuth-Desktop hydration or resolve_impersonated_credentials(), then instantiates adapters.outbound.storage._google_drive.GoogleDriveProvider keyed on aeat_google_drive_root_folder_id.

  4. Refuse unknown kinds with OutboundStorageValidationError.

build_google_credentials(*, profile)[source]

Resolve Google Credentials for the profile’s chosen credential source.

Reads the profile’s persisted GoogleCredentialSourceSelection (load_credential_source_selection()). A missing selection defaults to OAUTH_DESKTOP, so a profile that has never opted into service-account impersonation gets byte-for-byte the same behaviour as before this dispatch existed.

Imports the upstream Google libraries lazily so unit tests for the local backend do not pay the cost.

Return type:

Credentials

Parameters:

profile (str)

resolve_drive_root_folder_id(*, profile, settings)[source]

Resolve the Drive root folder id with the canonical precedence.

  1. AEAT_GOOGLE_DRIVE_ROOT_FOLDER_ID env var / .env value (core.config.Settings aeat_google_drive_root_folder_id; overrides for one-off / CI / debugging without persisting state)

  2. Per-profile persisted adapters.outbound.google.DriveConfig record (canonical operator enrolment via aeat config google folder set <id>)

Returns the empty string when neither source is configured.

Return type:

str

Parameters:
get_storage_provider(*, settings=None)[source]

Build a StorageProvider for the active AEAT profile.

Parameters:

settings (Settings | None) – Optional pre-built core.config.Settings. Defaults to core.config.load_settings().

Return type:

StorageProvider

Returns:

A concrete StorageProvider already wired with credentials and root directory or folder ID for the resolved profile.

Raises:

OutboundStorageValidationError – When the settings value is unknown, the Drive backend is selected without aeat_google_drive_root_folder_id, or the profile lacks the records the chosen backend needs.