From 3baef6b396fe2641e7d5ef8ae243327eb839585b Mon Sep 17 00:00:00 2001 From: Dan Malloy <91972154+dnmll@users.noreply.github.com> Date: Tue, 17 Oct 2023 07:48:01 -0700 Subject: [PATCH] Feature user add paginator (#645) --- cid/common.py | 1 + cid/helpers/quicksight/__init__.py | 19 ++++++++++++++++++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/cid/common.py b/cid/common.py index 725c4981..aa81df6e 100644 --- a/cid/common.py +++ b/cid/common.py @@ -825,6 +825,7 @@ def _share(self, dashboard_id, **kwargs): template_filename = 'data/permissions/dashboard_permissions_namespace.json' elif share_method == 'user': template_filename = 'data/permissions/dashboard_permissions.json' + print('Fetching QuickSight users. Duration will scale with the number of users.') user = self.qs.select_user() while not user: user_name = get_parameter( diff --git a/cid/helpers/quicksight/__init__.py b/cid/helpers/quicksight/__init__.py index 90303e5a..40f3f240 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