api

package
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: Nov 15, 2026 License: Apache-2.0 Imports: 24 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package api implements the scanner's HTTP API: POST /v1/scans submits a target, GET /v1/scans/{id} polls its result, and /healthz, /readyz serve standard liveness/readiness checks. It is net/http only - no router dependency, using the method+wildcard patterns net/http.ServeMux has supported since Go 1.22.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Options

type Options struct {
	Policy             policy.Policy
	MaxBodyBytes       int64
	MaxConcurrentScans int
	MaxInFlight        int
	ScanTimeout        time.Duration

	// ScanOptions is the base scanner.Options built from the server's configuration file
	// (app.ScanOptions(cfg)) - analyzers, timeouts, and per-analyzer settings. handleSubmit copies it,
	// applies request analyzers and blocking severity, then sets the policy baseline and resolved
	// source root.
	ScanOptions scanner.Options

	// AllowedTargetKinds restricts what POST /v1/scans will accept.
	// Defaults to remote only - anything that starts a process or reads a
	// local path is opt-in per deployment.
	AllowedTargetKinds []model.TargetKind

	// TokenEnv names the environment variable holding the bearer token required on every request
	// except /healthz and /readyz. Empty means no token; NewServer accepts that only when no
	// sensitive target kind is enabled. The secret is read once during construction.
	TokenEnv string

	// BaseDir bounds a submitted source/static-target path: it is resolved
	// against BaseDir with filepath.EvalSymlinks and a containment check.
	// For TargetSource, Options.Root for the scan is set from the result;
	// for TargetStatic, Target.Path is. Required whenever TargetSource or
	// TargetStatic is in AllowedTargetKinds.
	BaseDir string

	// RecordRetention bounds how long a stored record survives before the
	// next put evicts it. Defaults to defaultRecordRetention.
	RecordRetention time.Duration
	// MaxStoredRecords caps the store regardless of age. Defaults to
	// defaultMaxStoredRecords.
	MaxStoredRecords int
	// MaxStoredBytes caps the store by the summed size of every stored
	// result, oldest evicted first, regardless of MaxStoredRecords: a
	// remote target the caller controls decides how large its own
	// discovery snapshot is, so a count cap alone does not bound memory.
	// Defaults to defaultMaxStoredBytes.
	MaxStoredBytes int64

	// Logger receives detail that must not go back to an API caller - for
	// example the underlying filesystem error behind a redacted "target
	// could not be read" response. Defaults to a discard logger.
	Logger *slog.Logger
}

Options configures a Server. Zero values fall back to the defaults above.

type Server

type Server struct {
	// contains filtered or unexported fields
}

Server is the HTTP API. Build one with NewServer and mount Handler()

func NewServer

func NewServer(sc *scanner.Scanner, opts Options) (*Server, error)

NewServer builds a Server around an already-configured *scanner.Scanner; its Preparer and registry decide what scans can do. Startup fails when sensitive target kinds lack authentication or the filesystem boundary needed to prevent unauthenticated process execution or arbitrary file reads.

func (*Server) Handler

func (s *Server) Handler() http.Handler

Handler returns the API's http.Handler. Every route but the two health checks requires the configured bearer token, when one is configured.

func (*Server) Shutdown

func (s *Server) Shutdown(context.Context) error

Shutdown marks the server not-ready. It does not cancel scans already running; callers still shut those down via the context passed to Handler's own server (e.g. http.Server.Shutdown at the transport level).

Jump to

Keyboard shortcuts

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