Documentation
¶
Overview ¶
Package plugins defines the plugin interface and core plugin types for Aegis.
Index ¶
- Variables
- 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 Register(p Plugin)
- 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 Migration
- type Plugin
- type PluginData
- type RequestMeta
- type Schema
- type SchemaInfo
- type SchemaRequirement
- type UserEnricher
Constants ¶
This section is empty.
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 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 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 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
GetSchemas() []Schema // Return plugin-specific schemas for all dialects
// Routing
MountRoutes(router router.Router, prefix string) // Register HTTP routes
// Metadata
Dependencies() []Dependency // Informational only
RequiresTables() []string // Informational only
ProvidesAuthMethods() []string // Informational only
}
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 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 Schema ¶
type Schema struct {
Dialect Dialect
SQL string
Info SchemaInfo
}
Schema represents the complete schema for a dialect
type SchemaInfo ¶
SchemaInfo contains metadata about a schema
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.
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. |
|
Package emailotp provides email-based OTP (One-Time Password) verification and authentication.
|
Package emailotp provides email-based OTP (One-Time Password) verification and authentication. |
|
Package jwt implements JWT (JSON Web Token) authentication for Aegis.
|
Package jwt implements JWT (JSON Web Token) authentication for Aegis. |
|
Package oauth provides database migration management for the OAuth plugin.
|
Package oauth provides database migration management for 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. |
|
Package sms provides phone-based OTP (One-Time Password) verification and authentication.
|
Package sms provides phone-based OTP (One-Time Password) verification and authentication. |