extension

package
v1.8.2 Latest Latest
Warning

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

Go to latest
Published: Nov 11, 2026 License: MIT Imports: 17 Imported by: 0

Documentation

Overview

Package extension provides the Forge extension adapter for Vault.

It implements the forge.Extension interface to integrate Vault into a Forge application with automatic dependency discovery, route registration, and lifecycle management.

Configuration can be provided programmatically via Option functions or via YAML configuration files under "extensions.vault" or "vault" keys.

Index

Constants

View Source
const ExtensionDescription = "Composable secrets management, feature flags, and runtime configuration"

ExtensionDescription is the human-readable description.

View Source
const ExtensionName = "vault"

ExtensionName is the name registered with Forge.

View Source
const ExtensionVersion = "0.1.0"

ExtensionVersion is the semantic version.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	// DisableRoutes prevents HTTP route registration.
	DisableRoutes bool `json:"disable_routes" mapstructure:"disable_routes" yaml:"disable_routes"`

	// DisableMigrate prevents auto-migration on start.
	DisableMigrate bool `json:"disable_migrate" mapstructure:"disable_migrate" yaml:"disable_migrate"`

	// BasePath is the URL prefix for vault routes (default: "/vault").
	BasePath string `json:"base_path" mapstructure:"base_path" yaml:"base_path"`

	// AppID is the application identifier used for scoping secrets, flags, and config.
	AppID string `json:"app_id" mapstructure:"app_id" yaml:"app_id"`

	// EncryptionKeyEnv is the environment variable name for the encryption key.
	// Used to load the master encryption key at startup.
	EncryptionKeyEnv string `json:"encryption_key_env" mapstructure:"encryption_key_env" yaml:"encryption_key_env"`

	// FlagCacheTTL is the TTL for the flag evaluation cache.
	// Defaults to 30 seconds.
	FlagCacheTTL time.Duration `json:"flag_cache_ttl" mapstructure:"flag_cache_ttl" yaml:"flag_cache_ttl"`

	// SourcePollInterval is the interval for polling database sources.
	// Defaults to 30 seconds.
	SourcePollInterval time.Duration `json:"source_poll_interval" mapstructure:"source_poll_interval" yaml:"source_poll_interval"`

	// Deprecated: audit logging is always on and this setting has no effect.
	EnableAudit bool `json:"enable_audit" mapstructure:"enable_audit" yaml:"enable_audit"`

	// GroveDatabase is the name of a grove.DB registered in the DI container.
	// When set, the extension resolves this named database and auto-constructs
	// the appropriate store based on the driver type (pg/sqlite/mongo).
	// When empty and WithGroveDatabase was called, the default (unnamed) DB is used.
	GroveDatabase string `json:"grove_database" mapstructure:"grove_database" yaml:"grove_database"`

	// MountToConfy registers vault as a confy ConfigSource and SecretProvider
	// so vault-managed config and secrets are accessible via the forge ConfigManager.
	MountToConfy bool `json:"mount_to_confy" mapstructure:"mount_to_confy" yaml:"mount_to_confy"`

	// ConfyKeyPrefix is prepended to all vault keys when exposed through confy.
	// For example, "vault." causes vault key "db.host" to appear as "vault.db.host".
	ConfyKeyPrefix string `json:"confy_key_prefix" mapstructure:"confy_key_prefix" yaml:"confy_key_prefix"`

	// ConfyMountKeys restricts which vault keys are mounted into confy.
	// Only the listed keys will be included; all others are filtered out.
	// When empty, all keys are included (unless ConfyMountPatterns is set).
	ConfyMountKeys []string `json:"confy_mount_keys" mapstructure:"confy_mount_keys" yaml:"confy_mount_keys"`

	// ConfyMountPatterns restricts which vault keys are mounted into confy
	// using glob patterns (e.g. "db.*", "auth.*"). Multiple patterns are OR-ed.
	// When empty, all keys are included (unless ConfyMountKeys is set).
	ConfyMountPatterns []string `json:"confy_mount_patterns" mapstructure:"confy_mount_patterns" yaml:"confy_mount_patterns"`

	// RequireConfig requires config to be present in YAML files.
	// If true and no config is found, Register returns an error.
	RequireConfig bool `json:"-" yaml:"-"`
}

Config holds the Vault extension configuration. Fields can be set programmatically via Option functions or loaded from YAML configuration files (under "extensions.vault" or "vault" keys).

func DefaultConfig

func DefaultConfig() Config

DefaultConfig returns a Config with sensible defaults.

type Extension

type Extension struct {
	*forge.BaseExtension
	// contains filtered or unexported fields
}

Extension adapts Vault as a Forge extension.

func New

func New(opts ...Option) *Extension

New creates a new Vault Forge extension with the given options.

func (*Extension) Health

func (e *Extension) Health(ctx context.Context) error

Health implements forge.Extension.

func (*Extension) Register

func (e *Extension) Register(fapp forge.App) error

Register implements forge.Extension. It loads configuration, initializes the vault, and registers it in the DI container.

func (*Extension) RegisterContractContributor

func (e *Extension) RegisterContractContributor(
	disp *dispatcher.Dispatcher,
	reg dashcontract.Registry,
	wreg dashcontract.WardenRegistry,
) error

RegisterContractContributor implements dashboard.ContractContributorAware. It registers the vault contract contributor, which is what the React shell reads.

func (*Extension) Start

func (e *Extension) Start(_ context.Context) error

Start implements forge.Extension. It starts the rotation manager's background loop, without which a policy with an enabled, due rotation and a registered rotator never rotates on schedule. The loop is started with context.Background() rather than the context Start receives, which may be cancelled or time out well before the extension itself stops.

It also starts the version-encryption backfill in the background, so Start does not wait on a large table. The backfill only records what the configured key proves, so running it on every start is safe and a second run marks nothing.

func (*Extension) Stop

func (e *Extension) Stop(ctx context.Context) error

Stop implements forge.Extension. The rotation loop is stopped before the store is closed, so no in-flight rotation check can run against a closed store.

func (*Extension) Store

func (e *Extension) Store() store.Store

Store returns the configured store backend. This is nil if no store was provided.

func (*Extension) Vault

func (e *Extension) Vault() *vault.Vault

Vault returns the underlying Vault instance. This is nil until Register is called.

type Option

type Option func(*Extension)

Option configures the Vault Forge extension.

func WithAppID

func WithAppID(appID string) Option

WithAppID sets the application identifier used for scoping.

func WithBasePath

func WithBasePath(path string) Option

WithBasePath sets the URL prefix for vault routes.

func WithConfig

func WithConfig(cfg Config) Option

WithConfig sets the Forge extension configuration.

func WithConfyKeyPrefix

func WithConfyKeyPrefix(prefix string) Option

WithConfyKeyPrefix sets a prefix prepended to all vault keys in confy. For example, "vault." causes vault key "db.host" to appear as "vault.db.host".

func WithConfyMountKeys

func WithConfyMountKeys(keys ...string) Option

WithConfyMountKeys restricts which vault keys are mounted into confy. Only the listed keys will be included; all others are filtered out.

func WithConfyMountPatterns

func WithConfyMountPatterns(patterns ...string) Option

WithConfyMountPatterns restricts which vault keys are mounted into confy using glob patterns (e.g. "db.*", "auth.*"). Multiple patterns are OR-ed.

func WithDisableMigrate

func WithDisableMigrate() Option

WithDisableMigrate prevents auto-migration on start.

func WithDisableRoutes

func WithDisableRoutes() Option

WithDisableRoutes prevents HTTP route registration.

func WithEnableAudit deprecated

func WithEnableAudit(enable bool) Option

Deprecated: audit logging is always on and this setting has no effect.

func WithEncryptionKeyEnv

func WithEncryptionKeyEnv(envVar string) Option

WithEncryptionKeyEnv sets the environment variable name for the encryption key.

func WithGroveDatabase

func WithGroveDatabase(name string) Option

WithGroveDatabase sets the name of the grove.DB to resolve from the DI container. The extension will auto-construct the appropriate store backend (postgres/sqlite/mongo) based on the grove driver type. Pass an empty string to use the default (unnamed) grove.DB.

func WithMountToConfy

func WithMountToConfy() Option

WithMountToConfy enables mounting vault config and secrets into the forge ConfigManager via confy's ConfigSource and SecretProvider interfaces.

func WithRequireConfig

func WithRequireConfig(require bool) Option

WithRequireConfig requires config to be present in YAML files. If true and no config is found, Register returns an error.

func WithStore

func WithStore(s store.Store) Option

WithStore sets the composite store backend for the vault.

func WithVaultOption

func WithVaultOption(opt vault.Option) Option

WithVaultOption passes a vault option through to the underlying Vault instance.

Directories

Path Synopsis
Package contract wires Vault into the Forge dashboard's contract path.
Package contract wires Vault into the Forge dashboard's contract path.

Jump to

Keyboard shortcuts

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