file

package
v0.0.23 Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2026 License: Apache-2.0 Imports: 22 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Manager

type Manager struct {
	sync.Mutex
	// contains filtered or unexported fields
}

Manager stores credentials in files in a directory, one for each key, encrypted with a passphrase. Each file is a record: the passphrase version, the credential's description, which isn't encrypted, and the encrypted credential.

func New

func New(path string, opts ...Opt) (_ *Manager, err error)

New returns a manager for credentials in the directory at the path. The directory is created when it doesn't exist, its permissions are set so that only its owner can access it, and it must be writable.

func (*Manager) Decrypt

func (self *Manager) Decrypt(ctx context.Context, key, passphrase string) (_ json.RawMessage, err error)

Decrypt returns the credential for the key, as JSON, when the passphrase is the one it was encrypted with, compared in constant time, or ErrForbidden when it isn't

func (*Manager) Delete

func (self *Manager) Delete(ctx context.Context, key string) (err error)

Delete removes the file for the key, and returns ErrNotFound when there isn't one

func (*Manager) Describe

func (self *Manager) Describe(ctx context.Context, key, description string) (err error)

Describe sets the description of the key's credential, in its file, which isn't encrypted, as a description isn't secret, so it needs no passphrase, or removes it, when it's empty, and returns ErrNotFound when there's no credential

func (*Manager) Expand

func (self *Manager) Expand(ctx context.Context, value string) (_ string, err error)

Expand replaces each $KEY or ${KEY} placeholder in the value with the credential for the key, which must be a string, or with the environment variable, with WithEnv, when there is no file for it. Keys containing "-" must use the ${KEY} form. Returns an error, rather than a partly expanded value, if a placeholder is not a valid key, or its credential does not exist or is not a string.

func (*Manager) Get

func (self *Manager) Get(ctx context.Context, key string) (_ json.RawMessage, err error)

Get returns the credential for the key, as JSON, or the environment variable's value, with WithEnv, when there is no file for it. Returns an error if the key isn't valid, or the credential doesn't exist.

func (*Manager) List

func (self *Manager) List(ctx context.Context) (_ []credential.Credential, err error)

List returns the stored credentials, in key order, with their descriptions, without reading or decrypting their values. Files whose names aren't keys, such as temporary files, aren't listed.

func (*Manager) Path

func (self *Manager) Path() string

Path returns the directory the credentials are stored in

func (*Manager) Rotate

func (self *Manager) Rotate(ctx context.Context, key string) (err error)

Rotate re-encrypts the file for the key with the latest passphrase, keeping its description, and returns ErrNotModified when it already uses it, or ErrNotFound when there isn't one

func (*Manager) Set

func (self *Manager) Set(ctx context.Context, key string, value json.RawMessage) (err error)

Set encrypts the credential with the latest passphrase, and writes it to the key's file, keeping its description, replacing any credential with the key. Returns an error if the key isn't valid, the value isn't JSON, or there is no passphrase.

type Opt

type Opt func(*opt) error

Opt is a functional option for the file credential manager

func WithEnv

func WithEnv() Opt

WithEnv reads a credential from the environment when it isn't stored in a file, so $KEY is expanded from the environment variable KEY. The environment is read-only, so credentials are still stored in files.

func WithPassphrase

func WithPassphrase(version uint64, passphrase string) Opt

WithPassphrase registers a passphrase for a passphrase version. Credentials are encrypted with the latest version, and decrypted with the version they were encrypted with. Versions are uint64 and passphrases must be non-empty.

func WithTracer

func WithTracer(tracer trace.Tracer) Opt

WithTracer sets the tracer used for tracing operations

Jump to

Keyboard shortcuts

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