backend

package
v0.0.0-...-04bf11e Latest Latest
Warning

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

Go to latest
Published: Dec 17, 2017 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsNotFound

func IsNotFound(err error) bool

IsNotFound returns true if the error returned is for a key that was not found.

Types

type ETCD

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

ETCD is a wrapper around the ETCD client that implements the backend.KV interface.

func NewETCDClient

func NewETCDClient(endpoints []string, dialTimeout time.Duration) (*ETCD, error)

NewETCDClient returns a new ETCD v3 client. Returns an error in case the connection to all endpoints fails.

func (*ETCD) Close

func (e *ETCD) Close() error

Close closes the connection to ETCD.

func (*ETCD) Delete

func (e *ETCD) Delete(ctx context.Context, key string) error

Delete deletes a key from ETCD. Returns NotFoundError in case the key does not exist.

func (*ETCD) Get

func (e *ETCD) Get(ctx context.Context, key string) (string, error)

Get retrieves values from ETCD. Returns NotFoundError in case the key does not exist.

func (*ETCD) List

func (e *ETCD) List(ctx context.Context, root string) (map[string]string, error)

List lists keys in ETCD that have root as a prefix.

func (*ETCD) Lock

func (e *ETCD) Lock(ctx context.Context, key string) (func(), error)

Lock creates a new distributes lock on a key. Any future locks on the same key block until the lock is released. The lock is released if the context is cancelled.

When no longer needed, the lock must be unlocked by calling the returned unlock function.

Note: if the context is cancelled due to a timeout, this will still wait to acquire the lock. The lock will timeout automatically by a value set on the ETCD server (default 60 seconds).

func (*ETCD) Put

func (e *ETCD) Put(ctx context.Context, key, value string) error

Put stores a value in ETCD. The key is created if it doesn't exist, if it exists it is overwritten. Any watchers on the key will be notified.

type Lister

type Lister interface {
	// List lists keys directly under a root key.
	List(ctx context.Context, root string) (map[string]string, error)
}

The Lister interface is implemented by backends that can list keys under a key.

type Locker

type Locker interface {
	// Locker creates a distributed lock on a key.
	Lock(ctx context.Context, key string) (func(), error)
}

Locker locks resources, preventing multiple clients modifying the same resource in the backend.

type NotFoundError

type NotFoundError struct {
	// Key is the key that was not found.
	Key string
}

NotFoundError indicates that a key was not found.

func (*NotFoundError) Error

func (e *NotFoundError) Error() string

Error returns the error string for a not found error.

type Reader

type Reader interface {
	// Get gets a value. In case the key does not exist, returns NotFoundError
	// if the key was not found.
	Get(ctx context.Context, key string) (string, error)
}

Reader reads values from a backend.

type TestKV

type TestKV struct {
	Data map[string]string
	// contains filtered or unexported fields
}

TestKV keeps data in memory. It should only be used for unit tests.

func NewTestKV

func NewTestKV() *TestKV

NewTestKV creates a new in key-value backend for tests. Snapshots are loaded to set the initial state.

func (*TestKV) Copy

func (t *TestKV) Copy() *TestKV

Copy returns a copy of the TestKV, including its data. This is meant for unit tests, where a single instance of the TestKV is created, and copies of it are mutated.

func (*TestKV) Delete

func (t *TestKV) Delete(ctx context.Context, key string) error

Delete removes a key from the in memory store.

func (*TestKV) Get

func (t *TestKV) Get(ctx context.Context, key string) (string, error)

Get returns a value from the in memory store.

func (*TestKV) List

func (t *TestKV) List(ctx context.Context, root string) (map[string]string, error)

List lists keys in the test store.

func (*TestKV) Lock

func (t *TestKV) Lock(ctx context.Context, key string) (func(), error)

Lock locks a key on the test kv. The key is locked for concurrent access until unlocked by calling the returned function.

func (*TestKV) Put

func (t *TestKV) Put(ctx context.Context, key, value string) error

Put adds or overwrites a key to the in memory store.

type Vault

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

Vault implemnts KV by storing values in Vault as generic secrets. Only the generic secret backend is supported.

func NewVaultClient

func NewVaultClient(address string) (*Vault, error)

NewVaultClient creates a new Vault client and connects to the Vault server The environment variable VAULT_TOKEN is read automatically to authenticate the client. Returns an error if the address is not in a valid url.

func (*Vault) Delete

func (v *Vault) Delete(ctx context.Context, key string) error

Delete deletes a generic secret from Vault. Returns NotFoundError if the secret does not exist.

Since Vault doesn't return if the secret was actually deleted a check is done first to read the key.

func (*Vault) Get

func (v *Vault) Get(ctx context.Context, key string) (string, error)

Get gets a generic secret from Vault. Returns NotFoundError if the secret does not exist.

func (*Vault) Put

func (v *Vault) Put(ctx context.Context, key, value string) error

Put stores a generic secret in Vault. If the key already exists it is overwritten. If the target data is other keys than the vaultDataKey the entire map is overwritten.

type Writer

type Writer interface {
	// Put inserts a value under a key. In case the value already exists it is
	// overwritten. The key is case-insensitive.
	Put(ctx context.Context, key, value string) error
	// Delete deletes a key. In case the key does not exist, returns NotFoundError
	// if the key was not found.
	Delete(ctx context.Context, key string) error
}

The Writer interface is implemented by a backend that can be written to.

Jump to

Keyboard shortcuts

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