1818"""
1919
2020import os
21+ import uuid
2122import pytest
2223from ibm_cloud_sdk_core import ApiException , read_external_sources
2324from ibm_platform_services .configuration_governance_v1 import *
4243enterprise_scope_id = None
4344subacct_scope_id = None
4445
46+ transaction_id = str (uuid .uuid4 ())
47+
48+
4549##############################################################################
4650# Start of Examples for Service: ConfigurationGovernanceV1
4751##############################################################################
@@ -67,7 +71,8 @@ def setup_class(cls):
6771
6872 # Load the configuration
6973 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 )
7176
7277 account_id = config ['ACCOUNT_ID' ]
7378 service_name = config ['EXAMPLE_SERVICE_NAME' ]
@@ -109,32 +114,34 @@ def test_create_rules_example(self):
109114 'account_id' : account_id ,
110115 'name' : 'Disable public access' ,
111116 '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' }]},
114119 'enforcement_actions' : [enforcement_action_model ],
115120 'labels' : [test_label ]
116121 }
117122
118123 create_rule_request_model = {
119124 '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' }]}
121126 }
122127
123128 detailed_response = configuration_governance_service .create_rules (
124- rules = [create_rule_request_model ]
129+ rules = [create_rule_request_model ],
130+ transaction_id = transaction_id
125131 )
126132 create_rules_response = detailed_response .get_result ()
127133 if detailed_response .status_code == 207 :
128134 for responseEntry in create_rules_response ['rules' ]:
129135 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' ])
131138
132139 print (json .dumps (create_rules_response , indent = 2 ))
133140
134141 # end-create_rules
135142
136143 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' ]
138145 except ApiException as e :
139146 pytest .fail (str (e ))
140147
@@ -154,21 +161,22 @@ def test_create_attachments_example(self):
154161
155162 attachment_request_model = {
156163 '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' },
158165 'excluded_scopes' : [excluded_scope_model ]
159166 }
160167
161168 create_attachments_response = configuration_governance_service .create_attachments (
162169 rule_id = rule_id_link ,
163- attachments = [attachment_request_model ]
170+ attachments = [attachment_request_model ],
171+ transaction_id = transaction_id
164172 ).get_result ()
165173
166174 print (json .dumps (create_attachments_response , indent = 2 ))
167175
168176 # end-create_attachments
169177
170178 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' ]
172180 except ApiException as e :
173181 pytest .fail (str (e ))
174182
@@ -182,7 +190,8 @@ def test_get_attachment_example(self):
182190
183191 attachment = configuration_governance_service .get_attachment (
184192 rule_id = rule_id_link ,
185- attachment_id = attachment_id_link
193+ attachment_id = attachment_id_link ,
194+ transaction_id = transaction_id
186195 ).get_result ()
187196
188197 print (json .dumps (attachment , indent = 2 ))
@@ -191,7 +200,10 @@ def test_get_attachment_example(self):
191200
192201 global attachment_etag_link
193202 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' )
195207 except ApiException as e :
196208 pytest .fail (str (e ))
197209
@@ -204,15 +216,19 @@ def test_get_rule_example(self):
204216 # begin-get_rule
205217
206218 rule = configuration_governance_service .get_rule (
207- rule_id = rule_id_link
219+ rule_id = rule_id_link ,
220+ transaction_id = transaction_id
208221 ).get_result ()
209222
210223 print (json .dumps (rule , indent = 2 ))
211224
212225 # end-get_rule
213226
214227 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' )
216232 except ApiException as e :
217233 pytest .fail (str (e ))
218234
@@ -225,7 +241,8 @@ def test_list_rules_example(self):
225241 # begin-list_rules
226242
227243 rule_list = configuration_governance_service .list_rules (
228- account_id = account_id
244+ account_id = account_id ,
245+ transaction_id = transaction_id
229246 ).get_result ()
230247
231248 print (json .dumps (rule_list , indent = 2 ))
@@ -265,11 +282,14 @@ def test_update_rule_example(self):
265282
266283 rule = configuration_governance_service .update_rule (
267284 rule_id = rule_id_link ,
285+ transaction_id = transaction_id ,
268286 if_match = rule_etag_link ,
269287 name = 'Disable public access' ,
270288 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' },
273293 enforcement_actions = [enforcement_action_model ],
274294 account_id = account_id ,
275295 rule_type = 'user_defined' ,
@@ -292,7 +312,8 @@ def test_list_attachments_example(self):
292312 # begin-list_attachments
293313
294314 attachment_list = configuration_governance_service .list_attachments (
295- rule_id = rule_id_link
315+ rule_id = rule_id_link ,
316+ transaction_id = transaction_id
296317 ).get_result ()
297318
298319 print (json .dumps (attachment_list , indent = 2 ))
@@ -319,9 +340,11 @@ def test_update_attachment_example(self):
319340 attachment = configuration_governance_service .update_attachment (
320341 rule_id = rule_id_link ,
321342 attachment_id = attachment_id_link ,
343+ transaction_id = transaction_id ,
322344 if_match = attachment_etag_link ,
323345 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' },
325348 excluded_scopes = [excluded_scope_model ]
326349 ).get_result ()
327350
@@ -342,7 +365,8 @@ def test_delete_attachment_example(self):
342365
343366 response = configuration_governance_service .delete_attachment (
344367 rule_id = rule_id_link ,
345- attachment_id = attachment_id_link
368+ attachment_id = attachment_id_link ,
369+ transaction_id = transaction_id
346370 ).get_result ()
347371
348372 print (json .dumps (response , indent = 2 ))
@@ -361,7 +385,8 @@ def test_delete_rule_example(self):
361385 # begin-delete_rule
362386
363387 response = configuration_governance_service .delete_rule (
364- rule_id = rule_id_link
388+ rule_id = rule_id_link ,
389+ transaction_id = transaction_id
365390 ).get_result ()
366391
367392 print (json .dumps (response , indent = 2 ))
@@ -378,8 +403,9 @@ def clean_rules(cls):
378403 """
379404 try :
380405 rule_list = configuration_governance_service .list_rules (
406+ transaction_id = transaction_id ,
381407 account_id = account_id ,
382- labels = test_label
408+ labels = test_label ,
383409 ).get_result ()
384410
385411 for rule in rule_list ['rules' ]:
0 commit comments