azuredol.connection

Connection-layer for azuredol.

Owns the expensive resource (BlobServiceClient) and the credential cascade. See misc/docs/architecture.md Layer A and misc/docs/design_decisions.md §6.

class azuredol.connection.AzureConnection(credential: str | dict | Any | None = None, connection_string: str | None = None, account_url: str | None = None, account_key: str | None = None, client_kwargs: dict = <factory>)[source]

Holds a resolved credential and a lazy BlobServiceClient.

This is the dependency-injection seam for the whole package. Tests construct one pointing at Azurite without touching any store class.

Parameters:
  • credential – explicit credential object, key string, or SAS string.

  • connection_string – full connection string (overrides credential).

  • account_url – storage account URL (with or without credential).

  • account_key – shared-key for the account.

All four args are optional; the credential cascade in resolve_credential is consulted if none are provided.

blob_client(container: str, blob: str)[source]

Cheap derivation of a BlobClient from the shared service client.

container_client(container: str)[source]

Cheap derivation of a ContainerClient from the shared service client.

classmethod from_anything(source) AzureConnection[source]

Convenience: build an AzureConnection from a thing-or-spec.

Accepts:
  • AzureConnection (returned as-is)

  • BlobServiceClient (wrapped without further resolution)

  • str (connection string)

  • dict (passed as kwargs)

  • None (defer to env / AAD)

property service_client: BlobServiceClient

The lazily-constructed BlobServiceClient. Cached for the connection’s lifetime.

azuredol.connection.CredentialLike

account-key string, connection string, SAS string, dict of kwargs, azure.identity credential object, or None (defer to env / DefaultAzureCredential).

Type:

Any of

alias of str | dict | Any | None

azuredol.connection.resolve_credential(*, credential: str | dict | Any | None = None, connection_string: str | None = None, account_url: str | None = None, account_key: str | None = None) dict[source]

Resolve a credential into a normalized form that can build a BlobServiceClient.

Cascade (first hit wins):

  1. Explicit credential=

  2. Explicit connection_string=

  3. Explicit account_url= + account_key= (or just account_url= + AAD)

  4. Env var AZURE_STORAGE_CONNECTION_STRING

  5. Env vars AZURE_STORAGE_ACCOUNT_URL + AZURE_STORAGE_ACCOUNT_KEY

  6. Env var AZURE_STORAGE_ACCOUNT_URL alone + DefaultAzureCredential

Returns:

{"conn_str": "..."} # for from_connection_string {"account_url": "...", "credential": <obj>} # for __init__

Return type:

A dict with one of these shapes

Raises:

ValueError – if no source resolves.