@@ -472,10 +472,32 @@ def get_vulnerabilities(self, vulnerability, parameters={}):
472
472
return response .json ()
473
473
474
474
def get_vulnerability_affected_projects (self , vulnerability ):
475
- url = self .config ['baseurl' ] + "/api/v1/composite/vulnerability" + "/{}" .format (vulnerability )
475
+ url = self ._get_vulnerabilities_url () + "/{}/affected-projects" .format (vulnerability )
476
+ custom_headers = {'Accept' : 'application/vnd.blackducksoftware.vulnerability-4+json' }
477
+ response = self .execute_get (url , custom_headers = custom_headers )
478
+ return response .json ()
479
+
480
+ # TODO: Refactor this, i.e. use get_link method?
481
+ def get_vulnerable_bom_components (self , version_obj , limit = 9999 ):
482
+ url = "{}/vulnerable-bom-components" .format (version_obj ['_meta' ]['href' ])
483
+ custom_headers = {'Accept' : 'application/vnd.blackducksoftware.bill-of-materials-6+json' }
484
+ param_string = self ._get_parameter_string ({'limit' : limit })
485
+ url = "{}{}" .format (url , param_string )
486
+ response = self .execute_get (url , custom_headers = custom_headers )
487
+ return response .json ()
488
+
489
+ # TODO: Remove or refactor this
490
+ def get_component_remediation (self , bom_component ):
491
+ url = "{}/remediating" .format (bom_component ['componentVersion' ])
492
+ logging .debug ("Url for getting remediation info is : {}" .format (url ))
476
493
response = self .execute_get (url )
477
494
return response .json ()
478
495
496
+ ##
497
+ #
498
+ # Lookup Black Duck (Hub) KB info given Protex KB info
499
+ #
500
+ ##
479
501
def find_component_info_for_protex_component (self , protex_component_id , protex_component_release_id ):
480
502
'''Will return the Hub component corresponding to the protex_component_id, and if a release (version) id
481
503
is given, the response will also include the component-version. Returns an empty list if there were
@@ -495,24 +517,6 @@ def find_component_info_for_protex_component(self, protex_component_id, protex_c
495
517
component_list_d = response .json ()
496
518
return response .json ()
497
519
498
- def get_vulnerable_bom_components (self , version_obj , limit = 9999 ):
499
- url = "{}/vulnerable-bom-components" .format (version_obj ['_meta' ]['href' ])
500
- custom_headers = {'Content-Type' : 'application/vnd.blackducksoftware.bill-of-materials-4+json' }
501
- param_string = self ._get_parameter_string ({'limit' : limit })
502
- url = "{}{}" .format (url , param_string )
503
- response = self .execute_get (url , custom_headers = custom_headers )
504
- if response .status_code == 200 :
505
- vulnerable_bom_components = response .json ()
506
- return vulnerable_bom_components
507
- else :
508
- logging .warning ("Failed to retrieve vulnerable bom components for project {}, status code {}" .format (
509
- version_obj , response .status_code ))
510
-
511
- def get_component_remediation (self , bom_component ):
512
- url = "{}/remediating" .format (bom_component ['componentVersion' ])
513
- logging .debug ("Url for getting remediation info is : {}" .format (url ))
514
- response = self .execute_get (url )
515
- return response .json ()
516
520
517
521
##
518
522
#
@@ -1146,6 +1150,25 @@ def get_project_roles(self):
1146
1150
all_project_roles = self .get_roles (parameters = {"filter" :"scope:project" })
1147
1151
return all_project_roles ['items' ]
1148
1152
1153
+ def get_version_scan_info (self , version_obj ):
1154
+ url = self .get_link (version_obj , "codelocations" )
1155
+ custom_headers = {'Accept' : 'application/vnd.blackducksoftware.project-detail-5+json' }
1156
+ response = self .execute_get (url , custom_headers = custom_headers )
1157
+ code_locations = response .json ().get ('items' , [])
1158
+ if code_locations :
1159
+ scan_info = {
1160
+ 'most_recent_scan' : max ([cl ['updatedAt' ] for cl in code_locations ]),
1161
+ 'oldest_scan' : min ([cl ['createdAt' ] for cl in code_locations ]),
1162
+ 'number_scans' : len (code_locations )
1163
+ }
1164
+ else :
1165
+ scan_info = {
1166
+ 'most_recent_scan' : None ,
1167
+ 'oldest_scan' : None ,
1168
+ 'number_scans' : None
1169
+ }
1170
+ return scan_info
1171
+
1149
1172
###
1150
1173
#
1151
1174
# Add project version as a component to another project
@@ -1237,18 +1260,7 @@ def get_codelocations(self, limit=100, unmapped=False, parameters={}):
1237
1260
url = self .get_apibase () + "/codelocations" + paramstring
1238
1261
headers ['Accept' ] = 'application/vnd.blackducksoftware.scan-4+json'
1239
1262
response = requests .get (url , headers = headers , verify = not self .config ['insecure' ])
1240
- if response .status_code == 200 :
1241
- jsondata = response .json ()
1242
- if unmapped :
1243
- jsondata ['items' ] = [s for s in jsondata ['items' ] if 'mappedProjectVersion' not in s ]
1244
- jsondata ['totalCount' ] = len (jsondata ['items' ])
1245
- return jsondata
1246
- elif response .status_code == 403 :
1247
- logging .warning ("Failed to retrieve code locations (aka scans) probably due to lack of permissions, status code {}" .format (
1248
- response .status_code ))
1249
- else :
1250
- logging .error ("Failed to retrieve code locations (aka scans), status code {}" .format (
1251
- response .status_code ))
1263
+ return response .json ()
1252
1264
1253
1265
def get_codelocation_scan_summaries (self , code_location_id = None , code_location_obj = None , limit = 100 ):
1254
1266
'''Retrieve the scans (aka scan summaries) for the given location. You can give either
@@ -1269,7 +1281,7 @@ def get_codelocation_scan_summaries(self, code_location_id = None, code_location
1269
1281
return jsondata
1270
1282
1271
1283
def delete_unmapped_codelocations (self , limit = 1000 ):
1272
- code_locations = self .get_codelocations (limit , True ).get ('items' , [])
1284
+ code_locations = self .get_codelocations (limit = limit , unmapped = True ).get ('items' , [])
1273
1285
1274
1286
for c in code_locations :
1275
1287
scan_summaries = self .get_codelocation_scan_summaries (code_location_obj = c ).get ('items' , [])
@@ -1509,6 +1521,18 @@ def get_health_checks(self):
1509
1521
url = self .get_urlbase () + "/api/health-checks/liveness"
1510
1522
return self .execute_get (url )
1511
1523
1524
+ ##
1525
+ #
1526
+ # Jobs
1527
+ #
1528
+ ##
1529
+ def get_jobs (self , parameters = {}):
1530
+ url = self .get_apibase () + "/jobs"
1531
+ url = url + self ._get_parameter_string (parameters )
1532
+ custom_headers = {'Accept' : 'application/vnd.blackducksoftware.status-4+json' }
1533
+ response = self .execute_get (url , custom_headers = custom_headers )
1534
+ return response .json ()
1535
+
1512
1536
##
1513
1537
#
1514
1538
# Job Statistics
0 commit comments