Documentation
¶
Index ¶
- Constants
- type APIRateLimiter
- func (rl *APIRateLimiter) Allow(key string) bool
- func (rl *APIRateLimiter) Enabled() bool
- func (rl *APIRateLimiter) Middleware(next http.Handler) http.Handler
- func (rl *APIRateLimiter) Reset(key string)
- func (rl *APIRateLimiter) SetEnabled(enabled bool)
- func (rl *APIRateLimiter) Stop()
- func (rl *APIRateLimiter) UpdateConfig(config *RateLimiterConfig)
- func (rl *APIRateLimiter) Wait(ctx context.Context, key string) error
- type AuthMiddleware
- type EnsureAccountFunc
- type GetUserFromUserAuthFunc
- type PATUsageTracker
- type RateLimiterConfig
- type SyncUserJWTGroupsFunc
Constants ¶
const ( RateLimitingEnabledEnv = "NB_API_RATE_LIMITING_ENABLED" RateLimitingBurstEnv = "NB_API_RATE_LIMITING_BURST" RateLimitingRPMEnv = "NB_API_RATE_LIMITING_RPM" )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type APIRateLimiter ¶ added in v0.59.13
type APIRateLimiter struct {
// contains filtered or unexported fields
}
APIRateLimiter manages rate limiting for API tokens
func NewAPIRateLimiter ¶ added in v0.59.13
func NewAPIRateLimiter(config *RateLimiterConfig) *APIRateLimiter
NewAPIRateLimiter creates a new API rate limiter with the given configuration
func (*APIRateLimiter) Allow ¶ added in v0.59.13
func (rl *APIRateLimiter) Allow(key string) bool
Allow checks if a request for the given key (token) is allowed
func (*APIRateLimiter) Enabled ¶ added in v0.70.0
func (rl *APIRateLimiter) Enabled() bool
func (*APIRateLimiter) Middleware ¶ added in v0.64.2
func (rl *APIRateLimiter) Middleware(next http.Handler) http.Handler
Middleware returns an HTTP middleware that rate limits requests by client IP. Returns 429 Too Many Requests if the rate limit is exceeded.
func (*APIRateLimiter) Reset ¶ added in v0.59.13
func (rl *APIRateLimiter) Reset(key string)
Reset removes the rate limiter for a specific key
func (*APIRateLimiter) SetEnabled ¶ added in v0.70.0
func (rl *APIRateLimiter) SetEnabled(enabled bool)
func (*APIRateLimiter) Stop ¶ added in v0.59.13
func (rl *APIRateLimiter) Stop()
Stop stops the cleanup goroutine
func (*APIRateLimiter) UpdateConfig ¶ added in v0.70.0
func (rl *APIRateLimiter) UpdateConfig(config *RateLimiterConfig)
type AuthMiddleware ¶ added in v0.15.0
type AuthMiddleware struct {
// contains filtered or unexported fields
}
AuthMiddleware middleware to verify personal access tokens (PAT) and JWT tokens
func NewAuthMiddleware ¶ added in v0.15.0
func NewAuthMiddleware( authManager serverauth.Manager, ensureAccount EnsureAccountFunc, syncUserJWTGroups SyncUserJWTGroupsFunc, getUserFromUserAuth GetUserFromUserAuthFunc, rateLimiter *APIRateLimiter, meter metric.Meter, ) *AuthMiddleware
NewAuthMiddleware instance constructor
type EnsureAccountFunc ¶ added in v0.37.0
type GetUserFromUserAuthFunc ¶ added in v0.42.0
type PATUsageTracker ¶ added in v0.60.5
type PATUsageTracker struct {
// contains filtered or unexported fields
}
PATUsageTracker tracks PAT usage metrics
func NewPATUsageTracker ¶ added in v0.60.5
NewPATUsageTracker creates a new PAT usage tracker with metrics
func (*PATUsageTracker) IncrementUsage ¶ added in v0.60.5
func (t *PATUsageTracker) IncrementUsage(token string)
IncrementUsage increments the usage counter for a given token
func (*PATUsageTracker) Stop ¶ added in v0.60.5
func (t *PATUsageTracker) Stop()
Stop stops the reporting goroutine
type RateLimiterConfig ¶ added in v0.59.13
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 ¶ added in v0.59.13
func DefaultRateLimiterConfig() *RateLimiterConfig
DefaultRateLimiterConfig returns a default configuration
func RateLimiterConfigFromEnv ¶ added in v0.70.0
func RateLimiterConfigFromEnv() (cfg *RateLimiterConfig, enabled bool)