mirror of
https://github.com/serverless/serverless.git
synced 2026-01-18 14:58:43 +00:00
47 lines
1.3 KiB
JavaScript
47 lines
1.3 KiB
JavaScript
'use strict';
|
|
|
|
const _ = require('lodash');
|
|
const BbPromise = require('bluebird');
|
|
|
|
module.exports = {
|
|
compileApiKeys() {
|
|
if (this.serverless.service.provider.apiKeys) {
|
|
if (this.serverless.service.provider.apiKeys.constructor !== Array) {
|
|
throw new this.serverless.classes.Error('apiKeys property must be an array');
|
|
}
|
|
|
|
let apiKeyNumber = 0;
|
|
this.serverless.service.provider.apiKeys.forEach(apiKey => {
|
|
apiKeyNumber++;
|
|
if (typeof apiKey !== 'string') {
|
|
throw new this.serverless.classes.Error('API Keys must be strings');
|
|
}
|
|
|
|
const apiKeysTemplate = `
|
|
{
|
|
"Type" : "AWS::ApiGateway::ApiKey",
|
|
"Properties" : {
|
|
"Enabled" : true,
|
|
"Name" : "${apiKey}",
|
|
"StageKeys" : [{
|
|
"RestApiId": { "Ref": "ApiGatewayRestApi" },
|
|
"StageName": "${this.options.stage}"
|
|
}]
|
|
},
|
|
"DependsOn": "${this.apiGateWayDeploymentLogicalId}"
|
|
}
|
|
`;
|
|
|
|
const newApiKeyObject = {
|
|
[`ApiGatewayApiKey${apiKeyNumber}`]: JSON.parse(apiKeysTemplate),
|
|
};
|
|
|
|
_.merge(this.serverless.service.provider.compiledCloudFormationTemplate.Resources,
|
|
newApiKeyObject);
|
|
});
|
|
}
|
|
|
|
return BbPromise.resolve();
|
|
},
|
|
};
|