Skip to content

Commit

Permalink
#6 fetch should handle >100 resources (#7)
Browse files Browse the repository at this point in the history
* fetch should handle >100 resources

* lint fixes, update test

* lint fixes

* lint fixes

* Removed trailing commas because they cause istanbul to fail,
Change lint rule to allow trailing commas instead of requiring

* Lint fixes

* Fixed bug in test
  • Loading branch information
tloltman authored and rurri committed Jan 3, 2018
1 parent 96f45ec commit f0a5033
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 4 deletions.
1 change: 1 addition & 0 deletions .eslintrc.js
Expand Up @@ -4,6 +4,7 @@ module.exports = {
strict: 0, /* remove after Chrome supports strict mode in modules OR Babel is integrated */
'no-unused-vars': [2, { args: 'after-used', argsIgnorePattern: '^_' }],
'no-param-reassign': [2, { props: false }],
'comma-dangle': ['error', 'only-multiline'],
},
globals: {},
env: {
Expand Down
35 changes: 33 additions & 2 deletions index.js
Expand Up @@ -132,8 +132,39 @@ class ServerlessResourcesEnv {
fetchCFResources() {
const stackName = this.getStackName();
this.serverless.cli.log(`[serverless-resources-env] Looking up resources for CF Named: ${stackName}`);
return Promise.promisify(this.cloudFormation.describeStackResources.bind(this.cloudFormation))({
StackName: stackName,
return this.fetchCFResourcesPages(stackName, null, []);
}

/**
* Recursively look up the CF Resource pages for this stack from AWS
* and concatenate the resource pages
* @returns {Promise.<String>}
*/
fetchCFResourcesPages(stackName, nextToken, resourceSummaries) {
const self = this;
return new Promise((resolve, reject) => {
self.cloudFormation.listStackResources(
{ StackName: stackName, NextToken: nextToken },
(err, resourceResultPage) => {
if (err == null) {
if (resourceResultPage.NextToken == null) {
const results = resourceSummaries.concat(resourceResultPage.StackResourceSummaries);
self.serverless.cli.log(`[serverless-resources-env] Returned ${results.length} ResourceSummaries`);
resolve({ StackResources: results });
} else {
self.serverless.cli.log('[serverless-resources-env] Getting next Resources page');
const allSummaries =
resourceSummaries.concat(resourceResultPage.StackResourceSummaries);
resolve(self.fetchCFResourcesPages(
stackName,
resourceResultPage.NextToken,
allSummaries));
}
} else {
reject(err);
}
}
);
});
}

Expand Down
4 changes: 2 additions & 2 deletions test/plugin-test.js
Expand Up @@ -134,10 +134,10 @@ describe('serverless-fetch-stack-resource', () => {
{ LogicalResourceId: 'b', PhysicalResourceId: '2' },
{ LogicalResourceId: 'c', PhysicalResourceId: '3' },
];
instance.cloudFormation.describeStackResources =
instance.cloudFormation.listStackResources =
(params, callback) => {
callback(null, {
StackResources: resources,
StackResourceSummaries: resources,
});
};

Expand Down

0 comments on commit f0a5033

Please sign in to comment.