storage

package
v0.15.0 Latest Latest
Warning

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

Go to latest
Published: Apr 10, 2024 License: AGPL-3.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// Ptrs to underlying storage library errors.
	ErrAlreadyExists = storage.ErrAlreadyExists
	ErrNotFound      = storage.ErrNotFound
)

Functions

This section is empty.

Types

type Driver

type Driver struct {
	// Underlying storage
	Storage storage.Storage

	// S3-only parameters
	Proxy          bool
	Bucket         string
	PresignedCache *ttl.Cache[string, PresignedURL]
}

Driver wraps a kv.KVStore to also provide S3 presigned GET URLs.

func AutoConfig

func AutoConfig() (*Driver, error)

func NewFileStorage added in v0.6.0

func NewFileStorage() (*Driver, error)

func NewS3Storage added in v0.6.0

func NewS3Storage() (*Driver, error)

func (*Driver) Close added in v0.8.0

func (d *Driver) Close() error

Close will close the storage, releasing any file locks.

func (*Driver) Delete

func (d *Driver) Delete(ctx context.Context, key string) error

Remove attempts to remove the supplied key (and corresponding value) from storage.

func (*Driver) Get

func (d *Driver) Get(ctx context.Context, key string) ([]byte, error)

Get returns the byte value for key in storage.

func (*Driver) GetStream

func (d *Driver) GetStream(ctx context.Context, key string) (io.ReadCloser, error)

GetStream returns an io.ReadCloser for the value bytes at key in the storage.

func (*Driver) Has added in v0.8.0

func (d *Driver) Has(ctx context.Context, key string) (bool, error)

Has checks if the supplied key is in the storage.

func (*Driver) ProbeCSPUri added in v0.11.1

func (d *Driver) ProbeCSPUri(ctx context.Context) (string, error)

ProbeCSPUri returns a URI string that can be added to a content-security-policy to allow requests to endpoints served by this driver.

If the driver is not backed by non-proxying S3, this will return an empty string and no error.

Otherwise, this function probes for a CSP URI by doing the following:

  1. Create a temporary file in the S3 bucket.
  2. Generate a pre-signed URL for that file.
  3. Extract '[scheme]://[host]' from the URL.
  4. Remove the temporary file.
  5. Return the '[scheme]://[host]' string.

func (*Driver) Put

func (d *Driver) Put(ctx context.Context, key string, value []byte) (int, error)

Put writes the supplied value bytes at key in the storage

func (*Driver) PutStream

func (d *Driver) PutStream(ctx context.Context, key string, r io.Reader) (int64, error)

PutStream writes the bytes from supplied reader at key in the storage

func (*Driver) URL

func (d *Driver) URL(ctx context.Context, key string) *PresignedURL

URL will return a presigned GET object URL, but only if running on S3 storage with proxying disabled.

func (*Driver) WalkKeys added in v0.8.0

func (d *Driver) WalkKeys(ctx context.Context, walk func(context.Context, string) error) error

WalkKeys walks the keys in the storage.

type PresignedURL added in v0.7.0

type PresignedURL struct {
	*url.URL
	Expiry time.Time // link expires at this time
}

PresignedURL represents a pre signed S3 URL with an expiry time.

Jump to

Keyboard shortcuts

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