12
12
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
13
# See the License for the specific language governing permissions and
14
14
# limitations under the License.
15
-
16
15
"""
17
16
Examples for ConfigurationGovernanceV1
18
17
"""
43
42
enterprise_scope_id = None
44
43
subacct_scope_id = None
45
44
46
- transaction_id = str (uuid .uuid4 ())
47
-
48
45
49
46
##############################################################################
50
47
# Start of Examples for Service: ConfigurationGovernanceV1
@@ -54,7 +51,6 @@ class TestConfigurationGovernanceV1Examples():
54
51
"""
55
52
Example Test Class for ConfigurationGovernanceV1
56
53
"""
57
-
58
54
@classmethod
59
55
def setup_class (cls ):
60
56
global configuration_governance_service
@@ -84,8 +80,8 @@ def setup_class(cls):
84
80
print ('Setup complete.' )
85
81
86
82
needscredentials = pytest .mark .skipif (
87
- not os .path .exists (config_file ), reason = "External configuration not available, skipping..."
88
- )
83
+ not os .path .exists (config_file ),
84
+ reason = "External configuration not available, skipping..." )
89
85
90
86
@needscredentials
91
87
def test_create_rules_example (self ):
@@ -106,35 +102,68 @@ def test_create_rules_example(self):
106
102
'operator' : 'is_true'
107
103
}
108
104
109
- enforcement_action_model = {
110
- 'action' : 'disallow'
111
- }
105
+ enforcement_action_model = {'action' : 'disallow' }
112
106
113
107
rule_request_model = {
114
108
'account_id' : account_id ,
115
109
'name' : 'Disable public access' ,
116
- 'description' : 'Ensure that public access to account resources is disabled.' ,
117
- 'target' : {'service_name' : service_name , 'resource_kind' : 'service' },
118
- 'required_config' : {'description' : 'Public access check' , 'and' : [{'property' : 'public_access_enabled' , 'operator' : 'is_false' }]},
110
+ 'description' :
111
+ 'Ensure that public access to account resources is disabled.' ,
112
+ 'target' : {
113
+ 'service_name' : service_name ,
114
+ 'resource_kind' : 'service'
115
+ },
116
+ 'required_config' : {
117
+ 'description' :
118
+ 'Public access check' ,
119
+ 'and' : [{
120
+ 'property' : 'public_access_enabled' ,
121
+ 'operator' : 'is_false'
122
+ }]
123
+ },
119
124
'enforcement_actions' : [enforcement_action_model ],
120
125
'labels' : [test_label ]
121
126
}
122
127
123
128
create_rule_request_model = {
124
129
'request_id' : '3cebc877-58e7-44a5-a292-32114fa73558' ,
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' }]}
130
+ 'rule' : {
131
+ 'account_id' :
132
+ account_id ,
133
+ 'name' :
134
+ 'Disable public access' ,
135
+ 'description' :
136
+ 'Ensure that public access to account resources is disabled.' ,
137
+ 'labels' : [test_label ],
138
+ 'target' : {
139
+ 'service_name' : service_name ,
140
+ 'resource_kind' : 'service'
141
+ },
142
+ 'required_config' : {
143
+ 'description' :
144
+ 'Public access check' ,
145
+ 'and' : [{
146
+ 'property' : 'public_access_enabled' ,
147
+ 'operator' : 'is_false'
148
+ }]
149
+ },
150
+ 'enforcement_actions' : [{
151
+ 'action' : 'disallow'
152
+ }, {
153
+ 'action' : 'audit_log'
154
+ }]
155
+ }
126
156
}
127
157
128
158
detailed_response = configuration_governance_service .create_rules (
129
- rules = [create_rule_request_model ],
130
- transaction_id = transaction_id
131
- )
159
+ rules = [create_rule_request_model ])
132
160
create_rules_response = detailed_response .get_result ()
133
161
if detailed_response .status_code == 207 :
134
162
for responseEntry in create_rules_response ['rules' ]:
135
163
if responseEntry ['status_code' ] > 299 :
136
164
raise ApiException (
137
- code = responseEntry ['errors' ][0 ]['code' ], message = responseEntry ['errors' ][0 ]['message' ])
165
+ code = responseEntry ['errors' ][0 ]['code' ],
166
+ message = responseEntry ['errors' ][0 ]['message' ])
138
167
139
168
print (json .dumps (create_rules_response , indent = 2 ))
140
169
@@ -161,22 +190,25 @@ def test_create_attachments_example(self):
161
190
162
191
attachment_request_model = {
163
192
'account_id' : account_id ,
164
- 'included_scope' : {'note' : 'My enterprise' , 'scope_id' : enterprise_scope_id , 'scope_type' : 'enterprise' },
193
+ 'included_scope' : {
194
+ 'note' : 'My enterprise' ,
195
+ 'scope_id' : enterprise_scope_id ,
196
+ 'scope_type' : 'enterprise'
197
+ },
165
198
'excluded_scopes' : [excluded_scope_model ]
166
199
}
167
200
168
201
create_attachments_response = configuration_governance_service .create_attachments (
169
202
rule_id = rule_id_link ,
170
- attachments = [attachment_request_model ],
171
- transaction_id = transaction_id
172
- ).get_result ()
203
+ attachments = [attachment_request_model ]).get_result ()
173
204
174
205
print (json .dumps (create_attachments_response , indent = 2 ))
175
206
176
207
# end-create_attachments
177
208
178
209
global attachment_id_link
179
- attachment_id_link = create_attachments_response ['attachments' ][0 ]['attachment_id' ]
210
+ attachment_id_link = create_attachments_response ['attachments' ][0 ][
211
+ 'attachment_id' ]
180
212
except ApiException as e :
181
213
pytest .fail (str (e ))
182
214
@@ -190,9 +222,7 @@ def test_get_attachment_example(self):
190
222
191
223
attachment = configuration_governance_service .get_attachment (
192
224
rule_id = rule_id_link ,
193
- attachment_id = attachment_id_link ,
194
- transaction_id = transaction_id
195
- ).get_result ()
225
+ attachment_id = attachment_id_link ).get_result ()
196
226
197
227
print (json .dumps (attachment , indent = 2 ))
198
228
@@ -201,9 +231,7 @@ def test_get_attachment_example(self):
201
231
global attachment_etag_link
202
232
attachment_etag_link = configuration_governance_service .get_attachment (
203
233
rule_id = rule_id_link ,
204
- attachment_id = attachment_id_link ,
205
- transaction_id = transaction_id
206
- ).get_headers ().get ('Etag' )
234
+ attachment_id = attachment_id_link ).get_headers ().get ('Etag' )
207
235
except ApiException as e :
208
236
pytest .fail (str (e ))
209
237
@@ -216,19 +244,15 @@ def test_get_rule_example(self):
216
244
# begin-get_rule
217
245
218
246
rule = configuration_governance_service .get_rule (
219
- rule_id = rule_id_link ,
220
- transaction_id = transaction_id
221
- ).get_result ()
247
+ rule_id = rule_id_link ).get_result ()
222
248
223
249
print (json .dumps (rule , indent = 2 ))
224
250
225
251
# end-get_rule
226
252
227
253
global rule_etag_link
228
254
rule_etag_link = configuration_governance_service .get_rule (
229
- rule_id = rule_id_link ,
230
- transaction_id = transaction_id
231
- ).get_headers ().get ('etag' )
255
+ rule_id = rule_id_link ).get_headers ().get ('etag' )
232
256
except ApiException as e :
233
257
pytest .fail (str (e ))
234
258
@@ -241,9 +265,7 @@ def test_list_rules_example(self):
241
265
# begin-list_rules
242
266
243
267
rule_list = configuration_governance_service .list_rules (
244
- account_id = account_id ,
245
- transaction_id = transaction_id
246
- ).get_result ()
268
+ account_id = account_id ).get_result ()
247
269
248
270
print (json .dumps (rule_list , indent = 2 ))
249
271
@@ -276,25 +298,27 @@ def test_update_rule_example(self):
276
298
'operator' : 'is_false'
277
299
}
278
300
279
- enforcement_action_model = {
280
- 'action' : 'audit_log'
281
- }
301
+ enforcement_action_model = {'action' : 'audit_log' }
282
302
283
303
rule = configuration_governance_service .update_rule (
284
304
rule_id = rule_id_link ,
285
- transaction_id = transaction_id ,
286
305
if_match = rule_etag_link ,
287
306
name = 'Disable public access' ,
288
- description = 'Ensure that public access to account resources is disabled.' ,
289
- target = {'service_name' : service_name , 'resource_kind' : 'service' ,
290
- 'additional_target_attributes' : []},
307
+ description =
308
+ 'Ensure that public access to account resources is disabled.' ,
309
+ target = {
310
+ 'service_name' : service_name ,
311
+ 'resource_kind' : 'service' ,
312
+ 'additional_target_attributes' : []
313
+ },
291
314
required_config = {
292
- 'property' : 'public_access_enabled' , 'operator' : 'is_false' },
315
+ 'property' : 'public_access_enabled' ,
316
+ 'operator' : 'is_false'
317
+ },
293
318
enforcement_actions = [enforcement_action_model ],
294
319
account_id = account_id ,
295
320
rule_type = 'user_defined' ,
296
- labels = ['testString' ]
297
- ).get_result ()
321
+ labels = ['testString' ]).get_result ()
298
322
299
323
print (json .dumps (rule , indent = 2 ))
300
324
@@ -312,9 +336,7 @@ def test_list_attachments_example(self):
312
336
# begin-list_attachments
313
337
314
338
attachment_list = configuration_governance_service .list_attachments (
315
- rule_id = rule_id_link ,
316
- transaction_id = transaction_id
317
- ).get_result ()
339
+ rule_id = rule_id_link ).get_result ()
318
340
319
341
print (json .dumps (attachment_list , indent = 2 ))
320
342
@@ -340,13 +362,14 @@ def test_update_attachment_example(self):
340
362
attachment = configuration_governance_service .update_attachment (
341
363
rule_id = rule_id_link ,
342
364
attachment_id = attachment_id_link ,
343
- transaction_id = transaction_id ,
344
365
if_match = attachment_etag_link ,
345
366
account_id = account_id ,
346
- included_scope = {'note' : 'My enterprise' ,
347
- 'scope_id' : enterprise_scope_id , 'scope_type' : 'enterprise' },
348
- excluded_scopes = [excluded_scope_model ]
349
- ).get_result ()
367
+ included_scope = {
368
+ 'note' : 'My enterprise' ,
369
+ 'scope_id' : enterprise_scope_id ,
370
+ 'scope_type' : 'enterprise'
371
+ },
372
+ excluded_scopes = [excluded_scope_model ]).get_result ()
350
373
351
374
print (json .dumps (attachment , indent = 2 ))
352
375
@@ -365,9 +388,7 @@ def test_delete_attachment_example(self):
365
388
366
389
response = configuration_governance_service .delete_attachment (
367
390
rule_id = rule_id_link ,
368
- attachment_id = attachment_id_link ,
369
- transaction_id = transaction_id
370
- ).get_result ()
391
+ attachment_id = attachment_id_link ).get_result ()
371
392
372
393
print (json .dumps (response , indent = 2 ))
373
394
@@ -385,9 +406,7 @@ def test_delete_rule_example(self):
385
406
# begin-delete_rule
386
407
387
408
response = configuration_governance_service .delete_rule (
388
- rule_id = rule_id_link ,
389
- transaction_id = transaction_id
390
- ).get_result ()
409
+ rule_id = rule_id_link ).get_result ()
391
410
392
411
print (json .dumps (response , indent = 2 ))
393
412
@@ -403,7 +422,6 @@ def clean_rules(cls):
403
422
"""
404
423
try :
405
424
rule_list = configuration_governance_service .list_rules (
406
- transaction_id = transaction_id ,
407
425
account_id = account_id ,
408
426
labels = test_label ,
409
427
).get_result ()
@@ -416,6 +434,7 @@ def clean_rules(cls):
416
434
except ApiException as e :
417
435
print (str (e ))
418
436
437
+
419
438
# endregion
420
439
##############################################################################
421
440
# End of Examples for Service: ConfigurationGovernanceV1
0 commit comments