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

Update spdx_parser.py to handle spdx file parsing logic to generate correct key value pair of dictionary #5

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
15 changes: 15 additions & 0 deletions sbomdiff/spdx_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,31 @@ def parse_spdx_tag(self, sbom_file):
packages = {}
package = ""
version = None
githubStr = "pkg.go.dev/"
Copy link
Owner

Choose a reason for hiding this comment

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

This is not appropriate as this only works for Go packages. sbomdiff needs to be generic for all SBOMs and languages

Copy link
Author

Choose a reason for hiding this comment

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

Agree I will add some check to do this only for GO libs.

Copy link
Author

Choose a reason for hiding this comment

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

Could you suggest how to find packages for other language like java, python etc.

Copy link
Owner

Choose a reason for hiding this comment

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

Could you suggest how to find packages for other language like java, python etc.

I don't think this is a valid change,

The differences in package name is due to the differences in the SBOM generator. Comparing SBOMs from different generators is a valid use case and I can see how useful it is to detect that the generators are creating different names for the same package. Trying to make sbomdiff cater for different generators and establish that the different package names are actually the same package is beyond the scope of sbomdiff as it is not viable to accommodate the approaches adopted by all the different SBOM generators for generating package names.

for line in lines:
line_elements = line.split(":")
if line_elements[0] == "PackageName":
isProductNameWithOnlyVersionNumber = False
package = line_elements[1].strip().rstrip("\n")
productNameWithOnlyVersionNumber = re.compile(r'(/)')
if bool(productNameWithOnlyVersionNumber.search(package)) != True:
isProductNameWithOnlyVersionNumber = True
version = None
license = None
if line_elements[0] == "PackageVersion":
version = line[16:].strip().rstrip("\n")
if line_elements[0] == "PackageLicenseConcluded":
license = line_elements[1].strip().rstrip("\n")
if line_elements[0] == "PackageHomePage":
Copy link
Owner

Choose a reason for hiding this comment

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

If we add this check,we also need to do a corresponding check for all formats of SBOMs not just SPDX tag value SBOMs.

Copy link
Author

Choose a reason for hiding this comment

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

Yes I will add same check for json, xml, yaml and rdf.
Thanks @anthonyharrison

packageHomePage = line_elements[1].strip().rstrip("\n")
packageHomePageRemaining = ""
if len(line_elements) > 2 :
packageHomePageRemaining = line_elements[2].strip().rstrip("\n")
packageHomePage = packageHomePage + packageHomePageRemaining
if isProductNameWithOnlyVersionNumber:
tempArry = packageHomePage.split(githubStr)
if len(tempArry) == 2:
package = tempArry[1]
if package not in packages and version is not None and license is not None:
packages[package] = [version, license]

Expand Down