Skip to content

Commit

Permalink
Handle paginated results for roles. Fixes #17.
Browse files Browse the repository at this point in the history
  • Loading branch information
garnaat committed Jun 22, 2015
1 parent c2bb94b commit bbc712e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
2 changes: 1 addition & 1 deletion kappa/policy.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def arn(self):
return self._arn

def _find_all_policies(self):
# boto3 does not currently do pagination for ListPolicies
# boto3 does not currently do pagination
# so we have to do it ourselves
policies = []
try:
Expand Down
23 changes: 17 additions & 6 deletions kappa/role.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,26 @@ def arn(self):
LOG.debug('Unable to find ARN for role: %s', self.name)
return self._arn

def exists(self):
def _find_all_roles(self):
# boto3 does not currently do pagination
# so we have to do it ourselves
roles = []
try:
response = self._iam_svc.list_roles(PathPrefix=self.Path)
LOG.debug(response)
for role in response['Roles']:
if role['RoleName'] == self.name:
return role
response = self._iam_svc.list_roles()
roles += response['Roles']
while response['IsTruncated']:
LOG.debug('getting another page of roles')
response = self._iam_svc.list_roles(
Marker=response['Marker'])
roles += response['Roles']
except Exception:
LOG.exception('Error listing roles')
return roles

def exists(self):
for role in self._find_all_roles():
if role['RoleName'] == self.name:
return role
return None

def create(self):
Expand Down

0 comments on commit bbc712e

Please sign in to comment.