Skip to content

Commit f1ccda4

Browse files
authored
fix(IAM Policy Management): remove support for v2/polices until GA (#183)
Signed-off-by: Shaun Colley <shaun.colley@ibm.com>
1 parent 8252e26 commit f1ccda4

File tree

4 files changed

+606
-3304
lines changed

4 files changed

+606
-3304
lines changed

examples/test_iam_policy_management_v1_examples.py

Lines changed: 0 additions & 189 deletions
Original file line numberDiff line numberDiff line change
@@ -243,195 +243,6 @@ def test_delete_policy_example(self):
243243
except ApiException as e:
244244
pytest.fail(str(e))
245245

246-
@needscredentials
247-
def test_v2_create_policy_example(self):
248-
"""
249-
v2_create_policy request example
250-
"""
251-
try:
252-
global example_policy_id
253-
254-
print('\nv2_create_policy() result:')
255-
# begin-v2_create_policy
256-
257-
policy_subject = V2PolicyBaseSubject(
258-
attributes=[V2PolicyAttribute(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 = V2PolicyAttribute(
262-
key='accountId', value=example_account_id, operator='stringEquals'
263-
)
264-
service_name_resource_attribute = V2PolicyAttribute(
265-
key='serviceType', value='service', operator='stringEquals'
266-
)
267-
policy_resource = PolicyResource(
268-
attributes=[account_id_resource_attribute, service_name_resource_attribute],
269-
)
270-
policy_control = V2PolicyBaseControl(grant=V2PolicyBaseControlGrant(roles=[policy_role]))
271-
policy_rule = V2PolicyBaseRuleV2RuleWithConditions(
272-
operator='and',
273-
conditions=[
274-
V2PolicyAttribute(
275-
key='{{environment.attributes.day_of_week}}', operator='dayOfWeekAnyOf', value=[1, 2, 3, 4, 5]
276-
),
277-
V2PolicyAttribute(
278-
key='{{environment.attributes.current_time}}',
279-
operator='timeGreaterThanOrEquals',
280-
value='09:00:00+00:00',
281-
),
282-
V2PolicyAttribute(
283-
key='{{environment.attributes.current_time}}',
284-
operator='timeLessThanOrEquals',
285-
value='17:00:00+00:00',
286-
),
287-
],
288-
)
289-
policy_pattern = 'time-based-restrictions:weekly'
290-
291-
policy = iam_policy_management_service.v2_create_policy(
292-
type='access',
293-
subject=policy_subject,
294-
control=policy_control,
295-
resource=policy_resource,
296-
rule=policy_rule,
297-
pattern=policy_pattern,
298-
).get_result()
299-
300-
print(json.dumps(policy, indent=2))
301-
302-
# end-v2_create_policy
303-
304-
example_policy_id = policy['id']
305-
306-
except ApiException as e:
307-
pytest.fail(str(e))
308-
309-
@needscredentials
310-
def test_v2_get_policy_example(self):
311-
"""
312-
v2_get_policy request example
313-
"""
314-
try:
315-
global example_policy_etag
316-
317-
print('\nv2_get_policy() result:')
318-
# begin-v2_get_policy
319-
320-
response = iam_policy_management_service.v2_get_policy(policy_id=example_policy_id)
321-
policy = response.get_result()
322-
323-
print(json.dumps(policy, indent=2))
324-
325-
# end-v2_get_policy
326-
327-
example_policy_etag = response.get_headers().get("Etag")
328-
329-
except ApiException as e:
330-
pytest.fail(str(e))
331-
332-
@needscredentials
333-
def test_v2_update_policy_example(self):
334-
"""
335-
v2_update_policy request example
336-
"""
337-
try:
338-
339-
print('\nupdate_policy() result:')
340-
# begin-v2_update_policy
341-
342-
policy_subject = V2PolicyBaseSubject(
343-
attributes=[V2PolicyAttribute(key='iam_id', value=example_user_id, operator='stringEquals')]
344-
)
345-
updated_policy_role = PolicyRole(role_id='crn:v1:bluemix:public:iam::::role:Editor')
346-
account_id_resource_attribute = V2PolicyAttribute(
347-
key='accountId', value=example_account_id, operator='stringEquals'
348-
)
349-
service_name_resource_attribute = V2PolicyAttribute(
350-
key='serviceType', value='service', operator='stringEquals'
351-
)
352-
policy_resource = PolicyResource(
353-
attributes=[account_id_resource_attribute, service_name_resource_attribute],
354-
)
355-
policy_control = V2PolicyBaseControl(grant=V2PolicyBaseControlGrant(roles=[updated_policy_role]))
356-
policy_rule = V2PolicyBaseRuleV2RuleWithConditions(
357-
operator='and',
358-
conditions=[
359-
V2PolicyAttribute(
360-
key='{{environment.attributes.day_of_week}}', operator='dayOfWeekAnyOf', value=[1, 2, 3, 4, 5]
361-
),
362-
V2PolicyAttribute(
363-
key='{{environment.attributes.current_time}}',
364-
operator='timeGreaterThanOrEquals',
365-
value='09:00:00+00:00',
366-
),
367-
V2PolicyAttribute(
368-
key='{{environment.attributes.current_time}}',
369-
operator='timeLessThanOrEquals',
370-
value='17:00:00+00:00',
371-
),
372-
],
373-
)
374-
policy_pattern = 'time-based-restrictions:weekly'
375-
376-
response = iam_policy_management_service.v2_update_policy(
377-
type='access',
378-
policy_id=example_policy_id,
379-
if_match=example_policy_etag,
380-
subject=policy_subject,
381-
control=policy_control,
382-
resource=policy_resource,
383-
rule=policy_rule,
384-
pattern=policy_pattern,
385-
)
386-
policy = response.get_result()
387-
388-
print(json.dumps(policy, indent=2))
389-
390-
# end-v2_update_policy
391-
392-
except ApiException as e:
393-
pytest.fail(str(e))
394-
395-
@needscredentials
396-
def test_v2_list_policies_example(self):
397-
"""
398-
v2_list_policies request example
399-
"""
400-
try:
401-
402-
print('\nlist_policies() result:')
403-
# begin-v2_list_policies
404-
405-
policy_list = iam_policy_management_service.v2_list_policies(
406-
account_id=example_account_id, iam_id=example_user_id, format='include_last_permit'
407-
).get_result()
408-
409-
print(json.dumps(policy_list, indent=2))
410-
411-
# end-v2_list_policies
412-
413-
except ApiException as e:
414-
pytest.fail(str(e))
415-
416-
@needscredentials
417-
def test_v2_delete_policy_example(self):
418-
"""
419-
v2_delete_policy request example
420-
"""
421-
try:
422-
423-
print('\nv2_delete_policy() result:')
424-
# begin-v2_delete_policy
425-
426-
response = iam_policy_management_service.v2_delete_policy(policy_id=example_policy_id).get_result()
427-
428-
print(json.dumps(response, indent=2))
429-
430-
# end-v2_delete_policy
431-
432-
except ApiException as e:
433-
pytest.fail(str(e))
434-
435246
@needscredentials
436247
def test_create_role_example(self):
437248
"""

0 commit comments

Comments
 (0)