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
- type Config
- type Extension
- func (e *Extension) API() *api.API
- func (e *Extension) DashboardContributor() contributor.LocalContributor
- func (e *Extension) Engine() *warden.Engine
- func (e *Extension) Handler() http.Handler
- func (e *Extension) Health(ctx context.Context) error
- func (e *Extension) Register(fapp forge.App) error
- func (e *Extension) RegisterRoutes(router forge.Router) error
- func (e *Extension) Start(ctx context.Context) error
- func (e *Extension) Stop(ctx context.Context) error
- type Option
- func WithBasePath(path string) Option
- func WithConfig(cfg Config) Option
- func WithDisableMigrate() Option
- func WithDisableRoutes() Option
- func WithEngineOptions(opts ...warden.Option) Option
- func WithGroveDatabase(name string) Option
- func WithPlugin(x plugin.Plugin) Option
- func WithRequireConfig() Option
- func WithStore(s store.Store) Option
Constants ¶
const ExtensionDescription = "Composable permissions & authorization engine (RBAC, ABAC, ReBAC)"
ExtensionDescription is the human-readable description.
const ExtensionName = "warden"
ExtensionName is the name registered with Forge.
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 (*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) Health ¶
Health implements forge.Extension.
func (*Extension) Register ¶
Register implements forge.Extension. It loads configuration, initializes the engine, registers it in the DI container, and optionally registers HTTP routes.
func (*Extension) RegisterRoutes ¶
RegisterRoutes registers all warden API routes into a Forge router.
type Option ¶
type Option func(*Extension)
Option configures the Warden Forge extension.
func WithBasePath ¶
WithBasePath sets the URL prefix for warden routes.
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 ¶
WithEngineOptions adds engine-level options.
func WithGroveDatabase ¶
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 ¶
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.