-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: spdx license list generation (#3)
* wip: wip Signed-off-by: Christopher Phillips <[email protected]> * feat: add code generation for spdx license list Signed-off-by: Christopher Phillips <[email protected]> * chore: update generated license list with lower case ID Signed-off-by: Christopher Phillips <[email protected]> --------- Signed-off-by: Christopher Phillips <[email protected]>
- Loading branch information
Showing
11 changed files
with
7,653 additions
and
225 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,3 +39,4 @@ go.work.sum | |
|
||
# mac | ||
.DS_Store | ||
*.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,45 @@ | ||
package grant | ||
|
||
import ( | ||
"github.com/anchore/syft/syft/pkg" | ||
) | ||
|
||
type License struct { | ||
// SPDXExpression is the SPDX expression for the license | ||
SPDXExpression string `json:"spdxExpression"` | ||
// Name is the name of the individual license if SPDXExpression is unset | ||
Name string `json:"name"` | ||
// Value is contents of the license | ||
Value string `json:"value"` | ||
// Locations are the paths for a package that show evidence of the license | ||
Locations []string `json:"location"` | ||
} | ||
|
||
// ConvertSyftLicenses converts a syft LicenseSet to a grant License slice | ||
func ConvertSyftLicenses(set pkg.LicenseSet) (licenses []License) { | ||
licenses = make([]License, 0) | ||
for _, lic := range set.ToSlice() { | ||
// get all the locations for the license | ||
locations := lic.Locations.ToSlice() | ||
licenseLocations := make([]string, 0) | ||
for _, location := range locations { | ||
licenseLocations = append(licenseLocations, location.RealPath) | ||
} | ||
|
||
if lic.SPDXExpression != "" { | ||
licenses = append(licenses, License{ | ||
SPDXExpression: lic.SPDXExpression, | ||
Locations: licenseLocations, | ||
}) | ||
continue | ||
} | ||
|
||
// no spdx expression from syft so just add the license as-is | ||
// currently these are ignored by the checker | ||
licenses = append(licenses, License{ | ||
Name: lic.Value, | ||
Locations: licenseLocations, | ||
}) | ||
} | ||
return licenses | ||
} |
Oops, something went wrong.