secret

package
v0.0.0-...-0bec3fc Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2024 License: BSD-3-Clause Imports: 3 Imported by: 0

Documentation

Overview

Package secret defines an interface to a database storing secrets, such as passwords and API keys.

TODO(rsc): Consider adding a basic key: value text file format besides netrc.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DB

type DB interface {
	Get(name string) (secret string, ok bool)
	Set(name, secret string)
}

A DB is a secret database, which is a persistent map from names to secret values.

func Empty

func Empty() DB

Empty returns a read-only, empty secret database.

type Map

type Map map[string]string

A Map is a read-write, in-memory DB.

func (Map) Get

func (m Map) Get(name string) (secret string, ok bool)

Get returns the named secret.

func (Map) Set

func (m Map) Set(name, secret string)

Set adds a secret with the given name.

type ReadOnlyMap

type ReadOnlyMap map[string]string

A ReadOnlyMap is a read-only DB. Calling [Set] panics.

func Netrc

func Netrc() ReadOnlyMap

Netrc returns a read-only secret database initialized by the content of $HOME/.netrc, if it exists. A line in .netrc of the form

machine name login user password pass

causes Get("name") to return "user:pass". Lines later in .netrc take priority over lines earlier in .netrc.

If the environment $NETRC is set and non-empty, the file it names is used instead of $HOME/.netrc.

func (ReadOnlyMap) Get

func (m ReadOnlyMap) Get(name string) (secret string, ok bool)

Get returns the named secret.

func (ReadOnlyMap) Set

func (m ReadOnlyMap) Set(name, secret string)

Set panics.

Jump to

Keyboard shortcuts

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