storage

package
v0.17.0-rc4 Latest Latest
Warning

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

Go to latest
Published: Oct 11, 2024 License: AGPL-3.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsAlreadyExist added in v0.16.0

func IsAlreadyExist(err error) bool

IsAlreadyExist returns whether error is an already-exists type error returned by the underlying storage library.

func IsInvalidKey added in v0.17.0

func IsInvalidKey(err error) bool

IsInvalidKey returns whether error is an invalid-key type error returned by the underlying storage library.

func IsNotFound added in v0.16.0

func IsNotFound(err error) bool

IsNotFound returns whether error is a not-found error type returned by the underlying storage library.

Types

type Driver

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

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

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) Delete

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

Delete 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) PutFile added in v0.17.0

func (d *Driver) PutFile(ctx context.Context, key, filepath, contentType string) (int64, error)

PutFile moves the contents of file at path, to storage.Driver{} under given key (with content-type if supported).

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(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