scanpipeline

package
v0.20.0 Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2026 License: MIT Imports: 21 Imported by: 1 module, 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 scanpipeline runs the scan pipeline that assembles a neutral sbom.Inventory. Run is the full flow over a source path: collect files → fingerprint → scan → source declared dependencies from the same tree (the lockfile graph, and the manifests no lockfile covers, via sbom/depsource) → gather + enrich the requested layers via the SDK's decoration pipeline (scanoss.DecorationPipeline). Enricher is the gathering half on its own, for callers that already have an inventory (a scan result, or a parsed SBOM). Rendering is left to sbom.Generate — this package does not render. Layers to gather are driven by the caller's request, never by any output format.

Index

Constants

View Source
const (
	LayerCollect     = "collect"     // local: walking the tree and applying the filters
	LayerFingerprint = "fingerprint" // local: hashing the collected files
	LayerManifests   = "manifests"   // local: parsing dependency manifests
	LayerUpload      = "upload"      // remote: uploading the WFP
	LayerScan        = "scan"        // remote: the server-side scan
	LayerClassify    = "classify"    // remote+local: scoring snippet matches with the classifier
)

Layers the pipeline runs itself or delegates. Enrichment layers are not listed: they report under their API service name, which the SDK already supplies.

Variables

This section is empty.

Functions

This section is empty.

Types

type ClassifySummary added in v0.16.0

type ClassifySummary struct {
	snippetmatch.Summary

	// Removed is how many snippet matches FilterFalsePositives removed.
	Removed int
	// DeniedStatus is the HTTP status (401 or 403) the API answered a file-contents request with,
	// or 0. Every match needs its OSS file, so a key without file-contents access scores nothing.
	DeniedStatus int
	// Err is set when the classifier could not start; nothing was scored.
	Err error
}

ClassifySummary is what snippet classification did, for the caller to report: the classifier's own tally plus what the pipeline did around it.

type Enricher added in v0.8.0

type Enricher struct {
	Client   *scanoss.Client
	Services []scanoss.Service
	Reporter scanoss.DecorationReporter
}

Enricher is what the requested layers are gathered with: a client to ask, the layers to ask for, and who to report progress to. Run builds one from its Options; a caller that already has an inventory — from a scan result, or parsed from an existing SBOM — builds one directly.

The zero Services asks for nothing, which is not an error: a bare scan does no decoration work.

func (Enricher) Enrich added in v0.8.0

func (e Enricher) Enrich(ctx context.Context, inv *sbom.Inventory) error

Enrich attaches the requested purl-layers to the inventory's components in place — licenses/cryptography/geoprovenance inline on each component, vulnerabilities as the flat top-level list. It is format-blind, keyed purely by PURL (+ version).

Enrichment is non-fatal, so the inventory is usable whatever this returns: a layer that failed is simply absent. The error names what did not arrive, which is the only way to tell an inventory with no licences because the project declares none from one with no licences because every request failed. With no layer requested, or no component to decorate, it makes no API call and returns nil.

type Options

type Options struct {
	Client *scanoss.Client // required

	// Services are the decoration services to gather over the components. The caller resolves
	// these — from a flag, a config file, or nothing at all — and hands over the result: this
	// package knows services, not whatever vocabulary produced them.
	Services []scanoss.Service

	// SourceDeclared asks for declared dependencies to be sourced from the dependency manifests in
	// the same tree, and merged into the inventory alongside the scan's detected components. It is
	// not a decoration service: nothing is fetched, the manifests already carry resolved PURLs.
	SourceDeclared bool
	// Deps says how the dependency manifests are resolved; the zero value reads lockfiles only.
	Deps depsource.Options

	SourcePath string // file or directory to scan (required)
	Threads    int    // fingerprint workers (<1 => 1)
	// ScanFilters collects the files to fingerprint; DependencyFilters collects the
	// manifests, when SourceDeclared asks for them.
	//
	// Both are the caller's to build, because only the caller knows which of the values
	// in them came from a user flag and which from a profile. This package used to
	// derive the second from the first by copying selected fields, which meant a field
	// the dependency profile had deliberately set was overwritten by the scan's.
	ScanFilters       filter.Options
	DependencyFilters filter.Options
	ScanOptions       []scanoss.ScanOption // per-scan tuning (chunk size, poll interval, BOM, ...)
	// WFPOptions tunes how each file is fingerprinted (see wfp.Option) — today, whether the
	// leading licence header, comments and imports are dropped. Empty gets pkg/wfp's defaults,
	// which drop them; pass wfp.WithoutSkipHeaders to fingerprint files whole.
	WFPOptions []wfp.Option

	// WFP2 opts the whole scan into token-aware (wfp2) snippet matching: each file's
	// fingerprint gains a wfp2= block (wfp.WithWFP2) and the scan request carries the
	// enable_wfp2 opt-in (scanoss.WithWFP2), so the two always travel together — generating
	// the blocks without sending the opt-in, or the reverse, would be pointless. Off by
	// default; the WFP and the request are then byte-for-byte unchanged.
	WFP2 bool

	// WFPWriter, when set, receives the WFP as it is generated, block by block. It is how a
	// caller keeps the WFP: pass a file to save it, a bytes.Buffer to hold it in memory. Nil
	// discards it after upload, which costs nothing. Block order is completion order.
	WFPWriter io.Writer

	// OnProgress receives every layer's progress. Optional; nil reports nothing. The pipeline runs
	// layers concurrently, so it must be safe for concurrent use.
	OnProgress func(Progress)

	// ClassifySnippets asks for each snippet match in the inventory to be scored by the local
	// snippet classifier, which proposes whether the match is a false positive (its reported OSS
	// and local line ranges do not correspond). The verdict lands on each match's
	// FileEvidence.SnippetClassification; nothing is removed unless FilterFalsePositives says so.
	// It is opt-in because scoring fetches the matched OSS files over the network, so a bare scan
	// pays nothing for it.
	ClassifySnippets bool
	// ClassifyThreshold overrides the classifier's decision threshold (P(false positive) at or
	// above which a match is proposed as a false positive). 0 uses snippetmatch.DefaultThreshold
	// (0.7), tuned to propose for human confirmation.
	ClassifyThreshold float64
	// FilterFalsePositives removes the snippet matches the classifier proposed as false positives,
	// and any component left with no evidence (see sbom.Inventory.RemoveFalsePositiveSnippets).
	// Ignored unless ClassifySnippets is set.
	FilterFalsePositives bool
}

Options configures Run, the full scan pipeline over a source path. Every layer reports through OnProgress — the steps the pipeline runs itself and the ones it delegates to the SDK alike, so a caller listens on one channel rather than reconciling two.

type Progress added in v0.5.0

type Progress struct {
	Layer  string // which layer is reporting; see the Layer* constants
	Status Status // where that layer is
	Done   int    // units done, only ever growing
	Total  int    // units in total; 0 when the layer cannot say
}

Progress is one update from one pipeline layer, whether the pipeline ran that layer itself or delegated it to the SDK. Every field means the same thing for every layer, so a consumer can render any update without knowing which layer produced it, or how that layer works.

Done and Total only ever grow within a layer. Where the underlying work says otherwise — the server-side scan runs in passes that each restart their own counter — it is normalised here, so that no consumer has to know.

type Reporter added in v0.5.0

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

Reporter turns the SDK's stages into this package's layer updates. Run wires one up itself; it is exported for the callers that drive the SDK directly — `results` resumes a scan and enriches it, collecting and fingerprinting nothing — so that every entry point reports layers the same way and the translation exists in one place.

Hand it to a call with WithScanReporter and WithDecorationReporter — the reporter belongs to the operation, not to the client, so the same client can serve several with different listeners.

func NewReporter added in v0.5.0

func NewReporter(on func(Progress)) *Reporter

NewReporter returns a Reporter delivering to on. A nil on makes every update a no-op.

func (*Reporter) Decorating added in v0.5.0

func (r *Reporter) Decorating(service string, done, total int)

Decorating names the layer after the service that reported it, which is what a consumer sees.

func (*Reporter) Fingerprinting added in v0.5.0

func (r *Reporter) Fingerprinting(done, total int)

func (*Reporter) Scanning added in v0.5.0

func (r *Reporter) Scanning(e scanossapi.ScanEnvelope)

Scanning normalises the poll: the server restarts its counter on every pass, so each pass owns a share of the layer's range and the result only ever grows.

func (*Reporter) Uploading added in v0.5.0

func (r *Reporter) Uploading(done, total int)

type Result

type Result struct {
	Inventory sbom.Inventory

	// ProcessErrors are the files that could not be fingerprinted, as pkg/wfp reported them.
	// A scan of 3000 files that skipped 3 unreadable ones still produced a usable WFP, so these
	// are not fatal — but which file failed and why is the caller's to judge, and a count alone
	// cannot answer it. Empty when every file was fingerprinted.
	ProcessErrors []error

	// EnrichError reports that the requested layers did not all come back. The pipeline stays
	// non-fatal — a service that fails does not discard a scan — so this is how a caller tells an
	// inventory with no licences because the project declares none from one with no licences
	// because every request failed. Nil when everything asked for arrived.
	EnrichError error

	// Classification reports the snippet classification. Nil unless Options.ClassifySnippets was
	// set and the scan produced an inventory.
	Classification *ClassifySummary
}

Result is the outcome of Run: the gathered inventory, the files that could not be fingerprinted, and whether enrichment came back whole. The WFP is not here — it streams through a temporary file, and a caller that wants it passes Options.WFPWriter.

What the filters excluded is not here: it is reported as the collect layer completing, while the scan is still ahead, rather than handed back once everything is over.

func Run

func Run(ctx context.Context, opts Options) (Result, error)

Run executes the full pipeline over Options.SourcePath: collect the files (applying the filters for a directory), fingerprint them, scan, source declared dependencies from the same file set (when the deps layer is requested), and gather + enrich into an Inventory. It owns everything from file collection onward; the caller supplies only flag-derived configuration.

type Status added in v0.5.0

type Status string

Status is a layer's position in its lifecycle, normalised so that layers as different as a local file walk and a queued server-side scan are rendered the same way.

const (
	StatusPending   Status = "pending" // known, not started: a queued scan, a layer awaiting its turn
	StatusRunning   Status = "running"
	StatusCompleted Status = "completed"
	StatusFailed    Status = "failed"
)

Jump to

Keyboard shortcuts

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