Documentation
¶
Overview ¶
Package plugins defines the plugin interface and core plugin types for Aegis.
Index ¶
- Constants
- Variables
- func CheckVersionedRequirements(pluginName string, reqs []VersionedRequirement, ...) error
- func Clear()
- func ExtendUser(ctx context.Context, key string, value any)
- func GetIPAddress(ctx context.Context) string
- func GetPluginValue(ctx context.Context, key string) any
- func GetRequestID(ctx context.Context) string
- func GetUserAgent(ctx context.Context) string
- func GetUserExtension(ctx context.Context, key string) any
- func GetUserExtensionBool(ctx context.Context, key string) bool
- func GetUserExtensionString(ctx context.Context, key string) string
- func GetUserID(ctx context.Context) string
- func IsUserEnricher(p Plugin) bool
- func MeetsMinVersion(have, need string) bool
- func Register(p Plugin) error
- func RunUserEnrichers(ctx context.Context, user *core.EnrichedUser) error
- func RunUserEnrichersByName(ctx context.Context, user *core.EnrichedUser, pluginNames ...string) error
- func SetPluginValue(ctx context.Context, key string, value any)
- type Aegis
- type Dependency
- type Dialect
- type EnrichedUser
- type HealthChecker
- type Migration
- type Plugin
- type PluginData
- type PluginMinAegisVersion
- type PluginRequires
- type PluginShutdown
- type PluginVersionRequires
- type RequestMeta
- type SchemaRequirement
- type UserEnricher
- type VersionedRequirement
Constants ¶
const ( // DialectPostgres represents PostgreSQL database DialectPostgres = config.DialectPostgres // DialectMySQL represents MySQL database DialectMySQL = config.DialectMySQL // DialectSQLite represents SQLite database DialectSQLite = config.DialectSQLite )
Database dialect constants
Variables ¶
var ValidateColumnExists = core.ValidateColumnExists
ValidateColumnExists creates a requirement to check if a column exists in a table
var ValidateTableExists = core.ValidateTableExists
ValidateTableExists creates a requirement to check if a table exists
Functions ¶
func CheckVersionedRequirements ¶ added in v1.5.0
func CheckVersionedRequirements(pluginName string, reqs []VersionedRequirement, lookup func(string) (Plugin, bool)) error
CheckVersionedRequirements validates versioned plugin dependencies against a lookup function. Returns a descriptive error if any requirement is unmet. Called by Aegis internals; exposed so tests and custom hosts can reuse it.
func ExtendUser ¶
ExtendUser adds extension data to the enriched user in context. Use simple field names - these become top-level fields in JSON responses.
Example:
plugins.ExtendUser(ctx, "role", "admin")
plugins.ExtendUser(ctx, "claims", claims)
plugins.ExtendUser(ctx, "organizations", []string{"org1", "org2"})
These produce JSON like: {"id": "...", "email": "...", "role": "admin", "organizations": [...]}
func GetIPAddress ¶
GetIPAddress retrieves the client IP from context metadata.
func GetPluginValue ¶
GetPluginValue is a convenience function to get a plugin value from context.
func GetRequestID ¶
GetRequestID retrieves the request ID from context (useful for logging/tracing).
func GetUserAgent ¶
GetUserAgent retrieves the user agent from context metadata.
func GetUserExtension ¶
GetUserExtension retrieves a specific extension from the enriched user.
func GetUserExtensionBool ¶
GetUserExtensionBool retrieves a bool extension from the enriched user.
func GetUserExtensionString ¶
GetUserExtensionString retrieves a string extension from the enriched user.
func GetUserID ¶
GetUserID retrieves the authenticated user's ID from context. Returns empty string if not authenticated.
func IsUserEnricher ¶
IsUserEnricher checks if a plugin implements the UserEnricher interface.
func MeetsMinVersion ¶ added in v1.5.0
MeetsMinVersion reports whether `have` satisfies the semver lower-bound `need`. Both strings must be "major.minor.patch" (e.g. "2.1.0"). Returns true when have >= need by comparing each numeric component left-to-right. Malformed version strings are treated as "0.0.0" (never satisfies a non-zero need).
func Register ¶
Register adds a plugin to the global registry. Returns an error if a plugin with the same name is already registered.
func RunUserEnrichers ¶
func RunUserEnrichers(ctx context.Context, user *core.EnrichedUser) error
RunUserEnrichers runs all registered plugins that implement UserEnricher. This populates the EnrichedUser with plugin-specific extension fields. Called automatically by middleware after authentication.
func RunUserEnrichersByName ¶
func RunUserEnrichersByName(ctx context.Context, user *core.EnrichedUser, pluginNames ...string) error
RunUserEnrichersByName runs specific plugins' user enrichers by name. Useful when you only want to enrich with specific plugins.
Types ¶
type Aegis ¶
type Aegis interface {
GetAuthService() *core.AuthService // Returns the auth service for user operations
GetLogger() config.Logger // Returns the configured logger (may be nil)
GetRateLimiter() *core.RateLimiter // Returns the rate limiter (may be nil)
DeriveSecret(purpose string) []byte // Derives a purpose-specific secret from the master secret
DB() *sql.DB // Returns the database connection for schema validation
ValidateSchemaRequirements(ctx context.Context, requirements []SchemaRequirement) error // Validates schema requirements
GetPlugin(name string) (Plugin, bool) // Returns a registered plugin by name (for inter-plugin communication)
}
Aegis is the interface that plugins use to interact with the Aegis framework. Uses one generic parameter for the User model (U). Account, Session, and Verification models are standard across the framework.
type Dependency ¶
type Dependency struct {
Package string // Go package import path
Version string // Required version (e.g., "v1.2.3" or "latest")
Purpose string // Why this dependency is needed
}
Dependency represents an external package dependency.
type EnrichedUser ¶
type EnrichedUser = core.EnrichedUser
EnrichedUser is re-exported from core for plugin convenience
func GetEnrichedUser ¶
func GetEnrichedUser(ctx context.Context) *EnrichedUser
GetEnrichedUser retrieves the enriched user from context. Returns nil if not authenticated.
type HealthChecker ¶ added in v1.5.0
HealthChecker is an optional interface for plugins that can report their own health. Aegis itself does not poll this automatically; it is intended for use by readiness / liveness handlers or monitoring integrations.
Example:
func (p *Plugin) Health(ctx context.Context) error {
return p.store.Ping(ctx)
}
type Migration ¶
type Migration struct {
Version int // Migration version (e.g., 001, 002)
Description string // Human-readable description
Up string // SQL for applying migration
Down string // SQL for reverting migration
}
Migration represents a database migration for a plugin.
type Plugin ¶
type Plugin interface {
// Identity
Name() string // Plugin identifier (e.g., "sms", "oauth", "email")
Version() string // Plugin version
Description() string // Human-readable description
// Lifecycle
Init(ctx context.Context, a Aegis) error // Initialize plugin with Aegis instance
GetMigrations() []Migration // Return plugin-specific migrations
// Routing
MountRoutes(router router.Router, prefix string) // Register HTTP routes
// Metadata
Dependencies() []Dependency // External Go package dependencies (library-level, not inter-plugin)
RequiresTables() []string // Core tables this plugin reads from (used for schema validation in Init)
ProvidesAuthMethods() []string // Auth method identifiers this plugin enables (e.g. "oauth_google", "jwt")
}
Plugin is the interface that all plugins must implement. Simplified to one generic parameter (U).
type PluginData ¶
type PluginData = core.PluginData
PluginData is re-exported from core for plugin convenience
func GetPluginData ¶
func GetPluginData(ctx context.Context) *PluginData
GetPluginData retrieves the plugin data store from context. For plugin-internal data (not exposed in API responses), use namespaced keys.
type PluginMinAegisVersion ¶ added in v1.5.0
type PluginMinAegisVersion interface {
MinAegisVersion() string
}
PluginMinAegisVersion is an optional interface for plugins that require a minimum version of the Aegis framework itself. Aegis checks this at Use/UseWithPriority time and returns an error if the running aegis.Version is below the declared minimum.
Example:
func (p *Plugin) MinAegisVersion() string { return "1.1.0" }
type PluginRequires ¶ added in v1.5.0
type PluginRequires interface {
Requires() []string
}
PluginRequires is an optional interface for plugins that depend on other plugins being registered first. When a plugin implementing this interface is registered via Aegis.Use / Aegis.UseWithPriority, Aegis validates that every name returned by Requires is already registered.
Example:
func (a *Plugin) Requires() []string {
return []string{"organizations"}
}
type PluginShutdown ¶ added in v1.5.0
PluginShutdown is an optional interface for plugins that hold resources requiring cleanup (goroutines, connections, timers). Aegis calls Shutdown on all plugins that implement this interface when Aegis.Shutdown is invoked, in reverse priority order (highest priority number first).
Example implementation (JWT key-rotation goroutine):
func (p *Plugin) Shutdown(ctx context.Context) error {
p.stopKeyRotation()
return nil
}
type PluginVersionRequires ¶ added in v1.5.0
type PluginVersionRequires interface {
VersionedRequires() []VersionedRequirement
}
PluginVersionRequires is an optional interface for plugins that need a specific minimum version of another plugin. Aegis checks this at Use/UseWithPriority time: the required plugin must already be registered AND its Version() must satisfy the declared MinVersion.
Use this instead of (or alongside) PluginRequires when the API contract of the required plugin changed between versions and you need to enforce compatibility.
Example:
func (p *Plugin) VersionedRequires() []plugins.VersionedRequirement {
return []plugins.VersionedRequirement{
{Plugin: "oauth", MinVersion: "2.0.0"},
}
}
type RequestMeta ¶
type RequestMeta = core.RequestMeta
RequestMeta is re-exported from core for plugin convenience
func GetRequestMeta ¶
func GetRequestMeta(ctx context.Context) *RequestMeta
GetRequestMeta retrieves request metadata from context.
type SchemaRequirement ¶
type SchemaRequirement = core.SchemaRequirement
SchemaRequirement defines a schema validation requirement
type UserEnricher ¶
type UserEnricher interface {
// EnrichUser adds plugin-specific data to the enriched user.
// Called after authentication to populate extension fields.
// Use simple field names (e.g., "role", not "admin:role").
EnrichUser(ctx context.Context, user *core.EnrichedUser) error
}
UserEnricher is an optional interface that plugins can implement to add extension fields to the EnrichedUser. Plugins that implement this interface will have their EnrichUser method called after authentication to populate user-specific data (role, permissions, organizations, etc.).
Example implementation:
func (a *Admin) EnrichUser(ctx context.Context, user *core.EnrichedUser) error {
role, err := a.store.GetRole(ctx, user.ID)
if err == nil && role != "" {
user.Set("role", role)
}
return nil
}
func GetUserEnricher ¶
func GetUserEnricher(p Plugin) (UserEnricher, bool)
GetUserEnricher returns the UserEnricher interface if the plugin implements it.
type VersionedRequirement ¶ added in v1.5.0
type VersionedRequirement struct {
Plugin string // Name of the required plugin (matches Plugin.Name())
MinVersion string // Minimum acceptable semver, e.g. "2.0.0"
}
VersionedRequirement specifies a plugin dependency with a minimum version constraint. Used by PluginVersionRequires to declare version-aware inter-plugin dependencies.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package admin provides role-based access control (RBAC) and administrative user management.
|
Package admin provides role-based access control (RBAC) and administrative user management. |
|
default_store
Package defaultstore implements the SQL-backed default store for the admin plugin.
|
Package defaultstore implements the SQL-backed default store for the admin plugin. |
|
types
Package types defines the domain models and request/response types used by the admin plugin.
|
Package types defines the domain models and request/response types used by the admin plugin. |
|
Package emailotp provides email-based OTP (One-Time Password) verification and authentication.
|
Package emailotp provides email-based OTP (One-Time Password) verification and authentication. |
|
default_store
Package defaultstore implements the SQL-backed default store for the emailotp plugin.
|
Package defaultstore implements the SQL-backed default store for the emailotp plugin. |
|
types
Package types defines the domain models and request/response types used by the emailotp plugin.
|
Package types defines the domain models and request/response types used by the emailotp plugin. |
|
Package jwt implements JWT (JSON Web Token) authentication for Aegis.
|
Package jwt implements JWT (JSON Web Token) authentication for Aegis. |
|
default_store
Package defaultstore implements the SQL-backed default store for the jwt plugin.
|
Package defaultstore implements the SQL-backed default store for the jwt plugin. |
|
types
Package jwt defines the domain models and types used by the jwt plugin.
|
Package jwt defines the domain models and types used by the jwt plugin. |
|
Package oauth provides database migration management for the OAuth plugin.
|
Package oauth provides database migration management for the OAuth plugin. |
|
default_store
Package defaultstore implements the SQL-backed default store for the oauth plugin.
|
Package defaultstore implements the SQL-backed default store for the oauth plugin. |
|
types
Package types defines the domain models and types used by the oauth plugin.
|
Package types defines the domain models and types used by the oauth plugin. |
|
Package openapi provides automatic OpenAPI 3.0 specification generation for Aegis.
|
Package openapi provides automatic OpenAPI 3.0 specification generation for Aegis. |
|
Package organizations provides multi-tenancy and team management for Aegis.
|
Package organizations provides multi-tenancy and team management for Aegis. |
|
default_store
Package defaultstore implements the SQL-backed default store for the organizations plugin.
|
Package defaultstore implements the SQL-backed default store for the organizations plugin. |
|
types
Package types defines the domain models and types used by the organizations plugin.
|
Package types defines the domain models and types used by the organizations plugin. |
|
Package sms provides phone-based OTP (One-Time Password) verification and authentication.
|
Package sms provides phone-based OTP (One-Time Password) verification and authentication. |
|
default_store
Package defaultstore implements the SQL-backed default store for the sms plugin.
|
Package defaultstore implements the SQL-backed default store for the sms plugin. |
|
types
Package types defines the domain models and request/response types used by the sms plugin.
|
Package types defines the domain models and request/response types used by the sms plugin. |