From a905d103711d0ddadd6b0a0a9be85dada7fbb6a9 Mon Sep 17 00:00:00 2001 From: Dan Malloy Date: Wed, 11 Oct 2023 23:57:35 -0700 Subject: [PATCH] Added pagination support and sorted the user list --- cid/helpers/quicksight/__init__.py | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/cid/helpers/quicksight/__init__.py b/cid/helpers/quicksight/__init__.py index ac8dd19b..fb1325c5 100644 --- a/cid/helpers/quicksight/__init__.py +++ b/cid/helpers/quicksight/__init__.py @@ -648,8 +648,25 @@ def select_dashboard(self, force=False) -> str: def select_user(self): """ Select a user from the list of users """ + all_users = [] + next_token = None try: - user_list = self.identityClient.list_users(AwsAccountId=self.account_id, Namespace='default').get('UserList') + while True: + if next_token: + response = self.identityClient.list_users(AwsAccountId=self.account_id, Namespace='default', NextToken=next_token) + else: + response = self.identityClient.list_users(AwsAccountId=self.account_id, Namespace='default') + + user_list = response.get('UserList', []) + all_users.extend(user_list) + + next_token = response.get('NextToken') + if not next_token: + break + + # Sort the users by UserName + user_list = sorted(all_users, key=lambda x: x.get('UserName')) + except self.client.exceptions.AccessDeniedException as exc: raise CidCritical('AccessDenied for listing users, your can explicitly provide --quicksight-user parameter') from exc