Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for where filter and text wrap in license policy command #16

Merged
merged 22 commits into from
Apr 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
8cc559a
Update license policy command to support multi-row output for text fo…
mrutkows Apr 7, 2023
483934b
Support common tests for report contains(values) pattern
mrutkows Apr 12, 2023
0b0f3b5
Fix linting errors
mrutkows Apr 12, 2023
d86fae3
Fix linting errors
mrutkows Apr 12, 2023
5127f7f
Abstract license policy test info and stub in --where flag
mrutkows Apr 12, 2023
8d36997
Expose wrap flag on policy command
mrutkows Apr 13, 2023
4814b8e
Update help and README to document the wrap flag
mrutkows Apr 13, 2023
11ffb0c
Update license policy output example to reflect new column names
mrutkows Apr 13, 2023
665795d
Update license policy output example to reflect new column names
mrutkows Apr 13, 2023
480c5b3
Update license policy output example to reflect new column names
mrutkows Apr 13, 2023
03f3874
Add generic function that wraps text across report tables rows
mrutkows Apr 14, 2023
380aa46
Simplify exhaustive policy list test
mrutkows Apr 14, 2023
688c06c
Always Reset() global license policy config on new load
mrutkows Apr 14, 2023
297b85c
Add initial --where filter support for license policy cmd
mrutkows Apr 14, 2023
d098da9
Improve init. of filtered hashmap
mrutkows Apr 17, 2023
e81593a
Support filtered policies for csv and markdown formats
mrutkows Apr 17, 2023
c0e0e4a
Document where flag support for policy command in README
mrutkows Apr 17, 2023
9f4b564
lint fix
mrutkows Apr 17, 2023
437a676
lint fix
mrutkows Apr 17, 2023
cc054a3
Document where flag support for policy command in README
mrutkows Apr 17, 2023
164c945
Document where flag support for policy command in README
mrutkows Apr 17, 2023
910682a
Document where flag support for policy command in README
mrutkows Apr 17, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"databind",
"Debugf",
"defn",
"deserializers",
"DHTML",
"EMEA",
"Exploitability",
Expand Down
42 changes: 32 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -435,20 +435,42 @@ To view a report listing the contents of the current policy file (i.e., [`licens
```

```bash
Policy Family SPDX ID Name Annotations
------ ------ ------- ---- -----------
allow 0BSD 0BSD BSD Zero Clause Lice APPROVED
allow AFL AFL-3.0 Academic Free Licens APPROVED
needs-review AGPL AGPL-3.0-or-later Affero General Publi NEEDS-APPROVAL
needs-review APSL APSL-2.0 Apple Public Source NEEDS-APPROVAL
allow Adobe Adobe-2006 Adobe Systems Incorp APPROVED
allow Apache Apache-2.0 Apache License 2.0 APPROVED
usage-policy family spdx-id name annotations aliases notes
------------ ------ ------- ---- ----------- ------- -----
allow 0BSD 0BSD BSD Zero Clause Lice (20/23) APPROVED Free Public License 1.0. (24/25)
needs-review ADSL ADSL Amazon Digital Servi (20/31) NEEDS-APPROVAL
allow AFL AFL-1.1 Academic Free Licens (20/26) APPROVED
needs-review AGPL AGPL-1.0 Affero General Publi (20/34) NEEDS-APPROVAL,AGPL-WARN (24/38)
needs-review APSL APSL-1.0 Apple Public Source (20/27) NEEDS-APPROVAL
allow Adobe Adobe-2006 Adobe Systems Incorp (20/56) APPROVED
allow Apache Apache-2.0 Apache License 2.0 APPROVED Apache License, Version (24/105)
...
```

- **Note**:
- Currently, the default `license.json` file does not contain an entry for the complete SPDX 3.2 license templates. An issue [12](https://github.com/CycloneDX/sbom-utility/issues/12) is open to add parity.
- Annotations can be defined within the `license.json` file and one or more assigned each license entry.
- Column data is, by default, truncated in `txt` format views only. In these cases, the number of characters shown out of the total available will be displayed at the point of truncation (e.g., seeing `(24/26)` in a column would indicate 24 out of 26b characters were displayed).

##### Wrap flag

Use the `--wrap` flag to toggle the wrapping of text within columns of the license policy report (`txt` format only) output using the values `true` or `false`. The default value is `false`.

###### Example: policy with where filter

The following example shows filtering of license policies using the `id` column:

```bash
./sbom-utility license policy --where id=Apache
```

```bash
usage-policy family id name annotations aliases notes
------------ ------ -- ---- ----------- ------- -----
allow Apache Apache-1.0 Apache v1.0 APPROVED
allow Apache Apache-1.1 Apache v1.1 APPROVED This license has been su (24/54)
allow Apache Apache-2.0 Apache License 2.0 APPROVED Apache License, Version (24/105)
```

---

Expand Down Expand Up @@ -811,7 +833,7 @@ Currently, all `vulnerability list` command results are sorted by vulnerability
```

```bash
id bom-ref source-name source-url created published updated rejected description
id bom-ref source-name source-url created published updated rejected description
-- ------- ---------- ----------- ------- --------- ------- -------- -----------
CVE-2020-25649 NVD https://nvd.nist.gov/vuln/detail/CVE-2020-25649 2020-12-03T00:00:00.000Z 2020-12-03T00:00:00.000Z 2023-02-02T00:00:00.000Z com.fasterxml.jackson.core:jackson-databind is a library which contains the general-purpose data-binding functionality and tree-model for Jackson Data Processor. Affected versions of this package are vulnerable to XML External Entity (XXE) Injection.
CVE-2022-42003 NVD https://nvd.nist.gov/vuln/detail/CVE-2022-42003 2022-10-02T00:00:00.000Z 2022-10-02T00:00:00.000Z 2022-10-02T00:00:00.000Z In FasterXML jackson-databind before 2.14.0-rc1, resource exhaustion can occur because of a lack of a check in primitive value deserializers to avoid deep wrapper array nesting, when the UNWRAP_SINGLE_VALUE_ARRAYS feature is enabled.
Expand All @@ -825,7 +847,7 @@ CVE-2022-42004 NVD https://nvd.nist.gov/vuln/detail/CVE-2022-4
```

```bash
id bom-ref source-name source-url created published updated rejected description
id bom-ref source-name source-url created published updated rejected description
-- ------- ---------- ----------- ------- --------- ------- -------- -----------
CVE-2020-25649 NVD https://nvd.nist.gov/vuln/detail/CVE-2020-25649 2020-12-03T00:00:00.000Z 2020-12-03T00:00:00.000Z 2023-02-02T00:00:00.000Z com.fasterxml.jackson.core:jackson-databind is a library which contains the general-purpose data-binding functionality and tree-model for Jackson Data Processor. Affected versions of this package are vulnerable to XML External Entity (XXE) Injection.
```
Expand Down
4 changes: 1 addition & 3 deletions cmd/license.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ func ClearGlobalLicenseData() {
}

func HashLicenseInfo(key string, licenseInfo LicenseInfo, whereFilters []WhereFilter) {
// Append to slice
// Find license usage policy by either license Id, Name or Expression
policy, err := FindPolicy(licenseInfo)

if err != nil {
Expand Down Expand Up @@ -174,8 +174,6 @@ func loadDocumentLicenses(document *schema.Sbom, whereFilters []WhereFilter) (er
// NOTE: DEBUG: use this to debug license policy hashmaps have appropriate # of entries
//licensePolicyConfig.Debug()

// TODO Support processing of []WhereFilter

// At this time, fail SPDX format SBOMs as "unsupported" (for "any" format)
if !document.FormatInfo.IsCycloneDx() {
err = schema.NewUnsupportedFormatForCommandError(
Expand Down
29 changes: 6 additions & 23 deletions cmd/license_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,24 +36,18 @@ import (
// TODO: Support a new --sort <column> flag
const (
FLAG_LICENSE_SUMMARY = "summary"
FLAG_LICENSE_EXCLUDE = "exclude"
FLAG_LICENSE_POLICY = "policy" // policy-match, policy-filter, etc.
)

// License list command flag help messages
const (
FLAG_LICENSE_LIST_OUTPUT_FORMAT_HELP = "format output using the specified format type"
FLAG_LICENSE_LIST_SUMMARY_HELP = "summarize licenses and component references in table format (see --format flag help for supported types)"
FLAG_LICENSE_LIST_EXCLUDE_HELP = "exclude policy column from summary listing"
FLAG_LICENSE_LIST_POLICY_HELP = "filter license summary by usage policy (i.e., allow|deny|needs-review|UNDEFINED)"
)

// License list command informational messages
const (
MSG_OUTPUT_NO_LICENSES_FOUND = "No licenses found in BOM document"
MSG_OUTPUT_NO_LICENSES_ONLY_NOASSERTION = "No valid licenses found in BOM document (only licenses marked NOASSERTION)"
MSG_OUTPUT_NO_SCHEMAS_FOUND = "[WARN] no schemas found in configuration (i.e., \"config.json\")"
MSG_OUTPUT_NO_RESOURCES_FOUND = "[WARN] no matching resources found for query"
MSG_OUTPUT_NO_LICENSES_FOUND = "no licenses found in BOM document"
MSG_OUTPUT_NO_LICENSES_ONLY_NOASSERTION = "no valid licenses found in BOM document (only licenses marked NOASSERTION)"
)

//"Type", "ID/Name/Expression", "Component(s)", "BOM ref.", "Document location"
Expand Down Expand Up @@ -111,24 +105,13 @@ func NewCommandList() *cobra.Command {
&utils.GlobalFlags.LicenseFlags.Summary,
FLAG_LICENSE_SUMMARY, "", false,
FLAG_LICENSE_LIST_SUMMARY_HELP)
command.Flags().StringVarP(
&utils.GlobalFlags.LicenseFlags.Policy,
FLAG_LICENSE_POLICY, "", "",
FLAG_LICENSE_LIST_POLICY_HELP)
command.Flags().StringP(FLAG_REPORT_WHERE, "", "", FLAG_REPORT_WHERE_HELP)
command.RunE = listCmdImpl
command.PreRunE = func(cmd *cobra.Command, args []string) (err error) {
if len(args) != 0 {
return getLogger().Errorf("Too many arguments provided: %v", args)
}

// Validate command line flag combinations
// TODO: document this flag relationship more clearly
bSummary := utils.GlobalFlags.LicenseFlags.Summary
if utils.GlobalFlags.LicenseFlags.Policy != "" && !bSummary {
return getLogger().Errorf("`%s` flag not valid without `%s` flag", FLAG_LICENSE_POLICY, FLAG_LICENSE_SUMMARY)
}

// Test for required flags (parameters)
err = preRunTestForInputFile(cmd, args)
return
Expand Down Expand Up @@ -500,11 +483,11 @@ func DisplayLicenseListSummaryCSV(output io.Writer) (err error) {
// which is automatically done by the CSV writer
currentRow = append(currentRow,
licenseInfo.Policy.UsagePolicy,
licenseInfo.LicenseChoiceType, //LC_TYPE_NAMES[licenseInfo.LicenseChoiceTypeValue],
licenseInfo.LicenseChoiceType,
licenseName.(string),
licenseInfo.ResourceName,
licenseInfo.BomRef,
licenseInfo.BomLocation, //CDX_LICENSE_LOCATION_NAMES[licenseInfo.BomLocationValue]
licenseInfo.BomLocation,
)

if errWrite := w.Write(currentRow); errWrite != nil {
Expand Down Expand Up @@ -555,11 +538,11 @@ func DisplayLicenseListSummaryMarkdown(output io.Writer) {
// Format line and write to output
line = append(line,
licenseInfo.Policy.UsagePolicy,
licenseInfo.LicenseChoiceType, // LC_TYPE_NAMES[licenseInfo.LicenseChoiceTypeValue],
licenseInfo.LicenseChoiceType,
licenseName.(string),
licenseInfo.ResourceName,
licenseInfo.BomRef,
licenseInfo.BomLocation, // CDX_LICENSE_LOCATION_NAMES[licenseInfo.BomLocationValue]
licenseInfo.BomLocation,
)

lineRow = createMarkdownRow(line)
Expand Down
Loading