@opscompass/opscompass-cli 1.0.42 → 1.0.43

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.
@@ -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.42",
3
+ "version": "1.0.43",
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.41",
19
+ "@opscompass/opscompass-api": "^1.0.42",
20
20
  "adm-zip": "^0.5.16",
21
21
  "axios": "^0.28.1",
22
22
  "better-sqlite3": "^11.8.0",