Add support for iam update_user
This covers both the NewPath and NewUserName parameters for update_user, but without regex validation for these values.
This commit is contained in:
parent
64152f4cda
commit
d53626ad9a
@ -2334,7 +2334,7 @@
|
||||
- [ ] update_service_specific_credential
|
||||
- [X] update_signing_certificate
|
||||
- [ ] update_ssh_public_key
|
||||
- [ ] update_user
|
||||
- [X] update_user
|
||||
- [X] upload_server_certificate
|
||||
- [X] upload_signing_certificate
|
||||
- [ ] upload_ssh_public_key
|
||||
|
@ -892,6 +892,18 @@ class IAMBackend(BaseBackend):
|
||||
|
||||
return users
|
||||
|
||||
def update_user(self, user_name, new_path=None, new_user_name=None):
|
||||
try:
|
||||
user = self.users[user_name]
|
||||
except KeyError:
|
||||
raise IAMNotFoundException("User {0} not found".format(user_name))
|
||||
|
||||
if new_path:
|
||||
user.path = new_path
|
||||
if new_user_name:
|
||||
user.name = new_user_name
|
||||
self.users[new_user_name] = self.users.pop(user_name)
|
||||
|
||||
def list_roles(self, path_prefix, marker, max_items):
|
||||
roles = None
|
||||
try:
|
||||
|
@ -440,6 +440,18 @@ class IamResponse(BaseResponse):
|
||||
template = self.response_template(LIST_USERS_TEMPLATE)
|
||||
return template.render(action='List', users=users)
|
||||
|
||||
def update_user(self):
|
||||
user_name = self._get_param('UserName')
|
||||
new_path = self._get_param('NewPath')
|
||||
new_user_name = self._get_param('NewUserName')
|
||||
iam_backend.update_user(user_name, new_path, new_user_name)
|
||||
if new_user_name:
|
||||
user = iam_backend.get_user(new_user_name)
|
||||
else:
|
||||
user = iam_backend.get_user(user_name)
|
||||
template = self.response_template(USER_TEMPLATE)
|
||||
return template.render(action='Update', user=user)
|
||||
|
||||
def create_login_profile(self):
|
||||
user_name = self._get_param('UserName')
|
||||
password = self._get_param('Password')
|
||||
|
@ -401,6 +401,19 @@ def test_get_user():
|
||||
conn.get_user('my-user')
|
||||
|
||||
|
||||
@mock_iam()
|
||||
def test_update_user():
|
||||
conn = boto3.client('iam', region_name='us-east-1')
|
||||
with assert_raises(conn.exceptions.NoSuchEntityException):
|
||||
conn.update_user(UserName='my-user')
|
||||
conn.create_user(UserName='my-user')
|
||||
conn.update_user(UserName='my-user', NewPath='/new-path/', NewUserName='new-user')
|
||||
response = conn.get_user(UserName='new-user')
|
||||
response['User'].get('Path').should.equal('/new-path/')
|
||||
with assert_raises(conn.exceptions.NoSuchEntityException):
|
||||
conn.get_user(UserName='my-user')
|
||||
|
||||
|
||||
@mock_iam_deprecated()
|
||||
def test_get_current_user():
|
||||
"""If no user is specific, IAM returns the current user"""
|
||||
|
Loading…
Reference in New Issue
Block a user