18
18
"""
19
19
20
20
import os
21
+ import uuid
21
22
import pytest
22
23
from ibm_cloud_sdk_core import ApiException , read_external_sources
23
24
from ibm_platform_services .configuration_governance_v1 import *
42
43
enterprise_scope_id = None
43
44
subacct_scope_id = None
44
45
46
+ transaction_id = str (uuid .uuid4 ())
47
+
48
+
45
49
##############################################################################
46
50
# Start of Examples for Service: ConfigurationGovernanceV1
47
51
##############################################################################
@@ -67,7 +71,8 @@ def setup_class(cls):
67
71
68
72
# Load the configuration
69
73
global config , account_id , service_name , enterprise_scope_id , subacct_scope_id
70
- config = read_external_sources (ConfigurationGovernanceV1 .DEFAULT_SERVICE_NAME )
74
+ config = read_external_sources (
75
+ ConfigurationGovernanceV1 .DEFAULT_SERVICE_NAME )
71
76
72
77
account_id = config ['ACCOUNT_ID' ]
73
78
service_name = config ['EXAMPLE_SERVICE_NAME' ]
@@ -109,32 +114,34 @@ def test_create_rules_example(self):
109
114
'account_id' : account_id ,
110
115
'name' : 'Disable public access' ,
111
116
'description' : 'Ensure that public access to account resources is disabled.' ,
112
- 'target' : {'service_name' :service_name ,'resource_kind' :'service' },
113
- 'required_config' : {'description' :'Public access check' ,'and' :[{'property' :'public_access_enabled' ,'operator' :'is_false' }]},
117
+ 'target' : {'service_name' : service_name , 'resource_kind' : 'service' },
118
+ 'required_config' : {'description' : 'Public access check' , 'and' : [{'property' : 'public_access_enabled' , 'operator' : 'is_false' }]},
114
119
'enforcement_actions' : [enforcement_action_model ],
115
120
'labels' : [test_label ]
116
121
}
117
122
118
123
create_rule_request_model = {
119
124
'request_id' : '3cebc877-58e7-44a5-a292-32114fa73558' ,
120
- 'rule' : {'account_id' :account_id ,'name' :'Disable public access' ,'description' :'Ensure that public access to account resources is disabled.' ,'labels' :[test_label ],'target' :{'service_name' :service_name ,'resource_kind' :'service' },'required_config' :{'description' :'Public access check' ,'and' :[{'property' :'public_access_enabled' ,'operator' :'is_false' }]},'enforcement_actions' :[{'action' :'disallow' },{'action' :'audit_log' }]}
125
+ 'rule' : {'account_id' : account_id , 'name' : 'Disable public access' , 'description' : 'Ensure that public access to account resources is disabled.' , 'labels' : [test_label ], 'target' : {'service_name' : service_name , 'resource_kind' : 'service' }, 'required_config' : {'description' : 'Public access check' , 'and' : [{'property' : 'public_access_enabled' , 'operator' : 'is_false' }]}, 'enforcement_actions' : [{'action' : 'disallow' }, {'action' : 'audit_log' }]}
121
126
}
122
127
123
128
detailed_response = configuration_governance_service .create_rules (
124
- rules = [create_rule_request_model ]
129
+ rules = [create_rule_request_model ],
130
+ transaction_id = transaction_id
125
131
)
126
132
create_rules_response = detailed_response .get_result ()
127
133
if detailed_response .status_code == 207 :
128
134
for responseEntry in create_rules_response ['rules' ]:
129
135
if responseEntry ['status_code' ] > 299 :
130
- raise ApiException (code = responseEntry ['errors' ][0 ]['code' ], message = responseEntry ['errors' ][0 ]['message' ])
136
+ raise ApiException (
137
+ code = responseEntry ['errors' ][0 ]['code' ], message = responseEntry ['errors' ][0 ]['message' ])
131
138
132
139
print (json .dumps (create_rules_response , indent = 2 ))
133
140
134
141
# end-create_rules
135
142
136
143
global rule_id_link
137
- rule_id_link = create_rules_response ['rules' ][0 ]['rule' ]['rule_id' ];
144
+ rule_id_link = create_rules_response ['rules' ][0 ]['rule' ]['rule_id' ]
138
145
except ApiException as e :
139
146
pytest .fail (str (e ))
140
147
@@ -154,21 +161,22 @@ def test_create_attachments_example(self):
154
161
155
162
attachment_request_model = {
156
163
'account_id' : account_id ,
157
- 'included_scope' : {'note' :'My enterprise' ,'scope_id' :enterprise_scope_id ,'scope_type' :'enterprise' },
164
+ 'included_scope' : {'note' : 'My enterprise' , 'scope_id' : enterprise_scope_id , 'scope_type' : 'enterprise' },
158
165
'excluded_scopes' : [excluded_scope_model ]
159
166
}
160
167
161
168
create_attachments_response = configuration_governance_service .create_attachments (
162
169
rule_id = rule_id_link ,
163
- attachments = [attachment_request_model ]
170
+ attachments = [attachment_request_model ],
171
+ transaction_id = transaction_id
164
172
).get_result ()
165
173
166
174
print (json .dumps (create_attachments_response , indent = 2 ))
167
175
168
176
# end-create_attachments
169
177
170
178
global attachment_id_link
171
- attachment_id_link = create_attachments_response ['attachments' ][0 ]['attachment_id' ];
179
+ attachment_id_link = create_attachments_response ['attachments' ][0 ]['attachment_id' ]
172
180
except ApiException as e :
173
181
pytest .fail (str (e ))
174
182
@@ -182,7 +190,8 @@ def test_get_attachment_example(self):
182
190
183
191
attachment = configuration_governance_service .get_attachment (
184
192
rule_id = rule_id_link ,
185
- attachment_id = attachment_id_link
193
+ attachment_id = attachment_id_link ,
194
+ transaction_id = transaction_id
186
195
).get_result ()
187
196
188
197
print (json .dumps (attachment , indent = 2 ))
@@ -191,7 +200,10 @@ def test_get_attachment_example(self):
191
200
192
201
global attachment_etag_link
193
202
attachment_etag_link = configuration_governance_service .get_attachment (
194
- rule_id = rule_id_link , attachment_id = attachment_id_link ).get_headers ().get ('Etag' )
203
+ rule_id = rule_id_link ,
204
+ attachment_id = attachment_id_link ,
205
+ transaction_id = transaction_id
206
+ ).get_headers ().get ('Etag' )
195
207
except ApiException as e :
196
208
pytest .fail (str (e ))
197
209
@@ -204,15 +216,19 @@ def test_get_rule_example(self):
204
216
# begin-get_rule
205
217
206
218
rule = configuration_governance_service .get_rule (
207
- rule_id = rule_id_link
219
+ rule_id = rule_id_link ,
220
+ transaction_id = transaction_id
208
221
).get_result ()
209
222
210
223
print (json .dumps (rule , indent = 2 ))
211
224
212
225
# end-get_rule
213
226
214
227
global rule_etag_link
215
- rule_etag_link = configuration_governance_service .get_rule (rule_id = rule_id_link ).get_headers ().get ('etag' )
228
+ rule_etag_link = configuration_governance_service .get_rule (
229
+ rule_id = rule_id_link ,
230
+ transaction_id = transaction_id
231
+ ).get_headers ().get ('etag' )
216
232
except ApiException as e :
217
233
pytest .fail (str (e ))
218
234
@@ -225,7 +241,8 @@ def test_list_rules_example(self):
225
241
# begin-list_rules
226
242
227
243
rule_list = configuration_governance_service .list_rules (
228
- account_id = account_id
244
+ account_id = account_id ,
245
+ transaction_id = transaction_id
229
246
).get_result ()
230
247
231
248
print (json .dumps (rule_list , indent = 2 ))
@@ -265,11 +282,14 @@ def test_update_rule_example(self):
265
282
266
283
rule = configuration_governance_service .update_rule (
267
284
rule_id = rule_id_link ,
285
+ transaction_id = transaction_id ,
268
286
if_match = rule_etag_link ,
269
287
name = 'Disable public access' ,
270
288
description = 'Ensure that public access to account resources is disabled.' ,
271
- target = {'service_name' :service_name ,'resource_kind' :'service' ,'additional_target_attributes' :[]},
272
- required_config = {'property' :'public_access_enabled' ,'operator' :'is_false' },
289
+ target = {'service_name' : service_name , 'resource_kind' : 'service' ,
290
+ 'additional_target_attributes' : []},
291
+ required_config = {
292
+ 'property' : 'public_access_enabled' , 'operator' : 'is_false' },
273
293
enforcement_actions = [enforcement_action_model ],
274
294
account_id = account_id ,
275
295
rule_type = 'user_defined' ,
@@ -292,7 +312,8 @@ def test_list_attachments_example(self):
292
312
# begin-list_attachments
293
313
294
314
attachment_list = configuration_governance_service .list_attachments (
295
- rule_id = rule_id_link
315
+ rule_id = rule_id_link ,
316
+ transaction_id = transaction_id
296
317
).get_result ()
297
318
298
319
print (json .dumps (attachment_list , indent = 2 ))
@@ -319,9 +340,11 @@ def test_update_attachment_example(self):
319
340
attachment = configuration_governance_service .update_attachment (
320
341
rule_id = rule_id_link ,
321
342
attachment_id = attachment_id_link ,
343
+ transaction_id = transaction_id ,
322
344
if_match = attachment_etag_link ,
323
345
account_id = account_id ,
324
- included_scope = {'note' :'My enterprise' ,'scope_id' :enterprise_scope_id ,'scope_type' :'enterprise' },
346
+ included_scope = {'note' : 'My enterprise' ,
347
+ 'scope_id' : enterprise_scope_id , 'scope_type' : 'enterprise' },
325
348
excluded_scopes = [excluded_scope_model ]
326
349
).get_result ()
327
350
@@ -342,7 +365,8 @@ def test_delete_attachment_example(self):
342
365
343
366
response = configuration_governance_service .delete_attachment (
344
367
rule_id = rule_id_link ,
345
- attachment_id = attachment_id_link
368
+ attachment_id = attachment_id_link ,
369
+ transaction_id = transaction_id
346
370
).get_result ()
347
371
348
372
print (json .dumps (response , indent = 2 ))
@@ -361,7 +385,8 @@ def test_delete_rule_example(self):
361
385
# begin-delete_rule
362
386
363
387
response = configuration_governance_service .delete_rule (
364
- rule_id = rule_id_link
388
+ rule_id = rule_id_link ,
389
+ transaction_id = transaction_id
365
390
).get_result ()
366
391
367
392
print (json .dumps (response , indent = 2 ))
@@ -378,8 +403,9 @@ def clean_rules(cls):
378
403
"""
379
404
try :
380
405
rule_list = configuration_governance_service .list_rules (
406
+ transaction_id = transaction_id ,
381
407
account_id = account_id ,
382
- labels = test_label
408
+ labels = test_label ,
383
409
).get_result ()
384
410
385
411
for rule in rule_list ['rules' ]:
0 commit comments