@contrast/agentify 1.11.0 → 1.13.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/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright: 2022 Contrast Security, Inc
1
+ Copyright: 2023 Contrast Security, Inc
2
2
  Contact: support@contrastsecurity.com
3
3
  License: Commercial
4
4
 
@@ -1,5 +1,5 @@
1
1
  /*
2
- * Copyright: 2022 Contrast Security, Inc
2
+ * Copyright: 2023 Contrast Security, Inc
3
3
  * Contact: support@contrastsecurity.com
4
4
  * License: Commercial
5
5
 
package/lib/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  /*
2
- * Copyright: 2022 Contrast Security, Inc
2
+ * Copyright: 2023 Contrast Security, Inc
3
3
  * Contact: support@contrastsecurity.com
4
4
  * License: Commercial
5
5
 
package/lib/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*
2
- * Copyright: 2022 Contrast Security, Inc
2
+ * Copyright: 2023 Contrast Security, Inc
3
3
  * Contact: support@contrastsecurity.com
4
4
  * License: Commercial
5
5
 
@@ -15,7 +15,7 @@
15
15
 
16
16
  'use strict';
17
17
 
18
- const fs = require('fs');
18
+ const fs = require('fs').promises;
19
19
  const path = require('path');
20
20
  const Module = require('module');
21
21
 
@@ -38,7 +38,7 @@ const defaultOpts = {
38
38
  ]
39
39
  };
40
40
 
41
- module.exports = function(core) {
41
+ module.exports = function (core) {
42
42
  // compose add'l local services
43
43
  require('./sources')(core);
44
44
  require('./function-hooks')(core);
@@ -88,8 +88,12 @@ class Agent {
88
88
  * This is one side effect that will always occur, even with `install: false`.
89
89
  * The act of calling `agentify()` is enough to cause this side effect, by design.
90
90
  */
91
- Module.runMain = async function(...args) {
91
+ Module.runMain = async function (...args) {
92
92
  try {
93
+ for (const err of config._errors) {
94
+ throw err;
95
+ }
96
+
93
97
  logger.info('Starting the Contrast agent');
94
98
  logger.debug({ config }, 'Agent configuration');
95
99
 
@@ -99,7 +103,7 @@ class Agent {
99
103
  await self.install();
100
104
  }
101
105
 
102
- if (plugin && plugin.install) {
106
+ if (plugin?.install) {
103
107
  await plugin.install();
104
108
  }
105
109
  } catch (err) {
@@ -128,7 +132,7 @@ class Agent {
128
132
  async install() {
129
133
  for (const svcName of this.opts.svcList) {
130
134
  const svc = this.core[svcName];
131
- if (svc && svc.install) {
135
+ if (svc?.install) {
132
136
  this.core.logger.trace('installing service: %s', svcName);
133
137
  await svc.install();
134
138
  }
@@ -136,35 +140,26 @@ class Agent {
136
140
  }
137
141
 
138
142
  logDiagnosticFiles() {
139
- const { config, getEffectiveConfig, getSystemInfo } = this.core;
140
-
141
- if (config.agent.diagnostics.enable !== false) {
142
- const effectiveConfig = JSON.stringify(getEffectiveConfig(), null, 2);
143
- const systemInfo = JSON.stringify(getSystemInfo(), null, 2);
144
-
145
- if (!config.agent.diagnostics.quiet) {
146
- fs.writeFileSync(1, effectiveConfig, 'utf8');
147
- fs.writeFileSync(1, systemInfo, 'utf8');
148
- }
149
-
150
- let outputDir = config.agent.diagnostics.report_path;
151
- if (!outputDir && config.agent.logger.path) {
152
- outputDir = path.join(config.agent.logger.path, '..');
153
- }
154
-
155
- try {
156
- fs.writeFileSync(path.join(outputDir, 'contrast_effective_config.json'), effectiveConfig, 'utf-8');
157
- fs.writeFileSync(path.join(outputDir, 'contrast_system_info.json'), systemInfo, 'utf-8');
158
- } catch (err) {
159
- outputDir = path.join(process.cwd());
160
- try {
161
- fs.writeFileSync(path.join(outputDir, 'contrast_effective_config.json'), effectiveConfig, 'utf-8');
162
- fs.writeFileSync(path.join(outputDir, 'contrast_system_info.json'), systemInfo, 'utf-8');
163
- } catch (err) {
164
- fs.writeFileSync(1, `Couldn't create the diagnostic files: ${err}`, 'utf-8');
165
- }
166
- }
167
- }
143
+ const { config, logger } = this.core;
144
+
145
+ if (!config.agent.diagnostics.enable) return;
146
+
147
+ const { report_path } = config.agent.diagnostics;
148
+
149
+ // let these run async so they don't block agent startup.
150
+ fs.writeFile(
151
+ path.join(report_path, 'contrast_effective_config.json'),
152
+ JSON.stringify(config.getReport({ redact: true }), null, 2)
153
+ ).catch((err) => {
154
+ logger.warn({ err }, 'unable to write effective config file');
155
+ });
156
+
157
+ fs.writeFile(
158
+ path.join(report_path, 'contrast_system_info.json'),
159
+ JSON.stringify(this.core.getSystemInfo(), null, 2)
160
+ ).catch((err) => {
161
+ logger.warn({ err }, 'unable to write system info file');
162
+ });
168
163
  }
169
164
  }
170
165
 
@@ -1,5 +1,5 @@
1
1
  /*
2
- * Copyright: 2022 Contrast Security, Inc
2
+ * Copyright: 2023 Contrast Security, Inc
3
3
  * Contact: support@contrastsecurity.com
4
4
  * License: Commercial
5
5
 
package/lib/sources.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*
2
- * Copyright: 2022 Contrast Security, Inc
2
+ * Copyright: 2023 Contrast Security, Inc
3
3
  * Contact: support@contrastsecurity.com
4
4
  * License: Commercial
5
5
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@contrast/agentify",
3
- "version": "1.11.0",
3
+ "version": "1.13.0",
4
4
  "description": "Configures Contrast agent services and instrumentation within an application",
5
5
  "license": "SEE LICENSE IN LICENSE",
6
6
  "author": "Contrast Security <nodejs@contrastsecurity.com> (https://www.contrastsecurity.com)",
@@ -17,6 +17,6 @@
17
17
  "test": "../scripts/test.sh"
18
18
  },
19
19
  "dependencies": {
20
- "@contrast/common": "1.13.0"
20
+ "@contrast/common": "1.15.0"
21
21
  }
22
- }
22
+ }