Skip to content

Commit 204c79d

Browse files
author
Jakob Maier
committed
refactor
1 parent 41aca6c commit 204c79d

File tree

2 files changed

+14
-13
lines changed

2 files changed

+14
-13
lines changed

examples/client/get_project_vulnerabilites_as_csv.py

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,20 @@
11
'''
22
Export the vulnerabilites from a project as CSV. Can be used to apply batch vulnerability
33
remediation with vuln_batch_remediation.py
4+
5+
Output is in format:
6+
identifier, status, comment, componentName, componentVersion, description
7+
8+
The API token should be specified in a .env file.
49
'''
5-
from blackduck import Client
6-
import logging
10+
import re
11+
import os
12+
import sys
713
import csv
14+
import logging
815
import argparse
916
from pprint import pprint
10-
import os
11-
import sys
17+
from blackduck import Client
1218
from dotenv import load_dotenv
1319

1420
load_dotenv()
@@ -47,27 +53,24 @@ def main():
4753
for project in bd.get_resource('projects'):
4854
if (project['name'] == projectname):
4955
for version in bd.get_resource('versions', project):
50-
5156
if (projectversion == None):
5257
pprint(version['versionName'])
5358

5459
else:
5560
if (version['versionName'] == projectversion):
5661
for vulnverable_component in bd.get_resource('vulnerable-components', version):
57-
# TODO maybe match component name with regex?
58-
if (vulnverable_component['componentName'] == component or component == None):
62+
componentName = vulnverable_component["componentName"]
5963

60-
componentName = vulnverable_component["componentName"]
64+
if (re.search(component, componentName, re.IGNORECASE) or component == None):
6165
componentVersion = vulnverable_component["componentVersionName"]
62-
6366
remediation = vulnverable_component['vulnerabilityWithRemediation']
6467

65-
name = remediation['vulnerabilityName']
6668
status = remediation['remediationStatus']
69+
identifier = remediation['vulnerabilityName']
6770
description = remediation['description'].replace('\r', '').replace('\n', '')
6871
comment = remediation.get('remediationComment', "").replace('\r', '').replace('\n', '')
6972

70-
row = [name, status, comment, componentName, componentVersion, description]
73+
row = [identifier, status, comment, componentName, componentVersion, description]
7174
csv_writer.writerow(row)
7275
break
7376
break

examples/vuln_batch_remediation.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,6 @@ def main(argv=None): # IGNORE:C0111
230230
custom_fields = hub.get_cf_values(project)
231231

232232
if (process_cve_remediation):
233-
234233
if (local_cve_remediation_file):
235234
cve_remediation_file = local_cve_remediation_file
236235
print (f' Opening: {cve_remediation_file}')
@@ -243,7 +242,6 @@ def main(argv=None): # IGNORE:C0111
243242
remediation_data = None
244243

245244
if (process_origin_exclulsion):
246-
247245
if local_origin_exclusion_file:
248246
exclusion_list_file = local_origin_exclusion_file
249247
print (f' Opening: {exclusion_list_file}')

0 commit comments

Comments
 (0)