Skip to content

Commit aa08801

Browse files
committed
0.5 prototype
1 parent a7ad4be commit aa08801

File tree

1 file changed

+8
-25
lines changed

1 file changed

+8
-25
lines changed

examples/client/file_hierarchy_report.py

Lines changed: 8 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,9 @@
3131
import logging
3232
import sys
3333
import io
34-
import os
35-
import re
3634
import time
37-
import subprocess
3835
import json
3936
import traceback
40-
import copy
41-
import ijson
4237
from blackduck import Client
4338
from zipfile import ZipFile
4439
from pprint import pprint
@@ -49,17 +44,6 @@
4944
5045
This script assumes a project version exists and has scans associated with it (i.e. the project is not scanned as part of this process).
5146
52-
Config file:
53-
API Token and Black Duck URL need to be placed in the .restconfig.json file which must be placed in the same folder where this script resides.
54-
{
55-
"baseurl": "https://hub-hostname",
56-
"api_token": "<API token goes here>",
57-
"insecure": true or false <Default is false>,
58-
"debug": true or false <Default is false>
59-
}
60-
61-
Remarks:
62-
This script uses 3rd party PyPI package "ijson". This package must be installed.
6347
'''
6448

6549
# BD report general
@@ -134,26 +118,24 @@ def create_version_details_report(bd, version):
134118
if (r.status_code == 403):
135119
logging.debug("Authorization Error - Please ensure the token you are using has write permissions!")
136120
r.raise_for_status()
137-
pprint(r.headers)
138121
location = r.headers.get('Location')
139122
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"
140123
return location
141124

142125
def download_report(bd, location, retries):
143126
report_id = location.split("/")[-1]
144-
print (location)
127+
logging.debug(f"Report location {location}")
145128
url_data = location.split('/')
146129
url_data.pop(4)
147130
url_data.pop(4)
148131
download_link = '/'.join(url_data)
149-
print(download_link)
132+
logging.debug(f"Report Download link {download_link}")
150133
if retries:
151-
logging.debug(f"Retrieving generated report from {location}")
134+
logging.debug(f"Retrieving generated report for {location} via {download_link}")
152135
response = bd.session.get(location)
153136
report_status = response.json().get('status', 'Not Ready')
154137
if response.status_code == 200 and report_status == 'COMPLETED':
155138
response = bd.session.get(download_link, headers={'Content-Type': 'application/zip', 'Accept':'application/zip'})
156-
pprint(response)
157139
if response.status_code == 200:
158140
return response.content
159141
else:
@@ -204,17 +186,18 @@ def main():
204186

205187
project = find_project_by_name(hub_client, args.project_name)
206188
version = find_project_version_by_name(hub_client, project, args.project_version_name)
207-
pprint(version)
208189
location = create_version_details_report(hub_client, version)
209-
pprint(location)
210190
report_zip = download_report(hub_client, location, args.report_retries)
211-
pprint(report_zip)
212191
logging.debug(f"Deleting report from Black Duck {hub_client.session.delete(location)}")
213192
zip=ZipFile(io.BytesIO(report_zip), "r")
214193
pprint(zip.namelist())
215194
report_data = {name: zip.read(name) for name in zip.namelist()}
216195
filename = [i for i in report_data.keys() if i.endswith(".json")][0]
217-
pprint(json.loads(report_data[filename]))
196+
version_report = json.loads(report_data[filename])
197+
# TODO items
198+
# Process file section of report data to identify primary paths
199+
# Combine component data with selected file data
200+
# Output result with CSV anf JSON as options.
218201

219202

220203
except (Exception, BaseException) as err:

0 commit comments

Comments
 (0)