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

feat: Support displaying multiple PURL and CPE values (fixes #4) #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
32 changes: 24 additions & 8 deletions sbom2doc/generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,26 +145,42 @@ def generate_document(format, sbom_parser, filename, outfile, include_license):

# Show Purl and CPE information
sbom_document.paragraph("")
sbom_document.createtable(
["Name", "PURL", "CPE"], [12, 12, 15]
)
sbom_document.createtable(["Name", "PURL"], [12, 12])
for package in packages:
name = package.get("name", None)
purl = cpe = ""
purl = ""
external_info = package.get("externalreference", None)
at_least_one_found = False
if external_info is not None:
for reference in external_info:
if reference[1] == "purl":
try:
purl = reference[2]
at_least_one_found = True
sbom_document.addrow([name, purl])
except ValueError:
purl = ""
elif reference[1] in ["cpe22Type", "cpe23Type"]:
cpe = reference[2]
if not at_least_one_found:
sbom_document.addrow([name, purl])
sbom_document.showtable(widths=[5, 2])

sbom_document.addrow([name, purl, cpe])
sbom_document.showtable(widths=[5, 2, 2, 2, 2])
sbom_document.paragraph("")
sbom_document.createtable(["Name", "CPE"], [12, 12])
for package in packages:
name = package.get("name", None)
cpe = ""
external_info = package.get("externalreference", None)
at_least_one_found = False
if external_info is not None:
for reference in external_info:
if reference[1] in ["cpe22Type", "cpe23Type"]:
cpe = reference[2]
at_least_one_found = True
sbom_document.addrow([name, cpe])

if not at_least_one_found:
sbom_document.addrow([name, cpe])
sbom_document.showtable(widths=[5, 2])

sbom_document.heading(1, "Component Type Summary")
sbom_document.createtable(["Type", "Count"], [25, 6])
Expand Down