vaultwarden

package
v0.0.0-...-9eed10d Latest Latest
Warning

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

Go to latest
Published: Jun 27, 2026 License: MIT Imports: 26 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

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

Functions

This section is empty.

Types

type APIError

type APIError struct {
	StatusCode int
	Body       string
}

APIError represents a non-successful HTTP response from Vaultwarden.

func (*APIError) Error

func (e *APIError) Error() string

type Client

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

Client is a reusable Vaultwarden API client with token caching.

func NewClient

func NewClient(cfg Config, opts ...Option) (*Client, error)

NewClient creates a Vaultwarden client with validated configuration.

func (*Client) Authenticate

func (c *Client) Authenticate(ctx context.Context) error

Authenticate obtains and caches a valid token.

func (*Client) Do

func (c *Client) Do(ctx context.Context, method, path string, requestBody any, responseBody any) error

Do sends a JSON request with bearer authentication.

func (*Client) Get

func (c *Client) Get(ctx context.Context, path string, responseBody any) error

Get performs a GET request.

func (*Client) GetDecryptedSecretByID

func (c *Client) GetDecryptedSecretByID(ctx context.Context, itemID string) (Secret, error)

GetDecryptedSecretByID returns one decrypted secret by item ID.

func (*Client) GetSecretByID

func (c *Client) GetSecretByID(ctx context.Context, itemID string) (Secret, error)

GetSecretByID returns one raw secret by item ID.

func (*Client) ListDecryptedSecrets

func (c *Client) ListDecryptedSecrets(ctx context.Context) ([]Secret, error)

ListDecryptedSecrets fetches sync data and decrypts secret fields with the master password.

func (*Client) ListDecryptedSecretsByOrganization

func (c *Client) ListDecryptedSecretsByOrganization(ctx context.Context, organizationID string) ([]Secret, error)

ListDecryptedSecretsByOrganization returns decrypted secrets filtered by organization ID.

func (*Client) ListSecrets

func (c *Client) ListSecrets(ctx context.Context) ([]Secret, error)

ListSecrets fetches and normalizes secrets from the default Vaultwarden sync endpoint.

func (*Client) ListSecretsByOrganization

func (c *Client) ListSecretsByOrganization(ctx context.Context, organizationID string) ([]Secret, error)

ListSecretsByOrganization returns raw secrets filtered by organization ID.

func (*Client) Post

func (c *Client) Post(ctx context.Context, path string, requestBody any, responseBody any) error

Post performs a POST request.

type Config

type Config struct {
	BaseURL          string
	TokenEndpoint    string
	ClientID         string
	ClientSecret     string
	MasterPassword   string
	Username         string
	Password         string
	Scope            string
	GrantType        string
	DeviceIdentifier string
	DeviceName       string
	DeviceType       string
	Timeout          time.Duration
}

Config contains connector settings for Vaultwarden authentication and API calls.

func LoadConfigFromEnv

func LoadConfigFromEnv() (Config, error)

LoadConfigFromEnv loads connector configuration from environment variables.

func (Config) Validate

func (c Config) Validate() error

Validate validates mandatory fields and configuration values.

type Option

type Option func(*Client) error

Option configures client initialization.

func WithHTTPClient

func WithHTTPClient(httpClient *http.Client) Option

WithHTTPClient injects a custom HTTP client.

type Secret

type Secret struct {
	ID             string            `json:"id"`
	Name           string            `json:"name"`
	OrganizationID string            `json:"organization_id,omitempty"`
	Username       string            `json:"username,omitempty"`
	Password       string            `json:"password,omitempty"`
	TOTP           string            `json:"totp,omitempty"`
	TOTPCode       string            `json:"totp_code,omitempty"`
	SSHPublicKey   string            `json:"ssh_public_key,omitempty"`
	SSHPrivateKey  string            `json:"ssh_private_key,omitempty"`
	SSHFingerprint string            `json:"ssh_fingerprint,omitempty"`
	CardholderName string            `json:"cardholder_name,omitempty"`
	CardBrand      string            `json:"card_brand,omitempty"`
	CardNumber     string            `json:"card_number,omitempty"`
	CardExpMonth   string            `json:"card_exp_month,omitempty"`
	CardExpYear    string            `json:"card_exp_year,omitempty"`
	CardCode       string            `json:"card_code,omitempty"`
	Notes          string            `json:"notes,omitempty"`
	Fields         map[string]string `json:"fields,omitempty"`
}

Secret represents a normalized secret extracted from Vaultwarden sync data.

type Token

type Token struct {
	AccessToken string    `json:"access_token"`
	TokenType   string    `json:"token_type"`
	ExpiresIn   int       `json:"expires_in"`
	Scope       string    `json:"scope,omitempty"`
	ObtainedAt  time.Time `json:"-"`
}

Token represents an OAuth2-like access token response.

func (Token) Expired

func (t Token) Expired(skew time.Duration) bool

Expired reports whether a token is expired using an expiration skew.

Jump to

Keyboard shortcuts

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