UNPKG

serverless

Version:

Serverless Framework - Build web, mobile and IoT applications with serverless architectures using AWS Lambda, Azure Functions, Google CloudFunctions & more

106 lines (89 loc) 3.51 kB
'use strict'; /* eslint-disable global-require */ const BbPromise = require('bluebird'); const validate = require('./lib/validate'); const compileRestApi = require('./lib/restApi'); const compileApiKeys = require('./lib/apiKeys'); const compileUsagePlan = require('./lib/usagePlan'); const compileUsagePlanKeys = require('./lib/usagePlanKeys'); const compileResources = require('./lib/resources'); const compileCors = require('./lib/cors'); const compileMethods = require('./lib/method/index'); const compileAuthorizers = require('./lib/authorizers'); const compileDeployment = require('./lib/deployment'); const compilePermissions = require('./lib/permissions'); const compileStage = require('./lib/stage'); const getMethodAuthorization = require('./lib/method/authorization'); const getMethodIntegration = require('./lib/method/integration'); const getMethodResponses = require('./lib/method/responses'); class AwsCompileApigEvents { constructor(serverless, options) { this.serverless = serverless; this.options = options; this.provider = this.serverless.getProvider('aws'); this.serverless.configSchemaHandler.defineFunctionEvent('aws', 'http', { // TODO: Complete schema, see https://github.com/serverless/serverless/issues/8018 anyOf: [{ type: 'string' }, { type: 'object' }], }); // used for the generated method logical ids (GET, PATCH, PUT, DELETE, OPTIONS, ...) this.apiGatewayMethodLogicalIds = []; Object.assign( this, validate, compileRestApi, compileApiKeys, compileUsagePlan, compileUsagePlanKeys, compileResources, compileCors, compileMethods, compileAuthorizers, compileDeployment, compilePermissions, compileStage, getMethodAuthorization, getMethodIntegration, getMethodResponses ); this.hooks = { 'package:compileEvents': () => { this.validated = this.validate(); if (this.validated.events.length === 0) { return BbPromise.resolve(); } return BbPromise.bind(this) .then(this.compileRestApi) .then(this.compileResources) .then(this.compileCors) .then(this.compileMethods) .then(this.compileAuthorizers) .then(this.compileDeployment) .then(this.compileApiKeys) .then(this.compileUsagePlan) .then(this.compileUsagePlanKeys) .then(this.compilePermissions) .then(this.compileStage); }, // TODO should be removed once AWS fixes the CloudFormation problems using a separate Stage 'after:deploy:deploy': () => { const getServiceState = require('../../../../lib/getServiceState').getServiceState; const state = getServiceState.call(this); const updateStage = require('./lib/hack/updateStage').updateStage; this.state = state; return updateStage.call(this); }, // TODO should be removed once AWS fixes the removal via CloudFormation 'before:remove:remove': () => { // eslint-disable-next-line no-shadow const validate = require('../../../../lib/validate').validate; // eslint-disable-next-line max-len const disassociateUsagePlan = require('./lib/hack/disassociateUsagePlan') .disassociateUsagePlan; return BbPromise.bind(this) .then(validate) .then(disassociateUsagePlan); }, }; } } module.exports = AwsCompileApigEvents;