/
index.js
112 lines (103 loc) · 3.71 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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
'use strict';
const BbPromise = require('bluebird');
const validate = require('./lib/validate');
const compileTargetGroups = require('./lib/targetGroups');
const compileListenerRules = require('./lib/listenerRules');
const compilePermissions = require('./lib/permissions');
function defineArray(schema) {
return { type: 'array', items: schema };
}
class AwsCompileAlbEvents {
constructor(serverless, options) {
this.serverless = serverless;
this.options = options;
this.provider = this.serverless.getProvider('aws');
Object.assign(this, validate, compileTargetGroups, compileListenerRules, compilePermissions);
this.hooks = {
'package:compileEvents': () => {
return BbPromise.try(() => {
this.validated = this.validate();
if (this.validated.events.length === 0) return;
this.compileTargetGroups();
this.compileListenerRules();
this.compilePermissions();
});
},
};
this.serverless.configSchemaHandler.defineFunctionEvent('aws', 'alb', {
type: 'object',
properties: {
authorizer: defineArray({ type: 'string' }),
conditions: {
type: 'object',
properties: {
header: {
type: 'object',
properties: {
name: { type: 'string', maxLength: 40 },
values: { type: 'array', items: { type: 'string', maxLength: 128 } },
},
additionalProperties: false,
required: ['name', 'values'],
},
host: defineArray({
type: 'string',
pattern: '^[A-Za-z0-9*?.-]+$',
maxLength: 128,
}),
ip: defineArray({
oneOf: [
{ type: 'string', format: 'ipv4' },
{ type: 'string', format: 'ipv6' },
],
}),
method: defineArray({ type: 'string', pattern: '^[A-Z_-]+$', maxLength: 40 }),
path: defineArray({
type: 'string',
pattern: '^([A-Za-z0-9*?_.$/~"\'@:+-]|&)+$',
maxLength: 128,
}),
query: {
type: 'object',
additionalProperties: { type: 'string', maxLength: 128 },
propertyNames: { type: 'string', maxLength: 128 },
},
},
required: ['path'],
additionalProperties: false,
},
healthCheck: {
oneOf: [
{ type: 'boolean' },
{
type: 'object',
properties: {
healthyThresholdCount: { type: 'integer', minimum: 2, maximum: 10 },
intervalSeconds: { type: 'integer', minimum: 5, maximum: 300 },
matcher: {
type: 'object',
properties: {
httpCode: { type: 'string', pattern: '^\\d{3}(-\\d{3})?(,\\d{3}(-\\d{3})?)*$' },
},
additionalProperties: false,
},
path: { type: 'string', minLength: 1, maxLength: 1024 },
timeoutSeconds: { type: 'integer', minimum: 2, maximum: 120 },
unhealthyThresholdCount: { type: 'integer', minimum: 2, maximum: 10 },
},
additionalProperties: false,
},
],
},
listenerArn: {
oneOf: [{ $ref: '#/definitions/awsAlbListenerArn' }, { $ref: '#/definitions/awsCfRef' }],
},
multiValueHeaders: { type: 'boolean' },
priority: { type: 'integer', minimum: 1, maximum: 50000 },
},
required: ['listenerArn', 'priority', 'conditions'],
additionalProperties: false,
});
}
}
module.exports = AwsCompileAlbEvents;