Skip to content

Commit

Permalink
Support offline validation (no network) using only built-in, local sc…
Browse files Browse the repository at this point in the history
…hema

Signed-off-by: Matt Rutkowski <[email protected]>
  • Loading branch information
mrutkows committed Nov 16, 2024
2 parents 8031926 + 39bfb28 commit c221d3f
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 7 deletions.
11 changes: 11 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,17 @@
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [

{
"showGlobalVariables": true,
"name": "Debug: validate",
"type": "go",
"request": "launch",
"mode": "debug",
"program": "main.go", // "program": "${file}",
"args": ["validate", "-i", "examples/cyclonedx/SBOM/protonmail-webclient-v4-0912dff/bom.json"],
"dlvFlags": ["--check-go-version=false"]
},
{
"showGlobalVariables": true,
"name": "Debug: validate (offline)",
Expand Down
15 changes: 9 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,10 @@ Use the [schema](#schema) command to list supported schemas formats, versions an

Customized JSON schemas can also be permanently configured as named schema "variants" within the utility's configuration file. See [adding schemas](#adding-schemas).

- **Overriding default schema**
- Using the [`--force` flag](#--force-flag) and passing in a URI to an alternative JSON schema.
- **"Customized" schema** variants, perhaps derived from standard BOM schemas, can be used for validation using the `--variant` flag (e.g., industry or company-specific schemas).
- **Note**: *These variants need to be built into the utility binary as a resource.*
- **Overriding default schema**
- Using the [`--force` flag](#--force-flag) and passing in a URI to an alternative JSON schema.
- **"Customized" schema** variants, perhaps derived from standard BOM schemas, can be used for validation using the `--variant` flag (e.g., industry or company-specific schemas).
Expand All @@ -339,6 +343,11 @@ The following flags can be used to improve performance when formatting error out

##### `--force` flag

You can override the schema used for validation *(which defaults to the schema that matches the declared format and version found in the input BOM file)* by providing a different one using the `--force` flag. This may be useful to verify a BOM contents against a newer specification version or provide a customized schema.
- **Note**: *The `--force` flag works with schema files with valid URIs which include URLs (e.g., 'https://') and files (e.g., 'file://').*

##### `--force` flag

You can override the schema used for validation *(which defaults to the schema that matches the declared format and version found in the input BOM file)* by providing a different one using the `--force` flag. This may be useful to verify a BOM contents against a newer specification version or provide a customized schema.
- **Note**: *The `--force` flag works with schema files with valid URIs which include URLs (e.g., 'https://') and files (e.g., 'file://').*

Expand Down Expand Up @@ -386,12 +395,6 @@ echo $?
0 // no error (valid)
```
##### Example: Validate 1.5
```bash
./sbom-utility validate -i test/cyclonedx/cdx-1-5-mature-example-1.json
```
##### Example: Validate using a remote JSON schema file using '--force' flag
```bash
Expand Down
2 changes: 1 addition & 1 deletion cmd/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ func Validate(writer io.Writer, persistentFlags utils.PersistentCommandFlags, va
}

if errLoad != nil {
return INVALID, bom, schemaErrors, fmt.Errorf("unable to load schema: '%s'", schemaName)
return INVALID, bom, schemaErrors, fmt.Errorf("unable to load schema: `%s`", schemaName)
}
}

Expand Down

0 comments on commit c221d3f

Please sign in to comment.