Skip to content

Commit 8b666db

Browse files
authored
feat(Context-Based Restrictions): add service group support to operations (#219)
Signed-off-by: Dylan <[email protected]>
1 parent c9050ad commit 8b666db

File tree

4 files changed

+943
-308
lines changed

4 files changed

+943
-308
lines changed

examples/test_context_based_restrictions_v1_examples.py

Lines changed: 51 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# -*- coding: utf-8 -*-
2-
# (C) Copyright IBM Corp. 2022.
2+
# (C) Copyright IBM Corp. 2023.
33
#
44
# Licensed under the Apache License, Version 2.0 (the "License");
55
# you may not use this file except in compliance with the License.
@@ -34,6 +34,7 @@
3434
# CONTEXT_BASED_RESTRICTIONS_TEST_SERVICE_NAME=<the name of the service to be associated with the test CBR rules>
3535
# CONTEXT_BASED_RESTRICTIONS_TEST_VPC_CRN=<the CRN of the vpc instance to be associated with the test CBR rules>
3636
#
37+
#
3738
# These configuration properties can be exported as environment variables, or stored
3839
# in a configuration file and then:
3940
# export IBM_CREDENTIALS_FILE=<name of configuration file>
@@ -52,7 +53,6 @@
5253
rule_id = None
5354
rule_rev = None
5455

55-
5656
##############################################################################
5757
# Start of Examples for Service: ContextBasedRestrictionsV1
5858
##############################################################################
@@ -131,7 +131,7 @@ def test_create_zone_example(self):
131131
'value': '169.23.22.127',
132132
}
133133

134-
zone = context_based_restrictions_service.create_zone(
134+
response = context_based_restrictions_service.create_zone(
135135
name='an example of zone',
136136
account_id=account_id,
137137
addresses=[
@@ -141,9 +141,10 @@ def test_create_zone_example(self):
141141
vpc_address_model,
142142
service_ref_address_model,
143143
],
144-
excluded=[excluded_ip_address_model],
145144
description='this is an example of zone',
146-
).get_result()
145+
excluded=[excluded_ip_address_model],
146+
)
147+
zone = response.get_result()
147148

148149
print(json.dumps(zone, indent=2))
149150

@@ -163,7 +164,10 @@ def test_list_zones_example(self):
163164
print('\nlist_zones() result:')
164165
# begin-list_zones
165166

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()
167171

168172
print(json.dumps(zone_list, indent=2))
169173

@@ -181,14 +185,16 @@ def test_get_zone_example(self):
181185
print('\nget_zone() result:')
182186
# begin-get_zone
183187

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()
186192

187193
print(json.dumps(zone, indent=2))
188194

189195
# end-get_zone
190196
global zone_rev
191-
zone_rev = get_zone_response.headers.get("ETag")
197+
zone_rev = response.headers.get("ETag")
192198

193199
except ApiException as e:
194200
pytest.fail(str(e))
@@ -207,14 +213,15 @@ def test_replace_zone_example(self):
207213
'value': '169.23.56.234',
208214
}
209215

210-
zone = context_based_restrictions_service.replace_zone(
216+
response = context_based_restrictions_service.replace_zone(
211217
zone_id=zone_id,
212218
if_match=zone_rev,
213-
name='an example of updated zone',
219+
name='an example of zone',
214220
account_id=account_id,
215221
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()
218225

219226
print(json.dumps(zone, indent=2))
220227

@@ -232,9 +239,8 @@ def test_list_available_serviceref_targets_example(self):
232239
print('\nlist_available_serviceref_targets() result:')
233240
# begin-list_available_serviceref_targets
234241

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()
238244

239245
print(json.dumps(service_ref_target_list, indent=2))
240246

@@ -261,7 +267,7 @@ def test_create_rule_example(self):
261267
'attributes': [rule_context_attribute_model],
262268
}
263269

264-
resource_attribute_account_id_model = {
270+
resource_attribute_model = {
265271
'name': 'accountId',
266272
'value': account_id,
267273
}
@@ -272,15 +278,16 @@ def test_create_rule_example(self):
272278
}
273279

274280
resource_model = {
275-
'attributes': [resource_attribute_account_id_model, resource_attribute_service_name_model],
281+
'attributes': [resource_attribute_model, resource_attribute_service_name_model],
276282
}
277283

278-
rule = context_based_restrictions_service.create_rule(
284+
response = context_based_restrictions_service.create_rule(
279285
contexts=[rule_context_model],
280286
resources=[resource_model],
281287
description='this is an example of rule',
282288
enforcement_mode='enabled',
283-
).get_result()
289+
)
290+
rule = response.get_result()
284291

285292
print(json.dumps(rule, indent=2))
286293

@@ -300,7 +307,10 @@ def test_list_rules_example(self):
300307
print('\nlist_rules() result:')
301308
# begin-list_rules
302309

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()
304314

305315
print(json.dumps(rule_list, indent=2))
306316

@@ -318,14 +328,16 @@ def test_get_rule_example(self):
318328
print('\nget_rule() result:')
319329
# begin-get_rule
320330

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()
323335

324336
print(json.dumps(rule, indent=2))
325337

326338
# end-get_rule
327339
global rule_rev
328-
rule_rev = get_rule_response.headers.get("ETag")
340+
rule_rev = response.headers.get("ETag")
329341

330342
except ApiException as e:
331343
pytest.fail(str(e))
@@ -348,7 +360,7 @@ def test_replace_rule_example(self):
348360
'attributes': [rule_context_attribute_model],
349361
}
350362

351-
resource_attribute_account_id_model = {
363+
resource_attribute_model = {
352364
'name': 'accountId',
353365
'value': account_id,
354366
}
@@ -364,18 +376,19 @@ def test_replace_rule_example(self):
364376
}
365377

366378
resource_model = {
367-
'attributes': [resource_attribute_account_id_model, resource_attribute_service_name_model],
379+
'attributes': [resource_attribute_model, resource_attribute_service_name_model],
368380
'tags': [resource_tag_attribute_model],
369381
}
370382

371-
rule = context_based_restrictions_service.replace_rule(
383+
response = context_based_restrictions_service.replace_rule(
372384
rule_id=rule_id,
373385
if_match=rule_rev,
374386
contexts=[rule_context_model],
375387
resources=[resource_model],
376388
description='this is an example of updated rule',
377389
enforcement_mode='disabled',
378-
).get_result()
390+
)
391+
rule = response.get_result()
379392

380393
print(json.dumps(rule, indent=2))
381394

@@ -393,9 +406,10 @@ def test_get_account_settings_example(self):
393406
print('\nget_account_settings() result:')
394407
# begin-get_account_settings
395408

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()
399413

400414
print(json.dumps(account_settings, indent=2))
401415

@@ -432,7 +446,9 @@ def test_delete_rule_example(self):
432446
try:
433447
# begin-delete_rule
434448

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+
)
436452

437453
# end-delete_rule
438454
print('\ndelete_rule() response status code: ', response.get_status_code())
@@ -448,7 +464,9 @@ def test_delete_zone_example(self):
448464
try:
449465
# begin-delete_zone
450466

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+
)
452470

453471
# end-delete_zone
454472
print('\ndelete_zone() response status code: ', response.get_status_code())

0 commit comments

Comments
 (0)