Mitch Garnaat

Handle paginated results for roles. Fixes #17.

...@@ -52,7 +52,7 @@ class Policy(object): ...@@ -52,7 +52,7 @@ class Policy(object):
52 return self._arn 52 return self._arn
53 53
54 def _find_all_policies(self): 54 def _find_all_policies(self):
55 - # boto3 does not currently do pagination for ListPolicies 55 + # boto3 does not currently do pagination
56 # so we have to do it ourselves 56 # so we have to do it ourselves
57 policies = [] 57 policies = []
58 try: 58 try:
......
...@@ -59,15 +59,26 @@ class Role(object): ...@@ -59,15 +59,26 @@ class Role(object):
59 LOG.debug('Unable to find ARN for role: %s', self.name) 59 LOG.debug('Unable to find ARN for role: %s', self.name)
60 return self._arn 60 return self._arn
61 61
62 - def exists(self): 62 + def _find_all_roles(self):
63 + # boto3 does not currently do pagination
64 + # so we have to do it ourselves
65 + roles = []
63 try: 66 try:
64 - response = self._iam_svc.list_roles(PathPrefix=self.Path) 67 + response = self._iam_svc.list_roles()
65 - LOG.debug(response) 68 + roles += response['Roles']
66 - for role in response['Roles']: 69 + while response['IsTruncated']:
67 - if role['RoleName'] == self.name: 70 + LOG.debug('getting another page of roles')
68 - return role 71 + response = self._iam_svc.list_roles(
72 + Marker=response['Marker'])
73 + roles += response['Roles']
69 except Exception: 74 except Exception:
70 LOG.exception('Error listing roles') 75 LOG.exception('Error listing roles')
76 + return roles
77 +
78 + def exists(self):
79 + for role in self._find_all_roles():
80 + if role['RoleName'] == self.name:
81 + return role
71 return None 82 return None
72 83
73 def create(self): 84 def create(self):
......