secretprovider

package
v0.40.1 Latest Latest
Warning

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

Go to latest
Published: Nov 13, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package secretprovider is the host-side registry behind scriptling.secret: the Provider interface, the alias Registry, provider Config blocks, and a table of provider-type factories.

It holds no concrete provider, so it links no HTTP client. An application either registers its own Provider with Registry.Register, or enables the built-in provider types it wants and builds providers from config:

import (
	"github.com/paularlott/scriptling/extlibs/secretprovider"
	"github.com/paularlott/scriptling/extlibs/secretprovider/onepassword"
	"github.com/paularlott/scriptling/extlibs/secretprovider/vault"
)

if err := vault.Register(); err != nil { ... }       // provider = "vault"
if err := onepassword.Register(); err != nil { ... } // provider = "onepassword" (Connect)
registry := secretprovider.NewRegistry()
err := secretprovider.RegisterConfigs(registry, configs)

A onepassword config with service_account_token needs the github.com/paularlott/scriptling-onepassword extension imported, which installs itself with RegisterOnePasswordServiceAccount.

Index

Constants

View Source
const DefaultCacheTTL = 5 * time.Minute

Variables

This section is empty.

Functions

func RegisterConfigs

func RegisterConfigs(registry *Registry, configs []Config) error

RegisterConfigs creates and registers providers from config blocks. Each block's provider type must have been registered with RegisterFactory (for example by vault.Register or onepassword.Register).

func RegisterFactory added in v0.40.0

func RegisterFactory(typeName string, factory Factory) error

RegisterFactory makes a provider type available to NewProvider and RegisterConfigs under typeName (the provider = "..." value in config).

The concrete providers live in their own packages so an application links only the ones it uses; each has a Register function that calls this, e.g. vault.Register() or onepassword.Register().

A type name can be registered once: registering it again is an error, the same way Registry.Register rejects a duplicate alias, so two packages can never silently replace each other's provider.

func RegisterOnePasswordServiceAccount added in v0.30.4

func RegisterOnePasswordServiceAccount(factory func(Config) (Provider, error))

RegisterOnePasswordServiceAccount installs the constructor for 1Password service account providers. The github.com/paularlott/scriptling-onepassword extension calls it from init: the 1Password SDK is large, so it lives outside Scriptling, only binaries that import the extension link it, and a service_account_token config fails clearly everywhere else.

func RegisteredTypes added in v0.40.0

func RegisteredTypes() []string

RegisteredTypes returns the registered provider type names, sorted.

Types

type Config

type Config struct {
	Provider string `toml:"provider"`
	Alias    string `toml:"alias"`

	Address string `toml:"address"`
	Token   string `toml:"token"`
	// ServiceAccountToken selects a 1Password service account instead of
	// 1Password Connect for the onepassword provider. Needs the
	// github.com/paularlott/scriptling-onepassword extension linked in.
	ServiceAccountToken string `toml:"service_account_token"`
	CacheTTL            string `toml:"cache_ttl"`
	DefaultField        string `toml:"default_field"`

	AppRoleID     string `toml:"app_role_id"`
	AppRoleSecret string `toml:"app_role_secret"`
	Namespace     string `toml:"namespace"`
	KVVersion     int    `toml:"kv_version"`

	InsecureSkipTLS bool `toml:"insecure_skip_tls"`
}

Config describes one secret provider registration.

type Factory added in v0.40.0

type Factory func(Config) (Provider, error)

Factory builds a provider from one config block.

type Provider

type Provider interface {
	ID() string
	Resolve(ctx context.Context, path string, field string) (string, error)
	List(ctx context.Context, path string) ([]string, error)
}

Provider resolves secrets from an external source.

func NewProvider

func NewProvider(cfg Config) (Provider, error)

NewProvider creates a concrete provider from config, using the factory registered for cfg.Provider. A onepassword config with service_account_token goes to the 1Password service-account constructor (see RegisterOnePasswordServiceAccount) instead.

type Registry

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

Registry stores secret providers by alias and caches resolved values.

func NewRegistry

func NewRegistry() *Registry

NewRegistry creates an empty secret provider registry.

func (*Registry) Aliases

func (r *Registry) Aliases() []string

Aliases returns the registered aliases in unspecified order.

func (*Registry) HasProviders

func (r *Registry) HasProviders() bool

HasProviders reports whether any aliases are registered.

func (*Registry) List

func (r *Registry) List(ctx context.Context, alias, path string) ([]string, error)

List returns the keys at a path using the provider registered for alias.

func (*Registry) Register

func (r *Registry) Register(p Provider, alias string, cacheTTL time.Duration) error

Register adds a provider under an alias.

func (*Registry) ResetForTests

func (r *Registry) ResetForTests()

ResetForTests clears registrations and cache. Intended for tests only.

func (*Registry) Resolve

func (r *Registry) Resolve(ctx context.Context, alias, path, field string) (string, error)

Resolve fetches a secret using the provider registered for alias.

Directories

Path Synopsis
Package onepassword is the 1Password Connect secret provider.
Package onepassword is the 1Password Connect secret provider.
Package vault is the HashiCorp Vault secret provider.
Package vault is the HashiCorp Vault secret provider.

Jump to

Keyboard shortcuts

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