@contrast/cli 1.2.0 → 1.3.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/config-diagnostics.js +29 -18
- package/lib/system-diagnostics.js +15 -16
- package/package.json +7 -3
|
@@ -15,34 +15,45 @@
|
|
|
15
15
|
*/
|
|
16
16
|
'use strict';
|
|
17
17
|
|
|
18
|
-
const path = require('path');
|
|
19
|
-
const fs = require('fs');
|
|
20
18
|
const commander = require('commander');
|
|
19
|
+
const fs = require('fs');
|
|
20
|
+
const path = require('path');
|
|
21
|
+
const { name: agentName, version: agentVersion } = require('../package.json');
|
|
22
|
+
const core = require('@contrast/core')({ agentName, agentVersion });
|
|
21
23
|
|
|
22
|
-
|
|
24
|
+
if (require.main === module) {
|
|
23
25
|
commander.program
|
|
24
26
|
.name('config-diagnostics')
|
|
25
27
|
.description('The config-diagnostics utility returns the current effective node agent configuration.')
|
|
26
28
|
.argument('<entrypoint>', 'The entrypoint JavaScript or ESM file for the application')
|
|
27
29
|
.option('-q, --quiet', 'suppress logging to stdout')
|
|
28
30
|
.option('-o, --output <string>', 'output directory for generated JSON file', path.join(process.cwd(), 'contrast_effective_config.json'))
|
|
29
|
-
.action(
|
|
30
|
-
const { reporter, getEffectiveConfig } = core;
|
|
31
|
-
await reporter.install();
|
|
32
|
-
const content = JSON.stringify(getEffectiveConfig(), null, 2).concat('\n\n');
|
|
33
|
-
|
|
34
|
-
if (!options.quiet) {
|
|
35
|
-
fs.writeFileSync(1, content, 'utf8');
|
|
36
|
-
}
|
|
37
|
-
if (options.output) {
|
|
38
|
-
fs.writeFileSync(options.output, content, 'utf-8');
|
|
39
|
-
}
|
|
40
|
-
})
|
|
31
|
+
.action(action)
|
|
41
32
|
.parse();
|
|
42
33
|
}
|
|
43
34
|
|
|
44
|
-
|
|
35
|
+
async function action(entrypoint, options) {
|
|
36
|
+
const { reporter, getEffectiveConfig } = core;
|
|
37
|
+
let Status;
|
|
45
38
|
|
|
46
|
-
|
|
47
|
-
|
|
39
|
+
try {
|
|
40
|
+
if (!core.config.api.enable) {
|
|
41
|
+
throw new Error('config.api.enable = false');
|
|
42
|
+
}
|
|
43
|
+
await reporter.install();
|
|
44
|
+
Status = 'TeamServer connection successful. Remote settings are included in output.';
|
|
45
|
+
} catch (err) {
|
|
46
|
+
Status = `Unable to connect to TeamServer. Remote settings are not included in output. Error: ${err.message}`;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const content = JSON.stringify({ ...getEffectiveConfig(), Status }, null, 2);
|
|
50
|
+
|
|
51
|
+
if (!options.quiet) {
|
|
52
|
+
fs.writeFileSync(1, content, 'utf8');
|
|
53
|
+
}
|
|
54
|
+
if (options.output) {
|
|
55
|
+
fs.writeFileSync(options.output, content, 'utf-8');
|
|
56
|
+
}
|
|
48
57
|
}
|
|
58
|
+
|
|
59
|
+
module.exports.action = action;
|
|
@@ -18,30 +18,29 @@
|
|
|
18
18
|
const commander = require('commander');
|
|
19
19
|
const fs = require('fs');
|
|
20
20
|
const path = require('path');
|
|
21
|
+
const { name: agentName, version: agentVersion } = require('../package.json');
|
|
22
|
+
const core = require('@contrast/core')({ agentName, agentVersion });
|
|
21
23
|
|
|
22
|
-
|
|
24
|
+
if (require.main === module) {
|
|
23
25
|
commander.program
|
|
24
26
|
.name('system-diagnostics')
|
|
25
27
|
.description('The system-diagnostics utility returns the system info for the server/container the agent is running on.')
|
|
26
28
|
.option('-q, --quiet', 'suppress logging to stdout')
|
|
27
29
|
.option('-o, --output <string>', 'output directory for generated JSON file', path.join(process.cwd(), 'contrast_system_info.json'))
|
|
28
|
-
.action(
|
|
29
|
-
const { reporter, getSystemInfo } = core;
|
|
30
|
-
await reporter.install();
|
|
31
|
-
const content = JSON.stringify(getSystemInfo(), null, 2).concat('\n\n');
|
|
32
|
-
|
|
33
|
-
if (!options.quiet) {
|
|
34
|
-
fs.writeFileSync(1, content, 'utf8');
|
|
35
|
-
}
|
|
36
|
-
if (options.output) {
|
|
37
|
-
fs.writeFileSync(options.output, content, 'utf-8');
|
|
38
|
-
}
|
|
39
|
-
})
|
|
30
|
+
.action(action)
|
|
40
31
|
.parse();
|
|
41
32
|
}
|
|
42
33
|
|
|
43
|
-
|
|
34
|
+
async function action(options) {
|
|
35
|
+
const content = JSON.stringify(core.getSystemInfo(), null, 2).concat();
|
|
36
|
+
console.log(content);
|
|
44
37
|
|
|
45
|
-
if (
|
|
46
|
-
|
|
38
|
+
if (!options.quiet) {
|
|
39
|
+
fs.writeFileSync(1, content, 'utf8');
|
|
40
|
+
}
|
|
41
|
+
if (options.output) {
|
|
42
|
+
fs.writeFileSync(options.output, content, 'utf-8');
|
|
43
|
+
}
|
|
47
44
|
}
|
|
45
|
+
|
|
46
|
+
module.exports.action = action;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"author": "Contrast Security <nodejs@contrastsecurity.com> (https://www.contrastsecurity.com)",
|
|
3
3
|
"name": "@contrast/cli",
|
|
4
|
-
"version": "1.
|
|
4
|
+
"version": "1.3.0",
|
|
5
5
|
"description": "A collection of agent related CLI utilities",
|
|
6
6
|
"scripts": {
|
|
7
7
|
"test": "../scripts/test.sh"
|
|
@@ -20,8 +20,12 @@
|
|
|
20
20
|
},
|
|
21
21
|
"keywords": [],
|
|
22
22
|
"license": "SEE LICENSE IN LICENSE",
|
|
23
|
+
"peerDependencies": {
|
|
24
|
+
"@contrast/agent": "5.0.0-alpha.2",
|
|
25
|
+
"@contrast/protect-agent": "5.5.0"
|
|
26
|
+
},
|
|
23
27
|
"dependencies": {
|
|
24
|
-
"@contrast/core": "1.
|
|
28
|
+
"@contrast/core": "1.12.0",
|
|
25
29
|
"commander": "^9.4.1"
|
|
26
30
|
}
|
|
27
|
-
}
|
|
31
|
+
}
|