extension

package
v1.9.0 Latest Latest
Warning

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

Go to latest
Published: Nov 3, 2026 License: MIT Imports: 20 Imported by: 0

Documentation

Overview

Package extension adapts Keysmith as a Forge extension.

Index

Constants

View Source
const ExtensionDescription = "Composable API key management engine for key lifecycle, validation, and usage analytics"

ExtensionDescription is the human-readable description.

View Source
const ExtensionName = "keysmith"

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 keysmith routes (default: "/keysmith").
	BasePath string `json:"base_path" mapstructure:"base_path" yaml:"base_path"`

	// 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"`

	// Dashboard scopes the React dashboard's contract handlers.
	Dashboard DashboardConfig `json:"dashboard" mapstructure:"dashboard" yaml:"dashboard"`

	// 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 Keysmith extension configuration. Fields can be set programmatically via Option functions or loaded from YAML configuration files (under "extensions.keysmith" or "keysmith" keys).

func DefaultConfig

func DefaultConfig() Config

DefaultConfig returns a Config with sensible defaults.

type DashboardConfig

type DashboardConfig struct {
	// TenantID is the tenant a dashboard request is scoped to when it carries
	// no tenant claim and no session org (the forge Scope an auth extension
	// such as authsome sets). Leave it empty and those requests refuse, so
	// the dashboard never guesses.
	TenantID string `json:"tenant_id" mapstructure:"tenant_id" yaml:"tenant_id"`

	// AppID labels rows the dashboard creates when the principal carries no
	// app claim. It may be empty. Keysmith never filters reads by app.
	AppID string `json:"app_id" mapstructure:"app_id" yaml:"app_id"`
}

DashboardConfig scopes the dashboard contract handlers to a tenant.

type ExtOption

type ExtOption func(*Extension)

ExtOption is a functional option for the Forge extension.

func WithBasePath

func WithBasePath(path string) ExtOption

WithBasePath sets the URL prefix for keysmith routes.

func WithConfig

func WithConfig(c Config) ExtOption

WithConfig sets the extension config.

func WithDashboardTenant

func WithDashboardTenant(tenantID, appID string) ExtOption

WithDashboardTenant sets the tenant (and optional app) the dashboard's contract handlers use when a request carries no tenant claim and no session org. A YAML dashboard.tenant_id or dashboard.app_id wins over these values.

func WithDisableMigrate

func WithDisableMigrate() ExtOption

WithDisableMigrate prevents auto-migration on start.

func WithDisableRoutes

func WithDisableRoutes() ExtOption

WithDisableRoutes prevents HTTP route registration.

func WithEngineOptions

func WithEngineOptions(opts ...keysmith.Option) ExtOption

WithEngineOptions passes options to the underlying keysmith engine.

func WithGroveDatabase

func WithGroveDatabase(name string) ExtOption

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 WithHookExtension

func WithHookExtension(x plugin.Plugin) ExtOption

WithHookExtension registers a lifecycle plugin with the engine.

func WithLogger

func WithLogger(l log.Logger) ExtOption

WithLogger sets the logger.

func WithRequireConfig

func WithRequireConfig(require bool) ExtOption

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

type Extension

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

Extension adapts Keysmith as a Forge extension.

func New

func New(opts ...ExtOption) *Extension

New creates a Keysmith Forge extension with the given options.

func (*Extension) API

func (e *Extension) API() *api.API

API returns the API handler.

func (*Extension) Engine

func (e *Extension) Engine() *keysmith.Engine

Engine returns the underlying keysmith engine (nil until Register is called).

func (*Extension) Handler

func (e *Extension) Handler() http.Handler

Handler returns the HTTP handler for standalone use outside Forge.

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.

func (*Extension) RegisterContractContributor

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

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

func (*Extension) Start

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

Start begins the keysmith engine and runs auto-migration if enabled.

func (*Extension) Stop

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

Stop gracefully shuts down the keysmith engine.

Directories

Path Synopsis
Package contract wires keysmith into the Forge dashboard's contract path.
Package contract wires keysmith 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