rdev/internal/port/rate_limiter.go
jordan 72d16929ca feat: Implement hexagonal architecture with services, webhooks, queue, and telemetry
Major refactoring to hexagonal (ports & adapters) architecture:

- Add service layer (apikey_service, project_service) for business logic
- Add webhook system with dispatcher and delivery tracking
- Add command queue with priority-based processing
- Add rate limiting with sliding window algorithm
- Add audit logging for command execution
- Add OpenTelemetry integration (traces, metrics, spans)
- Add circuit breaker for fault tolerance
- Add cached repository wrapper for performance
- Add comprehensive validation package
- Add Kubernetes client integration for pod management
- Add database migrations (allowed_ips, audit_log, rate_limiting, queue, webhooks)
- Add network policy and PodDisruptionBudget for k8s
- Remove legacy executor and projects/registry packages
- Untrack secrets.yaml (now managed via envault)
- Add coverage.out to .gitignore
- Add e2e test infrastructure with docker-compose
- Add comprehensive documentation (API, architecture, operations, plans)
- Add golangci-lint config and pre-commit hook

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-25 19:57:46 -07:00

27 lines
981 B
Go

package port
import (
"context"
"github.com/orchard9/rdev/internal/domain"
)
// RateLimiter defines operations for rate limiting API requests.
type RateLimiter interface {
// CheckLimit checks if a request is allowed under the rate limit.
// Returns the result including whether allowed, remaining counts, and retry timing.
CheckLimit(ctx context.Context, keyID string) (*domain.RateLimitResult, error)
// RecordRequest records that a request was made for the given API key.
// This should be called after CheckLimit returns Allowed=true.
RecordRequest(ctx context.Context, keyID string) error
// GetLimits retrieves the rate limit configuration for an API key.
// Returns default limits if the key doesn't have custom limits set.
GetLimits(ctx context.Context, keyID string) (*domain.RateLimitConfig, error)
// Cleanup removes expired rate limit state entries.
// This should be called periodically to prevent table bloat.
Cleanup(ctx context.Context) error
}