|
1 | 1 | '''
|
2 | 2 | Export the vulnerabilites from a project as CSV. Can be used to apply batch vulnerability
|
3 | 3 | 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. |
4 | 9 | '''
|
5 |
| -from blackduck import Client |
6 |
| -import logging |
| 10 | +import re |
| 11 | +import os |
| 12 | +import sys |
7 | 13 | import csv
|
| 14 | +import logging |
8 | 15 | import argparse
|
9 | 16 | from pprint import pprint
|
10 |
| -import os |
11 |
| -import sys |
| 17 | +from blackduck import Client |
12 | 18 | from dotenv import load_dotenv
|
13 | 19 |
|
14 | 20 | load_dotenv()
|
@@ -47,27 +53,24 @@ def main():
|
47 | 53 | for project in bd.get_resource('projects'):
|
48 | 54 | if (project['name'] == projectname):
|
49 | 55 | for version in bd.get_resource('versions', project):
|
50 |
| - |
51 | 56 | if (projectversion == None):
|
52 | 57 | pprint(version['versionName'])
|
53 | 58 |
|
54 | 59 | else:
|
55 | 60 | if (version['versionName'] == projectversion):
|
56 | 61 | 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"] |
59 | 63 |
|
60 |
| - componentName = vulnverable_component["componentName"] |
| 64 | + if (re.search(component, componentName, re.IGNORECASE) or component == None): |
61 | 65 | componentVersion = vulnverable_component["componentVersionName"]
|
62 |
| - |
63 | 66 | remediation = vulnverable_component['vulnerabilityWithRemediation']
|
64 | 67 |
|
65 |
| - name = remediation['vulnerabilityName'] |
66 | 68 | status = remediation['remediationStatus']
|
| 69 | + identifier = remediation['vulnerabilityName'] |
67 | 70 | description = remediation['description'].replace('\r', '').replace('\n', '')
|
68 | 71 | comment = remediation.get('remediationComment', "").replace('\r', '').replace('\n', '')
|
69 | 72 |
|
70 |
| - row = [name, status, comment, componentName, componentVersion, description] |
| 73 | + row = [identifier, status, comment, componentName, componentVersion, description] |
71 | 74 | csv_writer.writerow(row)
|
72 | 75 | break
|
73 | 76 | break
|
|
0 commit comments