handlers

package
v0.0.1-rc2 Latest Latest
Warning

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

Go to latest
Published: Apr 27, 2026 License: MIT Imports: 24 Imported by: 0

Documentation

Overview

Package handlers implements the WebSec101 OpenAPI server interface generated by ogen. At Phase 3, only health/version/openapi are real — the rest delegates to client.UnimplementedHandler and returns 501 via the configured error handler.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ErrorHandler

func ErrorHandler(_ context.Context, w http.ResponseWriter, _ *http.Request, err error)

ErrorHandler maps handler-returned errors to JSON envelopes. ogen's UnimplementedHandler returns ht.ErrNotImplemented; we surface that as 501. Decode failures (typed by ogenerrors) become 400. Anything else is a 500.

Types

type Handler

type Handler struct {
	client.UnimplementedHandler
	// contains filtered or unexported fields
}

Handler is the concrete ogen Handler implementation.

The embedded UnimplementedHandler causes any method we do not override to return ht.ErrNotImplemented, which the configured error handler translates to HTTP 501.

func New

func New(opts Options) *Handler

New constructs a Handler.

func (*Handler) CreateScan

func (h *Handler) CreateScan(ctx context.Context, req *client.ScanRequest) (client.CreateScanRes, error)

CreateScan implements POST /api/v1/scans.

func (*Handler) DeleteScan

func (h *Handler) DeleteScan(ctx context.Context, params client.DeleteScanParams) (client.DeleteScanRes, error)

DeleteScan implements DELETE /api/v1/scans/{guid}.

NOTE: ogen drops the Authorization header parameter from the OpenAPI spec because it conflicts with security-scheme handling. Private-mode auth is therefore deferred to Phase 13, which will introduce a dedicated header (e.g. X-Private-Token) on the spec.

func (*Handler) GetCheck

func (h *Handler) GetCheck(_ context.Context, params client.GetCheckParams) (client.GetCheckRes, error)

GetCheck implements GET /api/v1/checks/{check_id}.

func (*Handler) GetHealth

func (h *Handler) GetHealth(_ context.Context) (*client.Health, error)

GetHealth implements GET /api/v1/health.

func (*Handler) GetOpenAPI

func (h *Handler) GetOpenAPI(_ context.Context) (client.GetOpenAPIOK, error)

GetOpenAPI implements GET /api/v1/openapi.json.

func (*Handler) GetScan

func (h *Handler) GetScan(ctx context.Context, params client.GetScanParams) (client.GetScanRes, error)

GetScan implements GET /api/v1/scans/{guid} (always 200 if known).

func (*Handler) GetScanMarkdown

GetScanMarkdown implements GET /api/v1/scans/{guid}/markdown.

func (*Handler) GetScanSARIF

func (h *Handler) GetScanSARIF(ctx context.Context, params client.GetScanSARIFParams) (client.GetScanSARIFRes, error)

GetScanSARIF implements GET /api/v1/scans/{guid}/sarif.

func (*Handler) GetVersion

func (h *Handler) GetVersion(_ context.Context) (*client.Version, error)

GetVersion implements GET /api/v1/version.

func (*Handler) ListChecks

func (h *Handler) ListChecks(_ context.Context) ([]client.Check, error)

ListChecks implements GET /api/v1/checks.

func (*Handler) SSEHandler

func (h *Handler) SSEHandler(w http.ResponseWriter, r *http.Request)

SSEHandler returns an http.HandlerFunc that streams scan events for the scan id taken from chi URL param "guid". It honours the spec contract: progress, finding, completed/failed events; retry hint; heartbeat.

Behaviour by current state:

  • unknown id → 404 JSON
  • already terminal → emit one synthetic completed/failed event from the stored Scan and close
  • in flight → live-subscribe via the manager, stream until a terminal event arrives or the client drops

type Options

type Options struct {
	Store          storage.ScanStore
	Registry       *checks.Registry
	Scans          ScanService
	Policy         *safety.Policy
	Tracker        *ratelimit.TargetTracker
	AuditLog       *audit.Logger
	PerScanTimeout time.Duration
}

Options aggregates the dependencies of a Handler.

type ScanService

type ScanService interface {
	CreateScan(ctx context.Context, target *checks.Target, scanTimeout time.Duration) (*storage.Scan, error)
	Subscribe(id string) (<-chan scanner.Event, func(), error)
}

ScanService is what the handler needs from the scanner package — kept as an interface so tests can swap it.

Jump to

Keyboard shortcuts

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