Skip to content

Commit

Permalink
Support license detection for SBOM scan
Browse files Browse the repository at this point in the history
  • Loading branch information
bedla committed Feb 6, 2024
1 parent 6ccc0a5 commit 5d7784b
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions pkg/commands/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -1123,8 +1123,14 @@ func NewSBOMCommand(globalFlags *flag.GlobalFlagGroup) *cobra.Command {
reportFlagGroup.DependencyTree = nil // disable '--dependency-tree'
reportFlagGroup.ReportFormat = nil // TODO: support --report summary

scanners := flag.ScannersFlag.Clone()
scanners.Values = xstrings.ToStringSlice(types.Scanners{
types.VulnerabilityScanner,
types.LicenseScanner,
})
scanFlagGroup := flag.NewScanFlagGroup()
scanFlagGroup.Scanners = nil // disable '--scanners' as it always scans for vulnerabilities
scanFlagGroup.Scanners = scanners // allow only 'vuln' and 'license' options for '--scanners'

scanFlagGroup.IncludeDevDeps = nil // disable '--include-dev-deps'
scanFlagGroup.Parallel = nil // disable '--parallel'

Expand All @@ -1137,11 +1143,12 @@ func NewSBOMCommand(globalFlags *flag.GlobalFlagGroup) *cobra.Command {
ScanFlagGroup: scanFlagGroup,
SBOMFlagGroup: flag.NewSBOMFlagGroup(),
VulnerabilityFlagGroup: flag.NewVulnerabilityFlagGroup(),
LicenseFlagGroup: flag.NewLicenseFlagGroup(),
}

cmd := &cobra.Command{
Use: "sbom [flags] SBOM_PATH",
Short: "Scan SBOM for vulnerabilities",
Short: "Scan SBOM for vulnerabilities and licenses",
GroupID: groupScanning,
Example: ` # Scan CycloneDX and show the result in tables
$ trivy sbom /path/to/report.cdx
Expand All @@ -1164,9 +1171,6 @@ func NewSBOMCommand(globalFlags *flag.GlobalFlagGroup) *cobra.Command {
return xerrors.Errorf("flag error: %w", err)
}

// Scan vulnerabilities
options.Scanners = types.Scanners{types.VulnerabilityScanner}

return artifact.Run(cmd.Context(), options, artifact.TargetSBOM)
},
SilenceErrors: true,
Expand Down

0 comments on commit 5d7784b

Please sign in to comment.