Skip to content

Commit

Permalink
feat: example vulnerability summary
Browse files Browse the repository at this point in the history
  • Loading branch information
anthonyharrison committed Dec 9, 2024
1 parent c411827 commit 30b1cd1
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions examples/vuln_summary.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Copyright (C) 2023 Anthony Harrison
# SPDX-License-Identifier: Apache-2.0

### Example to show use of lib4sbom to parse a SBOM and
### produce a summary of the vulnerabilities

import sys

from lib4sbom.data.document import SBOMDocument
from lib4sbom.parser import SBOMParser

test_parser = SBOMParser()
# Load SBOM
try:
test_parser.parse_file(sys.argv[1])

# What type of SBOM
document = SBOMDocument()
document.copy_document(test_parser.get_document())

vulnerabilities = test_parser.get_vulnerabilities()
print("Summary")
print("=" * len("summary"))
print(f"SBOM Type {document.get_type()}")
print(f"Version {document.get_version()}")
print(f"Name {document.get_name()}")
print(f"\nVulnerabilities {len(vulnerabilities)}")
if len(vulnerabilities) > 0:
print("-" * 70)
for vuln in vulnerabilities:
print(f"{vuln['id']} {vuln['source-name']}")

except FileNotFoundError:
print(f"{sys.argv[1]} not found")

0 comments on commit 30b1cd1

Please sign in to comment.