mirror of
https://github.com/anchore/syft.git
synced 2026-11-05 00:46:38 +01:00
detect license ID from full text when incidentally provided as a value (#3876)
--------- Signed-off-by: Christopher Phillips <32073428+spiffcs@users.noreply.github.com> Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com> Co-authored-by: Alex Goodman <wagoodman@users.noreply.github.com>
This commit is contained in:
co-authored by
Alex Goodman
parent
b4d717fb30
commit
f77d503892
@@ -1,13 +1,15 @@
|
||||
package lua
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/anchore/packageurl-go"
|
||||
"github.com/anchore/syft/syft/file"
|
||||
"github.com/anchore/syft/syft/pkg"
|
||||
)
|
||||
|
||||
func newLuaRocksPackage(u luaRocksPackage, indexLocation file.Location) pkg.Package {
|
||||
license := pkg.NewLicensesFromLocation(indexLocation, u.License)
|
||||
func newLuaRocksPackage(ctx context.Context, u luaRocksPackage, indexLocation file.Location) pkg.Package {
|
||||
license := pkg.NewLicensesFromLocationWithContext(ctx, indexLocation, u.License)
|
||||
p := pkg.Package{
|
||||
Name: u.Name,
|
||||
Version: u.Version,
|
||||
|
||||
@@ -27,7 +27,7 @@ type repository struct {
|
||||
}
|
||||
|
||||
// parseRockspec parses a package.rockspec and returns the discovered Lua packages.
|
||||
func parseRockspec(_ context.Context, _ file.Resolver, _ *generic.Environment, reader file.LocationReadCloser) ([]pkg.Package, []artifact.Relationship, error) {
|
||||
func parseRockspec(ctx context.Context, _ file.Resolver, _ *generic.Environment, reader file.LocationReadCloser) ([]pkg.Package, []artifact.Relationship, error) {
|
||||
doc, err := parseRockspecData(reader)
|
||||
if err != nil {
|
||||
log.WithFields("error", err).Trace("unable to parse Rockspec app")
|
||||
@@ -64,6 +64,7 @@ func parseRockspec(_ context.Context, _ file.Resolver, _ *generic.Environment, r
|
||||
}
|
||||
|
||||
p := newLuaRocksPackage(
|
||||
ctx,
|
||||
luaRocksPackage{
|
||||
Name: name,
|
||||
Version: version,
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package lua
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"github.com/anchore/syft/syft/file"
|
||||
@@ -9,6 +10,7 @@ import (
|
||||
)
|
||||
|
||||
func TestParseRockspec(t *testing.T) {
|
||||
ctx := context.TODO()
|
||||
tests := []struct {
|
||||
Fixture string
|
||||
ExpectedPkg pkg.Package
|
||||
@@ -22,7 +24,7 @@ func TestParseRockspec(t *testing.T) {
|
||||
Type: pkg.LuaRocksPkg,
|
||||
Language: pkg.Lua,
|
||||
Licenses: pkg.NewLicenseSet(
|
||||
pkg.NewLicenseFromLocations("Apache-2.0", file.NewLocation("test-fixtures/rockspec/kong-3.7.0-0.rockspec")),
|
||||
pkg.NewLicenseFromLocationsWithContext(ctx, "Apache-2.0", file.NewLocation("test-fixtures/rockspec/kong-3.7.0-0.rockspec")),
|
||||
),
|
||||
Metadata: pkg.LuaRocksPackage{
|
||||
Name: "kong",
|
||||
@@ -43,7 +45,7 @@ func TestParseRockspec(t *testing.T) {
|
||||
Type: pkg.LuaRocksPkg,
|
||||
Language: pkg.Lua,
|
||||
Licenses: pkg.NewLicenseSet(
|
||||
pkg.NewLicenseFromLocations("MIT/X11", file.NewLocation("test-fixtures/rockspec/lpeg-1.0.2-1.rockspec")),
|
||||
pkg.NewLicenseFromLocationsWithContext(ctx, "MIT/X11", file.NewLocation("test-fixtures/rockspec/lpeg-1.0.2-1.rockspec")),
|
||||
),
|
||||
Metadata: pkg.LuaRocksPackage{
|
||||
Name: "LPeg",
|
||||
@@ -64,7 +66,7 @@ func TestParseRockspec(t *testing.T) {
|
||||
Type: pkg.LuaRocksPkg,
|
||||
Language: pkg.Lua,
|
||||
Licenses: pkg.NewLicenseSet(
|
||||
pkg.NewLicenseFromLocations("MIT", file.NewLocation("test-fixtures/rockspec/kong-pgmoon-1.16.2-1.rockspec")),
|
||||
pkg.NewLicenseFromLocationsWithContext(ctx, "MIT", file.NewLocation("test-fixtures/rockspec/kong-pgmoon-1.16.2-1.rockspec")),
|
||||
),
|
||||
Metadata: pkg.LuaRocksPackage{
|
||||
Name: "kong-pgmoon",
|
||||
@@ -85,7 +87,7 @@ func TestParseRockspec(t *testing.T) {
|
||||
Type: pkg.LuaRocksPkg,
|
||||
Language: pkg.Lua,
|
||||
Licenses: pkg.NewLicenseSet(
|
||||
pkg.NewLicenseFromLocations("MIT/X11", file.NewLocation("test-fixtures/rockspec/luasyslog-2.0.1-1.rockspec")),
|
||||
pkg.NewLicenseFromLocationsWithContext(ctx, "MIT/X11", file.NewLocation("test-fixtures/rockspec/luasyslog-2.0.1-1.rockspec")),
|
||||
),
|
||||
Metadata: pkg.LuaRocksPackage{
|
||||
Name: "luasyslog",
|
||||
|
||||
Reference in New Issue
Block a user