Skip to content

Commit

Permalink
add Version field in PacakgeNode (guacsec#164)
Browse files Browse the repository at this point in the history
* add Version field in PacakgeNode

Signed-off-by: Brandon Lum <[email protected]>

* add cdx root level version

Signed-off-by: Brandon Lum <[email protected]>

Signed-off-by: Brandon Lum <[email protected]>
  • Loading branch information
lumjjb authored Oct 18, 2022
1 parent 9decb01 commit b51f492
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 24 deletions.
53 changes: 30 additions & 23 deletions internal/testing/ingestor/testdata/testdata.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ var (
},
}

// SDPX Testdata
// SPDX Testdata

topLevelPack = assembler.PackageNode{
Name: "gcr.io/google-containers/alpine-latest",
Expand All @@ -208,9 +208,10 @@ var (
}

baselayoutPack = assembler.PackageNode{
Name: "alpine-baselayout",
Digest: nil,
Purl: "pkg:alpine/[email protected]?arch=x86_64&upstream=alpine-baselayout&distro=alpine-3.16.2",
Name: "alpine-baselayout",
Digest: nil,
Purl: "pkg:alpine/[email protected]?arch=x86_64&upstream=alpine-baselayout&distro=alpine-3.16.2",
Version: "3.2.0-r22",
CPEs: []string{
"cpe:2.3:a:alpine-baselayout:alpine-baselayout:3.2.0-r22:*:*:*:*:*:*:*",
"cpe:2.3:a:alpine-baselayout:alpine_baselayout:3.2.0-r22:*:*:*:*:*:*:*",
Expand All @@ -224,9 +225,10 @@ var (
}

keysPack = assembler.PackageNode{
Name: "alpine-keys",
Digest: nil,
Purl: "pkg:alpine/[email protected]?arch=x86_64&upstream=alpine-keys&distro=alpine-3.16.2",
Name: "alpine-keys",
Digest: nil,
Purl: "pkg:alpine/[email protected]?arch=x86_64&upstream=alpine-keys&distro=alpine-3.16.2",
Version: "2.4-r1",
CPEs: []string{
"cpe:2.3:a:alpine-keys:alpine-keys:2.4-r1:*:*:*:*:*:*:*",
"cpe:2.3:a:alpine-keys:alpine_keys:2.4-r1:*:*:*:*:*:*:*",
Expand All @@ -242,9 +244,10 @@ var (
}

baselayoutdataPack = assembler.PackageNode{
Name: "alpine-baselayout-data",
Digest: nil,
Purl: "pkg:alpine/[email protected]?arch=x86_64&upstream=alpine-baselayout&distro=alpine-3.16.2",
Name: "alpine-baselayout-data",
Digest: nil,
Purl: "pkg:alpine/[email protected]?arch=x86_64&upstream=alpine-baselayout&distro=alpine-3.16.2",
Version: "3.2.0-r22",
CPEs: []string{
"cpe:2.3:a:alpine-baselayout-data:alpine-baselayout-data:3.2.0-r22:*:*:*:*:*:*:*",
"cpe:2.3:a:alpine-baselayout-data:alpine_baselayout_data:3.2.0-r22:*:*:*:*:*:*:*",
Expand Down Expand Up @@ -353,10 +356,11 @@ var (
// CycloneDX Testdata

cdxTopLevelPack = assembler.PackageNode{
Name: "gcr.io/distroless/static:nonroot",
Digest: []string{"sha256:6ad5b696af3ca05a048bd29bf0f623040462638cb0b29c8d702cbb2805687388"},
Purl: "pkg:oci/static:nonroot?repository_url=gcr.io/distroless",
CPEs: nil,
Name: "gcr.io/distroless/static:nonroot",
Digest: []string{"sha256:6ad5b696af3ca05a048bd29bf0f623040462638cb0b29c8d702cbb2805687388"},
Version: "sha256:6ad5b696af3ca05a048bd29bf0f623040462638cb0b29c8d702cbb2805687388",
Purl: "pkg:oci/static:nonroot?repository_url=gcr.io/distroless",
CPEs: nil,
NodeData: *assembler.NewObjectMetadata(
processor.SourceInformation{
Collector: "TestCollector",
Expand All @@ -366,9 +370,10 @@ var (
}

cdxTzdataPack = assembler.PackageNode{
Name: "tzdata",
Digest: nil,
Purl: "pkg:deb/debian/tzdata@2021a-1+deb11u6?arch=all&distro=debian-11",
Name: "tzdata",
Digest: nil,
Version: "2021a-1+deb11u6",
Purl: "pkg:deb/debian/tzdata@2021a-1+deb11u6?arch=all&distro=debian-11",
CPEs: []string{
"cpe:2.3:a:tzdata:tzdata:2021a-1\\+deb11u6:*:*:*:*:*:*:*"},
NodeData: *assembler.NewObjectMetadata(
Expand All @@ -380,9 +385,10 @@ var (
}

cdxNetbasePack = assembler.PackageNode{
Name: "netbase",
Digest: nil,
Purl: "pkg:deb/debian/[email protected]?arch=all&distro=debian-11",
Name: "netbase",
Digest: nil,
Version: "6.3",
Purl: "pkg:deb/debian/[email protected]?arch=all&distro=debian-11",
CPEs: []string{
"cpe:2.3:a:netbase:netbase:6.3:*:*:*:*:*:*:*"},
NodeData: *assembler.NewObjectMetadata(
Expand All @@ -394,9 +400,10 @@ var (
}

cdxBasefilesPack = assembler.PackageNode{
Name: "base-files",
Digest: nil,
Purl: "pkg:deb/debian/[email protected]+deb11u5?arch=amd64&distro=debian-11",
Name: "base-files",
Digest: nil,
Version: "11.1+deb11u5",
Purl: "pkg:deb/debian/[email protected]+deb11u5?arch=amd64&distro=debian-11",
CPEs: []string{
"cpe:2.3:a:base-files:base-files:11.1\\+deb11u5:*:*:*:*:*:*:*"},
NodeData: *assembler.NewObjectMetadata(
Expand Down
4 changes: 3 additions & 1 deletion pkg/assembler/nodes.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ func (an ArtifactNode) IdentifiablePropertyNames() []string {
type PackageNode struct {
Name string
Digest []string
Version string
Purl string
CPEs []string
Tags []string
Expand All @@ -67,6 +68,7 @@ func (pn PackageNode) Properties() map[string]interface{} {
properties := make(map[string]interface{})
properties["name"] = pn.Name
properties["purl"] = pn.Purl
properties["version"] = pn.Version
properties["cpes"] = pn.CPEs
properties["digest"] = toLower(pn.Digest...)
properties["tags"] = pn.Tags
Expand All @@ -75,7 +77,7 @@ func (pn PackageNode) Properties() map[string]interface{} {
}

func (pn PackageNode) PropertyNames() []string {
fields := []string{"name", "digest", "purl", "cpes", "tags"}
fields := []string{"name", "digest", "purl", "cpes", "tags", "version"}
fields = append(fields, pn.NodeData.getProperties()...)
return fields
}
Expand Down
2 changes: 2 additions & 0 deletions pkg/ingestor/parser/cyclonedx/parser_cyclonedx.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ func (c *cyclonedxParser) addRootPackage(cdxBom *cdx.BOM) {
rootPackage := assembler.PackageNode{}
rootPackage.Purl = "pkg:oci/" + splitImage[2] + "?repository_url=" + splitImage[0] + "/" + splitImage[1]
rootPackage.Name = cdxBom.Metadata.Component.Name
rootPackage.Version = cdxBom.Metadata.Component.Version
rootPackage.Digest = append(rootPackage.Digest, cdxBom.Metadata.Component.Version)
rootPackage.NodeData = *assembler.NewObjectMetadata(c.doc.SourceInformation)
c.rootPackage = parentPackages{
Expand All @@ -114,6 +115,7 @@ func (c *cyclonedxParser) addPackages(cdxBom *cdx.BOM) {
Name: comp.Name,
// Digest: []string{comp.Version},
Purl: comp.PackageURL,
Version: comp.Version,
CPEs: []string{comp.CPE},
NodeData: *assembler.NewObjectMetadata(c.doc.SourceInformation),
}
Expand Down
1 change: 1 addition & 0 deletions pkg/ingestor/parser/spdx/parse_spdx.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ func (s *spdxParser) getPackages() {
currentPackage := assembler.PackageNode{}
currentPackage.Name = pac.PackageName
currentPackage.NodeData = *assembler.NewObjectMetadata(s.doc.SourceInformation)
currentPackage.Version = pac.PackageVersion
for _, ext := range pac.PackageExternalReferences {
if strings.HasPrefix(ext.RefType, "cpe") {
currentPackage.CPEs = append(currentPackage.CPEs, ext.Locator)
Expand Down

0 comments on commit b51f492

Please sign in to comment.