Skip to content

Commit

Permalink
tmp
Browse files Browse the repository at this point in the history
Signed-off-by: Caroline Russell <[email protected]>
  • Loading branch information
cerrussell committed Jun 5, 2024
1 parent 78ab3ff commit 92c6a34
Show file tree
Hide file tree
Showing 13 changed files with 528 additions and 287 deletions.
66 changes: 50 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# custom-json-diff

Comparing two JSON files presents an issue when the two files have certain fields which are
dynamically generated (e.g. timestamps), variable ordering, or other field which need to be
dynamically generated (e.g. timestamps), variable ordering, or other fields which need to be
excluded for one reason or another. Enter custom-json-diff, which allows you to specify fields to
ignore in the comparison and sorts all fields.

Expand All @@ -13,36 +13,48 @@ ignore in the comparison and sorts all fields.
## CLI Usage

```
usage: cjd [-h] -i INPUT INPUT [-o OUTPUT] (-c CONFIG | -x EXCLUDE [EXCLUDE ...] | -p {cdxgen,cdxgen-extended}) {bom-diff} ...
usage: cjd [-h] -i INPUT INPUT [-o OUTPUT] [-c CONFIG] {bom-diff,json-diff} ...
positional arguments:
{bom-diff} subcommand help
{bom-diff,json-diff} subcommand help
bom-diff compare CycloneDX BOMs
json-diff compare two JSON files
options:
-h, --help show this help message and exit
-i INPUT INPUT, --input INPUT INPUT
Two JSON files to compare.
Two JSON files to compare - older file first.
-o OUTPUT, --output OUTPUT
Export JSON of differences to this file.
-c CONFIG, --config-file CONFIG
Import TOML configuration file.
-x EXCLUDE [EXCLUDE ...], --exclude EXCLUDE [EXCLUDE ...]
Exclude field(s) from comparison.
-p {cdxgen,cdxgen-extended}, --preset {cdxgen,cdxgen-extended}
Preset to use
Import TOML configuration file (overrides commandline options).
```

bom-diff usage
```
usage: cjd bom-diff [-h] [-a] [-r REPORT_TEMPLATE]
usage: cjd bom-diff [-h] [--allow-new-versions] [--allow-new-data] [--components-only] [-r REPORT_TEMPLATE] [--include-extra INCLUDE [INCLUDE ...]]
options:
-h, --help show this help message and exit
-a, --allow-new-versions
Allow new versions in BOM comparison.
--allow-new-versions, -anv
Allow newer versions in second BOM to pass.
--allow-new-data, -and
Allow populated BOM values in newer BOM to pass against empty values in original BOM.
--components-only Only compare components.
-r REPORT_TEMPLATE, --report-template REPORT_TEMPLATE
Jinja2 template to use for report generation.
--include-extra INCLUDE [INCLUDE ...]
Include properties/evidence/licenses/hashes in comparison (list which with space inbetween).
```

json-diff usage
```
usage: cjd json-diff [-h] [-x EXCLUDE [EXCLUDE ...]]
options:
-h, --help show this help message and exit
-x EXCLUDE [EXCLUDE ...], --exclude EXCLUDE [EXCLUDE ...]
Exclude field(s) from comparison.
```

## Specifying fields to exclude
Expand Down Expand Up @@ -81,6 +93,25 @@ be, check out json-flatten, which is the package used for this function.
>Note: In the context of BOM diffing, this list is only used for the metadata, not the components,
> services, or dependencies.
## Bom Diff

The bom-diff command compares CycloneDx BOM components, services, and dependencies, as well as data
outside of these parts.

Some fields are excluded from the component comparison by default but can be explicitly specified
for inclusion (see the Usage examples):
- properties
- evidence
- licenses

The --allow-new-versions option attempts to parse versions and ascertain if a discrepancy is
attributable to an updated version.

The --allow-new-data option allows for empty fields in the original BOM not to be reported as a
difference when the data is populated in the second specified BOM.

The --components-only option only analyzes components, not services, dependencies, or other data.

## Sorting

custom-json-diff will sort the imported JSON alphabetically. If your JSON document contains arrays
Expand All @@ -91,10 +122,13 @@ The first key located from the provided keys that is present in the object will

```toml
[settings]
excluded_fields = ["serialNumber", "metadata.timestamp"]
excluded_fields = []
sort_keys = ["url", "content", "ref", "name", "value"]

[bom_diff]
allow_new_versions = false
report_template = "my_template.j2"
[bom_settings]
allow_new_data = false
allow_new_versions = true
components_only = false
extra_included_fields = ["licenses", "properties", "evidence", "hashes"]
report_template = "custom_json_diff/bom_diff_template.j2"
```
Loading

0 comments on commit 92c6a34

Please sign in to comment.