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 license extraction to APK extractor and proto. #19

Merged
merged 1 commit into from
Apr 17, 2024
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
1 change: 1 addition & 0 deletions binary/proto/proto.go
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,7 @@ func setProtoMetadata(meta any, i *spb.Inventory) {
OsVersionId: m.OSVersionID,
Maintainer: m.Maintainer,
Architecture: m.Architecture,
License: m.License,
},
}
case *dpkg.Metadata:
Expand Down
1 change: 1 addition & 0 deletions binary/proto/scan_result.proto
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ message APKPackageMetadata {
string os_version_id = 4;
string maintainer = 5;
string architecture = 6;
string license = 7;
}

// The additional data found in DPKG packages.
Expand Down
2 changes: 2 additions & 0 deletions extractor/os/apk/extractor.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ func (e Extractor) Extract(ctx context.Context, input *extractor.ScanInput) ([]*
originName := h.Get("o")
maintainer := h.Get("m")
arch := h.Get("A")
license := h.Get("L")
pkgs = append(pkgs, &extractor.Inventory{
Name: pkgName,
Version: version,
Expand All @@ -101,6 +102,7 @@ func (e Extractor) Extract(ctx context.Context, input *extractor.ScanInput) ([]*
OSVersionID: m["VERSION_ID"],
Maintainer: maintainer,
Architecture: arch,
License: license,
},
Locations: []string{input.Path},
Extractor: e.Name(),
Expand Down
41 changes: 21 additions & 20 deletions extractor/os/apk/extractor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,29 +90,29 @@ func TestExtract(t *testing.T) {
path: "testdata/installed",
osrelease: alpine,
wantInventory: []*extractor.Inventory{
getInventory("testdata/installed", e.Name(), "alpine-baselayout", "alpine-baselayout", "3.4.3-r1", "alpine", "3.18.0", "Natanael Copa <[email protected]>", "x86_64"),
getInventory("testdata/installed", e.Name(), "alpine-baselayout-data", "alpine-baselayout", "3.4.3-r1", "alpine", "3.18.0", "Natanael Copa <[email protected]>", "x86_64"),
getInventory("testdata/installed", e.Name(), "alpine-keys", "alpine-keys", "2.4-r1", "alpine", "3.18.0", "Natanael Copa <[email protected]>", "x86_64"),
getInventory("testdata/installed", e.Name(), "apk-tools", "apk-tools", "2.14.0-r0", "alpine", "3.18.0", "Natanael Copa <[email protected]>", "x86_64"),
getInventory("testdata/installed", e.Name(), "busybox", "busybox", "1.36.0-r9", "alpine", "3.18.0", "Sören Tempel <[email protected]>", "x86_64"),
getInventory("testdata/installed", e.Name(), "busybox-binsh", "busybox", "1.36.0-r9", "alpine", "3.18.0", "Sören Tempel <[email protected]>", "x86_64"),
getInventory("testdata/installed", e.Name(), "ca-certificates-bundle", "ca-certificates", "20230506-r0", "alpine", "3.18.0", "Natanael Copa <[email protected]>", "x86_64"),
getInventory("testdata/installed", e.Name(), "libc-utils", "libc-dev", "0.7.2-r5", "alpine", "3.18.0", "Natanael Copa <[email protected]>", "x86_64"),
getInventory("testdata/installed", e.Name(), "libcrypto3", "openssl", "3.1.0-r4", "alpine", "3.18.0", "Ariadne Conill <[email protected]>", "x86_64"),
getInventory("testdata/installed", e.Name(), "libssl3", "openssl", "3.1.0-r4", "alpine", "3.18.0", "Ariadne Conill <[email protected]>", "x86_64"),
getInventory("testdata/installed", e.Name(), "musl", "musl", "1.2.4-r0", "alpine", "3.18.0", "Timo Teräs <[email protected]>", "x86_64"),
getInventory("testdata/installed", e.Name(), "musl-utils", "musl", "1.2.4-r0", "alpine", "3.18.0", "Timo Teräs <[email protected]>", "x86_64"),
getInventory("testdata/installed", e.Name(), "scanelf", "pax-utils", "1.3.7-r1", "alpine", "3.18.0", "Natanael Copa <[email protected]>", "x86_64"),
getInventory("testdata/installed", e.Name(), "ssl_client", "busybox", "1.36.0-r9", "alpine", "3.18.0", "Sören Tempel <[email protected]>", "x86_64"),
getInventory("testdata/installed", e.Name(), "zlib", "zlib", "1.2.13-r1", "alpine", "3.18.0", "Natanael Copa <[email protected]>", "x86_64"),
getInventory("testdata/installed", e.Name(), "alpine-baselayout", "alpine-baselayout", "3.4.3-r1", "alpine", "3.18.0", "Natanael Copa <[email protected]>", "x86_64", "GPL-2.0-only"),
getInventory("testdata/installed", e.Name(), "alpine-baselayout-data", "alpine-baselayout", "3.4.3-r1", "alpine", "3.18.0", "Natanael Copa <[email protected]>", "x86_64", "GPL-2.0-only"),
getInventory("testdata/installed", e.Name(), "alpine-keys", "alpine-keys", "2.4-r1", "alpine", "3.18.0", "Natanael Copa <[email protected]>", "x86_64", "MIT"),
getInventory("testdata/installed", e.Name(), "apk-tools", "apk-tools", "2.14.0-r0", "alpine", "3.18.0", "Natanael Copa <[email protected]>", "x86_64", "GPL-2.0-only"),
getInventory("testdata/installed", e.Name(), "busybox", "busybox", "1.36.0-r9", "alpine", "3.18.0", "Sören Tempel <[email protected]>", "x86_64", "GPL-2.0-only"),
getInventory("testdata/installed", e.Name(), "busybox-binsh", "busybox", "1.36.0-r9", "alpine", "3.18.0", "Sören Tempel <[email protected]>", "x86_64", "GPL-2.0-only"),
getInventory("testdata/installed", e.Name(), "ca-certificates-bundle", "ca-certificates", "20230506-r0", "alpine", "3.18.0", "Natanael Copa <[email protected]>", "x86_64", "MPL-2.0 AND MIT"),
getInventory("testdata/installed", e.Name(), "libc-utils", "libc-dev", "0.7.2-r5", "alpine", "3.18.0", "Natanael Copa <[email protected]>", "x86_64", "BSD-2-Clause AND BSD-3-Clause"),
getInventory("testdata/installed", e.Name(), "libcrypto3", "openssl", "3.1.0-r4", "alpine", "3.18.0", "Ariadne Conill <[email protected]>", "x86_64", "Apache-2.0"),
getInventory("testdata/installed", e.Name(), "libssl3", "openssl", "3.1.0-r4", "alpine", "3.18.0", "Ariadne Conill <[email protected]>", "x86_64", "Apache-2.0"),
getInventory("testdata/installed", e.Name(), "musl", "musl", "1.2.4-r0", "alpine", "3.18.0", "Timo Teräs <[email protected]>", "x86_64", "MIT"),
getInventory("testdata/installed", e.Name(), "musl-utils", "musl", "1.2.4-r0", "alpine", "3.18.0", "Timo Teräs <[email protected]>", "x86_64", "MIT AND BSD-2-Clause AND GPL-2.0-or-later"),
getInventory("testdata/installed", e.Name(), "scanelf", "pax-utils", "1.3.7-r1", "alpine", "3.18.0", "Natanael Copa <[email protected]>", "x86_64", "GPL-2.0-only"),
getInventory("testdata/installed", e.Name(), "ssl_client", "busybox", "1.36.0-r9", "alpine", "3.18.0", "Sören Tempel <[email protected]>", "x86_64", "GPL-2.0-only"),
getInventory("testdata/installed", e.Name(), "zlib", "zlib", "1.2.13-r1", "alpine", "3.18.0", "Natanael Copa <[email protected]>", "x86_64", "Zlib"),
},
},
{
name: "origin not set",
path: "testdata/no-origin",
osrelease: alpine,
wantInventory: []*extractor.Inventory{
getInventory("testdata/no-origin", e.Name(), "pkgname", "", "1.2.3", "alpine", "3.18.0", "", "x86_64"),
getInventory("testdata/no-origin", e.Name(), "pkgname", "", "1.2.3", "alpine", "3.18.0", "", "x86_64", "GPL-2.0-only"),
},
},
{
Expand All @@ -131,23 +131,23 @@ func TestExtract(t *testing.T) {
osrelease: `ID=openwrt
VERSION_ID=1.2.3`,
wantInventory: []*extractor.Inventory{
getInventory("testdata/single", e.Name(), "alpine-baselayout-data", "alpine-baselayout", "3.4.3-r1", "openwrt", "1.2.3", "Natanael Copa <[email protected]>", "x86_64"),
getInventory("testdata/single", e.Name(), "alpine-baselayout-data", "alpine-baselayout", "3.4.3-r1", "openwrt", "1.2.3", "Natanael Copa <[email protected]>", "x86_64", "GPL-2.0-only"),
},
},
{
name: "osrelease no version",
path: "testdata/single",
osrelease: "ID=openwrt",
wantInventory: []*extractor.Inventory{
getInventory("testdata/single", e.Name(), "alpine-baselayout-data", "alpine-baselayout", "3.4.3-r1", "openwrt", "", "Natanael Copa <[email protected]>", "x86_64"),
getInventory("testdata/single", e.Name(), "alpine-baselayout-data", "alpine-baselayout", "3.4.3-r1", "openwrt", "", "Natanael Copa <[email protected]>", "x86_64", "GPL-2.0-only"),
},
},
{
name: "no osrelease",
path: "testdata/single",
osrelease: "",
wantInventory: []*extractor.Inventory{
getInventory("testdata/single", e.Name(), "alpine-baselayout-data", "alpine-baselayout", "3.4.3-r1", "", "", "Natanael Copa <[email protected]>", "x86_64"),
getInventory("testdata/single", e.Name(), "alpine-baselayout-data", "alpine-baselayout", "3.4.3-r1", "", "", "Natanael Copa <[email protected]>", "x86_64", "GPL-2.0-only"),
},
},
}
Expand Down Expand Up @@ -256,7 +256,7 @@ func TestToPURL(t *testing.T) {
}
}

func getInventory(path, ext, pkgName, origin, version, osID, osVersionID, maintainer, arch string) *extractor.Inventory {
func getInventory(path, ext, pkgName, origin, version, osID, osVersionID, maintainer, arch, license string) *extractor.Inventory {
return &extractor.Inventory{
Locations: []string{path},
Extractor: ext,
Expand All @@ -269,6 +269,7 @@ func getInventory(path, ext, pkgName, origin, version, osID, osVersionID, mainta
OSVersionID: osVersionID,
Maintainer: maintainer,
Architecture: arch,
License: license,
},
}
}
Expand Down
1 change: 1 addition & 0 deletions extractor/os/apk/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,5 @@ type Metadata struct {
OSVersionID string
Maintainer string
Architecture string
License string
}
Loading