Remove dependency on API key id in outputs section

This commit is contained in:
Philipp Muens 2016-09-22 11:40:45 +02:00
parent a5dcee1cad
commit 40da6be2b2
4 changed files with 12 additions and 55 deletions

View File

@ -38,21 +38,6 @@ module.exports = {
_.merge(this.serverless.service.provider.compiledCloudFormationTemplate.Resources,
newApiKeyObject);
// Add Id of API Key to Outputs section (Note: This is the Id, not the value!)
const newOutput = {
Description: `Id of API key "${apiKey}"`,
Value: {
Ref: `ApiGatewayApiKey${apiKeyNumber}`,
},
};
const newOutputObject = {
[`ApiGatewayApiKey${apiKeyNumber}Value`]: newOutput,
};
_.merge(this.serverless.service.provider.compiledCloudFormationTemplate.Outputs,
newOutputObject);
});
}

View File

@ -82,20 +82,6 @@ describe('#compileApiKeys()', () => {
})
);
it('should add api keys cf output template', () => awsCompileApigEvents
.compileApiKeys().then(() => {
expect(
awsCompileApigEvents.serverless.service.provider.compiledCloudFormationTemplate
.Outputs.ApiGatewayApiKey1Value.Description
).to.equal('Id of API key "1234567890"');
expect(
awsCompileApigEvents.serverless.service.provider.compiledCloudFormationTemplate
.Outputs.ApiGatewayApiKey1Value.Value.Ref
).to.equal('ApiGatewayApiKey1');
})
);
it('throw error if apiKey property is not an array', () => {
awsCompileApigEvents.serverless.service.provider.apiKeys = 2;
expect(() => awsCompileApigEvents.compileApiKeys()).to.throw(Error);

View File

@ -106,30 +106,22 @@ class AwsInfo {
}
getApiKeyValues(gatheredData) {
const outputs = gatheredData.outputs;
const info = gatheredData.info;
// check if there are API key outputs in the stacks Outputs section
let apiKeyOutputs;
if (outputs) {
apiKeyOutputs = outputs.filter((output) => output.OutputKey.match(/^ApiGatewayApiKey/));
}
// check if the user has set api keys
const apiKeyNames = this.serverless.service.provider.apiKeys || [];
if (apiKeyOutputs.length) {
if (apiKeyNames.length) {
return this.sdk.request('APIGateway',
'getApiKeys',
{ includeValues: true },
this.options.stage,
this.options.region
).then((apiKeys) => {
const items = apiKeys.items;
).then((allApiKeys) => {
const items = allApiKeys.items;
if (items) {
// extract the ids from the API key object
const apiKeyIds = [];
apiKeyOutputs.forEach((apiKeyOutput) => apiKeyIds.push(apiKeyOutput.OutputValue));
// filter out the API keys only created for this stack
const filteredItems = items.filter((item) => _.includes(apiKeyIds, item.id));
const filteredItems = items.filter((item) => _.includes(apiKeyNames, item.name));
// iterate over all apiKeys and push the API key info and update the info object
filteredItems.forEach((item) => {

View File

@ -255,19 +255,11 @@ describe('AwsInfo', () => {
// TODO: implement a pattern for stub restoring to get rid of this
awsInfo.sdk.request.restore();
// set the API Keys for the service
awsInfo.serverless.service.provider.apiKeys = ['foo', 'bar'];
const gatheredData = {
outputs: [
{
OutputKey: 'ApiGatewayApiKey1Value',
OutputValue: '1234',
Description: 'Id for API key "foo"',
},
{
OutputKey: 'ApiGatewayApiKey2Value',
OutputValue: '5678',
Description: 'Id for API key "bar"',
},
],
outputs: [],
info: {
apiKeys: [],
},
@ -315,6 +307,8 @@ describe('AwsInfo', () => {
});
it('should resolve with the passed-in data if no API key retrieval is necessary', () => {
awsInfo.serverless.service.provider.apiKeys = null;
const gatheredData = {
outputs: [],
info: {