bucket

package
v1.15.0-rc.1 Latest Latest
Warning

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

Go to latest
Published: Apr 1, 2023 License: Apache-2.0 Imports: 22 Imported by: 4

Documentation

Index

Constants

View Source
const (
	// S3 is the value for the S3 storage backend.
	S3 = "s3"

	// GCS is the value for the GCS storage backend.
	GCS = "gcs"

	// Azure is the value for the Azure storage backend.
	Azure = "azure"

	// Swift is the value for the Openstack Swift storage backend.
	Swift = "swift"

	// Filesystem is the value for the filesystem storage backend.
	Filesystem = "filesystem"
)

Variables

View Source
var (
	SupportedBackends = []string{S3, GCS, Azure, Swift, Filesystem}

	ErrUnsupportedStorageBackend = errors.New("unsupported storage backend")
)

Functions

func DeletePrefix added in v1.7.0

func DeletePrefix(ctx context.Context, bkt objstore.Bucket, prefix string, logger log.Logger) (int, error)

DeletePrefix removes all objects with given prefix, recursively. It returns number of deleted objects. If deletion of any object fails, it returns error and stops.

func NewClient

func NewClient(ctx context.Context, cfg Config, name string, logger log.Logger, reg prometheus.Registerer) (client objstore.Bucket, err error)

NewClient creates a new bucket client based on the configured backend

func NewUserBucketClient

func NewUserBucketClient(userID string, bucket objstore.Bucket, cfgProvider TenantConfigProvider) objstore.InstrumentedBucket

NewUserBucketClient returns a bucket client to use to access the storage on behalf of the provided user. The cfgProvider can be nil.

Types

type ClientMock

type ClientMock struct {
	mock.Mock
}

ClientMock mocks objstore.Bucket

func (*ClientMock) Attributes

func (m *ClientMock) Attributes(ctx context.Context, name string) (objstore.ObjectAttributes, error)

ObjectSize mocks objstore.Bucket.Attributes()

func (*ClientMock) Close

func (m *ClientMock) Close() error

Close mocks objstore.Bucket.Close()

func (*ClientMock) Delete

func (m *ClientMock) Delete(ctx context.Context, name string) error

Delete mocks objstore.Bucket.Delete()

func (*ClientMock) Exists

func (m *ClientMock) Exists(ctx context.Context, name string) (bool, error)

Exists mocks objstore.Bucket.Exists()

func (*ClientMock) Get

func (m *ClientMock) Get(ctx context.Context, name string) (io.ReadCloser, error)

Get mocks objstore.Bucket.Get()

func (*ClientMock) GetRange

func (m *ClientMock) GetRange(ctx context.Context, name string, off, length int64) (io.ReadCloser, error)

GetRange mocks objstore.Bucket.GetRange()

func (*ClientMock) IsObjNotFoundErr

func (m *ClientMock) IsObjNotFoundErr(err error) bool

IsObjNotFoundErr mocks objstore.Bucket.IsObjNotFoundErr()

func (*ClientMock) Iter

func (m *ClientMock) Iter(ctx context.Context, dir string, f func(string) error, options ...objstore.IterOption) error

Iter mocks objstore.Bucket.Iter()

func (*ClientMock) MockDelete

func (m *ClientMock) MockDelete(name string, err error)

func (*ClientMock) MockExists

func (m *ClientMock) MockExists(name string, exists bool, err error)

func (*ClientMock) MockGet

func (m *ClientMock) MockGet(name, content string, err error)

MockGet is a convenient method to mock Get() and Exists()

func (*ClientMock) MockGetTimes added in v1.14.0

func (m *ClientMock) MockGetTimes(name, content string, err error, times int)

MockGetTimes is a convenient method to mock Get() and Exists() to run x time

func (*ClientMock) MockIter

func (m *ClientMock) MockIter(prefix string, objects []string, err error)

MockIter is a convenient method to mock Iter()

func (*ClientMock) MockIterWithCallback

func (m *ClientMock) MockIterWithCallback(prefix string, objects []string, err error, cb func())

MockIterWithCallback is a convenient method to mock Iter() and get a callback called when the Iter API is called.

func (*ClientMock) MockUpload added in v1.7.0

func (m *ClientMock) MockUpload(name string, err error)

func (*ClientMock) Name

func (m *ClientMock) Name() string

Name mocks objstore.Bucket.Name()

func (*ClientMock) Upload

func (m *ClientMock) Upload(ctx context.Context, name string, r io.Reader) error

Upload mocks objstore.Bucket.Upload()

type Config

type Config struct {
	Backend string `yaml:"backend"`
	// Backends
	S3         s3.Config         `yaml:"s3"`
	GCS        gcs.Config        `yaml:"gcs"`
	Azure      azure.Config      `yaml:"azure"`
	Swift      swift.Config      `yaml:"swift"`
	Filesystem filesystem.Config `yaml:"filesystem"`

	// Not used internally, meant to allow callers to wrap Buckets
	// created using this config
	Middlewares []func(objstore.Bucket) (objstore.Bucket, error) `yaml:"-"`

	// Used to inject additional backends into the config. Allows for this config to
	// be embedded in multiple contexts and support non-object storage based backends.
	ExtraBackends []string `yaml:"-"`
}

Config holds configuration for accessing long-term storage.

func (*Config) RegisterFlags

func (cfg *Config) RegisterFlags(f *flag.FlagSet)

RegisterFlags registers the backend storage config.

func (*Config) RegisterFlagsWithPrefix

func (cfg *Config) RegisterFlagsWithPrefix(prefix string, f *flag.FlagSet)

func (*Config) Validate

func (cfg *Config) Validate() error

type PrefixedBucketClient added in v1.8.0

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

func NewPrefixedBucketClient added in v1.8.0

func NewPrefixedBucketClient(bucket objstore.Bucket, prefix string) *PrefixedBucketClient

NewPrefixedBucketClient returns a new PrefixedBucketClient.

func (*PrefixedBucketClient) Attributes added in v1.8.0

Attributes returns attributes of the specified object.

func (*PrefixedBucketClient) Close added in v1.8.0

func (b *PrefixedBucketClient) Close() error

Close implements io.Closer

func (*PrefixedBucketClient) Delete added in v1.8.0

func (b *PrefixedBucketClient) Delete(ctx context.Context, name string) error

Delete removes the object with the given name.

func (*PrefixedBucketClient) Exists added in v1.8.0

func (b *PrefixedBucketClient) Exists(ctx context.Context, name string) (bool, error)

Exists checks if the given object exists in the bucket.

func (*PrefixedBucketClient) Get added in v1.8.0

Get returns a reader for the given object name.

func (*PrefixedBucketClient) GetRange added in v1.8.0

func (b *PrefixedBucketClient) GetRange(ctx context.Context, name string, off, length int64) (io.ReadCloser, error)

GetRange returns a new range reader for the given object name and range.

func (*PrefixedBucketClient) IsObjNotFoundErr added in v1.8.0

func (b *PrefixedBucketClient) IsObjNotFoundErr(err error) bool

IsObjNotFoundErr returns true if error means that object is not found. Relevant to Get operations.

func (*PrefixedBucketClient) Iter added in v1.8.0

func (b *PrefixedBucketClient) Iter(ctx context.Context, dir string, f func(string) error, options ...objstore.IterOption) error

Iter calls f for each entry in the given directory (not recursive.). The argument to f is the full object name including the prefix of the inspected directory. The configured prefix will be stripped before supplied function is applied.

func (*PrefixedBucketClient) Name added in v1.8.0

func (b *PrefixedBucketClient) Name() string

Name returns the bucket name for the provider.

func (*PrefixedBucketClient) ReaderWithExpectedErrs added in v1.8.0

WithExpectedErrs allows to specify a filter that marks certain errors as expected, so it will not increment thanos_objstore_bucket_operation_failures_total metric.

func (*PrefixedBucketClient) Upload added in v1.8.0

func (b *PrefixedBucketClient) Upload(ctx context.Context, name string, r io.Reader) (err error)

Upload the contents of the reader as an object into the bucket.

func (*PrefixedBucketClient) WithExpectedErrs added in v1.8.0

ReaderWithExpectedErrs allows to specify a filter that marks certain errors as expected, so it will not increment thanos_objstore_bucket_operation_failures_total metric.

type SSEBucketClient added in v1.8.0

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

SSEBucketClient is a wrapper around a objstore.BucketReader that configures the object storage server-side encryption (SSE) for a given user.

func NewSSEBucketClient added in v1.8.0

func NewSSEBucketClient(userID string, bucket objstore.Bucket, cfgProvider TenantConfigProvider) *SSEBucketClient

NewSSEBucketClient makes a new SSEBucketClient. The cfgProvider can be nil.

func (*SSEBucketClient) Attributes added in v1.8.0

func (b *SSEBucketClient) Attributes(ctx context.Context, name string) (objstore.ObjectAttributes, error)

Attributes implements objstore.Bucket.

func (*SSEBucketClient) Close added in v1.8.0

func (b *SSEBucketClient) Close() error

Close implements objstore.Bucket.

func (*SSEBucketClient) Delete added in v1.8.0

func (b *SSEBucketClient) Delete(ctx context.Context, name string) error

Delete implements objstore.Bucket.

func (*SSEBucketClient) Exists added in v1.8.0

func (b *SSEBucketClient) Exists(ctx context.Context, name string) (bool, error)

Exists implements objstore.Bucket.

func (*SSEBucketClient) Get added in v1.8.0

func (b *SSEBucketClient) Get(ctx context.Context, name string) (io.ReadCloser, error)

Get implements objstore.Bucket.

func (*SSEBucketClient) GetRange added in v1.8.0

func (b *SSEBucketClient) GetRange(ctx context.Context, name string, off, length int64) (io.ReadCloser, error)

GetRange implements objstore.Bucket.

func (*SSEBucketClient) IsObjNotFoundErr added in v1.8.0

func (b *SSEBucketClient) IsObjNotFoundErr(err error) bool

IsObjNotFoundErr implements objstore.Bucket.

func (*SSEBucketClient) Iter added in v1.8.0

func (b *SSEBucketClient) Iter(ctx context.Context, dir string, f func(string) error, options ...objstore.IterOption) error

Iter implements objstore.Bucket.

func (*SSEBucketClient) Name added in v1.8.0

func (b *SSEBucketClient) Name() string

Name implements objstore.Bucket.

func (*SSEBucketClient) ReaderWithExpectedErrs added in v1.8.0

ReaderWithExpectedErrs implements objstore.Bucket.

func (*SSEBucketClient) Upload added in v1.8.0

func (b *SSEBucketClient) Upload(ctx context.Context, name string, r io.Reader) error

Upload the contents of the reader as an object into the bucket.

func (*SSEBucketClient) WithExpectedErrs added in v1.8.0

WithExpectedErrs implements objstore.Bucket.

type TenantConfigProvider added in v1.8.0

type TenantConfigProvider interface {
	// S3SSEType returns the per-tenant S3 SSE type.
	S3SSEType(userID string) string

	// S3SSEKMSKeyID returns the per-tenant S3 KMS-SSE key id or an empty string if not set.
	S3SSEKMSKeyID(userID string) string

	// S3SSEKMSEncryptionContext returns the per-tenant S3 KMS-SSE key id or an empty string if not set.
	S3SSEKMSEncryptionContext(userID string) string
}

TenantConfigProvider defines a per-tenant config provider.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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