plugin

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Jul 5, 2025 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package plugin provides the foundation for Hockeypuck's plugin system

Index

Constants

View Source
const (
	// Endpoint protection events
	EventEndpointProtectionRequest = "endpoint.protection.request"
	EventEndpointProtectionUpdate  = "endpoint.protection.update"
	EventEndpointAccessDenied      = "endpoint.access.denied"
	EventEndpointAccessGranted     = "endpoint.access.granted"

	// Security events
	EventSecurityThreatDetected     = "security.threat.detected"
	EventSecurityAnomalyDetected    = "security.anomaly.detected"
	EventSecurityRateLimitTriggered = "security.ratelimit.triggered"
)

Event types for dynamic endpoint protection

Variables

This section is empty.

Functions

func Register

func Register(plugin Plugin)

Register registers a plugin globally

func SetHost

func SetHost(host PluginHost)

SetHost sets the plugin host for the global registry

Types

type Alert

type Alert struct {
	Level       string                 `json:"level"`
	Title       string                 `json:"title"`
	Description string                 `json:"description"`
	Timestamp   time.Time              `json:"timestamp"`
	Tags        map[string]string      `json:"tags"`
	Data        map[string]interface{} `json:"data"`
}

Alert represents an alert

type AlertConfig

type AlertConfig struct {
	Provider string                 `json:"provider"`
	Webhook  string                 `json:"webhook"`
	Config   map[string]interface{} `json:"config"`
}

AlertConfig provides configuration for alert providers

type AlertProvider

type AlertProvider interface {
	SendAlert(alert Alert) error
}

AlertProvider interface for alerting

type AuditConfig

type AuditConfig struct {
	Level  string                 `json:"level"`
	Output string                 `json:"output"`
	Config map[string]interface{} `json:"config"`
}

AuditConfig provides configuration for audit logging

type AuditEvent

type AuditEvent struct {
	Timestamp time.Time              `json:"timestamp"`
	User      string                 `json:"user"`
	Action    string                 `json:"action"`
	Resource  string                 `json:"resource"`
	Result    string                 `json:"result"`
	Details   map[string]interface{} `json:"details"`
}

AuditEvent represents an audit event

type AuditLogger

type AuditLogger interface {
	LogEvent(event AuditEvent) error
}

AuditLogger interface for audit logging

type AuthConfig

type AuthConfig struct {
	Type     string                 `json:"type"`
	Provider string                 `json:"provider"`
	Config   map[string]interface{} `json:"config"`
}

AuthConfig provides configuration for authentication providers

type AuthProvider

type AuthProvider interface {
	Authenticate(username, password string) (bool, error)
	ValidateToken(token string) (bool, error)
}

AuthProvider interface for authentication providers

type BasePlugin

type BasePlugin struct {
	// contains filtered or unexported fields
}

BasePlugin provides a base implementation for plugins

func (*BasePlugin) Dependencies

func (p *BasePlugin) Dependencies() []PluginDependency

Dependencies returns an empty dependency list by default

func (*BasePlugin) Description

func (p *BasePlugin) Description() string

Description returns the plugin description

func (*BasePlugin) IsInitialized

func (p *BasePlugin) IsInitialized() bool

IsInitialized returns whether the plugin is initialized

func (*BasePlugin) Name

func (p *BasePlugin) Name() string

Name returns the plugin name

func (*BasePlugin) SetInfo

func (p *BasePlugin) SetInfo(name, version, description string)

SetInfo sets the plugin information

func (*BasePlugin) SetInitialized

func (p *BasePlugin) SetInitialized(initialized bool)

SetInitialized sets the initialization status

func (*BasePlugin) Shutdown

func (p *BasePlugin) Shutdown(ctx context.Context) error

Default implementation of Shutdown

func (*BasePlugin) Version

func (p *BasePlugin) Version() string

Version returns the plugin version

type CoreExtensionPlugin

type CoreExtensionPlugin interface {
	Plugin

	// Extend server initialization
	ExtendServerInit(server *Server) error

	// Modify server configuration
	ModifyConfig(config *Settings) error

	// Register custom services
	RegisterServices(host PluginHost) error
}

CoreExtensionPlugin extends fundamental server capabilities

type DashboardConfig

type DashboardConfig struct {
	Type     string                 `json:"type"`
	Endpoint string                 `json:"endpoint"`
	Config   map[string]interface{} `json:"config"`
}

DashboardConfig provides configuration for dashboard providers

type DashboardProvider

type DashboardProvider interface {
	CreateDashboard(config DashboardConfig) error
	UpdateDashboard(id string, config DashboardConfig) error
}

DashboardProvider interface for dashboard providers

type DependencyGraph

type DependencyGraph struct {
	// contains filtered or unexported fields
}

DependencyGraph represents a dependency graph for plugins

func NewDependencyGraph

func NewDependencyGraph() *DependencyGraph

NewDependencyGraph creates a new dependency graph

func (*DependencyGraph) AddEdge

func (g *DependencyGraph) AddEdge(from, to string)

AddEdge adds an edge from 'from' to 'to'

func (*DependencyGraph) AddNode

func (g *DependencyGraph) AddNode(name string)

AddNode adds a node to the graph

func (*DependencyGraph) TopologicalSort

func (g *DependencyGraph) TopologicalSort() ([]string, error)

TopologicalSort returns a topologically sorted list of nodes

type DependencyType

type DependencyType string

DependencyType represents the type of dependency

const (
	DependencyRequired DependencyType = "required"
	DependencyOptional DependencyType = "optional"
	DependencyConflict DependencyType = "conflict"
)

type EncryptionConfig

type EncryptionConfig struct {
	Algorithm string                 `json:"algorithm"`
	KeySize   int                    `json:"key_size"`
	Config    map[string]interface{} `json:"config"`
}

EncryptionConfig provides configuration for encryption providers

type EncryptionProvider

type EncryptionProvider interface {
	Encrypt(data []byte) ([]byte, error)
	Decrypt(data []byte) ([]byte, error)
}

EncryptionProvider interface for encryption providers

type EndpointProtectionRequest

type EndpointProtectionRequest struct {
	Action      string   `json:"action"`       // "protect" or "whitelist"
	Paths       []string `json:"paths"`        // Endpoint paths to protect/whitelist
	Reason      string   `json:"reason"`       // Reason for the request
	RequesterID string   `json:"requester_id"` // Plugin requesting the change
	Temporary   bool     `json:"temporary"`    // Whether the protection is temporary
	Duration    string   `json:"duration"`     // Duration for temporary protection (e.g., "5m", "1h")
	Priority    int      `json:"priority"`     // Priority level (higher = more important)
}

EndpointProtectionRequest represents a request to protect/whitelist endpoints

type Logger

type Logger interface {
	Info(msg string, args ...interface{})
	Warn(msg string, args ...interface{})
	Error(msg string, args ...interface{})
	Debug(msg string, args ...interface{})
}

Logger interface for plugin logging

type MetricsCollector

type MetricsCollector interface {
	Collect() (map[string]interface{}, error)
	Name() string
}

MetricsCollector interface for custom metrics

type MetricsConfig

type MetricsConfig struct {
	Type     string                 `json:"type"`
	Endpoint string                 `json:"endpoint"`
	Config   map[string]interface{} `json:"config"`
}

MetricsConfig provides configuration for metrics collectors

type MiddlewareConfig

type MiddlewareConfig struct {
	Path     string                 `json:"path"`
	Priority int                    `json:"priority"`
	Config   map[string]interface{} `json:"config"`
}

MiddlewareConfig provides configuration for middleware creation

type MiddlewarePlugin

type MiddlewarePlugin interface {
	Plugin

	// Create middleware handler
	CreateMiddleware(config MiddlewareConfig) (func(http.Handler) http.Handler, error)

	// Middleware priority (lower numbers run first)
	Priority() int

	// Paths this middleware applies to
	ApplicablePaths() []string
}

Middleware plugins provide HTTP request/response processing

type MonitoringPlugin

type MonitoringPlugin interface {
	Plugin

	// Custom metrics collectors
	CreateMetricsCollector(config MetricsConfig) (MetricsCollector, error)

	// Alert providers
	CreateAlertProvider(config AlertConfig) (AlertProvider, error)

	// Dashboard providers
	CreateDashboardProvider(config DashboardConfig) (DashboardProvider, error)
}

MonitoringPlugin provides observability enhancements

type Plugin

type Plugin interface {
	// Initialize the plugin with server context and configuration
	Initialize(ctx context.Context, server PluginHost, config map[string]interface{}) error

	// Name returns the unique plugin identifier
	Name() string

	// Version returns the plugin version
	Version() string

	// Description returns human-readable plugin description
	Description() string

	// Dependencies returns required plugin dependencies
	Dependencies() []PluginDependency

	// Shutdown gracefully stops the plugin
	Shutdown(ctx context.Context) error
}

Plugin represents a loadable module that extends Hockeypuck functionality

type PluginDependency

type PluginDependency struct {
	Name     string         `json:"name"`
	Version  string         `json:"version"`
	Type     DependencyType `json:"type"`
	Optional bool           `json:"optional"`
}

PluginDependency represents a plugin dependency

type PluginEvent

type PluginEvent struct {
	Type      string                 `json:"type"`
	Source    string                 `json:"source"`
	Timestamp time.Time              `json:"timestamp"`
	Data      map[string]interface{} `json:"data"`
}

PluginEvent represents an event in the plugin system

type PluginEventHandler

type PluginEventHandler func(event PluginEvent) error

PluginEventHandler handles plugin events

type PluginHost

type PluginHost interface {
	// Register middleware handlers
	RegisterMiddleware(path string, middleware func(http.Handler) http.Handler) error

	// Register API endpoints
	RegisterHandler(pattern string, handler http.HandlerFunc) error

	// Access storage backend
	Storage() storage.Storage

	// Access configuration
	Config() *Settings

	// Access metrics system
	Metrics() *metrics.Metrics

	// Access logger
	Logger() *slog.Logger

	// Register periodic tasks
	RegisterTask(name string, interval time.Duration, task func(context.Context) error) error

	// Publish events to plugin system
	PublishEvent(event PluginEvent) error

	// Subscribe to plugin events
	SubscribeEvent(eventType string, handler PluginEventHandler) error
}

PluginHost provides server context and services to plugins

type PluginLifecycle

type PluginLifecycle struct {
	// contains filtered or unexported fields
}

Plugin lifecycle management

func NewPluginLifecycle

func NewPluginLifecycle(registry *PluginRegistry) *PluginLifecycle

NewPluginLifecycle creates a new plugin lifecycle manager

func (*PluginLifecycle) Initialize

func (l *PluginLifecycle) Initialize(ctx context.Context, configs map[string]map[string]interface{}) error

Initialize initializes plugins in dependency order

func (*PluginLifecycle) Shutdown

func (l *PluginLifecycle) Shutdown(ctx context.Context) error

Shutdown shuts down plugins in reverse dependency order

type PluginManager

type PluginManager struct {
	// contains filtered or unexported fields
}

PluginManager manages the entire plugin system

func NewPluginManager

func NewPluginManager(host PluginHost, logger Logger) *PluginManager

NewPluginManager creates a new plugin manager

func (*PluginManager) GetPlugin

func (pm *PluginManager) GetPlugin(name string) (Plugin, bool)

GetPlugin gets a plugin by name

func (*PluginManager) GetRoutes

func (pm *PluginManager) GetRoutes() map[string]http.HandlerFunc

GetRoutes returns HTTP routes from all plugins

func (*PluginManager) Initialize

func (pm *PluginManager) Initialize(ctx context.Context, configs map[string]map[string]interface{}) error

Initialize initializes all registered plugins

func (*PluginManager) ListPlugins

func (pm *PluginManager) ListPlugins() []Plugin

ListPlugins lists all registered plugins

func (*PluginManager) LoadPlugin

func (pm *PluginManager) LoadPlugin(ctx context.Context, plugin Plugin, config map[string]interface{}) error

LoadPlugin loads and initializes a plugin

func (*PluginManager) Register

func (pm *PluginManager) Register(plugin Plugin) error

Register registers a plugin with the manager

func (*PluginManager) Shutdown

func (pm *PluginManager) Shutdown(ctx context.Context) error

Shutdown shuts down all plugins

type PluginRegistry

type PluginRegistry struct {
	// contains filtered or unexported fields
}

Plugin registry for managing plugins

func GetRegistry

func GetRegistry() *PluginRegistry

GetRegistry returns the global plugin registry

func NewPluginRegistry

func NewPluginRegistry(host PluginHost) *PluginRegistry

NewPluginRegistry creates a new plugin registry

func (*PluginRegistry) Get

func (r *PluginRegistry) Get(name string) (Plugin, bool)

Get retrieves a plugin by name

func (*PluginRegistry) Initialize

func (r *PluginRegistry) Initialize(ctx context.Context, configs map[string]map[string]interface{}) error

Initialize initializes all plugins

func (*PluginRegistry) List

func (r *PluginRegistry) List() []Plugin

List returns all registered plugins

func (*PluginRegistry) Register

func (r *PluginRegistry) Register(plugin Plugin) error

Register registers a plugin

func (*PluginRegistry) Shutdown

func (r *PluginRegistry) Shutdown(ctx context.Context) error

Shutdown shuts down all plugins

type SecurityPlugin

type SecurityPlugin interface {
	Plugin

	// Authentication providers
	CreateAuthProvider(config AuthConfig) (AuthProvider, error)

	// Audit logging enhancements
	CreateAuditLogger(config AuditConfig) (AuditLogger, error)

	// Encryption providers
	CreateEncryptionProvider(config EncryptionConfig) (EncryptionProvider, error)
}

SecurityPlugin provides security enhancements

type SecurityThreatInfo

type SecurityThreatInfo struct {
	ThreatType        string  `json:"threat_type"`        // Type of threat (e.g., "malicious_ip", "suspicious_behavior")
	Severity          string  `json:"severity"`           // "low", "medium", "high", "critical"
	ClientIP          string  `json:"client_ip"`          // IP address of the threat
	UserAgent         string  `json:"user_agent"`         // User agent string
	Endpoint          string  `json:"endpoint"`           // Endpoint being accessed
	Description       string  `json:"description"`        // Human-readable description
	Confidence        float64 `json:"confidence"`         // Confidence score (0.0 to 1.0)
	RecommendedAction string  `json:"recommended_action"` // "block", "monitor", "rate_limit"
}

SecurityThreatInfo represents information about a detected threat

type Server

type Server struct {
}

Server represents the Hockeypuck server (placeholder interface)

type Settings

type Settings struct {
	Bind    string `toml:"bind"`
	DataDir string `toml:"dataDir"`
}

Settings represents the server configuration (simplified interface)

type StorageConfig

type StorageConfig struct {
	Type   string                 `json:"type"`
	Config map[string]interface{} `json:"config"`
}

StorageConfig provides configuration for storage backend creation

type StoragePlugin

type StoragePlugin interface {
	Plugin

	// Create storage backend instance
	CreateStorage(config StorageConfig) (storage.Storage, error)

	// Backend type identifier
	BackendType() string

	// Required configuration schema
	ConfigSchema() map[string]interface{}
}

StoragePlugin provides custom storage implementations

Jump to

Keyboard shortcuts

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