GetUser returns the IAM user who owns the access key in the request.
This commit is contained in:
parent
7db2d0f38c
commit
1b8179992e
@ -1248,5 +1248,13 @@ class IAMBackend(BaseBackend):
|
||||
return saml_provider
|
||||
raise IAMNotFoundException("SamlProvider {0} not found".format(saml_provider_arn))
|
||||
|
||||
def get_user_from_access_key_id(self, access_key_id):
|
||||
for user_name, user in self.users.items():
|
||||
access_keys = self.get_all_access_keys(user_name)
|
||||
for access_key in access_keys:
|
||||
if access_key.access_key_id == access_key_id:
|
||||
return user
|
||||
return None
|
||||
|
||||
|
||||
iam_backend = IAMBackend()
|
||||
|
@ -1,9 +1,8 @@
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from moto.core.responses import BaseResponse
|
||||
from .models import iam_backend
|
||||
|
||||
AVATAO_USER_NAME = "avatao-user"
|
||||
from .models import iam_backend, User
|
||||
|
||||
|
||||
class IamResponse(BaseResponse):
|
||||
@ -428,9 +427,12 @@ class IamResponse(BaseResponse):
|
||||
def get_user(self):
|
||||
user_name = self._get_param('UserName')
|
||||
if not user_name:
|
||||
user_name = AVATAO_USER_NAME
|
||||
# If no user is specified, IAM returns the current user
|
||||
user = iam_backend.get_user(user_name)
|
||||
access_key_id = self.get_current_user()
|
||||
user = iam_backend.get_user_from_access_key_id(access_key_id)
|
||||
if user is None:
|
||||
user = User("default_user")
|
||||
else:
|
||||
user = iam_backend.get_user(user_name)
|
||||
|
||||
template = self.response_template(USER_TEMPLATE)
|
||||
return template.render(action='Get', user=user)
|
||||
|
Loading…
Reference in New Issue
Block a user