Skip to content

Commit b91778e

Browse files
committed
include sbom param in git audit cmd
1 parent 8a6904e commit b91778e

File tree

6 files changed

+21
-10
lines changed

6 files changed

+21
-10
lines changed

cli/docs/flags.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ var commandFlags = map[string][]string{
183183
scanProjectKey, Watches, ScanVuln, Fail,
184184
// Scan params
185185
Threads, ExclusionsAudit,
186-
Sca, Iac, Sast, Secrets, WithoutCA, SecretValidation,
186+
Sca, Iac, Sast, Secrets, WithoutCA, SecretValidation, Sbom,
187187
// Output params
188188
Licenses, OutputFormat, ExtendedTable, OutputDir, UploadRtRepoPath,
189189
// Scan Logic params

cli/gitcommands.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ func GitAuditCmd(c *components.Context) error {
7070
} else if len(subScans) > 0 {
7171
gitAuditCmd.SetScansToPerform(subScans)
7272
}
73+
gitAuditCmd.SetIncludeSbom(shouldIncludeSbom(c, format))
7374
if threads, err := pluginsCommon.GetThreadsCount(c); err != nil {
7475
return err
7576
} else {

cli/scancommands.go

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ func ScanCmd(c *components.Context) error {
287287
SetBaseRepoPath(repoPath).
288288
SetIncludeVulnerabilities(c.GetBoolFlagValue(flags.Vuln) || shouldIncludeVulnerabilities(c)).
289289
SetIncludeLicenses(c.GetBoolFlagValue(flags.Licenses)).
290-
SetIncludeSbom(c.GetBoolFlagValue(flags.Sbom)).
290+
SetIncludeSbom(shouldIncludeSbom(c, format)).
291291
SetFail(c.GetBoolFlagValue(flags.Fail)).
292292
SetPrintExtendedTable(c.GetBoolFlagValue(flags.ExtendedTable)).
293293
SetBypassArchiveLimits(c.GetBoolFlagValue(flags.BypassArchiveLimits)).
@@ -453,16 +453,11 @@ func CreateAuditCmd(c *components.Context) (string, string, *coreConfig.ServerDe
453453
auditCmd.SetScaScanStrategy(scaScanStrategy)
454454
auditCmd.SetViolationGenerator(violationGenerator)
455455
auditCmd.SetUploadCdxResults(uploadResults).SetRtResultRepository(c.GetStringFlagValue(flags.UploadRtRepoPath))
456-
// Make sure include SBOM is only set if the output format supports it
457-
includeSbom := c.GetBoolFlagValue(flags.Sbom)
458-
if includeSbom && format != outputFormat.Table && format != outputFormat.CycloneDx {
459-
log.Warn(fmt.Sprintf("The '--%s' flag is only supported with the 'table' or 'cyclonedx' output format. The SBOM will not be included in the output.", flags.Sbom))
460-
}
461456
auditCmd.SetTargetRepoPath(addTrailingSlashToRepoPathIfNeeded(c)).
462457
SetProject(getProject(c)).
463458
SetIncludeVulnerabilities(c.GetBoolFlagValue(flags.Vuln)).
464459
SetIncludeLicenses(c.GetBoolFlagValue(flags.Licenses)).
465-
SetIncludeSbom(includeSbom).
460+
SetIncludeSbom(shouldIncludeSbom(c, format)).
466461
SetFail(c.GetBoolFlagValue(flags.Fail)).
467462
SetPrintExtendedTable(c.GetBoolFlagValue(flags.ExtendedTable)).
468463
SetMinSeverityFilter(minSeverity).
@@ -709,7 +704,7 @@ func DockerScan(c *components.Context, image string) error {
709704
SetBaseRepoPath(addTrailingSlashToRepoPathIfNeeded(c)).
710705
SetIncludeVulnerabilities(c.GetBoolFlagValue(flags.Vuln) || shouldIncludeVulnerabilities(c)).
711706
SetIncludeLicenses(c.GetBoolFlagValue(flags.Licenses)).
712-
SetIncludeSbom(c.GetBoolFlagValue(flags.Sbom)).
707+
SetIncludeSbom(shouldIncludeSbom(c, format)).
713708
SetFail(c.GetBoolFlagValue(flags.Fail)).
714709
SetPrintExtendedTable(c.GetBoolFlagValue(flags.ExtendedTable)).
715710
SetBypassArchiveLimits(c.GetBoolFlagValue(flags.BypassArchiveLimits)).

cli/utils.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,3 +187,12 @@ func getFlagValueAsString(c *components.Context, flag components.Flag) string {
187187
}
188188
return ""
189189
}
190+
191+
func shouldIncludeSbom(c *components.Context, format outputFormat.OutputFormat) bool {
192+
// Make sure include SBOM is only set if the output format supports it
193+
includeSbom := c.GetBoolFlagValue(flags.Sbom)
194+
if includeSbom && format != outputFormat.Table && format != outputFormat.CycloneDx {
195+
log.Warn(fmt.Sprintf("The '--%s' flag is only supported with the 'table' or 'cyclonedx' output format. The SBOM will not be included in the output.", flags.Sbom))
196+
}
197+
return includeSbom
198+
}

commands/git/audit/gitaudit.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ func toAuditParams(params GitAuditParams) *sourceAudit.AuditParams {
8787
params.gitContext.Source.GitRepoHttpsCloneUrl,
8888
params.resultsContext.IncludeVulnerabilities,
8989
params.resultsContext.IncludeLicenses,
90-
false,
90+
params.includeSbom,
9191
)
9292
auditParams.SetResultsContext(resultContext)
9393
log.Debug(fmt.Sprintf("Results context: %+v", resultContext))

commands/git/audit/gitauditparams.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ type GitAuditParams struct {
2323
failBuild bool
2424
// Scan params
2525
scansToPerform []utils.SubScanType
26+
includeSbom bool
2627
threads int
2728
exclusions []string
2829
// Output params
@@ -163,3 +164,8 @@ func (gap *GitAuditParams) SetRtResultRepository(rtResultRepository string) *Git
163164
func (gap *GitAuditParams) RtResultRepository() string {
164165
return gap.rtResultRepository
165166
}
167+
168+
func (gap *GitAuditParams) SetIncludeSbom(includeSbom bool) *GitAuditParams {
169+
gap.includeSbom = includeSbom
170+
return gap
171+
}

0 commit comments

Comments
 (0)