19
19
20
20
import os
21
21
import pytest
22
- import random
23
22
from ibm_cloud_sdk_core import ApiException , read_external_sources
24
23
from ibm_platform_services .iam_policy_management_v1 import *
25
24
45
44
46
45
config = None
47
46
48
- test_account_id = None
49
- test_policy_id = None
50
- test_policy_etag = None
51
- test_custom_role_id = None
52
- test_custom_role_etag = None
53
- test_user_id = "IBMid-SDKPython" + str ( random . randint ( 0 , 99999 ))
54
- test_service_name = "iam-groups"
47
+ example_account_id = None
48
+ example_policy_id = None
49
+ example_policy_etag = None
50
+ example_custom_role_id = None
51
+ example_custom_role_etag = None
52
+ example_user_id = "IBMid-user1"
53
+ example_service_name = "iam-groups"
55
54
56
55
##############################################################################
57
56
# Start of Examples for Service: IamPolicyManagementV1
@@ -77,9 +76,9 @@ def setup_class(cls):
77
76
assert iam_policy_management_service is not None
78
77
79
78
# Load the configuration
80
- global config , test_account_id
79
+ global config , example_account_id
81
80
config = read_external_sources (IamPolicyManagementV1 .DEFAULT_SERVICE_NAME )
82
- test_account_id = config ['TEST_ACCOUNT_ID' ]
81
+ example_account_id = config ['TEST_ACCOUNT_ID' ]
83
82
84
83
print ('Setup complete.' )
85
84
@@ -93,34 +92,34 @@ def test_create_policy_example(self):
93
92
create_policy request example
94
93
"""
95
94
try :
96
- global test_policy_id
95
+ global example_policy_id
97
96
# begin-create_policy
98
97
99
- policy_subject = PolicySubject (
100
- attributes = [SubjectAttribute (name = 'iam_id' , value = test_user_id )])
101
- policy_role = PolicyRole (
98
+ policy_subjects = PolicySubject (
99
+ attributes = [SubjectAttribute (name = 'iam_id' , value = example_user_id )])
100
+ policy_roles = PolicyRole (
102
101
role_id = 'crn:v1:bluemix:public:iam::::role:Viewer' )
103
- resource_account_attribute = ResourceAttribute (
104
- name = 'accountId' , value = test_account_id )
105
- resource_service_attribute = ResourceAttribute (
106
- name = 'serviceName' , value = test_service_name )
107
- resource_tag = ResourceTag (name = 'project' , value = 'prototype' )
108
- policy_resource = PolicyResource (
109
- attributes = [resource_account_attribute ,
110
- resource_service_attribute ],
111
- tags = [resource_tag ])
102
+ account_id_resource_attribute = ResourceAttribute (
103
+ name = 'accountId' , value = example_account_id )
104
+ service_name_resource_attribute = ResourceAttribute (
105
+ name = 'serviceName' , value = example_service_name )
106
+ policy_resource_tag = ResourceTag (name = 'project' , value = 'prototype' )
107
+ policy_resources = PolicyResource (
108
+ attributes = [account_id_resource_attribute ,
109
+ service_name_resource_attribute ],
110
+ tags = [policy_resource_tag ])
112
111
113
112
policy = iam_policy_management_service .create_policy (
114
113
type = 'access' ,
115
- subjects = [policy_subject ],
116
- roles = [policy_role ],
117
- resources = [policy_resource ]
114
+ subjects = [policy_subjects ],
115
+ roles = [policy_roles ],
116
+ resources = [policy_resources ]
118
117
).get_result ()
119
118
120
- print (policy )
119
+ print (json . dumps ( policy , indent = 2 ) )
121
120
122
121
# end-create_policy
123
- test_policy_id = policy ['id' ]
122
+ example_policy_id = policy ['id' ]
124
123
125
124
except ApiException as e :
126
125
pytest .fail (str (e ))
@@ -131,18 +130,18 @@ def test_get_policy_example(self):
131
130
get_policy request example
132
131
"""
133
132
try :
134
- global test_policy_etag
133
+ global example_policy_etag
135
134
# begin-get_policy
136
135
137
136
response = iam_policy_management_service .get_policy (
138
- policy_id = test_policy_id
137
+ policy_id = example_policy_id
139
138
)
140
139
policy = response .get_result ()
141
140
142
- print (policy )
141
+ print (json . dumps ( policy , indent = 2 ) )
143
142
144
143
# end-get_policy
145
- test_policy_etag = response .get_headers ().get ("Etag" )
144
+ example_policy_etag = response .get_headers ().get ("Etag" )
146
145
147
146
except ApiException as e :
148
147
pytest .fail (str (e ))
@@ -155,30 +154,30 @@ def test_update_policy_example(self):
155
154
try :
156
155
# begin-update_policy
157
156
158
- policy_subject = PolicySubject (
159
- attributes = [SubjectAttribute (name = 'iam_id' , value = test_user_id )])
160
- updated_policy_role = PolicyRole (
157
+ policy_subjects = PolicySubject (
158
+ attributes = [SubjectAttribute (name = 'iam_id' , value = example_user_id )])
159
+ account_id_resource_attribute = ResourceAttribute (
160
+ name = 'accountId' , value = example_account_id )
161
+ service_name_resource_attribute = ResourceAttribute (
162
+ name = 'serviceName' , value = example_service_name )
163
+ policy_resource_tag = ResourceTag (name = 'project' , value = 'prototype' )
164
+ policy_resources = PolicyResource (
165
+ attributes = [account_id_resource_attribute ,
166
+ service_name_resource_attribute ],
167
+ tags = [policy_resource_tag ])
168
+ updated_policy_roles = PolicyRole (
161
169
role_id = 'crn:v1:bluemix:public:iam::::role:Editor' )
162
- resource_account_attribute = ResourceAttribute (
163
- name = 'accountId' , value = test_account_id )
164
- resource_service_attribute = ResourceAttribute (
165
- name = 'serviceName' , value = test_service_name )
166
- resource_tag = ResourceTag (name = 'project' , value = 'prototype' )
167
- policy_resource = PolicyResource (
168
- attributes = [resource_account_attribute ,
169
- resource_service_attribute ],
170
- tags = [resource_tag ])
171
170
172
171
policy = iam_policy_management_service .update_policy (
173
172
type = 'access' ,
174
- policy_id = test_policy_id ,
175
- if_match = test_policy_etag ,
176
- subjects = [policy_subject ],
177
- roles = [updated_policy_role ],
178
- resources = [policy_resource ]
173
+ policy_id = example_policy_id ,
174
+ if_match = example_policy_etag ,
175
+ subjects = [policy_subjects ],
176
+ roles = [updated_policy_roles ],
177
+ resources = [policy_resources ]
179
178
).get_result ()
180
179
181
- print (policy )
180
+ print (json . dumps ( policy , indent = 2 ) )
182
181
183
182
# end-update_policy
184
183
@@ -194,10 +193,10 @@ def test_list_policies_example(self):
194
193
# begin-list_policies
195
194
196
195
policy_list = iam_policy_management_service .list_policies (
197
- account_id = test_account_id , iam_id = test_user_id , format = 'include_last_permit'
196
+ account_id = example_account_id , iam_id = example_user_id , format = 'include_last_permit'
198
197
).get_result ()
199
198
200
- print (policy_list )
199
+ print (json . dumps ( policy_list , indent = 2 ) )
201
200
202
201
# end-list_policies
203
202
@@ -213,10 +212,10 @@ def test_delete_policy_example(self):
213
212
# begin-delete_policy
214
213
215
214
response = iam_policy_management_service .delete_policy (
216
- policy_id = test_policy_id
217
- )
215
+ policy_id = example_policy_id
216
+ ). get_result ()
218
217
219
- print (response )
218
+ print (json . dumps ( response , indent = 2 ) )
220
219
221
220
# end-delete_policy
222
221
@@ -229,21 +228,21 @@ def test_create_role_example(self):
229
228
create_role request example
230
229
"""
231
230
try :
232
- global test_custom_role_id
231
+ global example_custom_role_id
233
232
# begin-create_role
234
233
235
234
custom_role = iam_policy_management_service .create_role (
236
235
display_name = 'IAM Groups read access' ,
237
236
actions = ['iam-groups.groups.read' ],
238
237
name = 'ExampleRoleIAMGroups' ,
239
- account_id = test_account_id ,
240
- service_name = test_service_name
238
+ account_id = example_account_id ,
239
+ service_name = example_service_name
241
240
).get_result ()
242
241
243
- print (custom_role )
242
+ print (json . dumps ( custom_role , indent = 2 ) )
244
243
245
244
# end-create_role
246
- test_custom_role_id = custom_role ["id" ]
245
+ example_custom_role_id = custom_role ["id" ]
247
246
248
247
except ApiException as e :
249
248
pytest .fail (str (e ))
@@ -254,18 +253,18 @@ def test_get_role_example(self):
254
253
get_role request example
255
254
"""
256
255
try :
257
- global test_custom_role_etag
256
+ global example_custom_role_etag
258
257
# begin-get_role
259
258
260
259
response = iam_policy_management_service .get_role (
261
- role_id = test_custom_role_id
260
+ role_id = example_custom_role_id
262
261
)
263
262
custom_role = response .get_result ()
264
263
265
- print (custom_role )
264
+ print (json . dumps ( custom_role , indent = 2 ) )
266
265
267
266
# end-get_role
268
- test_custom_role_etag = response .get_headers ().get ("Etag" )
267
+ example_custom_role_etag = response .get_headers ().get ("Etag" )
269
268
270
269
except ApiException as e :
271
270
pytest .fail (str (e ))
@@ -280,12 +279,12 @@ def test_update_role_example(self):
280
279
281
280
updated_role_actions = ['iam-groups.groups.read' , 'iam-groups.groups.list' ]
282
281
custom_role = iam_policy_management_service .update_role (
283
- role_id = test_custom_role_id ,
284
- if_match = test_custom_role_etag ,
282
+ role_id = example_custom_role_id ,
283
+ if_match = example_custom_role_etag ,
285
284
actions = updated_role_actions
286
285
).get_result ()
287
286
288
- print (custom_role )
287
+ print (json . dumps ( custom_role , indent = 2 ) )
289
288
290
289
# end-update_role
291
290
@@ -301,10 +300,10 @@ def test_list_roles_example(self):
301
300
# begin-list_roles
302
301
303
302
role_list = iam_policy_management_service .list_roles (
304
- account_id = test_account_id
303
+ account_id = example_account_id
305
304
).get_result ()
306
305
307
- print (role_list )
306
+ print (json . dumps ( role_list , indent = 2 ) )
308
307
309
308
# end-list_roles
310
309
@@ -320,10 +319,10 @@ def test_delete_role_example(self):
320
319
# begin-delete_role
321
320
322
321
response = iam_policy_management_service .delete_role (
323
- role_id = test_custom_role_id
324
- )
322
+ role_id = example_custom_role_id
323
+ ). get_result ()
325
324
326
- print (response )
325
+ print (json . dumps ( response , indent = 2 ) )
327
326
328
327
# end-delete_role
329
328
0 commit comments