bitwarden

package
v0.0.22 Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2026 License: Apache-2.0 Imports: 29 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

Index

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

func New(opts ...Opt) (_ *Manager, err error)

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

func (self *Manager) Delete(ctx context.Context, key string) (err error)

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

func (self *Manager) Describe(ctx context.Context, key, description string) (err error)

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

func (self *Manager) Expand(ctx context.Context, value string) (_ string, err error)

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

func (self *Manager) Get(ctx context.Context, key string) (_ json.RawMessage, err error)

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

func (self *Manager) Set(ctx context.Context, key string, value json.RawMessage) (err error)

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

func WithAccessToken(token string) Opt

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

func WithHTTPClient(client *http.Client) Opt

WithHTTPClient sets the HTTP client, in place of http.DefaultClient

func WithProject

func WithProject(id string) Opt

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

func WithServerURL(server string) Opt

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

func WithTracer(tracer trace.Tracer) Opt

WithTracer sets the tracer used for tracing operations

func WithURLs

func WithURLs(api, identity string) Opt

WithURLs sets the API and identity servers, such as https://api.bitwarden.eu and https://identity.bitwarden.eu for Bitwarden's EU cloud

Jump to

Keyboard shortcuts

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