store

package
v0.0.0-...-7234002 Latest Latest
Warning

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

Go to latest
Published: Oct 14, 2018 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrBadVersion = errors.New("bad version")

Error when retrieving store metadata that has an unknown version.

View Source
var ErrForbiddenKey = errors.New("read/write to key name is forbidden")

Error when attempting to read/write to a forbidden key name (e.g. "metadata" which is used internally).

View Source
var ErrMalformedMetadata = errors.New("malformed metadata")

Error when retrieving store metadata that's unreadable.

View Source
var ErrMissingMetadata = errors.New("user metadata not set")

Error when attempting to read a custom metadata field which hasn't been set.

View Source
var ErrStoreNotConnected = errors.New("store not ready for reading/writing")

Error when attempting to read/write from the store before it's been opened, unlocked or wiped.

View Source
var ErrStoreNotInitialized = errors.New("remote store not initialized")

Error when attempting to unlock a store which hasn't been initialized.

Functions

This section is empty.

Types

type ByteRange

type ByteRange [2]int

ByteRange is an offset pair (zero-indexed, inclusive) used when requesting partial contents from the storage layer. See http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.35 for more details.

type Keys

type Keys struct {
	EncKey  []byte `json:"encKey"`  // base64 encoded at rest
	AuthKey []byte `json:"authKey"` // base64 encoded at rest
}

Keys is a struct for handling the encryption and authentication keys to store data.

type Packer

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

A Packer is used for storing multiple blobs as a single object.

func (*Packer) Close

func (p *Packer) Close() error

Close finishes writing, returning any last errors.

func (*Packer) PutReader

func (p *Packer) PutReader(r io.Reader) (written int, err error)

PutReader reads data into the object. Returns the bytes written.

type S3Config

type S3Config struct {
	S3Region     string `json:"s3Region"`
	S3Bucket     string `json:"s3Bucket"`
	AWSAccessKey string `json:"awsAccessKey"`
	AWSSecretKey string `json:"awsSecretKey"`
}

S3Config has the configuration options for creating a new S3 connection.

type StorageLayer

type StorageLayer interface {
	// Exists returns true if the container (S3 bucket, folder, etc.) exists and is usable.
	Exists() (bool, error)
	// Create ensures the container exists and is usable.
	Create() error

	// Size returns the encrypted content length of an object identified by key.
	Size(key string) (int, error)
	// GetReader returns the contents of an object identified by key.
	GetReader(key string) (io.Reader, error)
	// PutReader reads in from r and stores the result to an object.
	PutReader(key string, r io.Reader) (int, error)
	// IsNotExist returns true if the error indicates an object does not exist.
	IsNotExist(err error) bool
}

StorageLayer is the interface used by the store for underlying storage.

type Store

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

Store handles compressing, encrypting and uploading blobs to some storage medium.

func NewStore

func NewStore(layer StorageLayer, id string) *Store

NewStore returns a store using some storage layer.

func NewStoreFS

func NewStoreFS(root string) (s *Store, err error)

NewStoreFS returns a store using the filesystem as its storage layer.

func NewStoreS3

func NewStoreS3(cfg S3Config) (s *Store, err error)

NewStoreS3 returns a store using S3 as its storage layer.

func (*Store) Get

func (s *Store) Get(key string) (data []byte, err error)

Get returns the data stored by the given key.

func (*Store) GetMetadata

func (s *Store) GetMetadata(key string) (interface{}, error)

GetMetadata returns the value of a custom metadata field.

func (*Store) GetReader

func (s *Store) GetReader(key string) (data io.Reader, err error)

GetReader returns a reader for the data stored by the given key.

func (*Store) ID

func (s *Store) ID() string

ID returns the unique identifier of the store.

func (*Store) IsClean

func (s *Store) IsClean() bool

IsEmpty returns true if the store is clean (has no metadata) and is thus safe to wipe.

func (*Store) IsNotExist

func (s *Store) IsNotExist(err error) bool

IsNotExist returns a boolean indicating whether the error is because the object does not exist.

func (*Store) Open

func (s *Store) Open(keys Keys) (err error)

Open sets the encryption keys to use, tests that we can read from the store.

func (*Store) Pack

func (s *Store) Pack(key string) (*Packer, error)

Pack multiple blobs as a single object in the store. Will overwrite existing keys.

func (*Store) Put

func (s *Store) Put(key string, data []byte) (written int, err error)

Put some blob as an object in the store. Returns the bytes written. Will overwrite existing keys.

func (*Store) PutMetadata

func (s *Store) PutMetadata(key string, data interface{}) error

PutMetadata writes some arbitrary (unencrypted) field to the store metadata. Ideally, this should be some small configuration data or similar.

func (*Store) PutReader

func (s *Store) PutReader(key string, r io.Reader) (written int, err error)

PutReader reads data into an object in the store. Returns the bytes written. Will overwrite existing keys.

func (*Store) Unlock

func (s *Store) Unlock(secret []byte) (keys Keys, err error)

Unlock reads the store metadata and returns encryption keys derived from our secret+salt. This will be followed by a call to Open so the store will be ready for use.

func (*Store) Wipe

func (s *Store) Wipe(secret []byte) (keys Keys, err error)

Wipe initializes the store by (re)populating it with metadata/salt. All existing data will be lost! This will be followed by a call to Open so the store will be ready for use.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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