@mimik/configuration 6.0.6 → 6.0.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude/settings.local.json +15 -0
- package/.husky/pre-commit +0 -2
- package/.husky/pre-push +0 -2
- package/README.md +31 -29
- package/eslint.config.js +35 -11
- package/index.js +137 -204
- package/lib/common.js +13 -141
- package/package.json +21 -23
- package/test/configuration.spec.js +1038 -0
- package/test/testEnv.js +46 -0
- package/.nycrc +0 -4
package/index.js
CHANGED
|
@@ -1,74 +1,15 @@
|
|
|
1
|
-
/* eslint no-process-env: "off" */
|
|
1
|
+
/* eslint no-process-env: "off", no-magic-numbers: "off" */
|
|
2
2
|
import {
|
|
3
3
|
ALL,
|
|
4
4
|
AWS_S3,
|
|
5
5
|
CUSTOMER_CODE_SEP,
|
|
6
|
-
|
|
7
|
-
DEFAULT_AWS_LOCAL_PROPERTIES,
|
|
8
|
-
DEFAULT_AWS_REGION,
|
|
9
|
-
DEFAULT_BITBUCKET_PASSWORD,
|
|
10
|
-
DEFAULT_BITBUCKET_USERNAME,
|
|
11
|
-
DEFAULT_CACHE_API_ID_TTL,
|
|
12
|
-
DEFAULT_CACHE_API_OPTION_TTL,
|
|
13
|
-
DEFAULT_CACHE_CONNECTION_TIMEOUT,
|
|
14
|
-
DEFAULT_CACHE_IP,
|
|
15
|
-
DEFAULT_CACHE_RECONNECTION_OFFSET,
|
|
16
|
-
DEFAULT_CACHE_REQUEST_TTL,
|
|
17
|
-
DEFAULT_CACHE_SET,
|
|
18
|
-
DEFAULT_CACHE_VALIDATION_CHECK,
|
|
19
|
-
DEFAULT_CLOUD_PROVIDER,
|
|
20
|
-
DEFAULT_CLUSTER_MANAGEMENT,
|
|
21
|
-
DEFAULT_CUSTOMER_CODE,
|
|
22
|
-
DEFAULT_DATABASE_CONNECTION_TIMEOUT,
|
|
23
|
-
DEFAULT_DATABASE_IP,
|
|
24
|
-
DEFAULT_DATABASE_PASSWORD,
|
|
25
|
-
DEFAULT_DATABASE_RECONNECTION_OFFSET,
|
|
26
|
-
DEFAULT_DATABASE_USER,
|
|
27
|
-
DEFAULT_DATABASE_VALIDATION_CHECK,
|
|
28
|
-
DEFAULT_DYNAMODB_LOCAL_URL,
|
|
29
|
-
DEFAULT_DYNAMO_THROUGHPUT,
|
|
30
|
-
DEFAULT_DYNAMO_THROUGHPUT_READ,
|
|
31
|
-
DEFAULT_DYNAMO_THROUGHPUT_WRITE,
|
|
32
|
-
DEFAULT_ENCRYPTION_SET,
|
|
33
|
-
DEFAULT_ENV,
|
|
34
|
-
DEFAULT_EXIT_DELAY,
|
|
35
|
-
DEFAULT_FILTER_FILE,
|
|
36
|
-
DEFAULT_INTERCEPT_ERROR,
|
|
37
|
-
DEFAULT_KMS_PROVIDER,
|
|
38
|
-
DEFAULT_LOCATION_PROVIDER,
|
|
39
|
-
DEFAULT_LOG_LEVEL,
|
|
40
|
-
DEFAULT_MONGO_FAMILY,
|
|
41
|
-
DEFAULT_MONGO_HEARTBEAT_FREQUENCY,
|
|
42
|
-
DEFAULT_MONGO_MAX_IDLE_TIME,
|
|
43
|
-
DEFAULT_MONGO_MAX_POOL_SIZE,
|
|
44
|
-
DEFAULT_MONGO_MIN_POOL_SIZE,
|
|
45
|
-
DEFAULT_MONGO_SERVER_SELECTION_TIMEOUT,
|
|
46
|
-
DEFAULT_MONGO_SOCKET_TIMEOUT,
|
|
47
|
-
DEFAULT_NO_STACK,
|
|
48
|
-
DEFAULT_REDIS_DISABLE_OFFLINE_QUEUE,
|
|
49
|
-
DEFAULT_REDIS_RECONNECT_INTERVAL,
|
|
50
|
-
DEFAULT_REDIS_RECONNECT_TRIES,
|
|
51
|
-
DEFAULT_REDIS_REQUEST_MAX_MEMORY,
|
|
52
|
-
DEFAULT_REDIS_REQUEST_MAX_MEMORY_POLICY,
|
|
53
|
-
DEFAULT_REDIS_SOCKET_KEEPALIVE,
|
|
54
|
-
DEFAULT_REGISTRATION_AFTER_POSTOPS_SET,
|
|
55
|
-
DEFAULT_REGISTRATION_RETRY,
|
|
56
|
-
DEFAULT_REGISTRATION_SET,
|
|
57
|
-
DEFAULT_REQUEST_TIMEOUT,
|
|
58
|
-
DEFAULT_S3_AWS_MAX_EVENTS,
|
|
59
|
-
DEFAULT_S3_AWS_MAX_SIZE,
|
|
60
|
-
DEFAULT_S3_AWS_TIMEOUT,
|
|
61
|
-
DEFAULT_SERVER_PUBLIC_DOMAIN_NAME,
|
|
62
|
-
DEFAULT_SERVER_PUBLIC_PROTOCOL,
|
|
63
|
-
DEFAULT_SERVER_SECURITY_SET,
|
|
64
|
-
DEFAULT_SWAGGER_DIR,
|
|
65
|
-
DEFAULT_SWAGGER_FILE_PROVIDER,
|
|
66
|
-
DEFAULT_TOPIC_SET,
|
|
67
|
-
DEFAULT_USER_DEFINITIONS_FILE,
|
|
6
|
+
DEBUG,
|
|
68
7
|
ENV_VARIABLE,
|
|
8
|
+
LOCAL,
|
|
69
9
|
MONGO_BASE_URL,
|
|
70
10
|
MONGO_BASE_URL_SRV,
|
|
71
11
|
NO,
|
|
12
|
+
NOT_SET,
|
|
72
13
|
NO_GENERIC,
|
|
73
14
|
NO_PUBLIC_PROVIDER,
|
|
74
15
|
PRODUCTIONS,
|
|
@@ -80,23 +21,16 @@ import {
|
|
|
80
21
|
SWAGGER_EXT,
|
|
81
22
|
SWAGGER_SEP,
|
|
82
23
|
YES,
|
|
24
|
+
toInt,
|
|
83
25
|
} from './lib/common.js';
|
|
84
|
-
import
|
|
26
|
+
import crypto from 'node:crypto';
|
|
27
|
+
import fs from 'node:fs';
|
|
85
28
|
import { getCorrelationId } from '@mimik/request-helper';
|
|
86
|
-
import includes from 'lodash.includes';
|
|
87
29
|
import ip from 'ip';
|
|
88
|
-
import isNaN from 'lodash.isnan';
|
|
89
|
-
import isNil from 'lodash.isnil';
|
|
90
|
-
import isString from 'lodash.isstring';
|
|
91
|
-
import isUndefined from 'lodash.isundefined';
|
|
92
30
|
import logger from '@mimik/sumologic-winston-logger';
|
|
93
|
-
import process from 'process';
|
|
94
|
-
import querystring from 'querystring';
|
|
95
|
-
import split from 'lodash.split';
|
|
31
|
+
import process from 'node:process';
|
|
96
32
|
import { userDefinitions } from '@mimik/user-filters';
|
|
97
|
-
import { v4 as uuidv4 } from 'uuid';
|
|
98
33
|
|
|
99
|
-
const DECIMAL = 10;
|
|
100
34
|
const AT_LEAST_ONE = 0;
|
|
101
35
|
const SOME_KEYS = 0;
|
|
102
36
|
const SOME_ERRORS = 0;
|
|
@@ -116,11 +50,11 @@ const correlationIdStart = getCorrelationId('config-start');
|
|
|
116
50
|
const isMSTSet = process.env.MST_SET !== SET_OFF;
|
|
117
51
|
|
|
118
52
|
const setupRedis = () => {
|
|
119
|
-
const domain = process.env.CACHE_IP ||
|
|
53
|
+
const domain = process.env.CACHE_IP || 'localhost:6379';
|
|
120
54
|
const username = process.env.CACHE_USER;
|
|
121
55
|
const password = process.env.CACHE_PASSWORD;
|
|
122
|
-
const reconnectTries =
|
|
123
|
-
const reconnectInterval =
|
|
56
|
+
const reconnectTries = toInt(process.env.REDIS_RECONNECT_TRIES, 100);
|
|
57
|
+
const reconnectInterval = toInt(process.env.REDIS_RECONNECT_INTERVAL, 500);
|
|
124
58
|
let url = REDIS_BASE_URL;
|
|
125
59
|
let noAuthUrl = url;
|
|
126
60
|
if (username && password) url += `${username}:${password}@`;
|
|
@@ -135,16 +69,16 @@ const setupRedis = () => {
|
|
|
135
69
|
|
|
136
70
|
return {
|
|
137
71
|
api: {
|
|
138
|
-
idTTL:
|
|
139
|
-
optionTTL:
|
|
72
|
+
idTTL: toInt(process.env.CACHE_API_ID_TTL, 20),
|
|
73
|
+
optionTTL: toInt(process.env.CACHE_API_OPTION_TTL, 5),
|
|
140
74
|
},
|
|
141
75
|
cluster: clusterConfig,
|
|
142
|
-
connectTimeout:
|
|
76
|
+
connectTimeout: toInt(process.env.CACHE_CONNECTION_TIMEOUT, 30),
|
|
143
77
|
domain,
|
|
144
78
|
noAuthUrl,
|
|
145
79
|
options: {
|
|
146
80
|
socket: {
|
|
147
|
-
keepAlive: process.env.REDIS_SOCKET_KEEPALIVE
|
|
81
|
+
keepAlive: toInt(process.env.REDIS_SOCKET_KEEPALIVE, 5000),
|
|
148
82
|
reconnectStrategy: function reconnectStrategy(opts) {
|
|
149
83
|
if (opts.timesConnected > AT_LEAST_ONE && opts.attempt < reconnectTries) {
|
|
150
84
|
return reconnectInterval;
|
|
@@ -158,15 +92,15 @@ const setupRedis = () => {
|
|
|
158
92
|
}
|
|
159
93
|
return undefined;
|
|
160
94
|
},
|
|
161
|
-
disableOfflineQueue: (process.env.REDIS_DISABLE_OFFLINE_QUEUE === YES)
|
|
95
|
+
disableOfflineQueue: (process.env.REDIS_DISABLE_OFFLINE_QUEUE === YES),
|
|
162
96
|
},
|
|
163
|
-
maxMemory: process.env.REDIS_REQUEST_MAX_MEMORY ||
|
|
164
|
-
maxMemoryPolicy: process.env.REDIS_REQUEST_MAX_MEMORY_POLICY ||
|
|
97
|
+
maxMemory: process.env.REDIS_REQUEST_MAX_MEMORY || '10mb',
|
|
98
|
+
maxMemoryPolicy: process.env.REDIS_REQUEST_MAX_MEMORY_POLICY || 'allkeys-lru',
|
|
165
99
|
},
|
|
166
100
|
password,
|
|
167
|
-
reconnectOffset:
|
|
101
|
+
reconnectOffset: toInt(process.env.CACHE_RECONNECTION_OFFSET, 5),
|
|
168
102
|
request: {
|
|
169
|
-
TTL:
|
|
103
|
+
TTL: toInt(process.env.CACHE_REQUEST_TTL, 10),
|
|
170
104
|
},
|
|
171
105
|
retryStrategyOptions: {
|
|
172
106
|
reconnectTries,
|
|
@@ -174,39 +108,36 @@ const setupRedis = () => {
|
|
|
174
108
|
},
|
|
175
109
|
url,
|
|
176
110
|
username,
|
|
177
|
-
validationCheck:
|
|
111
|
+
validationCheck: toInt(process.env.CACHE_VALIDATION_CHECK, 1000),
|
|
178
112
|
};
|
|
179
113
|
};
|
|
180
114
|
|
|
181
115
|
const setupDynamo = (dbOpts) => {
|
|
182
116
|
const dbConfig = {
|
|
183
|
-
connectTimeout:
|
|
184
|
-
validationCheck:
|
|
185
|
-
reconnectOffset:
|
|
186
|
-
region: process.env.DYNAMODB_AWS_REGION ||
|
|
187
|
-
url: process.env.DYNAMODB_LOCAL_URL ||
|
|
117
|
+
connectTimeout: toInt(process.env.DATABASE_CONNECTION_TIMEOUT, 30),
|
|
118
|
+
validationCheck: toInt(process.env.DATABASE_VALIDATION_CHECK, 1000),
|
|
119
|
+
reconnectOffset: toInt(process.env.DATABASE_RECONNECTION_OFFSET, 5),
|
|
120
|
+
region: process.env.DYNAMODB_AWS_REGION || '----noRegion----',
|
|
121
|
+
url: process.env.DYNAMODB_LOCAL_URL || 'http://localhost:8000',
|
|
188
122
|
throughput: {
|
|
189
|
-
read:
|
|
190
|
-
write:
|
|
123
|
+
read: toInt(process.env.DYNAMO_THROUGHPUT_READ, 1),
|
|
124
|
+
write: toInt(process.env.DYNAMO_THROUGHPUT_WRITE, 1),
|
|
191
125
|
},
|
|
192
126
|
schemaThroughput: {
|
|
193
|
-
read:
|
|
194
|
-
write:
|
|
127
|
+
read: toInt(process.env.DYNAMO_SCHEMA_THROUGHPUT_READ, 1),
|
|
128
|
+
write: toInt(process.env.DYNAMO_SCHEMA_THROUGHPUT_WRITE, 1),
|
|
195
129
|
},
|
|
196
130
|
tableName: dbOpts.table,
|
|
197
131
|
};
|
|
198
|
-
if (
|
|
199
|
-
if (
|
|
132
|
+
if (process.env.DYNAMODB_AWS_ACCESS_KEY_ID !== undefined) dbConfig.accessKeyId = process.env.DYNAMODB_AWS_ACCESS_KEY_ID;
|
|
133
|
+
if (process.env.DYNAMODB_AWS_SECRET_ACCESS_KEY !== undefined) dbConfig.secretAccessKey = process.env.DYNAMODB_AWS_SECRET_ACCESS_KEY;
|
|
200
134
|
|
|
201
135
|
if (process.env.DYNAMO_SCHEMA_THROUGHPUT === 'ON_DEMAND') {
|
|
202
136
|
dbConfig.schemaThroughput = process.env.DYNAMO_SCHEMA_THROUGHPUT;
|
|
203
137
|
delete dbConfig.throughput;
|
|
204
138
|
}
|
|
205
|
-
else if (
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
if (isNil(throughput) || isNaN(throughput)) dbConfig.schemaThroughput = DEFAULT_DYNAMO_THROUGHPUT;
|
|
209
|
-
else dbConfig.schemaThroughput = throughput;
|
|
139
|
+
else if (process.env.DYNAMO_SCHEMA_THROUGHPUT !== undefined) {
|
|
140
|
+
dbConfig.schemaThroughput = toInt(process.env.DYNAMO_SCHEMA_THROUGHPUT, 1);
|
|
210
141
|
}
|
|
211
142
|
return dbConfig;
|
|
212
143
|
};
|
|
@@ -215,9 +146,9 @@ const setupMongo = (dbOpts) => {
|
|
|
215
146
|
const processStringOptions = () => {
|
|
216
147
|
// default string variables
|
|
217
148
|
const stringOptions = {
|
|
218
|
-
maxPoolSize:
|
|
219
|
-
minPoolSize:
|
|
220
|
-
maxIdleTimeMS:
|
|
149
|
+
maxPoolSize: toInt(process.env.MONGO_MAX_POOL_SIZE, 10),
|
|
150
|
+
minPoolSize: toInt(process.env.MONGO_MIN_POOL_SIZE, 0),
|
|
151
|
+
maxIdleTimeMS: toInt(process.env.MONGO_MAX_IDLE_TIME, 30000),
|
|
221
152
|
};
|
|
222
153
|
// string variables without default
|
|
223
154
|
if (process.env.MONGO_SSL === YES) stringOptions.ssl = true; // default value of mongo driver is false
|
|
@@ -229,17 +160,17 @@ const setupMongo = (dbOpts) => {
|
|
|
229
160
|
// eslint-disable-next-line id-length
|
|
230
161
|
if (process.env.MONGO_WRITE_CONCERN) stringOptions.w = process.env.MONGO_WRITE_CONCERN;
|
|
231
162
|
if (process.env.MONGO_RETRY_WRITES) stringOptions.retryWrites = process.env.MONGO_RETRY_WRITES;
|
|
232
|
-
if (process.env.MONGO_WAIT_QUEUE_MULTIPLE) stringOptions.waitQueueMultiple =
|
|
233
|
-
if (process.env.MONGO_WAIT_QUEUE_TIMEOUT) stringOptions.waitQueueTimeoutMS =
|
|
234
|
-
return
|
|
163
|
+
if (process.env.MONGO_WAIT_QUEUE_MULTIPLE) stringOptions.waitQueueMultiple = toInt(process.env.MONGO_WAIT_QUEUE_MULTIPLE, 0);
|
|
164
|
+
if (process.env.MONGO_WAIT_QUEUE_TIMEOUT) stringOptions.waitQueueTimeoutMS = toInt(process.env.MONGO_WAIT_QUEUE_TIMEOUT, 0); // in ms
|
|
165
|
+
return new URLSearchParams(stringOptions).toString();
|
|
235
166
|
};
|
|
236
167
|
const database = process.env.DATABASE_NAME;
|
|
237
168
|
if (!database) {
|
|
238
169
|
return undefined;
|
|
239
170
|
}
|
|
240
|
-
const domain = process.env.DATABASE_IP ||
|
|
241
|
-
const user = process.env.DATABASE_USER ||
|
|
242
|
-
const password = process.env.DATABASE_PASSWORD ||
|
|
171
|
+
const domain = process.env.DATABASE_IP || 'localhost';
|
|
172
|
+
const user = process.env.DATABASE_USER || null;
|
|
173
|
+
const password = process.env.DATABASE_PASSWORD || null;
|
|
243
174
|
const qs = processStringOptions();
|
|
244
175
|
let url = (process.env.MONGO_USE_SRV === YES) ? MONGO_BASE_URL_SRV : MONGO_BASE_URL;
|
|
245
176
|
let noAuthUrl = url;
|
|
@@ -252,24 +183,24 @@ const setupMongo = (dbOpts) => {
|
|
|
252
183
|
noAuthUrl = `${noAuthUrl}?${qs}`;
|
|
253
184
|
}
|
|
254
185
|
return {
|
|
255
|
-
connectTimeout:
|
|
186
|
+
connectTimeout: toInt(process.env.DATABASE_CONNECTION_TIMEOUT, 30),
|
|
256
187
|
database,
|
|
257
188
|
domain,
|
|
258
189
|
noAuthUrl,
|
|
259
190
|
options: {
|
|
260
|
-
family:
|
|
261
|
-
socketTimeoutMS:
|
|
262
|
-
serverSelectionTimeoutMS:
|
|
263
|
-
heartbeatFrequencyMS:
|
|
191
|
+
family: toInt(process.env.MONGO_FAMILY, 4),
|
|
192
|
+
socketTimeoutMS: toInt(process.env.MONGO_SOCKET_TIMEOUT, 20000),
|
|
193
|
+
serverSelectionTimeoutMS: toInt(process.env.MONGO_SERVER_SELECTION_TIMEOUT, 30000),
|
|
194
|
+
heartbeatFrequencyMS: toInt(process.env.MONGO_HEARTBEAT_FREQUENCY, 10000),
|
|
264
195
|
},
|
|
265
196
|
password,
|
|
266
|
-
reconnectOffset:
|
|
197
|
+
reconnectOffset: toInt(process.env.DATABASE_RECONNECTION_OFFSET, 5),
|
|
267
198
|
replicat: Boolean(process.env.MONGO_REPLICAT_SET),
|
|
268
199
|
stringOptions: qs,
|
|
269
200
|
table: dbOpts.table,
|
|
270
201
|
url,
|
|
271
202
|
user,
|
|
272
|
-
validationCheck:
|
|
203
|
+
validationCheck: toInt(process.env.DATABASE_VALIDATION_CHECK, 1000),
|
|
273
204
|
};
|
|
274
205
|
};
|
|
275
206
|
|
|
@@ -277,7 +208,7 @@ const setupLocationProvider = () => {
|
|
|
277
208
|
const url = process.env.LOCATION_PROVIDER;
|
|
278
209
|
|
|
279
210
|
if (!url) return NO_PUBLIC_PROVIDER;
|
|
280
|
-
if (includes(
|
|
211
|
+
if (locParams.includes(url)) return url;
|
|
281
212
|
const locationProvider = { url };
|
|
282
213
|
|
|
283
214
|
if (process.env.LOCATION_PROVIDER_KEY) locationProvider.key = process.env.LOCATION_PROVIDER_KEY;
|
|
@@ -288,12 +219,12 @@ const setupLog = () => {
|
|
|
288
219
|
const logInfo = {
|
|
289
220
|
mode: process.env.LOG_MODE || SUMOLOGIC,
|
|
290
221
|
level: {
|
|
291
|
-
console: process.env.CONSOLE_LEVEL ||
|
|
292
|
-
log: process.env.LOG_LEVEL ||
|
|
222
|
+
console: process.env.CONSOLE_LEVEL || DEBUG,
|
|
223
|
+
log: process.env.LOG_LEVEL || DEBUG,
|
|
293
224
|
},
|
|
294
|
-
filterFile: process.env.FILTER_FILE ||
|
|
295
|
-
exitDelay:
|
|
296
|
-
noStack: process.env.NO_STACK ||
|
|
225
|
+
filterFile: process.env.FILTER_FILE || NOT_SET,
|
|
226
|
+
exitDelay: toInt(process.env.EXIT_DELAY, 2000),
|
|
227
|
+
noStack: process.env.NO_STACK || YES,
|
|
297
228
|
};
|
|
298
229
|
|
|
299
230
|
if (logInfo.mode === SUMOLOGIC || logInfo.mode === ALL) {
|
|
@@ -305,28 +236,28 @@ const setupLog = () => {
|
|
|
305
236
|
if (logInfo.mode === AWS_S3 || logInfo.mode === ALL) {
|
|
306
237
|
logInfo[AWS_S3] = {
|
|
307
238
|
region: process.env.S3_AWS_REGION,
|
|
308
|
-
|
|
309
|
-
timeout:
|
|
310
|
-
maxSize:
|
|
311
|
-
maxEvents:
|
|
239
|
+
bucketName: process.env.S3_AWS_BUCKET_NAME,
|
|
240
|
+
timeout: toInt(process.env.S3_AWS_TIMEOUT, 5),
|
|
241
|
+
maxSize: toInt(process.env.S3_AWS_MAX_SIZE, 5),
|
|
242
|
+
maxEvents: toInt(process.env.S3_AWS_MAX_EVENTS, 1000),
|
|
312
243
|
};
|
|
313
|
-
if (
|
|
314
|
-
if (
|
|
244
|
+
if (process.env.S3_AWS_ACCESS_KEY_ID !== undefined) logInfo[AWS_S3].accessKeyId = process.env.S3_AWS_ACCESS_KEY_ID;
|
|
245
|
+
if (process.env.S3_AWS_SECRET_ACCESS_KEY !== undefined) logInfo[AWS_S3].secretAccessKey = process.env.S3_AWS_SECRET_ACCESS_KEY;
|
|
315
246
|
}
|
|
316
247
|
return logInfo;
|
|
317
248
|
};
|
|
318
249
|
|
|
319
250
|
const setupTopic = (topicOpts) => {
|
|
320
251
|
const topicConfig = {
|
|
321
|
-
region: process.env.SNS_AWS_REGION ||
|
|
252
|
+
region: process.env.SNS_AWS_REGION || '----noRegion----',
|
|
322
253
|
name: topicOpts.name,
|
|
323
254
|
isFifoTopic: process.env.SET_SNS_TOPIC_FIFO === YES,
|
|
324
255
|
contentBasedDeduplication: false,
|
|
325
256
|
};
|
|
326
257
|
|
|
327
258
|
if (topicConfig.isFifoTopic) topicConfig.contentBasedDeduplication = process.env.SET_SNS_CONTENT_DEDUPLICATION === YES;
|
|
328
|
-
if (
|
|
329
|
-
if (
|
|
259
|
+
if (process.env.SNS_AWS_ACCESS_KEY_ID !== undefined) topicConfig.accessKeyId = process.env.SNS_AWS_ACCESS_KEY_ID;
|
|
260
|
+
if (process.env.SNS_AWS_SECRET_ACCESS_KEY !== undefined) topicConfig.secretAccessKey = process.env.SNS_AWS_SECRET_ACCESS_KEY;
|
|
330
261
|
|
|
331
262
|
return topicConfig;
|
|
332
263
|
};
|
|
@@ -336,16 +267,16 @@ const setupEncryption = (encryptionOpts) => {
|
|
|
336
267
|
set: encryptionOpts.set,
|
|
337
268
|
database: process.env.ENCRYPTION_DATABASE,
|
|
338
269
|
keyVaultTable: process.env.KEY_VAULT_TABLE,
|
|
339
|
-
kmsProvider: process.env.KMS_PROVIDER ||
|
|
270
|
+
kmsProvider: process.env.KMS_PROVIDER || LOCAL,
|
|
340
271
|
};
|
|
341
272
|
|
|
342
273
|
if (encryptionConfig.kmsProvider.toLowerCase() === 'aws') {
|
|
343
274
|
encryptionConfig.aws = {};
|
|
344
|
-
encryptionConfig.region = process.env.MASTER_KEY_AWS_REGION ||
|
|
275
|
+
encryptionConfig.region = process.env.MASTER_KEY_AWS_REGION || '----noRegion----';
|
|
345
276
|
encryptionConfig.masterKeyARN = process.env.MASTER_KEY_ARN;
|
|
346
277
|
|
|
347
|
-
if (
|
|
348
|
-
if (
|
|
278
|
+
if (process.env.ENCRYPTION_ACCESS_KEY_ID !== undefined) encryptionConfig.aws.accessKeyId = process.env.ENCRYPTION_ACCESS_KEY_ID;
|
|
279
|
+
if (process.env.ENCRYPTION_SECRET_ACCESS_KEY !== undefined) encryptionConfig.aws.secretAccessKey = process.env.ENCRYPTION_SECRET_ACCESS_KEY;
|
|
349
280
|
}
|
|
350
281
|
else encryptionConfig.localMasterKey = process.env.LOCAL_MASTER_KEY;
|
|
351
282
|
|
|
@@ -357,12 +288,12 @@ const setupEncryption = (encryptionOpts) => {
|
|
|
357
288
|
const setupUserDefinitions = (definitions) => {
|
|
358
289
|
const userDefinitionsFile = definitions.file;
|
|
359
290
|
let customDefinitions = {};
|
|
360
|
-
if (userDefinitionsFile && userDefinitionsFile !==
|
|
291
|
+
if (userDefinitionsFile && userDefinitionsFile !== NOT_SET) {
|
|
361
292
|
try {
|
|
362
293
|
customDefinitions = JSON.parse(fs.readFileSync(userDefinitionsFile).toString());
|
|
363
294
|
}
|
|
364
295
|
catch (err) {
|
|
365
|
-
throw new Error(`Invalid file for user definitions: ${userDefinitionsFile}, error: ${err.message}
|
|
296
|
+
throw new Error(`Invalid file for user definitions: ${userDefinitionsFile}, error: ${err.message}`, { cause: err });
|
|
366
297
|
}
|
|
367
298
|
}
|
|
368
299
|
return {
|
|
@@ -376,11 +307,12 @@ const checkConfig = (config) => {
|
|
|
376
307
|
const errors = [];
|
|
377
308
|
|
|
378
309
|
const traverseNodeSync = (node, path) => {
|
|
310
|
+
if (Array.isArray(node)) return;
|
|
379
311
|
Object.keys(node).forEach((prop) => {
|
|
380
312
|
if (typeof node[prop] === 'object' && node[prop]) {
|
|
381
313
|
traverseNodeSync(node[prop], `${path}.${prop}`);
|
|
382
314
|
}
|
|
383
|
-
else if (
|
|
315
|
+
else if (node[prop] === undefined) errors.push({ reason: 'missing', value: `${path}.${prop}` });
|
|
384
316
|
});
|
|
385
317
|
};
|
|
386
318
|
|
|
@@ -407,27 +339,27 @@ const checkConfig = (config) => {
|
|
|
407
339
|
*
|
|
408
340
|
* | Env variable name | Description | Value | Comments |
|
|
409
341
|
* | ----------------- | ----------- | ----- | -------- |
|
|
410
|
-
* | NODE_ENV |
|
|
342
|
+
* | NODE_ENV | environment of the microservice |
|
|
411
343
|
*/
|
|
412
344
|
export const isProd = () => {
|
|
413
|
-
if (
|
|
345
|
+
if (typeof process.env.NODE_ENV === 'string') return PRODUCTIONS.includes(process.env.NODE_ENV.toLowerCase());
|
|
414
346
|
return false;
|
|
415
347
|
};
|
|
416
348
|
|
|
417
349
|
process.env.SERVER_LOCAL_IPV4 = ip.address();
|
|
418
|
-
process.env.AWS_LOCAL_PROPERTIES =
|
|
419
|
-
process.env.CONSOLE_LEVEL ||=
|
|
420
|
-
process.env.LOG_LEVEL ||=
|
|
421
|
-
process.env.SERVER_ID ||=
|
|
350
|
+
process.env.AWS_LOCAL_PROPERTIES = '169.254.169.254';
|
|
351
|
+
process.env.CONSOLE_LEVEL ||= DEBUG;
|
|
352
|
+
process.env.LOG_LEVEL ||= DEBUG;
|
|
353
|
+
process.env.SERVER_ID ||= crypto.randomUUID();
|
|
422
354
|
|
|
423
355
|
const configuration = {
|
|
424
356
|
cache: {
|
|
425
|
-
set: process.env.CACHE_SET ||
|
|
357
|
+
set: process.env.CACHE_SET || SET_OFF,
|
|
426
358
|
},
|
|
427
|
-
cloudProvider: process.env.CLOUD_PROVIDER ||
|
|
359
|
+
cloudProvider: process.env.CLOUD_PROVIDER || 'noCloud',
|
|
428
360
|
cluster: {
|
|
429
|
-
management: process.env.CLUSTER_MANAGEMENT ||
|
|
430
|
-
timeout:
|
|
361
|
+
management: process.env.CLUSTER_MANAGEMENT || SET_OFF,
|
|
362
|
+
timeout: toInt(process.env.REQUEST_TIMEOUT, 10000),
|
|
431
363
|
},
|
|
432
364
|
dependencies: {
|
|
433
365
|
mIT: {
|
|
@@ -436,18 +368,18 @@ const configuration = {
|
|
|
436
368
|
},
|
|
437
369
|
},
|
|
438
370
|
encryption: {
|
|
439
|
-
set: process.env.ENCRYPTION_SET ||
|
|
371
|
+
set: process.env.ENCRYPTION_SET || SET_OFF,
|
|
440
372
|
},
|
|
441
|
-
locationProvider: process.env.LOCATION_PROVIDER ||
|
|
442
|
-
nodeEnvironment: process.env.NODE_ENV ||
|
|
373
|
+
locationProvider: process.env.LOCATION_PROVIDER || NO_PUBLIC_PROVIDER,
|
|
374
|
+
nodeEnvironment: process.env.NODE_ENV || LOCAL,
|
|
443
375
|
registration: {
|
|
444
|
-
set: process.env.REGISTRATION_SET ||
|
|
445
|
-
retry:
|
|
446
|
-
afterPostOpsSet: process.env.REGISTRATION_AFTER_POSTOPS_SET ||
|
|
376
|
+
set: process.env.REGISTRATION_SET || SET_ON,
|
|
377
|
+
retry: toInt(process.env.REGISTRATION_RETRY, 3000),
|
|
378
|
+
afterPostOpsSet: process.env.REGISTRATION_AFTER_POSTOPS_SET || SET_OFF,
|
|
447
379
|
},
|
|
448
380
|
security: {
|
|
449
381
|
admin: {
|
|
450
|
-
externalId: process.env.ADMIN_EXTERNAL_ID ||
|
|
382
|
+
externalId: process.env.ADMIN_EXTERNAL_ID || 'admin',
|
|
451
383
|
},
|
|
452
384
|
server: {
|
|
453
385
|
id: process.env.OAUTH_CLIENT_ID,
|
|
@@ -460,29 +392,29 @@ const configuration = {
|
|
|
460
392
|
key: process.env.OAUTH_GENERIC_KEY || NO_GENERIC,
|
|
461
393
|
audience: process.env.OAUTH_GENERIC_AUDIENCE || NO_GENERIC,
|
|
462
394
|
},
|
|
463
|
-
apiKeys: process.env.API_KEYS ?
|
|
395
|
+
apiKeys: process.env.API_KEYS ? process.env.API_KEYS.trim().split(/\s*,\s*/u) : [],
|
|
464
396
|
},
|
|
465
397
|
serverSettings: {
|
|
466
398
|
id: process.env.SERVER_ID,
|
|
467
|
-
customerCode: process.env.CUSTOMER_CODE ||
|
|
399
|
+
customerCode: process.env.CUSTOMER_CODE || '',
|
|
468
400
|
customerCodeSep: process.env.CUSTOMER_CODE ? CUSTOMER_CODE_SEP : '',
|
|
469
|
-
securitySet: process.env.SERVER_SECURITY_SET ||
|
|
401
|
+
securitySet: process.env.SERVER_SECURITY_SET || SET_ON,
|
|
470
402
|
isMSTSet,
|
|
471
|
-
port:
|
|
472
|
-
interceptError: process.env.INTERCEPT_ERROR ||
|
|
403
|
+
port: toInt(process.env.SERVER_PORT, undefined),
|
|
404
|
+
interceptError: process.env.INTERCEPT_ERROR || SET_ON,
|
|
473
405
|
ip: {
|
|
474
406
|
local: process.env.SERVER_LOCAL_IPV4,
|
|
475
407
|
},
|
|
476
408
|
public: {
|
|
477
|
-
protocol: process.env.SERVER_PUBLIC_PROTOCOL ||
|
|
478
|
-
domainName: process.env.SERVER_PUBLIC_DOMAIN_NAME ||
|
|
409
|
+
protocol: process.env.SERVER_PUBLIC_PROTOCOL || 'http:',
|
|
410
|
+
domainName: process.env.SERVER_PUBLIC_DOMAIN_NAME || null,
|
|
479
411
|
},
|
|
480
412
|
},
|
|
481
413
|
topic: {
|
|
482
|
-
set: process.env.TOPIC_SET ||
|
|
414
|
+
set: process.env.TOPIC_SET || SET_OFF,
|
|
483
415
|
},
|
|
484
416
|
userDefinitions: {
|
|
485
|
-
file: process.env.USER_DEFINITIONS_FILE ||
|
|
417
|
+
file: process.env.USER_DEFINITIONS_FILE || NOT_SET,
|
|
486
418
|
},
|
|
487
419
|
};
|
|
488
420
|
|
|
@@ -496,8 +428,8 @@ if (!isMSTSet) {
|
|
|
496
428
|
if (process.env.OAUTH_GENERIC_PREVIOUS_KEY) configuration.security.generic.previousKey = process.env.OAUTH_GENERIC_PREVIOUS_KEY;
|
|
497
429
|
if (process.env.BITBUCKET_USERNAME || process.env.BITBUCKET_PASSWORD) {
|
|
498
430
|
configuration.serverSettings.apiBasicAuth = {
|
|
499
|
-
username: process.env.BITBUCKET_USERNAME ||
|
|
500
|
-
password: process.env.BITBUCKET_PASSWORD ||
|
|
431
|
+
username: process.env.BITBUCKET_USERNAME || ' ',
|
|
432
|
+
password: process.env.BITBUCKET_PASSWORD || ' ',
|
|
501
433
|
};
|
|
502
434
|
}
|
|
503
435
|
if (process.env.SWAGGERHUB_API_KEY) {
|
|
@@ -513,10 +445,10 @@ configuration.locationProvider = setupLocationProvider();
|
|
|
513
445
|
*
|
|
514
446
|
* @function setConfig
|
|
515
447
|
* @category sync
|
|
516
|
-
* @param {
|
|
448
|
+
* @param {object} pack - `Package.json` object to use for the configuration.
|
|
517
449
|
* @param {object} options - Options to add to the config.
|
|
518
450
|
* @return {object} The configuration.
|
|
519
|
-
* @exception Will
|
|
451
|
+
* @exception Will throw an error if a mandatory value is missing.
|
|
520
452
|
*
|
|
521
453
|
* The following environment variables are being setup:
|
|
522
454
|
*
|
|
@@ -535,7 +467,7 @@ configuration.locationProvider = setupLocationProvider();
|
|
|
535
467
|
* | AWS_LOCAL_PROPERTIES | internal ip address to access aws instance properties | 169.254.169.254
|
|
536
468
|
* | MST_SET | to setup configuration without mST and oauth token setup | on | on/off
|
|
537
469
|
*
|
|
538
|
-
* The following
|
|
470
|
+
* The following environment variables are being used for the configuration:
|
|
539
471
|
*
|
|
540
472
|
* | Env variable name | Description | Default | Config property | Comments |
|
|
541
473
|
* | ----------------- | ----------- | ------- | ----------------| -------- |
|
|
@@ -543,18 +475,18 @@ configuration.locationProvider = setupLocationProvider();
|
|
|
543
475
|
* | LOCATION_PROVIDER | location provider URL to use for ip location or `noPublic` or `environment` | noPublic | locationProvider.url or locationProvider | `see public-helper`
|
|
544
476
|
* | LOCATION_PROVIDER_KEY | location provider key to use to access the location provider | null | locationProvider.key | see `public-helper`
|
|
545
477
|
* | CLOUD_PROVIDER | cloud provider running the service | noCloud | cloudProvider | see `public-helper`
|
|
546
|
-
* | SERVER_ID | service id |
|
|
478
|
+
* | SERVER_ID | service id | crypto.randomUUID() | serverSettings.id |
|
|
547
479
|
* | CUSTOMER_CODE | customer code associated with the service instance | '' | serverSettings.customerCode | empty string
|
|
548
|
-
* | SWAGGER_FILE_DIRECTORY | directory where the api definition is located |
|
|
480
|
+
* | SWAGGER_FILE_DIRECTORY | directory where the api definition is located | ../api | serverSettings.api | [1]
|
|
549
481
|
* | BITBUCKET_USERNAME | username to access bitbucket read access on the swagger repos | ' ' | serverSettings.apiBasicAuth.username
|
|
550
482
|
* | BITBUCKET_PASSWORD | password to access bitbucket read access on the swagger repos | ' ' | serverSettings.apiBasicAuth.password
|
|
551
483
|
* | SWAGGERHUB_API_KEY | apiKey to access swaggerhub | | serverSettings.apiApiKey
|
|
552
484
|
* | SERVER_SECURITY_SET | switch to enable or disable the token interpretation | on | serverSettings.securitySet | only active if environment is `local`
|
|
553
485
|
* | INTERCEPT_ERROR | switch to use or not the errorIntercept option | on | serverSettings.interceptError | must be set to off for mID
|
|
554
486
|
* | SERVER_PORT | port of the server | | serverSettings.port |
|
|
555
|
-
* | SERVER_PUBLIC_PROTOCOL | protocol used to
|
|
487
|
+
* | SERVER_PUBLIC_PROTOCOL | protocol used to define the domain address of the service | http: | serverSettings.public.protocol |
|
|
556
488
|
* | SERVER_PUBLIC_DOMAIN_NAME | domain name used to define the domain address of the service | null | serverSettings.public.domainName |
|
|
557
|
-
* | ADMIN_EXTERNAL_ID | external id of the admin role to be
|
|
489
|
+
* | ADMIN_EXTERNAL_ID | external id of the admin role to be checked in the token | admin | security.admin.externalId |
|
|
558
490
|
* | OAUTH_CLIENT_ID | security id of the service | | security.server.id | [2]
|
|
559
491
|
* | OAUTH_CLIENT_SECRET | secret of the service | | security.server.secret | [2]
|
|
560
492
|
* | OAUTH_CLIENT_ACCESS_KEY | key for token signature | | security.server.accessKey | [2]
|
|
@@ -563,9 +495,9 @@ configuration.locationProvider = setupLocationProvider();
|
|
|
563
495
|
* | OAUTH_GENERIC_KEY | key for token signature provided when a generic for this service type is defined | noGeneric | security.generic.key | [2]
|
|
564
496
|
* | OAUTH_GENERIC_PREVIOUS_KEY | key for the token signature before change the public key | | security.generic.previousKey | [2]
|
|
565
497
|
* | OAUTH_GENERIC_AUDIENCE | url representing the generic of the service type to mST | noGeneric | security.generic.audience | [2]
|
|
566
|
-
* | API_KEYS | list of API Keys which
|
|
567
|
-
* | LOG_MODE | collector
|
|
568
|
-
* | NO_STACK | disable the inclusion of
|
|
498
|
+
* | API_KEYS | list of API Keys which are tested against in case of APIKey security | [] |
|
|
499
|
+
* | LOG_MODE | collector to be used to log events | sumologic | logInfo.mode | can be `sumologic`, `awsS3`, `all`, 'awsKinesis'
|
|
500
|
+
* | NO_STACK | disable the inclusion of the stack in all logs | yes | logInfo.noStack
|
|
569
501
|
* | FILTER_FILE | path for the filter file definition | null | logInfo.filterFile |
|
|
570
502
|
* | USER_DEFINITIONS_FILE | path for the custom user definitions | null | userDefinitions.file |
|
|
571
503
|
* | EXIT_DELAY | delay to allow the log transports to flush | 2000 | logInfo.exitDelay | in milliseconds
|
|
@@ -578,23 +510,23 @@ configuration.locationProvider = setupLocationProvider();
|
|
|
578
510
|
* | ENCRYPTION_SET | switch to enable use of mongodb encryption | off | encryption.set | can be `on`, or `off`
|
|
579
511
|
* | MIT_URL | url for reaching mIT | | dependencies.mIT.url |
|
|
580
512
|
* | MIT_AUDIENCE | audience of mIT | | dependencies.mIT.audience | [2]
|
|
581
|
-
* | REGISTRATION_SET |
|
|
513
|
+
* | REGISTRATION_SET | switch to enable use of registration | on | registration.set | can be `on` or `off`
|
|
582
514
|
* | REGISTRATION_RETRY | retry time for registering to mIT | 3000 | registration.retry | in milliseconds
|
|
583
|
-
* | REGISTRATION_AFTER_POSTOPS_SET | switch to set the registration of execution the postOps | off |
|
|
515
|
+
* | REGISTRATION_AFTER_POSTOPS_SET | switch to set the registration of execution the postOps | off | registration.afterPostOpsSet | can be `on` or `off`
|
|
584
516
|
* | `${configuration.serverSettings.type}_URL`.toUpperCase() | cluster information | self | dependencies.`(SERVER_TYPE)`.url | should not be used
|
|
585
517
|
* | `${configuration.serverSettings.type}_AUDIENCE`.toUpperCase() | cluster information | | dependencies.`(SERVER_TYPE)`.audience | [2], but should not be used
|
|
586
518
|
*
|
|
587
|
-
* [1]: `/(SWAGGER_FILE_ACCOUNT)_(
|
|
519
|
+
* [1]: `/(SWAGGER_FILE_ACCOUNT)_(SWAGGER_FILE_NAME)_(SWAGGER_FILE_VERSION)_swagger.json` is added to the `serverSettings.api` property
|
|
588
520
|
*
|
|
589
521
|
* [2]: defined when registering to mST
|
|
590
522
|
*
|
|
591
|
-
* When MST_SET is `off`, registration and cluster should not be enabled, so configuration.cluster.management and configuration.registration.set will be set to `off
|
|
523
|
+
* When MST_SET is `off`, registration and cluster should not be enabled, so configuration.cluster.management and configuration.registration.set will be set to `off`
|
|
592
524
|
*
|
|
593
525
|
* When `sumologic` or `all` is used for `LOG_MODE` the following environment variables are used for the configuration:
|
|
594
526
|
*
|
|
595
527
|
* | Env variable name | Description | Default | Comments |
|
|
596
528
|
* | ----------------- | ----------- | ------- | -------- |
|
|
597
|
-
* | SUMO_LOGIC_ENDPOINT | endpoint of the sumologic collector
|
|
529
|
+
* | SUMO_LOGIC_ENDPOINT | endpoint of the sumologic collector used for logs |
|
|
598
530
|
* | SUMO_LOGIC_COLLECTOR_CODE | id of the collector in sumologic |
|
|
599
531
|
*
|
|
600
532
|
* When `awsS3` or `all` is used for `LOG_MODE` the following environment variables are used for the configuration:
|
|
@@ -618,7 +550,9 @@ configuration.locationProvider = setupLocationProvider();
|
|
|
618
550
|
* | SNS_AWS_REGION | region where the topic is | ----noRegion---- |
|
|
619
551
|
*
|
|
620
552
|
* When a database is involved
|
|
553
|
+
*
|
|
621
554
|
* | Env variable name | Description | Default | Comments |
|
|
555
|
+
* | ----------------- | ----------- | ------- | -------- |
|
|
622
556
|
* | DATABASE_CONNECTION_TIMEOUT | the time to connect to the database before error is generated | 30 | in seconds
|
|
623
557
|
* | DATABASE_VALIDATION_CHECK | the delay before checking for connection | 1000 | in ms
|
|
624
558
|
* | DATABASE_RECONNECTION_OFFSET | offset for the time to reconnect to the database before error is generated | 5 | in seconds
|
|
@@ -632,17 +566,17 @@ configuration.locationProvider = setupLocationProvider();
|
|
|
632
566
|
* | DATABASE_USER | user to access the database | null | if missing no user/password will be used
|
|
633
567
|
* | DATABASE_PASSWORD | password to access the database | null | if missing no user/password will be used
|
|
634
568
|
* | MONGO_USE_SRV | to use srv connection url set to `yes` | `no` |
|
|
635
|
-
* | MONGO_AUTH_DATABASE | the auth database where users
|
|
636
|
-
* |
|
|
637
|
-
* |
|
|
638
|
-
* | MONGO_MAX_IDLE_TIME | the maximum number of milliseconds that a connection can remain idle in the pool before being removed and closed |
|
|
569
|
+
* | MONGO_AUTH_DATABASE | the auth database where users exist | |
|
|
570
|
+
* | MONGO_MIN_POOL_SIZE | the minimum number of connections in the connection pool | 0 |
|
|
571
|
+
* | MONGO_MAX_POOL_SIZE | the maximum number of connections in the connection pool | 10 |
|
|
572
|
+
* | MONGO_MAX_IDLE_TIME | the maximum number of milliseconds that a connection can remain idle in the pool before being removed and closed | 30000 | in milliseconds
|
|
639
573
|
* | MONGO_RETRY_WRITES | defines if the transaction should be tried again to write set to true or false | |
|
|
640
574
|
* | MONGO_WRITE_CONCERN | accepts a number or `majority` | |
|
|
641
575
|
* | MONGO_SSL | uses ssl connection if `yes` | `no` |
|
|
642
576
|
* | MONGO_SSL_VALIDATE | validates mongod server certificate against ca if set to `yes` | `yes` | `yes` if MONGO_SSL is also `yes`
|
|
643
|
-
* | MONGO_SSL_ALLOW_INVALID_HOSTNAMES | set to yes to
|
|
577
|
+
* | MONGO_SSL_ALLOW_INVALID_HOSTNAMES | set to yes to allow invalid hostnames | |
|
|
644
578
|
* | MONGO_REPLICAT_SET | specifies the name of the replica set, if the mongod is a member of a replica set | | not mandatory
|
|
645
|
-
* | MONGO_WAIT_QUEUE_MULTIPLE | a number that the driver
|
|
579
|
+
* | MONGO_WAIT_QUEUE_MULTIPLE | a number that the driver multiplies the maxPoolSize value to, to provide the maximum number of threads allowed to wait for a connection to become available from the pool | | not mandatory
|
|
646
580
|
* | MONGO_WAIT_QUEUE_TIMEOUT | the maximum time in milliseconds that a thread can wait for a connection to become available | | not mandatory
|
|
647
581
|
* | MONGO_SOCKET_TIMEOUT | The time in milliseconds to attempt a send or receive on a socket before the attempt times out | 20000 | in milliseconds
|
|
648
582
|
* | MONGO_FAMILY | IP address family | 4 | 4 -> IPV4, 6 -> IPV6
|
|
@@ -662,7 +596,7 @@ configuration.locationProvider = setupLocationProvider();
|
|
|
662
596
|
* | ENCRYPTION_SECRET_ACCESS_KEY | if KMS is aws, secretAccessKey to connect KMS | |
|
|
663
597
|
* | LOCAL_MASTER_KEY | if KMS is local, masterkey to encrypt data keys | |
|
|
664
598
|
*
|
|
665
|
-
* When `dynamodb` is used the following
|
|
599
|
+
* When `dynamodb` is used the following environment variables are used for the configuration:
|
|
666
600
|
*
|
|
667
601
|
* | Env variable name | Description | Default | Comments |
|
|
668
602
|
* | ----------------- | ----------- | ------- | -------- |
|
|
@@ -676,13 +610,13 @@ configuration.locationProvider = setupLocationProvider();
|
|
|
676
610
|
* | DYNAMO_SCHEMA_THROUGHPUT_WRITE | throughput write for dynamodb schema | 1 |
|
|
677
611
|
* | DYNAMO_SCHEMA_THROUGHPUT | throughput for dynamodb schema |
|
|
678
612
|
*
|
|
679
|
-
* `DYNAMO_SCHEMA_THROUGHPUT` takes precedence over `DYNAMO_SCHEMA_THROUGHPUT_READ` and `DYNAMO_SCHEMA_THROUGHPUT_WRITE`. If DYNAMO_SCHEMA_THROUGHPUT is set to `ON_DEMAND` then index throughput
|
|
613
|
+
* `DYNAMO_SCHEMA_THROUGHPUT` takes precedence over `DYNAMO_SCHEMA_THROUGHPUT_READ` and `DYNAMO_SCHEMA_THROUGHPUT_WRITE`. If DYNAMO_SCHEMA_THROUGHPUT is set to `ON_DEMAND` then index throughput won't apply, and if DYNAMO_SCHEMA_THROUGHPUT is not set to a number the value will be 1.
|
|
680
614
|
*
|
|
681
|
-
* When `redis` is used the following
|
|
615
|
+
* When `redis` is used the following environment variables are used for the configuration:
|
|
682
616
|
*
|
|
683
617
|
* | Env variable name | Description | Default | Comments |
|
|
684
618
|
* | ----------------- | ----------- | ------- | -------- |
|
|
685
|
-
* | CACHE_IP | domain of the redis server to use with port, a comma
|
|
619
|
+
* | CACHE_IP | domain of the redis server to use with port, a comma separated list if using cluster | localhost:6379 |
|
|
686
620
|
* | CACHE_USER | redis user if the redis service is auth protected | null |
|
|
687
621
|
* | CACHE_PASSWORD | redis password for the user if the redis service is auth protected | null |
|
|
688
622
|
* | CACHE_CLUSTER_SET | set on, when using redis in a cluster. | off |
|
|
@@ -694,11 +628,11 @@ configuration.locationProvider = setupLocationProvider();
|
|
|
694
628
|
* | CACHE_REQUEST_TTL | request time to live in cache | 10 | in seconds
|
|
695
629
|
* | CACHE_API_ID_TTL | API request time to live for main resource | 20 | in seconds
|
|
696
630
|
* | CACHE_API_OPTION_TTL | API request time to live for option | 5 | in seconds
|
|
697
|
-
* | REDIS_RECONNECT_TRIES | number of tries to
|
|
631
|
+
* | REDIS_RECONNECT_TRIES | number of tries to reestablish a connection | 100 |
|
|
698
632
|
* | REDIS_RECONNECT_INTERVAL | time to wait before retry | 500 | in milliseconds
|
|
699
|
-
* | REDIS_REQUEST_MAX_MEMORY | maximum memory size of the request cache |
|
|
633
|
+
* | REDIS_REQUEST_MAX_MEMORY | maximum memory size of the request cache | 10mb | in megabytes
|
|
700
634
|
* | REDIS_REQUEST_MAX_MEMORY_POLICY | eviction policy of the request cache | allkeys-lru |
|
|
701
|
-
* | REDIS_SOCKET_KEEPALIVE | keep long
|
|
635
|
+
* | REDIS_SOCKET_KEEPALIVE | keep long-running connections alive | 5000 | in milliseconds
|
|
702
636
|
* | REDIS_DISABLE_OFFLINE_QUEUE | queuing event when not connected | no |
|
|
703
637
|
*/
|
|
704
638
|
export const setConfig = (pack, options) => {
|
|
@@ -710,16 +644,15 @@ export const setConfig = (pack, options) => {
|
|
|
710
644
|
process.env.SWAGGER_FILE_ACCOUNT = pack.swaggerFile.account;
|
|
711
645
|
process.env.SWAGGER_FILE_NAME = pack.swaggerFile.name;
|
|
712
646
|
if (pack.swaggerFile.provider) process.env.SWAGGER_FILE_PROVIDER = pack.swaggerFile.provider;
|
|
713
|
-
else process.env.SWAGGER_FILE_PROVIDER =
|
|
647
|
+
else process.env.SWAGGER_FILE_PROVIDER = 'bitbucket';
|
|
714
648
|
}
|
|
715
649
|
|
|
716
|
-
// eslint-disable-next-line max-len
|
|
717
650
|
const apiFilename = `${process.env.SWAGGER_FILE_ACCOUNT}${SWAGGER_SEP}${process.env.SWAGGER_FILE_NAME}${SWAGGER_SEP}${process.env.SWAGGER_FILE_VERSION}${SWAGGER_SEP}${SWAGGER_EXT}`;
|
|
718
651
|
|
|
719
652
|
configuration.serverSettings.name = process.env.SERVER_NAME;
|
|
720
653
|
configuration.serverSettings.type = process.env.SERVER_TYPE;
|
|
721
654
|
configuration.serverSettings.version = process.env.SERVER_VERSION;
|
|
722
|
-
configuration.serverSettings.api = `${process.env.SWAGGER_FILE_DIRECTORY ||
|
|
655
|
+
configuration.serverSettings.api = `${process.env.SWAGGER_FILE_DIRECTORY || '../api'}/${apiFilename}`;
|
|
723
656
|
configuration.serverSettings.swaggerFile = {
|
|
724
657
|
version: process.env.SWAGGER_FILE_VERSION,
|
|
725
658
|
name: process.env.SWAGGER_FILE_NAME,
|
|
@@ -751,15 +684,15 @@ export const setConfig = (pack, options) => {
|
|
|
751
684
|
configuration.dynamoose = setupDynamo(options.database);
|
|
752
685
|
}
|
|
753
686
|
else {
|
|
754
|
-
throw new Error(`database type
|
|
687
|
+
throw new Error(`database type not supported: ${options.database.type}`);
|
|
755
688
|
}
|
|
756
689
|
}
|
|
757
690
|
if (options.cache && configuration.cache.set === SET_ON) {
|
|
758
691
|
if (options.cache.type === 'redis') {
|
|
759
|
-
configuration.redisSettings = setupRedis(
|
|
692
|
+
configuration.redisSettings = setupRedis();
|
|
760
693
|
}
|
|
761
694
|
else {
|
|
762
|
-
throw new Error(`cache type
|
|
695
|
+
throw new Error(`cache type not supported: ${options.cache.type}`);
|
|
763
696
|
}
|
|
764
697
|
}
|
|
765
698
|
if (options.topic && configuration.topic.set === SET_ON) {
|
|
@@ -791,7 +724,7 @@ export const setConfig = (pack, options) => {
|
|
|
791
724
|
}
|
|
792
725
|
if (options.security) {
|
|
793
726
|
Object.keys(options.security).forEach((securityItem) => {
|
|
794
|
-
if (configuration.security
|
|
727
|
+
if (securityItem in configuration.security) {
|
|
795
728
|
Object.keys(options.security[securityItem]).forEach((subSecurityItem) => {
|
|
796
729
|
configuration.security[securityItem][subSecurityItem] = options.security[securityItem][subSecurityItem];
|
|
797
730
|
});
|