Skip to content

Commit

Permalink
fix(group-list): fix issue with pagination logic for listing google g… (
Browse files Browse the repository at this point in the history
#75)

* fix(group-list): fix issue with pagination logic for listing google groups

* fix(groups): regression test, fix pagination logic

* chore(refactor): use .get instead of explicit check
  • Loading branch information
Avantol13 authored Oct 3, 2019
1 parent 45ad662 commit 65c7e1d
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 25 deletions.
45 changes: 21 additions & 24 deletions cirrus/google_cloud/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -747,12 +747,11 @@ def get_all_service_accounts(self):
response = self._authed_request("GET", api_url).json()
all_service_accounts.extend(response["accounts"])

if "nextPageToken" in response:
while response["nextPageToken"]:
response = self._authed_request(
"GET", api_url + "&pageToken=" + response["nextPageToken"]
).json()
all_service_accounts.extend(response["accounts"])
while response.get("nextPageToken"):
response = self._authed_request(
"GET", api_url + "&pageToken=" + response["nextPageToken"]
).json()
all_service_accounts.extend(response["accounts"])

return all_service_accounts

Expand Down Expand Up @@ -1306,17 +1305,16 @@ def get_all_groups(self):
)
all_groups.extend(response["groups"])

if "nextPageToken" in response:
while response["nextPageToken"]:
response = (
self._admin_service.groups()
.list(
pageToken=response["nextPageToken"],
domain=config.GOOGLE_IDENTITY_DOMAIN,
)
.execute()
while response.get("nextPageToken"):
response = (
self._admin_service.groups()
.list(
pageToken=response["nextPageToken"],
domain=config.GOOGLE_IDENTITY_DOMAIN,
)
all_groups.extend(response["groups"])
.execute()
)
all_groups.extend(response["groups"])

return all_groups

Expand Down Expand Up @@ -1596,14 +1594,13 @@ def get_group_members(self, group_id):
response = self._admin_service.members().list(groupKey=group_id).execute()
all_members.extend(response.get("members", []))

if "nextPageToken" in response:
while response["nextPageToken"]:
response = (
self._admin_service.members()
.list(pageToken=response["nextPageToken"], groupKey=group_id)
.execute()
)
all_members.extend(response.get("members", []))
while response.get("nextPageToken"):
response = (
self._admin_service.members()
.list(pageToken=response["nextPageToken"], groupKey=group_id)
.execute()
)
all_members.extend(response.get("members", []))

return all_members

Expand Down
2 changes: 1 addition & 1 deletion test/test_google_cloud_manage.py
Original file line number Diff line number Diff line change
Expand Up @@ -742,7 +742,7 @@ def test_get_group_members_pagination(test_cloud_manager):
response_2 = copy.deepcopy(full_response)
response_2["members"][0]["id"] = member_3_id
response_2["members"][1]["id"] = member_4_id
response_2["nextPageToken"] = ""
del response_2["nextPageToken"]

two_pages = [full_response, response_2]

Expand Down

0 comments on commit 65c7e1d

Please sign in to comment.