@@ -61,7 +61,8 @@ func NewResultCommand(resultsWrapper wrappers.ResultsWrapper, scanWrapper wrappe
61
61
RunE : runGetResultCommand (resultsWrapper , scanWrapper ),
62
62
}
63
63
addScanIDFlag (resultCmd , "ID to report on." )
64
- addResultFormatFlag (resultCmd , util .FormatJSON , util .FormatSummary , util .FormatSummaryConsole , util .FormatSarif )
64
+ addResultFormatFlag (resultCmd ,
65
+ util .FormatJSON , util .FormatSummary , util .FormatSummaryConsole , util .FormatSarif , util .FormatSummaryJSON )
65
66
resultCmd .PersistentFlags ().String (commonParams .TargetFlag , "cx_result" , "Output file" )
66
67
resultCmd .PersistentFlags ().String (commonParams .TargetPathFlag , "." , "Output Path" )
67
68
resultCmd .PersistentFlags ().StringSlice (commonParams .FilterFlag , []string {}, filterResultsListFlagUsage )
@@ -250,6 +251,10 @@ func createReport(
250
251
summaryRpt := createTargetName (targetFile , targetPath , "html" )
251
252
return writeHTMLSummary (summaryRpt , summary )
252
253
}
254
+ if util .IsFormat (format , util .FormatSummaryJSON ) {
255
+ summaryRpt := createTargetName (targetFile , targetPath , "json" )
256
+ return exportJSONSummaryResults (summaryRpt , summary )
257
+ }
253
258
err := fmt .Errorf ("bad report format %s" , format )
254
259
return err
255
260
}
@@ -342,6 +347,23 @@ func exportJSONResults(targetFile string, results *wrappers.ScanResultsCollectio
342
347
return nil
343
348
}
344
349
350
+ func exportJSONSummaryResults (targetFile string , results * wrappers.ResultSummary ) error {
351
+ var err error
352
+ var resultsJSON []byte
353
+ log .Println ("Creating summary JSON Report: " , targetFile )
354
+ resultsJSON , err = json .Marshal (results )
355
+ if err != nil {
356
+ return errors .Wrapf (err , "%s: failed to serialize results response " , failedGettingAll )
357
+ }
358
+ f , err := os .Create (targetFile )
359
+ if err != nil {
360
+ return errors .Wrapf (err , "%s: failed to create target file " , failedGettingAll )
361
+ }
362
+ _ , _ = fmt .Fprintln (f , string (resultsJSON ))
363
+ _ = f .Close ()
364
+ return nil
365
+ }
366
+
345
367
func convertCxResultsToSarif (results * wrappers.ScanResultsCollection ) * wrappers.SarifResultsCollection {
346
368
var sarif = new (wrappers.SarifResultsCollection )
347
369
sarif .Schema = "https://raw.githubusercontent.com/oasis-tcs/sarif-spec/master/Schemata/sarif-schema-2.1.0.json"
0 commit comments