diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 4b621f6b..d3b125d0 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -19,3 +19,6 @@ Pull requests are the best way to propose changes to the codebase (we use [GitHu ## Report bugs using GitHub's [issues](https://github.com/boeing/config-file-validator/issues) We use GitHub issues to track public bugs. Report a bug by [opening a new issue](https://github.com/Boeing/config-file-validator/issues/new); + +## Functional Testing +Until we can automate the functional testing, you must run through the [functional testing](./functional_test.md) procedures before submitting your PR for review. diff --git a/Dockerfile b/Dockerfile index 9ec563f9..d78db21e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,6 +1,6 @@ -ARG BASE_IMAGE=alpine:3.20@sha256:0a4eaa0eecf5f8c050e5bba433f58c052be7587ee8af3e8b3910ef9ab5fbe9f5 +ARG BASE_IMAGE=alpine:3.21@sha256:21dc6063fd678b478f57c0e13f47560d0ea4eeba26dfc947b2a4f81f686b9f45 -FROM golang:1.22@sha256:f43c6f049f04cbbaeb28f0aad3eea15274a7d0a7899a617d0037aec48d7ab010 as go-builder +FROM golang:1.23@sha256:70031844b8c225351d0bb63e2c383f80db85d92ba894e3da7e13bcf80efa9a37 AS go-builder ARG VALIDATOR_VERSION=unknown COPY . /build/ WORKDIR /build diff --git a/PKGBUILD b/PKGBUILD index c45e7398..9a3ef813 100644 --- a/PKGBUILD +++ b/PKGBUILD @@ -1,7 +1,7 @@ # Maintainer: Clayton Kehoe # Contributor : wiz64 pkgname=config-file-validator -pkgver=1.7.1 +pkgver=1.8.0 pkgrel=1 pkgdesc="A tool to validate the syntax of configuration files" arch=('x86_64') diff --git a/README.md b/README.md index 60233e1a..030d9dd6 100644 --- a/README.md +++ b/README.md @@ -87,7 +87,7 @@ makepkg -si If you have a go environment on your desktop you can use [go install](https://go.dev/doc/go-get-install-deprecation) to install the validator executable. The validator executable will be installed to the directory named by the GOBIN environment variable, which defaults to $GOPATH/bin or $HOME/go/bin if the GOPATH environment variable is not set. ``` -go install github.com/Boeing/config-file-validator/cmd/validator@v1.7.1 +go install github.com/Boeing/config-file-validator/cmd/validator@v1.8.0 ``` ## Usage @@ -99,25 +99,25 @@ positional arguments: optional flags: -depth int - Depth of recursion for the provided search paths. Set depth to 0 to disable recursive path traversal + Depth of recursion for the provided search paths. Set depth to 0 to disable recursive path traversal -exclude-dirs string - Subdirectories to exclude when searching for configuration files + Subdirectories to exclude when searching for configuration files -exclude-file-types string - A comma separated list of file types to ignore + A comma separated list of file types to ignore + -globbing + If globbing flag is set, check for glob patterns in the arguments. -groupby string - Group output by filetype, directory, pass-fail. Supported for Standard and JSON reports - -globbing bool - Set globbing to true to enable pattern matching for search paths. Enclose the pattern in double quotes. The flag is not compatible with -exclude-dirs and -exclude-file-types. + Group output by filetype, directory, pass-fail. Supported for Standard and JSON reports -quiet - If quiet flag is set. It doesn't print any output to stdout. - -reporter string - A string representing report format and optional output file path separated by colon if present. - Usage: --reporter : - Multiple reporters can be specified: --reporter json:file_path.json --reporter junit:another_file_path.xml - Omit the file path to output to stdout: --reporter json or explicitly specify stdout using "-": --reporter json:- - Supported formats: standard, json, junit (default: "standard") + If quiet flag is set. It doesn't print any output to stdout. + -reporter value + A string representing report format and optional output file path separated by colon if present. + Usage: --reporter : + Multiple reporters can be specified: --reporter json:file_path.json --reporter junit:another_file_path.xml + Omit the file path to output to stdout: --reporter json or explicitly specify stdout using "-": --reporter json:- + Supported formats: standard, json, junit, and sarif (default: "standard") -version - Version prints the release version of validator + Version prints the release version of validator ``` ### Environment Variables @@ -132,6 +132,7 @@ The config-file-validator supports setting options via environment variables. If | `CFV_REPORTER` | `-reporter` | | `CFV_GROUPBY` | `-groupby` | | `CFV_QUIET` | `-quiet` | +| `CFV_GLOBBING` | `-globbing` | ### Examples #### Standard Run @@ -178,9 +179,9 @@ validator --depth=0 /path/to/search ![Custom Recursion Run](./img/custom_recursion.gif) #### Customize report output -You can customize the report output and save the results to a file (default name is result.{extension}). The available report types are `standard`, `junit`, and `json`. You can specify multiple report types by chaining the `--reporter` flags. +You can customize the report output and save the results to a file (default name is result.{extension}). The available report types are `standard`, `junit`, `json`, and `sarif`. You can specify multiple report types by chaining the `--reporter` flags. -Providing an output file is optional, the results will be printed to stdout by default. To explicitly direct the output to stdout, use file path as `-`. +You can specify a path to an output file for any reporter by appending `:` the the name of the reporter. Providing an output file is optional and the results will be printed to stdout by default. To explicitly direct the output to stdout, use `:-` as the file path. ``` validator --reporter=json:- /path/to/search @@ -229,13 +230,6 @@ validator -globbing "/path/to/files/**/*.json" validator -globbing "/path/*.json" /path/to/search ``` -#### Container Run -``` -docker run -it --rm -v /path/to/config/files:/test config-file-validator:1.6.0 /test -``` - -![Docker Standard Run](./img/docker_run.png) - ## Build The project can be downloaded and built from source using an environment with Go 1.21+ installed. After a successful build, the binary can be moved to a location on your operating system PATH. @@ -301,7 +295,7 @@ cp .\validator.exe 'C:\Program Files\validator' You can also use the provided Dockerfile to build the config file validator tool as a container ``` -docker build . -t config-file-validator:v1.6.0 +docker build . -t config-file-validator:v1.8.0 ``` ## Contributors diff --git a/cmd/validator/validator.go b/cmd/validator/validator.go index 876e0110..1b5be826 100644 --- a/cmd/validator/validator.go +++ b/cmd/validator/validator.go @@ -24,7 +24,7 @@ optional flags: Usage: --reporter : Multiple reporters can be specified: --reporter json:file_path.json --reporter junit:another_file_path.xml Omit the file path to output to stdout: --reporter json or explicitly specify stdout using "-": --reporter json:- - Supported formats: standard, json, junit (default: "standard") + Supported formats: standard, json, junit, and sarif (default: "standard") -version Version prints the release version of validator */ @@ -136,7 +136,7 @@ func getFlags() (validatorConfig, error) { Usage: --reporter : Multiple reporters can be specified: --reporter json:file_path.json --reporter junit:another_file_path.xml Omit the file path to output to stdout: --reporter json or explicitly specify stdout using "-": --reporter json:- -Supported formats: standard, json, junit (default: "standard")`, +Supported formats: standard, json, junit, and sarif (default: "standard")`, ) flag.Parse() @@ -238,8 +238,6 @@ func validateGroupByConf(groupBy *string) error { func validateGlobbing(globbingPrt *bool) error { if *globbingPrt && (isFlagSet("exclude-dirs") || isFlagSet("exclude-file-types")) { - fmt.Println("The -globbing flag cannot be used with --exclude-dirs or --exclude-file-types") - flag.Usage() return errors.New("the -globbing flag cannot be used with --exclude-dirs or --exclude-file-types") } return nil @@ -320,6 +318,7 @@ func applyDefaultFlagsFromEnv() error { "reporter": "CFV_REPORTER", "groupby": "CFV_GROUPBY", "quiet": "CFV_QUIET", + "globbing": "CFV_GLOBBING", } for flagName, envVar := range flagsEnvMap { diff --git a/cmd/validator/validator_test.go b/cmd/validator/validator_test.go index 6b3d62ea..36957fdb 100644 --- a/cmd/validator/validator_test.go +++ b/cmd/validator/validator_test.go @@ -57,7 +57,7 @@ func Test_flags(t *testing.T) { os.Args = append([]string{tc.Name}, tc.Args...) actualExit := mainInit() if tc.ExpectedExit != actualExit { - t.Errorf("Wrong exit code, expected: %v, got: %v", tc.ExpectedExit, actualExit) + t.Errorf("Test Case %v: Wrong exit code, expected: %v, got: %v", tc.Name, tc.ExpectedExit, actualExit) } } } diff --git a/functional_test.md b/functional_test.md new file mode 100644 index 00000000..93471446 --- /dev/null +++ b/functional_test.md @@ -0,0 +1,123 @@ +# Functional Tests for the config-file-validator + +Manual procedures for functionally testing the config-file-validator. These will eventually be used as requirements for creating automated function tests + +## Setup + +1. Build the latest changes in a container `docker build . -t cfv:` tagging the local container with a tag that indicates what feature is being tested +2. Run the container and mount the test directory `docker run -it --rm -v $(pwd)/test:/test --entrypoint sh cfv:` + +## Basic Functionality + +This section tests basic validator functionality + +| Test | Expected Result | Notes | +| ---- | --------------- | ----- | +| `cd /test && /validator` | 37 passed and 12 failed | | +| `/validator /test` | 37 passed and 12 failed | | +| `/validator /test/fixtures/subdir /test/fixtures/subdir2` | 3 passed and 12 failed | | +| `/validator --help` | Help is displayed | | +| `/validator --version` | Output should read "validator version unknown" | | +| `/validator /badpath` | Error output should read: "An error occurred during CLI execution: Unable to find files: stat /badpath: no such file or directory" | | +| `/validator -v` | Error "flag provided but not defined: -v" is displayed on the terminal in addition to the help output | | + + +## Reports + +This section validates report output + +| Test | Expected Result | Notes | +| ---- | --------------- | ----- | +| `cd /test && /validator --reporter=json:-` | JSON output is produced on the terminal and summary is `"summary": {"passed": 37,"failed": 12}` | | +| `cd /test && /validator --reporter=standard:-` | Text output is produced on the screen | | +| `cd /test && /validator --reporter=junit:-` | JUnit XML is produced on the terminal | | +| `cd /test && /validator --reporter=sarif:-` | Sarif output is produced on the terminal | | +| `cd /test && /validator --reporter=json:/json_report.json` | JSON is written to `/json_report.json` and summary in the contents of the file reads `"summary": {"passed": 37,"failed": 12}` | | +| `cd /test && /validator --reporter=standard:/standard_report.txt` | Text is written to `/standard_report.txt` | | +| `cd /test && /validator --reporter=junit:/junit_report.xml` | JUnit XML is written to `/junit_report.xml` | | +| `cd /test && /validator --reporter=sarif:/sarif_report.sarif` | Sarif JSON is written to `/sarif_report.sarif` | This is currently failing as the sarif report is written to stdout in addition to the file | +| `cd /test && /validator --reporter=json:/json_report_2.json --reporter=standard:-` | JSON is written to `/json_report_2.json` and standard text is output to the terminal | | +| `cd /test && /validator --reporter=bad` | Error message "Wrong parameter value for reporter, only supports standard, json, junit, or sarif" should be displayed in addition to the help output | | +| `cd /test && /validator --reporter=json --quiet` | Nothing is displayed to the terminal since the `--quiet` flag supresses the output | | +| `cd /test && /validator --reporter=json:/json_report_3.json --quiet` | Nothing is displayed to the terminal since the `--quiet` flag supresses the output but the `/json_report_3.json` file is populated | | + +## Grouping + +This section validates organization of the output + +| Test | Expected Result | Notes | +| ---- | --------------- | ----- | +| `cd /test && /validator --groupby=filetype` | Results are grouped by file type | | +| `cd /test && /validator --groupby=pass-fail` | Results are grouped by pass/fail | Bug filed for duplicate summaries | +| `cd /test && /validator --reporter=standard --groupby=pass-fail` | Results are grouped by pass/fail | Bug filed for duplicate summaries | +| `cd /test && /validator --groupby=directory` | Results are grouped by directory | | +| `cd /test && /validator --groupby=filetype,directory` | Results are grouped by file type, then directory | | +| `cd /test && /validator --groupby=pass-fail,filetype` | Results are grouped by pass-fail, then filetype | | +| `cd /test && /validator --groupby=pass-fail,directory` | Results are grouped by pass-fail, then directory | | +| `cd /test && /validator --groupby=pass-fail,directory,filetype` | Results are grouped by pass-fail, then directory, then file type | | +| `cd /test && /validator --groupby=pass-fail,pass-fail` | Error "Wrong parameter value for groupby, duplicate values are not allowed" is displayed with help output | | +| `cd /test && /validator --reporter=json --groupby=filetype,directory` | JSON Results are grouped by file type, then directory | This does not work, bug filed | +| `cd /test && /validator --reporter=junit --groupby=pass-fail` | Error "Wrong parameter value for reporter, groupby is only supported for standard and JSON reports" is displayed with help output | | +| `cd /test && /validator --reporter=sarif --groupby=directory` | Error "Wrong parameter value for reporter, groupby is only supported for standard and JSON reports" is displayed with help output | | + +## Depth +| Test | Expected Result | Notes | +| ---- | --------------- | ----- | +| `cd / && /validator --depth=0 /test` | Nothing is displayed since there are no config files at the root of the `/test` directory and recursion is disabled with depth set to 0 | | +| `cd / && /validator --depth=1 /test` | Files in `/test/fixtures/` are validated | | +| `cd / && /validator --depth=2 /test` | Files in `/test/fixtures/*` directories are validated | | + +## Globbing + +| Test | Expected Result | Notes | +| ---- | --------------- | ----- | +| `cd /test && /validator --globbing "fixtures/**/*.json"` | All json files in subdirectories are displayed | | +| `cd /test && /validator --globbing "fixtures/**/*.json" /test/fixtures/subdir2` | All json files in subdirectories are displayed and other files in `/test/fixtures/subdir2` are displayed | | +| `cd /test && /validator --groupby=pass-fail --globbing "fixtures/**/*.json"` | All json files in subdirectories are displayed and grouped by pass/fail | | +| `cd /test && /validator --reporter=json --globbing "fixtures/**/*.json"` | All json files in subdirectories are displayed as a JSON report | | +| `cd /test && /validator "fixtures/**/*.json"` | Error "An error occurred during CLI execution: Unable to find files: stat fixtures/**/*.json: no such file or directory" should be displayed when using glob patterns without flag enabling it | | +| `cd /test && /validator --exclude-file-types=json --globbing "fixtures/**/*.json"` | Error "the -globbing flag cannot be used with --exclude-dirs or --exclude-file-types" is displayed | | +| `cd /test && /validator --exclude-dirs=subdir2 --globbing "fixtures/**/*.json"` | Error "the -globbing flag cannot be used with --exclude-dirs or --exclude-file-types" is displayed | | + + +## Environment Variables + +Run `unset ` to unset the previous var before testing + +| Test | Expected Result | Notes | +| ---- | --------------- | ----- | +| `export CFV_REPORTER=json:- && /validator /test` | JSON output should display on the terminal | | +| `export CFV_REPORTER=json:/test_env_var.json && /validator /test` | JSON output should be written to `/test_env_var.json` and NOT displayed on the terminal | | +| `export CFV_GLOBBING=true && cd /test && /validator "fixtures/**/*.json"` | Results should include json files in all subdirectories for fixtures | This does not work and a bug has been filed | +| `export CFV_QUIET=true && cd /test && /validator` | No output should be displayed on the terminal | | +| `export CFV_QUIET=false && cd /test && /validator` | Output should be displayed on the terminal | | +| `export CFV_GROUPBY=pass-fail && cd /test && /validator` | Output should be displayed on the terminal and grouped by pass-fail | | +| `export CFV_DEPTH=0 && cd /test && /validator` | Output should only display config files at the root of `/test/fixtures` | | +| `export CFV_EXCLUDE_DIRS=subdir2,subdir && cd /test && /validator` | `subdir` and `subdir2` directories should be excluded | | +| `export CFV_EXCLUDE_FILE_TYPES=yml,yaml,json,toml,properties,hocon,csv,hcl,ini,env,plist,editorconfig,xml && cd /test && /validator` | No output since all types are excluded | | +| `export CFV_EXCLUDE_FILE_TYPES=yml,yaml,json,toml,properties,hocon,csv,hcl,ini,env,plist,editorconfig && cd /test && /validator --exclude-file-types=""` | All config files should be displayed since the argument overrides the environment variable | | + +## Exclude Dirs +| Test | Expected Result | Notes | +| ---- | --------------- | ----- | +| `cd /test && /validator --exclude-dirs=baddir` | Non-existent subdirectory is ignored | | +| `cd /test && /validator --exclude-dirs=subdir,subdir2` | `subdir` and `subdir2` directories are ignored | | +| ` cd /test && /validator --exclude-dirs=test /` | `test` subdirectory is excluded from root directory search path `/` | | + + +## Exclude File Types + +| Test | Expected Result | Notes | +| ---- | --------------- | ----- | +| `cd /test && /validator --exclude-file-types=xml` | XML validation should be skipped | | +| `cd /test && /validator --exclude-file-types=yml` | `.yaml` and `.yml` should be excluded from validation | | +| `cd /test && /validator --exclude-file-types=YaML` | `.yaml` and `.yml` should be excluded from validation since argument values are not case sensitive | | + + +## Other Flags + +| Test | Expected Result | Notes | +| ---- | --------------- | ----- | +| `cd /test && /validator --quiet` | Nothing is displayed to the terminal since the `--quiet` flag supresses the output | | +| `cd /test && /validator /badpath --quiet` | Error "An error occurred during CLI execution: Unable to find files: stat /badpath: no such file or directory" is output to the terminal even through `--quiet` was enabled | | + diff --git a/index.md b/index.md index 7b94e3bb..5c10500a 100644 --- a/index.md +++ b/index.md @@ -101,7 +101,7 @@ makepkg -si If you have a go environment on your desktop you can use [go install](https://go.dev/doc/go-get-install-deprecation) to install the validator executable. The validator executable will be installed to the directory named by the GOBIN environment variable, which defaults to $GOPATH/bin or $HOME/go/bin if the GOPATH environment variable is not set. ``` -go install github.com/Boeing/config-file-validator/cmd/validator@v1.6.0 +go install github.com/Boeing/config-file-validator/cmd/validator@v1.8.0 ``` ## Usage @@ -113,23 +113,41 @@ positional arguments: optional flags: -depth int - Depth of recursion for the provided search paths. Set depth to 0 to disable recursive path traversal + Depth of recursion for the provided search paths. Set depth to 0 to disable recursive path traversal -exclude-dirs string - Subdirectories to exclude when searching for configuration files + Subdirectories to exclude when searching for configuration files -exclude-file-types string - A comma separated list of file types to ignore + A comma separated list of file types to ignore + -globbing + If globbing flag is set, check for glob patterns in the arguments. -groupby string - Group output by filetype, directory, pass-fail. Supported for Standard and JSON reports - -output string - Destination to a file to output results + Group output by filetype, directory, pass-fail. Supported for Standard and JSON reports -quiet - If quiet flag is set. It doesn't print any output to stdout. - -reporter string - Format of the printed report. Options are standard and json (default "standard") + If quiet flag is set. It doesn't print any output to stdout. + -reporter value + A string representing report format and optional output file path separated by colon if present. + Usage: --reporter : + Multiple reporters can be specified: --reporter json:file_path.json --reporter junit:another_file_path.xml + Omit the file path to output to stdout: --reporter json or explicitly specify stdout using "-": --reporter json:- + Supported formats: standard, json, junit, and sarif (default: "standard") -version - Version prints the release version of validator + Version prints the release version of validator ``` +### Environment Variables + +The config-file-validator supports setting options via environment variables. If both command-line flags and environment variables are set, the command-line flags will take precedence. The supported environment variables are as follows: + +| Environment Variable | Equivalent Flag | +|----------------------|-----------------| +| `CFV_DEPTH` | `-depth` | +| `CFV_EXCLUDE_DIRS` | `-exclude-dirs` | +| `CFV_EXCLUDE_FILE_TYPES` | `-exclude-file-types` | +| `CFV_REPORTER` | `-reporter` | +| `CFV_GROUPBY` | `-groupby` | +| `CFV_QUIET` | `-quiet` | +| `CFV_GLOBBING` | `-globbing` | + ### Examples #### Standard Run If the search path is omitted it will search the current directory @@ -137,7 +155,7 @@ If the search path is omitted it will search the current directory validator /path/to/search ``` -![Standard Run](./img/standard_run.png) +![Standard Run](./img/standard_run.gif) #### Multiple search paths Multiple search paths are supported, and the results will be merged into a single report @@ -145,7 +163,7 @@ Multiple search paths are supported, and the results will be merged into a singl validator /path/to/search /another/path/to/search ``` -![Multiple Search Paths Run](./img/multiple_paths.png) +![Multiple Search Paths Run](./img/multiple_paths.gif) #### Exclude directories Exclude subdirectories in the search path @@ -154,7 +172,7 @@ Exclude subdirectories in the search path validator --exclude-dirs=/path/to/search/tests /path/to/search ``` -![Exclude Dirs Run](./img/exclude_dirs.png) +![Exclude Dirs Run](./img/exclude_dirs.gif) #### Exclude file types Exclude file types in the search path. Available file types are `csv`, `env`, `hcl`, `hocon`, `ini`, `json`, `plist`, `properties`, `toml`, `xml`, `yaml`, and `yml` @@ -163,7 +181,7 @@ Exclude file types in the search path. Available file types are `csv`, `env`, `h validator --exclude-file-types=json /path/to/search ``` -![Exclude File Types Run](./img/exclude_file_types.png) +![Exclude File Types Run](./img/exclude_file_types.gif) #### Customize recursion depth By default there is no recursion limit. If desired, the recursion depth can be set to an integer value. If depth is set to `0` recursion will be disabled and only the files in the search path will be validated. @@ -172,16 +190,19 @@ By default there is no recursion limit. If desired, the recursion depth can be s validator --depth=0 /path/to/search ``` -![Custom Recursion Run](./img/custom_recursion.png) +![Custom Recursion Run](./img/custom_recursion.gif) #### Customize report output -Customize the report output. Available options are `standard`, `junit`, and `json` +You can customize the report output and save the results to a file (default name is result.{extension}). The available report types are `standard`, `junit`, `json`, and `sarif`. You can specify multiple report types by chaining the `--reporter` flags. + +You can specify a path to an output file for any reporter by appending `:` the the name of the reporter. Providing an output file is optional and the results will be printed to stdout by default. To explicitly direct the output to stdout, use `:-` as the file path. ``` -validator --reporter=json /path/to/search +validator --reporter=json:- /path/to/search +validator --reporter=json:output.json --reporter=standard /path/to/search ``` -![Exclude File Types Run](./img/custom_reporter.png) +![Exclude File Types Run](./img/custom_reporter.gif) ### Group report output Group the report output by file type, directory, or pass-fail. Supports one or more groupings. @@ -190,21 +211,14 @@ Group the report output by file type, directory, or pass-fail. Supports one or m validator -groupby filetype ``` -![Groupby File Type](./img/gb-filetype.png) +![Groupby File Type](./img/gb-filetype.gif) #### Multiple groups ``` validator -groupby directory,pass-fail ``` -![Groupby File Type and Pass/Fail](./img/gb-filetype-and-pass-fail.png) - -### Output results to a file -Output report results to a file (default name is `result.{extension}`). Must provide reporter flag with a supported extension format. Available options are `junit` and `json`. If an existing directory is provided, create a file named default name in the given directory. If a file name is provided, create a file named the given name at the current working directory. - -``` -validator --reporter=json --output=/path/to/dir -``` +![Groupby File Type and Pass/Fail](./img/gb-filetype-and-pass-fail.gif) ### Suppress output Passing the `--quiet` flag suppresses all output to stdout. If there are invalid config files the validator tool will exit with 1. Any errors in execution such as an invalid path will still be displayed. @@ -213,12 +227,22 @@ Passing the `--quiet` flag suppresses all output to stdout. If there are invalid validator --quiet /path/to/search ``` -#### Container Run -``` -docker run -it --rm -v /path/to/config/files:/test config-file-validator:1.6.0 /test +### Search files using a glob pattern + +Use the `-globbing` flag to validate files matching a specified pattern. Include the pattern as a positional argument in double quotes. Multiple glob patterns and direct file paths are supported. If invalid config files are detected, the validator tool exits with code 1, and errors (e.g., invalid patterns) are displayed. + +[Learn more about glob patterns](https://www.digitalocean.com/community/tools/glob) + ``` +# Validate all `.json` files in a directory +validator -globbing "/path/to/files/*.json" + +# Recursively validate all `.json` files in subdirectories +validator -globbing "/path/to/files/**/*.json" -![Docker Standard Run](./img/docker_run.png) +# Mix glob patterns and paths +validator -globbing "/path/*.json" /path/to/search +``` ## Build The project can be downloaded and built from source using an environment with Go 1.21+ installed. After a successful build, the binary can be moved to a location on your operating system PATH. @@ -285,7 +309,7 @@ cp .\validator.exe 'C:\Program Files\validator' You can also use the provided Dockerfile to build the config file validator tool as a container ``` -docker build . -t config-file-validator:v1.6.0 +docker build . -t config-file-validator:v1.8.0 ``` ## Contributors diff --git a/pkg/cli/cli.go b/pkg/cli/cli.go index 0a3489fc..8cbe6e5f 100644 --- a/pkg/cli/cli.go +++ b/pkg/cli/cli.go @@ -151,7 +151,7 @@ func (c CLI) printGroupSingle(reports []reporter.Report) error { // Check reporter type to determine how to print for _, reporterObj := range c.Reporters { - if _, ok := reporterObj.(reporter.JSONReporter); ok { + if _, ok := reporterObj.(*reporter.JSONReporter); ok { return reporter.PrintSingleGroupJSON(reportGroup) } } @@ -167,7 +167,7 @@ func (c CLI) printGroupDouble(reports []reporter.Report) error { // Check reporter type to determine how to print for _, reporterObj := range c.Reporters { - if _, ok := reporterObj.(reporter.JSONReporter); ok { + if _, ok := reporterObj.(*reporter.JSONReporter); ok { return reporter.PrintDoubleGroupJSON(reportGroup) } } @@ -182,7 +182,7 @@ func (c CLI) printGroupTriple(reports []reporter.Report) error { } for _, reporterObj := range c.Reporters { - if _, ok := reporterObj.(reporter.JSONReporter); ok { + if _, ok := reporterObj.(*reporter.JSONReporter); ok { return reporter.PrintTripleGroupJSON(reportGroup) } } diff --git a/pkg/reporter/json_reporter.go b/pkg/reporter/json_reporter.go index 90c777ff..66338193 100644 --- a/pkg/reporter/json_reporter.go +++ b/pkg/reporter/json_reporter.go @@ -151,7 +151,7 @@ func PrintDoubleGroupJSON(groupReports map[string]map[string][]Report) error { return nil } -// Prinnts the report for when three groups are passed in the groupby flag +// Prints the report for when three groups are passed in the groupby flag func PrintTripleGroupJSON(groupReports map[string]map[string]map[string][]Report) error { var jsonReport tripleGroupReportJSON totalPassed := 0 diff --git a/pkg/reporter/sarif_reporter.go b/pkg/reporter/sarif_reporter.go index b775a254..e55d3e8e 100644 --- a/pkg/reporter/sarif_reporter.go +++ b/pkg/reporter/sarif_reporter.go @@ -10,7 +10,7 @@ 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" +const DriverVersion = "1.8.0" type SARIFReporter struct { outputDest string @@ -121,13 +121,13 @@ func (sr SARIFReporter) Print(reports []Report) error { 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) } + if len(reports) > 0 && !reports[0].IsQuiet { + fmt.Print(string(sarifBytes)) + } + return nil } diff --git a/test/output/example/result.sarif b/test/output/example/result.sarif index e86e9f47..b25862b8 100644 --- a/test/output/example/result.sarif +++ b/test/output/example/result.sarif @@ -7,7 +7,7 @@ "driver": { "name": "config-file-validator", "informationUri": "https://github.com/Boeing/config-file-validator", - "version": "1.7.1" + "version": "1.8.0" } }, "results": [