From 8eb019624a38bca836ba41ab95355ccdee9cc683 Mon Sep 17 00:00:00 2001 From: dortam888 Date: Wed, 11 Sep 2024 01:39:49 +0300 Subject: [PATCH 1/3] change build scan to always print violations context (as the api always runs on watches) the command will print violations alone at default and will append vulnerabilities with --vuln flag --- commands/scan/buildscan.go | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/commands/scan/buildscan.go b/commands/scan/buildscan.go index a1a59148..bd42f375 100644 --- a/commands/scan/buildscan.go +++ b/commands/scan/buildscan.go @@ -155,7 +155,7 @@ func (bsc *BuildScanCommand) runBuildScanAndPrintResults(xrayManager *xray.XrayS resultsPrinter := utils.NewResultsWriter(scanResults). SetOutputFormat(bsc.outputFormat). - SetHasViolationContext(bsc.hasViolationContext()). + SetHasViolationContext(true). SetIncludeVulnerabilities(bsc.includeVulnerabilities). SetIncludeLicenses(false). SetIsMultipleRootProject(true). @@ -176,12 +176,6 @@ func (bsc *BuildScanCommand) runBuildScanAndPrintResults(xrayManager *xray.XrayS return false, err } } - if bsc.includeVulnerabilities { - resultsPrinter.SetIncludeVulnerabilities(true) - if err = resultsPrinter.PrintScanResults(); err != nil { - return false, err - } - } } err = utils.RecordSecurityCommandSummary(utils.NewBuildScanSummary( scanResults, From 4aebc1962e9940c29bed7335a4c5b93f2445344f Mon Sep 17 00:00:00 2001 From: dortam888 Date: Wed, 11 Sep 2024 01:46:23 +0300 Subject: [PATCH 2/3] changed the record to always have true violation context and dropped the function to change the violation context --- commands/scan/buildscan.go | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/commands/scan/buildscan.go b/commands/scan/buildscan.go index bd42f375..0b705207 100644 --- a/commands/scan/buildscan.go +++ b/commands/scan/buildscan.go @@ -181,7 +181,7 @@ func (bsc *BuildScanCommand) runBuildScanAndPrintResults(xrayManager *xray.XrayS scanResults, bsc.serverDetails, bsc.includeVulnerabilities, - bsc.hasViolationContext(), + true, params.BuildName, params.BuildNumber, )) return @@ -191,10 +191,6 @@ func (bsc *BuildScanCommand) CommandName() string { return "xr_build_scan" } -func (bsc *BuildScanCommand) hasViolationContext() bool { - return bsc.buildConfiguration.GetProject() != "" -} - // There are two cases. when serverDetails.Url is configured and when serverDetails.XrayUrl and serverDetails.ArtifactoryUrl are configured // The function will return the Url if configured and will trim xray if serverDetails.Url is not configured func getActualUrl(serverDetails config.ServerDetails) (string, error) { From c70c8dbc0bed14e8d5bf04157c69b021cf323f1d Mon Sep 17 00:00:00 2001 From: dortam888 Date: Wed, 11 Sep 2024 01:53:50 +0300 Subject: [PATCH 3/3] make the code readable and fix the security job summary for build scan to always have violations requested --- commands/scan/buildscan.go | 1 - utils/securityJobSummary.go | 4 ++-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/commands/scan/buildscan.go b/commands/scan/buildscan.go index 0b705207..30c4f390 100644 --- a/commands/scan/buildscan.go +++ b/commands/scan/buildscan.go @@ -181,7 +181,6 @@ func (bsc *BuildScanCommand) runBuildScanAndPrintResults(xrayManager *xray.XrayS scanResults, bsc.serverDetails, bsc.includeVulnerabilities, - true, params.BuildName, params.BuildNumber, )) return diff --git a/utils/securityJobSummary.go b/utils/securityJobSummary.go index 210173af..1e370208 100644 --- a/utils/securityJobSummary.go +++ b/utils/securityJobSummary.go @@ -73,8 +73,8 @@ func newResultSummary(cmdResults *Results, cmdType CommandType, serverDetails *c return } -func NewBuildScanSummary(cmdResults *Results, serverDetails *config.ServerDetails, vulnerabilitiesRequested, violationsRequested bool, buildName, buildNumber string) (summary ScanCommandResultSummary) { - summary = newResultSummary(cmdResults, Build, serverDetails, vulnerabilitiesRequested, violationsRequested) +func NewBuildScanSummary(cmdResults *Results, serverDetails *config.ServerDetails, vulnerabilitiesRequested bool, buildName, buildNumber string) (summary ScanCommandResultSummary) { + summary = newResultSummary(cmdResults, Build, serverDetails, vulnerabilitiesRequested, true) summary.Args.BuildName = buildName summary.Args.BuildNumbers = []string{buildNumber} return