# `Ankusa.BlobStore.Azure`
[🔗](https://github.com/jamescarr/ankusa/blob/ankusa-v0.7.0/packages/ankusa/lib/ankusa/blob_store/azure.ex#L1)

`Ankusa.BlobStore` backed by Azure Blob Storage, via
[`Req`](https://hex.pm/packages/req). Works against real Azure or the
[Azurite](https://learn.microsoft.com/azure/storage/common/storage-use-azurite)
emulator.

This adapter deliberately carries **no credential dependency** — the same
stance as `Ankusa.BlobStore.GCS`. It accepts a credential you already have,
in either of the two forms Azure supports without the account key:

  * `:sas_token` — a Shared Access Signature query string (no leading `?`),
    generated out-of-band with the Azure CLI, SDK, or portal. The adapter
    appends it to every request and never sees the account key.
  * `:token_provider` — `{module, fun, args}`, applied per request, must
    return `{:ok, bearer_token} | :error`. For a service running on Azure,
    use the built-in `Ankusa.BlobStore.Azure.ManagedIdentity` (system- or
    user-assigned) rather than wiring your own Entra ID token source. On a
    `401` the adapter calls the module's `invalidate/n` (same arguments) when
    it exports one, and sends the request once more with the fresh token.

Shared Key signing (the `Authorization: SharedKey ...` HMAC) is deliberately
not implemented — it is the kind of security-sensitive canonicalization this
project does not hand-roll, and a SAS token is the least-privilege credential
Azure recommends anyway.

opts:

  * `:account_name`   — required, e.g. `"myaccount"`
  * `:container`      — required; Azure's name for the bucket
  * `:sas_token`      — optional; a SAS query string (no leading `?`)
  * `:token_provider` — optional; `{module, fun, args}` returning a bearer token
  * `:endpoint`       — default `"https://#{account_name}.blob.core.windows.net"`;
                         point at `"http://127.0.0.1:10000/#{account_name}"` for Azurite
  * `:timeout_ms`     — default `10_000`, for both connect and response of
                         one request that carries at most 1 MiB
  * `:upload_timeout_ms`, `:op_deadline_ms`, `:multipart_threshold_bytes`,
    `:multipart_part_bytes`, `:breaker_*`, `:pool_*` — one deadline per
                         operation, a block-list upload above a size, a
                         breaker per container and a connection pool per
                         endpoint. See `Ankusa.BlobStore.Options`
  * `:req_options`    — transport options for the HTTP client, e.g. a custom
                         Finch pool, a proxy, or `plug:` for `Req.Test` in
                         tests. See `Ankusa.HttpClient` for the accepted keys
  * `:retries`        — default `2`: extra attempts after a transport error
                         or a `408`/`429`/`5xx`. See `Ankusa.BlobStore.Retry`
  * `:sse`            — `%{type: :kms, key_id: encryption_scope}`: every blob is
                         written under that encryption scope
                         (`x-ms-encryption-scope`). Blob Storage encrypts
                         everything at rest anyway; this picks the key. See
                         `Ankusa.BlobStore.SSE`

`put_if_absent/4` sends `If-None-Match: *` (a `409`/`412` is `:already_exists`);
every `PUT` carries `Content-MD5` (validated by Azure) and
`x-ms-blob-content-md5` (stored), and a `GET` verifies the `Content-MD5` it is
sent (`Ankusa.BlobStore.Checksum`); a body over `multipart_threshold_bytes` is
Put Block per `multipart_part_bytes` and a Put Block List.

## Local dev

    config :ankusa,
      storage: %{
        blob_store:
          {Ankusa.BlobStore.Azure,
           account_name: "devstoreaccount1",
           container: "ankusa-segments-dev",
           endpoint: "http://127.0.0.1:10000/devstoreaccount1",
           sas_token: System.get_env("AZURE_BLOB_SAS")}
      }

`docker compose -f docker-compose.integration.yml up -d azurite azure-bootstrap` brings up
the emulator and creates the container.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
