Documentation
¶
Overview ¶
Package azure implements blob.Store on Azure Blob Storage (and Azurite).
Authentication, in order of precedence:
- cfg.ConnectionString (Azurite, shared key or account-SAS connection strings; "UseDevelopmentStorage=true" selects local Azurite),
- cfg.Account + cfg.AccountKey (shared key),
- 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 ¶
- type Option
- type Store
- func (s *Store) Client() *container.Client
- func (s *Store) Close() error
- func (s *Store) Delete(ctx context.Context, key string) error
- func (s *Store) DeletePrefix(ctx context.Context, prefix string) error
- func (s *Store) Describe() blob.Description
- func (s *Store) Get(ctx context.Context, key string) (io.ReadCloser, *blob.ObjectInfo, error)
- func (s *Store) GetRange(ctx context.Context, key string, offset, length int64) (io.ReadCloser, *blob.ObjectInfo, error)
- func (s *Store) List(ctx context.Context, prefix, delimiter string) (*blob.ListResult, error)
- func (s *Store) Ping(ctx context.Context) error
- func (s *Store) PresignGet(ctx context.Context, key string, ttl time.Duration) (*blob.PresignedRequest, error)
- func (s *Store) PresignPut(ctx context.Context, key string, opts blob.PresignPutOptions, ...) (*blob.PresignedRequest, error)
- func (s *Store) Put(ctx context.Context, key string, r io.Reader, size int64, contentType string) (*blob.ObjectInfo, error)
- func (s *Store) Stat(ctx context.Context, key string) (*blob.ObjectInfo, error)
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 ¶
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 ¶
New creates a Store from configuration. It does not contact Azure; use Ping to verify access.
func (*Store) Delete ¶
Delete removes an object (and its snapshots); deleting a missing object is not an error.
func (*Store) DeletePrefix ¶
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 ¶
List returns all objects under prefix, sorted by key. With delimiter "/", keys below the next "/" are folded into Prefixes.
func (*Store) Ping ¶
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.