secrets

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2026 License: Apache-2.0 Imports: 6 Imported by: 0 modules, 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

Overview

Package secrets parses and resolves value references (SPEC §3.6, T10):

literal:VALUE        a non-secret value, used as-is
env:VAR              an environment variable
keyring:SERVICE/KEY  an OS keyring item

Every reference needs an explicit scheme, so a secret can't be pasted in as a bare string by accident. Secrets themselves (auth credentials, and secrets on the command line, where other local users can read them) must be env: or keyring:. Errors name the reference, never the value.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNoScheme            = errors.New("value needs an explicit literal:, env: or keyring: prefix")
	ErrLiteralSecret       = errors.New("secrets must come from env: or keyring:, not a literal value")
	ErrInvalidRef          = errors.New("invalid reference")
	ErrNotFound            = errors.New("secret not found")
	ErrEmpty               = errors.New("secret is empty")
	ErrKeyring             = errors.New("keyring error")
	ErrKeyringItemNotFound = errors.New("keyring item not found")
)

Sentinel errors callers can match with errors.Is.

Functions

This section is empty.

Types

type KeyringGetter

type KeyringGetter interface {
	Get(service, key string) (string, error)
}

KeyringGetter reads an OS keyring item. It returns ErrKeyringItemNotFound for a missing item.

type OSKeyring

type OSKeyring struct{}

OSKeyring is the OS credential store: Windows Credential Manager, macOS Keychain or the Secret Service on Linux.

func (OSKeyring) Get

func (OSKeyring) Get(service, key string) (string, error)

Get reads an item.

func (OSKeyring) Set

func (OSKeyring) Set(service, key, value string) error

Set stores an item, replacing any existing value.

type Ref

type Ref struct {
	Scheme  Scheme
	Literal string
	Var     string
	Service string
	Key     string
}

Ref is a parsed reference. Only the fields for its Scheme are set.

func ParseRef

func ParseRef(s string) (Ref, error)

ParseRef parses a reference with an explicit scheme.

func ParseSecretRef

func ParseSecretRef(s string) (Ref, error)

ParseSecretRef parses a reference that must hold a secret: env: or keyring: only.

func (Ref) IsSecret

func (r Ref) IsSecret() bool

IsSecret reports whether the value is secret (env: or keyring:). Secret values are redacted wherever they appear (SPEC T11).

func (Ref) String

func (r Ref) String() string

String returns the reference in its parseable form. It never contains a resolved secret.

type Resolver

type Resolver struct {
	LookupEnv func(string) (string, bool)
	Keyring   KeyringGetter
}

Resolver resolves references.

func NewResolver

func NewResolver() *Resolver

NewResolver resolves against the process environment and the OS keyring.

func (*Resolver) Resolve

func (res *Resolver) Resolve(r Ref) (string, error)

Resolve returns the value r refers to. Missing and empty secrets are errors.

type Scheme

type Scheme int

Scheme says where a reference's value comes from.

const (
	Literal Scheme = iota + 1
	Env
	Keyring
)

Reference schemes.

Jump to

Keyboard shortcuts

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