Skip to content

Commit

Permalink
Feature user add paginator (#645)
Browse files Browse the repository at this point in the history
  • Loading branch information
dnmll authored Oct 17, 2023
1 parent 954dff6 commit 3baef6b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
1 change: 1 addition & 0 deletions cid/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
19 changes: 18 additions & 1 deletion cid/helpers/quicksight/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 3baef6b

Please sign in to comment.