secrets

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Dec 1, 2025 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package secrets provides secret resolution backends.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrUnknownScheme indicates the URI scheme is not recognized.
	ErrUnknownScheme = errors.New("unknown URI scheme")

	// ErrNoBackendRegistered indicates no backend is registered for the scheme.
	ErrNoBackendRegistered = errors.New("no backend registered for scheme")
)

Common secret errors.

View Source
var (
	// ErrReferenceEmpty indicates reference is empty.
	ErrReferenceEmpty = errors.New("reference cannot be empty")

	// ErrReferenceInvalidFormat indicates reference has invalid format.
	ErrReferenceInvalidFormat = errors.New("invalid reference format")

	// ErrReferenceEmptyParts indicates reference has empty required components.
	ErrReferenceEmptyParts = errors.New("reference has empty required parts")
)

Generic reference errors (apply to all backends).

View Source
var (
	// ErrFieldsEmpty indicates no fields requested for retrieval.
	ErrFieldsEmpty = errors.New("fields list cannot be empty")

	// ErrFieldNotFound indicates requested field not found in secret.
	ErrFieldNotFound = errors.New("field not found in secret")
)

Generic field extraction errors (apply to all backends).

View Source
var (
	// ErrFileNotFound indicates encrypted file not found.
	ErrFileNotFound = errors.New("file not found")

	// ErrDecryptionFailed indicates decryption operation failed.
	ErrDecryptionFailed = errors.New("decryption failed")

	// ErrInvalidJSON indicates decrypted content is not valid JSON.
	ErrInvalidJSON = errors.New("decrypted content is not valid JSON")

	// ErrIdentityNotSet indicates identity/key environment variable not set.
	ErrIdentityNotSet = errors.New("identity environment variable not set")

	// ErrIdentityNotFound indicates identity/key file not found.
	ErrIdentityNotFound = errors.New("identity file not found")

	// ErrNoMatchingIdentity indicates no identity could decrypt the content.
	ErrNoMatchingIdentity = errors.New("no identity matched (wrong key?)")
)

Generic encryption/decryption errors (apply to encryption-based backends like age, SOPS).

View Source
var (
	// ErrDocumentEmpty indicates document resolved to empty content.
	ErrDocumentEmpty = errors.New("document resolved to empty content")
)

Generic document errors (apply to all backends).

Functions

This section is empty.

Types

type AgeBackend

type AgeBackend struct{}

AgeBackend implements secret resolution using age encryption.

func NewAgeBackend

func NewAgeBackend() *AgeBackend

NewAgeBackend creates a new age backend.

func (*AgeBackend) Resolve

func (b *AgeBackend) Resolve(_ context.Context, path string, fields []string) (map[string]string, error)

Resolve retrieves secrets from age-encrypted files. Path format: "path/to/file.age[/json/path]" Examples:

  • "secrets/db.json.age" - entire file
  • "secrets/db.json.age/prod" - navigate to "prod" key
  • "secrets/db.json.age/prod/credentials" - deep navigation

Paths are resolved relative to current working directory. Fields: list of field names to extract from the resolved JSON subtree.

func (*AgeBackend) ResolveDocument

func (b *AgeBackend) ResolveDocument(_ context.Context, path string) ([]byte, error)

ResolveDocument retrieves raw decrypted content from age-encrypted files. Path format: "path/to/file.age" Returns the raw decrypted content without any JSON parsing.

func (*AgeBackend) Scheme

func (*AgeBackend) Scheme() string

Scheme returns the URI scheme for age ("age").

type Backend

type Backend interface {
	// Resolve retrieves secrets from the backend.
	// path: Backend-specific path without scheme (e.g., "vault/item" or "path/to/file.age/key")
	// fields: List of field names to extract from the secret
	// Returns a map of field name to field value.
	Resolve(ctx context.Context, path string, fields []string) (map[string]string, error)

	// ResolveDocument retrieves raw document content from the backend.
	// path: Backend-specific path without scheme (e.g., "vault/item" or "path/to/file.age")
	// Returns the raw decrypted/retrieved content as bytes.
	ResolveDocument(ctx context.Context, path string) ([]byte, error)

	// Scheme returns the URI scheme this backend handles (e.g., "op", "age")
	Scheme() string
}

Backend defines the interface for secret resolution backends.

type OnePasswordBackend

type OnePasswordBackend struct{}

OnePasswordBackend implements secret resolution using 1Password CLI.

func NewOnePasswordBackend

func NewOnePasswordBackend() *OnePasswordBackend

NewOnePasswordBackend creates a new 1Password backend.

func (*OnePasswordBackend) Resolve

func (*OnePasswordBackend) Resolve(ctx context.Context, path string, fields []string) (map[string]string, error)

Resolve retrieves secrets from 1Password. Path format: "vault/item" Fields: list of field names to extract from the item.

func (*OnePasswordBackend) ResolveDocument

func (*OnePasswordBackend) ResolveDocument(ctx context.Context, path string) ([]byte, error)

ResolveDocument retrieves raw document content from 1Password. Path format: "vault/item" Uses `op document get` to retrieve the raw document content.

func (*OnePasswordBackend) Scheme

func (*OnePasswordBackend) Scheme() string

Scheme returns the URI scheme for 1Password ("op").

type Resolver

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

Resolver manages secret backends and routes requests to the appropriate backend.

func NewResolver

func NewResolver() *Resolver

NewResolver creates a new secret resolver.

func (*Resolver) Register

func (r *Resolver) Register(backend Backend)

Register registers a backend for a specific URI scheme.

func (*Resolver) Resolve

func (r *Resolver) Resolve(ctx context.Context, uri string, fields []string) (map[string]string, error)

Resolve routes a secret resolution request to the appropriate backend. URI format: "scheme://path" Returns a map of field names to values.

func (*Resolver) ResolveDocument

func (r *Resolver) ResolveDocument(ctx context.Context, uri string) ([]byte, error)

ResolveDocument routes a document resolution request to the appropriate backend. URI format: "scheme://path" Returns the raw document content as bytes.

Jump to

Keyboard shortcuts

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