forked from salesforce/refocus
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.js
301 lines (277 loc) · 10.1 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
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
/**
* Copyright (c) 2016, salesforce.com, inc.
* All rights reserved.
* Licensed under the BSD 3-Clause license.
* For full license text, see LICENSE.txt file in the repo root or
* https://opensource.org/licenses/BSD-3-Clause
*/
/**
* ./config.js
*
* Configuration Settings
*/
'use strict'; // eslint-disable-line strict
require('./config/toggles'); // Loads the feature toggles
const configUtil = require('./config/configUtil');
const redisConfig = require('./config/redisConfig');
const collectorConfig = require('./config/collectorConfig');
const defaultPort = 3000;
const defaultPostgresPort = 5432;
const pe = process.env; // eslint-disable-line no-process-env
const nodeEnv = pe.NODE_ENV || 'development';
const port = pe.PORT || defaultPort;
const defaultPayloadLimit = '200MB';
const payloadLimit = pe.REQUEST_PAYLOAD_LIMIT || defaultPayloadLimit;
const newRelicKey = pe.NEW_RELIC_LICENSE_KEY || '';
const pgdatabase = pe.PGDATABASE || 'focusdb';
const pguser = pe.PGUSER || 'postgres';
const pgpass = pe.PGPASS || 'postgres';
const pghost = pe.PGHOST || 'localhost';
const pgport = pe.PGPORT || defaultPostgresPort;
const defaultDbUrl = 'postgres://' + pguser + ':' + pgpass + '@' + pghost +
':' + pgport + '/' + pgdatabase;
const DEFAULT_DB_CONNECTION_POOL = { // sequelize defaults
max: 5,
min: 0,
idle: 10000,
};
const hiddenRoutes = pe.HIDDEN_ROUTES ?
pe.HIDDEN_ROUTES.split(',') : ['']; // Routes to hide
const corsRoutes = pe.CORS_ROUTES ?
pe.CORS_ROUTES.split(',') : ['']; // Routes to allow CORS
const DEFAULT_BULK_UPSERT_JOB_CONCURRENCY = 1;
const DEFAULT_GET_HIERARCHY_JOB_CONCURRENCY = 1;
const DEFAULT_BULK_CREATE_AUDIT_EVENT_JOB_CONCURRENCY = 1;
const DEFAULT_BULK_DELETE_SUBJECTS_JOB_CONCURRENCY = 1;
// By default, allow all IP's
const ipWhitelist = pe.IP_WHITELIST || '[[0.0.0.0,255.255.255.255]]';
const iplist = configUtil.parseIPlist(ipWhitelist);
// Check for timed-out samples every 30 seconds if not specified in env var
const DEFAULT_CHECK_TIMEOUT_INTERVAL_MILLIS = 30000;
// GET Samples Cache invalidation default time
const DEFAULT_GET_SAMPLES_WILDCARD_CACHE_INVALIDATION = 5;
// Expiry time used for redis cache
const DEFAULT_CACHE_EXPIRY_IN_SECS = 60;
const CACHE_EXPIRY_IN_SECS = pe.CACHE_EXPIRY_IN_SECS ||
DEFAULT_CACHE_EXPIRY_IN_SECS;
// request limiter settings
const expressLimiterPath = configUtil.csvToArray(pe.EXPRESS_LIMITER_PATH);
const expressLimiterMethod = configUtil.csvToArray(pe.EXPRESS_LIMITER_METHOD);
const expressLimiterLookup =
configUtil.csvToArray(pe.EXPRESS_LIMITER_LOOKUP || 'headers.UserName');
const expressLimiterTotal = pe.EXPRESS_LIMITER_TOTAL;
const expressLimiterExpire = pe.EXPRESS_LIMITER_EXPIRE;
const expressLimiterTotal2 = pe.EXPRESS_LIMITER_TOTAL_2;
const expressLimiterExpire2 = pe.EXPRESS_LIMITER_EXPIRE_2;
const DEFAULT_PERSIST_REDIS_SAMPLE_STORE_MILLISECONDS = 120000; // 2min
const botEventLimit = pe.BOT_EVENT_LIMIT || 100;
const deactivateRoomsInterval = +pe.DEACTIVATE_ROOMS_INTERVAL || 300000; // 5min
const minRoomDeactivationAge = 120; // 2 hours
/*
* name of the environment variable containing the read-only
* database names as CSV
*/
const replicaConfigLabel = 'REPLICAS';
// an array of read-only data base URLs
const readReplicas = configUtil.getReadReplicas(pe, replicaConfigLabel);
const DEFAULT_JOB_QUEUE_TTL_SECONDS_ASYNC = 3600;
const DEFAULT_JOB_QUEUE_TTL_SECONDS_SYNC = 25;
const DEFAULT_JOB_REMOVAL_INTERVAL_MINUTES = 30;
const JOB_REMOVAL_INTERVAL = 60 * 1000 * (pe.KUE_JOBS_REMOVAL_INTERVAL_MINUTES ||
DEFAULT_JOB_REMOVAL_INTERVAL_MINUTES);
const DEFAULT_JOB_REMOVAL_DELAY_MINUTES = 30;
const JOB_REMOVAL_DELAY = 60 * 1000 * (pe.KUE_JOBS_REMOVAL_DELAY_MINUTES ||
DEFAULT_JOB_REMOVAL_DELAY_MINUTES);
const DEFAULT_JOB_REMOVAL_BATCH_SIZE = 1000;
const JOB_REMOVAL_BATCH_SIZE = pe.KUE_JOBS_REMOVAL_BATCH_SIZE ||
DEFAULT_JOB_REMOVAL_BATCH_SIZE;
// This must be set to several times the value of JOB_REMOVAL_INTERVAL or
// completed jobs may be overwritten sooner that JOB_REMOVAL_DELAY
const DEFAULT_JOB_COUNTER_RESET_INTERVAL_MINUTES = 24 * 60;
const JOB_COUNTER_RESET_INTERVAL = 60 * 1000 *
(pe.KUE_JOB_COUNTER_RESET_INTERVAL_MINUTES ||
DEFAULT_JOB_COUNTER_RESET_INTERVAL_MINUTES);
/*
* If you're using worker dynos, you can set env vars PRIORITIZE_JOBS_FROM
* and/or DEPRIORITIZE_JOBS_FROM to comma-separated lists of user names, token
* names or ip addresses if you want to prioritize or deprioritize jobs from
* particular users and/or tokens and/or ip addresses. Has no effect if you're
* not using worker dynos.
*/
const prioritizeJobsFrom = configUtil.csvToArray(pe.PRIORITIZE_JOBS_FROM);
const deprioritizeJobsFrom = configUtil.csvToArray(pe.DEPRIORITIZE_JOBS_FROM);
// set time to live for "kue" jobs
const JOB_QUEUE_TTL_SECONDS_ASYNC = pe.TTL_KUE_JOBS_ASYNC
|| DEFAULT_JOB_QUEUE_TTL_SECONDS_ASYNC;
const JOB_QUEUE_TTL_SECONDS_SYNC = pe.TTL_KUE_JOBS_SYNC
|| DEFAULT_JOB_QUEUE_TTL_SECONDS_SYNC;
// set time interval for enableQueueStatsActivityLogs
const queueStatsActivityLogsInterval = 60000;
// encryption/decryption algorithm used for securing the context variables when
// sent to collector.
const encryptionAlgoForCollector = 'aes-256-cbc';
const kueShutdownTimeout = +pe.KUE_SHUTDOWN_TIMEOUT || 5000;
const waitingSigKillTimeout = +pe.WAITING_SIG_KILL_TIMEOUT || 60000;
module.exports = {
api: {
defaults: {
limit: +pe.GET_REQUEST_DEFAULT_LIMIT || 10000,
offset: 0,
},
swagger: {
doc: './api/v1/swagger.yaml',
router: {
controllers: './api/v1/controllers',
},
validator: {
validateResponse: true,
},
},
sessionSecret: pe.SESSION_SECRET || 'refocusrockswithgreenowls',
},
db: {
adminProfile: {
name: 'Admin',
aspectAccess: 'rw',
botAccess: 'rw',
eventAccess: 'rw',
lensAccess: 'rw',
perspectiveAccess: 'rw',
profileAccess: 'rw',
roomAccess: 'rw',
roomTypeAccess: 'rw',
sampleAccess: 'rw',
subjectAccess: 'rw',
userAccess: 'rw',
},
adminUser: {
email: 'admin@refocus.admin',
name: 'admin@refocus.admin',
password: 'password',
},
connectionPool: {
max: pe.DB_CONNECTION_POOL_MAX || DEFAULT_DB_CONNECTION_POOL.max,
min: pe.DB_CONNECTION_POOL_MIN || DEFAULT_DB_CONNECTION_POOL.min,
idle: pe.DB_CONNECTION_POOL_IDLE || DEFAULT_DB_CONNECTION_POOL.idle,
acquire: null, // disable acquire timeout
},
modelDirName: 'model',
passwordHashSaltNumRounds: 8,
},
redis: redisConfig,
collector: collectorConfig,
// When adding new environment, consider adding it to /config/migrationConfig
// as well to enable database migraton in the environment.
environment: {
build: {
dbLogging: false, // console.log | false | ...
dbUrl: defaultDbUrl,
defaultNodePort: defaultPort,
host: '127.0.0.1',
ipWhitelist: iplist.push('::ffff:127.0.0.1'),
dialect: 'postgres',
tokenSecret:
'7265666f637573726f636b7377697468677265656e6f776c7373616e6672616e',
},
development: {
dbLogging: false, // console.log | false | ...
dbUrl: defaultDbUrl,
defaultNodePort: defaultPort,
host: '127.0.0.1',
ipWhitelist: iplist,
dialect: 'postgres',
protocol: 'postgres',
dialectOptions: {
ssl: true,
},
tokenSecret:
'7265666f637573726f636b7377697468677265656e6f776c7373616e6672616e',
},
production: {
dbLogging: false, // console.log | false | ...
dbUrl: pe.DATABASE_URL,
ipWhitelist: iplist,
dialect: 'postgres',
protocol: 'postgres',
dialectOptions: {
ssl: true,
},
tokenSecret: pe.SECRET_TOKEN ||
'7265666f637573726f636b7377697468677265656e6f776c7373616e6672616e',
},
testWhitelistLocalhost: {
dbLogging: false, // console.log | false | ...
dbUrl: defaultDbUrl,
defaultNodePort: defaultPort,
host: '127.0.0.1',
ipWhitelist: iplist,
tokenSecret:
'7265666f637573726f636b7377697468677265656e6f776c7373616e6672616e',
},
testBlockAllhosts: {
dbLogging: false, // console.log | false | ...
dbUrl: defaultDbUrl,
defaultNodePort: defaultPort,
host: '127.0.0.1',
ipWhitelist: [''],
tokenSecret:
'7265666f637573726f636b7377697468677265656e6f776c7373616e6672616e',
},
},
bulkUpsertSampleJobConcurrency: pe.BULK_UPSERT_JOB_CONCURRENCY ||
DEFAULT_BULK_UPSERT_JOB_CONCURRENCY,
getHierarchyJobConcurrency: pe.GET_HIERARCHY_JOB_CONCURRENCY ||
DEFAULT_GET_HIERARCHY_JOB_CONCURRENCY,
getBulkCreateAuditEventJobConcurrency:
pe.BULK_CREATE_AUDIT_EVENT_JOB_CONCURRENCY ||
DEFAULT_BULK_CREATE_AUDIT_EVENT_JOB_CONCURRENCY,
getBulkDeleteSubjectsJobConcurrency:
pe.BULK_DELETE_SUBJECTS_JOB_CONCURRENCY ||
DEFAULT_BULK_DELETE_SUBJECTS_JOB_CONCURRENCY,
checkTimeoutIntervalMillis: pe.CHECK_TIMEOUT_INTERVAL_MILLIS ||
DEFAULT_CHECK_TIMEOUT_INTERVAL_MILLIS,
getSamplesWildcardCacheInvalidation:
pe.GET_SAMPLES_WILDCARD_CACHE_INVALIDATION ||
DEFAULT_GET_SAMPLES_WILDCARD_CACHE_INVALIDATION,
CACHE_EXPIRY_IN_SECS,
JOB_QUEUE_TTL_SECONDS_ASYNC,
JOB_QUEUE_TTL_SECONDS_SYNC,
JOB_REMOVAL_INTERVAL,
JOB_REMOVAL_DELAY,
JOB_REMOVAL_BATCH_SIZE,
JOB_COUNTER_RESET_INTERVAL,
deprioritizeJobsFrom,
expressLimiterPath,
expressLimiterMethod,
expressLimiterLookup,
expressLimiterTotal,
expressLimiterExpire,
expressLimiterTotal2,
expressLimiterExpire2,
botEventLimit,
deactivateRoomsInterval,
logEnvVars: {
MASK_LIST: pe.LOG_ENV_VARS_MASK_LIST ?
pe.LOG_ENV_VARS_MASK_LIST.split(',') : [],
MAX_LEN: +pe.LOG_ENV_VARS_MAX_LEN || 512,
},
minRoomDeactivationAge,
kueStatsInactiveWarning: pe.KUESTATS_INACTIVE_WARNING,
newRelicKey,
nodeEnv,
payloadLimit,
persistRedisSampleStoreMilliseconds:
pe.PERSIST_REDIS_SAMPLE_STORE_MILLISECONDS ||
DEFAULT_PERSIST_REDIS_SAMPLE_STORE_MILLISECONDS,
port,
prioritizeJobsFrom,
pubStatsLogsIntervalMillis: +pe.PUB_STATS_LOGS_INTERVAL_MILLIS || 60000,
queueStatsActivityLogsInterval,
queueTime95thMillis: pe.QUEUESTATS_95TH_WARNING_MILLIS,
readReplicas,
hiddenRoutes,
corsRoutes,
encryptionAlgoForCollector,
kueShutdownTimeout,
waitingSigKillTimeout,
};