Skip to content

Commit e09bfd5

Browse files
authored
Merge pull request #465 from NHSDigital/get-api-pagination
Get API request pagination
2 parents 0150551 + 54232c0 commit e09bfd5

2 files changed

Lines changed: 24 additions & 6 deletions

File tree

  • ansible/collections/ansible_collections/nhsd/apigee

ansible/collections/ansible_collections/nhsd/apigee/plugins/module_utils/utils.py

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -98,13 +98,31 @@ def get_all_apidocs(organization, access_token, task_vars=None, refresh=False):
9898
"""
9999
if task_vars is None:
100100
task_vars = {}
101+
101102
apidocs = task_vars.get("APIGEE_APIDOCS")
103+
102104
if refresh or not apidocs:
103-
apidocs_request = get(constants.portal_uri(organization), access_token)
104-
if apidocs_request.get("failed"):
105-
return apidocs_request
106-
apidocs = apidocs_request["response"]["body"]["data"]
107-
task_vars.update({"APIGEE_APIDOCS": apidocs})
105+
all_results = []
106+
107+
params = {
108+
"pageSize" : 100
109+
}
110+
scan = True
111+
112+
while scan:
113+
apidocs_request = get(constants.portal_uri(organization), access_token, params=params)
114+
if apidocs_request.get("failed"):
115+
return apidocs_request
116+
117+
next_page_token = apidocs_request["response"]["body"]["next_page_token"]
118+
all_results += apidocs_request["response"]["body"]["data"]
119+
120+
if next_page_token != "":
121+
params["pageToken"] = next_page_token
122+
else:
123+
scan = False
124+
125+
task_vars.update({"APIGEE_APIDOCS": all_results})
108126
return task_vars
109127

110128

ansible/collections/ansible_collections/nhsd/apigee/roles/deploy_manifest/tasks/main.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,4 +72,4 @@
7272
# See comment on product loop control. (I believe APIDocs
7373
# actually can reference products that don't exist. But this is
7474
# cleaner.)
75-
when: item.edgeAPIProductName | regex_search('^' + SERVICE_NAME + '-' + PULL_REQUEST | default(APIGEE_ENVIRONMENT))
75+
when: APIGEE_ORGANIZATION == 'nhsd-prod' and item.edgeAPIProductName | regex_search('^' + SERVICE_NAME + '-' + PULL_REQUEST | default(APIGEE_ENVIRONMENT))

0 commit comments

Comments
 (0)