@opscompass/opscompass-cli 1.3.2 → 1.3.4
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/dataGathering/events.js +146 -0
- package/lib/dataGathering/moduleDiscovery.js +62 -0
- package/lib/dataGathering/olmDataParms.js +140 -0
- package/lib/dataGathering/sendDg.js +971 -0
- package/lib/dataGathering/setupWizard.js +826 -0
- package/lib/dataGathering/ui.js +83 -0
- package/lib/dataGathering/validateInstall.js +210 -0
- package/lib/homeInteraction.js +84 -19
- package/lib/maskValues.js +320 -71
- package/lib/pgpTools.js +156 -92
- package/lib/utils.js +122 -39
- package/modules/data-gathering-scripts.js +6 -35
- package/modules/data-gathering.js +732 -0
- package/modules/defaults.js +68 -15
- package/modules/license-manager/importMonitoringConfiguration.js +369 -0
- package/modules/license-manager/microsoft.js +11 -4
- package/modules/license-manager/nutanix.js +10 -4
- package/modules/license-manager/resolveMonitoringConfigId.js +28 -0
- package/modules/license-manager/vcenter.js +10 -4
- package/modules/license-manager.js +89 -9
- package/modules.js +2 -0
- package/package.json +34 -6
- package/updates.js +409 -57
- package/environment/demo.js +0 -30
- package/environment/dev.js +0 -30
- package/environment/local.js +0 -31
- package/environment/production.js +0 -30
package/lib/pgpTools.js
CHANGED
|
@@ -2,100 +2,164 @@
|
|
|
2
2
|
|
|
3
3
|
import * as openpgp from "openpgp";
|
|
4
4
|
import fs from "fs";
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
signature,
|
|
81
|
-
verificationKeys: publicKey,
|
|
5
|
+
|
|
6
|
+
const SCRIPT_BUNDLE_VERIFICATION_STATUS = {
|
|
7
|
+
verified: "verified",
|
|
8
|
+
unverified: "unverified",
|
|
9
|
+
invalid: "invalid",
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
const DEFAULT_PINNED_SIGNER = "cli-token@opscompass.com";
|
|
13
|
+
|
|
14
|
+
const PINNED_SIGNER_KEYS = {
|
|
15
|
+
[DEFAULT_PINNED_SIGNER]: `-----BEGIN PGP PUBLIC KEY BLOCK-----
|
|
16
|
+
Comment: 85BF E879 64BE 0203 C2C1 C8D1 8874 71E6 B9D8 82DB
|
|
17
|
+
Comment: OpsCompass Tooling <cli-token@opscompass.com>
|
|
18
|
+
|
|
19
|
+
mDMEZS2pnRYJKwYBBAHaRw8BAQdASHC55jY2qSZ4QwKuCig7XpW0KjniaqSpmmAG
|
|
20
|
+
fOwDgQ+0LU9wc0NvbXBhc3MgVG9vbGluZyA8Y2xpLXRva2VuQG9wc2NvbXBhc3Mu
|
|
21
|
+
Y29tPoiZBBMWCgBBAhsDBQsJCAcCAiICBhUKCQgLAgQWAgMBAh4HAheAFiEEhb/o
|
|
22
|
+
eWS+AgPCwcjRiHRx5rnYgtsFAmhsNrMFCQWo3JYACgkQiHRx5rnYgtsXxgD9ExID
|
|
23
|
+
xjTxVRGGe4eohvrdDrmlgJs3CBJzvwI4Y6wMfJsBAKO+PgtXAHyAZv1e64tH7qAZ
|
|
24
|
+
pL6EC81iLmExNdGUqroLuDgEZS2pnRIKKwYBBAGXVQEFAQEHQH7ng7p5sviGKtNw
|
|
25
|
+
ExwTaEvXx9+fy9mhQBXtBTGzsqQzAwEIB4h+BBgWCgAmAhsMFiEEhb/oeWS+AgPC
|
|
26
|
+
wcjRiHRx5rnYgtsFAmhsNsEFCQWo3KQACgkQiHRx5rnYgtsghgEA9qAXuQdWlJVG
|
|
27
|
+
r0jA4PfkgIYcRboSlEQqS/MtFbCbNOkA/08ciTsADdoc7JkXu5rErQlHL7iD4wUX
|
|
28
|
+
ZT2xvhQ8oogL
|
|
29
|
+
=QkMP
|
|
30
|
+
-----END PGP PUBLIC KEY BLOCK-----`,
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
const publicKeyCache = {};
|
|
34
|
+
|
|
35
|
+
function resolveOutput(output = console) {
|
|
36
|
+
return {
|
|
37
|
+
log: output?.log?.bind(output) || (() => {}),
|
|
38
|
+
warn:
|
|
39
|
+
output?.warn?.bind(output) ||
|
|
40
|
+
output?.log?.bind(output) ||
|
|
41
|
+
(() => {}),
|
|
42
|
+
error:
|
|
43
|
+
output?.error?.bind(output) ||
|
|
44
|
+
output?.warn?.bind(output) ||
|
|
45
|
+
output?.log?.bind(output) ||
|
|
46
|
+
(() => {}),
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function normalizeSigner(signer) {
|
|
51
|
+
return (signer || DEFAULT_PINNED_SIGNER).toLowerCase();
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function verificationResult(status, details = {}) {
|
|
55
|
+
return { status, ...details };
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
async function getPinnedPublicKey(gpgSigner) {
|
|
59
|
+
const signer = normalizeSigner(gpgSigner);
|
|
60
|
+
const armoredKey = PINNED_SIGNER_KEYS[signer];
|
|
61
|
+
if (!armoredKey) {
|
|
62
|
+
return undefined;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
if (!publicKeyCache[signer]) {
|
|
66
|
+
publicKeyCache[signer] = await openpgp.readKey({ armoredKey });
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
return publicKeyCache[signer];
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
async function Verify(scriptDownloadInfo, output = console) {
|
|
73
|
+
const reporter = resolveOutput(output);
|
|
74
|
+
|
|
75
|
+
// If the download info does not include a gpg signature, treat as unverified.
|
|
76
|
+
if (!scriptDownloadInfo?.gpgSignature) {
|
|
77
|
+
reporter.warn("Archive file NOT digitally signed");
|
|
78
|
+
return verificationResult(SCRIPT_BUNDLE_VERIFICATION_STATUS.unverified, {
|
|
79
|
+
reason: "missing-signature",
|
|
82
80
|
});
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
return false;
|
|
89
|
-
}
|
|
90
|
-
console.log(
|
|
91
|
-
"Archive file digitally signed by:\n %s",
|
|
92
|
-
publicKey?.users[0]?.userID?.userID || gpgSigner,
|
|
93
|
-
);
|
|
94
|
-
return true;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
let readableStream = undefined;
|
|
84
|
+
if (fs.existsSync(scriptDownloadInfo.filePath)) {
|
|
85
|
+
readableStream = fs.readFileSync(scriptDownloadInfo.filePath);
|
|
95
86
|
} else {
|
|
96
|
-
|
|
97
|
-
return
|
|
87
|
+
reporter.error("Cannot read archive file: %s", scriptDownloadInfo.filePath);
|
|
88
|
+
return verificationResult(SCRIPT_BUNDLE_VERIFICATION_STATUS.invalid, {
|
|
89
|
+
reason: "archive-not-found",
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
const gpgSigner = normalizeSigner(scriptDownloadInfo?.gpgSigner);
|
|
94
|
+
let publicKey = undefined;
|
|
95
|
+
try {
|
|
96
|
+
publicKey = await getPinnedPublicKey(gpgSigner);
|
|
97
|
+
} catch (err) {
|
|
98
|
+
reporter.error("Validation error reading pinned key:\n%s", err);
|
|
99
|
+
return verificationResult(SCRIPT_BUNDLE_VERIFICATION_STATUS.invalid, {
|
|
100
|
+
signer: gpgSigner,
|
|
101
|
+
reason: "pinned-key-read-failed",
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
if (!publicKey) {
|
|
106
|
+
reporter.warn(
|
|
107
|
+
"Signer %s is not pinned; treating archive as unverified",
|
|
108
|
+
gpgSigner,
|
|
109
|
+
);
|
|
110
|
+
return verificationResult(SCRIPT_BUNDLE_VERIFICATION_STATUS.unverified, {
|
|
111
|
+
signer: gpgSigner,
|
|
112
|
+
reason: "non-pinned-signer",
|
|
113
|
+
});
|
|
98
114
|
}
|
|
115
|
+
|
|
116
|
+
let signature = undefined;
|
|
117
|
+
try {
|
|
118
|
+
signature = await openpgp.readSignature({
|
|
119
|
+
armoredSignature: scriptDownloadInfo.gpgSignature,
|
|
120
|
+
});
|
|
121
|
+
} catch (err) {
|
|
122
|
+
reporter.error("Validation error reading file signature:\n%s", err);
|
|
123
|
+
return verificationResult(SCRIPT_BUNDLE_VERIFICATION_STATUS.invalid, {
|
|
124
|
+
signer: gpgSigner,
|
|
125
|
+
reason: "signature-parse-failed",
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
const message = await openpgp.createMessage({ binary: readableStream });
|
|
130
|
+
const signatureVerification = await openpgp.verify({
|
|
131
|
+
message,
|
|
132
|
+
signature,
|
|
133
|
+
verificationKeys: publicKey,
|
|
134
|
+
});
|
|
135
|
+
const { verified, keyID } = signatureVerification.signatures[0];
|
|
136
|
+
|
|
137
|
+
try {
|
|
138
|
+
await verified;
|
|
139
|
+
} catch (e) {
|
|
140
|
+
reporter.error("Archive file verification failed:\n%s", e.message);
|
|
141
|
+
return verificationResult(SCRIPT_BUNDLE_VERIFICATION_STATUS.invalid, {
|
|
142
|
+
signer: gpgSigner,
|
|
143
|
+
reason: "signature-invalid",
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
const signerFingerprint = publicKey.getFingerprint().toUpperCase();
|
|
148
|
+
reporter.log(
|
|
149
|
+
"Archive file digitally signed by:\n %s",
|
|
150
|
+
publicKey?.users[0]?.userID?.userID || gpgSigner,
|
|
151
|
+
);
|
|
152
|
+
|
|
153
|
+
return verificationResult(SCRIPT_BUNDLE_VERIFICATION_STATUS.verified, {
|
|
154
|
+
signer: gpgSigner,
|
|
155
|
+
signerFingerprint,
|
|
156
|
+
keyId: keyID?.toHex?.(),
|
|
157
|
+
});
|
|
99
158
|
}
|
|
100
159
|
|
|
101
|
-
export {
|
|
160
|
+
export {
|
|
161
|
+
Verify,
|
|
162
|
+
PINNED_SIGNER_KEYS,
|
|
163
|
+
SCRIPT_BUNDLE_VERIFICATION_STATUS,
|
|
164
|
+
DEFAULT_PINNED_SIGNER,
|
|
165
|
+
};
|
package/lib/utils.js
CHANGED
|
@@ -33,8 +33,8 @@ function hasNullOrUndefined(obj, count = Object.keys(obj).length) {
|
|
|
33
33
|
// Function to get a timestamp
|
|
34
34
|
|
|
35
35
|
// (E) MANUAL FORMAT timestamp
|
|
36
|
-
function getTimestamp() {
|
|
37
|
-
|
|
36
|
+
function getTimestamp(dNow = new Date()) {
|
|
37
|
+
let
|
|
38
38
|
tsYr = dNow.getFullYear(),
|
|
39
39
|
tsMo = prezero(dNow.getMonth() + 1),
|
|
40
40
|
tsDy = prezero(dNow.getDate()),
|
|
@@ -43,7 +43,6 @@ function getTimestamp() {
|
|
|
43
43
|
tsSe = prezero(dNow.getSeconds());
|
|
44
44
|
return `${tsYr}${tsMo}${tsDy}-${tsHr}${tsMi}${tsSe}`;
|
|
45
45
|
}
|
|
46
|
-
const tStamp = getTimestamp();
|
|
47
46
|
|
|
48
47
|
/**
|
|
49
48
|
* Process standard arguments (eg company) and remove them
|
|
@@ -128,12 +127,27 @@ function getConfigFilePath(args = []) {
|
|
|
128
127
|
case "--save-file":
|
|
129
128
|
// This means we are supposed to save the file
|
|
130
129
|
explicitFilePath = args[i + 1];
|
|
130
|
+
if (typeof explicitFilePath === "boolean") {
|
|
131
|
+
explicitFilePath = explicitFilePath.toString();
|
|
132
|
+
}
|
|
133
|
+
// Normalize non-string explicitFilePath values to strings to avoid
|
|
134
|
+
// runtime errors when calling string methods (eg. startsWith) or
|
|
135
|
+
// fs APIs that expect a path string.
|
|
136
|
+
if (typeof explicitFilePath !== "string") {
|
|
137
|
+
try {
|
|
138
|
+
explicitFilePath = String(explicitFilePath);
|
|
139
|
+
} catch (e) {
|
|
140
|
+
explicitFilePath = undefined;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
|
|
131
144
|
if (["true", "false"].includes(explicitFilePath)) {
|
|
132
145
|
// If the next argument is true or false, then it is not a file path
|
|
133
146
|
explicitFilePath = undefined;
|
|
134
147
|
} else {
|
|
135
148
|
// If explicitFilePath is an existing directory, use the default file name
|
|
136
149
|
if (
|
|
150
|
+
typeof explicitFilePath === "string" &&
|
|
137
151
|
fs.existsSync(explicitFilePath) &&
|
|
138
152
|
fs.lstatSync(explicitFilePath).isDirectory()
|
|
139
153
|
) {
|
|
@@ -190,7 +204,7 @@ function getConfigFilePath(args = []) {
|
|
|
190
204
|
}
|
|
191
205
|
|
|
192
206
|
// If we have an odd number of arguments the last one should be an explicit file path
|
|
193
|
-
if (explicitFilePath && !explicitFilePath.startsWith("--")) {
|
|
207
|
+
if (explicitFilePath && typeof explicitFilePath === "string" && !explicitFilePath.startsWith("--")) {
|
|
194
208
|
cfgFile.filePath = explicitFilePath;
|
|
195
209
|
} else {
|
|
196
210
|
try {
|
|
@@ -292,6 +306,20 @@ async function readConfigFile(args) {
|
|
|
292
306
|
* If there is an existing file (based on args), we'll create a copy first
|
|
293
307
|
*/
|
|
294
308
|
async function writeConfigFile(args, cfgData = undefined, overwrite = false) {
|
|
309
|
+
const output = arguments[3] || console;
|
|
310
|
+
const reporter = {
|
|
311
|
+
log: output?.log?.bind(output) || (() => {}),
|
|
312
|
+
warn:
|
|
313
|
+
output?.warn?.bind(output) ||
|
|
314
|
+
output?.log?.bind(output) ||
|
|
315
|
+
(() => {}),
|
|
316
|
+
error:
|
|
317
|
+
output?.error?.bind(output) ||
|
|
318
|
+
output?.warn?.bind(output) ||
|
|
319
|
+
output?.log?.bind(output) ||
|
|
320
|
+
(() => {}),
|
|
321
|
+
};
|
|
322
|
+
|
|
295
323
|
// If the cfgData has values, use them to override the global values
|
|
296
324
|
// from defaults.json
|
|
297
325
|
// CUST_NAME is the name of the Licensing Account. Company is not in cfgData.
|
|
@@ -325,7 +353,7 @@ async function writeConfigFile(args, cfgData = undefined, overwrite = false) {
|
|
|
325
353
|
const cfgBaseName = path.basename(cfgFile.filePath);
|
|
326
354
|
// if overwriting, delete the existing file
|
|
327
355
|
if (!cfgBaseName.startsWith("opscompass-monitoring-configuration.")) {
|
|
328
|
-
|
|
356
|
+
reporter.warn("WARNING: overwriting existing config file: %s", cfgBaseName);
|
|
329
357
|
}
|
|
330
358
|
fs.rmSync(cfgFile.filePath, { force: true });
|
|
331
359
|
}
|
|
@@ -351,15 +379,26 @@ async function writeConfigFile(args, cfgData = undefined, overwrite = false) {
|
|
|
351
379
|
cfgBase = cfgBase.replace(/_[0-9-]+/, "");
|
|
352
380
|
|
|
353
381
|
// Construct the name of the backup file
|
|
354
|
-
const buCfg = `${cfgPath}/${cfgBase}_${tStamp}.${fExt}`;
|
|
355
382
|
cfgName = `${cfgPath}/${cfgBase}.${fExt}`;
|
|
356
383
|
|
|
357
384
|
// Make a versioned backup of the config file (if it exists)
|
|
358
385
|
try {
|
|
359
386
|
fs.accessSync(cfgName, fs.constants.F_OK);
|
|
360
387
|
try {
|
|
361
|
-
|
|
388
|
+
const existingStats = fs.statSync(cfgName);
|
|
389
|
+
const backupStamp = getTimestamp(new Date(existingStats.mtime));
|
|
390
|
+
let buCfg = `${cfgPath}/${cfgBase}_${backupStamp}.${fExt}`;
|
|
391
|
+
let backupSuffix = 1;
|
|
392
|
+
while (fs.existsSync(buCfg)) {
|
|
393
|
+
buCfg = `${cfgPath}/${cfgBase}_${backupStamp}_${backupSuffix}.${fExt}`;
|
|
394
|
+
backupSuffix += 1;
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
// Create a copy with a timestamp based on the previous file mtime
|
|
362
398
|
fs.copyFileSync(cfgName, buCfg);
|
|
399
|
+
// Touch backup to now so cleanup treats this as a fresh backup
|
|
400
|
+
const now = new Date();
|
|
401
|
+
fs.utimesSync(buCfg, now, now);
|
|
363
402
|
// console.error(`renamed\n ${cfgName}\nto\n ${buCfg}`)
|
|
364
403
|
fs.rmSync(cfgName, { force: true });
|
|
365
404
|
} catch (err) {
|
|
@@ -386,14 +425,8 @@ async function writeConfigFile(args, cfgData = undefined, overwrite = false) {
|
|
|
386
425
|
encryptValues(newConfig);
|
|
387
426
|
const json = JSON.stringify(newConfig, null, 2) + "\n";
|
|
388
427
|
fs.mkdirSync(cfgPath, { recursive: true });
|
|
389
|
-
fs.writeFileSync(cfgName, json
|
|
390
|
-
|
|
391
|
-
console.error("ERROR: " + err);
|
|
392
|
-
throw err;
|
|
393
|
-
}
|
|
394
|
-
fs.chmodSync(cfgName, "0600");
|
|
395
|
-
console.log(cfgName);
|
|
396
|
-
});
|
|
428
|
+
fs.writeFileSync(cfgName, json);
|
|
429
|
+
fs.chmodSync(cfgName, "0600");
|
|
397
430
|
decryptValues(newConfig);
|
|
398
431
|
newConfig.filePath = cfgName;
|
|
399
432
|
|
|
@@ -424,9 +457,11 @@ async function writeConfigFile(args, cfgData = undefined, overwrite = false) {
|
|
|
424
457
|
*/
|
|
425
458
|
const algorithm = "aes-256-cbc";
|
|
426
459
|
const hashType = "md5";
|
|
427
|
-
function getCipher() {
|
|
460
|
+
function getCipher(accountOverride) {
|
|
428
461
|
let custTok;
|
|
429
|
-
if (
|
|
462
|
+
if (typeof accountOverride === "string" && accountOverride.length > 0) {
|
|
463
|
+
custTok = accountOverride;
|
|
464
|
+
} else if (global.account) {
|
|
430
465
|
custTok = global.account;
|
|
431
466
|
} else {
|
|
432
467
|
// Punt, try to use environment
|
|
@@ -529,32 +564,78 @@ function encryptAES(data) {
|
|
|
529
564
|
|
|
530
565
|
// Encrypt a file, as a stream
|
|
531
566
|
function encryptFileAES(args) {
|
|
532
|
-
const enc = getCipher();
|
|
567
|
+
const enc = getCipher(args?.account);
|
|
533
568
|
const outFname = `${args.filePath}.gpg`;
|
|
534
569
|
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
570
|
+
return new Promise((resolve, reject) => {
|
|
571
|
+
const infile = fs.createReadStream(args.filePath);
|
|
572
|
+
const outfile = fs.createWriteStream(outFname);
|
|
573
|
+
let settled = false;
|
|
574
|
+
let waitingDrain = false;
|
|
575
|
+
let inputEnded = false;
|
|
576
|
+
|
|
577
|
+
const fail = (err) => {
|
|
578
|
+
if (settled) return;
|
|
579
|
+
settled = true;
|
|
580
|
+
infile.destroy();
|
|
581
|
+
outfile.destroy();
|
|
582
|
+
reject(err);
|
|
583
|
+
};
|
|
584
|
+
|
|
585
|
+
const writeChunk = (chunk) => {
|
|
586
|
+
if (!chunk || chunk.length === 0) return;
|
|
587
|
+
if (!outfile.write(chunk)) {
|
|
588
|
+
waitingDrain = true;
|
|
589
|
+
infile.pause();
|
|
590
|
+
}
|
|
591
|
+
};
|
|
592
|
+
|
|
593
|
+
const maybeFinalize = () => {
|
|
594
|
+
if (inputEnded && !waitingDrain && !settled) {
|
|
595
|
+
outfile.end();
|
|
596
|
+
}
|
|
597
|
+
};
|
|
598
|
+
|
|
599
|
+
infile.on("error", (err) => fail(err));
|
|
600
|
+
outfile.on("error", (err) => fail(err));
|
|
601
|
+
outfile.on("drain", () => {
|
|
602
|
+
waitingDrain = false;
|
|
603
|
+
infile.resume();
|
|
604
|
+
maybeFinalize();
|
|
605
|
+
});
|
|
606
|
+
|
|
607
|
+
try {
|
|
608
|
+
// Write OpenSSL-compatible header once, even for empty files.
|
|
609
|
+
writeChunk(Buffer.concat([Buffer.from("Salted__"), enc.salt]));
|
|
610
|
+
} catch (err) {
|
|
611
|
+
fail(err);
|
|
612
|
+
return;
|
|
551
613
|
}
|
|
614
|
+
|
|
615
|
+
infile.on("data", function (data) {
|
|
616
|
+
try {
|
|
617
|
+
writeChunk(enc.cipher.update(data));
|
|
618
|
+
} catch (err) {
|
|
619
|
+
fail(err);
|
|
620
|
+
}
|
|
621
|
+
});
|
|
622
|
+
|
|
623
|
+
infile.on("end", function () {
|
|
624
|
+
try {
|
|
625
|
+
writeChunk(enc.cipher.final());
|
|
626
|
+
inputEnded = true;
|
|
627
|
+
maybeFinalize();
|
|
628
|
+
} catch (err) {
|
|
629
|
+
fail(err);
|
|
630
|
+
}
|
|
631
|
+
});
|
|
632
|
+
|
|
633
|
+
outfile.on("finish", () => {
|
|
634
|
+
if (settled) return;
|
|
635
|
+
settled = true;
|
|
636
|
+
resolve(outFname);
|
|
637
|
+
});
|
|
552
638
|
});
|
|
553
|
-
infile.on("close", function () {
|
|
554
|
-
outfile.write(enc.cipher.final());
|
|
555
|
-
outfile.close();
|
|
556
|
-
});
|
|
557
|
-
return outFname;
|
|
558
639
|
}
|
|
559
640
|
|
|
560
641
|
/**
|
|
@@ -714,9 +795,11 @@ const utilsModule = {
|
|
|
714
795
|
getConfigFilePath,
|
|
715
796
|
getTimestamp,
|
|
716
797
|
opscompassHome,
|
|
798
|
+
hobKey: HOBKEY,
|
|
717
799
|
readConfigFile,
|
|
718
800
|
readFromStdinSync,
|
|
719
801
|
writeConfigFile,
|
|
802
|
+
encryptFileAES,
|
|
720
803
|
isIPv4,
|
|
721
804
|
isIPv6,
|
|
722
805
|
md5sum,
|
|
@@ -2,21 +2,14 @@ import { getOpsCompassClient } from "../opscompass.js";
|
|
|
2
2
|
import { ScriptType, cliCommand } from "../environment/current.js";
|
|
3
3
|
import {
|
|
4
4
|
downloadScriptsToHome,
|
|
5
|
-
findOrCreateScriptTypeFolder,
|
|
6
5
|
findOrCreateScriptsFolder,
|
|
7
|
-
SRC_FOLDER_NAME,
|
|
8
|
-
BASE_SCRIPTS_RUN_ALL_RELATIVE_PATH,
|
|
9
6
|
getInstalledScriptVersion,
|
|
10
7
|
previousScriptsDownloaded,
|
|
11
8
|
} from "../lib/homeInteraction.js";
|
|
12
|
-
import { canReadFile } from "../lib/cliHelpers.js";
|
|
13
9
|
|
|
14
10
|
import semver from "semver";
|
|
15
11
|
import path from "path";
|
|
16
12
|
import fs from "fs-extra";
|
|
17
|
-
import util from "util";
|
|
18
|
-
import { exec as execSync } from "child_process";
|
|
19
|
-
const exec = util.promisify(execSync);
|
|
20
13
|
|
|
21
14
|
/**
|
|
22
15
|
* Lists script types that are locally downloaded
|
|
@@ -369,33 +362,11 @@ async function autoCheckScriptUpdates(args) {
|
|
|
369
362
|
* The runall.sh file runs all configured modules.
|
|
370
363
|
*/
|
|
371
364
|
async function manuallyRunScripts() {
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
baseScriptFolderPath,
|
|
378
|
-
SRC_FOLDER_NAME,
|
|
379
|
-
BASE_SCRIPTS_RUN_ALL_RELATIVE_PATH,
|
|
380
|
-
);
|
|
381
|
-
|
|
382
|
-
if (canReadFile(runAllFilePath)) {
|
|
383
|
-
const runAllScript = await fs.readFile(runAllFilePath, {
|
|
384
|
-
encoding: "utf-8",
|
|
385
|
-
});
|
|
386
|
-
|
|
387
|
-
const { stdout, stderr } = await exec(runAllScript);
|
|
388
|
-
if (!!stderr) {
|
|
389
|
-
console.log(`Error: ${stderr}`);
|
|
390
|
-
} else {
|
|
391
|
-
console.log(stdout);
|
|
392
|
-
}
|
|
393
|
-
} else {
|
|
394
|
-
throw "Cannot manually run scripts. Make sure the scripts are downloaded.\nIf the issue persists, contact your OpsCompass rep.";
|
|
395
|
-
}
|
|
396
|
-
} catch (err) {
|
|
397
|
-
console.log(err);
|
|
398
|
-
}
|
|
365
|
+
const message =
|
|
366
|
+
"Command disabled for security reasons. Use `opscompass data-gathering run` instead.";
|
|
367
|
+
console.error(message);
|
|
368
|
+
process.exitCode = 1;
|
|
369
|
+
return { error: message, exitCode: 1 };
|
|
399
370
|
}
|
|
400
371
|
|
|
401
372
|
async function printHelp() {
|
|
@@ -438,7 +409,7 @@ async function printHelp() {
|
|
|
438
409
|
console.log();
|
|
439
410
|
console.log(
|
|
440
411
|
"manually-run-scripts",
|
|
441
|
-
"
|
|
412
|
+
"Deprecated and disabled for security reasons. Use `opscompass data-gathering run`.",
|
|
442
413
|
);
|
|
443
414
|
console.log();
|
|
444
415
|
}
|