From ea4f508f5ee91b370c6912cde26b1a432380d037 Mon Sep 17 00:00:00 2001 From: bndw Date: Sat, 14 Feb 2026 12:14:19 -0800 Subject: feat: integrate config system into relay main.go Add support for loading configuration from YAML file via -config flag. Wire up auth, rate limiting, and metrics interceptors based on config. Changes: - Add -config flag to relay command - Use config types directly in auth package (AuthOperationConfig) - Add conversion methods: RateLimitConfig.ToRateLimiter(), MetricsConfig.ToMetrics() - Add Metrics.Serve() method for prometheus HTTP endpoint - Update main.go to initialize interceptors from config - Fix type naming: OperationAuthConfig -> AuthOperationConfig for consistency Config now supports complete relay setup including auth read/write allowlists, rate limiting, and prometheus metrics. --- internal/auth/interceptor.go | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) (limited to 'internal/auth/interceptor.go') diff --git a/internal/auth/interceptor.go b/internal/auth/interceptor.go index 42c2688..67450ce 100644 --- a/internal/auth/interceptor.go +++ b/internal/auth/interceptor.go @@ -18,28 +18,25 @@ const ( ) type InterceptorOptions struct { - Read OperationAuthConfig - Write OperationAuthConfig + Read AuthOperationConfig + Write AuthOperationConfig TimestampWindow int64 ValidatePayload bool SkipMethods []string } -// OperationAuthConfig configures auth for read or write operations. -// Three states: disabled (allow all), enabled with empty list (require auth), -// enabled with npubs (whitelist only). Npubs normalized to hex at load time. -type OperationAuthConfig struct { +type AuthOperationConfig struct { Enabled bool AllowedNpubs []string } func DefaultInterceptorOptions() *InterceptorOptions { return &InterceptorOptions{ - Read: OperationAuthConfig{ + Read: AuthOperationConfig{ Enabled: false, AllowedNpubs: nil, }, - Write: OperationAuthConfig{ + Write: AuthOperationConfig{ Enabled: false, AllowedNpubs: nil, }, @@ -154,7 +151,7 @@ func validateAuthFromContext(ctx context.Context, method string, opts *Intercept pubkey := ExtractPubkey(event) - var opConfig OperationAuthConfig + var opConfig AuthOperationConfig if isWriteMethod(method) { opConfig = opts.Write } else { -- cgit v1.2.3