From 430f83b00afe866d33760187cac8eb576d824e63 Mon Sep 17 00:00:00 2001 From: Christopher Phillips Date: Tue, 12 Dec 2023 03:05:28 -0500 Subject: [PATCH] feat: case updates for cli Signed-off-by: Christopher Phillips --- .grant.yaml | 9 ++++++--- cmd/grant/cli/internal/check/report.go | 6 ++++-- grant/case.go | 3 --- grant/evalutation/license_evalutation.go | 17 +++++++++++++++-- 4 files changed, 25 insertions(+), 10 deletions(-) diff --git a/.grant.yaml b/.grant.yaml index 5d1a827..83576d8 100644 --- a/.grant.yaml +++ b/.grant.yaml @@ -1,5 +1,6 @@ #.grant.yaml show-packages: false +ignore-orphan-packages: false check-non-spdx: true format: table rules: @@ -7,13 +8,15 @@ rules: name: "gpl-denied" mode: "deny" reason: "GPL licenses are not allowed per xxx-xx company policy" - exclusions: - - "alpine-base-layout" # We don't link against this package so we don't care about its license + exceptions: + - "alpine-baselayout" # We don't link against this package so we don't care about its license + - "base-files" + - "netbase" - pattern: "*BSD*" name: "bsd-denied" mode: "deny" reason: "BSD licenses are not allowed per xxx-xx company policy" - exclusions: + exceptions: - "1apt" - "1bsdutils" - "1dash" diff --git a/cmd/grant/cli/internal/check/report.go b/cmd/grant/cli/internal/check/report.go index 2da8c56..4049f5e 100644 --- a/cmd/grant/cli/internal/check/report.go +++ b/cmd/grant/cli/internal/check/report.go @@ -94,7 +94,7 @@ func (r *Report) renderCheckTree() error { failedEvaluations := r.Results.GetFailedEvaluations(res.Case.UserInput, rule) if len(failedEvaluations) == 0 { resulList.Indent() - resulList.AppendItem(color.Success.Sprintf("%s", "No License Violations Found")) + resulList.AppendItem(color.Success.Sprintf("No License Violations Found for Rule %s", rule.Name)) resulList.UnIndent() continue } @@ -148,7 +148,9 @@ func (r *Report) renderList() error { resulList.UnIndent() } } - renderOrphanPackages(resulList, res, true) + if r.Config.ShowPackages { + renderOrphanPackages(resulList, res, true) + } } // segment the results into lists by user input diff --git a/grant/case.go b/grant/case.go index 42f45bc..cff6faa 100644 --- a/grant/case.go +++ b/grant/case.go @@ -277,9 +277,6 @@ func grantLicenseFromClassifierResults(r results.LicenseTypes) []License { }) } else { licenses = append(licenses, License{ - SPDXExpression: license.Name, - Name: spdxLicense.Name, - //Locations: , we know this with the path Reference: spdxLicense.Reference, IsDeprecatedLicenseID: spdxLicense.IsDeprecatedLicenseID, DetailsURL: spdxLicense.DetailsURL, diff --git a/grant/evalutation/license_evalutation.go b/grant/evalutation/license_evalutation.go index 55503eb..314198f 100644 --- a/grant/evalutation/license_evalutation.go +++ b/grant/evalutation/license_evalutation.go @@ -139,19 +139,32 @@ func (le LicenseEvaluations) GetLicenses() []string { licenseMap := make(map[string]struct{}) // get the set of unique licenses from the list for the given package... for _, e := range le { - if _, ok := licenseMap[e.License.SPDXExpression]; !ok && e.License.SPDXExpression != "" { + if _, ok := licenseMap[e.License.LicenseID]; !ok && e.License.LicenseID != "" { licenseMap[e.License.LicenseID] = struct{}{} - licenses = append(licenses, e.License.SPDXExpression) + licenses = append(licenses, e.License.LicenseID) } if _, ok := licenseMap[e.License.Name]; !ok && e.License.Name != "" { licenseMap[e.License.Name] = struct{}{} licenses = append(licenses, e.License.Name) } } + licenses = removeDuplicates(licenses) sort.Strings(licenses) return licenses } +func removeDuplicates(elements []string) []string { + encountered := map[string]bool{} + result := []string{} + for _, element := range elements { + if !encountered[element] { + encountered[element] = true + result = append(result, element) + } + } + return result +} + func (le LicenseEvaluations) Failed(r grant.Rule) LicenseEvaluations { var failed LicenseEvaluations for _, e := range le {