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
|
return saml_provider
|
||||||
raise IAMNotFoundException("SamlProvider {0} not found".format(saml_provider_arn))
|
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()
|
iam_backend = IAMBackend()
|
||||||
|
@ -1,9 +1,8 @@
|
|||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
from moto.core.responses import BaseResponse
|
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):
|
class IamResponse(BaseResponse):
|
||||||
@ -428,9 +427,12 @@ class IamResponse(BaseResponse):
|
|||||||
def get_user(self):
|
def get_user(self):
|
||||||
user_name = self._get_param('UserName')
|
user_name = self._get_param('UserName')
|
||||||
if not user_name:
|
if not user_name:
|
||||||
user_name = AVATAO_USER_NAME
|
access_key_id = self.get_current_user()
|
||||||
# If no user is specified, IAM returns the current user
|
user = iam_backend.get_user_from_access_key_id(access_key_id)
|
||||||
user = iam_backend.get_user(user_name)
|
if user is None:
|
||||||
|
user = User("default_user")
|
||||||
|
else:
|
||||||
|
user = iam_backend.get_user(user_name)
|
||||||
|
|
||||||
template = self.response_template(USER_TEMPLATE)
|
template = self.response_template(USER_TEMPLATE)
|
||||||
return template.render(action='Get', user=user)
|
return template.render(action='Get', user=user)
|
||||||
|
Loading…
Reference in New Issue
Block a user