@contrast/core 1.14.0 → 1.16.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.
@@ -15,18 +15,19 @@
15
15
 
16
16
  'use strict';
17
17
 
18
+ const REDACTED_KEYS = ['api.api_key', 'api.service_key'];
18
19
  const { Event, featureReaders, settingsReaders, mergeRemoteData } = require('@contrast/common');
19
20
  const { configOptions } = require('@contrast/config/lib/options');
20
21
 
21
22
  module.exports = function(core) {
22
23
  const { config, messages } = core;
23
24
  const effectiveConfig = createEffectiveConfig({ config, remoteData: {} });
24
- let Status = '';
25
+ let status = '';
25
26
 
26
27
  if (core.config?.protect?.enable === true) {
27
28
  messages.on(Event.SERVER_SETTINGS_UPDATE, (msg) => {
28
- if (!Status) {
29
- Status = 'Success';
29
+ if (!status) {
30
+ status = 'Success';
30
31
  }
31
32
 
32
33
  mergeRemoteData(config, msg, featureReaders, setterFn, effectiveConfig);
@@ -34,8 +35,8 @@ module.exports = function(core) {
34
35
  });
35
36
  }
36
37
 
37
- core.getEffectiveConfig = function () {
38
- return formatEffectiveConfig(effectiveConfig);
38
+ core.getEffectiveConfig = function (tsFriendly = false) {
39
+ return formatEffectiveConfig(effectiveConfig, tsFriendly);
39
40
  };
40
41
 
41
42
  return;
@@ -44,34 +45,46 @@ module.exports = function(core) {
44
45
  let remoteValue = value;
45
46
  if (typeof value === 'string') remoteValue = remoteValue.toLowerCase();
46
47
  target.set(name, {
47
- CanonicalName: name,
48
- Name: name,
49
- Value: remoteValue,
50
- Source: 'ContrastUI',
48
+ canonical_name: name,
49
+ name,
50
+ value: remoteValue,
51
+ source: 'CONTRAST_UI',
51
52
  });
52
53
  }
53
54
 
54
- function createEffectiveConfig({ config, remoteData }) {
55
- const list = configOptions.map(({ name }) => ({
56
- CanonicalName: name,
57
- Name: name,
58
- Value: config._flat[name],
59
- Source: config._sources[name]
60
- }));
61
-
62
- return new Map(list.map((entry) => [entry.CanonicalName, entry]));
55
+ function createEffectiveConfig({ config }) {
56
+ return new Map(configOptions.map(({ name }) => [name, {
57
+ canonical_name: name,
58
+ name,
59
+ value: config._flat[name],
60
+ source: config._sources[name]
61
+ }]));
63
62
  }
64
63
 
65
- function formatEffectiveConfig(configMap) {
66
- const values = Array.from(configMap.values()).filter(s => s.Value != undefined);
64
+ function formatEffectiveConfig(configMap, tsFriendly = false) {
65
+ const effective_config = [], environment_variable = [], contrast_ui = [];
66
+ Array.from(configMap.values()).forEach((v) => {
67
+ if (v.value != undefined) {
68
+ if (tsFriendly) {
69
+ const value = REDACTED_KEYS.includes(v.name)
70
+ ? `contrast-redacted-${v.name}`
71
+ : v.value.toString();
72
+ effective_config.push({ ...v, value });
73
+ } else {
74
+ effective_config.push(v);
75
+ }
76
+ }
77
+ if (v.source === 'ENVIRONMENT_VARIABLE') environment_variable.push(v);
78
+ if (v.source === 'CONTRAST_UI') contrast_ui.push(v);
79
+ });
80
+
67
81
  const content = {
68
- Status,
69
- ReportCreate: new Date(),
70
- Config: {
71
- EffectiveConfig: values,
72
- Environment: values.filter(v => v.Source === 'ENV'),
73
- ContrastUI: values.filter(v => v.Source === 'ContrastUI'),
74
- File: values.filter(v => v.Source === 'YAML'),
82
+ report_create: new Date(),
83
+ config: {
84
+ status,
85
+ effective_config,
86
+ environment_variable,
87
+ contrast_ui,
75
88
  }
76
89
  };
77
90
 
package/lib/index.d.ts CHANGED
@@ -13,6 +13,7 @@
13
13
  * way not consistent with the End User License Agreement.
14
14
  */
15
15
 
16
+ import { EventEmitter } from 'events';
16
17
  import { Agentify } from '@contrast/agentify';
17
18
  import { Config } from '@contrast/config';
18
19
  import { Logger } from '@contrast/logger';
@@ -34,12 +35,14 @@ export interface Core {
34
35
  appInfo: AppInfo;
35
36
  logger: Logger;
36
37
  messages: Messages;
38
+ events: { lifecycle: EventEmitter };
37
39
  patcher: Patcher;
38
40
  reporter: ReporterBus;
39
41
  protect: Protect;
40
42
  rewriter: Rewriter;
41
43
  scopes: Scopes;
42
44
  deadzones: Deadzones;
45
+ getEffectiveConfig: any;
43
46
  }
44
47
 
45
48
  declare function init(): Core;
package/lib/index.js CHANGED
@@ -19,6 +19,10 @@ const EventEmitter = require('events');
19
19
 
20
20
  module.exports = function init(core = {}) {
21
21
  core.messages = new EventEmitter();
22
+ core.events = {
23
+ lifecycle: new EventEmitter(),
24
+ // messages: new EventEmitter(),
25
+ };
22
26
  require('./agent-info')(core);
23
27
  require('@contrast/config')(core);
24
28
  require('./logger-factory')(core);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@contrast/core",
3
- "version": "1.14.0",
3
+ "version": "1.16.0",
4
4
  "description": "Preconfigured Contrast agent core services and models",
5
5
  "license": "SEE LICENSE IN LICENSE",
6
6
  "author": "Contrast Security <nodejs@contrastsecurity.com> (https://www.contrastsecurity.com)",
@@ -17,16 +17,16 @@
17
17
  "test": "../scripts/test.sh"
18
18
  },
19
19
  "dependencies": {
20
- "@contrast/agentify": "1.5.1",
21
- "@contrast/common": "1.7.0",
22
- "@contrast/config": "1.9.0",
20
+ "@contrast/agentify": "1.7.0",
21
+ "@contrast/common": "1.9.0",
22
+ "@contrast/config": "1.11.0",
23
23
  "@contrast/deadzones": "1.1.0",
24
24
  "@contrast/dep-hooks": "1.1.0",
25
25
  "@contrast/fn-inspect": "^3.2.0",
26
26
  "@contrast/instrumentation": "1.1.1",
27
- "@contrast/logger": "1.2.0",
28
- "@contrast/patcher": "1.2.0",
29
- "@contrast/reporter": "1.12.0",
27
+ "@contrast/logger": "1.3.0",
28
+ "@contrast/patcher": "1.4.0",
29
+ "@contrast/reporter": "1.14.0",
30
30
  "@contrast/rewriter": "1.4.0",
31
31
  "@contrast/scopes": "1.3.0"
32
32
  }