-
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c411827
commit 30b1cd1
Showing
1 changed file
with
34 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") |