Documentation
¶
Overview ¶
Package api provides HTTP handlers for the cloudDNS REST API.
Index ¶
- Constants
- Variables
- func AuthMiddleware(repo ports.DNSRepository) func(http.Handler) http.Handler
- func CORSMiddleware(config *CORSConfig) func(http.Handler) http.Handler
- func RateLimitMiddleware(ml *multiLimiter, cat endpointCategory) func(http.Handler) http.Handler
- func RequireRole(roles ...domain.Role) func(http.Handler) http.Handler
- func SetTrustedProxyCIDRs(cidrs []*net.IPNet)
- type CORSConfig
- type Handler
- func (h *Handler) CreateRecord(w http.ResponseWriter, r *http.Request)
- func (h *Handler) CreateZone(w http.ResponseWriter, r *http.Request)
- func (h *Handler) DeleteRecord(w http.ResponseWriter, r *http.Request)
- func (h *Handler) DeleteZone(w http.ResponseWriter, r *http.Request)
- func (h *Handler) HealthCheck(w http.ResponseWriter, r *http.Request)
- func (h *Handler) ListAuditLogs(w http.ResponseWriter, r *http.Request)
- func (h *Handler) ListRecordsForZone(w http.ResponseWriter, r *http.Request)
- func (h *Handler) ListZones(w http.ResponseWriter, r *http.Request)
- func (h *Handler) Metrics(w http.ResponseWriter, r *http.Request)
- func (h *Handler) RegisterRoutes(mux *http.ServeMux)
- func (h *Handler) UpdateRecord(w http.ResponseWriter, r *http.Request)
- type RateLimitConfig
Constants ¶
const CtxRole contextKey = "role"
CtxRole is the context key for the role extracted from the API key.
const CtxTenantID contextKey = "tenant_id"
CtxTenantID is the context key for the tenant ID extracted from the API key.
Variables ¶
var (
TrustedProxyCIDRs []*net.IPNet
)
TrustedProxyCIDRs contains CIDR ranges for trusted proxies. If set, only requests from these IPs will have X-Real-IP/X-Forwarded-For honored. Use SetTrustedProxyCIDRs to update safely.
Functions ¶
func AuthMiddleware ¶
AuthMiddleware validates API keys and injects tenant context into requests.
func CORSMiddleware ¶
func CORSMiddleware(config *CORSConfig) func(http.Handler) http.Handler
CORSMiddleware returns middleware that adds CORS headers.
func RateLimitMiddleware ¶
RateLimitMiddleware creates middleware that applies per-tenant and per-IP rate limiting. Pass a pointer to the multiLimiter from the Handler and the endpoint category.
func RequireRole ¶
RequireRole returns middleware that restricts access to users with one of the given roles.
func SetTrustedProxyCIDRs ¶
SetTrustedProxyCIDRs updates the trusted proxy CIDRs list safely.
Types ¶
type CORSConfig ¶
type CORSConfig struct {
AllowedOrigins []string
AllowedMethods []string
AllowedHeaders []string
MaxAge int
}
CORSConfig holds CORS settings from environment.
func DefaultCORSConfig ¶
func DefaultCORSConfig() *CORSConfig
DefaultCORSConfig creates config from CORS_ALLOWED_ORIGINS env var (comma-separated). When the env var is not set, no origins are allowed — operators must explicitly configure.
type Handler ¶
type Handler struct {
// contains filtered or unexported fields
}
Handler handles HTTP requests for zone and record management.
func New ¶
func New(svc ports.DNSService, repo ports.DNSRepository, logger *slog.Logger) *Handler
New creates and returns a new Handler instance.
func (*Handler) CreateRecord ¶
func (h *Handler) CreateRecord(w http.ResponseWriter, r *http.Request)
CreateRecord handles POST /zones/{id}/records requests.
func (*Handler) CreateZone ¶
func (h *Handler) CreateZone(w http.ResponseWriter, r *http.Request)
CreateZone handles POST /zones requests.
func (*Handler) DeleteRecord ¶
func (h *Handler) DeleteRecord(w http.ResponseWriter, r *http.Request)
DeleteRecord handles DELETE /zones/{zone_id}/records/{id} requests.
func (*Handler) DeleteZone ¶
func (h *Handler) DeleteZone(w http.ResponseWriter, r *http.Request)
DeleteZone handles DELETE /zones/{id} requests.
func (*Handler) HealthCheck ¶
func (h *Handler) HealthCheck(w http.ResponseWriter, r *http.Request)
HealthCheck handles health check requests.
func (*Handler) ListAuditLogs ¶
func (h *Handler) ListAuditLogs(w http.ResponseWriter, r *http.Request)
ListAuditLogs retrieves audit entries for a specific tenant via the management API.
func (*Handler) ListRecordsForZone ¶
func (h *Handler) ListRecordsForZone(w http.ResponseWriter, r *http.Request)
ListRecordsForZone handles GET /zones/{id}/records requests.
func (*Handler) ListZones ¶
func (h *Handler) ListZones(w http.ResponseWriter, r *http.Request)
ListZones handles GET /zones requests.
func (*Handler) Metrics ¶
func (h *Handler) Metrics(w http.ResponseWriter, r *http.Request)
Metrics handles Prometheus metrics scraping requests.
func (*Handler) RegisterRoutes ¶
RegisterRoutes registers the API routes with the provided ServeMux.
func (*Handler) UpdateRecord ¶
func (h *Handler) UpdateRecord(w http.ResponseWriter, r *http.Request)
UpdateRecord handles PUT /zones/{zone_id}/records/{id} requests.
type RateLimitConfig ¶
type RateLimitConfig struct {
// Tenant limits
TenantReadRate float64
TenantReadBurst int
TenantWriteRate float64
TenantWriteBurst int
TenantDeleteZoneRate float64
TenantDeleteZoneBurst int
TenantDeleteRecordRate float64
TenantDeleteRecordBurst int
// IP limits
IPReadRate float64
IPReadBurst int
IPWriteRate float64
IPWriteBurst int
// Bounds
MaxTenants int
MaxIPs int
}
RateLimitConfig holds configuration for rate limiting.
func DefaultRateLimitConfig ¶
func DefaultRateLimitConfig() RateLimitConfig
DefaultRateLimitConfig returns the default rate limit configuration.