secrets

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Sep 7, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package secrets provides named credential sources and a value type that redacts formatted output.

Design

Secret redacts fmt, text and JSON serialization; Bytes provides explicit access to the value. Static, Env, Dir and Chain providers support injected values, normalized environment names, bounded rooted files and fallback. Dir uses os.Root so names cannot escape its configured directory.

Redaction reduces accidental disclosure through formatting; it does not protect values after explicit extraction or encrypt memory. storage/crypt provides sealing for selected persisted values.

References

Index

Constants

View Source
const Redacted = "[redacted]"

Redacted is what a Secret prints as.

Variables

View Source
var ErrName = errors.New("secrets: invalid name")

ErrName is returned for names a provider cannot map safely.

View Source
var ErrNotFound = errors.New("secrets: not found")

ErrNotFound is returned when a provider has no value for a name.

Functions

This section is empty.

Types

type Chain

type Chain []Provider

Chain queries providers in order and returns the first hit.

func (Chain) Get

func (c Chain) Get(ctx context.Context, name string) (Secret, error)

Get implements Provider. Errors other than ErrNotFound stop the chain.

type Dir

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

Dir reads each secret from a file named after it inside one directory, the layout Docker and Kubernetes secrets mount. Trailing newlines are trimmed. Names must not contain path separators.

func NewDir

func NewDir(path string) (*Dir, error)

NewDir opens the directory.

func (*Dir) Close

func (d *Dir) Close() error

Close releases the directory handle.

func (*Dir) Get

func (d *Dir) Get(_ context.Context, name string) (Secret, error)

Get implements Provider.

type Env

type Env struct {
	Prefix string
	// Lookup defaults to os.LookupEnv.
	Lookup func(string) (string, bool)
}

Env reads secrets from environment variables. The name is upper-cased with dots and dashes replaced by underscores, then prefixed.

func (Env) Get

func (e Env) Get(_ context.Context, name string) (Secret, error)

Get implements Provider.

func (Env) Key

func (e Env) Key(name string) string

Key returns the variable name for a secret name.

type Provider

type Provider interface {
	Get(ctx context.Context, name string) (Secret, error)
}

Provider resolves secrets by name.

type Secret

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

Secret holds a credential. Its String, GoString, Format, MarshalJSON, and MarshalText outputs are always Redacted; use Bytes to get the value.

func New

func New(b []byte) Secret

New wraps a value (copied).

func (Secret) Bytes

func (s Secret) Bytes() []byte

Bytes returns a copy of the value.

func (Secret) Equal

func (s Secret) Equal(o Secret) bool

Equal compares in constant time.

func (Secret) Format

func (Secret) Format(f fmt.State, _ rune)

Format implements fmt.Formatter so every verb prints the constant.

func (Secret) GoString

func (Secret) GoString() string

GoString implements fmt.GoStringer with a constant.

func (Secret) IsZero

func (s Secret) IsZero() bool

IsZero reports whether the secret is empty.

func (Secret) MarshalJSON

func (Secret) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler with the constant.

func (Secret) MarshalText

func (Secret) MarshalText() ([]byte, error)

MarshalText implements encoding.TextMarshaler with the constant.

func (Secret) String

func (Secret) String() string

String implements fmt.Stringer with a constant.

type Static

type Static map[string][]byte

Static serves secrets from memory, for tests and embedded config.

func (Static) Get

func (s Static) Get(_ context.Context, name string) (Secret, error)

Get implements Provider.

Jump to

Keyboard shortcuts

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