Documentation
¶
Overview ¶
Package credential stores secrets in the keyring of the operating system and falls back to files only the user can read where the keyring is unavailable.
Index ¶
Constants ¶
const ( // DefaultService is the keyring service of a [Store] without [WithService]. DefaultService = "nctl" // DefaultTimeout bounds a keyring operation of a [Store] without [WithTimeout]. DefaultTimeout = 10 * time.Second )
Variables ¶
var ( // ErrNotFound is returned when a store holds no secret for a key. // It matches [fs.ErrNotExist]. ErrNotFound = fmt.Errorf("credential not found: %w", fs.ErrNotExist) // so the store cannot tell whether it holds a secret. ErrUnavailable = errors.New("keyring unavailable") )
Functions ¶
This section is empty.
Types ¶
type FallbackHandler ¶
FallbackHandler is called with the path of the file and the error of the keyring when a secret is written to a file because the keyring failed. created is true if the file did not exist before, so the secret of the key is in plain text for the first time.
type Option ¶
type Option func(*Store)
Option configures a Store.
func WithFallbackHandler ¶
func WithFallbackHandler(handler FallbackHandler) Option
WithFallbackHandler sets the handler called whenever a secret is written to a file because the keyring failed. It is not called for a store using WithInsecure.
func WithInsecure ¶
WithInsecure makes the store use files only and never touch the keyring.
func WithNamespace ¶
WithNamespace prefixes the names of the keyring entries, so stores of different kinds of secrets can share a service.
func WithService ¶
WithService sets the keyring service holding the secrets, DefaultService by default.
func WithTimeout ¶
WithTimeout bounds each keyring operation, which can hang while the keyring waits for an unlock prompt nobody answers. It is DefaultTimeout by default.
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
Store keeps secrets by key in the keyring of the operating system or, where the keyring is unavailable, in files below a directory.
A file exists only while it holds the newest secret of its key, as writing a secret to the keyring removes its file. Reads therefore prefer the file, which also picks up secrets written before the keyring was used.
func (*Store) Delete ¶
Delete removes the secret of key from both the file and the keyring. It returns ErrNotFound if neither held it. If the keyring cannot be reached, Delete succeeds when it removed the file, which held the newest secret, and otherwise returns an error wrapping ErrUnavailable.
func (*Store) Get ¶
Get returns the secret of key. It returns ErrNotFound if neither the file nor the keyring holds it, and an error wrapping ErrUnavailable if there is no file and the keyring cannot be reached.