Skip to content

Commit

Permalink
Fetch all usage plan pages in catalog updater
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Chew committed Jun 25, 2019
1 parent c447bfc commit 5bf6b1c
Showing 1 changed file with 24 additions and 5 deletions.
29 changes: 24 additions & 5 deletions lambdas/catalog-updater/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,26 @@ function copyAnyMethod(api) {
return api
}

/** Fetches all usage plans, combining all pages into a single array. */
async function getAllUsagePlans() {
// The maximum allowed value of `limit` is 500 according to
// https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/APIGateway.html#getUsagePlans-property
const defaultParams = {limit: 500}

console.log('Fetching first page of usage plans')
let response = await exports.gateway.getUsagePlans(defaultParams).promise()
const usagePlans = response.items

while (response.position) {
console.log(`Fetching next page of usage plans, at position=[${response.position}]`)
const nextParams = {...defaultParams, position: response.position}
response = await exports.gateway.getUsagePlans(nextParams).promise()
usagePlans.push(...response.items)
}

return usagePlans
}

function buildCatalog(swaggerFiles, sdkGeneration) {
console.log(`results: ${JSON.stringify(swaggerFiles, null, 4)}`)
console.log(sdkGeneration)
Expand All @@ -185,10 +205,9 @@ function buildCatalog(swaggerFiles, sdkGeneration) {
generic: []
}

return exports.gateway.getUsagePlans({}).promise()
.then((result) => {
console.log(`usagePlans: ${JSON.stringify(result.items, null, 4)}`)
let usagePlans = result.items
return getAllUsagePlans()
.then(usagePlans => {
console.log(`usagePlans: ${JSON.stringify(usagePlans, null, 4)}`)
for (let i = 0; i < usagePlans.length; i++) {
catalog.apiGateway[i] = usagePlanToCatalogObject(usagePlans[i], swaggerFiles, sdkGeneration)
}
Expand Down Expand Up @@ -252,4 +271,4 @@ exports = module.exports = {
gateway: new AWS.APIGateway(),
handler,
hash
}
}

0 comments on commit 5bf6b1c

Please sign in to comment.