Merge pull request #958 from JackDanger/implement_iam_delete_role
implementing IAM delete_role
This commit is contained in:
commit
584352aaf6
@ -569,6 +569,13 @@ class IAMBackend(BaseBackend):
|
||||
return role
|
||||
raise IAMNotFoundException("Role {0} not found".format(role_name))
|
||||
|
||||
def delete_role(self, role_name):
|
||||
for role in self.get_roles():
|
||||
if role.name == role_name:
|
||||
del self.roles[role.id]
|
||||
return
|
||||
raise IAMNotFoundException("Role {0} not found".format(role_name))
|
||||
|
||||
def get_roles(self):
|
||||
return self.roles.values()
|
||||
|
||||
|
@ -62,6 +62,12 @@ class IamResponse(BaseResponse):
|
||||
template = self.response_template(GET_ROLE_TEMPLATE)
|
||||
return template.render(role=role)
|
||||
|
||||
def delete_role(self):
|
||||
role_name = self._get_param('RoleName')
|
||||
iam_backend.delete_role(role_name)
|
||||
template = self.response_template(GENERIC_EMPTY_TEMPLATE)
|
||||
return template.render(name="DeleteRoleResponse")
|
||||
|
||||
def list_role_policies(self):
|
||||
role_name = self._get_param('RoleName')
|
||||
role_policies_names = iam_backend.list_role_policies(role_name)
|
||||
|
@ -8,7 +8,7 @@ from boto.exception import BotoServerError
|
||||
from botocore.exceptions import ClientError
|
||||
from moto import mock_iam, mock_iam_deprecated
|
||||
from moto.iam.models import aws_managed_policies
|
||||
from nose.tools import assert_raises, assert_equals, assert_not_equals
|
||||
from nose.tools import assert_raises, assert_equals
|
||||
from nose.tools import raises
|
||||
|
||||
from tests.helpers import requires_boto_gte
|
||||
@ -114,6 +114,23 @@ def test_remove_role_from_instance_profile():
|
||||
dict(profile.roles).should.be.empty
|
||||
|
||||
|
||||
@mock_iam()
|
||||
def test_delete_role():
|
||||
conn = boto3.client('iam', region_name='us-east-1')
|
||||
|
||||
with assert_raises(ClientError):
|
||||
conn.delete_role(RoleName="my-role")
|
||||
|
||||
conn.create_role(RoleName="my-role", AssumeRolePolicyDocument="some policy", Path="/my-path/")
|
||||
role = conn.get_role(RoleName="my-role")
|
||||
role.get('Role').get('Arn').should.equal('arn:aws:iam::123456789012:role/my-path/my-role')
|
||||
|
||||
conn.delete_role(RoleName="my-role")
|
||||
|
||||
with assert_raises(ClientError):
|
||||
conn.get_role(RoleName="my-role")
|
||||
|
||||
|
||||
@mock_iam_deprecated()
|
||||
def test_list_instance_profiles():
|
||||
conn = boto.connect_iam()
|
||||
|
Loading…
Reference in New Issue
Block a user