mirror of
https://github.com/serverless/serverless.git
synced 2026-01-18 14:58:43 +00:00
basic structure for apig event
This commit is contained in:
parent
618841ad3c
commit
6cd49bf117
41
lib/plugins/awsCompileApigEvents/awsCompileApigEvents.js
Normal file
41
lib/plugins/awsCompileApigEvents/awsCompileApigEvents.js
Normal file
@ -0,0 +1,41 @@
|
||||
'use strict';
|
||||
|
||||
const BbPromise = require('bluebird');
|
||||
|
||||
const compileRestApi = require('./lib/compileRestApi');
|
||||
const compileDeployment = require('./lib/compileDeployment');
|
||||
const compileStage = require('./lib/compileStage');
|
||||
const compileBasePathMapping = require('./lib/compileBasePathMapping');
|
||||
const compileResource = require('./lib/compileResource');
|
||||
const compileMethod = require('./lib/compileMethod');
|
||||
const compilePermission = require('./lib/compilePermission');
|
||||
|
||||
class AwsCompileApigEvents {
|
||||
constructor(serverless) {
|
||||
this.serverless = serverless;
|
||||
|
||||
Object.assign(
|
||||
this,
|
||||
compileRestApi,
|
||||
compileDeployment,
|
||||
compileStage,
|
||||
compileBasePathMapping,
|
||||
compileResource,
|
||||
compileMethod,
|
||||
compilePermission
|
||||
);
|
||||
|
||||
this.hooks = {
|
||||
'deploy:compileEvents': () => BbPromise.bind(this)
|
||||
.then(this.compileRestApi)
|
||||
.then(this.compileDeployment)
|
||||
.then(this.compileStage)
|
||||
.then(this.compileBasePathMapping)
|
||||
.then(this.compileResource)
|
||||
.then(this.compileMethod)
|
||||
.then(this.compilePermission),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = AwsCompileApigEvents;
|
||||
@ -0,0 +1,10 @@
|
||||
'use strict';
|
||||
|
||||
const BbPromise = require('bluebird');
|
||||
|
||||
module.exports = {
|
||||
compileStage() {
|
||||
|
||||
return BbPromise.resolve();
|
||||
},
|
||||
};
|
||||
10
lib/plugins/awsCompileApigEvents/lib/compileDeployment.js
Normal file
10
lib/plugins/awsCompileApigEvents/lib/compileDeployment.js
Normal file
@ -0,0 +1,10 @@
|
||||
'use strict';
|
||||
|
||||
const BbPromise = require('bluebird');
|
||||
|
||||
module.exports = {
|
||||
compileDeployment() {
|
||||
|
||||
return BbPromise.resolve();
|
||||
},
|
||||
};
|
||||
10
lib/plugins/awsCompileApigEvents/lib/compileMethod.js
Normal file
10
lib/plugins/awsCompileApigEvents/lib/compileMethod.js
Normal file
@ -0,0 +1,10 @@
|
||||
'use strict';
|
||||
|
||||
const BbPromise = require('bluebird');
|
||||
|
||||
module.exports = {
|
||||
compileMethod() {
|
||||
|
||||
return BbPromise.resolve();
|
||||
},
|
||||
};
|
||||
10
lib/plugins/awsCompileApigEvents/lib/compilePermission.js
Normal file
10
lib/plugins/awsCompileApigEvents/lib/compilePermission.js
Normal file
@ -0,0 +1,10 @@
|
||||
'use strict';
|
||||
|
||||
const BbPromise = require('bluebird');
|
||||
|
||||
module.exports = {
|
||||
compilePermission() {
|
||||
|
||||
return BbPromise.resolve();
|
||||
},
|
||||
};
|
||||
10
lib/plugins/awsCompileApigEvents/lib/compileResource.js
Normal file
10
lib/plugins/awsCompileApigEvents/lib/compileResource.js
Normal file
@ -0,0 +1,10 @@
|
||||
'use strict';
|
||||
|
||||
const BbPromise = require('bluebird');
|
||||
|
||||
module.exports = {
|
||||
compileResource() {
|
||||
|
||||
return BbPromise.resolve();
|
||||
},
|
||||
};
|
||||
10
lib/plugins/awsCompileApigEvents/lib/compileRestApi.js
Normal file
10
lib/plugins/awsCompileApigEvents/lib/compileRestApi.js
Normal file
@ -0,0 +1,10 @@
|
||||
'use strict';
|
||||
|
||||
const BbPromise = require('bluebird');
|
||||
|
||||
module.exports = {
|
||||
compileRestApi() {
|
||||
|
||||
return BbPromise.resolve();
|
||||
},
|
||||
};
|
||||
10
lib/plugins/awsCompileApigEvents/lib/compileStage.js
Normal file
10
lib/plugins/awsCompileApigEvents/lib/compileStage.js
Normal file
@ -0,0 +1,10 @@
|
||||
'use strict';
|
||||
|
||||
const BbPromise = require('bluebird');
|
||||
|
||||
module.exports = {
|
||||
compileStage() {
|
||||
|
||||
return BbPromise.resolve();
|
||||
},
|
||||
};
|
||||
@ -0,0 +1,72 @@
|
||||
'use strict';
|
||||
|
||||
const expect = require('chai').expect;
|
||||
const AwsCompileScheduledEvents = require('../awsCompileScheduledEvents');
|
||||
const Serverless = require('../../../Serverless');
|
||||
|
||||
describe('awsCompileScheduledEvents', () => {
|
||||
let serverless;
|
||||
let awsCompileScheduledEvents;
|
||||
|
||||
beforeEach(() => {
|
||||
serverless = new Serverless();
|
||||
serverless.init();
|
||||
serverless.service.resources = { aws: { Resources: {} } };
|
||||
awsCompileScheduledEvents = new AwsCompileScheduledEvents(serverless);
|
||||
awsCompileScheduledEvents.serverless.service.service = 'new-service';
|
||||
});
|
||||
|
||||
describe('#compileScheduledEvents()', () => {
|
||||
it('should throw an error if the aws resource is not available', () => {
|
||||
awsCompileScheduledEvents.serverless.service.resources.aws.Resources = false;
|
||||
expect(() => awsCompileScheduledEvents.compileScheduledEvents()).to.throw(Error);
|
||||
});
|
||||
|
||||
it('should compile scheduled events into CF resources', () => {
|
||||
awsCompileScheduledEvents.serverless.service.functions = {
|
||||
hello: {
|
||||
events: {
|
||||
aws: {
|
||||
schedule: 'rate(10 minutes)',
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
const scheduleResrouce = `
|
||||
{
|
||||
"Type": "AWS::Events::Rule",
|
||||
"Properties": {
|
||||
"ScheduleExpression": "rate(10 minutes)",
|
||||
"State": "ENABLED",
|
||||
"Targets": [{
|
||||
"Arn": { "Fn::GetAtt": ["hello", "Arn"] },
|
||||
"Id": "helloScheduleEvent"
|
||||
}]
|
||||
}
|
||||
}
|
||||
`;
|
||||
|
||||
const permissionResource = `
|
||||
{
|
||||
"Type": "AWS::Lambda::Permission",
|
||||
"Properties": {
|
||||
"FunctionName": { "Fn::GetAtt": ["hello", "Arn"] },
|
||||
"Action": "lambda:InvokeFunction",
|
||||
"Principal": "events.amazonaws.com",
|
||||
"SourceArn": { "Fn::GetAtt": ["helloScheduleEvent", "Arn"] }
|
||||
}
|
||||
}
|
||||
`;
|
||||
|
||||
awsCompileScheduledEvents.compileScheduledEvents();
|
||||
|
||||
expect(awsCompileScheduledEvents.serverless.service
|
||||
.resources.aws.Resources.helloScheduleEvent)
|
||||
.to.deep.equal(JSON.parse(scheduleResrouce));
|
||||
expect(awsCompileScheduledEvents.serverless.service
|
||||
.resources.aws.Resources.helloScheduleEventPermission)
|
||||
.to.deep.equal(JSON.parse(permissionResource));
|
||||
});
|
||||
});
|
||||
});
|
||||
Loading…
x
Reference in New Issue
Block a user