middleware

package
v0.260418.2200 Latest Latest
Warning

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

Go to latest
Published: Apr 18, 2026 License: MPL-2.0 Imports: 23 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// MaxRequestBodySize is the maximum size of request body to store (1MB)
	MaxRequestBodySize = 1024 * 1024
	// MaxRequestBodies is the maximum number of request bodies to keep in memory
	MaxRequestBodies = 50
)

Request body storage configuration

Variables

This section is empty.

Functions

func CORS

func CORS() gin.HandlerFunc

CORS returns a CORS middleware handler

func CORSWithConfig

func CORSWithConfig(config CORSConfig) gin.HandlerFunc

CORSWithConfig returns a CORS middleware handler with custom configuration

func RateLimitMiddleware

func RateLimitMiddleware(rl *RateLimiter, authPaths ...string) gin.HandlerFunc

RateLimitMiddleware returns a Gin middleware for rate limiting This is specifically for auth endpoints (handshake, execute)

Types

type APITokenStore added in v0.260418.2200

type APITokenStore interface {
	ValidateToken(tokenID string) (*db.APITokenRecord, error)
	UpdateLastUsed(tokenID string) error
}

APITokenStore interface for token validation (abstracted for testability)

type AuthMiddleware

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

AuthMiddleware provides authentication middleware for different types of authentication

func NewAuthMiddleware

func NewAuthMiddleware(cfg *config.Config, jwtManager *auth.JWTManager, apiTokenManager *auth.APITokenManager, apiTokenStore APITokenStore) *AuthMiddleware

NewAuthMiddleware creates a new authentication middleware

func (*AuthMiddleware) ModelAuthMiddleware

func (am *AuthMiddleware) ModelAuthMiddleware() gin.HandlerFunc

ModelAuthMiddleware middleware for OpenAI and Anthropic API authentication The auth will support both `Authorization` and `X-Api-Key` Supports three authentication methods (in order of precedence): 1. JWT API tokens (when multi-tenant is enabled) 2. Global config model token (backward compatibility) 3. Enterprise context JWT (X-TBE-Context-JWT header)

func (*AuthMiddleware) UserAuthMiddleware

func (am *AuthMiddleware) UserAuthMiddleware() gin.HandlerFunc

UserAuthMiddleware middleware for UI and control API authentication

type CORSConfig

type CORSConfig struct {
	AllowOrigins    string
	AllowMethods    string
	AllowHeaders    string
	ExposeHeaders   string
	MaxAge          int
	HandlePreflight bool
}

CORSConfig defines the configuration for CORS middleware

type ErrorDetail

type ErrorDetail struct {
	Message string `json:"message"`
	Type    string `json:"type"`
	Code    string `json:"code,omitempty"`
}

ErrorDetail represents error details

type ErrorLogMiddleware

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

ErrorLogMiddleware logs requests and responses to a file when debug mode is enabled

func NewErrorLogMiddleware

func NewErrorLogMiddleware(logPath string, maxSizeMB int) *ErrorLogMiddleware

NewErrorLogMiddleware creates a new debug middleware

func (*ErrorLogMiddleware) Disable

func (dm *ErrorLogMiddleware) Disable()

Disable disables debug logging

func (*ErrorLogMiddleware) Enable

func (dm *ErrorLogMiddleware) Enable() error

Enable enables debug logging

func (*ErrorLogMiddleware) IsEnabled

func (dm *ErrorLogMiddleware) IsEnabled() bool

IsEnabled returns whether debug logging is enabled

func (*ErrorLogMiddleware) Middleware

func (dm *ErrorLogMiddleware) Middleware() gin.HandlerFunc

Middleware returns the Gin middleware function

func (*ErrorLogMiddleware) SetFilterExpression

func (dm *ErrorLogMiddleware) SetFilterExpression(expression string) error

SetFilterExpression recompiles and sets a new filter expression

func (*ErrorLogMiddleware) Stop

func (dm *ErrorLogMiddleware) Stop()

Stop closes the log file

type ErrorResponse

type ErrorResponse struct {
	Error ErrorDetail `json:"error"`
}

ErrorResponse represents an error response

type FilterContext

type FilterContext struct {
	StatusCode int    `expr:"StatusCode"`
	Method     string `expr:"Method"`
	Path       string `expr:"Path"`
	Query      string `expr:"Query"`
}

FilterContext provides the context for filter expression evaluation

type MultiModeMemoryLogMiddleware

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

MultiModeMemoryLogMiddleware provides Gin middleware with both persistent and memory log storage Logs are written to: 1. Multi-mode logger (text + JSON files for persistence) 2. Memory (circular buffer for quick API access) 3. Request body store (pure memory, referenced by body_ref ID)

func NewMultiModeMemoryLogMiddleware

func NewMultiModeMemoryLogMiddleware(multiLogger *obs.MultiLogger) *MultiModeMemoryLogMiddleware

NewMultiModeMemoryLogMiddleware creates a new middleware with both persistent and memory logging

func (*MultiModeMemoryLogMiddleware) Clear

func (m *MultiModeMemoryLogMiddleware) Clear()

Clear removes all log entries from memory

func (*MultiModeMemoryLogMiddleware) GetEntries

func (m *MultiModeMemoryLogMiddleware) GetEntries() []*logrus.Entry

GetEntries returns all log entries from memory in chronological order

func (*MultiModeMemoryLogMiddleware) GetEntriesByLevel

func (m *MultiModeMemoryLogMiddleware) GetEntriesByLevel(level logrus.Level) []*logrus.Entry

GetEntriesByLevel returns log entries from memory matching the specified level

func (*MultiModeMemoryLogMiddleware) GetEntriesSince

func (m *MultiModeMemoryLogMiddleware) GetEntriesSince(since time.Time) []*logrus.Entry

GetEntriesSince returns log entries from memory after the specified time

func (*MultiModeMemoryLogMiddleware) GetLatestEntries

func (m *MultiModeMemoryLogMiddleware) GetLatestEntries(n int) []*logrus.Entry

GetLatestEntries returns the newest N log entries from memory

func (*MultiModeMemoryLogMiddleware) GetRequestBodyStore added in v0.260418.2200

func (m *MultiModeMemoryLogMiddleware) GetRequestBodyStore() *obs.RequestBodyStore

GetRequestBodyStore returns the request body store for retrieving stored request bodies

func (*MultiModeMemoryLogMiddleware) Middleware

Middleware returns a Gin middleware compatible with gin.Logger() It logs all HTTP requests to both the multi-mode logger and memory

func (*MultiModeMemoryLogMiddleware) Size

Size returns the current number of stored log entries in memory

type RateLimiter

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

RateLimiter provides rate limiting functionality

func NewRateLimiter

func NewRateLimiter(maxAttempts int, windowSize, blockDuration time.Duration) *RateLimiter

NewRateLimiter creates a new rate limiter

func (*RateLimiter) Cleanup

func (rl *RateLimiter) Cleanup()

cleanup runs periodically to remove expired entries

func (*RateLimiter) GetStats

func (rl *RateLimiter) GetStats() map[string]interface{}

GetStats returns rate limiting statistics

func (*RateLimiter) ResetIP

func (rl *RateLimiter) ResetIP(ip string)

ResetIP resets the rate limit for a specific IP (admin use only)

Jump to

Keyboard shortcuts

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