Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
86 changes: 82 additions & 4 deletions examples/test_iam_policy_management_v1_examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
example_role_template_etag = None
example_role_template_assignment_id = None
example_role_template_assignment_etag = None
example_role_policy_template_id = None


##############################################################################
Expand Down Expand Up @@ -1443,10 +1444,17 @@ def test_create_role_template_example(self):
print('\ncreate_role_template() result:')

# begin-create_role_template

template_role_model = {
'name': 'SDKCustomRoleName',
'display_name': 'SDK Test Custom Role',
'service_name': 'am-test-service',
'description': 'SDK Test Custom Role',
'actions': ['am-test-service.test.create'],
}
response = iam_policy_management_service.create_role_template(
name='SDKRoleTemplateExample',
account_id=example_account_id,
role=template_role_model,
)
role_template = response.get_result()

Expand All @@ -1462,6 +1470,61 @@ def test_create_role_template_example(self):
except ApiException as e:
pytest.fail(str(e))

@needscredentials
def test_create_role_policy_template_example(self):
"""
create_role_policy_template request example
"""
try:
print('\ncreate_role_policy_template() result:')
# begin-create_role_policy_template

policy_resource_model = {
'attributes': [
{
'key': 'serviceName',
'operator': 'stringEquals',
'value': 'am-test-service',
}
],
}

control_model = TemplateControl(
grant=TemplateGrant(
roles=[
{
'role_id': 'crn:v1:bluemix:public:iam::::role:Viewer',
}
],
role_template_references=[
{'id': example_role_template_id, 'version': example_role_template_version}
],
)
)

template_policy_model = {
'type': 'access',
'resource': policy_resource_model,
'control': control_model.to_dict(),
}

response = iam_policy_management_service.create_policy_template(
name='SDKExamplesTest',
account_id=example_account_id,
policy=template_policy_model,
)
policy_template = response.get_result()

global example_role_policy_template_id
example_role_policy_template_id = policy_template['id']

print(json.dumps(policy_template, indent=2))

# end-create_policy_template

except ApiException as e:
pytest.fail(str(e))

# @needscredentials
def test_get_role_template_example(self):
"""
Expand Down Expand Up @@ -1498,7 +1561,6 @@ def test_replace_role_template_example(self):
# begin-replace_role_template

template_role_model = {
'name': 'SDKRoleTemplateExampleRe',
'display_name': 'am-test-service',
'service_name': 'am-test-service',
'actions': ['am-test-service.test.delete'],
Expand Down Expand Up @@ -1558,9 +1620,7 @@ def test_create_role_template_version_example(self):
# begin-create_role_template_version

template_role_model = {
'name': 'SDKRoleTemplateExampleVer',
'display_name': 'am-test-service',
'service_name': 'am-test-service',
'actions': ['am-test-service.test.delete', 'am-test-service.test.create'],
}

Expand Down Expand Up @@ -1779,6 +1839,24 @@ def test_delete_role_assignment_example(self):
except ApiException as e:
pytest.fail(str(e))

@needscredentials
def test_delete_role_policy_template_example(self):
"""
delete_role_policy_template request example
"""
try:
# begin-delete_role_policy_template

response = iam_policy_management_service.delete_policy_template(
policy_template_id=example_role_policy_template_id,
)

# end-delete_policy_template
print('\ndelete_role_policy_template() response status code: ', response.get_status_code())

except ApiException as e:
pytest.fail(str(e))

# @needscredentials
def test_delete_role_template_version_example(self):
"""
Expand Down
Loading