middleware

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2025 License: BSD-3-Clause, AGPL-3.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type APIRateLimiter

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

APIRateLimiter manages rate limiting for API tokens

func NewAPIRateLimiter

func NewAPIRateLimiter(config *RateLimiterConfig) *APIRateLimiter

NewAPIRateLimiter creates a new API rate limiter with the given configuration

func (*APIRateLimiter) Allow

func (rl *APIRateLimiter) Allow(key string) bool

Allow checks if a request for the given key (token) is allowed

func (*APIRateLimiter) Reset

func (rl *APIRateLimiter) Reset(key string)

Reset removes the rate limiter for a specific key

func (*APIRateLimiter) Stop

func (rl *APIRateLimiter) Stop()

Stop stops the cleanup goroutine

func (*APIRateLimiter) Wait

func (rl *APIRateLimiter) Wait(ctx context.Context, key string) error

Wait blocks until the rate limiter allows another request for the given key Returns an error if the context is canceled

type AuthMiddleware

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

AuthMiddleware middleware to verify personal access tokens (PAT) and JWT tokens

func NewAuthMiddleware

func NewAuthMiddleware(
	authManager serverauth.Manager,
	ensureAccount EnsureAccountFunc,
	syncUserJWTGroups SyncUserJWTGroupsFunc,
	getUserFromUserAuth GetUserFromUserAuthFunc,
	rateLimiterConfig *RateLimiterConfig,
	meter metric.Meter,
) *AuthMiddleware

NewAuthMiddleware instance constructor

func (*AuthMiddleware) Handler

func (m *AuthMiddleware) Handler(h http.Handler) http.Handler

Handler method of the middleware which authenticates a user either by JWT claims or by PAT

type EnsureAccountFunc

type EnsureAccountFunc func(ctx context.Context, userAuth auth.UserAuth) (string, string, error)

type GetUserFromUserAuthFunc

type GetUserFromUserAuthFunc func(ctx context.Context, userAuth auth.UserAuth) (*types.User, error)

type PATUsageTracker added in v0.2.1

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

PATUsageTracker tracks PAT usage metrics

func NewPATUsageTracker added in v0.2.1

func NewPATUsageTracker(ctx context.Context, meter metric.Meter) (*PATUsageTracker, error)

NewPATUsageTracker creates a new PAT usage tracker with metrics

func (*PATUsageTracker) IncrementUsage added in v0.2.1

func (t *PATUsageTracker) IncrementUsage(token string)

IncrementUsage increments the usage counter for a given token

func (*PATUsageTracker) Stop added in v0.2.1

func (t *PATUsageTracker) Stop()

Stop stops the reporting goroutine

type RateLimiterConfig

type RateLimiterConfig struct {
	// RequestsPerMinute defines the rate at which tokens are replenished
	RequestsPerMinute float64
	// Burst defines the maximum number of requests that can be made in a burst
	Burst int
	// CleanupInterval defines how often to clean up old limiters (how often garbage collection runs)
	CleanupInterval time.Duration
	// LimiterTTL defines how long a limiter should be kept after last use (age threshold for removal)
	LimiterTTL time.Duration
}

RateLimiterConfig holds configuration for the API rate limiter

func DefaultRateLimiterConfig

func DefaultRateLimiterConfig() *RateLimiterConfig

DefaultRateLimiterConfig returns a default configuration

type SyncUserJWTGroupsFunc

type SyncUserJWTGroupsFunc func(ctx context.Context, userAuth auth.UserAuth) error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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