@mimik/configuration 4.4.4 → 4.4.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/README.md CHANGED
@@ -99,6 +99,8 @@ The following environement variables are being used for the configuration:
99
99
 
100
100
  [2]: defined when registering to mST
101
101
 
102
+ 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``
103
+
102
104
  When `sumologic` or `all` is used for `LOG_MODE` the following environment variables are used for the configuration:
103
105
 
104
106
  | Env variable name | Description | Default | Comments |
package/index.js CHANGED
@@ -17,6 +17,7 @@ const {
17
17
  AWS_S3,
18
18
  ALL,
19
19
  SET_ON,
20
+ SET_OFF,
20
21
  NO_PUBLIC_PROVIDER,
21
22
  NO_GENERIC,
22
23
  ENV_VARIABLE,
@@ -89,7 +90,7 @@ const {
89
90
  let display = true;
90
91
  const locParams = [NO_PUBLIC_PROVIDER, ENV_VARIABLE];
91
92
  const correlationIdStart = getCorrelationId('config-start');
92
- const isMSTSet = process.env.MST_SET !== 'off';
93
+ const isMSTSet = process.env.MST_SET !== SET_OFF;
93
94
 
94
95
  const setupRedis = () => {
95
96
  const domain = process.env.CACHE_IP || DEFAULT_CACHE_IP;
@@ -134,7 +135,6 @@ const setupRedis = () => {
134
135
  idTTL: parseInt(process.env.CACHE_API_ID_TTL, 10) || DEFAULT_CACHE_API_ID_TTL,
135
136
  optionTTL: parseInt(process.env.CACHE_API_OPTION_TTL, 10) || DEFAULT_CACHE_API_OPTION_TTL,
136
137
  },
137
- isMSTSet,
138
138
  };
139
139
  };
140
140
 
@@ -303,22 +303,25 @@ const setupEncryption = (encryptionOpts) => {
303
303
  };
304
304
 
305
305
  const checkConfig = (config) => {
306
- const errs = [];
306
+ const errors = [];
307
307
 
308
308
  function traverseNodeSync(node, path) {
309
309
  Object.keys(node).forEach((prop) => {
310
310
  if (typeof node[prop] === 'object' && node[prop]) {
311
311
  traverseNodeSync(node[prop], `${path}.${prop}`);
312
312
  }
313
- else if (_.isUndefined(node[prop])) errs.push(`${path}.${prop}`);
313
+ else if (_.isUndefined(node[prop])) errors.push({ reason: 'missing', value: `${path}.${prop}` });
314
314
  });
315
315
  }
316
316
 
317
317
  traverseNodeSync(config, 'configuration');
318
- if (errs.length > 0) {
319
- const error = new Error('Missing values');
318
+ // dependency errors
319
+ if (!isMSTSet && config.security.apiKeys.length === 0) errors.push({ reason: 'invalid', value: 'config.security.apiKeys', cause: 'isMSTSet' });
320
+
321
+ if (errors.length > 0) {
322
+ const error = new Error('Errors in configuration');
320
323
 
321
- logger.error(error, { values: errs }, correlationIdStart);
324
+ logger.error(error, { errors }, correlationIdStart);
322
325
  throw error;
323
326
  }
324
327
  };
@@ -356,6 +359,7 @@ const configuration = {
356
359
  customerCode: process.env.CUSTOMER_CODE || DEFAULT_CUSTOMER_CODE,
357
360
  customerCodeSep: process.env.CUSTOMER_CODE ? CUSTOMER_CODE_SEP : '',
358
361
  securitySet: process.env.SERVER_SECURITY_SET || DEFAULT_SERVER_SECURITY_SET,
362
+ isMSTSet,
359
363
  port: process.env.SERVER_PORT,
360
364
  interceptError: process.env.INTERCEPT_ERROR || DEFAULT_INTERCEPT_ERROR,
361
365
  ip: {
@@ -370,7 +374,7 @@ const configuration = {
370
374
  admin: {
371
375
  externalId: process.env.ADMIN_EXTERNAL_ID || DEFAULT_ADMIN_EXTERNAL_ID,
372
376
  },
373
- server: !isMSTSet ? {} : {
377
+ server: {
374
378
  id: process.env.OAUTH_CLIENT_ID,
375
379
  secret: process.env.OAUTH_CLIENT_SECRET,
376
380
  accessKey: process.env.OAUTH_CLIENT_ACCESS_KEY,
@@ -396,7 +400,7 @@ const configuration = {
396
400
  topic: {
397
401
  set: process.env.TOPIC_SET || DEFAULT_TOPIC_SET,
398
402
  },
399
- dependencies: !isMSTSet ? {} : { // every server will report to mIT unless mST setup is disabled
403
+ dependencies: {
400
404
  mIT: {
401
405
  url: process.env.MIT_URL,
402
406
  audience: process.env.MIT_AUDIENCE,
@@ -408,6 +412,13 @@ const configuration = {
408
412
  },
409
413
  };
410
414
 
415
+ // cross dependencies
416
+ if (!isMSTSet) {
417
+ configuration.registration.set = SET_OFF;
418
+ configuration.cluster.management = SET_OFF;
419
+ configuration.security.server = {};
420
+ configuration.dependencies = {};
421
+ }
411
422
  if (process.env.OAUTH_GENERIC_PREVIOUS_KEY) configuration.security.generic.previousKey = process.env.OAUTH_GENERIC_PREVIOUS_KEY;
412
423
  if (process.env.SWAGGER_API_KEY) configuration.serverSettings.apiKey = process.env.SWAGGER_API_KEY;
413
424
  configuration.logInfo = setupLog();
@@ -488,6 +499,8 @@ configuration.locationProvider = setupLocationProvider();
488
499
  *
489
500
  * [2]: defined when registering to mST
490
501
  *
502
+ * 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``
503
+ *
491
504
  * When `sumologic` or `all` is used for `LOG_MODE` the following environment variables are used for the configuration:
492
505
  *
493
506
  * | Env variable name | Description | Default | Comments |
package/lib/common.js CHANGED
@@ -91,6 +91,7 @@ module.exports = {
91
91
  AWS_S3,
92
92
  ALL,
93
93
  SET_ON,
94
+ SET_OFF,
94
95
  CUSTOMER_CODE_SEP,
95
96
  NO_PUBLIC_PROVIDER,
96
97
  NO_GENERIC,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mimik/configuration",
3
- "version": "4.4.4",
3
+ "version": "4.4.8",
4
4
  "description": "Common configuration for mimik services",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -38,7 +38,7 @@
38
38
  "devDependencies": {
39
39
  "@mimik/eslint-plugin-dependencies": "^2.4.1",
40
40
  "@mimik/eslint-plugin-document-env": "^1.0.1",
41
- "eslint": "8.6.0",
41
+ "eslint": "8.7.0",
42
42
  "eslint-config-airbnb": "18.2.1",
43
43
  "eslint-plugin-import": "2.25.4",
44
44
  "eslint-plugin-jsx-a11y": "6.5.1",