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 spdx parser #108

Merged
merged 7 commits into from
Oct 7, 2022
Merged

add spdx parser #108

merged 7 commits into from
Oct 7, 2022

Conversation

pxp928
Copy link
Collaborator

@pxp928 pxp928 commented Sep 25, 2022

Signed-off-by: pxp928 parth.psu@gmail.com

SPDX Parser for #101

@pxp928 pxp928 changed the title add spdx unit tests add spdx parser with unit tests Sep 25, 2022
@pxp928 pxp928 changed the title add spdx parser with unit tests add spdx parser Sep 25, 2022
@pxp928 pxp928 force-pushed the spdx-parser branch 5 times, most recently from 1e30019 to 2eed0a7 Compare September 30, 2022 13:39
@pxp928 pxp928 marked this pull request as ready for review October 1, 2022 19:24
@pxp928
Copy link
Collaborator Author

pxp928 commented Oct 3, 2022

Ready for review!

Signed-off-by: pxp928 <parth.psu@gmail.com>
Signed-off-by: pxp928 <parth.psu@gmail.com>
Signed-off-by: pxp928 <parth.psu@gmail.com>
Signed-off-by: pxp928 <parth.psu@gmail.com>
Signed-off-by: pxp928 <parth.psu@gmail.com>
@pxp928 pxp928 force-pushed the spdx-parser branch 3 times, most recently from c5cab07 to 79f04e9 Compare October 6, 2022 21:15
Signed-off-by: pxp928 <parth.psu@gmail.com>
Copy link
Contributor

@lumjjb lumjjb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

functionality looks good, added a couple comments

pkg/ingestor/parser/parser_test.go Outdated Show resolved Hide resolved
pkg/ingestor/parser/parser_test.go Outdated Show resolved Hide resolved
pkg/ingestor/parser/spdx/parse_spdx.go Outdated Show resolved Hide resolved
pkg/ingestor/parser/spdx/parse_spdx.go Outdated Show resolved Hide resolved
}

func parseSpdxBlob(p []byte) (*v2_2.Document, error) {
reader := bytes.NewReader(p)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

defer reader.Close()

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no close defined for the reader.

pkg/ingestor/parser/spdx/parse_spdx_test.go Show resolved Hide resolved
pkg/ingestor/parser/spdx/parse_spdx.go Show resolved Hide resolved
pkg/ingestor/parser/spdx/parse_spdx.go Outdated Show resolved Hide resolved
internal/testing/ingestor/testdata/testdata.go Outdated Show resolved Hide resolved
j := 0
e := false
for j < n && !e {
if slice1[i].Type() == "DependsOn" && slice2[j].Type() == "DependsOn" {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think you can just do deep equal here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it kept randomly failing on the order of the elements in the slice. Even if they are equal.

Signed-off-by: pxp928 <parth.psu@gmail.com>
Copy link
Contributor

@lumjjb lumjjb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

minor nits, LGTM

pkg/ingestor/parser/common/types.go Show resolved Hide resolved
pkg/ingestor/parser/parser_test.go Show resolved Hide resolved
pkg/ingestor/parser/spdx/parse_spdx.go Show resolved Hide resolved
pkg/ingestor/parser/spdx/parse_spdx.go Show resolved Hide resolved
for _, packNode := range foundPackNodes {
createdEdge, err := getEdge(packNode, rel.Relationship, relatedPackNodes, relatedFileNodes)
if err != nil {
logger.Errorf("error generating spdx edge %v", err)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wonder if CreateEdge should return error... a discussion for a longer term, don't think we need to mind for now,

Copy link
Collaborator

@SantiagoTorres SantiagoTorres left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two minor and possibly non-issues.

topPackage.Purl = "pkg:oci/" + splitImage[2] + "?repository_url=" + splitImage[0] + "/" + splitImage[1]
topPackage.Name = s.spdxDoc.DocumentName
s.packages[string(s.spdxDoc.SPDXIdentifier)] = append(s.packages[string(s.spdxDoc.SPDXIdentifier)], topPackage)
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we err if len(splitImae) is not 3? when would this happen?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so this is a temporary fix until the upstream SPDX issue is resolved. This is a work around to create the node ourself based on the name of the image

Purl: "pkg:alpine/alpine-baselayout@3.2.0-r22?arch=x86_64&upstream=alpine-baselayout&distro=alpine-3.16.2",
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:*:*:*:*:*:*:*",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it matter this is the same CPE twice?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is what came out of the syft. Seems like a bug that needs to be fixed upstream?

@kodiakhq kodiakhq bot merged commit 3fa11be into guacsec:main Oct 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants