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

feat: case updates for cli #22

Merged
merged 1 commit into from
Dec 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
9 changes: 6 additions & 3 deletions .grant.yaml
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
#.grant.yaml
show-packages: false
ignore-orphan-packages: false
check-non-spdx: true
format: table
rules:
- pattern: "*gpl*"
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"
Expand Down
6 changes: 4 additions & 2 deletions cmd/grant/cli/internal/check/report.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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
Expand Down
3 changes: 0 additions & 3 deletions grant/case.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
17 changes: 15 additions & 2 deletions grant/evalutation/license_evalutation.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down