FIX : IAM - Added support for pathPrefix in list_users_function (#3180)
* FIX:IAM-Added support for pathPrefix in list_users_function * removed changes for roles * Added test for non decorator * changed filter function Co-authored-by: usmankb <usman@krazybee.com>
This commit is contained in:
parent
bc1674cb19
commit
1db42fb865
@ -946,6 +946,10 @@ class AccountSummary(BaseModel):
|
||||
return len(self._iam_backend.users)
|
||||
|
||||
|
||||
def filter_items_with_path_prefix(path_prefix, items):
|
||||
return [role for role in items if role.path.startswith(path_prefix)]
|
||||
|
||||
|
||||
class IAMBackend(BaseBackend):
|
||||
def __init__(self):
|
||||
self.instance_profiles = {}
|
||||
@ -1490,7 +1494,11 @@ class IAMBackend(BaseBackend):
|
||||
def list_users(self, path_prefix, marker, max_items):
|
||||
users = None
|
||||
try:
|
||||
|
||||
users = self.users.values()
|
||||
if path_prefix:
|
||||
users = filter_items_with_path_prefix(path_prefix, users)
|
||||
|
||||
except KeyError:
|
||||
raise IAMNotFoundException(
|
||||
"Users {0}, {1}, {2} not found".format(path_prefix, marker, max_items)
|
||||
|
@ -337,7 +337,6 @@ class IamResponse(BaseResponse):
|
||||
|
||||
def list_roles(self):
|
||||
roles = iam_backend.get_roles()
|
||||
|
||||
template = self.response_template(LIST_ROLES_TEMPLATE)
|
||||
return template.render(roles=roles)
|
||||
|
||||
|
@ -762,6 +762,12 @@ def test_list_users():
|
||||
user["Path"].should.equal("/")
|
||||
user["Arn"].should.equal("arn:aws:iam::{}:user/my-user".format(ACCOUNT_ID))
|
||||
|
||||
conn.create_user(UserName="my-user-1", Path="myUser")
|
||||
response = conn.list_users(PathPrefix="my")
|
||||
user = response["Users"][0]
|
||||
user["UserName"].should.equal("my-user-1")
|
||||
user["Path"].should.equal("myUser")
|
||||
|
||||
|
||||
@mock_iam()
|
||||
def test_user_policies():
|
||||
|
Loading…
Reference in New Issue
Block a user