Merge pull request #669 from netors/feature/implement-iam-list-users-for-boto3
implemented iam list users (Closes #668)
This commit is contained in:
commit
ea319698aa
@ -368,6 +368,15 @@ class IAMBackend(BaseBackend):
|
||||
|
||||
return user
|
||||
|
||||
def list_users(self, path_prefix, marker, max_items):
|
||||
users = None
|
||||
try:
|
||||
users = self.users
|
||||
except KeyError:
|
||||
raise IAMNotFoundException("Users {0}, {1}, {2} not found".format(path_prefix, marker, max_items))
|
||||
|
||||
return users
|
||||
|
||||
def create_login_profile(self, user_name, password):
|
||||
# This does not currently deal with PasswordPolicyViolation.
|
||||
user = self.get_user(user_name)
|
||||
|
@ -165,6 +165,14 @@ class IamResponse(BaseResponse):
|
||||
template = self.response_template(USER_TEMPLATE)
|
||||
return template.render(action='Get', user=user)
|
||||
|
||||
def list_users(self):
|
||||
path_prefix = self._get_param('PathPrefix')
|
||||
marker = self._get_param('Marker')
|
||||
max_items = self._get_param('MaxItems')
|
||||
user = iam_backend.list_users(path_prefix, marker, max_items)
|
||||
template = self.response_template(LIST_USERS_TEMPLATE)
|
||||
return template.render(action='List', user=user)
|
||||
|
||||
def create_login_profile(self):
|
||||
user_name = self._get_param('UserName')
|
||||
password = self._get_param('Password')
|
||||
@ -592,6 +600,24 @@ USER_TEMPLATE = """<{{ action }}UserResponse>
|
||||
</ResponseMetadata>
|
||||
</{{ action }}UserResponse>"""
|
||||
|
||||
LIST_USERS_TEMPLATE = """<{{ action }}UsersResponse>
|
||||
<{{ action }}UsersResult>
|
||||
<Users>
|
||||
{% for user in users %}
|
||||
<member>
|
||||
<UserId>{{ user.id }}</UserId>
|
||||
<Path>{{ user.path }}</Path>
|
||||
<UserName>{{ user.name }}</UserName>
|
||||
<Arn>arn:aws:iam::123456789012:user/{{ user.path }}/{{ user.name }}</Arn>
|
||||
</member>
|
||||
{% endfor %}
|
||||
</Users>
|
||||
</{{ action }}UsersResult>
|
||||
<ResponseMetadata>
|
||||
<RequestId>7a62c49f-347e-4fc4-9331-6e8eEXAMPLE</RequestId>
|
||||
</ResponseMetadata>
|
||||
</{{ action }}UsersResponse>"""
|
||||
|
||||
CREATE_LOGIN_PROFILE_TEMPLATE = """
|
||||
<CreateLoginProfileResponse>
|
||||
<CreateUserResult>
|
||||
|
@ -1,5 +1,6 @@
|
||||
from __future__ import unicode_literals
|
||||
import boto
|
||||
import boto3
|
||||
import sure # noqa
|
||||
|
||||
from nose.tools import assert_raises, assert_equals, assert_not_equals
|
||||
@ -183,6 +184,18 @@ def test_get_user():
|
||||
conn.create_user('my-user')
|
||||
conn.get_user('my-user')
|
||||
|
||||
@mock_iam()
|
||||
def test_list_users():
|
||||
path_prefix = '/'
|
||||
max_items = 10
|
||||
conn = boto3.client('iam')
|
||||
conn.create_user(UserName='my-user')
|
||||
response = conn.list_users(PathPrefix=path_prefix, MaxItems=max_items)
|
||||
assert_equals(
|
||||
response['Users'],
|
||||
[]
|
||||
)
|
||||
|
||||
|
||||
@mock_iam()
|
||||
def test_create_login_profile():
|
||||
|
Loading…
Reference in New Issue
Block a user