Add update_access_key endpoint (#1423)
This commit is contained in:
parent
56ce26a728
commit
350cf9257e
@ -349,6 +349,14 @@ class User(BaseModel):
|
|||||||
raise IAMNotFoundException(
|
raise IAMNotFoundException(
|
||||||
"Key {0} not found".format(access_key_id))
|
"Key {0} not found".format(access_key_id))
|
||||||
|
|
||||||
|
def update_access_key(self, access_key_id, status):
|
||||||
|
for key in self.access_keys:
|
||||||
|
if key.access_key_id == access_key_id:
|
||||||
|
key.status = status
|
||||||
|
break
|
||||||
|
else:
|
||||||
|
raise IAMNotFoundException("The Access Key with id {0} cannot be found".format(access_key_id))
|
||||||
|
|
||||||
def get_cfn_attribute(self, attribute_name):
|
def get_cfn_attribute(self, attribute_name):
|
||||||
from moto.cloudformation.exceptions import UnformattedGetAttTemplateException
|
from moto.cloudformation.exceptions import UnformattedGetAttTemplateException
|
||||||
if attribute_name == 'Arn':
|
if attribute_name == 'Arn':
|
||||||
@ -817,6 +825,10 @@ class IAMBackend(BaseBackend):
|
|||||||
key = user.create_access_key()
|
key = user.create_access_key()
|
||||||
return key
|
return key
|
||||||
|
|
||||||
|
def update_access_key(self, user_name, access_key_id, status):
|
||||||
|
user = self.get_user(user_name)
|
||||||
|
user.update_access_key(access_key_id, status)
|
||||||
|
|
||||||
def get_all_access_keys(self, user_name, marker=None, max_items=None):
|
def get_all_access_keys(self, user_name, marker=None, max_items=None):
|
||||||
user = self.get_user(user_name)
|
user = self.get_user(user_name)
|
||||||
keys = user.get_all_access_keys()
|
keys = user.get_all_access_keys()
|
||||||
|
@ -440,6 +440,14 @@ class IamResponse(BaseResponse):
|
|||||||
template = self.response_template(CREATE_ACCESS_KEY_TEMPLATE)
|
template = self.response_template(CREATE_ACCESS_KEY_TEMPLATE)
|
||||||
return template.render(key=key)
|
return template.render(key=key)
|
||||||
|
|
||||||
|
def update_access_key(self):
|
||||||
|
user_name = self._get_param('UserName')
|
||||||
|
access_key_id = self._get_param('AccessKeyId')
|
||||||
|
status = self._get_param('Status')
|
||||||
|
iam_backend.update_access_key(user_name, access_key_id, status)
|
||||||
|
template = self.response_template(GENERIC_EMPTY_TEMPLATE)
|
||||||
|
return template.render(name='UpdateAccessKey')
|
||||||
|
|
||||||
def list_access_keys(self):
|
def list_access_keys(self):
|
||||||
user_name = self._get_param('UserName')
|
user_name = self._get_param('UserName')
|
||||||
|
|
||||||
|
@ -651,3 +651,21 @@ def test_attach_detach_user_policy():
|
|||||||
|
|
||||||
resp = client.list_attached_user_policies(UserName=user.name)
|
resp = client.list_attached_user_policies(UserName=user.name)
|
||||||
resp['AttachedPolicies'].should.have.length_of(0)
|
resp['AttachedPolicies'].should.have.length_of(0)
|
||||||
|
|
||||||
|
|
||||||
|
@mock_iam
|
||||||
|
def test_update_access_key():
|
||||||
|
iam = boto3.resource('iam', region_name='us-east-1')
|
||||||
|
client = iam.meta.client
|
||||||
|
username = 'test-user'
|
||||||
|
iam.create_user(UserName=username)
|
||||||
|
with assert_raises(ClientError):
|
||||||
|
client.update_access_key(UserName=username,
|
||||||
|
AccessKeyId='non-existent-key',
|
||||||
|
Status='Inactive')
|
||||||
|
key = client.create_access_key(UserName=username)['AccessKey']
|
||||||
|
client.update_access_key(UserName=username,
|
||||||
|
AccessKeyId=key['AccessKeyId'],
|
||||||
|
Status='Inactive')
|
||||||
|
resp = client.list_access_keys(UserName=username)
|
||||||
|
resp['AccessKeyMetadata'][0]['Status'].should.equal('Inactive')
|
||||||
|
Loading…
Reference in New Issue
Block a user