@contrast/config 1.3.3 → 1.5.0

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/lib/options.js CHANGED
@@ -382,12 +382,23 @@ const protect = [
382
382
  fn: castBoolean,
383
383
  desc: 'turns on probe analysis and report them to Contrast UI'
384
384
  },
385
- ...Object.values(Rule).map((ruleId) => ({
386
- name: `protect.rules.${ruleId}.mode`,
387
- arg: '<mode>',
388
- enum: ['monitor', 'block', 'block_at_perimeter', 'off'],
389
- desc: `the mode in which to run the ${ruleId} rule`,
390
- })),
385
+ ...Object.values(Rule)
386
+ .filter((ruleId) => ![Rule.BOT_BLOCKER, Rule.IP_DENYLIST, Rule.VIRTUAL_PATCH].includes(ruleId))
387
+ .map((ruleId) => ({
388
+ name: `protect.rules.${ruleId}.mode`,
389
+ arg: '<mode>',
390
+ enum: ['monitor', 'block', 'block_at_perimeter', 'off'],
391
+ desc: `the mode in which to run the ${ruleId} rule`,
392
+ })),
393
+ ];
394
+
395
+ const assess = [
396
+ {
397
+ name: 'assess.enable',
398
+ arg: '[false]',
399
+ fn: castBoolean,
400
+ desc: 'if false, disable assess for this agent'
401
+ },
391
402
  ];
392
403
 
393
404
  const server = [
@@ -417,7 +428,15 @@ const server = [
417
428
  },
418
429
  ];
419
430
 
420
- const options = [].concat(config, api, agent, application, protect, server);
431
+ const options = [].concat(
432
+ config,
433
+ api,
434
+ agent,
435
+ application,
436
+ protect,
437
+ assess,
438
+ server
439
+ );
421
440
 
422
441
  module.exports.configOptions = options;
423
442
  module.exports.clearBaseCase = clearBaseCase;
package/lib/util.js CHANGED
@@ -42,9 +42,11 @@ function set(obj, name, value) {
42
42
  * @param {*} value
43
43
  * @param {boolean} def set from default or not
44
44
  */
45
- function setConfig(conf, name, value, def) {
45
+ function setConfig(conf, name, value, def, origin) {
46
46
  set(conf, name, value);
47
47
  conf._default[name] = def;
48
+ conf._flat[name] = value;
49
+ conf._sources[name] = origin;
48
50
  }
49
51
 
50
52
  class ConfigurationError extends Error {
@@ -57,7 +59,8 @@ class Config {
57
59
  constructor() {
58
60
  Object.assign(this, {
59
61
  _default: {},
60
- api: {},
62
+ _flat: {},
63
+ _sources: {},
61
64
  agent: {
62
65
  reporters: {},
63
66
  logger: {},
@@ -67,7 +70,9 @@ class Config {
67
70
  protect: {
68
71
  rules: {},
69
72
  },
73
+ assess: {},
70
74
  server: {},
75
+ api: {},
71
76
  });
72
77
  }
73
78
 
@@ -243,12 +248,17 @@ function mergeOptions() {
243
248
  .reduce((obj, prop) => obj?.[prop], fileOptions);
244
249
 
245
250
  // For some values, we want to know if we assigned by falling back to default
246
- let isFromDefault;
251
+ let isFromDefault, origin;
252
+
253
+ if (env != null || autoEnv != null) {
254
+ origin = 'ENV';
255
+ } else if (fileFlag != null) {
256
+ origin = 'YAML';
257
+ }
247
258
 
248
259
  // env > file > default
249
260
  let value = [env, autoEnv, fileFlag]
250
- .map((v) => fn(v))
251
- .find((flag) => flag !== undefined);
261
+ .map((v) => fn(v)).find((flag) => flag !== undefined);
252
262
 
253
263
  // if it's an enum, find it in the enum or set the value to default
254
264
  // ineffective if optDefault wasn't in the enum;
@@ -256,6 +266,7 @@ function mergeOptions() {
256
266
  if (optEnum && optEnum.indexOf(value) === -1) {
257
267
  value = fn(optDefault);
258
268
  isFromDefault = true;
269
+ origin = 'DEFAULT';
259
270
  }
260
271
 
261
272
  // set default last and separately, so that we can mark that the option was
@@ -263,9 +274,10 @@ function mergeOptions() {
263
274
  if (value === undefined) {
264
275
  value = fn(optDefault);
265
276
  isFromDefault = true;
277
+ origin = 'DEFAULT';
266
278
  }
267
279
 
268
- setConfig(options, name, value, isFromDefault);
280
+ setConfig(options, name, value, isFromDefault, origin);
269
281
  return options;
270
282
  }, new Config());
271
283
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@contrast/config",
3
- "version": "1.3.3",
3
+ "version": "1.5.0",
4
4
  "description": "An API for discovering Contrast agent configuration data",
5
5
  "license": "SEE LICENSE IN LICENSE",
6
6
  "author": "Contrast Security <nodejs@contrastsecurity.com> (https://www.contrastsecurity.com)",
@@ -17,7 +17,7 @@
17
17
  "test": "../scripts/test.sh"
18
18
  },
19
19
  "dependencies": {
20
- "@contrast/common": "1.1.5",
20
+ "@contrast/common": "1.3.0",
21
21
  "yaml": "^2.0.1"
22
22
  }
23
- }
23
+ }