Documentation
¶
Overview ¶
Package vault is the store of secrets that the controller resolves a secret://<vault>/<key> reference from. A vault has a name and a type. A type registers with its name, a constructor and the Go struct of its config block, so a different store, such as HashiCorp Vault, is a type that plugs in. osapi ships one type, nats, in package natsvault.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrNotFound = errors.New("secret not found")
ErrNotFound is the error of a key that a vault does not have.
Functions ¶
func CheckKey ¶
CheckKey is an error when key is not a name that a vault takes: 1 to 128 letters, digits, - or _, such as registry-token.
func IsReference ¶
IsReference reports whether s starts with secret.Scheme. A value that does is a reference, and never a literal value.
func Unregister ¶
func Unregister( name string, )
Unregister removes the type name. A test that registers a type removes it with this.
Types ¶
type Env ¶
type Env struct {
NATS *natsclient.Client
// Bucket is the KV bucket of nats.secrets.bucket, with the namespace,
// such as osapi-secrets. Empty when the config names none.
Bucket string
FS avfs.VFS
// LookupEnv reads an environment variable, as os.LookupEnv does.
LookupEnv func(key string) (string, bool)
}
Env is what the controller gives each type when it opens a vault: the NATS connection, the secrets bucket with its namespace, the file system and the environment.
type Meta ¶
type Meta struct {
// Key is the name of the key in its vault, such as registry-token.
Key string `json:"key"`
// Version is 1 for the first value of the key, and one more for each
// Put after it.
Version uint64 `json:"version"`
// Changed is when the last Put occurred.
Changed time.Time `json:"changed"`
// By is who did the last Put, from Actor. Empty when it is not known.
By string `json:"by,omitempty"`
}
Meta is what a vault tells about a key, without its value.
type Reference ¶
Reference names a key in a vault: secret://<vault>/<key>.
func ParseReference ¶
ParseReference is the reference s: the name of a vault, then its key.
type Set ¶
type Set struct {
// contains filtered or unexported fields
}
Set is the vaults of the controller, by name, each with its spec.
func Open ¶
Open makes a vault of each spec, from its registered type, in the order of specs. A spec with a type that is not registered, a config block that does not decode, a check that fails or a vault that does not open is an error that names the vault.
type Spec ¶
type Spec struct {
Name string `` /* 155-byte string literal not displayed */
Type string `mapstructure:"type" validate:"required" doc:"The type of the vault, such as nats."`
Targets []string `` /* 163-byte string literal not displayed */
KeyFile string `` /* 189-byte string literal not displayed */
KeyEnv string `` /* 175-byte string literal not displayed */
Config map[string]any `` /* 135-byte string literal not displayed */
}
Spec is one vault of controller.secrets.vaults: its name, its type, the targets that its secrets can go to, the key of a type that encrypts, and the config block of its type.
type Type ¶
type Type struct {
// Name is what the type of a vault names, such as nats.
Name string
// Doc says what the type is, in one line.
Doc string
// Config is the struct of the config block. Each field has a
// mapstructure name, a doc tag and its validate rules.
Config reflect.Type
// contains filtered or unexported fields
}
Type is a kind of vault, such as nats: its name, what it is, the Go struct of its config block, and how to make a vault of it. Define makes one, and Register adds it to the types that the controller and the config check know.
func Define ¶
func Define[C any]( name string, doc string, check func(spec Spec) error, build func(ctx context.Context, env Env, spec Spec, cfg C) (Vault, error), ) Type
Define is a type of vault: name, what it is in one line, and build, which makes a vault from its spec and its config block as a C. check, when it is not nil, checks the spec of a vault of the type, such as that it names its key. The config check runs it, and Open runs it before build.
func Register ¶
Register adds t to the types that the controller and the config check know, and returns it. Two types with one name are a mistake in the code, so it panics.
func TypeOf ¶
TypeOf is the registered type of spec, or an error that names the types that there are.
type Vault ¶
type Vault interface {
// Name is the name of the vault in the config, such as default.
Name() string
// Get is the value of key and its metadata. A key that is not there
// is ErrNotFound.
Get(ctx context.Context, key string) ([]byte, Meta, error)
// Put writes value as the next version of key. Actor(ctx) is who
// changed it.
Put(ctx context.Context, key string, value []byte) (Meta, error)
// Delete deletes key. A key that is not there is ErrNotFound.
Delete(ctx context.Context, key string) error
// List is the metadata of each key, sorted by key. It has no value.
List(ctx context.Context) ([]Meta, error)
}
Vault is a store of secrets, by key. A type, such as nats, makes it from the config of the vault. The controller resolves each reference through one. A value is []byte until secret.Value replaces it (osapi #1240).
Directories
¶
| Path | Synopsis |
|---|---|
|
Package mocks provides mock implementations for testing.
|
Package mocks provides mock implementations for testing. |
|
Package natsvault is the nats type of vault, the one that osapi ships.
|
Package natsvault is the nats type of vault, the one that osapi ships. |
|
mocks
Package mocks provides mock implementations for testing.
|
Package mocks provides mock implementations for testing. |