engine

package
v0.53.0 Latest Latest
Warning

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

Go to latest
Published: Aug 1, 2026 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Overview

Package engine orchestrates a run: it expands a Saga into scan jobs (controllers × components), executes them with bounded parallelism, and aggregates each control's results. Content-hash caching and the full describe→publish pipeline build on this.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Waivable added in v0.52.0

func Waivable(control string) bool

Waivable reports whether a failure under this control name is one --allow-scan-errors can accept.

The flag means "a scanner could not run and I accept a partial result" — the reader has other controls that did run and is choosing to proceed on those. A planning failure is not a scanner: it is the run saying there was nothing to do at all, so there is no partial result to accept. Treating the two alike turns the flag into "pass anyway", and a PASS that means "we did not look" is the worst thing this tool can print.

(sbom) stays waivable on purpose. A missing SBOM is missing evidence, not a missing check — the controls still ran and their verdict still means something.

Types

type Engine

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

Engine plans and runs scans against a registry of controllers and scanners.

func New

func New(reg *Registry, opts ...Option) *Engine

New creates an Engine over the given registry. By default it runs up to NumCPU jobs concurrently.

func (*Engine) Plan

func (e *Engine) Plan(model saga.Model) ([]PlannedJob, error)

Plan expands the model into scan jobs. Only registered controllers that are enabled (project-level for project-scoped controllers, per-component for component-scoped ones) are planned. Controllers are visited in name order for determinism.

func (*Engine) Run

func (e *Engine) Run(ctx context.Context, model saga.Model) (Result, error)

Run plans and executes scans with bounded concurrency, then aggregates per control. Scan errors do not abort the run; they are collected and returned (joined) alongside whatever results succeeded. Honors ctx cancellation.

type Option

type Option func(*Engine)

Option configures an Engine.

func WithAllowedEffects added in v0.45.0

func WithAllowedEffects(kinds []string) Option

WithAllowedEffects accepts scanner effects for this invocation, on top of whatever the Saga accepts. Backs the --allow-effects flag.

func WithCache

func WithCache(c cache.Cache) Option

WithCache enables result caching: a cache hit for a job's key reuses the stored report instead of re-scanning. A nil cache disables caching (the default).

func WithConcurrency

func WithConcurrency(n int) Option

WithConcurrency sets the maximum number of scan jobs running at once. Values < 1 are ignored (the default is used).

func WithPrioritization added in v0.5.0

func WithPrioritization(p Prioritizer) Option

WithPrioritization stamps each finding with a priority band computed by p. Priority is applied per run (never cached), since it depends on the component's current classification.

func WithSBOM added in v0.41.0

func WithSBOM(g sbom.Generator) Option

WithSBOM supplies the generator used when a Saga enables config.sbom. Injected rather than imported so pkg/engine stays free of a concrete tool, exactly as it does for scanners. Nil (the default) means a Saga asking for SBOMs gets an error rather than silence.

type PlannedJob

type PlannedJob struct {
	Control string
	Job     plugin.ScanJob
	// Component names the part of the application being scanned, empty for a project-scoped
	// control. Carried alongside the classification rather than derived from it: exposure and
	// criticality say what a component is worth, and a reader also has to know which one it was.
	Component   string
	Exposure    saga.Exposure
	Criticality saga.Criticality
}

PlannedJob is a scan job tagged with the control that produced it and the risk classification of the component it targets (empty for project-scoped controls).

type Prioritizer added in v0.5.0

type Prioritizer func(control string, exposure saga.Exposure, criticality saga.Criticality, res sarif.Result) string

Prioritizer computes a finding's priority band from its control and its component's risk classification. Injected via WithPrioritization so the engine stays decoupled from the prioritization matrices and per-control severity floors; nil disables priority stamping.

type Registry

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

Registry holds the controllers and scanners available to the engine, keyed by name.

func NewRegistry

func NewRegistry() *Registry

NewRegistry returns an empty registry.

func (*Registry) Controller

func (r *Registry) Controller(name string) (plugin.Controller, bool)

Controller returns the named controller, if registered.

func (*Registry) Controllers added in v0.18.0

func (r *Registry) Controllers() []plugin.Controller

Controllers returns all registered controllers, sorted by Info().Name for stable output.

func (*Registry) RegisterController

func (r *Registry) RegisterController(c plugin.Controller)

RegisterController adds a controller, keyed by its Info().Name.

func (*Registry) RegisterScanner

func (r *Registry) RegisterScanner(s plugin.Scanner)

RegisterScanner adds a scanner, keyed by its Info().Name.

func (*Registry) Scanner

func (r *Registry) Scanner(name string) (plugin.Scanner, bool)

Scanner returns the named scanner, if registered.

func (*Registry) Scanners added in v0.7.0

func (r *Registry) Scanners() []plugin.Scanner

Scanners returns all registered scanners, sorted by Info().Name for stable output.

type Result

type Result struct {
	Controls map[string]plugin.ControlResult
	Stats    Stats
	// Suppressed counts findings a config.exclude rule matched. They are still present in the
	// reports, marked with their justification — this is how many stopped counting.
	Suppressed int
	// LapsedExclusions are exclusions past their expiry date, which no longer suppress anything.
	// Reported so a finding that used to be accepted does not simply reappear with nothing to
	// say why.
	LapsedExclusions []saga.ExcludeRule
	// Effects records what this run did to its targets beyond reading them, deduplicated. Only
	// scans that actually executed count: a cache hit means the traffic was not sent this time,
	// and a record of effects has to describe what happened rather than what was configured.
	Effects []plugin.Effect
	// SBOMs are the Software Bills of Materials produced when the Saga enables config.sbom.
	// Evidence rather than judgement: they carry no findings and never affect the verdict.
	SBOMs []sbom.Document
	// ScanErrors records, per control, what stopped it completing — a missing scanner binary, a
	// tool that exited badly, a plan that couldn't be built. A control listed here checked less
	// than it was asked to, so its absence of findings is not evidence of absence, and callers
	// that treat an empty report as "clean" would be wrong.
	ScanErrors map[string][]string
}

Result is the outcome of a run: one aggregated ControlResult per control, plus run statistics.

type Stats

type Stats struct {
	Jobs      int
	Scans     int
	CacheHits int
	// Deduped counts jobs that reused an identical scan already running/completed in this run
	// (in-run singleflight), rather than scanning or hitting the persistent cache.
	Deduped int
	// Concurrency is the maximum number of scan jobs run in parallel for this run (the
	// effective value after applying WithConcurrency or the NumCPU default).
	Concurrency int
	// Duration is wall-clock for the whole run, and ByControl is how long each control's jobs
	// took summed across them. Reported because "why is this slow" is a question a job count
	// cannot answer: with concurrency the parts do not add up to the whole, and the control
	// worth attention is the slowest one rather than the one with the most jobs.
	Duration  time.Duration
	ByControl map[string]time.Duration
}

Stats summarizes execution, including cache effectiveness.

Jump to

Keyboard shortcuts

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