extension

package
v1.5.3 Latest Latest
Warning

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

Go to latest
Published: Jun 2, 2026 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Overview

Package extension provides a Forge extension entry point for Warden.

It implements the forge.Extension interface to integrate Warden 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.warden" or "warden" keys.

Index

Constants

View Source
const ExtensionDescription = "Composable permissions & authorization engine (RBAC, ABAC, ReBAC)"

ExtensionDescription is the human-readable description.

View Source
const ExtensionName = "warden"

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

	// MaxGraphDepth controls the maximum depth for ReBAC graph traversal.
	MaxGraphDepth int `json:"max_graph_depth" mapstructure:"max_graph_depth" yaml:"max_graph_depth"`

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

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

	// DeclarativePath is a single .warden file, directory, or glob pattern
	// to load. When unset, declarative auto-apply is skipped.
	DeclarativePath string `json:"declarative_path" mapstructure:"declarative_path" yaml:"declarative_path"`

	// DeclarativePaths is a list of paths to load (in addition to
	// DeclarativePath). Useful for splitting tenant-root and per-tenant
	// configs across multiple roots.
	DeclarativePaths []string `json:"declarative_paths" mapstructure:"declarative_paths" yaml:"declarative_paths"`

	// DeclarativeOnStart toggles auto-apply at Start time.
	DeclarativeOnStart bool `json:"declarative_on_start" mapstructure:"declarative_on_start" yaml:"declarative_on_start"`

	// DeclarativePrune deletes tenant entries not present in the config.
	// kubectl-style apply with prune. Defaults to false; opt-in only.
	DeclarativePrune bool `json:"declarative_prune" mapstructure:"declarative_prune" yaml:"declarative_prune"`

	// DeclarativeStrict makes startup fail when the apply produces
	// diagnostics. When false (default), errors are logged but startup
	// continues so a misconfigured tenant doesn't crash the app.
	DeclarativeStrict bool `json:"declarative_strict" mapstructure:"declarative_strict" yaml:"declarative_strict"`

	// DeclarativeTenantID overrides any `tenant <id>` declared in source.
	// Useful for multi-tenant deployments where the same source is applied
	// to many tenants.
	DeclarativeTenantID string `json:"declarative_tenant_id" mapstructure:"declarative_tenant_id" yaml:"declarative_tenant_id"`
}

Config holds the Warden extension configuration. Fields can be set programmatically via Option functions or loaded from YAML configuration files (under "extensions.warden" or "warden" 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 Warden as a Forge extension.

func New

func New(opts ...Option) *Extension

New creates a Warden Forge extension with the given options.

func (*Extension) API

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

API returns the API handler.

func (*Extension) DashboardContributor

func (e *Extension) DashboardContributor() contributor.LocalContributor

DashboardContributor implements dashboard.DashboardAware. It returns a LocalContributor that renders warden pages, widgets, and settings in the Forge dashboard using templ + ForgeUI.

func (*Extension) Engine

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

Engine returns the underlying Warden engine.

func (*Extension) Handler

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

Handler returns the HTTP handler for all API routes.

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 engine, registers it in the DI container, and optionally registers HTTP routes.

func (*Extension) RegisterRoutes

func (e *Extension) RegisterRoutes(router forge.Router) error

RegisterRoutes registers all warden API routes into a Forge router.

func (*Extension) Start

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

Start begins the warden engine and runs migrations if enabled.

func (*Extension) Stop

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

Stop gracefully shuts down the warden engine.

type Option

type Option func(*Extension)

Option configures the Warden Forge extension.

func WithBasePath

func WithBasePath(path string) Option

WithBasePath sets the URL prefix for warden routes.

func WithConfig

func WithConfig(cfg Config) Option

WithConfig sets the extension configuration.

func WithDisableMigrate

func WithDisableMigrate() Option

WithDisableMigrate disables auto-migration on start.

func WithDisableRoutes

func WithDisableRoutes() Option

WithDisableRoutes disables the registration of HTTP routes.

func WithEngineOptions

func WithEngineOptions(opts ...warden.Option) Option

WithEngineOptions adds engine-level options.

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 WithPlugin

func WithPlugin(x plugin.Plugin) Option

WithPlugin registers a lifecycle hook plugin.

func WithRequireConfig

func WithRequireConfig() 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 persistence backend.

Jump to

Keyboard shortcuts

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