@opscompass/opscompass-cli 1.0.42 → 1.0.44
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/utils.js +8 -3
- package/modules/license-manager.js +1 -1
- package/modules/resources.js +49 -0
- package/package.json +2 -2
package/lib/utils.js
CHANGED
|
@@ -24,6 +24,7 @@ const findRemoveSync = require("find-remove");
|
|
|
24
24
|
const HOBKEY = Buffer.from(`${decoder}=`, "base64").toString();
|
|
25
25
|
const hashPrefix = "oc$hash:"; // Prefix for encrypted values
|
|
26
26
|
const hashRegex = /^oc\$hash:/; // Regex for encrypted values
|
|
27
|
+
const obfuscatedRegex = /^oc\$(hash|mask)/; // Regex for encrypted or masked values
|
|
27
28
|
|
|
28
29
|
// Test for any null or undefined objects
|
|
29
30
|
function hasNullOrUndefined(obj, count = Object.keys(obj).length) {
|
|
@@ -263,7 +264,7 @@ function getConfigFilePath(args = []) {
|
|
|
263
264
|
* Function read a configuration file
|
|
264
265
|
* @param {string}[] args - license-manager arguments
|
|
265
266
|
*/
|
|
266
|
-
function readConfigFile(args) {
|
|
267
|
+
async function readConfigFile(args) {
|
|
267
268
|
const cfgFile = getConfigFilePath(args);
|
|
268
269
|
if (!cfgFile) return undefined;
|
|
269
270
|
|
|
@@ -279,6 +280,10 @@ function readConfigFile(args) {
|
|
|
279
280
|
}
|
|
280
281
|
|
|
281
282
|
decryptValues(cfgFile);
|
|
283
|
+
// Also unmask the cfg file here - in case there are masked values
|
|
284
|
+
const { unmaskObjValues } = require("./maskValues");
|
|
285
|
+
await unmaskObjValues(cfgFile);
|
|
286
|
+
|
|
282
287
|
return cfgFile;
|
|
283
288
|
}
|
|
284
289
|
|
|
@@ -602,8 +607,8 @@ function encryptValues(config) {
|
|
|
602
607
|
for (const resource of config[resType]) {
|
|
603
608
|
for (const attr of Object.keys(encryptAttrs)) {
|
|
604
609
|
if (resource.hasOwnProperty(attr) && resource[attr] !== null) {
|
|
605
|
-
// If this is a sensitive value and it is not already
|
|
606
|
-
if (!resource[attr].match(
|
|
610
|
+
// If this is a sensitive value and it is not already obfuscated
|
|
611
|
+
if (!resource[attr].match(obfuscatedRegex)) {
|
|
607
612
|
resource[attr] = encryptAES(resource[attr]);
|
|
608
613
|
// console.error("Encrypted attribute %s: %s ", attr, resource[attr]);
|
|
609
614
|
}
|
|
@@ -356,7 +356,7 @@ async function readMonitoringConfiguration(args) {
|
|
|
356
356
|
} else console.log("undefined");
|
|
357
357
|
return;
|
|
358
358
|
}
|
|
359
|
-
const monitoringConfig = utils.readConfigFile(args);
|
|
359
|
+
const monitoringConfig = await utils.readConfigFile(args);
|
|
360
360
|
if (monitoringConfig) {
|
|
361
361
|
console.log(JSON.stringify(monitoringConfig, null, 2));
|
|
362
362
|
}
|
package/modules/resources.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
const { getOpsCompassClient } = require("../opscompass.js");
|
|
2
2
|
const { parseMetrics } = require("../lib/parseMetrics.js");
|
|
3
|
+
const { readFileSync } = require("fs");
|
|
3
4
|
|
|
4
5
|
const actionMap = {
|
|
5
6
|
"get": "get",
|
|
@@ -9,6 +10,7 @@ const actionMap = {
|
|
|
9
10
|
"add-tags": "addTags",
|
|
10
11
|
"remove-tags": "removeTags",
|
|
11
12
|
"list": "list",
|
|
13
|
+
"send-external-resources": "sendExternalResources"
|
|
12
14
|
};
|
|
13
15
|
|
|
14
16
|
async function scan(args) {
|
|
@@ -462,6 +464,46 @@ async function getAggregateMetrics(args) {
|
|
|
462
464
|
console.log(JSON.stringify(aggregateMetrics, null, 2));
|
|
463
465
|
}
|
|
464
466
|
|
|
467
|
+
async function sendExternalResources(args) {
|
|
468
|
+
const passedData = {};
|
|
469
|
+
for (let i = 0; i < args.length - 1; i++) {
|
|
470
|
+
switch (args[i].toLowerCase()) {
|
|
471
|
+
case "--resources-info":
|
|
472
|
+
passedData.resourcesInfo = args[++i];
|
|
473
|
+
break;
|
|
474
|
+
case "--json-file-path":
|
|
475
|
+
passedData.jsonFilePath = args[++i];
|
|
476
|
+
break;
|
|
477
|
+
}
|
|
478
|
+
}
|
|
479
|
+
|
|
480
|
+
if (passedData.jsonFilePath) {
|
|
481
|
+
try {
|
|
482
|
+
const data = readFileSync(passedData.jsonFilePath, 'utf8');
|
|
483
|
+
passedData.resourcesInfo = data;
|
|
484
|
+
} catch (error) {
|
|
485
|
+
console.error("Error reading JSON file:", error.message);
|
|
486
|
+
return;
|
|
487
|
+
}
|
|
488
|
+
}
|
|
489
|
+
let callData = {};
|
|
490
|
+
if (!passedData.resourcesInfo) {
|
|
491
|
+
console.error("You must provide --resources-info with a stringified JSON object of resource info or --json-file-path.");
|
|
492
|
+
return;
|
|
493
|
+
} else {
|
|
494
|
+
try {
|
|
495
|
+
callData = JSON.parse(passedData.resourcesInfo);
|
|
496
|
+
} catch (error) {
|
|
497
|
+
console.error("Invalid JSON provided for --resources-info:", error.message);
|
|
498
|
+
return;
|
|
499
|
+
}
|
|
500
|
+
}
|
|
501
|
+
|
|
502
|
+
const client = await getOpsCompassClient();
|
|
503
|
+
const sendResponse = await client.resources[actionMap['send-external-resources']](callData);
|
|
504
|
+
console.log(JSON.stringify(sendResponse, null, 2));
|
|
505
|
+
}
|
|
506
|
+
|
|
465
507
|
async function printHelp() {
|
|
466
508
|
console.log("Actions available for resources:");
|
|
467
509
|
console.log();
|
|
@@ -586,6 +628,11 @@ async function printHelp() {
|
|
|
586
628
|
console.log("--calculated-at-from (optional) [timestamp]");
|
|
587
629
|
console.log("--calculated-at-to (optional) [timestamp]");
|
|
588
630
|
console.log();
|
|
631
|
+
console.log("send-external-resources", "Sends external resources to Opscompass to be scanned. Only 500 resources can be sent at a time.");
|
|
632
|
+
console.log("Parameters:");
|
|
633
|
+
console.log("--resources-info (optional) [Stringified JSON of resource info]");
|
|
634
|
+
console.log("--json-file-path (optional) [Path to JSON file containing resource info]");
|
|
635
|
+
console.log();
|
|
589
636
|
}
|
|
590
637
|
|
|
591
638
|
const resourcesModule = (action, ...args) => {
|
|
@@ -618,6 +665,8 @@ const resourcesModule = (action, ...args) => {
|
|
|
618
665
|
return getMetricCheckResults(args);
|
|
619
666
|
case "get-aggregate-metrics":
|
|
620
667
|
return getAggregateMetrics(args);
|
|
668
|
+
case "send-external-resources":
|
|
669
|
+
return sendExternalResources(args);
|
|
621
670
|
case "help":
|
|
622
671
|
case "":
|
|
623
672
|
return printHelp();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@opscompass/opscompass-cli",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.44",
|
|
4
4
|
"description": "Calls OpsCompass's APIs",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
"author": "opscompass",
|
|
17
17
|
"license": "SEE LICENSE IN license.txt",
|
|
18
18
|
"dependencies": {
|
|
19
|
-
"@opscompass/opscompass-api": "^1.0.
|
|
19
|
+
"@opscompass/opscompass-api": "^1.0.43",
|
|
20
20
|
"adm-zip": "^0.5.16",
|
|
21
21
|
"axios": "^0.28.1",
|
|
22
22
|
"better-sqlite3": "^11.8.0",
|