Skip to content

Commit d66f74f

Browse files
committed
add violations dump if requested, fix log info and include lic in upload artifact
1 parent 2597ad2 commit d66f74f

File tree

3 files changed

+30
-5
lines changed

3 files changed

+30
-5
lines changed

commands/audit/audit.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -574,11 +574,11 @@ func addScaScansToRunner(auditParallelRunner *utils.SecurityParallelRunner, audi
574574

575575
func addJasScansToRunner(auditParallelRunner *utils.SecurityParallelRunner, auditParams *AuditParams, scanResults *results.SecurityCommandResults, isNewFlow bool) (jasScanner *jas.JasScanner, generalError error) {
576576
if !scanResults.EntitledForJas {
577-
log.Info("Not entitled for JAS, skipping advance security scans...")
577+
log.Info("Advanced Security is not enabled on this system, so Advanced Security scans were skipped...")
578578
return
579579
}
580580
if !utils.IsJASRequested(scanResults.CmdType, auditParams.ScansToPerform()...) {
581-
log.Debug("JAS scans were not requested, skipping advance security scans...")
581+
log.Debug("Advanced Security scans were not initiated, so Advanced Security scans were skipped...")
582582
return
583583
}
584584
serverDetails, err := auditParams.ServerDetails()
@@ -750,8 +750,9 @@ func fetchViolations(uploadPath string, cmdResults *results.SecurityCommandResul
750750
local.WithAllowedLicenses(auditParams.allowedLicenses),
751751
enforcer.WithServerDetails(serverDetails),
752752
enforcer.WithProjectKey(auditParams.resultsContext.ProjectKey),
753-
enforcer.WithParams(auditParams.rtResultRepository, uploadPath),
753+
enforcer.WithArtifactParams(auditParams.rtResultRepository, uploadPath),
754754
enforcer.WithWatches(auditParams.resultsContext.Watches),
755+
enforcer.WithResultsOutputDir(auditParams.scanResultsOutputDir),
755756
)
756757
// Fetch violations from Xray
757758
if err = policy.EnrichWithGeneratedViolations(generator, cmdResults); err != nil {

policy/enforcer/policyenforcer.go

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package enforcer
22

33
import (
4+
"encoding/json"
45
"errors"
56
"fmt"
67
"slices"
@@ -38,7 +39,7 @@ type PolicyEnforcerViolationGenerator struct {
3839
projectKey string
3940
watches []string
4041
// Run options
41-
threadId int
42+
resultsOutputDir string
4243
}
4344

4445
func NewPolicyEnforcerViolationGenerator() *PolicyEnforcerViolationGenerator {
@@ -61,7 +62,15 @@ func WithProjectKey(projectKey string) policy.PolicyHandlerOption {
6162
}
6263
}
6364

64-
func WithParams(repo, path string) policy.PolicyHandlerOption {
65+
func WithResultsOutputDir(resultsOutputDir string) policy.PolicyHandlerOption {
66+
return func(generator policy.PolicyHandler) {
67+
if p, ok := generator.(*PolicyEnforcerViolationGenerator); ok {
68+
p.resultsOutputDir = resultsOutputDir
69+
}
70+
}
71+
}
72+
73+
func WithArtifactParams(repo, path string) policy.PolicyHandlerOption {
6574
return func(generator policy.PolicyHandler) {
6675
if p, ok := generator.(*PolicyEnforcerViolationGenerator); ok {
6776
p.rtRepository = repo
@@ -119,9 +128,23 @@ func (p *PolicyEnforcerViolationGenerator) GenerateViolations(cmdResults *result
119128
} else {
120129
log.Debug(fmt.Sprintf("Xray scans completed with %d violations", generatedViolations.Total))
121130
}
131+
if err = dumpViolationsResponseToFileIfNeeded(generatedViolations, p.resultsOutputDir); err != nil {
132+
return
133+
}
122134
return convertToViolations(cmdResults, generatedViolations.Violations)
123135
}
124136

137+
func dumpViolationsResponseToFileIfNeeded(generatedViolations *services.ViolationsResponse, resultsOutputDir string) (err error) {
138+
if resultsOutputDir == "" {
139+
return
140+
}
141+
fileContent, err := json.Marshal(generatedViolations)
142+
if err != nil {
143+
return fmt.Errorf("failed to write fetched violations to file: %s", err.Error())
144+
}
145+
return utils.DumpJsonContentToFile(fileContent, resultsOutputDir, "violations", -1)
146+
}
147+
125148
func convertToViolations(cmdResults *results.SecurityCommandResults, generatedViolations []services.XrayViolation) (convertedViolations violationutils.Violations, err error) {
126149
convertedViolations = violationutils.Violations{}
127150
for _, violation := range generatedViolations {

utils/results/output/reportartifact.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ func UploadCommandResults(serverDetails *config.ServerDetails, rtResultRepositor
2121
// Convert the scan results to CycloneDX format
2222
cdxResults, err := conversion.NewCommandResultsConvertor(conversion.ResultConvertParams{
2323
IncludeSbom: true,
24+
IncludeLicenses: true,
2425
IncludeVulnerabilities: true,
2526
}).ConvertToCycloneDx(cmdResults)
2627
if err != nil {

0 commit comments

Comments
 (0)