plugins

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Feb 23, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package plugins defines the plugin interface and core plugin types for Aegis.

Index

Constants

This section is empty.

Variables

View Source
var ValidateColumnExists = core.ValidateColumnExists

ValidateColumnExists creates a requirement to check if a column exists in a table

View Source
var ValidateTableExists = core.ValidateTableExists

ValidateTableExists creates a requirement to check if a table exists

Functions

func Clear

func Clear()

Clear removes all plugins from the registry

func ExtendUser

func ExtendUser(ctx context.Context, key string, value any)

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

func GetIPAddress(ctx context.Context) string

GetIPAddress retrieves the client IP from context metadata.

func GetPluginValue

func GetPluginValue(ctx context.Context, key string) any

GetPluginValue is a convenience function to get a plugin value from context.

func GetRequestID

func GetRequestID(ctx context.Context) string

GetRequestID retrieves the request ID from context (useful for logging/tracing).

func GetUserAgent

func GetUserAgent(ctx context.Context) string

GetUserAgent retrieves the user agent from context metadata.

func GetUserExtension

func GetUserExtension(ctx context.Context, key string) any

GetUserExtension retrieves a specific extension from the enriched user.

func GetUserExtensionBool

func GetUserExtensionBool(ctx context.Context, key string) bool

GetUserExtensionBool retrieves a bool extension from the enriched user.

func GetUserExtensionString

func GetUserExtensionString(ctx context.Context, key string) string

GetUserExtensionString retrieves a string extension from the enriched user.

func GetUserID

func GetUserID(ctx context.Context) string

GetUserID retrieves the authenticated user's ID from context. Returns empty string if not authenticated.

func IsUserEnricher

func IsUserEnricher(p Plugin) bool

IsUserEnricher checks if a plugin implements the UserEnricher interface.

func Register

func Register(p Plugin)

Register adds a plugin to the global registry

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.

func SetPluginValue

func SetPluginValue(ctx context.Context, key string, value any)

SetPluginValue is a convenience function to set a plugin value in context. For plugin-internal data (not exposed in API responses), use namespaced keys.

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 Dialect

type Dialect string

Dialect represents a database dialect

const (
	// DialectPostgres represents PostgreSQL database
	DialectPostgres Dialect = "postgres"
	// DialectMySQL represents MySQL database
	DialectMySQL Dialect = "mysql"
	// DialectSQLite represents SQLite database
	DialectSQLite Dialect = "sqlite"
)

Database dialect constants

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).

func Get

func Get(name string) (Plugin, bool)

Get retrieves a plugin by name

func List

func List() []Plugin

List returns all registered plugins

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

type SchemaInfo struct {
	Package     string
	Version     int
	Description string
}

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.
jwt
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.
sms
Package sms provides phone-based OTP (One-Time Password) verification and authentication.
Package sms provides phone-based OTP (One-Time Password) verification and authentication.

Jump to

Keyboard shortcuts

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