Merge pull request #2727 from titibike/master
Add 'Filter' parameter for cognito-idp function 'list_users()'
This commit is contained in:
commit
2f1e47b53e
@ -279,9 +279,18 @@ class CognitoIdpResponse(BaseResponse):
|
|||||||
user_pool_id = self._get_param("UserPoolId")
|
user_pool_id = self._get_param("UserPoolId")
|
||||||
limit = self._get_param("Limit")
|
limit = self._get_param("Limit")
|
||||||
token = self._get_param("PaginationToken")
|
token = self._get_param("PaginationToken")
|
||||||
|
filt = self._get_param("Filter")
|
||||||
users, token = cognitoidp_backends[self.region].list_users(
|
users, token = cognitoidp_backends[self.region].list_users(
|
||||||
user_pool_id, limit=limit, pagination_token=token
|
user_pool_id, limit=limit, pagination_token=token
|
||||||
)
|
)
|
||||||
|
if filt:
|
||||||
|
name, value = filt.replace('"', "").split("=")
|
||||||
|
users = [
|
||||||
|
user
|
||||||
|
for user in users
|
||||||
|
for attribute in user.attributes
|
||||||
|
if attribute["Name"] == name and attribute["Value"] == value
|
||||||
|
]
|
||||||
response = {"Users": [user.to_json(extended=True) for user in users]}
|
response = {"Users": [user.to_json(extended=True) for user in users]}
|
||||||
if token:
|
if token:
|
||||||
response["PaginationToken"] = str(token)
|
response["PaginationToken"] = str(token)
|
||||||
|
@ -958,6 +958,18 @@ def test_list_users():
|
|||||||
result["Users"].should.have.length_of(1)
|
result["Users"].should.have.length_of(1)
|
||||||
result["Users"][0]["Username"].should.equal(username)
|
result["Users"][0]["Username"].should.equal(username)
|
||||||
|
|
||||||
|
username_bis = str(uuid.uuid4())
|
||||||
|
conn.admin_create_user(
|
||||||
|
UserPoolId=user_pool_id,
|
||||||
|
Username=username_bis,
|
||||||
|
UserAttributes=[{"Name": "phone_number", "Value": "+33666666666"}],
|
||||||
|
)
|
||||||
|
result = conn.list_users(
|
||||||
|
UserPoolId=user_pool_id, Filter='phone_number="+33666666666'
|
||||||
|
)
|
||||||
|
result["Users"].should.have.length_of(1)
|
||||||
|
result["Users"][0]["Username"].should.equal(username_bis)
|
||||||
|
|
||||||
|
|
||||||
@mock_cognitoidp
|
@mock_cognitoidp
|
||||||
def test_list_users_returns_limit_items():
|
def test_list_users_returns_limit_items():
|
||||||
|
Loading…
Reference in New Issue
Block a user