azure

package
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 15, 2026 License: Apache-2.0 Imports: 26 Imported by: 0

Documentation

Overview

Package azure implements blob.Store on Azure Blob Storage (and Azurite).

Authentication, in order of precedence:

  1. cfg.ConnectionString (Azurite, shared key or account-SAS connection strings; "UseDevelopmentStorage=true" selects local Azurite),
  2. cfg.Account + cfg.AccountKey (shared key),
  3. azidentity.DefaultAzureCredential (managed identity, workload identity, Azure CLI, environment).

Presigned URLs are service SAS URLs signed with the shared key when one is available, otherwise user-delegation SAS URLs (the identity needs "Storage Blob Delegator", included in "Storage Blob Data Contributor"). Account-SAS connection strings cannot presign.

A SAS cannot restrict the size or content of an upload (it signs no request headers), so presigned uploads accept any body for their blob: PresignPutOptions.Size and SHA256 are not enforced and callers must verify uploads afterwards (the deploy gateway compares sizes at commit and deletes mismatching objects).

On accounts with a hierarchical namespace (ADLS Gen2), directory placeholder blobs (metadata hdi_isfolder=true) are hidden from listings.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Option

type Option func(*options)

Option configures a Store.

func WithClientOptions

func WithClientOptions(fn func(*service.ClientOptions)) Option

WithClientOptions adjusts the Azure SDK client options.

func WithCredential

func WithCredential(cred azcore.TokenCredential) Option

WithCredential sets the token credential used when neither a connection string nor an account key is configured (default DefaultAzureCredential).

func WithLogger

func WithLogger(l *slog.Logger) Option

WithLogger sets the logger (default slog.Default()).

type Store

type Store struct {
	// contains filtered or unexported fields
}

Store is a blob.Store backed by an Azure Blob Storage container (optionally under a key prefix). It is safe for concurrent use.

func New

func New(ctx context.Context, cfg config.AzureConfig, opts ...Option) (*Store, error)

New creates a Store from configuration. It does not contact Azure; use Ping to verify access.

func (*Store) Client

func (s *Store) Client() *container.Client

Client exposes the underlying container client (for tests and tooling).

func (*Store) Close

func (s *Store) Close() error

Close releases resources; the Azure clients need no explicit shutdown.

func (*Store) Delete

func (s *Store) Delete(ctx context.Context, key string) error

Delete removes an object (and its snapshots); deleting a missing object is not an error.

func (*Store) DeletePrefix

func (s *Store) DeletePrefix(ctx context.Context, prefix string) error

DeletePrefix removes every object whose key starts with prefix (deletes run concurrently; HNS directory placeholders are removed last, deepest first). An empty prefix is rejected.

func (*Store) Describe

func (s *Store) Describe() blob.Description

Describe returns the public storage description.

func (*Store) Get

func (s *Store) Get(ctx context.Context, key string) (io.ReadCloser, *blob.ObjectInfo, error)

Get opens an object for reading. Transient failures while reading are retried from the current offset.

func (*Store) GetRange

func (s *Store) GetRange(ctx context.Context, key string, offset, length int64) (io.ReadCloser, *blob.ObjectInfo, error)

GetRange reads length bytes from offset (length < 0 = to the end). The returned ObjectInfo describes the whole object; ranges past the end yield an empty body.

func (*Store) List

func (s *Store) List(ctx context.Context, prefix, delimiter string) (*blob.ListResult, error)

List returns all objects under prefix, sorted by key. With delimiter "/", keys below the next "/" are folded into Prefixes.

func (*Store) Ping

func (s *Store) Ping(ctx context.Context) error

Ping checks container access (Get Container Properties), falling back to listing one blob when the identity may only access blob data.

func (*Store) PresignGet

func (s *Store) PresignGet(ctx context.Context, key string, ttl time.Duration) (*blob.PresignedRequest, error)

PresignGet returns a read-only SAS URL.

func (*Store) PresignPut

func (s *Store) PresignPut(ctx context.Context, key string, opts blob.PresignPutOptions, ttl time.Duration) (*blob.PresignedRequest, error)

PresignPut returns a SAS URL accepting a PUT of the object's bytes. The returned Headers (x-ms-blob-type: BlockBlob and Content-Type) must be sent verbatim. A SAS cannot bind opts.Size or opts.SHA256: the URL accepts a body of any size and content until it expires (see the package doc).

func (*Store) Put

func (s *Store) Put(ctx context.Context, key string, r io.Reader, size int64, contentType string) (*blob.ObjectInfo, error)

Put writes a block blob. Bodies up to 8 MiB are sent in one request; larger or unknown-size bodies are staged in 4 MiB blocks. When contentType is empty it is derived from the key extension or content.

func (*Store) Stat

func (s *Store) Stat(ctx context.Context, key string) (*blob.ObjectInfo, error)

Stat returns object metadata or blob.ErrNotFound.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL