Version: v0.8.1 Latest Latest

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

Go to latest
Published: Aug 16, 2017 License: MPL-2.0 Imports: 11 Imported by: 0




View Source
const (
	DeleteOperation Operation = "delete"
	GetOperation              = "get"
	ListOperation             = "list"
	PutOperation              = "put"
View Source
const (
	// DefaultCacheSize is used if no cache size is specified for NewCache
	DefaultCacheSize = 32 * 1024
View Source
const DefaultParallelOperations = 128


View Source
var (
	ErrRelativePath = errors.New("relative paths not supported")


func ExerciseBackend added in v0.8.0

func ExerciseBackend(t *testing.T, b Backend)

func ExerciseBackend_ListPrefix added in v0.8.0

func ExerciseBackend_ListPrefix(t *testing.T, b Backend)

func ExerciseEventuallyConsistentBackend added in v0.8.0

func ExerciseEventuallyConsistentBackend(t *testing.T, b Backend, d Delays)

func ExerciseEventuallyConsistentBackend_ListPrefix added in v0.8.0

func ExerciseEventuallyConsistentBackend_ListPrefix(t *testing.T, b Backend, d Delays)

func ExerciseHABackend added in v0.8.0

func ExerciseHABackend(t *testing.T, b HABackend, b2 HABackend)

func ExerciseTransactionalBackend added in v0.8.0

func ExerciseTransactionalBackend(t *testing.T, b Backend)

func GenericTransactionHandler added in v0.8.0

func GenericTransactionHandler(t PseudoTransactional, txns []TxnEntry) (retErr error)

Implements the transaction interface

func Prefixes added in v0.8.0

func Prefixes(s string) []string

Prefixes is a shared helper function returns all parent 'folders' for a given vault key. e.g. for 'foo/bar/baz', it returns ['foo', 'foo/bar']


type ActiveFunction added in v0.8.0

type ActiveFunction func() bool

Callback signatures for RunServiceDiscovery

type Backend

type Backend interface {
	// Put is used to insert or update an entry
	Put(entry *Entry) error

	// Get is used to fetch an entry
	Get(key string) (*Entry, error)

	// Delete is used to permanently delete an entry
	Delete(key string) error

	// List is used ot list all the keys under a given
	// prefix, up to the next prefix.
	List(prefix string) ([]string, error)

Backend is the interface required for a physical backend. A physical backend is used to durably store data outside of Vault. As such, it is completely untrusted, and is only accessed via a security barrier. The backends must represent keys in a hierarchical manner. All methods are expected to be thread safe.

type Cache

type Cache struct {
	// contains filtered or unexported fields

Cache is used to wrap an underlying physical backend and provide an LRU cache layer on top. Most of the reads done by Vault are for policy objects so there is a large read reduction by using a simple write-through cache.

func NewCache

func NewCache(b Backend, size int, logger log.Logger) *Cache

NewCache returns a physical cache of the given size. If no size is provided, the default size is used.

func (*Cache) Delete

func (c *Cache) Delete(key string) error

func (*Cache) Get

func (c *Cache) Get(key string) (*Entry, error)

func (*Cache) List

func (c *Cache) List(prefix string) ([]string, error)

func (*Cache) Purge

func (c *Cache) Purge()

Purge is used to clear the cache

func (*Cache) Put

func (c *Cache) Put(entry *Entry) error

type Delays added in v0.8.0

type Delays struct {
	BeforeGet  time.Duration
	BeforeList time.Duration

type Entry

type Entry struct {
	Key   string
	Value []byte

Entry is used to represent data stored by the physical backend

type Factory

type Factory func(config map[string]string, logger log.Logger) (Backend, error)

Factory is the factory function to create a physical backend.

type HABackend

type HABackend interface {
	// LockWith is used for mutual exclusion based on the given key.
	LockWith(key, value string) (Lock, error)

	// Whether or not HA functionality is enabled
	HAEnabled() bool

HABackend is an extensions to the standard physical backend to support high-availability. Vault only expects to use mutual exclusion to allow multiple instances to act as a hot standby for a leader that services all requests.

type Lock

type Lock interface {
	// Lock is used to acquire the given lock
	// The stopCh is optional and if closed should interrupt the lock
	// acquisition attempt. The return struct should be closed when
	// leadership is lost.
	Lock(stopCh <-chan struct{}) (<-chan struct{}, error)

	// Unlock is used to release the lock
	Unlock() error

	// Returns the value of the lock and if it is held
	Value() (bool, string, error)

type Operation added in v0.7.0

type Operation string

The operation type

type PermitPool added in v0.4.0

type PermitPool struct {
	// contains filtered or unexported fields

PermitPool is used to limit maximum outstanding requests

func NewPermitPool added in v0.4.0

func NewPermitPool(permits int) *PermitPool

NewPermitPool returns a new permit pool with the provided number of permits

func (*PermitPool) Acquire added in v0.4.0

func (c *PermitPool) Acquire()

Acquire returns when a permit has been acquired

func (*PermitPool) Release added in v0.4.0

func (c *PermitPool) Release()

Release returns a permit to the pool

type PseudoTransactional added in v0.7.0

type PseudoTransactional interface {
	// An internal function should do no locking or permit pool acquisition.
	// Depending on the backend and if it natively supports transactions, these
	// may simply chain to the normal backend functions.
	GetInternal(string) (*Entry, error)
	PutInternal(*Entry) error
	DeleteInternal(string) error

type Purgable added in v0.6.5

type Purgable interface {

Purgable is an optional interface for backends that support purging of their caches.

type RedirectDetect added in v0.6.1

type RedirectDetect interface {
	// DetectHostAddr is used to detect the host address
	DetectHostAddr() (string, error)

RedirectDetect is an optional interface that an HABackend can implement. If they do, a redirect address can be automatically detected.

type SealedFunction added in v0.8.0

type SealedFunction func() bool

type ServiceDiscovery added in v0.6.0

type ServiceDiscovery interface {
	// NotifyActiveStateChange is used by Core to notify a backend
	// capable of ServiceDiscovery that this Vault instance has changed
	// its status to active or standby.
	NotifyActiveStateChange() error

	// NotifySealedStateChange is used by Core to notify a backend
	// capable of ServiceDiscovery that Vault has changed its Sealed
	// status to sealed or unsealed.
	NotifySealedStateChange() error

	// Run executes any background service discovery tasks until the
	// shutdown channel is closed.
	RunServiceDiscovery(waitGroup *sync.WaitGroup, shutdownCh ShutdownChannel, redirectAddr string, activeFunc ActiveFunction, sealedFunc SealedFunction) error

ServiceDiscovery is an optional interface that an HABackend can implement. If they do, the state of a backend is advertised to the service discovery network.

type ShutdownChannel added in v0.6.0

type ShutdownChannel chan struct{}


type Transactional added in v0.7.0

type Transactional interface {
	// The function to run a transaction
	Transaction([]TxnEntry) error

Transactional is an optional interface for backends that support doing transactional updates of multiple keys. This is required for some features such as replication.

type TransactionalCache added in v0.8.0

type TransactionalCache struct {

TransactionalCache is a Cache that wraps the physical that is transactional

func NewTransactionalCache added in v0.8.0

func NewTransactionalCache(b Backend, size int, logger log.Logger) *TransactionalCache

func (*TransactionalCache) Transaction added in v0.8.0

func (c *TransactionalCache) Transaction(txns []TxnEntry) error

type TxnEntry added in v0.7.0

type TxnEntry struct {
	Operation Operation
	Entry     *Entry

TxnEntry is an operation that takes atomically as part of a transactional update. Only supported by Transactional backends.

func SetupTestingTransactions added in v0.8.0

func SetupTestingTransactions(t *testing.T, b Backend) []TxnEntry

type View added in v0.8.0

type View struct {
	// contains filtered or unexported fields

View represents a prefixed view of a physical backend

func NewView added in v0.8.0

func NewView(backend Backend, prefix string) *View

NewView takes an underlying physical backend and returns a view of it that can only operate with the given prefix.

func (*View) Delete added in v0.8.0

func (v *View) Delete(key string) error

Delete the entry from the prefix view

func (*View) Get added in v0.8.0

func (v *View) Get(key string) (*Entry, error)

Get the key of the prefixed view

func (*View) List added in v0.8.0

func (v *View) List(prefix string) ([]string, error)

List the contents of the prefixed view

func (*View) Put added in v0.8.0

func (v *View) Put(entry *Entry) error

Put the entry into the prefix view

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL