storage

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Nov 1, 2024 License: MIT Imports: 17 Imported by: 0

Documentation

Overview

Package storage provides a client around Azure Blob Storage for sending data that will be used by the ARN service.

Usage:

cli, err := storage.New("https://myaccount.blob.core.windows.net", cred)
if err != nil {
	log.Fatal(err)
}
defer cli.Close()

if err := cli.Upload(ctx, "my-id", []byte("my-data")); err != nil {
	log.Fatal(err)
}

Changes from the original:

- Moved to the slog package and from passing logrus via context.

  • No longer use any logging from azcore.

- Made the credential cache non-blocking with background refreshes instead of stop the world refreshes - Used the exponential backoff package for retries - Moved to standard go options for constructors - Removed use of "to" package for pointer creation, replaced with a simple generic function - Wrote tests and changed structure to help with testing - Did some re-ordering of events to avoid making unnecessary calls in certain failiure cases

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

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

Client is a client for interacting with Azure Blob Storage for pushing and pulling data used by the ARN service.

func New

func New(endpoint string, cred azcore.TokenCredential, options ...Option) (*Client, error)

New creates a new storage client. endpoint is the Azure Blob Storage endpoint, cred is the Azure SDK TokenCredential, and opts are the policy options for the service.Client.

func (*Client) Close

func (c *Client) Close()

Close closes the client.

func (*Client) Upload

func (c *Client) Upload(ctx context.Context, id string, b []byte) (*url.URL, error)

Upload uploads bytes to a blob named id in today's container. It returns a SAS link enabling the blob to be read.

type Option

type Option func(*Client) error

Option is a function that sets an option on the client.

func WithContainerExt

func WithContainerExt(ext string) Option

WithContainerExt sets a name extension for a blob container. This can be useful for doing discovery of containers that are created by a particular client. Names are in the format "arm-ext-nt-YYYY-MM-DD". This will cause the client to create "arm-ext-nt-[ext]-YYYY-MM-DD". Note characters must be letters, numbers, or hyphens. Any letters will be automatically lowercased. The ext cannot be more than 41 characters.

func WithFake added in v0.1.1

func WithFake(f Uploader) Option

WithFake sets a fake uploader for testing purposes. This will cause the client to use the fake Upload() method instead of the real one. Can only be used in testing.

func WithLogger

func WithLogger(log *slog.Logger) Option

WithLogger sets the logger on the client. By default it uses slog.Default().

func WithPolicyOptions

func WithPolicyOptions(opts policy.ClientOptions) Option

WithPolicyOptions sets the policy options for the service.Client. By default it uses the default policy options.

type Uploader added in v0.1.1

type Uploader interface {
	// Upload simulates the Upload() method.
	Upload(ctx context.Context, id string, b []byte) (*url.URL, error)
}

Uploader is an interface for testing purposes to simulate the Upload() method.

Jump to

Keyboard shortcuts

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