@contrast/core 1.10.2 → 1.11.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/index.js CHANGED
@@ -23,6 +23,7 @@ module.exports = function init(core = {}) {
23
23
  require('@contrast/config')(core);
24
24
  require('./logger-factory')(core);
25
25
  require('./effective-config')(core);
26
+ require('./system-info')(core);
26
27
  require('./sensitive-data-masking')(core);
27
28
  require('./app-info')(core);
28
29
  require('./is-agent-path')(core);
@@ -0,0 +1,118 @@
1
+ /*
2
+ * Copyright: 2022 Contrast Security, Inc
3
+ * Contact: support@contrastsecurity.com
4
+ * License: Commercial
5
+
6
+ * NOTICE: This Software and the patented inventions embodied within may only be
7
+ * used as part of Contrast Security’s commercial offerings. Even though it is
8
+ * made available through public repositories, use of this Software is subject to
9
+ * the applicable End User Licensing Agreement found at
10
+ * https://www.contrastsecurity.com/enduser-terms-0317a or as otherwise agreed
11
+ * between Contrast Security and the End User. The Software may not be reverse
12
+ * engineered, modified, repackaged, sold, redistributed or otherwise used in a
13
+ * way not consistent with the End User License Agreement.
14
+ */
15
+
16
+ 'use strict';
17
+
18
+ const path = require('path');
19
+ const fs = require('fs');
20
+ const os = require('os');
21
+
22
+ function isUsingPM2() {
23
+ const used = !!process.env.pmx;
24
+ let version = null;
25
+
26
+ for (const pathVar of ['npm_package_json', 'PWD']) {
27
+ const packagePath = process.env[pathVar];
28
+ if (packagePath) {
29
+ try {
30
+ version = require(path.join(packagePath, 'package.json')).dependencies['pm2'];
31
+ } catch (err) {
32
+ //
33
+ }
34
+ }
35
+ if (version) break;
36
+ }
37
+
38
+ return { used, version };
39
+ }
40
+
41
+ function isDocker() {
42
+ const MOUNTINFO_REGEX = /\/docker\/containers\/(.*?)\//;
43
+ const CGROUP_REGEX = /:\/docker\/([^/]+)$/;
44
+
45
+ try {
46
+ const results = fs.readFileSync('/proc/self/mountinfo', 'utf8').match(MOUNTINFO_REGEX);
47
+ if (results) return { isDocker: true, containerID: results[1] };
48
+ } catch (err) {
49
+ // else check /proc/self/cgroup
50
+ }
51
+
52
+ try {
53
+ const results = fs.readFileSync('/proc/self/cgroup', 'utf8').match(CGROUP_REGEX);
54
+ if (results) return { isDocker: true, containerID: results[1] };
55
+ } catch (err) {
56
+ // else check /.dockerenv
57
+ }
58
+
59
+ try {
60
+ const result = fs.statSync('/.dockerenv');
61
+ if (result) return { isDocker: true, containerID: undefined };
62
+ } catch (err) {
63
+ // if there's not such file we can conclude it's not docker env
64
+ }
65
+
66
+ return { isDocker: false, containerID: undefined };
67
+ }
68
+
69
+ module.exports = function(core) {
70
+ // eslint-disable-next-line node/no-extraneous-require
71
+ const pkg = require('@contrast/protect-agent/package.json');
72
+ const { config } = core;
73
+
74
+ core.getSystemInfo = function() {
75
+ const appPath = process.cwd();
76
+
77
+ const info = {
78
+ ReportDate: new Date(),
79
+ MachineName: os.hostname(),
80
+ Contrast: {
81
+ Url: config.api.url,
82
+ Proxy: config.api.proxy,
83
+ Server: {
84
+ Name: config.server.name,
85
+ },
86
+ Agent: {
87
+ Name: pkg.name,
88
+ Version: pkg.version,
89
+ },
90
+ },
91
+ Node: {
92
+ Version: process.version
93
+ },
94
+ OperatingSystem: {
95
+ Architecture: os.arch(),
96
+ Name: os.type(),
97
+ Version: os.release(),
98
+ KernelVersion: os.version(),
99
+ CPU: {
100
+ type: os.cpus()[0].model,
101
+ count: os.cpus().length,
102
+ }
103
+ },
104
+ Host: {
105
+ Docker: isDocker(),
106
+ PM2: isUsingPM2(),
107
+ Memory: {
108
+ Total: (os.totalmem() / 1e6).toFixed(0).concat(' MB'),
109
+ Free: (os.freemem() / 1e6).toFixed(0).concat(' MB'),
110
+ Used: ((os.totalmem() - os.freemem()) / 1e6).toFixed(0).concat(' MB'),
111
+ }
112
+ },
113
+ Application: appPath ? require(path.join(appPath, 'package.json')) : null,
114
+ };
115
+
116
+ return info;
117
+ };
118
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@contrast/core",
3
- "version": "1.10.2",
3
+ "version": "1.11.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,17 +17,17 @@
17
17
  "test": "../scripts/test.sh"
18
18
  },
19
19
  "dependencies": {
20
- "@contrast/agentify": "1.3.1",
21
- "@contrast/common": "1.3.2",
22
- "@contrast/config": "1.5.2",
23
- "@contrast/deadzones": "1.0.0",
24
- "@contrast/dep-hooks": "1.0.5",
20
+ "@contrast/agentify": "1.4.0",
21
+ "@contrast/common": "1.4.0",
22
+ "@contrast/config": "1.6.0",
23
+ "@contrast/deadzones": "1.1.0",
24
+ "@contrast/dep-hooks": "1.1.0",
25
25
  "@contrast/fn-inspect": "^3.2.0",
26
- "@contrast/instrumentation": "1.0.1",
27
- "@contrast/logger": "1.1.2",
28
- "@contrast/patcher": "1.1.0",
29
- "@contrast/reporter": "1.8.3",
26
+ "@contrast/instrumentation": "1.1.0",
27
+ "@contrast/logger": "1.2.0",
28
+ "@contrast/patcher": "1.2.0",
29
+ "@contrast/reporter": "1.9.0",
30
30
  "@contrast/rewriter": "1.3.1",
31
- "@contrast/scopes": "1.2.0"
31
+ "@contrast/scopes": "1.3.0"
32
32
  }
33
33
  }