@@ -144,15 +144,15 @@ def test_get_policy_example(self):
144
144
pytest .fail (str (e ))
145
145
146
146
@needscredentials
147
- def test_update_policy_example (self ):
147
+ def test_replace_policy_example (self ):
148
148
"""
149
- update_policy request example
149
+ replace_policy request example
150
150
"""
151
151
try :
152
152
global example_updated_policy_etag
153
153
154
- print ('\n update_policy () result:' )
155
- # begin-update_policy
154
+ print ('\n replace_policy () result:' )
155
+ # begin-replace_policy
156
156
157
157
policy_subjects = PolicySubject (attributes = [SubjectAttribute (name = 'iam_id' , value = example_user_id )])
158
158
account_id_resource_attribute = ResourceAttribute (name = 'accountId' , value = example_account_id )
@@ -163,7 +163,7 @@ def test_update_policy_example(self):
163
163
)
164
164
updated_policy_roles = PolicyRole (role_id = 'crn:v1:bluemix:public:iam::::role:Editor' )
165
165
166
- response = iam_policy_management_service .update_policy (
166
+ response = iam_policy_management_service .replace_policy (
167
167
type = 'access' ,
168
168
policy_id = example_policy_id ,
169
169
if_match = example_policy_etag ,
@@ -175,30 +175,30 @@ def test_update_policy_example(self):
175
175
176
176
print (json .dumps (policy , indent = 2 ))
177
177
178
- # end-update_policy
178
+ # end-replace_policy
179
179
180
180
example_updated_policy_etag = response .get_headers ().get ("Etag" )
181
181
182
182
except ApiException as e :
183
183
pytest .fail (str (e ))
184
184
185
185
@needscredentials
186
- def test_patch_policy_example (self ):
186
+ def test_update_policy_state_example (self ):
187
187
"""
188
- patch_policy request example
188
+ update_policy_state request example
189
189
"""
190
190
try :
191
191
192
- print ('\n patch_policy () result:' )
193
- # begin-patch_policy
192
+ print ('\n update_policy_state () result:' )
193
+ # begin-update_policy_state
194
194
195
- policy = iam_policy_management_service .patch_policy (
195
+ policy = iam_policy_management_service .update_policy_state (
196
196
policy_id = example_policy_id , if_match = example_updated_policy_etag , state = 'active'
197
197
).get_result ()
198
198
199
199
print (json .dumps (policy , indent = 2 ))
200
200
201
- # end-patch_policy
201
+ # end-update_policy_state
202
202
203
203
except ApiException as e :
204
204
pytest .fail (str (e ))
@@ -243,6 +243,201 @@ def test_delete_policy_example(self):
243
243
except ApiException as e :
244
244
pytest .fail (str (e ))
245
245
246
+ @needscredentials
247
+ def test_create_v2_policy_example (self ):
248
+ """
249
+ create_v2_policy request example
250
+ """
251
+ try :
252
+ global example_policy_id
253
+
254
+ print ('\n create_v2_policy() result:' )
255
+ # begin-create_v2_policy
256
+
257
+ policy_subject = V2PolicySubject (
258
+ attributes = [V2PolicySubjectAttribute (key = 'iam_id' , value = example_user_id , operator = 'stringEquals' )]
259
+ )
260
+ policy_role = PolicyRole (role_id = 'crn:v1:bluemix:public:iam::::role:Viewer' )
261
+ account_id_resource_attribute = V2PolicyResourceAttribute (
262
+ key = 'accountId' , value = example_account_id , operator = 'stringEquals'
263
+ )
264
+ service_name_resource_attribute = V2PolicyResourceAttribute (
265
+ key = 'serviceType' , value = 'service' , operator = 'stringEquals'
266
+ )
267
+ policy_resource_tag = V2PolicyResourceTag (key = 'project' , value = 'prototype' , operator = 'stringEquals' )
268
+ policy_resource = V2PolicyResource (
269
+ attributes = [account_id_resource_attribute , service_name_resource_attribute ], tags = [policy_resource_tag ]
270
+ )
271
+ policy_control = Control (grant = V2PolicyGrant (roles = [policy_role ]))
272
+ policy_rule = V2PolicyRuleRuleWithConditions (
273
+ operator = 'and' ,
274
+ conditions = [
275
+ RuleAttribute (
276
+ key = '{{environment.attributes.day_of_week}}' ,
277
+ operator = 'dayOfWeekAnyOf' ,
278
+ value = ['1+00:00' , '2+00:00' , '3+00:00' , '4+00:00' , '5+00:00' ],
279
+ ),
280
+ RuleAttribute (
281
+ key = '{{environment.attributes.current_time}}' ,
282
+ operator = 'timeGreaterThanOrEquals' ,
283
+ value = '09:00:00+00:00' ,
284
+ ),
285
+ RuleAttribute (
286
+ key = '{{environment.attributes.current_time}}' ,
287
+ operator = 'timeLessThanOrEquals' ,
288
+ value = '17:00:00+00:00' ,
289
+ ),
290
+ ],
291
+ )
292
+ policy_pattern = 'time-based-conditions:weekly:custom-hours'
293
+
294
+ policy = iam_policy_management_service .create_v2_policy (
295
+ type = 'access' ,
296
+ subject = policy_subject ,
297
+ control = policy_control ,
298
+ resource = policy_resource ,
299
+ rule = policy_rule ,
300
+ pattern = policy_pattern ,
301
+ ).get_result ()
302
+
303
+ print (json .dumps (policy , indent = 2 ))
304
+
305
+ # end-create_v2_policy
306
+
307
+ example_policy_id = policy ['id' ]
308
+
309
+ except ApiException as e :
310
+ pytest .fail (str (e ))
311
+
312
+ @needscredentials
313
+ def test_get_v2_policy_example (self ):
314
+ """
315
+ get_v2_policy request example
316
+ """
317
+ try :
318
+ global example_policy_etag
319
+
320
+ print ('\n get_v2_policy() result:' )
321
+ # begin-get_v2_policy
322
+
323
+ response = iam_policy_management_service .get_v2_policy (id = example_policy_id )
324
+ policy = response .get_result ()
325
+
326
+ print (json .dumps (policy , indent = 2 ))
327
+
328
+ # end-get_v2_policy
329
+
330
+ example_policy_etag = response .get_headers ().get ("Etag" )
331
+
332
+ except ApiException as e :
333
+ pytest .fail (str (e ))
334
+
335
+ @needscredentials
336
+ def test_replace_v2_policy_example (self ):
337
+ """
338
+ replace_v2_policy request example
339
+ """
340
+ try :
341
+
342
+ print ('\n replace_v2_policy() result:' )
343
+ # begin-replace_v2_policy
344
+
345
+ policy_subject = V2PolicySubject (
346
+ attributes = [V2PolicySubjectAttribute (key = 'iam_id' , value = example_user_id , operator = 'stringEquals' )]
347
+ )
348
+ updated_policy_role = PolicyRole (role_id = 'crn:v1:bluemix:public:iam::::role:Editor' )
349
+ account_id_resource_attribute = V2PolicyResourceAttribute (
350
+ key = 'accountId' , value = example_account_id , operator = 'stringEquals'
351
+ )
352
+ service_name_resource_attribute = V2PolicyResourceAttribute (
353
+ key = 'serviceType' , value = 'service' , operator = 'stringEquals'
354
+ )
355
+ policy_resource_tag = V2PolicyResourceTag (key = 'project' , value = 'prototype' , operator = 'stringEquals' )
356
+ policy_resource = PolicyResource (
357
+ attributes = [account_id_resource_attribute , service_name_resource_attribute ], tags = [policy_resource_tag ]
358
+ )
359
+ policy_control = Control (grant = V2PolicyGrant (roles = [updated_policy_role ]))
360
+ policy_rule = V2PolicyRuleRuleWithConditions (
361
+ operator = 'and' ,
362
+ conditions = [
363
+ RuleAttribute (
364
+ key = '{{environment.attributes.day_of_week}}' ,
365
+ operator = 'dayOfWeekAnyOf' ,
366
+ value = ['1+00:00' , '2+00:00' , '3+00:00' , '4+00:00' , '5+00:00' ],
367
+ ),
368
+ RuleAttribute (
369
+ key = '{{environment.attributes.current_time}}' ,
370
+ operator = 'timeGreaterThanOrEquals' ,
371
+ value = '09:00:00+00:00' ,
372
+ ),
373
+ RuleAttribute (
374
+ key = '{{environment.attributes.current_time}}' ,
375
+ operator = 'timeLessThanOrEquals' ,
376
+ value = '17:00:00+00:00' ,
377
+ ),
378
+ ],
379
+ )
380
+ policy_pattern = 'time-based-conditions:weekly:custom-hours'
381
+
382
+ response = iam_policy_management_service .replace_v2_policy (
383
+ type = 'access' ,
384
+ id = example_policy_id ,
385
+ if_match = example_policy_etag ,
386
+ subject = policy_subject ,
387
+ control = policy_control ,
388
+ resource = policy_resource ,
389
+ rule = policy_rule ,
390
+ pattern = policy_pattern ,
391
+ )
392
+ policy = response .get_result ()
393
+
394
+ print (json .dumps (policy , indent = 2 ))
395
+
396
+ # end-replace_v2_policy
397
+
398
+ except ApiException as e :
399
+ pytest .fail (str (e ))
400
+
401
+ @needscredentials
402
+ def test_list_v2_policies_example (self ):
403
+ """
404
+ list_v2_policies request example
405
+ """
406
+ try :
407
+
408
+ print ('\n list_v2_policies() result:' )
409
+ # begin-list_v2_policies
410
+
411
+ policy_list = iam_policy_management_service .list_v2_policies (
412
+ account_id = example_account_id , iam_id = example_user_id , format = 'include_last_permit'
413
+ ).get_result ()
414
+
415
+ print (json .dumps (policy_list , indent = 2 ))
416
+
417
+ # end-list_v2_policies
418
+
419
+ except ApiException as e :
420
+ pytest .fail (str (e ))
421
+
422
+ @needscredentials
423
+ def test_delete_v2_policy_example (self ):
424
+ """
425
+ delete_v2_policy request example
426
+ """
427
+ try :
428
+
429
+ print ('\n delete_v2_policy() result:' )
430
+ # begin-delete_v2_policy
431
+
432
+ response = iam_policy_management_service .delete_v2_policy (id = example_policy_id ).get_result ()
433
+
434
+ print (json .dumps (response , indent = 2 ))
435
+
436
+ # end-delete_v2_policy
437
+
438
+ except ApiException as e :
439
+ pytest .fail (str (e ))
440
+
246
441
@needscredentials
247
442
def test_create_role_example (self ):
248
443
"""
@@ -295,23 +490,26 @@ def test_get_role_example(self):
295
490
pytest .fail (str (e ))
296
491
297
492
@needscredentials
298
- def test_update_role_example (self ):
493
+ def test_replace_role_example (self ):
299
494
"""
300
- update_role request example
495
+ replace_role request example
301
496
"""
302
497
try :
303
498
304
- print ('\n update_role () result:' )
305
- # begin-update_role
499
+ print ('\n replace_role () result:' )
500
+ # begin-replace_role
306
501
307
502
updated_role_actions = ['iam-groups.groups.read' , 'iam-groups.groups.list' ]
308
- custom_role = iam_policy_management_service .update_role (
309
- role_id = example_custom_role_id , if_match = example_custom_role_etag , actions = updated_role_actions
503
+ custom_role = iam_policy_management_service .replace_role (
504
+ role_id = example_custom_role_id ,
505
+ if_match = example_custom_role_etag ,
506
+ actions = updated_role_actions ,
507
+ display_name = 'IAM Groups read access' ,
310
508
).get_result ()
311
509
312
510
print (json .dumps (custom_role , indent = 2 ))
313
511
314
- # end-update_role
512
+ # end-replace_role
315
513
316
514
except ApiException as e :
317
515
pytest .fail (str (e ))
0 commit comments