Skip to content

Commit d484605

Browse files
authored
Merge pull request blackducksoftware#12 from blackducksoftware/gsnyder/improving-affected-projects-retrieval
enhancing reverse lookup to produce a table of information
2 parents f007a0b + cc2e3c2 commit d484605

File tree

1 file changed

+29
-3
lines changed

1 file changed

+29
-3
lines changed

examples/print_vulnerability_affected_projects.py

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,13 @@
22
Created on Nov 11, 2018
33
44
@author: gsnyder
5+
6+
Given a CVE (or BDSA) identifier, find all affected project-versions and print out
7+
their names, version(s), development phase, distribution, and last BOM update date
58
'''
69
import argparse
10+
from beautifultable import BeautifulTable
11+
712
from blackduck.HubRestApi import HubInstance
813
from pprint import pprint
914

@@ -13,6 +18,27 @@
1318
parser.add_argument("vulnerability", help="A CVE or BDSA number, e.g. CVE-2016-4009")
1419
args = parser.parse_args()
1520

16-
affected_projects = hub.get_vulnerability_affected_projects(args.vulnerability)
17-
for project in affected_projects['items']:
18-
pprint(project)
21+
affected_projects = hub.get_vulnerability_affected_projects(args.vulnerability.upper())
22+
23+
if 'totalCount' in affected_projects and affected_projects['totalCount'] > 0:
24+
table = BeautifulTable()
25+
table.column_headers = ["project-name", "version", "phase", "distribution", "last-bom-update"]
26+
for affected_project in affected_projects['items']:
27+
project_id = affected_project['project']['id']
28+
version_id = affected_project['release']['id']
29+
30+
project_name = affected_project['project']['name']
31+
version = affected_project['release']['version']
32+
33+
# Development phase does not appear to be in the payload returned by the affected projects
34+
# endpoint so we need to fetch it from the project-version endpoint
35+
project_version_info = hub.get_version_by_id(project_id, version_id)
36+
37+
phase = project_version_info['phase']
38+
distribution = project_version_info['distribution']
39+
last_bom_update = project_version_info['lastBomUpdateDate']
40+
41+
table.append_row([project_name, version, phase, distribution, last_bom_update])
42+
print(table)
43+
else:
44+
print("No affected projects found for this vulnerability {}".format(args.vulnerability.upper()))

0 commit comments

Comments
 (0)