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
- Variables
- func AddAuthorshipFlags(flags *pflag.FlagSet)
- func AddDeploymentFlags(f *pflag.FlagSet)
- func AddDisplayFlags(cmd *cobra.Command)
- func AddGateFlags(cmd *cobra.Command)
- func AddSurfaceFlags(cmd *cobra.Command)
- func AuthoringInputsFromCommand(cmd *cobra.Command) (cdx.AuthoringInputs, error)
- func FromCommand(cmd *cobra.Command) (pipeline.Options, error)
- func HideLegacyFlags(cmd *cobra.Command)
- func LegacyNotes(cmd *cobra.Command) []string
- func LifecycleOverrideFromCommand(cmd *cobra.Command) ([]cdx.LifecyclePhase, error)
- func ManufacturerSourcesFromCommand(cmd *cobra.Command) cdx.ManufacturerSources
- func NormaliseExploits(value string) (string, error)
- func NormaliseSeverity(value string) (string, error)
- func ParseRuleRefs(args []string) ([]sast.RuleRef, error)
- func ParseSet(values []string) []string
- func ReplayArgs(cmd, target *cobra.Command) []string
- func StampDeploymentJSON(data []byte, d DeploymentContext) ([]byte, error)
- type DeploymentContext
- type FailOn
- type Surface
Constants ¶
const ( // ManufacturerFlag names the organization that created the BOM. ManufacturerFlag = "bom-manufacturer" // ManufacturerEnv is the environment equivalent. ManufacturerEnv = "VULNETIX_BOM_MANUFACTURER" // LifecycleFlag overrides the capture stages the engine would derive. LifecycleFlag = "lifecycle" ManufacturerURLFlag = "bom-manufacturer-url" ManufacturerURLEnv = "VULNETIX_BOM_MANUFACTURER_URL" AuthorFlag = "bom-author" AuthorsEnv = "VULNETIX_BOM_AUTHORS" SupplierFlag = "bom-supplier" SupplierEnv = "VULNETIX_BOM_SUPPLIER" SupplierURLFlag = "bom-supplier-url" SupplierURLEnv = "VULNETIX_BOM_SUPPLIER_URL" SerialFlag = "bom-serial" SerialEnv = "VULNETIX_BOM_SERIAL" BOMVersionFlag = "bom-version" BOMVersionEnv = "VULNETIX_BOM_VERSION" LicenseFlag = "bom-license" LicensesEnv = "VULNETIX_BOM_LICENSES" PropertyFlag = "bom-property" PropertiesEnv = "VULNETIX_BOM_PROPERTIES" OverlayFlag = "bom-overlay" OverlayEnv = "VULNETIX_BOM_OVERLAY" ComponentNameFlag = "component-name" ComponentNameEnv = "VULNETIX_COMPONENT_NAME" ComponentVersionFlag = "component-version" ComponentVersionEnv = "VULNETIX_COMPONENT_VERSION" ComponentTypeFlag = "component-type" ComponentTypeEnv = "VULNETIX_COMPONENT_TYPE" ComponentGroupFlag = "component-group" ComponentGroupEnv = "VULNETIX_COMPONENT_GROUP" ComponentPurlFlag = "component-purl" ComponentPurlEnv = "VULNETIX_COMPONENT_PURL" )
Variables ¶
var AuthorshipFlags = []string{ ManufacturerFlag, ManufacturerURLFlag, AuthorFlag, SupplierFlag, SupplierURLFlag, SerialFlag, BOMVersionFlag, LifecycleFlag, LicenseFlag, PropertyFlag, OverlayFlag, ComponentNameFlag, ComponentVersionFlag, ComponentTypeFlag, ComponentGroupFlag, ComponentPurlFlag, }
AuthorshipFlags lists every flag AddAuthorshipFlags registers, for the tests that check they are registered and never replayed.
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.
var NotReplayed = map[string]string{}/* 104 elements not displayed */
NotReplayed lists the flags a suggested command does not repeat, with why.
Functions ¶
func AddAuthorshipFlags ¶
AddAuthorshipFlags registers the authoring-identity and customisation flags on a command that authors documents. Transformer-tier commands (bom enrich, bom import) do not register them: they have no manufacturer to claim.
func AddDeploymentFlags ¶
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 ¶
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 ¶
AddGateFlags registers the flags that decide the exit code.
func AddSurfaceFlags ¶
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 AuthoringInputsFromCommand ¶
func AuthoringInputsFromCommand(cmd *cobra.Command) (cdx.AuthoringInputs, error)
AuthoringInputsFromCommand reads everything the caller stated about the document's identity and content. A flag that was set wins; otherwise its environment variable is read. Values are parsed and checked here so a bad one fails before any work is done; what they mean is decided in internal/cdx.
func FromCommand ¶
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 ¶
HideLegacyFlags removes the superseded flags from help without disabling them.
func LegacyNotes ¶
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 ¶
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 ¶
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 ¶
NormaliseExploits lower-cases and validates an --exploits value. An empty value means "no exploit gate" and is returned unchanged.
func NormaliseSeverity ¶
NormaliseSeverity lower-cases and validates a --severity value. An empty value means "no severity gate" and is returned unchanged.
func ParseRuleRefs ¶
ParseRuleRefs turns --rule arguments into sast.RuleRefs, failing on the first malformed reference rather than silently dropping it.
func ParseSet ¶
ParseSet flattens repeatable, comma-separated flag values into a list of lower-case words.
func ReplayArgs ¶
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 ¶
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 ¶
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 ¶
func DeploymentFromCommand(cmd *cobra.Command) DeploymentContext
DeploymentFromCommand reads the deployment flags, falling back to CI.
type FailOn ¶
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 ¶
ParseFailOn parses repeatable, comma-separated `--fail-on` values. The first unrecognised rule is an error that lists every valid one.