forked from serverless/serverless
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
97 lines (88 loc) · 2.77 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
'use strict';
const BbPromise = require('bluebird');
const validate = require('./lib/validate');
const compileApi = require('./lib/api');
const compileIntegrations = require('./lib/integrations');
const compileRouteResponses = require('./lib/routeResponses');
const compilePermissions = require('./lib/permissions');
const compileRoutes = require('./lib/routes');
const compileDeployment = require('./lib/deployment');
const compileStage = require('./lib/stage');
const compileAuthorizers = require('./lib/authorizers');
class AwsCompileWebsockets {
constructor(serverless, options) {
this.serverless = serverless;
this.options = options;
this.provider = this.serverless.getProvider('aws');
Object.assign(
this,
validate,
compileApi,
compileIntegrations,
compileRouteResponses,
compileAuthorizers,
compilePermissions,
compileRoutes,
compileDeployment,
compileStage
);
this.hooks = {
'package:compileEvents': () => {
this.validated = this.validate();
if (this.validated.events.length === 0) {
return BbPromise.resolve();
}
return BbPromise.bind(this)
.then(this.compileApi)
.then(this.compileIntegrations)
.then(this.compileRouteResponses)
.then(this.compileAuthorizers)
.then(this.compilePermissions)
.then(this.compileRoutes)
.then(this.compileStage)
.then(this.compileDeployment);
},
};
this.serverless.configSchemaHandler.defineFunctionEvent('aws', 'websocket', {
anyOf: [
{ type: 'string' },
{
type: 'object',
properties: {
route: { type: 'string' },
routeResponseSelectionExpression: {
type: 'string',
regexp: /^(?:\$default)$/.toString(),
},
authorizer: {
anyOf: [
{ type: 'string' },
{
type: 'object',
properties: {
name: { type: 'string' },
identitySource: { type: 'array', items: { type: 'string' } },
},
required: ['name'],
additionalProperties: false,
},
{
type: 'object',
properties: {
arn: { type: 'string' },
identitySource: { type: 'array', items: { type: 'string' } },
},
required: ['arn'],
additionalProperties: false,
},
],
},
},
required: ['route'],
additionalProperties: false,
},
],
});
}
}
module.exports = AwsCompileWebsockets;