server

package
v0.0.8 Latest Latest
Warning

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

Go to latest
Published: Jul 7, 2025 License: MIT Imports: 15 Imported by: 0

Documentation

Overview

Package server provides a gRPC server framework for HKP plugins

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BasePlugin

type BasePlugin struct {
	Name         string
	Version      string
	Description  string
	Capabilities []string
	Config       map[string]interface{}
}

BasePlugin provides a basic implementation of PluginImplementation that plugins can embed and override specific methods

func (*BasePlugin) GetInfo

func (p *BasePlugin) GetInfo() PluginInfo

GetInfo implements PluginImplementation

func (*BasePlugin) HandleHTTPRequest

func (p *BasePlugin) HandleHTTPRequest(ctx context.Context, req *proto.HTTPRequest) (*proto.HTTPResponse, error)

HandleHTTPRequest implements PluginImplementation with a default pass-through

func (*BasePlugin) HandleKeyChange

func (p *BasePlugin) HandleKeyChange(ctx context.Context, event *proto.KeyChangeEvent) error

HandleKeyChange implements PluginImplementation with a no-op

func (*BasePlugin) Initialize

func (p *BasePlugin) Initialize(config map[string]interface{}) error

Initialize implements PluginImplementation

func (*BasePlugin) Shutdown

func (p *BasePlugin) Shutdown() error

Shutdown implements PluginImplementation

type ConfigHelper

type ConfigHelper struct {
	Config map[string]interface{}
}

ConfigHelper provides utility methods for working with plugin configuration

func NewConfigHelper

func NewConfigHelper(config map[string]interface{}) *ConfigHelper

NewConfigHelper creates a new config helper

func (*ConfigHelper) GetBool

func (c *ConfigHelper) GetBool(key string, defaultValue bool) bool

GetBool retrieves a boolean configuration value

func (*ConfigHelper) GetFloat

func (c *ConfigHelper) GetFloat(key string, defaultValue float64) float64

GetFloat retrieves a float configuration value

func (*ConfigHelper) GetInt

func (c *ConfigHelper) GetInt(key string, defaultValue int) int

GetInt retrieves an integer configuration value

func (*ConfigHelper) GetString

func (c *ConfigHelper) GetString(key string, defaultValue string) string

GetString retrieves a string configuration value

func (*ConfigHelper) GetStringSlice

func (c *ConfigHelper) GetStringSlice(key string) []string

GetStringSlice retrieves a string slice configuration value

func (*ConfigHelper) GetSubConfig

func (c *ConfigHelper) GetSubConfig(key string) map[string]interface{}

GetSubConfig retrieves a nested configuration map

func (*ConfigHelper) MustGetString

func (c *ConfigHelper) MustGetString(key string) string

MustGetString retrieves a string configuration value or panics

type EventHandler

type EventHandler func(ctx context.Context, event *proto.Event) error

EventHandler processes events

type Options

type Options struct {
	// Logger to use
	Logger *logrus.Logger
	// Address to listen on (default: from environment)
	Address string
	// Maximum message size (default: 4MB)
	MaxMessageSize int
	// Enable reflection for debugging
	EnableReflection bool
}

Options for creating a plugin server

type PluginImplementation

type PluginImplementation interface {
	// Initialize is called when the plugin starts
	Initialize(config map[string]interface{}) error

	// GetInfo returns plugin metadata
	GetInfo() PluginInfo

	// HandleHTTPRequest processes HTTP requests
	HandleHTTPRequest(ctx context.Context, req *proto.HTTPRequest) (*proto.HTTPResponse, error)

	// HandleKeyChange processes key change events
	HandleKeyChange(ctx context.Context, event *proto.KeyChangeEvent) error

	// Shutdown is called when the plugin stops
	Shutdown() error
}

PluginImplementation is the interface that plugin developers must implement

type PluginInfo

type PluginInfo struct {
	Name         string
	Version      string
	Description  string
	Capabilities []string
	Metadata     map[string]string
}

PluginInfo contains plugin metadata

type PluginServer

type PluginServer struct {
	proto.UnimplementedHKPPluginServer
	// contains filtered or unexported fields
}

PluginServer implements the gRPC HKPPlugin service

func NewPluginServer

func NewPluginServer(impl PluginImplementation, opts *Options) *PluginServer

NewPluginServer creates a new plugin server

func (*PluginServer) CheckRateLimit

func (s *PluginServer) CheckRateLimit(ctx context.Context, check *proto.RateLimitCheck) (*proto.RateLimitResponse, error)

func (*PluginServer) GetInfo

func (s *PluginServer) GetInfo(ctx context.Context, req *proto.Empty) (*proto.PluginInfo, error)

func (*PluginServer) HandleHTTPRequest

func (s *PluginServer) HandleHTTPRequest(ctx context.Context, req *proto.HTTPRequest) (*proto.HTTPResponse, error)

func (*PluginServer) HandleKeyChange

func (s *PluginServer) HandleKeyChange(ctx context.Context, event *proto.KeyChangeEvent) (*proto.Event, error)

func (*PluginServer) HealthCheck

func (s *PluginServer) HealthCheck(ctx context.Context, req *proto.Empty) (*proto.HealthStatus, error)

func (*PluginServer) Initialize

func (s *PluginServer) Initialize(ctx context.Context, req *proto.InitRequest) (*proto.InitResponse, error)

func (*PluginServer) PublishEvent

func (s *PluginServer) PublishEvent(ctx context.Context, event *proto.Event) (*proto.Empty, error)

func (*PluginServer) QueryStorage

func (s *PluginServer) QueryStorage(ctx context.Context, query *proto.StorageQuery) (*proto.StorageResponse, error)

func (*PluginServer) RegisterEventHandler

func (s *PluginServer) RegisterEventHandler(eventType string, handler EventHandler)

RegisterEventHandler registers a handler for specific event types

func (*PluginServer) ReportThreat

func (s *PluginServer) ReportThreat(ctx context.Context, threat *proto.ThreatInfo) (*proto.Empty, error)

func (*PluginServer) Run

func (s *PluginServer) Run() error

Run starts the gRPC server and blocks until shutdown

func (*PluginServer) Shutdown

func (*PluginServer) Start

func (s *PluginServer) Start() error

Start begins serving gRPC requests

func (*PluginServer) Stop

func (s *PluginServer) Stop() error

Stop gracefully shuts down the server

func (*PluginServer) SubscribeEvents

func (s *PluginServer) SubscribeEvents(filter *proto.EventFilter, stream proto.HKPPlugin_SubscribeEventsServer) error

type SimplePlugin

type SimplePlugin struct {
	BasePlugin

	// Handlers that can be set by the plugin
	HTTPHandler      func(context.Context, *proto.HTTPRequest) (*proto.HTTPResponse, error)
	KeyChangeHandler func(context.Context, *proto.KeyChangeEvent) error
	InitHandler      func(map[string]interface{}) error
	ShutdownHandler  func() error
}

SimplePlugin is a helper for creating simple plugins

func (*SimplePlugin) HandleHTTPRequest

func (p *SimplePlugin) HandleHTTPRequest(ctx context.Context, req *proto.HTTPRequest) (*proto.HTTPResponse, error)

HandleHTTPRequest calls the custom handler if set

func (*SimplePlugin) HandleKeyChange

func (p *SimplePlugin) HandleKeyChange(ctx context.Context, event *proto.KeyChangeEvent) error

HandleKeyChange calls the custom handler if set

func (*SimplePlugin) Initialize

func (p *SimplePlugin) Initialize(config map[string]interface{}) error

Initialize calls the custom init handler if set

func (*SimplePlugin) Shutdown

func (p *SimplePlugin) Shutdown() error

Shutdown calls the custom handler if set

Jump to

Keyboard shortcuts

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