Skip to content

Commit 2c03969

Browse files
committed
fix(IAM Policy Management): re-gen service and add examples after recent API changes
1 parent 413ff9e commit 2c03969

File tree

3 files changed

+499
-28
lines changed

3 files changed

+499
-28
lines changed
Lines changed: 290 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,290 @@
1+
# -*- coding: utf-8 -*-
2+
# (C) Copyright IBM Corp. 2021.
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
16+
"""
17+
Examples for IamPolicyManagementV1
18+
"""
19+
20+
import os
21+
import pytest
22+
from ibm_cloud_sdk_core import ApiException, read_external_sources
23+
from ibm_platform_services.iam_policy_management_v1 import *
24+
25+
# Config file name
26+
config_file = 'iam_policy_management_v1.env'
27+
28+
iam_policy_management_service = None
29+
30+
config = None
31+
32+
33+
##############################################################################
34+
# Start of Examples for Service: IamPolicyManagementV1
35+
##############################################################################
36+
# region
37+
class TestIamPolicyManagementV1Examples():
38+
"""
39+
Example Test Class for IamPolicyManagementV1
40+
"""
41+
42+
@classmethod
43+
def setup_class(cls):
44+
global iam_policy_management_service
45+
if os.path.exists(config_file):
46+
os.environ['IBM_CREDENTIALS_FILE'] = config_file
47+
48+
# begin-common
49+
50+
iam_policy_management_service = IamPolicyManagementV1.new_instance(
51+
)
52+
53+
# end-common
54+
assert iam_policy_management_service is not None
55+
56+
# Load the configuration
57+
global config
58+
config = read_external_sources(IamPolicyManagementV1.DEFAULT_SERVICE_NAME)
59+
60+
print('Setup complete.')
61+
62+
needscredentials = pytest.mark.skipif(
63+
not os.path.exists(config_file), reason="External configuration not available, skipping..."
64+
)
65+
66+
@needscredentials
67+
def test_list_policies_example(self):
68+
"""
69+
list_policies request example
70+
"""
71+
try:
72+
# begin-list_policies
73+
74+
policy_list = iam_policy_management_service.list_policies(
75+
account_id='testString'
76+
).get_result()
77+
78+
print(json.dumps(policy_list, indent=2))
79+
80+
# end-list_policies
81+
82+
except ApiException as e:
83+
pytest.fail(str(e))
84+
85+
@needscredentials
86+
def test_create_policy_example(self):
87+
"""
88+
create_policy request example
89+
"""
90+
try:
91+
# begin-create_policy
92+
93+
policy_subject_model = {
94+
}
95+
96+
policy_role_model = {
97+
'role_id': 'testString'
98+
}
99+
100+
policy_resource_model = {
101+
}
102+
103+
policy = iam_policy_management_service.create_policy(
104+
type='testString',
105+
subjects=[policy_subject_model],
106+
roles=[policy_role_model],
107+
resources=[policy_resource_model]
108+
).get_result()
109+
110+
print(json.dumps(policy, indent=2))
111+
112+
# end-create_policy
113+
114+
except ApiException as e:
115+
pytest.fail(str(e))
116+
117+
@needscredentials
118+
def test_update_policy_example(self):
119+
"""
120+
update_policy request example
121+
"""
122+
try:
123+
# begin-update_policy
124+
125+
policy_subject_model = {
126+
}
127+
128+
policy_role_model = {
129+
'role_id': 'testString'
130+
}
131+
132+
policy_resource_model = {
133+
}
134+
135+
policy = iam_policy_management_service.update_policy(
136+
policy_id='testString',
137+
if_match='testString',
138+
type='testString',
139+
subjects=[policy_subject_model],
140+
roles=[policy_role_model],
141+
resources=[policy_resource_model]
142+
).get_result()
143+
144+
print(json.dumps(policy, indent=2))
145+
146+
# end-update_policy
147+
148+
except ApiException as e:
149+
pytest.fail(str(e))
150+
151+
@needscredentials
152+
def test_get_policy_example(self):
153+
"""
154+
get_policy request example
155+
"""
156+
try:
157+
# begin-get_policy
158+
159+
policy = iam_policy_management_service.get_policy(
160+
policy_id='testString'
161+
).get_result()
162+
163+
print(json.dumps(policy, indent=2))
164+
165+
# end-get_policy
166+
167+
except ApiException as e:
168+
pytest.fail(str(e))
169+
170+
@needscredentials
171+
def test_list_roles_example(self):
172+
"""
173+
list_roles request example
174+
"""
175+
try:
176+
# begin-list_roles
177+
178+
role_list = iam_policy_management_service.list_roles().get_result()
179+
180+
print(json.dumps(role_list, indent=2))
181+
182+
# end-list_roles
183+
184+
except ApiException as e:
185+
pytest.fail(str(e))
186+
187+
@needscredentials
188+
def test_create_role_example(self):
189+
"""
190+
create_role request example
191+
"""
192+
try:
193+
# begin-create_role
194+
195+
custom_role = iam_policy_management_service.create_role(
196+
display_name='testString',
197+
actions=['testString'],
198+
name='testString',
199+
account_id='testString',
200+
service_name='testString'
201+
).get_result()
202+
203+
print(json.dumps(custom_role, indent=2))
204+
205+
# end-create_role
206+
207+
except ApiException as e:
208+
pytest.fail(str(e))
209+
210+
@needscredentials
211+
def test_update_role_example(self):
212+
"""
213+
update_role request example
214+
"""
215+
try:
216+
# begin-update_role
217+
218+
custom_role = iam_policy_management_service.update_role(
219+
role_id='testString',
220+
if_match='testString',
221+
).get_result()
222+
223+
print(json.dumps(custom_role, indent=2))
224+
225+
# end-update_role
226+
227+
except ApiException as e:
228+
pytest.fail(str(e))
229+
230+
@needscredentials
231+
def test_get_role_example(self):
232+
"""
233+
get_role request example
234+
"""
235+
try:
236+
# begin-get_role
237+
238+
custom_role = iam_policy_management_service.get_role(
239+
role_id='testString'
240+
).get_result()
241+
242+
print(json.dumps(custom_role, indent=2))
243+
244+
# end-get_role
245+
246+
except ApiException as e:
247+
pytest.fail(str(e))
248+
249+
@needscredentials
250+
def test_delete_role_example(self):
251+
"""
252+
delete_role request example
253+
"""
254+
try:
255+
# begin-delete_role
256+
257+
response = iam_policy_management_service.delete_role(
258+
role_id='testString'
259+
).get_result()
260+
261+
print(json.dumps(response, indent=2))
262+
263+
# end-delete_role
264+
265+
except ApiException as e:
266+
pytest.fail(str(e))
267+
268+
@needscredentials
269+
def test_delete_policy_example(self):
270+
"""
271+
delete_policy request example
272+
"""
273+
try:
274+
# begin-delete_policy
275+
276+
response = iam_policy_management_service.delete_policy(
277+
policy_id='testString'
278+
).get_result()
279+
280+
print(json.dumps(response, indent=2))
281+
282+
# end-delete_policy
283+
284+
except ApiException as e:
285+
pytest.fail(str(e))
286+
287+
# endregion
288+
##############################################################################
289+
# End of Examples for Service: IamPolicyManagementV1
290+
##############################################################################

0 commit comments

Comments
 (0)