Philipp Muens 1d631e0133 Add validateInput method
Add a validation step so that validation checks don't need to be rewritten in
each compile method / step.
2016-06-15 12:25:44 +02:00

36 lines
1.1 KiB
JavaScript

'use strict';
const merge = require('lodash').merge;
const BbPromise = require('bluebird');
module.exports = {
compileDeployment() {
this.serverless.service.getAllFunctions().forEach((functionName) => {
const functionObject = this.serverless.service.getFunction(functionName);
// checking all three levels in the obj tree
// to avoid "can't read property of undefined" error
if (functionObject.events && functionObject.events.aws
&& functionObject.events.aws.http_endpoint) {
const deploymentTemplate = `
{
"Type" : "AWS::ApiGateway::Deployment",
"Properties" : {
"RestApiId" : { "Ref": "${functionName}RestApiApigEvent" },
"StageName" : "${this.options.stage}"
}
}
`;
const newDeploymentObject = {
[`${functionName}DeploymentApigEvent`]: JSON.parse(deploymentTemplate),
};
merge(this.serverless.service.resources.aws.Resources, newDeploymentObject);
}
});
return BbPromise.resolve();
},
};