httpapi

package
v0.230.0 Latest Latest
Warning

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

Go to latest
Published: May 29, 2026 License: Apache-2.0 Imports: 27 Imported by: 0

README

HTTP Interface Module

HTTP exposes DeltaScope audit and metadata-aware review capabilities as a JSON service.

Files

File Responsibility
audit_metadata.go Executes one HTTP audit request through offline or direct metadata-aware flows and adds adapter context to the JSON response
audit_metadata_test.go Verifies HTTP metadata-aware execution wiring, additive context, and direct metadata client lifecycle handling
handler.go Binds Gin HTTP requests to the public audit/rule/capability APIs, auth checks, JSON responses, structured access logging, and health/readiness endpoints
handler_test.go Verifies HTTP request binding, error mapping, and JSON response shape
rule_catalog.go Builds HTTP rule-list, rule-detail, and capability payloads from the shipped catalog metadata
server.go Assembles the HTTP handler and long-running server wiring

Exports

  • NewHandler(configPath, version, opts ...HandlerOption) (http.Handler, error)
  • WithAuthConfig(AuthConfig) HandlerOption
  • WithMiddlewareConfig(MiddlewareConfig) HandlerOption
  • WithAuditFunc(func(context.Context, deltascope.Request) (deltascope.Result, error)) HandlerOption
  • WithMetadataConfig(MetadataConfig) HandlerOption
  • NewServer(addr, configPath, version, opts ...HandlerOption)

Notes

  • The HTTP layer is adapter-only: it reuses the shared public audit API and metadata-preparation helpers instead of reimplementing dialect or schema logic.
  • Routing uses Gin while keeping the public JSON API contract unchanged.
  • API-key auth is optional and configured through adapter options.
  • Rate limiting is optional and supports api-key or ip bucketing.
  • /metrics is exposed in Prometheus format by default and can be disabled via middleware config.
  • Default middleware chain is request-id -> recovery -> timeout -> metrics -> auth -> rate-limit -> access log.
  • Config hot-reload is achieved by re-reading the configured policy path on each audit request, so file updates take effect without restarting the server.
  • Current scope supports offline and metadata-aware audit plus HTTP-native rule discovery and capability discovery.
  • Responses preserve the public DeltaScope result body and add a context block describing mode, dialect/schema provenance, and metadata source.
  • Direct connection input accepts connect_timeout (duration string like 5s); empty/omitted/0s falls back to runtime config default, invalid/negative values return 400.

Dependencies

  • Upstream: cmd/deltascope-server
  • Downstream: pkg/deltascope, internal/application/policy, internal/domain/rule/catalog

Update Rule

  • If members/interfaces/dependencies change, update this file in same change.

Documentation

Overview

Package httpapi exposes the HTTP adapter for DeltaScope. input: parsed HTTP audit requests, shared metadata-preparation helpers, and public audit execution functions output: additive HTTP audit context plus offline or metadata-aware audit execution results pos: HTTP adapter glue between request-scoped metadata inputs and the public DeltaScope audit API note: if this file changes, update this header and module README.md.

Package httpapi exposes the HTTP adapter for DeltaScope. input: HTTP requests carrying SQL audit payloads plus service-level config/version wiring output: JSON audit, rule-catalog, capability, health, readiness, version, structured error responses, and structured access log lines pos: interface adapter between net/http and the public DeltaScope audit API note: if this file changes, update this header and module README.md.

Package httpapi exposes the HTTP adapter for DeltaScope. input: HTTP rule-discovery requests plus shipped catalog and capability metadata output: JSON rule-list, rule-detail, and capability payloads for the HTTP adapter pos: HTTP discovery helpers above the domain rule catalog and shared JSON writers note: if this file changes, update this header and module README.md.

Package httpapi exposes the HTTP adapter for DeltaScope. input: listen addresses plus service-level config/version wiring output: ready-to-run HTTP server instances for the JSON audit service pos: long-running net/http server assembly for the HTTP interface milestone note: if this file changes, update this header and module README.md.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewHandler

func NewHandler(configPath, version string, opts ...HandlerOption) (http.Handler, error)

NewHandler returns the JSON HTTP adapter for DeltaScope.

func NewServer

func NewServer(addr, configPath, version string, opts ...HandlerOption) (*http.Server, error)

NewServer builds the DeltaScope HTTP service.

Types

type AuthConfig added in v0.10.0

type AuthConfig struct {
	Enabled    bool
	Keys       []string
	AllowPaths []string
}

AuthConfig controls API-key authentication on the HTTP adapter.

type HandlerOption added in v0.10.0

type HandlerOption func(*handlerOptions)

HandlerOption configures NewHandler behavior.

func WithAuditFunc added in v0.10.0

WithAuditFunc overrides the audit execution function (primarily for tests).

func WithAuthConfig added in v0.10.0

func WithAuthConfig(cfg AuthConfig) HandlerOption

WithAuthConfig enables API-key authentication on selected routes.

func WithMetadataConfig added in v0.63.0

func WithMetadataConfig(cfg MetadataConfig) HandlerOption

WithMetadataConfig sets runtime-level metadata defaults for the HTTP adapter.

func WithMiddlewareConfig added in v0.10.0

func WithMiddlewareConfig(cfg MiddlewareConfig) HandlerOption

WithMiddlewareConfig overrides default middleware settings.

func WithSlogLogger added in v0.62.0

func WithSlogLogger(sl *slog.Logger) HandlerOption

WithSlogLogger sets the structured logger. The slog.Logger is bridged to a *log.Logger for use by existing recovery and access-log middleware. If sl is nil the option is a no-op and the default log.Default() logger is used.

type MetadataConfig added in v0.63.0

type MetadataConfig struct {
	ConnectTimeout time.Duration
}

MetadataConfig carries runtime-level metadata defaults for the HTTP adapter.

type MiddlewareConfig added in v0.10.0

type MiddlewareConfig struct {
	RequestTimeout time.Duration
	Logger         *log.Logger
	RateLimit      RateLimitConfig
	MetricsEnabled *bool
	TrustedProxies []string
}

MiddlewareConfig controls default middleware behavior.

type RateLimitConfig added in v0.10.0

type RateLimitConfig struct {
	Enabled    bool
	RPS        float64
	Burst      int
	KeyBy      string
	AllowPaths []string
}

RateLimitConfig controls per-key request throttling.

Jump to

Keyboard shortcuts

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