Documentation
¶
Overview ¶
Package vault is a pluggable configuration and secret store.
Vault decouples where configuration comes from (Source) and where it lives locally (Store). Sources are read-only providers that fetch entries from external systems. Stores are read-write backends that persist entries locally for fast access.
Core Interfaces ¶
Two pluggable interfaces define the contract:
- Store — persists entries locally (read-write)
- Source — fetches entries from an external system (read-only)
SourceFunc adapts a plain function into a Source.
Namespace Support ¶
Store implementations that support scoping implement Namespaced. When a Vault is configured with a namespace and its store implements Namespaced, the vault automatically scopes all operations.
Resolution Flow ¶
When [Vault.Get] is called:
- Check the store for the key
- If found and not expired (when TTL is configured), return it
- If missing or expired, auto-refresh from all sources (at most once per TTL period)
- Check the store again
Explicit [Vault.Refresh] is always available regardless of TTL.
Usage ¶
v := vault.New(
vault.WithStore(keychain.New()),
vault.WithSource(mySSMSource),
vault.WithNamespace("prod"),
vault.WithTTL(7 * 24 * time.Hour),
)
entry, err := v.Get(ctx, "db-password")
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrNotFound = errors.New("vault: not found")
ErrNotFound is returned when an entry does not exist in the store.
Functions ¶
This section is empty.
Types ¶
type Entry ¶
type Entry struct {
Key string `json:"key"`
Value string `json:"value"`
CreatedAt time.Time `json:"created_at"`
Source string `json:"source"`
}
Entry is a configuration or secret value.
type Memory ¶
type Memory struct {
// contains filtered or unexported fields
}
Memory is an in-memory Store. It is safe for concurrent use and implements Namespaced. Useful for testing and as the default store.
type Namespaced ¶
Namespaced is an optional interface for stores that support scoping. Store implementations that support namespacing implement this interface. When implemented, [Namespaced.WithNamespace] returns a Store whose operations are scoped to the given namespace. The returned store shares the same backing data as the original.
type Option ¶
type Option func(*config)
Option configures a Vault created by New.
func WithNamespace ¶
WithNamespace scopes the vault to a namespace. If the configured store implements Namespaced, all operations are scoped automatically. If the store does not implement Namespaced, this option has no effect.
func WithSource ¶
WithSource adds a source to the vault. Sources are consulted in the order they are added during [Vault.Refresh].
type Source ¶
Source fetches entries from an external system. Implementations are read-only providers — they produce entries but do not store them.
type SourceFunc ¶
SourceFunc adapts a plain function into a Source.
type Store ¶
type Store interface {
Get(ctx context.Context, key string) (Entry, error)
Set(ctx context.Context, entry Entry) error
Delete(ctx context.Context, key string) error
List(ctx context.Context) ([]Entry, error)
}
Store persists entries locally. Implementations must be safe for concurrent use.