Skip to content

Commit 29d5736

Browse files
author
Glenn Snyder
committed
adding option to choose SBOM report type
1 parent 8bcd57b commit 29d5736

File tree

1 file changed

+5
-8
lines changed

1 file changed

+5
-8
lines changed

examples/client/generate_sbom.py

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,8 @@ class FailedReportDownload(Exception):
4646
parser.add_argument("project_name")
4747
parser.add_argument("version_name")
4848
parser.add_argument("-z", "--zip_file_name", default="reports.zip")
49-
# parser.add_argument("-r", "--reports",
50-
# default=",".join(all_reports),
51-
# help=f"Comma separated list (no spaces) of the reports to generate - {list(version_name_map.keys())}. Default is all reports.")
52-
# parser.add_argument('--format', default='CSV', choices=["CSV"], help="Report format - only CSV available for now")
53-
parser.add_argument('-t', '--tries', default=4, type=int, help="How many times to retry downloading the report, i.e. wait for the report to be generated")
49+
parser.add_argument("-t", "--type", type=str, nargs='?', default="SPDX_22", choices=["SPDX_22", "CYCLONEDX_13"], help="Choose the type of SBOM report")
50+
parser.add_argument('-r', '--retries', default=4, type=int, help="How many times to retry downloading the report, i.e. wait for the report to be generated")
5451
parser.add_argument('-s', '--sleep_time', default=5, type=int, help="The amount of time to sleep in-between (re-)tries to download the report")
5552
parser.add_argument('--no-verify', dest='verify', action='store_false', help="disable TLS certificate verification")
5653

@@ -62,7 +59,7 @@ class FailedReportDownload(Exception):
6259
logging.getLogger("blackduck").setLevel(logging.WARNING)
6360

6461

65-
def download_report(bd_client, location, filename, retries=args.tries):
62+
def download_report(bd_client, location, filename, retries=args.retries):
6663
report_id = location.split("/")[-1]
6764
if retries:
6865
logging.debug(f"Retrieving generated report from {location}")
@@ -109,7 +106,7 @@ def download_report(bd_client, location, filename, retries=args.tries):
109106
post_data = {
110107
'reportFormat': "JSON",
111108
'reportType': 'SBOM',
112-
'sbomType': "SPDX_22"
109+
'sbomType': args.type,
113110
}
114111
sbom_reports_url = version['_meta']['href'] + "/sbom-reports"
115112

@@ -118,6 +115,6 @@ def download_report(bd_client, location, filename, retries=args.tries):
118115
location = r.headers.get('Location')
119116
assert location, "Hmm, this does not make sense. If we successfully created a report then there needs to be a location where we can get it from"
120117

121-
logging.debug(f"Created SBOM report for project {args.project_name}, version {args.version_name} at location {location}")
118+
logging.debug(f"Created SBOM report of type {args.type} for project {args.project_name}, version {args.version_name} at location {location}")
122119
download_report(bd, location, args.zip_file_name)
123120

0 commit comments

Comments
 (0)