scanopts

package
v3.125.0 Latest Latest
Warning

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

Go to latest
Published: Oct 16, 2026 License: AGPL-3.0 Imports: 15 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 scanopts builds a pipeline.Options from a cobra command's flags.

It exists so there is exactly one place that knows how a scan-family flag becomes an analysis input. The language server never calls it: it fills pipeline.Options from LSP client settings instead. That is the point of the split, and it is why this package depends on cobra while internal/pipeline does not.

Index

Constants

View Source
const (
	// ManufacturerFlag names the organization that created the BOM.
	ManufacturerFlag = "bom-manufacturer"
	// ManufacturerEnv is the environment equivalent, for a runner that sets it
	// once per job rather than per invocation.
	ManufacturerEnv = "VULNETIX_BOM_MANUFACTURER"
	// LifecycleFlag overrides the capture stages the engine would derive.
	LifecycleFlag = "lifecycle"
)

Variables

View Source
var FailOnRules = []string{
	"low", "medium", "high", "critical",
	"kev", "exploit=poc", "exploit=active", "exploit=weaponized",
	"malware", "eol", "unpinned", "unprotected", "lag=", "cooldown=",
}

FailOnRules are the values `--fail-on` accepts, for help and completion.

View Source
var NotReplayed = map[string]string{

	"rule":          "the suggestion loads the pack that supplied its rule, not every pack",
	"rule-id":       "--explain narrows the run to the rule it names",
	"explain":       "the suggestion names its own query",
	"only":          "the suggestion names the scanner that owns the finding",
	"skip":          "the suggestion names the scanner that owns the finding",
	"evaluate-sast": "feature selection", "evaluate-sca": "feature selection",
	"evaluate-licenses": "feature selection", "evaluate-secrets": "feature selection",
	"evaluate-iac": "feature selection", "enable-containers": "feature selection",
	"no-sast": "feature selection", "no-sca": "feature selection", "no-licenses": "feature selection",
	"no-secrets": "feature selection", "no-containers": "feature selection", "no-iac": "feature selection",

	"allow": "licence stage", "allow-file": "licence stage", "license-mode": "licence stage",
	"policy-file": "licence stage", "exceptions-file": "licence stage",

	"bom-manufacturer": "document label", "lifecycle": "document label",
	"project": "document label", "cluster": "document label", "namespace": "document label",
	"environment": "document label", "tag": "document label",

	"concurrency": "how fast, not what is found",
	"no-banner":   "display",

	"view": "display", "filter": "display", "min-severity": "display", "sort": "display",
	"show": "display", "hide": "display", "verbose": "display", "quiet": "display",
	"color": "display", "ascii": "display", "width": "display", "silent": "display",
	"no-progress": "display", "no-exploits": "display", "no-remediation": "display",
	"show-introduced-paths": "display", "paths": "display", "show-detected": "display",
	"show-all-manifests": "display", "results-only": "display", "no-analytics": "telemetry",

	"output": "output destination", "format": "output destination",
	"output-file": "output destination", "snippet-context": "shapes SARIF output only",

	"fail-on": "gate", "severity": "gate", "block-malware": "gate", "block-eol": "gate",
	"block-eol-severity": "gate", "block-unpinned": "gate", "exploits": "gate",
	"version-lag": "gate", "cooldown": "gate", "jail": "gate",

	"dry-run": "mode", "list-default-rules": "mode", "from-memory": "mode",
	"fresh-exploits": "mode", "fresh-advisories": "mode", "fresh-vulns": "mode",
	"sca-autofix": "mode", "sca-autofix-strategy": "mode", "sca-autofix-manifest": "mode",
	"sca-autofix-max-major-bump": "mode", "yes": "mode",
	"disable-memory": "an explain run writes no memory anyway",
	"no-aibom":       "an explain run skips the AIBOM pass",
	"no-cbom":        "an explain run skips the CBOM pass",
	"no-malscan":     "an explain run skips the malscan pass",
	"no-upload":      "an explain run uploads nothing",
}

NotReplayed lists the flags a suggested command does not repeat, with why.

Functions

func AddAuthorshipFlags added in v3.99.0

func AddAuthorshipFlags(flags *pflag.FlagSet)

AddAuthorshipFlags registers the authoring-identity flags on a command.

func AddDeploymentFlags added in v3.97.0

func AddDeploymentFlags(f *pflag.FlagSet)

AddDeploymentFlags registers the deployment-context flags on a flag set.

Registered on the whole scan family via addScanFlags, plus cdx, bom import and upload. AGENTS.md requires a family-wide flag to be honoured family-wide, and these are read in exactly one place — deploymentContextFromFlags — so no subcommand can quietly ignore them.

func AddDisplayFlags added in v3.115.0

func AddDisplayFlags(cmd *cobra.Command)

AddDisplayFlags registers the flags that only change what is shown. A command that replays or inspects results (report, defend) takes these and not the gates, so a flag that would be silently ignored is never offered.

func AddGateFlags added in v3.115.0

func AddGateFlags(cmd *cobra.Command)

AddGateFlags registers the flags that decide the exit code.

func AddSurfaceFlags added in v3.115.0

func AddSurfaceFlags(cmd *cobra.Command)

AddSurfaceFlags registers the output and gating vocabulary on a scan-family command: what to show, what to hide, what to filter, and when to fail.

It is registered by addScanFlags, so sca, sast, secrets, containers, iac and scan accept the same words and honour them the same way. The legacy flags that these supersede are not removed; they keep working and are hidden from help.

func FromCommand

func FromCommand(cmd *cobra.Command) (pipeline.Options, error)

FromCommand reads every scan-family flag that maps directly onto an analysis input and returns the corresponding pipeline.Options.

It covers only what the flags alone determine. Four groups of fields are deliberately left zero for the caller to fill, because the flags do not decide them:

  • Files, GitCtx, SysInfo, SeedBOM, VulnetixSeedBOM — discovered by detection and collection passes that run after flag parsing.
  • The No* feature booleans — derived from the --evaluate-*/--no-* toggles together with the invoking command's identity.
  • LockedKinds — specializedRuleKinds(cmd.Name()).
  • RespectGitignore — computed from the --*-include-ignored family, whose policy differs per command.

The gate fields (severity, exploits, block-*, version-lag, cooldown) are populated here but may be overwritten afterwards by org quality-gate policy, which always wins, even over an explicitly passed flag. That override must happen after this call and before any of those values is consumed.

Validation that would otherwise be duplicated per command lives here: --severity and --exploits are normalised and checked against the canonical lists, so an invalid value fails before any work starts rather than being silently ignored deep in a stage.

func HideLegacyFlags added in v3.115.0

func HideLegacyFlags(cmd *cobra.Command)

HideLegacyFlags removes the superseded flags from help without disabling them.

func LegacyNotes added in v3.115.0

func LegacyNotes(cmd *cobra.Command) []string

LegacyNotes returns one line for each superseded flag the user actually passed. It is empty unless stderr is a terminal and CI is not set: a pipeline's logs are not the place to nag.

func LifecycleOverrideFromCommand added in v3.99.0

func LifecycleOverrideFromCommand(cmd *cobra.Command) ([]cdx.LifecyclePhase, error)

LifecycleOverrideFromCommand reads --lifecycle. Nil means "derive from what the scan read"; an unknown phase is rejected rather than treated as a custom one, because a typo silently becoming a custom lifecycle name is indistinguishable downstream from a deliberate one.

func ManufacturerSourcesFromCommand added in v3.99.0

func ManufacturerSourcesFromCommand(cmd *cobra.Command) cdx.ManufacturerSources

ManufacturerSourcesFromCommand gathers every candidate for metadata.manufacturer that flags and the environment can supply.

The git fallback is deliberately left unset here and filled in where git context is already collected, so resolving the manufacturer never causes the repository to be walked a second time.

func NormaliseExploits

func NormaliseExploits(value string) (string, error)

NormaliseExploits lower-cases and validates an --exploits value. An empty value means "no exploit gate" and is returned unchanged.

func NormaliseSeverity

func NormaliseSeverity(value string) (string, error)

NormaliseSeverity lower-cases and validates a --severity value. An empty value means "no severity gate" and is returned unchanged.

func ParseRuleRefs

func ParseRuleRefs(args []string) ([]sast.RuleRef, error)

ParseRuleRefs turns --rule arguments into sast.RuleRefs, failing on the first malformed reference rather than silently dropping it.

func ParseSet added in v3.115.0

func ParseSet(values []string) []string

ParseSet flattens repeatable, comma-separated flag values into a list of lower-case words.

func ReplayArgs added in v3.124.0

func ReplayArgs(cmd, target *cobra.Command) []string

ReplayArgs returns the flags the user set on cmd that a suggested command on target must repeat, in the order pflag visits them. A flag target does not register is dropped: `scan --rule-registry X` must not become an `sca` command that refuses to start.

func StampDeploymentJSON added in v3.97.0

func StampDeploymentJSON(data []byte, d DeploymentContext) ([]byte, error)

StampDeploymentJSON applies deployment labels to already-serialised CycloneDX, for callers that hold bytes rather than a document.

This used to be a second, map-based implementation of ApplyDeploymentContext. The reason was real at the time: the CLI's own CycloneDX model did not declare most of the specification, so decoding a document into it and re-encoding silently dropped everything it did not know about — and a function asked only to label a document has no business narrowing it.

The model is now the shared one in vdb-cyclonedx, which round-trips unmodelled members rather than discarding them, so the duplicate is gone and this is a decode, the one implementation, and an encode. The guarantee is pinned by TestStampDeploymentJSONPreservesUnknownFields.

Types

type DeploymentContext added in v3.97.0

type DeploymentContext = cdx.DeploymentContext

DeploymentContext is the deployment label set. Aliased from internal/cdx so call sites read naturally without a second type to keep in step.

func DeploymentFromCommand added in v3.97.0

func DeploymentFromCommand(cmd *cobra.Command) DeploymentContext

DeploymentFromCommand reads the deployment flags, falling back to CI.

type FailOn added in v3.115.0

type FailOn struct {
	Severity    string
	Exploits    string
	Malware     bool
	EOL         bool
	EOLSeverity string
	Unpinned    bool
	Unprotected bool
	Lag         int
	CooldownDay int
}

FailOn is a parsed `--fail-on` value.

It is a vocabulary over the gates that already exist, not a second set of gates: ApplyTo folds it into the same pipeline.Options fields the legacy flags populate, so there is one evaluation path and one place an org quality gate can override. Seven flags that each meant "exit 1 when" become one.

func ParseFailOn added in v3.115.0

func ParseFailOn(values []string) (FailOn, error)

ParseFailOn parses repeatable, comma-separated `--fail-on` values. The first unrecognised rule is an error that lists every valid one.

func (FailOn) ApplyTo added in v3.115.0

func (f FailOn) ApplyTo(opts *pipeline.Options)

ApplyTo folds the rules into opts. Where a legacy flag already set the same gate the stricter of the two wins, so mixing vocabularies never loosens a pipeline.

type Surface added in v3.115.0

type Surface struct {
	Display report.Options
	Explain string
	FailOn  FailOn
	// Strict and AcceptDefended mirror the pipeline.Options fields.
	Strict, AcceptDefended bool
	// Color is auto, always or never.
	Color string
}

Surface is the parsed output and gating vocabulary.

func SurfaceFromCommand added in v3.115.0

func SurfaceFromCommand(cmd *cobra.Command) (Surface, error)

SurfaceFromCommand reads and validates the vocabulary registered by AddSurfaceFlags. A command that did not register it gets the zero Surface.

Jump to

Keyboard shortcuts

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