1
1
# -*- coding: utf-8 -*-
2
- # (C) Copyright IBM Corp. 2021 .
2
+ # (C) Copyright IBM Corp. 2023 .
3
3
#
4
4
# Licensed under the Apache License, Version 2.0 (the "License");
5
5
# you may not use this file except in compliance with the License.
14
14
# limitations under the License.
15
15
16
16
"""
17
- Examples for VulnerabilityAdvisorV3
17
+ Examples for VulnerabilityAdvisorV4
18
18
"""
19
19
20
+ from ibm_cloud_sdk_core import ApiException , read_external_sources
20
21
import os
21
22
import pytest
22
- from ibm_cloud_sdk_core import ApiException , read_external_sources
23
- from ibm_container_registry .vulnerability_advisor_v3 import *
23
+ from ibm_container_registry .vulnerability_advisor_v4 import *
24
24
25
- account = 'accountID'
26
25
accept_language = 'en_US'
26
+ account = 'accountID'
27
27
28
28
#
29
29
# This file provides an example of how to use the Vulnerability Advisor service.
38
38
# in a configuration file and then:
39
39
# export IBM_CREDENTIALS_FILE=<name of configuration file>
40
40
#
41
- config_file = 'vulnerability_advisor_v3 .env'
41
+ config_file = 'vulnerability_advisor_v4 .env'
42
42
43
43
vulnerability_advisor_service = None
44
44
45
45
config = None
46
46
47
47
48
48
##############################################################################
49
- # Start of Examples for Service: VulnerabilityAdvisorV3
49
+ # Start of Examples for Service: VulnerabilityAdvisorV4
50
50
##############################################################################
51
51
# region
52
- class TestVulnerabilityAdvisorV3Examples () :
52
+ class TestVulnerabilityAdvisorV4Examples :
53
53
"""
54
- Example Test Class for VulnerabilityAdvisorV3
54
+ Example Test Class for VulnerabilityAdvisorV4
55
55
"""
56
56
57
57
@classmethod
@@ -62,16 +62,16 @@ def setup_class(cls):
62
62
63
63
# begin-common
64
64
65
- vulnerability_advisor_service = VulnerabilityAdvisorV3 .new_instance (
66
- account = account
65
+ vulnerability_advisor_service = VulnerabilityAdvisorV4 .new_instance (
66
+ account = account ,
67
67
)
68
68
69
69
# end-common
70
70
assert vulnerability_advisor_service is not None
71
71
72
72
# Load the configuration
73
73
global config
74
- config = read_external_sources (VulnerabilityAdvisorV3 .DEFAULT_SERVICE_NAME )
74
+ config = read_external_sources (VulnerabilityAdvisorV4 .DEFAULT_SERVICE_NAME )
75
75
76
76
print ('Setup complete.' )
77
77
@@ -85,9 +85,11 @@ def test_account_report_query_path_example(self):
85
85
account_report_query_path request example
86
86
"""
87
87
try :
88
+ print ('\n account_report_query_path() result:' )
88
89
# begin-accountReportQueryPath
89
90
90
- scan_report_list = vulnerability_advisor_service .account_report_query_path ().get_result ()
91
+ response = vulnerability_advisor_service .account_report_query_path ()
92
+ scan_report_list = response .get_result ()
91
93
92
94
print (json .dumps (scan_report_list , indent = 2 ))
93
95
@@ -102,9 +104,11 @@ def test_account_status_query_path_example(self):
102
104
account_status_query_path request example
103
105
"""
104
106
try :
107
+ print ('\n account_status_query_path() result:' )
105
108
# begin-accountStatusQueryPath
106
109
107
- scanreport_image_summary_list = vulnerability_advisor_service .account_status_query_path ().get_result ()
110
+ response = vulnerability_advisor_service .account_status_query_path ()
111
+ scanreport_image_summary_list = response .get_result ()
108
112
109
113
print (json .dumps (scanreport_image_summary_list , indent = 2 ))
110
114
@@ -119,11 +123,13 @@ def test_image_report_query_path_example(self):
119
123
image_report_query_path request example
120
124
"""
121
125
try :
126
+ print ('\n image_report_query_path() result:' )
122
127
# begin-imageReportQueryPath
123
128
124
- scan_report = vulnerability_advisor_service .image_report_query_path (
125
- name = 'image name'
126
- ).get_result ()
129
+ response = vulnerability_advisor_service .image_report_query_path (
130
+ name = 'image name' ,
131
+ )
132
+ scan_report = response .get_result ()
127
133
128
134
print (json .dumps (scan_report , indent = 2 ))
129
135
@@ -138,11 +144,13 @@ def test_image_status_query_path_example(self):
138
144
image_status_query_path request example
139
145
"""
140
146
try :
147
+ print ('\n image_status_query_path() result:' )
141
148
# begin-imageStatusQueryPath
142
149
143
- scanreport_summary = vulnerability_advisor_service .image_status_query_path (
144
- name = 'image name'
145
- ).get_result ()
150
+ response = vulnerability_advisor_service .image_status_query_path (
151
+ name = 'image name' ,
152
+ )
153
+ scanreport_summary = response .get_result ()
146
154
147
155
print (json .dumps (scanreport_summary , indent = 2 ))
148
156
@@ -157,9 +165,11 @@ def test_list_exemption_account_example(self):
157
165
list_exemption_account request example
158
166
"""
159
167
try :
168
+ print ('\n list_exemption_account() result:' )
160
169
# begin-listExemptionAccount
161
170
162
- list_exemption = vulnerability_advisor_service .list_exemption_account ().get_result ()
171
+ response = vulnerability_advisor_service .list_exemption_account ()
172
+ list_exemption = response .get_result ()
163
173
164
174
print (json .dumps (list_exemption , indent = 2 ))
165
175
@@ -174,12 +184,14 @@ def test_get_exemption_account_example(self):
174
184
get_exemption_account request example
175
185
"""
176
186
try :
187
+ print ('\n get_exemption_account() result:' )
177
188
# begin-getExemptionAccount
178
189
179
- exemption = vulnerability_advisor_service .get_exemption_account (
190
+ response = vulnerability_advisor_service .get_exemption_account (
180
191
issue_type = 'cve' ,
181
- issue_id = 'CVE-2020-0001'
182
- ).get_result ()
192
+ issue_id = 'CVE-2023-0001' ,
193
+ )
194
+ exemption = response .get_result ()
183
195
184
196
print (json .dumps (exemption , indent = 2 ))
185
197
@@ -194,12 +206,14 @@ def test_create_exemption_account_example(self):
194
206
create_exemption_account request example
195
207
"""
196
208
try :
209
+ print ('\n create_exemption_account() result:' )
197
210
# begin-createExemptionAccount
198
211
199
- exemption = vulnerability_advisor_service .create_exemption_account (
212
+ response = vulnerability_advisor_service .create_exemption_account (
200
213
issue_type = 'cve' ,
201
- issue_id = 'CVE-2020-0001'
202
- ).get_result ()
214
+ issue_id = 'CVE-2023-0001' ,
215
+ )
216
+ exemption = response .get_result ()
203
217
204
218
print (json .dumps (exemption , indent = 2 ))
205
219
@@ -214,11 +228,13 @@ def test_list_exemption_resource_example(self):
214
228
list_exemption_resource request example
215
229
"""
216
230
try :
231
+ print ('\n list_exemption_resource() result:' )
217
232
# begin-listExemptionResource
218
233
219
- list_exemption = vulnerability_advisor_service .list_exemption_resource (
220
- resource = 'image name'
221
- ).get_result ()
234
+ response = vulnerability_advisor_service .list_exemption_resource (
235
+ resource = 'image name' ,
236
+ )
237
+ list_exemption = response .get_result ()
222
238
223
239
print (json .dumps (list_exemption , indent = 2 ))
224
240
@@ -233,13 +249,15 @@ def test_get_exemption_resource_example(self):
233
249
get_exemption_resource request example
234
250
"""
235
251
try :
252
+ print ('\n get_exemption_resource() result:' )
236
253
# begin-getExemptionResource
237
254
238
- exemption = vulnerability_advisor_service .get_exemption_resource (
255
+ response = vulnerability_advisor_service .get_exemption_resource (
239
256
resource = 'image name' ,
240
257
issue_type = 'cve' ,
241
- issue_id = 'CVE-2020-0001'
242
- ).get_result ()
258
+ issue_id = 'CVE-2023-0001' ,
259
+ )
260
+ exemption = response .get_result ()
243
261
244
262
print (json .dumps (exemption , indent = 2 ))
245
263
@@ -254,13 +272,15 @@ def test_create_exemption_resource_example(self):
254
272
create_exemption_resource request example
255
273
"""
256
274
try :
275
+ print ('\n create_exemption_resource() result:' )
257
276
# begin-createExemptionResource
258
277
259
- exemption = vulnerability_advisor_service .create_exemption_resource (
278
+ response = vulnerability_advisor_service .create_exemption_resource (
260
279
resource = 'image name' ,
261
280
issue_type = 'cve' ,
262
- issue_id = 'CVE-2020-0001'
263
- ).get_result ()
281
+ issue_id = 'CVE-2023-0001' ,
282
+ )
283
+ exemption = response .get_result ()
264
284
265
285
print (json .dumps (exemption , indent = 2 ))
266
286
@@ -275,9 +295,11 @@ def test_exempt_handler_example(self):
275
295
exempt_handler request example
276
296
"""
277
297
try :
298
+ print ('\n exempt_handler() result:' )
278
299
# begin-exemptHandler
279
300
280
- list_exemption_type_info = vulnerability_advisor_service .exempt_handler ().get_result ()
301
+ response = vulnerability_advisor_service .exempt_handler ()
302
+ list_exemption_type_info = response .get_result ()
281
303
282
304
print (json .dumps (list_exemption_type_info , indent = 2 ))
283
305
@@ -292,9 +314,11 @@ def test_list_account_exemptions_example(self):
292
314
list_account_exemptions request example
293
315
"""
294
316
try :
317
+ print ('\n list_account_exemptions() result:' )
295
318
# begin-listAccountExemptions
296
319
297
- list_exemption = vulnerability_advisor_service .list_account_exemptions ().get_result ()
320
+ response = vulnerability_advisor_service .list_account_exemptions ()
321
+ list_exemption = response .get_result ()
298
322
299
323
print (json .dumps (list_exemption , indent = 2 ))
300
324
@@ -309,9 +333,11 @@ def test_exemptions_account_delete_handler_example(self):
309
333
exemptions_account_delete_handler request example
310
334
"""
311
335
try :
336
+ print ('\n exemptions_account_delete_handler() result:' )
312
337
# begin-exemptionsAccountDeleteHandler
313
338
314
- exemption_deletion_info = vulnerability_advisor_service .exemptions_account_delete_handler ().get_result ()
339
+ response = vulnerability_advisor_service .exemptions_account_delete_handler ()
340
+ exemption_deletion_info = response .get_result ()
315
341
316
342
print (json .dumps (exemption_deletion_info , indent = 2 ))
317
343
@@ -326,11 +352,13 @@ def test_list_image_exemptions_example(self):
326
352
list_image_exemptions request example
327
353
"""
328
354
try :
355
+ print ('\n list_image_exemptions() result:' )
329
356
# begin-listImageExemptions
330
357
331
- list_exemption = vulnerability_advisor_service .list_image_exemptions (
332
- resource = 'image name'
333
- ).get_result ()
358
+ response = vulnerability_advisor_service .list_image_exemptions (
359
+ resource = 'image name' ,
360
+ )
361
+ list_exemption = response .get_result ()
334
362
335
363
print (json .dumps (list_exemption , indent = 2 ))
336
364
@@ -345,11 +373,13 @@ def test_list_bulk_image_exemptions_example(self):
345
373
list_bulk_image_exemptions request example
346
374
"""
347
375
try :
376
+ print ('\n list_bulk_image_exemptions() result:' )
348
377
# begin-listBulkImageExemptions
349
378
350
- exemptions_map = vulnerability_advisor_service .list_bulk_image_exemptions (
351
- body = ['image name' ]
352
- ).get_result ()
379
+ response = vulnerability_advisor_service .list_bulk_image_exemptions (
380
+ body = ['us.icr.io/birds/woodpecker:green' , 'us.icr.io/birds/grebe:crested' ],
381
+ )
382
+ exemptions_map = response .get_result ()
353
383
354
384
print (json .dumps (exemptions_map , indent = 2 ))
355
385
@@ -369,12 +399,11 @@ def test_delete_exemption_resource_example(self):
369
399
response = vulnerability_advisor_service .delete_exemption_resource (
370
400
resource = 'image name' ,
371
401
issue_type = 'cve' ,
372
- issue_id = 'CVE-2020-0001'
373
- ).get_result ()
374
-
375
- print (json .dumps (response , indent = 2 ))
402
+ issue_id = 'CVE-2023-0001' ,
403
+ )
376
404
377
405
# end-deleteExemptionResource
406
+ print ('\n delete_exemption_resource() response status code: ' , response .get_status_code ())
378
407
379
408
except ApiException as e :
380
409
pytest .fail (str (e ))
@@ -389,17 +418,17 @@ def test_delete_exemption_account_example(self):
389
418
390
419
response = vulnerability_advisor_service .delete_exemption_account (
391
420
issue_type = 'cve' ,
392
- issue_id = 'CVE-2020-0001'
393
- ).get_result ()
394
-
395
- print (json .dumps (response , indent = 2 ))
421
+ issue_id = 'CVE-2023-0001' ,
422
+ )
396
423
397
424
# end-deleteExemptionAccount
425
+ print ('\n delete_exemption_account() response status code: ' , response .get_status_code ())
398
426
399
427
except ApiException as e :
400
428
pytest .fail (str (e ))
401
429
430
+
402
431
# endregion
403
432
##############################################################################
404
- # End of Examples for Service: VulnerabilityAdvisorV3
433
+ # End of Examples for Service: VulnerabilityAdvisorV4
405
434
##############################################################################
0 commit comments