@mimik/configuration 4.4.6 → 4.4.9

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
@@ -82,6 +82,7 @@ The following environement variables are being used for the configuration:
82
82
  | LOG_MODE | collector the be used to log events | sumologic | logInfo.mode | can be `sumologic`, `awsS3`, `all`, 'awsKinesis'
83
83
  | NO_STACK | disable the inclusion of a the stack in all logs | yes | logInfo.noStack
84
84
  | FILTER_FILE | path for the filter file definition | null | logInfo.filterFile |
85
+ | USER_DEFINITIONS_FILE | path for the custom user definitions | null | userDefinitions.file |
85
86
  | EXIT_DELAY | delay to allow the log transports to flush | 2000 | logInfo.exitDelay | in milliseconds
86
87
  | CLUSTER_MANAGEMENT | switch to enable cluster communication | off | cluster.management | can be `on` or `off`
87
88
  | REQUEST_TIMEOUT | timeout for intra cluster http request | 10000 | cluster.timeout | in milliseconds
package/index.js CHANGED
@@ -1,11 +1,13 @@
1
1
  /* eslint no-process-env: "off" */
2
2
  const _ = require('lodash');
3
+ const fs = require('fs');
3
4
  const ip = require('ip');
4
5
  const uuid = require('uuid');
5
6
  const querystring = require('querystring');
6
7
 
7
8
  const logger = require('@mimik/sumologic-winston-logger');
8
9
  const { getCorrelationId } = require('@mimik/request-helper');
10
+ const { userDefinitions } = require('@mimik/user-filters');
9
11
  /**
10
12
  * @module configuration
11
13
  * @example
@@ -70,6 +72,7 @@ const {
70
72
  DEFAULT_FILTER_FILE,
71
73
  DEFAULT_EXIT_DELAY,
72
74
  DEFAULT_NO_STACK,
75
+ DEFAULT_USER_DEFINITIONS_FILE,
73
76
  DEFAULT_S3_AWS_TIMEOUT,
74
77
  DEFAULT_S3_AWS_MAX_SIZE,
75
78
  DEFAULT_S3_AWS_MAX_EVENTS,
@@ -135,7 +138,6 @@ const setupRedis = () => {
135
138
  idTTL: parseInt(process.env.CACHE_API_ID_TTL, 10) || DEFAULT_CACHE_API_ID_TTL,
136
139
  optionTTL: parseInt(process.env.CACHE_API_OPTION_TTL, 10) || DEFAULT_CACHE_API_OPTION_TTL,
137
140
  },
138
- isMSTSet,
139
141
  };
140
142
  };
141
143
 
@@ -303,23 +305,42 @@ const setupEncryption = (encryptionOpts) => {
303
305
  return encryptionConfig;
304
306
  };
305
307
 
308
+ const setupUserDefinitions = (definitions) => {
309
+ const userDefinitionsFile = definitions.file;
310
+ let customDefinitions = {};
311
+ if (userDefinitionsFile && userDefinitionsFile !== DEFAULT_USER_DEFINITIONS_FILE) {
312
+ try { customDefinitions = JSON.parse(fs.readFileSync(userDefinitionsFile).toString()); }
313
+ catch (err) {
314
+ throw new Error(`Invalid file for user definitions: ${userDefinitionsFile}, error: ${err.message}`);
315
+ }
316
+ }
317
+ return {
318
+ ...userDefinitions,
319
+ ...customDefinitions,
320
+ file: userDefinitionsFile,
321
+ };
322
+ };
323
+
306
324
  const checkConfig = (config) => {
307
- const errs = [];
325
+ const errors = [];
308
326
 
309
327
  function traverseNodeSync(node, path) {
310
328
  Object.keys(node).forEach((prop) => {
311
329
  if (typeof node[prop] === 'object' && node[prop]) {
312
330
  traverseNodeSync(node[prop], `${path}.${prop}`);
313
331
  }
314
- else if (_.isUndefined(node[prop])) errs.push(`${path}.${prop}`);
332
+ else if (_.isUndefined(node[prop])) errors.push({ reason: 'missing', value: `${path}.${prop}` });
315
333
  });
316
334
  }
317
335
 
318
336
  traverseNodeSync(config, 'configuration');
319
- if (errs.length > 0) {
320
- const error = new Error('Missing values');
337
+ // dependency errors
338
+ if (!isMSTSet && config.security.apiKeys.length === 0) errors.push({ reason: 'invalid', value: 'config.security.apiKeys', cause: 'isMSTSet' });
339
+
340
+ if (errors.length > 0) {
341
+ const error = new Error('Errors in configuration');
321
342
 
322
- logger.error(error, { values: errs }, correlationIdStart);
343
+ logger.error(error, { errors }, correlationIdStart);
323
344
  throw error;
324
345
  }
325
346
  };
@@ -372,7 +393,7 @@ const configuration = {
372
393
  admin: {
373
394
  externalId: process.env.ADMIN_EXTERNAL_ID || DEFAULT_ADMIN_EXTERNAL_ID,
374
395
  },
375
- server: !isMSTSet ? {} : {
396
+ server: {
376
397
  id: process.env.OAUTH_CLIENT_ID,
377
398
  secret: process.env.OAUTH_CLIENT_SECRET,
378
399
  accessKey: process.env.OAUTH_CLIENT_ACCESS_KEY,
@@ -395,10 +416,13 @@ const configuration = {
395
416
  encryption: {
396
417
  set: process.env.ENCRYPTION_SET || DEFAULT_ENCRYPTION_SET,
397
418
  },
419
+ userDefinitions: {
420
+ file: process.env.USER_DEFINITIONS_FILE || DEFAULT_USER_DEFINITIONS_FILE,
421
+ },
398
422
  topic: {
399
423
  set: process.env.TOPIC_SET || DEFAULT_TOPIC_SET,
400
424
  },
401
- dependencies: !isMSTSet ? {} : { // every server will report to mIT unless mST setup is disabled
425
+ dependencies: {
402
426
  mIT: {
403
427
  url: process.env.MIT_URL,
404
428
  audience: process.env.MIT_AUDIENCE,
@@ -410,9 +434,12 @@ const configuration = {
410
434
  },
411
435
  };
412
436
 
437
+ // cross dependencies
413
438
  if (!isMSTSet) {
414
439
  configuration.registration.set = SET_OFF;
415
440
  configuration.cluster.management = SET_OFF;
441
+ configuration.security.server = {};
442
+ configuration.dependencies = {};
416
443
  }
417
444
  if (process.env.OAUTH_GENERIC_PREVIOUS_KEY) configuration.security.generic.previousKey = process.env.OAUTH_GENERIC_PREVIOUS_KEY;
418
445
  if (process.env.SWAGGER_API_KEY) configuration.serverSettings.apiKey = process.env.SWAGGER_API_KEY;
@@ -477,6 +504,7 @@ configuration.locationProvider = setupLocationProvider();
477
504
  * | LOG_MODE | collector the be used to log events | sumologic | logInfo.mode | can be `sumologic`, `awsS3`, `all`, 'awsKinesis'
478
505
  * | NO_STACK | disable the inclusion of a the stack in all logs | yes | logInfo.noStack
479
506
  * | FILTER_FILE | path for the filter file definition | null | logInfo.filterFile |
507
+ * | USER_DEFINITIONS_FILE | path for the custom user definitions | null | userDefinitions.file |
480
508
  * | EXIT_DELAY | delay to allow the log transports to flush | 2000 | logInfo.exitDelay | in milliseconds
481
509
  * | CLUSTER_MANAGEMENT | switch to enable cluster communication | off | cluster.management | can be `on` or `off`
482
510
  * | REQUEST_TIMEOUT | timeout for intra cluster http request | 10000 | cluster.timeout | in milliseconds
@@ -656,6 +684,9 @@ const setConfig = (pack, options) => {
656
684
  if (options.encryption && configuration.encryption.set === SET_ON) {
657
685
  configuration.encryption = setupEncryption(options.encryption);
658
686
  }
687
+ if (options.userDefinitions) {
688
+ configuration.userDefinitions = setupUserDefinitions(options.userDefinitions);
689
+ }
659
690
  if (options.dependencies) {
660
691
  Object.keys(options.dependencies).forEach((dependency) => {
661
692
  if (isMSTSet) {
package/lib/common.js CHANGED
@@ -3,6 +3,7 @@ const AWS_S3 = 'awsS3';
3
3
  const ALL = 'all';
4
4
  const SET_ON = 'on';
5
5
  const SET_OFF = 'off';
6
+ const NOT_SET = 'not set';
6
7
  const NO_GENERIC = '--noGeneric--';
7
8
  const NO_PUBLIC_PROVIDER = 'noPublic';
8
9
  const ENV_VARIABLE = 'environment';
@@ -61,10 +62,12 @@ const DEFAULT_ENCRYPTION_SET = SET_OFF;
61
62
  const DEFAULT_KMS_PROVIDER = 'local';
62
63
 
63
64
  const DEFAULT_LOG_LEVEL = 'debug';
64
- const DEFAULT_FILTER_FILE = 'not set';
65
+ const DEFAULT_FILTER_FILE = NOT_SET;
65
66
  const DEFAULT_EXIT_DELAY = 2000; // in ms
66
67
  const DEFAULT_NO_STACK = 'yes';
67
68
 
69
+ const DEFAULT_USER_DEFINITIONS_FILE = NOT_SET;
70
+
68
71
  const DEFAULT_S3_AWS_TIMEOUT = 5; // in minutes
69
72
  const DEFAULT_S3_AWS_MAX_SIZE = 5; // in mB
70
73
  const DEFAULT_S3_AWS_MAX_EVENTS = 1000;
@@ -144,6 +147,7 @@ module.exports = {
144
147
  DEFAULT_FILTER_FILE,
145
148
  DEFAULT_EXIT_DELAY,
146
149
  DEFAULT_NO_STACK,
150
+ DEFAULT_USER_DEFINITIONS_FILE,
147
151
  DEFAULT_S3_AWS_TIMEOUT,
148
152
  DEFAULT_S3_AWS_MAX_SIZE,
149
153
  DEFAULT_S3_AWS_MAX_EVENTS,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mimik/configuration",
3
- "version": "4.4.6",
3
+ "version": "4.4.9",
4
4
  "description": "Common configuration for mimik services",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -31,6 +31,7 @@
31
31
  "dependencies": {
32
32
  "@mimik/request-helper": "^1.7.3",
33
33
  "@mimik/sumologic-winston-logger": "^1.6.6",
34
+ "@mimik/user-filters": "1.3.3",
34
35
  "ip": "1.1.5",
35
36
  "lodash": "4.17.21",
36
37
  "uuid": "8.3.2"
@@ -38,17 +39,17 @@
38
39
  "devDependencies": {
39
40
  "@mimik/eslint-plugin-dependencies": "^2.4.1",
40
41
  "@mimik/eslint-plugin-document-env": "^1.0.1",
41
- "eslint": "8.7.0",
42
+ "eslint": "8.13.0",
42
43
  "eslint-config-airbnb": "18.2.1",
43
- "eslint-plugin-import": "2.25.4",
44
+ "eslint-plugin-import": "2.26.0",
44
45
  "eslint-plugin-jsx-a11y": "6.5.1",
45
- "eslint-plugin-react": "7.28.0",
46
- "eslint-plugin-react-hooks": "4.3.0",
46
+ "eslint-plugin-react": "7.29.4",
47
+ "eslint-plugin-react-hooks": "4.4.0",
47
48
  "fancy-log": "2.0.0",
48
49
  "gulp": "4.0.2",
49
50
  "gulp-eslint": "6.0.0",
50
51
  "gulp-git": "2.10.1",
51
52
  "husky": "7.0.4",
52
- "jsdoc-to-markdown": "7.1.0"
53
+ "jsdoc-to-markdown": "7.1.1"
53
54
  }
54
55
  }