From 30b1cd1e25fef9a3b888e178d6675c89270037fe Mon Sep 17 00:00:00 2001 From: anthonyharrison Date: Mon, 9 Dec 2024 12:17:23 +0000 Subject: [PATCH] feat: example vulnerability summary --- examples/vuln_summary.py | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 examples/vuln_summary.py diff --git a/examples/vuln_summary.py b/examples/vuln_summary.py new file mode 100644 index 0000000..d89ad89 --- /dev/null +++ b/examples/vuln_summary.py @@ -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")