secrets

package
v0.8.5 Latest Latest
Warning

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

Go to latest
Published: Oct 26, 2026 License: Apache-2.0 Imports: 14 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

Overview

Package secrets keeps Blitz's secrets (API keys) out of its settings files: in the macOS Keychain, in the Secret Service on Linux (GNOME Keyring, KWallet), or, where neither is available, in an owner-only file beside the settings. A settings file refers to a stored secret as "keychain:<name>" (Ref); config resolves the reference when it loads.

Index

Constants

View Source
const (
	AnyScope      = ""
	OnlyGlobal    = "global"
	OnlyWorkspace = "workspace"
)

The scopes a placeholder can name: none (the workspace's, else the global one), only the global one, or only the workspace's.

View Source
const GlobalScope = "global"

GlobalScope is the scope of secrets every workspace sees.

View Source
const RefPrefix = "keychain:"

RefPrefix marks a settings value that names a stored secret.

View Source
const Service = "dev.blitz"

Service is the name secrets are stored under (the keychain item's service, the Secret Service attribute).

Variables

View Source
var ErrNotFound = errors.New("no such secret")

ErrNotFound means no secret is stored under the name.

Functions

func Expand added in v0.7.1

func Expand(text string, lookup func(scope, key string) (string, bool)) (string, []string)

Expand puts each placeholder in text's place with its value, as lookup finds it for the scope the placeholder names (AnyScope, OnlyGlobal or OnlyWorkspace), and returns the values used (for the redactor). One lookup doesn't find is left as written.

func HasPlaceholders added in v0.7.1

func HasPlaceholders(text string) bool

HasPlaceholders reports whether text names a secret.

func ParseRef

func ParseRef(v string) (string, bool)

ParseRef returns the secret a settings value names, if it names one.

func Ref

func Ref(name string) string

Ref is the settings value that names the secret name.

func SetDefault

func SetDefault(s Store)

SetDefault replaces the store Default returns (tests, and the service once it knows its settings directory).

func URN added in v0.7.1

func URN(scope, key string) string

URN is the stored name of the secret key in scope.

func ValidKey added in v0.7.1

func ValidKey(key string) bool

ValidKey reports whether key can name a secret: letters, digits, _, . and -, up to 64.

Types

type Entry added in v0.7.1

type Entry struct {
	Key     string
	Updated time.Time
}

Entry is a secret as listed: its key and when its value was last set.

type FileStore

type FileStore struct {
	Path string
	// contains filtered or unexported fields
}

FileStore keeps secrets in a TOML file.

func (*FileStore) Delete

func (f *FileStore) Delete(name string) error

Delete removes name's secret; a missing one isn't an error.

func (*FileStore) Get

func (f *FileStore) Get(name string) (string, error)

Get returns the secret stored under name, or ErrNotFound.

func (*FileStore) Kind

func (f *FileStore) Kind() string

Kind names the store and its file.

func (*FileStore) Set

func (f *FileStore) Set(name, value string) error

Set stores value under name, rewriting the file atomically.

type Memory

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

Memory keeps secrets in memory, for tests.

func (*Memory) Delete

func (s *Memory) Delete(name string) error

Delete removes name's secret; a missing one isn't an error.

func (*Memory) Get

func (s *Memory) Get(name string) (string, error)

Get returns the secret stored under name, or ErrNotFound.

func (*Memory) Kind

func (s *Memory) Kind() string

Kind is "memory".

func (*Memory) Set

func (s *Memory) Set(name, value string) error

Set stores value under name.

type Store

type Store interface {
	// Kind says where secrets go, for people ("macOS Keychain").
	Kind() string
	Get(name string) (string, error)
	Set(name, value string) error
	Delete(name string) error
}

Store keeps secrets by name.

func Default

func Default(dir string) Store

Default is this machine's store: the Keychain on macOS, the Credential Manager on Windows, the Secret Service on Linux when secret-tool can reach one, else a file in dir (the settings directory).

type Vault added in v0.7.1

type Vault struct {
	Store Store
	Index string
}

Vault keeps the user's secrets in Store, their names in the index file Index.

func (Vault) Delete added in v0.7.1

func (v Vault) Delete(scope, key string) error

Delete removes scope's secret key (a missing one isn't an error).

func (Vault) List added in v0.7.1

func (v Vault) List(scope string) ([]Entry, error)

List is scope's secrets, by key.

func (Vault) Lookup added in v0.7.1

func (v Vault) Lookup(scope, key string) (string, bool)

Lookup is the secret key as a workspace in scope sees it: its own, else the global one.

func (Vault) Resolve added in v0.7.1

func (v Vault) Resolve(workspaceScope string) func(scope, key string) (string, bool)

Resolve is a lookup for Expand in a workspace's scope: AnyScope tries the workspace's own, then the global one; OnlyGlobal and OnlyWorkspace only theirs.

func (Vault) Set added in v0.7.1

func (v Vault) Set(scope, key, value string) error

Set stores value as scope's secret key.

Jump to

Keyboard shortcuts

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