secrets

package
v1.0.0 Latest Latest
Warning

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

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

Documentation

Overview

Package secrets resolves SecretRef values (e.g. "${VAR}", "keychain://name", "vault://...") to their cleartext form via pluggable backends.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AWSSM

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

AWSSM resolves "awssm://..." refs from AWS Secrets Manager, reusing the standard AWS credential chain (env / shared config / instance role) — the same chain the S3 storage backend uses, so no separate credential wiring.

Ref shapes:

  • awssm://<secret-id> → the secret's whole SecretString
  • awssm://<secret-id>#<key> → field <key> of the secret's JSON object

The #<key> selector matters because Secrets Manager secrets are commonly JSON (e.g. {"username":...,"password":...}); without it a ref would resolve to the entire JSON blob rather than the one field a DSN needs.

func NewAWSSM

func NewAWSSM(ctx context.Context, region string) (*AWSSM, error)

NewAWSSM builds an AWS Secrets Manager backend. region may be empty to defer to the credential chain's region. Construction is lazy-free (the SDK config load happens here), so callers build it once at startup.

func (*AWSSM) Resolve

func (a *AWSSM) Resolve(ref string) (string, error)

func (AWSSM) Scheme

func (AWSSM) Scheme() string

type Backend

type Backend interface {
	Scheme() string // "env", "keychain", "vault", "" for passthrough
	Resolve(ref string) (string, error)
}

Backend resolves SecretRef values it claims via Scheme().

type Env

type Env struct{}

Env resolves "env:VAR" refs to os.Getenv("VAR").

func (Env) Resolve

func (Env) Resolve(ref string) (string, error)

func (Env) Scheme

func (Env) Scheme() string

type Keychain

type Keychain struct{}

Keychain resolves "keychain://..." refs from the OS credential store — macOS Keychain, Windows Credential Manager, or the Linux Secret Service — via go-keyring, which abstracts all three behind one call.

Ref shapes:

  • keychain://<service>/<account> → keyring.Get(service, account)
  • keychain://<account> → keyring.Get("siphon", account)

The two-segment form addresses an arbitrary stored credential; the short form is the common case (a siphon-owned secret named <account>).

func (Keychain) Resolve

func (Keychain) Resolve(ref string) (string, error)

func (Keychain) Scheme

func (Keychain) Scheme() string

type Passthrough

type Passthrough struct{}

Passthrough returns the ref as-is. Used for literal cleartext values (or for values that have already been env-interpolated at config-load time).

func (Passthrough) Resolve

func (Passthrough) Resolve(ref string) (string, error)

func (Passthrough) Scheme

func (Passthrough) Scheme() string

type Resolver

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

Resolver dispatches refs to the matching backend.

func NewResolver

func NewResolver(backends ...Backend) *Resolver

NewResolver builds a Resolver from the given backends. Order matters: the first backend whose Scheme() matches the ref handles it.

func (*Resolver) Resolve

func (r *Resolver) Resolve(ref string) (string, error)

Resolve dispatches ref to a matching backend. Refs use a "scheme:value" or "scheme://value" shape; values with no scheme go to passthrough.

${VAR} env interpolation is handled at config-load time (see internal/config), not here — this function operates on already-loaded ProfileConfig.Password values that may carry an explicit prefix.

Jump to

Keyboard shortcuts

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