1
1
# -*- coding: utf-8 -*-
2
- # (C) Copyright IBM Corp. 2022 .
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.
34
34
# CONTEXT_BASED_RESTRICTIONS_TEST_SERVICE_NAME=<the name of the service to be associated with the test CBR rules>
35
35
# CONTEXT_BASED_RESTRICTIONS_TEST_VPC_CRN=<the CRN of the vpc instance to be associated with the test CBR rules>
36
36
#
37
+ #
37
38
# These configuration properties can be exported as environment variables, or stored
38
39
# in a configuration file and then:
39
40
# export IBM_CREDENTIALS_FILE=<name of configuration file>
52
53
rule_id = None
53
54
rule_rev = None
54
55
55
-
56
56
##############################################################################
57
57
# Start of Examples for Service: ContextBasedRestrictionsV1
58
58
##############################################################################
@@ -131,7 +131,7 @@ def test_create_zone_example(self):
131
131
'value' : '169.23.22.127' ,
132
132
}
133
133
134
- zone = context_based_restrictions_service .create_zone (
134
+ response = context_based_restrictions_service .create_zone (
135
135
name = 'an example of zone' ,
136
136
account_id = account_id ,
137
137
addresses = [
@@ -141,9 +141,10 @@ def test_create_zone_example(self):
141
141
vpc_address_model ,
142
142
service_ref_address_model ,
143
143
],
144
- excluded = [excluded_ip_address_model ],
145
144
description = 'this is an example of zone' ,
146
- ).get_result ()
145
+ excluded = [excluded_ip_address_model ],
146
+ )
147
+ zone = response .get_result ()
147
148
148
149
print (json .dumps (zone , indent = 2 ))
149
150
@@ -163,7 +164,10 @@ def test_list_zones_example(self):
163
164
print ('\n list_zones() result:' )
164
165
# begin-list_zones
165
166
166
- zone_list = context_based_restrictions_service .list_zones (account_id = account_id ).get_result ()
167
+ response = context_based_restrictions_service .list_zones (
168
+ account_id = account_id ,
169
+ )
170
+ zone_list = response .get_result ()
167
171
168
172
print (json .dumps (zone_list , indent = 2 ))
169
173
@@ -181,14 +185,16 @@ def test_get_zone_example(self):
181
185
print ('\n get_zone() result:' )
182
186
# begin-get_zone
183
187
184
- get_zone_response = context_based_restrictions_service .get_zone (zone_id = zone_id )
185
- zone = get_zone_response .get_result ()
188
+ response = context_based_restrictions_service .get_zone (
189
+ zone_id = zone_id ,
190
+ )
191
+ zone = response .get_result ()
186
192
187
193
print (json .dumps (zone , indent = 2 ))
188
194
189
195
# end-get_zone
190
196
global zone_rev
191
- zone_rev = get_zone_response .headers .get ("ETag" )
197
+ zone_rev = response .headers .get ("ETag" )
192
198
193
199
except ApiException as e :
194
200
pytest .fail (str (e ))
@@ -207,14 +213,15 @@ def test_replace_zone_example(self):
207
213
'value' : '169.23.56.234' ,
208
214
}
209
215
210
- zone = context_based_restrictions_service .replace_zone (
216
+ response = context_based_restrictions_service .replace_zone (
211
217
zone_id = zone_id ,
212
218
if_match = zone_rev ,
213
- name = 'an example of updated zone' ,
219
+ name = 'an example of zone' ,
214
220
account_id = account_id ,
215
221
addresses = [address_model ],
216
- description = 'this is an example of updated zone' ,
217
- ).get_result ()
222
+ description = 'this is an example of zone' ,
223
+ )
224
+ zone = response .get_result ()
218
225
219
226
print (json .dumps (zone , indent = 2 ))
220
227
@@ -232,9 +239,8 @@ def test_list_available_serviceref_targets_example(self):
232
239
print ('\n list_available_serviceref_targets() result:' )
233
240
# begin-list_available_serviceref_targets
234
241
235
- service_ref_target_list = (
236
- context_based_restrictions_service .list_available_serviceref_targets ().get_result ()
237
- )
242
+ response = context_based_restrictions_service .list_available_serviceref_targets ()
243
+ service_ref_target_list = response .get_result ()
238
244
239
245
print (json .dumps (service_ref_target_list , indent = 2 ))
240
246
@@ -261,7 +267,7 @@ def test_create_rule_example(self):
261
267
'attributes' : [rule_context_attribute_model ],
262
268
}
263
269
264
- resource_attribute_account_id_model = {
270
+ resource_attribute_model = {
265
271
'name' : 'accountId' ,
266
272
'value' : account_id ,
267
273
}
@@ -272,15 +278,16 @@ def test_create_rule_example(self):
272
278
}
273
279
274
280
resource_model = {
275
- 'attributes' : [resource_attribute_account_id_model , resource_attribute_service_name_model ],
281
+ 'attributes' : [resource_attribute_model , resource_attribute_service_name_model ],
276
282
}
277
283
278
- rule = context_based_restrictions_service .create_rule (
284
+ response = context_based_restrictions_service .create_rule (
279
285
contexts = [rule_context_model ],
280
286
resources = [resource_model ],
281
287
description = 'this is an example of rule' ,
282
288
enforcement_mode = 'enabled' ,
283
- ).get_result ()
289
+ )
290
+ rule = response .get_result ()
284
291
285
292
print (json .dumps (rule , indent = 2 ))
286
293
@@ -300,7 +307,10 @@ def test_list_rules_example(self):
300
307
print ('\n list_rules() result:' )
301
308
# begin-list_rules
302
309
303
- rule_list = context_based_restrictions_service .list_rules (account_id = account_id ).get_result ()
310
+ response = context_based_restrictions_service .list_rules (
311
+ account_id = account_id ,
312
+ )
313
+ rule_list = response .get_result ()
304
314
305
315
print (json .dumps (rule_list , indent = 2 ))
306
316
@@ -318,14 +328,16 @@ def test_get_rule_example(self):
318
328
print ('\n get_rule() result:' )
319
329
# begin-get_rule
320
330
321
- get_rule_response = context_based_restrictions_service .get_rule (rule_id = rule_id )
322
- rule = get_rule_response .get_result ()
331
+ response = context_based_restrictions_service .get_rule (
332
+ rule_id = rule_id ,
333
+ )
334
+ rule = response .get_result ()
323
335
324
336
print (json .dumps (rule , indent = 2 ))
325
337
326
338
# end-get_rule
327
339
global rule_rev
328
- rule_rev = get_rule_response .headers .get ("ETag" )
340
+ rule_rev = response .headers .get ("ETag" )
329
341
330
342
except ApiException as e :
331
343
pytest .fail (str (e ))
@@ -348,7 +360,7 @@ def test_replace_rule_example(self):
348
360
'attributes' : [rule_context_attribute_model ],
349
361
}
350
362
351
- resource_attribute_account_id_model = {
363
+ resource_attribute_model = {
352
364
'name' : 'accountId' ,
353
365
'value' : account_id ,
354
366
}
@@ -364,18 +376,19 @@ def test_replace_rule_example(self):
364
376
}
365
377
366
378
resource_model = {
367
- 'attributes' : [resource_attribute_account_id_model , resource_attribute_service_name_model ],
379
+ 'attributes' : [resource_attribute_model , resource_attribute_service_name_model ],
368
380
'tags' : [resource_tag_attribute_model ],
369
381
}
370
382
371
- rule = context_based_restrictions_service .replace_rule (
383
+ response = context_based_restrictions_service .replace_rule (
372
384
rule_id = rule_id ,
373
385
if_match = rule_rev ,
374
386
contexts = [rule_context_model ],
375
387
resources = [resource_model ],
376
388
description = 'this is an example of updated rule' ,
377
389
enforcement_mode = 'disabled' ,
378
- ).get_result ()
390
+ )
391
+ rule = response .get_result ()
379
392
380
393
print (json .dumps (rule , indent = 2 ))
381
394
@@ -393,9 +406,10 @@ def test_get_account_settings_example(self):
393
406
print ('\n get_account_settings() result:' )
394
407
# begin-get_account_settings
395
408
396
- account_settings = context_based_restrictions_service .get_account_settings (
397
- account_id = account_id
398
- ).get_result ()
409
+ response = context_based_restrictions_service .get_account_settings (
410
+ account_id = account_id ,
411
+ )
412
+ account_settings = response .get_result ()
399
413
400
414
print (json .dumps (account_settings , indent = 2 ))
401
415
@@ -432,7 +446,9 @@ def test_delete_rule_example(self):
432
446
try :
433
447
# begin-delete_rule
434
448
435
- response = context_based_restrictions_service .delete_rule (rule_id = rule_id )
449
+ response = context_based_restrictions_service .delete_rule (
450
+ rule_id = rule_id ,
451
+ )
436
452
437
453
# end-delete_rule
438
454
print ('\n delete_rule() response status code: ' , response .get_status_code ())
@@ -448,7 +464,9 @@ def test_delete_zone_example(self):
448
464
try :
449
465
# begin-delete_zone
450
466
451
- response = context_based_restrictions_service .delete_zone (zone_id = zone_id )
467
+ response = context_based_restrictions_service .delete_zone (
468
+ zone_id = zone_id ,
469
+ )
452
470
453
471
# end-delete_zone
454
472
print ('\n delete_zone() response status code: ' , response .get_status_code ())
0 commit comments