-
Notifications
You must be signed in to change notification settings - Fork 4
/
config.js
233 lines (214 loc) · 8.81 KB
/
config.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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
/*
* Copyright (c) 2018 Livio, Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following
* disclaimer in the documentation and/or other materials provided with the
* distribution.
*
* Neither the name of the Livio Inc. nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
//the master config of which all other config files get their data from
const config = {
//USER CONFIGURABLE PROPERTIES
//the port that the web server binds to
httpPort: process.env.HTTP_PORT || 4000,
//enables usage of json web tokens as the form of unique identification
jwtSecret: process.env.JWT_SECRET,
//the address of the nomad and consul client. assumes manticore is launched by nomad
clientAgentIp: process.env.NOMAD_IP_http || 'localhost',
nomadAgentPort: process.env.NOMAD_AGENT_PORT || 4646, //the port the nomad agent listens on
consulAgentPort: process.env.CONSUL_AGENT_PORT || 8500, //the port the consul agent listens on
logLevel: process.env.LOG_LEVEL || 'debug', //the logging level of manticore to stdout
//the folder under /api to load from. only one version is allowed to run at a time
apiVersion: process.env.API_VERSION || 'v2',
haproxyPort: process.env.HAPROXY_HTTP_PORT, //the port haproxy listens on for http traffic
haproxyDomain: process.env.DOMAIN_NAME, //the domain under which clients will connect to the server
tcpPortStart: process.env.TCP_PORT_RANGE_START, //the smallest port haproxy can bind to for tcp
tcpPortEnd: process.env.TCP_PORT_RANGE_END, //the largest port haproxy can bind to for tcp
//reserved properties for manticore's use
//how long a user is allowed to use the Manticore service uninterrupted (in seconds)
usageDuration: process.env.USAGE_DURATION,
//how long a user has after being warned to send a websocket message to Manticore before being booted
//off the instance (in seconds). The total time a user has to use Manticore while idling is therefore
//usageDuration + warningDuration
warningDuration: process.env.WARNING_DURATION,
//whether a client can send a websocket message to reset the amount of time before a user is removed
//from Manticore. Enable this if you want to enforce a max limit of how long a user can use their jobs
resetTimerAllowed: process.env.RESET_TIMER_ALLOWED,
//whether the simple Manticore webpage will be served
webpageDisabled: process.env.WEBPAGE_DISABLED || false,
awsRegion: process.env.AWS_REGION, //the region Manticore is running on in AWS
//the security group ID that will allow access to Manticore's internal network
awsHaproxyGroupId: process.env.AWS_HAPROXY_GROUP_ID,
//the security group ID that will allow access through Manticore's external load balancer
awsElbGroupId: process.env.AWS_ELB_GROUP_ID,
elbName: process.env.ELB_MANTICORE_NAME, //name of the AWS ELB
elbEncryptHttp: process.env.ELB_ENCRYPT_HTTP, //whether to encrypt HTTP traffic to jobs and to the server
elbEncryptWs: process.env.ELB_ENCRYPT_WS, //whether to encrypt WS traffic to the server
elbEncryptTcp: process.env.ELB_ENCRYPT_TCP, //whether to encrypt TCP traffic to jobs
sslCertificateArn: process.env.SSL_CERTIFICATE_ARN, //SSL certificate attached to the AWS ELB
wsPort: process.env.ELB_WS_PORT, //WS port for TCP connections
cors: process.env.CORS,
//the amount of time in seconds between health evaluations
healthCheckPeriod: process.env.HEALTH_CHECK_PERIOD,
//the minimum milliseconds to wait between received requests before sending it in one batch
minDelayBuffer: process.env.MIN_DELAY_BUFFER || 500,
//the maximum milliseconds to wait between received requests before sending it in one batch
maxDelayBuffer: process.env.MAX_DELAY_BUFFER || 1500,
//RESERVED PROPERTIES FOR MANTICORE'S USE
//manticore interface modules
logger: null,
store: null,
job: null,
websocket: null,
//manticore modes and whether they're enabled
modes: {
haproxy: false,
inactivityTimer: false,
jwt: false,
aws: false,
awsSecurityGroup: false,
elb: false,
elbEncryptHttp: false,
elbEncryptWs: false,
elbEncryptTcp: false,
healthCheck: false
}
};
//convert strings to booleans for certain properties
if (config.resetTimerAllowed === "false") {
config.resetTimerAllowed = false;
}
if (config.resetTimerAllowed === "true") {
config.resetTimerAllowed = true;
}
if (config.webpageDisabled === "false") {
config.webpageDisabled = false;
}
if (config.webpageDisabled === "true") {
config.webpageDisabled = true;
}
if (config.elbEncryptHttp === "false") {
config.elbEncryptHttp = false;
}
if (config.elbEncryptHttp === "true") {
config.elbEncryptHttp = true;
}
if (config.elbEncryptWs === "false") {
config.elbEncryptWs = false;
}
if (config.elbEncryptWs === "true") {
config.elbEncryptWs = true;
}
if (config.elbEncryptTcp === "false") {
config.elbEncryptTcp = false;
}
if (config.elbEncryptTcp === "true") {
config.elbEncryptTcp = true;
}
if (config.cors === "false") {
config.cors = false;
}
if (config.cors === "true") {
config.cors = true;
}
//convert strings to numbers for certain properties
if (config.httpPort !== undefined) {
config.httpPort = Number(config.httpPort);
}
if (config.haproxyPort !== undefined) {
config.haproxyPort = Number(config.haproxyPort);
}
if (config.nomadAgentPort !== undefined) {
config.nomadAgentPort = Number(config.nomadAgentPort);
}
if (config.consulAgentPort !== undefined) {
config.consulAgentPort = Number(config.consulAgentPort);
}
if (config.tcpPortStart !== undefined) {
config.tcpPortStart = Number(config.tcpPortStart);
}
if (config.tcpPortEnd !== undefined) {
config.tcpPortEnd = Number(config.tcpPortEnd);
}
if (config.wsPort !== undefined) {
config.wsPort = Number(config.wsPort);
}
if (config.healthCheckPeriod !== undefined) {
config.healthCheckPeriod = Number(config.healthCheckPeriod);
}
if (config.minDelayBuffer !== undefined) {
config.minDelayBuffer = Number(config.minDelayBuffer);
}
if (config.maxDelayBuffer !== undefined) {
config.maxDelayBuffer = Number(config.maxDelayBuffer);
}
//provide properties to easily determine whether certain modes of manticore are enabled
if (config.haproxyPort !== undefined
&& config.haproxyDomain !== undefined
&& config.tcpPortStart !== undefined
&& config.tcpPortEnd !== undefined) {
config.modes.haproxy = true;
}
if (config.usageDuration !== undefined
&& config.warningDuration !== undefined
&& config.resetTimerAllowed !== undefined) {
config.modes.inactivityTimer = true;
}
if (config.jwtSecret !== undefined) {
config.modes.jwt = true;
}
if (config.awsRegion !== undefined) {
config.modes.aws = true;
if (config.modes.haproxy
&& config.elbName !== undefined
&& config.wsPort !== undefined) {
config.modes.elb = true;
}
if (config.modes.haproxy
&& config.modes.elb
&& config.awsHaproxyGroupId !== undefined
&& config.awsElbGroupId !== undefined) {
config.modes.awsSecurityGroup = true;
}
//encryption modes
if (config.modes.haproxy
&& config.modes.elb
&& config.sslCertificateArn !== undefined) {
if (config.elbEncryptHttp) {
config.modes.elbEncryptHttp = true;
}
if (config.elbEncryptWs) {
config.modes.elbEncryptWs = true;
}
if (config.elbEncryptTcp) {
config.modes.elbEncryptTcp = true;
}
}
}
if (config.healthCheckPeriod !== undefined) {
config.modes.healthCheck = true;
}
module.exports = config;