From e07e7da8069657c3b4a4f54ce65766f83f88d933 Mon Sep 17 00:00:00 2001 From: shiina <152995083+shiina4119@users.noreply.github.com> Date: Fri, 23 Aug 2024 22:16:25 +0530 Subject: [PATCH 01/10] cmd/validator/validator_test.go: Fix typo. --- cmd/validator/validator_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/validator/validator_test.go b/cmd/validator/validator_test.go index bcd9c03b..631af738 100644 --- a/cmd/validator/validator_test.go +++ b/cmd/validator/validator_test.go @@ -22,7 +22,7 @@ func Test_flags(t *testing.T) { {"depth set", []string{"-depth=1", "."}, 0}, {"flags set, wrong reporter", []string{"--exclude-dirs=subdir", "--reporter=wrong", "."}, 1}, {"flags set, json reporter", []string{"--exclude-dirs=subdir", "--reporter=json", "."}, 0}, - {"flags set, junit reported", []string{"--exclude-dirs=subdir", "--reporter=junit", "."}, 0}, + {"flags set, junit reporter", []string{"--exclude-dirs=subdir", "--reporter=junit", "."}, 0}, {"bad path", []string{"/path/does/not/exit"}, 1}, {"exclude file types set", []string{"--exclude-file-types=json", "."}, 0}, {"multiple paths", []string{"../../test/fixtures/subdir/good.json", "../../test/fixtures/good.json"}, 0}, From 29672bcb03898122d86d9b6ebc45ac683190197e Mon Sep 17 00:00:00 2001 From: shiina <152995083+shiina4119@users.noreply.github.com> Date: Fri, 23 Aug 2024 22:21:45 +0530 Subject: [PATCH 02/10] Add SARIF reporter cmd/validator/validator.go: Add option to select reporter type as SARIF. pkg/reporter/sarif_reporter.go: Create SARIF report. https://sarifweb.azurewebsites.net/ --- cmd/validator/validator.go | 18 +++-- pkg/reporter/sarif_reporter.go | 136 +++++++++++++++++++++++++++++++++ 2 files changed, 149 insertions(+), 5 deletions(-) create mode 100644 pkg/reporter/sarif_reporter.go diff --git a/cmd/validator/validator.go b/cmd/validator/validator.go index b59590ce..4cddb1b7 100644 --- a/cmd/validator/validator.go +++ b/cmd/validator/validator.go @@ -20,7 +20,7 @@ optional flags: -output Destination of a file to outputting results -reporter string - Format of the printed report. Options are standard and json (default "standard") + Format of the printed report. Options are standard, json, junit and sarif (default "standard") -version Version prints the release version of validator */ @@ -76,7 +76,7 @@ func getFlags() (validatorConfig, error) { excludeDirsPtr := flag.String("exclude-dirs", "", "Subdirectories to exclude when searching for configuration files") excludeFileTypesPtr := flag.String("exclude-file-types", "", "A comma separated list of file types to ignore") outputPtr := flag.String("output", "", "Destination to a file to output results") - reportTypePtr := flag.String("reporter", "standard", "Format of the printed report. Options are standard and json") + reportTypePtr := flag.String("reporter", "standard", "Format of the printed report. Options are standard, json, junit and sarif") versionPtr := flag.Bool("version", false, "Version prints the release version of validator") groupOutputPtr := flag.String("groupby", "", "Group output by filetype, directory, pass-fail. Supported for Standard and JSON reports") quietPtr := flag.Bool("quiet", false, "If quiet flag is set. It doesn't print any output to stdout.") @@ -110,10 +110,10 @@ func getFlags() (validatorConfig, error) { searchPaths = append(searchPaths, flag.Args()...) } - if *reportTypePtr != "standard" && *reportTypePtr != "json" && *reportTypePtr != "junit" { - fmt.Println("Wrong parameter value for reporter, only supports standard, json or junit") + if *reportTypePtr != "standard" && *reportTypePtr != "json" && *reportTypePtr != "junit" && *reportTypePtr != "sarif" { + fmt.Println("Wrong parameter value for reporter, only supports standard, json, junit or sarif") flag.Usage() - return validatorConfig{}, errors.New("Wrong parameter value for reporter, only supports standard, json or junit") + return validatorConfig{}, errors.New("Wrong parameter value for reporter, only supports standard, json, junit or sarif") } if *reportTypePtr == "junit" && *groupOutputPtr != "" { @@ -122,6 +122,12 @@ func getFlags() (validatorConfig, error) { return validatorConfig{}, errors.New("Wrong parameter value for reporter, groupby is not supported for JUnit reports") } + if *reportTypePtr == "sarif" && *groupOutputPtr != "" { + fmt.Println("Wrong parameter value for reporter, groupby is not supported for SARIF reports") + flag.Usage() + return validatorConfig{}, errors.New("Wrong parameter value for reporter, groupby is not supported for SARIF reports") + } + if depthPtr != nil && isFlagSet("depth") && *depthPtr < 0 { fmt.Println("Wrong parameter value for depth, value cannot be negative.") flag.Usage() @@ -200,6 +206,8 @@ func getReporter(reportType, outputDest *string) reporter.Reporter { return reporter.NewJunitReporter(*outputDest) case "json": return reporter.NewJSONReporter(*outputDest) + case "sarif": + return reporter.NewSARIFReporter(*outputDest) default: return reporter.StdoutReporter{} } diff --git a/pkg/reporter/sarif_reporter.go b/pkg/reporter/sarif_reporter.go new file mode 100644 index 00000000..39aa61ec --- /dev/null +++ b/pkg/reporter/sarif_reporter.go @@ -0,0 +1,136 @@ +package reporter + +import ( + "encoding/json" + "fmt" + "strings" +) + +type SARIFReporter struct { + outputDest string +} + +type SARIFLog struct { + Version string `json:"version"` + Schema string `json:"$schema"` + Runs []runs `json:"runs"` +} + +type runs struct { + Tool tool `json:"tool"` + Artifacts []artifact `json:"artifacts"` + Results []result `json:"results"` +} + +type tool struct { + Driver driver `json:"driver"` +} + +type driver struct { + Name string `json:"name"` + InfoURI string `json:"informationUri"` +} + +type artifact struct { + Location location `json:"location"` +} + +type result struct { + Kind string `json:"kind"` + Level string `json:"level"` + Message message `json:"message"` + Locations []resultLocation `json:"locations"` +} + +type message struct { + Text string `json:"text"` +} + +type resultLocation struct { + PhysicalLocation physicalLocation `json:"physicalLocation"` +} + +type physicalLocation struct { + Location location `json:"artifactLocation"` +} + +type location struct { + URI string `json:"uri"` + Index *int `json:"index,omitempty"` +} + +func NewSARIFReporter(outputDest string) *SARIFReporter { + return &SARIFReporter{ + outputDest: outputDest, + } +} + +func createSARIFReport(reports []Report) (SARIFLog, error) { + var log SARIFLog + + n := len(reports) + + log.Version = "2.1.0" + log.Schema = "https://schemastore.azurewebsites.net/schemas/json/sarif-2.1.0-rtm.4.json" + + log.Runs = make([]runs, 1) + runs := &log.Runs[0] + + runs.Tool.Driver.Name = "config-file-validator" + runs.Tool.Driver.InfoURI = "https://github.com/Boeing/config-file-validator" + + runs.Artifacts = make([]artifact, n) + runs.Results = make([]result, n) + + for i, report := range reports { + if strings.Contains(report.FilePath, "\\") { + report.FilePath = strings.ReplaceAll(report.FilePath, "\\", "/") + } + + artifact := &runs.Artifacts[i] + artifact.Location.URI = report.FilePath + + result := &runs.Results[i] + if !report.IsValid { + result.Kind = "fail" + result.Level = "error" + result.Message.Text = report.ValidationError.Error() + } else { + result.Kind = "pass" + result.Level = "none" + result.Message.Text = "No errors detected" + } + + result.Locations = make([]resultLocation, 1) + location := &result.Locations[0] + location.PhysicalLocation.Location.URI = report.FilePath + location.PhysicalLocation.Location.Index = new(int) + *location.PhysicalLocation.Location.Index = i + } + + return log, nil +} + +func (sr SARIFReporter) Print(reports []Report) error { + report, err := createSARIFReport(reports) + if err != nil { + return err + } + + sarifBytes, err := json.MarshalIndent(report, "", " ") + if err != nil { + return err + } + + sarifBytes = append(sarifBytes, '\n') + + if len(reports) > 0 && !reports[0].IsQuiet { + fmt.Print(string(sarifBytes)) + } + + if sr.outputDest != "" { + return outputBytesToFile(sr.outputDest, "result", "sarif", sarifBytes) + } + + return nil +} From 46d885c3c7354030d6f3d126b76ee92cd3d292e2 Mon Sep 17 00:00:00 2001 From: shiina <152995083+shiina4119@users.noreply.github.com> Date: Fri, 23 Aug 2024 23:04:08 +0530 Subject: [PATCH 03/10] Add tests for SARIF reporter. cmd/validator/validator_test.go: Test for --reporter=sarif flag. pkg/reporter/reporter_test.go: Test for SARIF report. --- cmd/validator/validator_test.go | 1 + pkg/reporter/reporter_test.go | 34 +++++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/cmd/validator/validator_test.go b/cmd/validator/validator_test.go index 631af738..144048b2 100644 --- a/cmd/validator/validator_test.go +++ b/cmd/validator/validator_test.go @@ -23,6 +23,7 @@ func Test_flags(t *testing.T) { {"flags set, wrong reporter", []string{"--exclude-dirs=subdir", "--reporter=wrong", "."}, 1}, {"flags set, json reporter", []string{"--exclude-dirs=subdir", "--reporter=json", "."}, 0}, {"flags set, junit reporter", []string{"--exclude-dirs=subdir", "--reporter=junit", "."}, 0}, + {"flags set, sarif reporter", []string{"--exclude-dirs=subdir", "--reporter=sarif", "."}, 0}, {"bad path", []string{"/path/does/not/exit"}, 1}, {"exclude file types set", []string{"--exclude-file-types=json", "."}, 0}, {"multiple paths", []string{"../../test/fixtures/subdir/good.json", "../../test/fixtures/good.json"}, 0}, diff --git a/pkg/reporter/reporter_test.go b/pkg/reporter/reporter_test.go index 4a0aa1f0..1813aa32 100644 --- a/pkg/reporter/reporter_test.go +++ b/pkg/reporter/reporter_test.go @@ -145,6 +145,40 @@ func Test_junitReport(t *testing.T) { } } +func Test_sarifReport(t *testing.T) { + reportNoValidationError := Report{ + "good.xml", + "/fake/path/good.xml", + true, + nil, + false, + } + + reportWithBackslashPath := Report{ + "good.xml", + "\\fake\\path\\good.xml", + true, + nil, + false, + } + + reportWithValidationError := Report{ + "bad.xml", + "/fake/path/bad.xml", + false, + errors.New("Unable to parse bad.xml file"), + false, + } + + reports := []Report{reportNoValidationError, reportWithValidationError, reportWithBackslashPath} + + sarifReporter := SARIFReporter{} + err := sarifReporter.Print(reports) + if err != nil { + t.Errorf("Reporting failed") + } +} + func Test_jsonReporterWriter(t *testing.T) { report := Report{ "good.json", From 28a83c532b8a68198fb40c8055c650f8416cd825 Mon Sep 17 00:00:00 2001 From: shiina <152995083+shiina4119@users.noreply.github.com> Date: Sat, 24 Aug 2024 16:42:14 +0530 Subject: [PATCH 04/10] Add test for SARIF reporter writer. --- pkg/reporter/reporter_test.go | 106 +++++++++++++++++++++++++++++++ test/output/example/result.sarif | 40 ++++++++++++ 2 files changed, 146 insertions(+) create mode 100644 test/output/example/result.sarif diff --git a/pkg/reporter/reporter_test.go b/pkg/reporter/reporter_test.go index 1813aa32..72473e88 100644 --- a/pkg/reporter/reporter_test.go +++ b/pkg/reporter/reporter_test.go @@ -285,6 +285,112 @@ func Test_jsonReporterWriter(t *testing.T) { } } +func Test_sarifReporterWriter(t *testing.T) { + report := Report{ + "good.json", + "test/output/example/good.json", + true, + nil, + false, + } + deleteFiles(t) + + bytes, err := os.ReadFile("../../test/output/example/result.sarif") + require.NoError(t, err) + + type args struct { + reports []Report + outputDest string + } + type want struct { + fileName string + data []byte + err assert.ErrorAssertionFunc + } + + tests := map[string]struct { + args args + want want + }{ + "normal/existing dir/default name": { + args: args{ + reports: []Report{ + report, + }, + outputDest: "../../test/output", + }, + want: want{ + fileName: "result.sarif", + data: bytes, + err: assert.NoError, + }, + }, + "normal/file name is given": { + args: args{ + reports: []Report{ + report, + }, + outputDest: "../../test/output/validator_result.sarif", + }, + want: want{ + fileName: "validator_result.sarif", + data: bytes, + err: assert.NoError, + }, + }, + "quash normal/empty string": { + args: args{ + reports: []Report{ + report, + }, + outputDest: "", + }, + want: want{ + fileName: "", + data: nil, + err: assert.NoError, + }, + }, + "abnormal/non-existing dir": { + args: args{ + reports: []Report{ + report, + }, + outputDest: "../../test/wrong/output", + }, + want: want{ + fileName: "", + data: nil, + err: assertRegexpError("failed to create a file: "), + }, + }, + } + for name, tt := range tests { + t.Run(name, func(t *testing.T) { + sut := NewSARIFReporter(tt.args.outputDest) + err := sut.Print(tt.args.reports) + tt.want.err(t, err) + if tt.want.data != nil { + info, err := os.Stat(tt.args.outputDest) + require.NoError(t, err) + var filePath string + if info.IsDir() { + filePath = tt.args.outputDest + "/result.sarif" + } else { // if file was named with outputDest value + assert.Equal(t, tt.want.fileName, info.Name()) + filePath = tt.args.outputDest + } + bytes, err := os.ReadFile(filePath) + require.NoError(t, err) + assert.Equal(t, tt.want.data, bytes) + err = os.Remove(filePath) + require.NoError(t, err) + } + }, + ) + } +} + func Test_JunitReporter_OutputBytesToFile(t *testing.T) { report := Report{ "good.json", diff --git a/test/output/example/result.sarif b/test/output/example/result.sarif new file mode 100644 index 00000000..4b91241b --- /dev/null +++ b/test/output/example/result.sarif @@ -0,0 +1,40 @@ +{ + "version": "2.1.0", + "$schema": "https://schemastore.azurewebsites.net/schemas/json/sarif-2.1.0-rtm.4.json", + "runs": [ + { + "tool": { + "driver": { + "name": "config-file-validator", + "informationUri": "https://github.com/Boeing/config-file-validator" + } + }, + "artifacts": [ + { + "location": { + "uri": "test/output/example/good.json" + } + } + ], + "results": [ + { + "kind": "pass", + "level": "none", + "message": { + "text": "No errors detected" + }, + "locations": [ + { + "physicalLocation": { + "artifactLocation": { + "uri": "test/output/example/good.json", + "index": 0 + } + } + } + ] + } + ] + } + ] +} From c22bd2620bde2355f136aec37b5422719df7b234 Mon Sep 17 00:00:00 2001 From: shiina <152995083+shiina4119@users.noreply.github.com> Date: Sat, 24 Aug 2024 19:41:28 +0530 Subject: [PATCH 05/10] cmd/validator/validator.go: Satisfy goreportcard. --- cmd/validator/validator.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/cmd/validator/validator.go b/cmd/validator/validator.go index 4cddb1b7..c1980964 100644 --- a/cmd/validator/validator.go +++ b/cmd/validator/validator.go @@ -110,7 +110,9 @@ func getFlags() (validatorConfig, error) { searchPaths = append(searchPaths, flag.Args()...) } - if *reportTypePtr != "standard" && *reportTypePtr != "json" && *reportTypePtr != "junit" && *reportTypePtr != "sarif" { + acceptedReportTypes := map[string]bool{"standard": true, "json": true, "junit": true, "sarif": true} + + if !acceptedReportTypes[*reportTypePtr] { fmt.Println("Wrong parameter value for reporter, only supports standard, json, junit or sarif") flag.Usage() return validatorConfig{}, errors.New("Wrong parameter value for reporter, only supports standard, json, junit or sarif") From 4a1cbd5a922b273871f6dc3c785ce9d23a0785fc Mon Sep 17 00:00:00 2001 From: shiina <152995083+shiina4119@users.noreply.github.com> Date: Fri, 11 Oct 2024 21:17:04 +0530 Subject: [PATCH 06/10] Fix SARIF validation errors --- pkg/reporter/sarif_reporter.go | 45 +++++++++++++------------------- test/output/example/result.sarif | 15 +++-------- 2 files changed, 22 insertions(+), 38 deletions(-) diff --git a/pkg/reporter/sarif_reporter.go b/pkg/reporter/sarif_reporter.go index 39aa61ec..dfb5ff00 100644 --- a/pkg/reporter/sarif_reporter.go +++ b/pkg/reporter/sarif_reporter.go @@ -17,9 +17,8 @@ type SARIFLog struct { } type runs struct { - Tool tool `json:"tool"` - Artifacts []artifact `json:"artifacts"` - Results []result `json:"results"` + Tool tool `json:"tool"` + Results []result `json:"results"` } type tool struct { @@ -29,34 +28,30 @@ type tool struct { type driver struct { Name string `json:"name"` InfoURI string `json:"informationUri"` -} - -type artifact struct { - Location location `json:"location"` + Version string `json:"version"` } type result struct { - Kind string `json:"kind"` - Level string `json:"level"` - Message message `json:"message"` - Locations []resultLocation `json:"locations"` + Kind string `json:"kind"` + Level string `json:"level"` + Message message `json:"message"` + Locations []location `json:"locations"` } type message struct { Text string `json:"text"` } -type resultLocation struct { +type location struct { PhysicalLocation physicalLocation `json:"physicalLocation"` } type physicalLocation struct { - Location location `json:"artifactLocation"` + ArtifactLocation artifactLocation `json:"artifactLocation"` } -type location struct { - URI string `json:"uri"` - Index *int `json:"index,omitempty"` +type artifactLocation struct { + URI string `json:"uri"` } func NewSARIFReporter(outputDest string) *SARIFReporter { @@ -65,21 +60,21 @@ func NewSARIFReporter(outputDest string) *SARIFReporter { } } -func createSARIFReport(reports []Report) (SARIFLog, error) { +func createSARIFReport(reports []Report) (*SARIFLog, error) { var log SARIFLog n := len(reports) log.Version = "2.1.0" - log.Schema = "https://schemastore.azurewebsites.net/schemas/json/sarif-2.1.0-rtm.4.json" + log.Schema = "https://docs.oasis-open.org/sarif/sarif/v2.1.0/errata01/os/schemas/sarif-schema-2.1.0.json" log.Runs = make([]runs, 1) runs := &log.Runs[0] runs.Tool.Driver.Name = "config-file-validator" runs.Tool.Driver.InfoURI = "https://github.com/Boeing/config-file-validator" + runs.Tool.Driver.Version = "1.7.1" - runs.Artifacts = make([]artifact, n) runs.Results = make([]result, n) for i, report := range reports { @@ -87,9 +82,6 @@ func createSARIFReport(reports []Report) (SARIFLog, error) { report.FilePath = strings.ReplaceAll(report.FilePath, "\\", "/") } - artifact := &runs.Artifacts[i] - artifact.Location.URI = report.FilePath - result := &runs.Results[i] if !report.IsValid { result.Kind = "fail" @@ -101,14 +93,13 @@ func createSARIFReport(reports []Report) (SARIFLog, error) { result.Message.Text = "No errors detected" } - result.Locations = make([]resultLocation, 1) + result.Locations = make([]location, 1) location := &result.Locations[0] - location.PhysicalLocation.Location.URI = report.FilePath - location.PhysicalLocation.Location.Index = new(int) - *location.PhysicalLocation.Location.Index = i + + location.PhysicalLocation.ArtifactLocation.URI = "file:///" + report.FilePath } - return log, nil + return &log, nil } func (sr SARIFReporter) Print(reports []Report) error { diff --git a/test/output/example/result.sarif b/test/output/example/result.sarif index 4b91241b..e86e9f47 100644 --- a/test/output/example/result.sarif +++ b/test/output/example/result.sarif @@ -1,21 +1,15 @@ { "version": "2.1.0", - "$schema": "https://schemastore.azurewebsites.net/schemas/json/sarif-2.1.0-rtm.4.json", + "$schema": "https://docs.oasis-open.org/sarif/sarif/v2.1.0/errata01/os/schemas/sarif-schema-2.1.0.json", "runs": [ { "tool": { "driver": { "name": "config-file-validator", - "informationUri": "https://github.com/Boeing/config-file-validator" + "informationUri": "https://github.com/Boeing/config-file-validator", + "version": "1.7.1" } }, - "artifacts": [ - { - "location": { - "uri": "test/output/example/good.json" - } - } - ], "results": [ { "kind": "pass", @@ -27,8 +21,7 @@ { "physicalLocation": { "artifactLocation": { - "uri": "test/output/example/good.json", - "index": 0 + "uri": "file:///test/output/example/good.json" } } } From bdd60c501708bc04a6ec08abdf39ffc930c84c54 Mon Sep 17 00:00:00 2001 From: Debanga Sarma Date: Wed, 23 Oct 2024 00:30:33 +0530 Subject: [PATCH 07/10] Combine groupOutput check for junit and sarif. --- cmd/validator/validator.go | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/cmd/validator/validator.go b/cmd/validator/validator.go index c1980964..726980f0 100644 --- a/cmd/validator/validator.go +++ b/cmd/validator/validator.go @@ -118,16 +118,10 @@ func getFlags() (validatorConfig, error) { return validatorConfig{}, errors.New("Wrong parameter value for reporter, only supports standard, json, junit or sarif") } - if *reportTypePtr == "junit" && *groupOutputPtr != "" { - fmt.Println("Wrong parameter value for reporter, groupby is not supported for JUnit reports") + if (*reportTypePtr == "junit" || *reportTypePtr == "sarif") && *groupOutputPtr != "" { + fmt.Println("Wrong parameter value for reporter, groupby is only supported for JSON reports") flag.Usage() - return validatorConfig{}, errors.New("Wrong parameter value for reporter, groupby is not supported for JUnit reports") - } - - if *reportTypePtr == "sarif" && *groupOutputPtr != "" { - fmt.Println("Wrong parameter value for reporter, groupby is not supported for SARIF reports") - flag.Usage() - return validatorConfig{}, errors.New("Wrong parameter value for reporter, groupby is not supported for SARIF reports") + return validatorConfig{}, errors.New("Wrong parameter value for reporter, groupby is only supported for JSON reports") } if depthPtr != nil && isFlagSet("depth") && *depthPtr < 0 { From 67bae286c8e4adaeddee839d60d96c08441ec7ad Mon Sep 17 00:00:00 2001 From: Debanga Sarma Date: Wed, 23 Oct 2024 00:31:06 +0530 Subject: [PATCH 08/10] Add groupby test for sarif reporter. --- cmd/validator/validator_test.go | 1 + 1 file changed, 1 insertion(+) diff --git a/cmd/validator/validator_test.go b/cmd/validator/validator_test.go index 144048b2..4f1ca4b1 100644 --- a/cmd/validator/validator_test.go +++ b/cmd/validator/validator_test.go @@ -34,6 +34,7 @@ func Test_flags(t *testing.T) { {"incorrect group", []string{"-groupby=badgroup", "."}, 1}, {"correct group", []string{"-groupby=directory", "."}, 0}, {"grouped junit", []string{"-groupby=directory", "--reporter=junit", "."}, 1}, + {"grouped sarif", []string{"-groupby=directory", "--reporter=sarif", "."}, 1}, {"groupby duplicate", []string{"--groupby=directory,directory", "."}, 1}, {"quiet flag", []string{"--quiet=true", "."}, 0}, } From 2aa0c3435e0b06aba1ad2f844b23544c9b9905ec Mon Sep 17 00:00:00 2001 From: Debanga Sarma Date: Wed, 23 Oct 2024 00:49:06 +0530 Subject: [PATCH 09/10] make version, schema, driver name and infoUri constants and move them outside. --- pkg/reporter/sarif_reporter.go | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/pkg/reporter/sarif_reporter.go b/pkg/reporter/sarif_reporter.go index dfb5ff00..b775a254 100644 --- a/pkg/reporter/sarif_reporter.go +++ b/pkg/reporter/sarif_reporter.go @@ -6,6 +6,12 @@ import ( "strings" ) +const SARIFVersion = "2.1.0" +const SARIFSchema = "https://docs.oasis-open.org/sarif/sarif/v2.1.0/errata01/os/schemas/sarif-schema-2.1.0.json" +const DriverName = "config-file-validator" +const DriverInfoURI = "https://github.com/Boeing/config-file-validator" +const DriverVersion = "1.7.1" + type SARIFReporter struct { outputDest string } @@ -65,15 +71,15 @@ func createSARIFReport(reports []Report) (*SARIFLog, error) { n := len(reports) - log.Version = "2.1.0" - log.Schema = "https://docs.oasis-open.org/sarif/sarif/v2.1.0/errata01/os/schemas/sarif-schema-2.1.0.json" + log.Version = SARIFVersion + log.Schema = SARIFSchema log.Runs = make([]runs, 1) runs := &log.Runs[0] - runs.Tool.Driver.Name = "config-file-validator" - runs.Tool.Driver.InfoURI = "https://github.com/Boeing/config-file-validator" - runs.Tool.Driver.Version = "1.7.1" + runs.Tool.Driver.Name = DriverName + runs.Tool.Driver.InfoURI = DriverInfoURI + runs.Tool.Driver.Version = DriverVersion runs.Results = make([]result, n) From 6a550c8630b96ae90a59f855fe77febed966409b Mon Sep 17 00:00:00 2001 From: Debanga Sarma Date: Wed, 23 Oct 2024 12:41:10 +0530 Subject: [PATCH 10/10] Make gocyclo happy --- cmd/validator/validator.go | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/cmd/validator/validator.go b/cmd/validator/validator.go index 726980f0..1c354166 100644 --- a/cmd/validator/validator.go +++ b/cmd/validator/validator.go @@ -118,10 +118,12 @@ func getFlags() (validatorConfig, error) { return validatorConfig{}, errors.New("Wrong parameter value for reporter, only supports standard, json, junit or sarif") } - if (*reportTypePtr == "junit" || *reportTypePtr == "sarif") && *groupOutputPtr != "" { - fmt.Println("Wrong parameter value for reporter, groupby is only supported for JSON reports") + groupOutputReportTypes := map[string]bool{"standard": true, "json": true} + + if !groupOutputReportTypes[*reportTypePtr] && *groupOutputPtr != "" { + fmt.Println("Wrong parameter value for reporter, groupby is only supported for standard and JSON reports") flag.Usage() - return validatorConfig{}, errors.New("Wrong parameter value for reporter, groupby is only supported for JSON reports") + return validatorConfig{}, errors.New("Wrong parameter value for reporter, groupby is only supported for standard and JSON reports") } if depthPtr != nil && isFlagSet("depth") && *depthPtr < 0 {