Merge pull request #2487 from bblommers/feature/iam_delete_policy

Feature - [IAM] Delete Policy
This commit is contained in:
Mike Grima 2019-10-18 09:53:51 -07:00 committed by GitHub
commit 4dd347e1fe
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 31 additions and 2 deletions

View File

@ -3194,7 +3194,7 @@
- [ ] delete_instance_profile
- [X] delete_login_profile
- [ ] delete_open_id_connect_provider
- [ ] delete_policy
- [X] delete_policy
- [X] delete_policy_version
- [X] delete_role
- [ ] delete_role_permissions_boundary

View File

@ -1099,6 +1099,9 @@ class IAMBackend(BaseBackend):
user = self.get_user(user_name)
user.delete_policy(policy_name)
def delete_policy(self, policy_arn):
del self.managed_policies[policy_arn]
def create_access_key(self, user_name=None):
user = self.get_user(user_name)
key = user.create_access_key()

View File

@ -604,6 +604,12 @@ class IamResponse(BaseResponse):
template = self.response_template(GENERIC_EMPTY_TEMPLATE)
return template.render(name='DeleteUser')
def delete_policy(self):
policy_arn = self._get_param('PolicyArn')
iam_backend.delete_policy(policy_arn)
template = self.response_template(GENERIC_EMPTY_TEMPLATE)
return template.render(name='DeletePolicy')
def delete_login_profile(self):
user_name = self._get_param('UserName')
iam_backend.delete_login_profile(user_name)

View File

@ -338,6 +338,15 @@ def test_create_policy():
response['Policy']['Arn'].should.equal("arn:aws:iam::123456789012:policy/TestCreatePolicy")
@mock_iam
def test_delete_policy():
conn = boto3.client('iam', region_name='us-east-1')
response = conn.create_policy(PolicyName="TestCreatePolicy", PolicyDocument=MOCK_POLICY)
[pol['PolicyName'] for pol in conn.list_policies(Scope='Local')['Policies']].should.equal(['TestCreatePolicy'])
conn.delete_policy(PolicyArn=response['Policy']['Arn'])
assert conn.list_policies(Scope='Local')['Policies'].should.be.empty
@mock_iam
def test_create_policy_versions():
conn = boto3.client('iam', region_name='us-east-1')
@ -713,7 +722,7 @@ def test_mfa_devices():
@mock_iam_deprecated()
def test_delete_user():
def test_delete_user_deprecated():
conn = boto.connect_iam()
with assert_raises(BotoServerError):
conn.delete_user('my-user')
@ -721,6 +730,17 @@ def test_delete_user():
conn.delete_user('my-user')
@mock_iam()
def test_delete_user():
conn = boto3.client('iam', region_name='us-east-1')
with assert_raises(ClientError):
conn.delete_user(UserName='my-user')
conn.create_user(UserName='my-user')
[user['UserName'] for user in conn.list_users()['Users']].should.equal(['my-user'])
conn.delete_user(UserName='my-user')
assert conn.list_users()['Users'].should.be.empty
@mock_iam_deprecated()
def test_generate_credential_report():
conn = boto.connect_iam()