Skip to content

Commit

Permalink
Add new options to control resultWriter (jfrog#1047)
Browse files Browse the repository at this point in the history
  • Loading branch information
attiasas authored and guyshe-jfrog committed Nov 30, 2023
1 parent 7c09fbd commit dda4d90
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions xray/utils/resultwriter.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,18 @@ type ResultsWriter struct {
isMultipleRoots bool
// PrintExtended, If true, show extended results.
printExtended bool
// IncludeSecrets, If true, also include secrets results as part of the output.
includeSecrets bool
// WriteFullScanResults, If true, write the full scan results to a file.
writeFullScanResults bool
// The scanType (binary,dependency)
scanType services.ScanType
// Messages - Option array of messages, to be displayed if the format is Table
messages []string
}

func NewResultsWriter(scanResults *Results) *ResultsWriter {
return &ResultsWriter{results: scanResults}
return &ResultsWriter{results: scanResults, includeSecrets: true, writeFullScanResults: true}
}

func (rw *ResultsWriter) SetOutputFormat(format OutputFormat) *ResultsWriter {
Expand Down Expand Up @@ -87,6 +91,11 @@ func (rw *ResultsWriter) SetIncludeLicenses(licenses bool) *ResultsWriter {
return rw
}

func (rw *ResultsWriter) SetIncludeSecrets(includeSecrets bool) *ResultsWriter {
rw.includeSecrets = includeSecrets
return rw
}

func (rw *ResultsWriter) SetIsMultipleRootProject(isMultipleRootProject bool) *ResultsWriter {
rw.isMultipleRoots = isMultipleRootProject
return rw
Expand All @@ -100,7 +109,11 @@ func (rw *ResultsWriter) SetPrintExtendedTable(extendedTable bool) *ResultsWrite
func (rw *ResultsWriter) SetExtraMessages(messages []string) *ResultsWriter {
rw.messages = messages
return rw
}

func (rw *ResultsWriter) SetWriteFullScanResults(writeFullScanResults bool) *ResultsWriter {
rw.writeFullScanResults = writeFullScanResults
return rw
}

// PrintScanResults prints the scan results in the specified format.
Expand All @@ -125,7 +138,7 @@ func (rw *ResultsWriter) PrintScanResults() error {
func (rw *ResultsWriter) printScanResultsTables() (err error) {
printMessages(rw.messages)
violations, vulnerabilities, licenses := SplitScanResults(rw.results.ScaResults)
if rw.results.IsIssuesFound() {
if rw.writeFullScanResults && rw.results.IsIssuesFound() {
var resultsPath string
if resultsPath, err = writeJsonResults(rw.results); err != nil {
return
Expand All @@ -146,8 +159,10 @@ func (rw *ResultsWriter) printScanResultsTables() (err error) {
return
}
}
if err = PrintSecretsTable(rw.results.ExtendedScanResults.SecretsScanResults, rw.results.ExtendedScanResults.EntitledForJas); err != nil {
return
if rw.includeSecrets {
if err = PrintSecretsTable(rw.results.ExtendedScanResults.SecretsScanResults, rw.results.ExtendedScanResults.EntitledForJas); err != nil {
return
}
}
if err = PrintIacTable(rw.results.ExtendedScanResults.IacScanResults, rw.results.ExtendedScanResults.EntitledForJas); err != nil {
return
Expand Down

0 comments on commit dda4d90

Please sign in to comment.