secrets

package
v0.182.2 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: 12 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 keeps account passwords out of the database: in the OS keychain (macOS login keychain, Windows Credential Manager, Secret Service), else a file only this user can read.

Index

Constants

This section is empty.

Variables

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

ErrNotFound is returned when no secret is stored for an account.

Functions

This section is empty.

Types

type Fallback

type Fallback struct {
	Primary Store
	File    *File
}

Fallback keeps secrets in the OS keychain and, where there is none (a Linux box without a Secret Service), in a file only this user can read.

func (Fallback) Delete

func (f Fallback) Delete(id int64) error

Delete removes from both.

func (Fallback) Get

func (f Fallback) Get(id int64) (string, error)

Get reads from the keychain, then the file.

func (Fallback) Set

func (f Fallback) Set(id int64, secret string) error

Set writes to the keychain, or to the file when the keychain refuses.

type File

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

File is a JSON map of secrets in a 0600 file.

func (*File) Delete

func (f *File) Delete(id int64) error

Delete removes a secret.

func (*File) Get

func (f *File) Get(id int64) (string, error)

Get reads a secret.

func (*File) Set

func (f *File) Set(id int64, secret string) error

Set writes a secret.

type Keychain

type Keychain struct{}

Keychain is the OS keychain through go-keyring: Windows Credential Manager and Secret Service. Not used on macOS, where go-keyring runs `security` without naming the keychain file (ADR-039's dialog risk); MacKeychain is.

func (Keychain) Delete

func (Keychain) Delete(id int64) error

Delete removes a secret; a missing one is not an error.

func (Keychain) Get

func (Keychain) Get(id int64) (string, error)

Get reads a secret.

func (Keychain) Set

func (Keychain) Set(id int64, secret string) error

Set writes a secret.

type MacKeychain added in v0.116.0

type MacKeychain struct {
	Path string        // the login keychain file
	Run  secret.Runner // nil runs /usr/bin/security; tests replace it
}

MacKeychain keeps each password as a generic password in the user's login keychain through internal/secret, which names the keychain file on every call, so no call can open a dialog. Items keep go-keyring's service and account, so a password saved by an earlier build is found.

func (MacKeychain) Delete added in v0.116.0

func (k MacKeychain) Delete(id int64) error

Delete removes a secret; a missing one is not an error.

func (MacKeychain) Get added in v0.116.0

func (k MacKeychain) Get(id int64) (string, error)

Get reads a secret, decoding one go-keyring wrote.

func (MacKeychain) Set added in v0.116.0

func (k MacKeychain) Set(id int64, v string) error

Set writes a secret.

type Memory

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

Memory is an in-process store for tests and previews; it never touches the OS.

func (*Memory) Delete

func (m *Memory) Delete(id int64) error

Delete removes a secret.

func (*Memory) Get

func (m *Memory) Get(id int64) (string, error)

Get reads a secret.

func (*Memory) Set

func (m *Memory) Set(id int64, secret string) error

Set writes a secret.

type Store

type Store interface {
	Get(accountID int64) (string, error)
	Set(accountID int64, secret string) error
	Delete(accountID int64) error
}

Store keeps one secret per account.

func Default added in v0.116.0

func Default(dataDir string) Store

Default is where Mail keeps passwords: on macOS the login keychain when its file exists, elsewhere the OS keychain, with the 0600 file behind either; only the file when CAPROCK_SECRET_STORE=file or there is no login keychain. Nothing runs until the first password is read or written: an unused Mail starts no process.

Jump to

Keyboard shortcuts

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