Documentation
¶
Index ¶
- type Manager
- func (self *Manager) Delete(ctx context.Context, key string) (err error)
- func (self *Manager) Describe(ctx context.Context, key, description string) (err error)
- func (self *Manager) Expand(ctx context.Context, value string) (_ string, err error)
- func (self *Manager) Get(ctx context.Context, key string) (_ json.RawMessage, err error)
- func (self *Manager) List(ctx context.Context) (_ []credential.Credential, err error)
- func (self *Manager) Set(ctx context.Context, key string, value json.RawMessage) (err error)
- type Opt
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager stores credentials as secrets in Bitwarden Secrets Manager, one for each key, which are encrypted and decrypted here with the organization's key, as Bitwarden is end-to-end encrypted
func New ¶
New returns a manager for credentials in Bitwarden Secrets Manager, for a machine account's access token, from BWS_ACCESS_TOKEN or WithAccessToken. The server is Bitwarden's US cloud, unless it's set with BWS_SERVER_URL, WithServerURL or WithURLs. It logs in when it's first used.
func (*Manager) Delete ¶
Delete deletes the key's secret, and returns ErrNotFound when there isn't one, or ErrConflict when there is more than one, rather than delete them all
func (*Manager) Describe ¶
Describe sets the description of the key's secret, which is its note, encrypted, as its key and value are, or removes it, when it's empty, without changing its value, and returns ErrNotFound when there isn't one, or ErrConflict when there's more than one
func (*Manager) Expand ¶
Expand replaces each $KEY or ${KEY} placeholder in the value with the credential for the key, which must be a string, or with the environment variable, with WithEnv, when there is no secret for it. Keys containing "-" must use the ${KEY} form. The secrets are listed once, and each is read once, however many times it's used. Returns an error, rather than a partly expanded value, if a placeholder is not a valid key, or its credential does not exist or is not a string.
func (*Manager) Get ¶
Get returns the credential for the key, as JSON, or the environment variable's value, with WithEnv, when there is no secret for it. A secret which isn't JSON is returned as a JSON string. Returns an error if the key isn't valid, or the credential doesn't exist.
func (*Manager) List ¶
func (self *Manager) List(ctx context.Context) (_ []credential.Credential, err error)
List returns the stored credentials, in key order, with their descriptions, which are their notes, without their values: the secrets the machine account can read, whose keys are valid. A key which is on more than one secret is listed for each of them.
func (*Manager) Set ¶
Set stores the credential for the key, replacing the value of its secret, or creating the secret in the projects set with WithProject when there isn't one. A JSON string is stored without its quotes, so it reads as plain text in Bitwarden and with bws, and other JSON is stored as it is. Returns an error if the key isn't valid, the value isn't JSON, or there is more than one secret with the key.
type Opt ¶
type Opt func(*opt) error
Opt is a functional option for the Bitwarden credential manager
func WithAccessToken ¶
WithAccessToken sets the machine account's access token, in place of BWS_ACCESS_TOKEN
func WithEnv ¶
func WithEnv() Opt
WithEnv reads a credential from the environment when there is no secret for it, so $KEY is expanded from the environment variable KEY. The environment is read-only, so credentials are still stored as secrets.
func WithHTTPClient ¶
WithHTTPClient sets the HTTP client, in place of http.DefaultClient
func WithProject ¶
WithProject adds a project, by its identifier, which new secrets are created in. A machine account can usually only create secrets in a project it can write to.
func WithServerURL ¶
WithServerURL sets the server of a self-hosted Bitwarden, in place of BWS_SERVER_URL, whose API is at /api and identity server at /identity
func WithTracer ¶
WithTracer sets the tracer used for tracing operations
func WithURLs ¶
WithURLs sets the API and identity servers, such as https://api.bitwarden.eu and https://identity.bitwarden.eu for Bitwarden's EU cloud