secrets

package
v2.0.1 Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2026 License: MIT Imports: 29 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

Secret stores API keys and other variables come from, such as Bitwarden Secrets Manager and 1Password, and the environment each profile reads through them: its own .env and what its stores supply over this process's environment

Index

Constants

View Source
const (
	// Variables bound one by one to references in the store, such as op:// ones
	Mapped = "mapped"
	// Every secret of a project, each under its own name
	Bulk = "bulk"
)

How a store hands its secrets over

View Source
const FetchTimeout = 120 * time.Second

Longest one fetch of a store may take unless its timeout_seconds says otherwise

Variables

This section is empty.

Functions

func Action

func Action(name, tokenEnv string, existing map[string]string, override bool) string

What the next fetch would do with a variable a store hands over: skip_token for the store's own credential, skip_set for one set already that the store does not replace, override for one it does, export for the rest

func Encode

func Encode(entry Entry) map[string]any

{"secrets", "fetched_at"} object of an entry, fetched_at in seconds since the epoch

func Expand

func Expand(cfg *config.Config, text string) string

Text a person gave a setting of a store as the store reads it, each ${NAME} standing for the variable it names among those the profile has without its stores, as a fetch reads its settings; a reference to a variable that is not set stays as it is written

func Fingerprint

func Fingerprint(material string) string

SHA-256 prefix of credential material a cache is keyed by, never shown

func RemoveFile

func RemoveFile(path string)

Deletes a file, or a link where one stands, leaving a folder at the path alone

func Save

func Save(cfg *config.Config, settings ...Saved) error

Keeps the settings a store's own steps give, such as those its setup chose: each checked as a person's write of it is checked and found unlocked before any is written, so a refusal leaves the settings as they were, then each written in order. A setting given as the profile has it already, as a person wrote it, is not written at all, so the settings file keeps it as it holds it, references, comments and all; nor is a nil one the file holds nothing of. The caller fetches the stores again

func Version

func Version(ctx context.Context, binary string, env map[string]string) string

First line of what the program says of its version, "version unknown" when it says nothing or fails. A program run with the variables of this machine alone says the same of the same file, so what it said is kept until its file changes

func Which

func Which(name, path string) string

Program of the name on the search path as packages.Which finds it, empty when there is none; the answer stands for lookAgain, so the several reads of one page search the path once

func WriteJSON

func WriteJSON(path string, payload any) error

Writes a cache file only its owner reads, at once, its folder tightened to 0700

Types

type Applied

type Applied struct {
	Source string
	// The store's value wins over one the .env gains later, the store overriding and the variable not kept local
	Authoritative bool
}

Where one variable the stores set came from

type Cache

type Cache struct {
	// File name in the profile folder
	Name string
	// contains filtered or unexported fields
}

What a store fetched kept in this process and in a file of the profile folder, so a start within the ttl asks the store nothing

func (*Cache) Clear

func (c *Cache) Clear(dir string)

Forgets every entry, the file's too

func (*Cache) Lookup

func (c *Cache) Lookup(dir, key string, ttl time.Duration, read func() (Entry, bool)) (Entry, bool, error)

Fresh entry of the key from this process, else from the file, or from read when one is given, which this process keeps from then on

func (*Cache) Path

func (c *Cache) Path(dir string) string

File of the cache in the profile folder

func (*Cache) Read

func (c *Cache) Read(dir, key string, ttl time.Duration) (Entry, bool, error)

Fresh entry of the key in the file, false when it is another key's, stale, or no entry; an error naming the file only for bytes that are not text

func (*Cache) Remember

func (c *Cache) Remember(key string, entry Entry)

Keeps the entry in this process

func (*Cache) Store

func (c *Cache) Store(dir, key string, entry Entry, ttl time.Duration)

Keeps the entry in this process and in the file

func (*Cache) Write

func (c *Cache) Write(dir, key string, entry Entry, ttl time.Duration)

Writes the entry to the file, nothing when there is no ttl or the write fails

type Configurable

type Configurable interface {
	Unconfigured(cfg *config.Config) string
}

Store that fetches with settings of its own beyond its credential, such as the project a bulk store pulls: the key of the first of them the profile leaves empty, empty once it is configured

type Entry

type Entry struct {
	Secrets map[string]string
	Fetched time.Time
}

Secrets fetched once, with when

func Decode

func Decode(payload map[string]any) (Entry, bool)

Entry of a cache file's {"secrets", "fetched_at"} object, false when it is not one; only text values are kept

func (Entry) Fresh

func (e Entry) Fresh(ttl time.Duration) bool

Whether the entry is younger than ttl, never for no ttl

type Failure

type Failure string

Kind of failure of a fetch, which picks the fix a person is told

const (
	NotConfigured Failure = "not_configured"
	BinaryMissing Failure = "binary_missing"
	AuthFailed    Failure = "auth_failed"
	AuthExpired   Failure = "auth_expired"
	RefInvalid    Failure = "ref_invalid"
	Network       Failure = "network"
	EmptyValue    Failure = "empty_value"
	Timeout       Failure = "timeout"
	Internal      Failure = "internal"
)

func Classify

func Classify(text string, rules []Rule) Failure

Kind of a helper's failure by its text, internal when no rule matches

type Fetch

type Fetch struct {
	// Settings of the profile, read without the stores, so a fetch never waits on itself
	Config *config.Config
	// Variables the profile has without any store: its .env over this process's environment
	Env map[string]string
	// Nothing kept from an earlier ask stands in for asking: a fetch neither reads nor writes the caches of what the store holds, and a store
	// asked what it lacks asks again what it keeps of how it stands, keeping the new answer
	Fresh bool
}

One fetch of a store's secrets for a profile

type Forgetter

type Forgetter interface {
	Forget()
}

Store that keeps something of how it stands between the times it is asked what it lacks, such as what its program said of a sign-in, which it forgets as the profile turns it on or off or removes its token

type Live

type Live interface {
	Registrant
	Live(profile string) []Source
}

Registrant whose stores come and go as it runs, such as those the extensions of a profile offer: its Sources has none, and the stores it offers a profile are listed again on every read, one whose name, shape or scheme can't be used left out rather than refused as a mistake of the code. Listing reads no setting or variable and starts nothing, since the stores are listed while a variable is being looked up

type Needer

type Needer interface {
	// What keeps it from working for the profile, in a few words and as a sentence; empty when nothing does. A slow question it asks, such as
	// whether its program is signed in, may be answered as it was a moment ago, and is asked again when the fetch is fresh
	Needs(ctx context.Context, fetch Fetch) (short, sentence string)
}

Store that says what it lacks to fill anything besides what the settings it fetches with hold, such as its program or a sign-in

type Outcome

type Outcome struct{ Name, Action string }

What a fetch of a store does with one variable: export, override, skip_set, skip_token or unresolved; exported or overrode once set

type Output

type Output struct {
	Stdout, Stderr string
	Code           int
}

What a helper program printed and how it ended

func Run

func Run(ctx context.Context, argv []string, env map[string]string, timeout time.Duration, label, timedOut string, stdin io.Reader) (Output, error)

Runs a helper program with exactly the variables given, those of this machine alone for none, its output as text; a timeout fails with the message given, a program that would not start with the label

type Registrant

type Registrant interface {
	Sources() []Source
}

type Registry

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

func (*Registry) Host

func (r *Registry) Host() *Secrets

Host the registry is nested in, through which plugins fetch from other stores and read a profile's environment

func (*Registry) Live

func (r *Registry) Live(profile string) []Source

Stores the live registrants offer the profile now, those of the registries nested in this one among them

func (*Registry) Register

func (r *Registry) Register(registrant Registrant)

func (*Registry) Sources

func (r *Registry) Sources() []Source

Stores fixed once they are registered, those of the registries nested in this one among them

type Report

type Report struct {
	Sources []SourceReport
	// Values the stores set and where each came from, by variable
	Values  map[string]string
	Applied map[string]Applied
	// Variables two stores supplied, the first keeping it
	Conflicts []string
}

What a pass over every enabled store did for a profile

type Result

type Result struct {
	// Values by variable
	Secrets  map[string]string
	Warnings []string
	// Why it failed, empty when it did not
	Error string
	Kind  Failure
	// Helper program it ran
	Binary string
}

What one fetch got

func Failed

func Failed(text string, kind Failure) Result

Result failing with the error of the kind

func (Result) OK

func (r Result) OK() bool

type Rule

type Rule struct {
	Kind  Failure
	Words []string
}

Words of a helper's failure that say which kind it is, the first rule to match winning

type Saved

type Saved struct {
	Key   string
	Value any
}

One setting of a store that its own steps keep, such as the project Bitwarden loads, nil taking it out of the settings file

type Secrets

type Secrets struct {
	Registry
	// contains filtered or unexported fields
}

The secret stores and the environment of every profile

func New

func New(cfg *config.Config) *Secrets

func (*Secrets) Asked

func (h *Secrets) Asked(cfg *config.Config) []Source

Every store in the order a fetch asks them: those that fill named variables first, so a variable bound to a reference wins over one a store holds among all its secrets, then the others, each kind in its place in Ordered

func (*Secrets) Bind

func (h *Secrets) Bind(cfg *config.Config, name, variable, reference string) error

Fills the variable from the reference in the store, the reference checked as it reads before it is kept as it is written, then fetches the stores again; a reference the variable is filled from already, as it is written, leaves the settings as they are

func (*Secrets) Bindings

func (h *Secrets) Bindings(cfg *config.Config, name string) map[string]string

Variables a store that fills named ones binds to its references, each named as it is written and its reference as it is read, every ${NAME} in it standing for the variable it names: what a fetch asks the store for

func (*Secrets) Configured

func (h *Secrets) Configured(cfg *config.Config, source Source) (bool, string)

Whether the store has every setting it fetches with, its credential aside, and the key of the first one missing when it has not

func (*Secrets) Delete

func (h *Secrets) Delete(profile string) error

Forgets what the stores supplied the deleted profile and what it was told

func (*Secrets) Enabled

func (h *Secrets) Enabled(cfg *config.Config, name string) bool

Whether the profile turned the store on

func (*Secrets) Environ

func (h *Secrets) Environ(c *config.Config) map[string]string

Every variable of the profile

func (*Secrets) Existing

func (h *Secrets) Existing(cfg *config.Config) map[string]string

Variables the profile has without its stores, to judge what a store would replace

func (*Secrets) Export

func (h *Secrets) Export(c *config.Config, source string, values map[string]string)

Sets the variables for the profile as the store supplied them, over the .env and what was there, until its stores are fetched again: what a sync exports

func (*Secrets) Fetch

func (h *Secrets) Fetch(ctx context.Context, cfg *config.Config, source Source, fresh bool) Result

Fetches the store's secrets for the profile within its timeout, the variables it reads being the profile's without any store

func (*Secrets) Forget

func (h *Secrets) Forget(cfg *config.Config, name string) (bool, error)

Removes the token the store signs in with from the profile's keys file, then fetches the stores again; false when the keys file held none

func (*Secrets) Lookup

func (h *Secrets) Lookup(c *config.Config, name string) (string, bool)

Value of the variable for the profile: what its stores set, else its .env, else the .env beside the icebath program when the profile has none, else this process's, else its .op.env and the .env beside the program

func (*Secrets) Ordered

func (h *Secrets) Ordered(cfg *config.Config) []Source

Every store: those secrets.sources names first, in its order, then the others in the order they are registered. The stores are listed once and found by name in that list, each name being one store's alone

func (*Secrets) Origin

func (h *Secrets) Origin(c *config.Config, name string) string

Store that supplied the variable the profile reads, by its short name, empty for one of the .env or this process

func (*Secrets) Overrides

func (h *Secrets) Overrides(cfg *config.Config, name string) bool

Whether the store's values replace those the shell or the .env set already

func (*Secrets) Preview

func (h *Secrets) Preview(ctx context.Context, cfg *config.Config, name string, apply bool) ([]Outcome, []string, error)

Fetches the store now, neither reading nor writing its cache, and says what the next start does with each variable it holds and why a bound one could not be read. Apply sets those it would set for the profile until the stores are fetched again

func (*Secrets) Refresh

func (h *Secrets) Refresh(profile string)

Has the stores of a profile fetched again the next time a variable of it is read, for stores that came or went, such as those of an extension that started or stopped

func (*Secrets) Register

func (h *Secrets) Register(registrant Registrant)

Adds a registrant; a registry nested in the host reaches it through Host

func (*Secrets) Remedy

func (h *Secrets) Remedy(cfg *config.Config, spec Spec, kind Failure) string

Fix of a failure of the store, empty when there is none to tell, the variable of its credential named as its setting is written

func (*Secrets) Reorder

func (h *Secrets) Reorder(cfg *config.Config, names []string) error

Asks the stores in the order named, those not named after them in the order they are registered, then fetches them again; the order as it is written already leaves the settings as they are

func (*Secrets) Report

func (h *Secrets) Report(c *config.Config) Report

What the stores of the profile last did, fetched now when they have not been

func (*Secrets) Reset

func (h *Secrets) Reset(c *config.Config) Report

Fetches the stores of the profile again, the report of the fetch coming back

func (*Secrets) Serve

func (h *Secrets) Serve(teller Teller)

Asks the stores of every profile from now on, for a process that serves its own profiles: each profile's are fetched the first time a variable of it is read, and the person on the profile is told through teller what went wrong in that first fetch. Serving again changes nothing

func (*Secrets) Source

func (h *Secrets) Source(cfg *config.Config, name string) (Source, bool)

Store of the profile with the name

func (*Secrets) State

func (h *Secrets) State(ctx context.Context, cfg *config.Config, source Source) State

How the store stands for the profile: on or off, what it lacks, how many variables it fills, and its credential

func (*Secrets) States

func (h *Secrets) States(ctx context.Context, cfg *config.Config, fresh bool, pass func() Report) ([]Source, []State, Report)

Every store of the profile in the order they are asked with how each stands, and the report of the pass over them that pass makes, such as Report or Reset. The pass and what each store lacks are asked side by side, the variables the profile has without its stores read once for all of them; fresh has every store ask again what it would otherwise keep of how it stands

func (*Secrets) Stop

func (h *Secrets) Stop(profile string) error

Forgets what the stores supplied a profile before its folder moves to a new name, its stores read again under that one

func (*Secrets) Switch

func (h *Secrets) Switch(cfg *config.Config, name string, on bool) error

Turns the store on or off for the profile, then fetches the stores again so what it fills comes or goes at once

func (*Secrets) TokenEnv

func (h *Secrets) TokenEnv(cfg *config.Config, spec Spec) string

Variable holding the store's own credential for the profile

func (*Secrets) Unbind

func (h *Secrets) Unbind(cfg *config.Config, name, variable string) (bool, error)

Stops filling the variable from the store, then fetches the stores again; false when the store did not fill it

func (*Secrets) WrittenBindings

func (h *Secrets) WrittenBindings(cfg *config.Config, name string) map[string]string

Variables a store that fills named ones binds to its references, each reference exactly as a person wrote it, every ${NAME} kept: what a person is shown of them and what a change of one starts from, so one sent back as it is shown is the one the settings file holds

func (*Secrets) WrittenTokenEnv

func (h *Secrets) WrittenTokenEnv(cfg *config.Config, spec Spec) string

Variable holding the store's own credential for the profile as a person wrote its name, every ${NAME} kept: what a person is shown of it, where TokenEnv is the variable read

type Source

type Source interface {
	Spec() Spec
	// Resolves the store's secrets for the profile; a failure is a Result, never a panic
	Fetch(ctx context.Context, fetch Fetch) Result
}

Store of secrets a plugin brings

type SourceReport

type SourceReport struct {
	Name, Label string
	Result      Result
	Applied     []string
	// Variables it supplied that were kept: set already and not replaced, taken by an earlier store, the credential of a store, not names
	Existing, Claimed, Protected, Invalid []string
}

What one store did in a pass

type Sources

type Sources []Source

Sources fixed once they are registered

func (Sources) Sources

func (s Sources) Sources() []Source

type Spec

type Spec struct {
	// Name of its section, secrets.<name>, and of its subcommand
	Name string
	// Name in status lines, and the short one variables are said to come from
	Label, Short string
	Shape        string
	// Scheme of the references it resolves, such as op for op://, owned by one store only, a reference of it a person reads as an example,
	// and a sentence saying where a person finds one
	Scheme, Example, Find string
	// Setting of its section naming the variable that holds its own credential, and that variable unless the setting names another; no
	// store may overwrite it
	TokenSetting, TokenEnv string
	// Fix of a kind of failure, {name} standing for the store and {token_env} for the variable of its credential
	Hints map[Failure]string
}

What a store is, fixed for it

type State

type State struct {
	On bool
	// What keeps it from filling anything, in the few words a row says, such as Needs a token, and as the sentence its page opens on; empty
	// when nothing does
	Needs, Lacks string
	// Variables it fills: those bound to its references for a store that fills named ones, those its last fetch set for one that fills all
	// it holds
	Fills int
	// Variable of the credential it signs in with as its setting is written, every ${NAME} kept, and whether the profile holds one, for a
	// store that has one
	TokenEnv string
	TokenSet bool
}

How a store stands for a profile

type Teller

type Teller interface {
	TellIn(profile, text string)
}

Where the person on a profile is told something once: a window on the profile shows it, a command of it prints it as it ends

Directories

Path Synopsis
Page of Secret stores in the settings menu: the stores with how each stands, the page of each with turning it on or off, setting it up, the variables it fills and its options, the order they are asked in, and the options every store shares
Page of Secret stores in the settings menu: the stores with how each stands, the page of each with turning it on or off, setting it up, the variables it fills and its options, the order they are asked in, and the options every store shares
The secrets command: the subcommands of each secret store, which the stores register, and what every store shares: how each stands, turning one on or off, and the order they are asked in
The secrets command: the subcommands of each secret store, which the stores register, and what every store shares: how each stands, turning one on or off, and the order they are asked in

Jump to

Keyboard shortcuts

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