diff --git a/cirrus/google_cloud/manager.py b/cirrus/google_cloud/manager.py index 747f4c6d..660afce9 100644 --- a/cirrus/google_cloud/manager.py +++ b/cirrus/google_cloud/manager.py @@ -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 @@ -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 @@ -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 diff --git a/test/test_google_cloud_manage.py b/test/test_google_cloud_manage.py index 697a5fa6..682ad5ed 100644 --- a/test/test_google_cloud_manage.py +++ b/test/test_google_cloud_manage.py @@ -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]