You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Trim() JSON document keys only under paths supplied using the '--from' flag (#63)
* support parsing the 'paths' flag from command line
Signed-off-by: Matt Rutkowski <[email protected]>
* Assure BOM hashing works with Trim changes
Signed-off-by: Matt Rutkowski <[email protected]>
* Use a custom JSON encoder to assure Trim() does not use HTML encoding this preserving fidelity
Signed-off-by: Matt Rutkowski <[email protected]>
* Move QueryRequest and QueryResult structs to common package
Signed-off-by: Matt Rutkowski <[email protected]>
* Move LicenseInfo struct to schema package as an abstract type
Signed-off-by: Matt Rutkowski <[email protected]>
* Prevent cmd package from accessing QueryRequest fields directly
Signed-off-by: Matt Rutkowski <[email protected]>
* Complete work to insulate QueryRequest and its parsing from the cmd package
Signed-off-by: Matt Rutkowski <[email protected]>
* Initial support for the Trim() --from flag
Signed-off-by: Matt Rutkowski <[email protected]>
* Improve temp file creation for Temp() tests
Signed-off-by: Matt Rutkowski <[email protected]>
* Improve temp file creation for Temp() tests
Signed-off-by: Matt Rutkowski <[email protected]>
* Improve query command to allow FROM to be used to select entire slices
Signed-off-by: Matt Rutkowski <[email protected]>
* Trim() should use shared encode JSON method from utils package
Signed-off-by: Matt Rutkowski <[email protected]>
* Remove unused query request flags
Signed-off-by: Matt Rutkowski <[email protected]>
* Streamline error handline in Query() internal methods
Signed-off-by: Matt Rutkowski <[email protected]>
* Restructure internal Query() methods to allow for reuse of JSON maps
Signed-off-by: Matt Rutkowski <[email protected]>
* Restructure internal Query() methods to allow for reuse of JSON maps
Signed-off-by: Matt Rutkowski <[email protected]>
* Add additional Query() tests for new logic that can return slices of FROM objects
Signed-off-by: Matt Rutkowski <[email protected]>
* Add additional Query() tests for new logic that can return slices of FROM objects
Signed-off-by: Matt Rutkowski <[email protected]>
* Add new README example for the improved Query() of slices
Signed-off-by: Matt Rutkowski <[email protected]>
* Add basic information on Trim command to README
Signed-off-by: Matt Rutkowski <[email protected]>
* Add flag and example or the Trim command to README
Signed-off-by: Matt Rutkowski <[email protected]>
* Add 2 more examples of Trim() command
Signed-off-by: Matt Rutkowski <[email protected]>
* Add additional tests to validate output bytes
Signed-off-by: Matt Rutkowski <[email protected]>
* Add additional buffer test and document command completion
Signed-off-by: Matt Rutkowski <[email protected]>
* Ensure all Go source files include a SPDX-License-Identifier
Signed-off-by: Matt Rutkowski <[email protected]>
---------
Signed-off-by: Matt Rutkowski <[email protected]>
Copy file name to clipboardExpand all lines: README.md
+306-6Lines changed: 306 additions & 6 deletions
Original file line number
Diff line number
Diff line change
@@ -8,7 +8,7 @@ The utility has now grown to include a rich set of commands, listed below, that
8
8
9
9
## Command Overview
10
10
11
-
The utility supports the following commands:
11
+
The utility supports the following BOM-related commands:
12
12
13
13
-**[license](#license)**
14
14
-**[list](#license-list-subcommand)** produce listings or summarized reports of license data contained in a BOM along with license "usage policy" determinations using the policies declared in the `license.json` file.
@@ -27,6 +27,14 @@ The utility supports the following commands:
27
27
28
28
-**[vulnerability](#vulnerability)** produce filterable listings or summarized reports of vulnerabilities from BOM data (i.e., CycloneDX Vulnerability Exploitability eXchange (**VEX**)) data or independently stored CycloneDX Vulnerability Disclosure Report (**VDR**) data.
29
29
30
+
**Experimental commands**:
31
+
32
+
Feedback and helpful commits appreciated on the following commands which will be moved to non-experimental after two point releases:
33
+
34
+
-**[diff](#diff)** : Shows the delta between two similar BOM versions in
35
+
36
+
-**[trim](#trim)** provide the ability to remove JSON information, by field key and limited query syntax, from the input JSON BOM document.
37
+
30
38
---
31
39
32
40
## Index
@@ -45,7 +53,9 @@ The utility supports the following commands:
45
53
-[`schema` command](#schema): list supported BOM formats, versions, variants
46
54
-[`validate` command](#validate): BOM against declared or required schema
47
55
-[`vulnerability` command](#vulnerability): lists vulnerability summary information included in the BOM or VEX
48
-
-[`diff` command](#diff): *experimental*: shows the delta between two BOM versions
56
+
-[`diff` command](#diff): *experimental*: shows the delta between two similar BOM versions
57
+
-[`trim` command](#diff): *experimental*: remove specified fields from JSON BOM documents and output smaller BOMs that are appropriate sized for different use cases and analysis
58
+
-[`completion` command](#completion): generates command-line completion scripts for the utility
49
59
-[Design considerations](#design-considerations)
50
60
-[Development](#development)
51
61
-[Prerequisites](#prerequisites)
@@ -110,10 +120,9 @@ For convenience, links to each command's section are here:
110
120
-[schema](#schema)
111
121
-[vulnerability](#vulnerability)
112
122
-[validate](#validate)
123
+
-[completion](#completion)
113
124
-[help](#help)
114
125
115
-
### General command information
116
-
117
126
#### Exit codes
118
127
119
128
All commands return a numeric exit code (i.e., a POSIX exit code) for use in automated processing where `0` indicates success and a non-zero value indicates failure of some kind designated by the number.
This command allows you to perform SQL-like queries into JSON format SBOMs. Currently, the command recognizes the `--select` and `--from` as well as the `--where` filter.
554
563
564
+
#### Query flags
565
+
566
+
##### Query `--from` flag
567
+
555
568
The `--from` clause value is applied to the JSON document object model and can return either a singleton JSON object or an array of JSON objects as a result. This is determined by the last property value's type as declared in the schema.
556
569
570
+
##### Query `--select` flag
571
+
557
572
The `--select` clause is then applied to the `--from` result set to only return the specified properties (names and their values).
558
573
574
+
##### Query `--where` flag
575
+
559
576
If the result set is an array, the array entries can be reduced by applying the `--where` filter to ony return those entries whose specified field names match the supplied regular expression (regex).
560
577
561
578
**Note**: All `query` command results are returned as valid JSON documents. This includes a `null` value for empty result sets.
@@ -564,9 +581,11 @@ If the result set is an array, the array entries can be reduced by applying the
564
581
565
582
The `query` command only supports JSON output.
566
583
584
+
-`json` (default)
585
+
567
586
#### Query result sorting
568
587
569
-
The `query` command does not support output results.
588
+
The `query` command does not support formatting of output results as JSON format is always returned.
570
589
571
590
#### Query examples
572
591
@@ -650,6 +669,56 @@ In this example, the `--from` clause references the singleton JSON object `compo
650
669
}
651
670
```
652
671
672
+
##### Example: Return the JSON array of components
673
+
674
+
In this example, the `--from` filter will return the entire JSON components array.
**Note**: The command for this example only used the `--from` flag and did not need to supply `--select '*'` as this us the default.
721
+
653
722
##### Example: Filter result entries with a specified value
654
723
655
724
In this example, the `--where` filter will be applied to a set of `properties` results to only include entries that match the specified regex.
@@ -807,6 +876,218 @@ For details see the "[Adding SBOM formats, schema versions and variants](#adding
807
876
808
877
If you wish to have the new schema *embedded in the executable*, simply add it to the project's `resources` subdirectory following the format and version-based directory structure.
809
878
879
+
### Trim
880
+
881
+
This command is able to "trim" one or more JSON keys (fields) from specified JSON BOM documents effectively "pruning" the JSON document. This functionality helps consumers of large-sized BOMs that need to analyze specific types of data in large BOMs in reducing the BOM data to just what is needed for their use cases or needs.
882
+
883
+
#### Trim supported output formats
884
+
885
+
This command is used to output, using the [`--output-file` flag](#output-flag), a "trimmed" BOM in JSON format.
886
+
887
+
- `json` (default)
888
+
889
+
#### Trim flags
890
+
891
+
Trim operates on a JSON BOM input file (see [`--input-file` flag](#input-flag)) and produces a trimmed JSON BOM output file using the following flags:
892
+
893
+
##### Trim `--keys` flag
894
+
895
+
A comma-separated list of JSON map keys. Similar to the [query command's `--select` flag](#query---select-flag) syntax.
896
+
897
+
##### Trim `--from` flag
898
+
899
+
A comma-separated list of JSON document paths using the same syntax as the [query command's `--from` flag](#query---from-flag).
900
+
901
+
#### Trim examples
902
+
903
+
The original BOM used for these examples can be found here:
This *experimental*command will compare two BOMs and return the delta (or "diff") in JSON (diff-patch format) or text.
1449
+
This *experimental*command will compare two *similar*BOMs and return the delta (or "diff") in JSON (diff-patch format) or text. This functionality is based upon code ancestral to that used to report file diffs between `git commit`s.
1169
1450
1170
1451
##### Notes
1171
1452
@@ -1217,6 +1498,25 @@ Use the `--format` flag on the to choose one of the supported output formats:
1217
1498
1218
1499
---
1219
1500
1501
+
#### Completion
1502
+
1503
+
This command will generate command-line completion scripts, for the this utility, customized for various supported shells.
1504
+
1505
+
The completion command can be invoked as follows:
1506
+
1507
+
```bash
1508
+
./sbom_utility completion [shell]
1509
+
```
1510
+
1511
+
where valid values for`shell` are:
1512
+
1513
+
- bash
1514
+
- fish
1515
+
- powershell
1516
+
- zsh
1517
+
1518
+
---
1519
+
1220
1520
### Help
1221
1521
1222
1522
The utility supports the `help`commandfor the root command as well as any supported commands
0 commit comments