@opscompass/opscompass-cli 1.0.36 → 1.0.38

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,14 +1,67 @@
1
1
  const { setArgumentArrays } = require("../lib/cliHelpers.js");
2
2
  const { getOpsCompassClient } = require("../opscompass.js");
3
+ const { utilsModule: utils } = require("../lib/utils.js");
4
+ const maskValues = require("../lib/maskValues.js");
5
+ const { config } = require("openpgp");
6
+
7
+ /**
8
+ * Create a masked configuration to prevent it from being sent to OpsCompass in the clear
9
+ *
10
+ * @param {string} funcName
11
+ * @param {string} configurationName - Name for the specific configuration object
12
+ * @param {object} optionalParams - values to send (and potentially mask)
13
+ */
14
+ async function createMaskedConfig(funcName, configurationName, optionalParams) {
15
+ const client = await getOpsCompassClient();
16
+
17
+ // Make sure we have a valid function name
18
+ if (!funcName || !client.licenseManager[funcName]) {
19
+ throw new Error("Invalid function name");
20
+ }
21
+ // Mask the data
22
+ await maskValues.maskObjValues(optionalParams);
23
+
24
+ // Call the API
25
+ const monitoringConfiguration = await client.licenseManager[funcName](
26
+ global.monitoringConfig,
27
+ configurationName,
28
+ optionalParams
29
+ );
30
+
31
+ return monitoringConfiguration;
32
+ }
33
+
34
+ /**
35
+ * Update a masked configuration to prevent it from being sent to OpsCompass in the clear
36
+ *
37
+ * @param {string} funcName
38
+ * @param {string} configurationId - ID of the configuration to be updated
39
+ * @param {object} optionalParams - values to send (and potentially mask)
40
+ */
41
+ async function updateMaskedConfig(funcName, configurationId, optionalParams) {
42
+ const client = await getOpsCompassClient();
43
+
44
+ // Make sure we have a valid function name
45
+ if (!funcName || !client.licenseManager[funcName]) {
46
+ throw new Error("Invalid function name");
47
+ }
48
+
49
+ // Mask the data
50
+ await maskValues.maskObjValues(optionalParams);
51
+
52
+ // Call the API
53
+ const targetConfiguration = await client.licenseManager[funcName](
54
+ configurationId,
55
+ optionalParams
56
+ );
57
+
58
+ return targetConfiguration;
59
+ }
3
60
 
4
61
  async function createOracleSharedCredential(args) {
5
62
  let optionalParams = {};
6
63
  for (let i = 0; i < args.length - 1; i++) {
7
64
  switch (args[i].toLowerCase()) {
8
- case "--monitoring-configuration-id":
9
- case "--monitoringconfigurationid":
10
- monitoringConfig = args[++i];
11
- break;
12
65
  case "--user":
13
66
  optionalParams.user = args[++i];
14
67
  break;
@@ -26,7 +79,7 @@ async function createOracleSharedCredential(args) {
26
79
  try {
27
80
  const createResponse =
28
81
  await client.licenseManager.createOracleSharedCredential(
29
- monitoringConfig,
82
+ global.monitoringConfig,
30
83
  optionalParams
31
84
  );
32
85
 
@@ -55,18 +108,9 @@ async function deleteOracleSharedCredential(args) {
55
108
  }
56
109
 
57
110
  async function getOracleDefaultCredential(args) {
58
- for (let i = 0; i < args.length - 1; i++) {
59
- switch (args[i].toLowerCase()) {
60
- case "--monitoring-configuration-id":
61
- case "--monitoringconfigurationid":
62
- monitoringConfig = args[++i];
63
- break;
64
- }
65
- }
66
-
67
111
  const client = await getOpsCompassClient();
68
112
  const getResponse = await client.licenseManager.getOracleDefaultCredential(
69
- monitoringConfig
113
+ global.monitoringConfig
70
114
  );
71
115
 
72
116
  console.log(JSON.stringify(getResponse, null, 2));
@@ -103,18 +147,9 @@ async function updateOracleSharedCredential(args) {
103
147
  }
104
148
 
105
149
  async function getMsqlDefaultCredential(args) {
106
- for (let i = 0; i < args.length - 1; i++) {
107
- switch (args[i].toLowerCase()) {
108
- case "--monitoring-configuration-id":
109
- case "--monitoringconfigurationid":
110
- monitoringConfig = args[++i];
111
- break;
112
- }
113
- }
114
-
115
150
  const client = await getOpsCompassClient();
116
151
  const getResponse = await client.licenseManager.getMsqlDefaultCredential(
117
- monitoringConfig
152
+ global.monitoringConfig
118
153
  );
119
154
 
120
155
  console.log(JSON.stringify(getResponse, null, 2));
@@ -124,10 +159,6 @@ async function createMsqlSharedCredential(args) {
124
159
  let optionalParams = {};
125
160
  for (let i = 0; i < args.length - 1; i++) {
126
161
  switch (args[i].toLowerCase()) {
127
- case "--monitoring-configuration-id":
128
- case "--monitoringconfigurationid":
129
- monitoringConfig = args[++i];
130
- break;
131
162
  case "--user":
132
163
  optionalParams.user = args[++i];
133
164
  break;
@@ -148,7 +179,7 @@ async function createMsqlSharedCredential(args) {
148
179
  const client = await getOpsCompassClient();
149
180
  const createResponse =
150
181
  await client.licenseManager.createMsqlSharedCredential(
151
- monitoringConfig,
182
+ global.monitoringConfig,
152
183
  optionalParams
153
184
  );
154
185
 
@@ -210,21 +241,18 @@ async function updateMsqlSharedCredential(args) {
210
241
  }
211
242
 
212
243
  async function listMonitoringConfigurations(args) {
213
- for (let i = 0; i < args.length - 1; i++) {
214
- switch (args[i].toLowerCase()) {
215
- case "--company":
216
- company = args[++i];
217
- break;
218
- }
219
- }
220
-
221
244
  const client = await getOpsCompassClient();
222
245
  const monitoringConfigs =
223
- await client.licenseManager.listMonitoringConfigurations(company);
246
+ await client.licenseManager.listMonitoringConfigurations(global.company);
224
247
 
225
248
  console.log(JSON.stringify(monitoringConfigs, null, 2));
226
249
  }
227
250
 
251
+ async function maskMonitoringConfigurations(args) {
252
+ const action = args.shift();
253
+ maskValues(action, ...args);
254
+ }
255
+
228
256
  async function deleteVCenterConfiguration(args) {
229
257
  let id = undefined;
230
258
  for (let i = 0; i < args.length - 1; i++) {
@@ -296,12 +324,8 @@ async function deleteMssqlEntitlements(args) {
296
324
  args = setArgumentArrays(["--id"], args);
297
325
 
298
326
  let recordIds = undefined;
299
- let company = undefined;
300
327
  for (let i = 0; i < args.length - 1; i++) {
301
328
  switch (args[i].toLowerCase()) {
302
- case "--company":
303
- company = args[++i];
304
- break;
305
329
  case "--id":
306
330
  recordIds = args[++i];
307
331
  break;
@@ -310,27 +334,17 @@ async function deleteMssqlEntitlements(args) {
310
334
 
311
335
  const client = await getOpsCompassClient();
312
336
  const response = await client.licenseManager.deleteMssqlEntitlements(
313
- company,
337
+ global.company,
314
338
  recordIds
315
339
  );
316
-
317
340
  console.log(JSON.stringify(response, null, 2));
318
341
  }
319
342
 
320
343
  async function listOracleDatabaseConfigurations(args) {
321
- for (let i = 0; i < args.length - 1; i++) {
322
- switch (args[i].toLowerCase()) {
323
- case "--monitoringconfigurationid":
324
- case "--monitoring-configuration-id":
325
- monitoringConfig = args[++i];
326
- break;
327
- }
328
- }
329
-
330
344
  const client = await getOpsCompassClient();
331
345
  const monitoringConfigs =
332
346
  await client.licenseManager.listOracleDatabaseConfigurations(
333
- monitoringConfig
347
+ global.monitoringConfig
334
348
  );
335
349
 
336
350
  console.log(JSON.stringify(monitoringConfigs, null, 2));
@@ -369,10 +383,10 @@ async function getSecretForConfiguration(args) {
369
383
  }
370
384
 
371
385
  const client = await getOpsCompassClient();
372
- const monitoringConfig =
386
+ const monitoringSecret =
373
387
  await client.licenseManager.getSecretForConfiguration(id, recordType);
374
388
 
375
- console.log(JSON.stringify(monitoringConfig, null, 2));
389
+ console.log(JSON.stringify(monitoringSecret, null, 2));
376
390
  }
377
391
 
378
392
  async function getNetworkDiscoveryConfiguration(args) {
@@ -394,12 +408,18 @@ async function getNetworkDiscoveryConfiguration(args) {
394
408
 
395
409
  async function getMonitoringConfiguration(args) {
396
410
  let optionalParams = { asFile: undefined };
411
+ let configId = global.monitoringConfig;
412
+ let saveFile = false;
397
413
  for (let i = 0; i < args.length - 1; i++) {
398
414
  switch (args[i].toLowerCase()) {
399
415
  case "--id":
400
- monitoringConfig = args[++i];
416
+ configId = args[++i];
401
417
  break;
418
+ case "--savefile":
419
+ case "--save-file":
420
+ saveFile = true; // and fall through because asFile is impled
402
421
  case "--asfile":
422
+ case "--as-file":
403
423
  optionalParams.asFile = args[++i];
404
424
  break;
405
425
  }
@@ -408,11 +428,63 @@ async function getMonitoringConfiguration(args) {
408
428
  const client = await getOpsCompassClient();
409
429
  const monitoringConfiguration =
410
430
  await client.licenseManager.getMonitoringConfiguration(
411
- monitoringConfig,
431
+ configId,
412
432
  optionalParams
413
433
  );
434
+ if (!monitoringConfiguration) {
435
+ console.error("No configuration found for ID: ", configId);
436
+ return;
437
+ }
414
438
 
415
- console.log(JSON.stringify(monitoringConfiguration, null, 2));
439
+ // Here we have to resolve any locally masked values
440
+ if (
441
+ optionalParams.hasOwnProperty("asFile") &&
442
+ optionalParams.asFile === "true"
443
+ ) {
444
+ await maskValues.unmaskObjValues(monitoringConfiguration);
445
+ // console.error(
446
+ // "Unmasked values in the configuration file.",
447
+ // JSON.stringify(monitoringConfiguration, null, 2)
448
+ // );
449
+ }
450
+
451
+ if (saveFile) {
452
+ if (!utils.writeConfigFile(args, monitoringConfiguration)) {
453
+ console.error("\n\nFailed to save the configuration file.\n");
454
+ console.log(JSON.stringify(monitoringConfiguration, null, 2));
455
+ } else {
456
+ console.log(monitoringConfiguration.filePath);
457
+ }
458
+ } else {
459
+ console.log(JSON.stringify(monitoringConfiguration, null, 2));
460
+ }
461
+ }
462
+
463
+ async function readMonitoringConfiguration(args) {
464
+ let getPath = false;
465
+ for (let i = 0; i <= args.length - 1; i++) {
466
+ switch (args[i].toLowerCase()) {
467
+ case "--id":
468
+ configId = args[++i];
469
+ break;
470
+ case "--listdetails":
471
+ case "--list-details":
472
+ getPath = true;
473
+ args.splice(i, 1);
474
+ break;
475
+ }
476
+ }
477
+
478
+ // If all they want is the details, then just return them
479
+ if (getPath === true) {
480
+ const cfgFile = utils.getConfigFilePath(args);
481
+ console.log(JSON.stringify(cfgFile, null, 2));
482
+ return;
483
+ }
484
+ const monitoringConfig = utils.readConfigFile(args);
485
+ if (monitoringConfig) {
486
+ console.log(JSON.stringify(monitoringConfig, null, 2));
487
+ }
416
488
  }
417
489
 
418
490
  async function createMonitoringConfiguration(args) {
@@ -423,9 +495,7 @@ async function createMonitoringConfiguration(args) {
423
495
  };
424
496
  for (let i = 0; i < args.length - 1; i++) {
425
497
  switch (args[i].toLowerCase()) {
426
- case "--company":
427
- company = args[++i];
428
- break;
498
+ case "--name":
429
499
  case "--configurationname":
430
500
  case "--configuration-name":
431
501
  name = args[++i];
@@ -443,24 +513,21 @@ async function createMonitoringConfiguration(args) {
443
513
 
444
514
  const client = await getOpsCompassClient();
445
515
  const monitoringConfiguration =
446
- await client.licenseManager.createMonitoringConfiguration(company, name, optionalParams);
516
+ await client.licenseManager.createMonitoringConfiguration(
517
+ global.company,
518
+ name,
519
+ optionalParams
520
+ );
447
521
 
448
522
  console.log(JSON.stringify(monitoringConfiguration, null, 2));
449
523
  }
450
524
 
451
525
  async function listVCenterConfigurations(args) {
452
- for (let i = 0; i < args.length - 1; i++) {
453
- switch (args[i].toLowerCase()) {
454
- case "--monitoringconfigurationid":
455
- case "--monitoring-configuration-id":
456
- monitoringConfig = args[++i];
457
- break;
458
- }
459
- }
460
-
461
526
  const client = await getOpsCompassClient();
462
527
  const listVCenterConfigs =
463
- await client.licenseManager.listVCenterConfigurations(monitoringConfig);
528
+ await client.licenseManager.listVCenterConfigurations(
529
+ global.monitoringConfig
530
+ );
464
531
 
465
532
  console.log(JSON.stringify(listVCenterConfigs, null, 2));
466
533
  }
@@ -484,7 +551,7 @@ async function getVCenterConfiguration(args) {
484
551
  }
485
552
 
486
553
  async function createVCenterConfiguration(args) {
487
- let name = undefined;
554
+ let configurationName = undefined;
488
555
  let optionalParams = {
489
556
  actions: undefined,
490
557
  connection: undefined,
@@ -493,12 +560,10 @@ async function createVCenterConfiguration(args) {
493
560
  };
494
561
  for (let i = 0; i < args.length - 1; i++) {
495
562
  switch (args[i].toLowerCase()) {
496
- case "--monitoringconfigurationid":
497
- case "--monitoring-configuration-id":
498
- monitoringConfig = args[++i];
499
- break;
500
563
  case "--name":
501
- name = args[++i];
564
+ case "--configuration-name":
565
+ case "--configurationname":
566
+ configurationName = args[++i];
502
567
  break;
503
568
  case "--action":
504
569
  if (optionalParams.actions === undefined) optionalParams.actions = [];
@@ -516,30 +581,18 @@ async function createVCenterConfiguration(args) {
516
581
  }
517
582
  }
518
583
 
519
- const client = await getOpsCompassClient();
520
- const monitoringConfiguration =
521
- await client.licenseManager.createVCenterConfiguration(
522
- monitoringConfig,
523
- name,
524
- optionalParams
525
- );
526
-
527
- console.log(JSON.stringify(monitoringConfiguration, null, 2));
584
+ const vCenterConfiguration = await createMaskedConfig(
585
+ arguments.callee.name,
586
+ configurationName,
587
+ optionalParams
588
+ );
589
+ console.log(JSON.stringify(vCenterConfiguration, null, 2));
528
590
  }
529
591
 
530
592
  async function listMsqlConfigurations(args) {
531
- for (let i = 0; i < args.length - 1; i++) {
532
- switch (args[i].toLowerCase()) {
533
- case "--monitoringconfigurationid":
534
- case "--monitoring-configuration-id":
535
- monitoringConfig = args[++i];
536
- break;
537
- }
538
- }
539
-
540
593
  const client = await getOpsCompassClient();
541
594
  const listMsqlConfigs = await client.licenseManager.listMsqlConfigurations(
542
- monitoringConfig
595
+ global.monitoringConfig
543
596
  );
544
597
 
545
598
  console.log(JSON.stringify(listMsqlConfigs, null, 2));
@@ -554,12 +607,10 @@ async function createMsqlConfiguration(args) {
554
607
  password: undefined,
555
608
  directory_auth: undefined,
556
609
  };
610
+
557
611
  for (let i = 0; i < args.length - 1; i++) {
558
612
  switch (args[i].toLowerCase()) {
559
- case "--monitoringconfigurationid":
560
- case "--monitoring-configuration-id":
561
- monitoringConfig = args[++i];
562
- break;
613
+ case "--name":
563
614
  case "--configuration-name":
564
615
  case "--configurationname":
565
616
  configurationName = args[++i];
@@ -588,14 +639,11 @@ async function createMsqlConfiguration(args) {
588
639
  }
589
640
  }
590
641
 
591
- const client = await getOpsCompassClient();
592
-
593
- const msqlConfiguration = await client.licenseManager.createMsqlConfiguration(
594
- monitoringConfig,
642
+ const msqlConfiguration = await createMaskedConfig(
643
+ arguments.callee.name,
595
644
  configurationName,
596
645
  optionalParams
597
646
  );
598
-
599
647
  console.log(JSON.stringify(msqlConfiguration, null, 2));
600
648
  }
601
649
 
@@ -616,34 +664,23 @@ async function getMsqlConfiguration(args) {
616
664
  }
617
665
 
618
666
  async function getMssqlEntitlements(args) {
619
- let company = undefined;
620
- for (let i = 0; i < args.length - 1; i++) {
621
- switch (args[i].toLowerCase()) {
622
- case "--company":
623
- company = args[++i];
624
- break;
625
- }
626
- }
627
-
628
667
  const client = await getOpsCompassClient();
629
668
  const mssqlEntitlements = await client.licenseManager.getMssqlEntitlements(
630
- company
669
+ global.company
631
670
  );
632
671
 
633
672
  console.log(JSON.stringify(mssqlEntitlements, null, 2));
634
673
  }
635
674
 
636
675
  async function createOracleDatabaseConfiguration(args) {
637
- let name = undefined;
676
+ let configurationName = undefined;
638
677
  let optionalParams = {};
639
678
  for (let i = 0; i < args.length - 1; i++) {
640
679
  switch (args[i].toLowerCase()) {
641
- case "--monitoringconfigurationid":
642
- case "--monitoring-configuration-id":
643
- monitoringConfig = args[++i];
644
- break;
645
680
  case "--name":
646
- name = args[++i];
681
+ case "--configuration-name":
682
+ case "--configurationname":
683
+ configurationName = args[++i];
647
684
  break;
648
685
  case "--action":
649
686
  if (optionalParams.actions === undefined) optionalParams.actions = [];
@@ -661,22 +698,45 @@ async function createOracleDatabaseConfiguration(args) {
661
698
  }
662
699
  }
663
700
 
664
- const client = await getOpsCompassClient();
665
- const monitoringConfiguration =
666
- await client.licenseManager.createOracleDatabaseConfiguration(
667
- monitoringConfig,
668
- name,
669
- optionalParams
670
- );
701
+ const oracleDatabaseConfiguration = await createMaskedConfig(
702
+ arguments.callee.name,
703
+ configurationName,
704
+ optionalParams
705
+ );
706
+ console.log(JSON.stringify(oracleDatabaseConfiguration, null, 2));
707
+ }
671
708
 
672
- console.log(JSON.stringify(monitoringConfiguration, null, 2));
709
+ /**
710
+ * Parse a configuration JSON string
711
+ * @param {*} jsonString
712
+ * @returns any
713
+ */
714
+ function parseConfigurationJson(jsonString) {
715
+ let obj = JSON.parse("{}");
716
+ try {
717
+ obj = JSON.parse(jsonString);
718
+ if (!Array.isArray(obj)) {
719
+ obj = [obj];
720
+ }
721
+ // If configId (as in data gathering config file), replace with just "id"
722
+ for (let i = 0; i < obj.length; i++) {
723
+ if (obj[i].config_id && !obj[i].id) {
724
+ obj[i].id = obj[i].config_id;
725
+ delete obj[i].config_id;
726
+ }
727
+ }
728
+ } catch (err) {
729
+ console.error("Invalid JSON string provided.");
730
+ return null;
731
+ }
732
+ return obj;
673
733
  }
674
734
 
675
735
  async function updateMonitoringConfiguration(args) {
676
736
  // Prep any arguments that are arrays
677
737
  args = setArgumentArrays(["--emailTo", "--notificationEmailTo"], args);
678
738
 
679
- callParams.id = monitoringConfig;
739
+ callParams.id = global.monitoringConfig;
680
740
  for (let i = 0; i < args.length - 1; i++) {
681
741
  switch (args[i].toLowerCase()) {
682
742
  case "--id":
@@ -762,13 +822,11 @@ async function updateOracleDatabaseConfiguration(args) {
762
822
  }
763
823
  }
764
824
 
765
- const client = await getOpsCompassClient();
766
- const oracleDatabaseConfiguration =
767
- await client.licenseManager.updateOracleDatabaseConfiguration(
768
- callParams.id,
769
- callParams
770
- );
771
-
825
+ const oracleDatabaseConfiguration = await updateMaskedConfig(
826
+ arguments.callee.name,
827
+ callParams.id,
828
+ callParams
829
+ );
772
830
  console.log(JSON.stringify(oracleDatabaseConfiguration, null, 2));
773
831
  }
774
832
 
@@ -780,8 +838,14 @@ async function updateOracleDatabaseConfigurations(args) {
780
838
 
781
839
  /* Process bulk update with JSON */
782
840
  if (jsonIndex !== -1) {
783
- const jsonString = args[jsonIndex + 1];
784
- callParamsArray = JSON.parse(jsonString);
841
+ const jsonString = args[jsonIndex + 1] || (await utils.readStdin());
842
+ if (!jsonString) {
843
+ if (process.stdin.isTTY) {
844
+ console.error("No JSON Oracle DB string provided as argument or stdin");
845
+ return console.log("");
846
+ }
847
+ }
848
+ callParamsArray = parseConfigurationJson(jsonString);
785
849
  } else if (idIndex !== -1) {
786
850
  /* If no '--json-update' flag, process bulk update with parameter flags (e.g. --id, --name, etc.) */
787
851
  for (let i = 0; i < args.length - 1; i++) {
@@ -813,6 +877,12 @@ async function updateOracleDatabaseConfigurations(args) {
813
877
  console.warn("Invalid input, please see help for examples.");
814
878
  return console.log("");
815
879
  }
880
+ // In case the cut/paste from an local config with values hashed
881
+ utils.decryptValues(callParamsArray);
882
+
883
+ // Here we need to mask the callParamsArray object
884
+ await maskValues.maskObjValues(callParamsArray);
885
+
816
886
  /* Call the API and print to console */
817
887
  const client = await getOpsCompassClient();
818
888
  const oracleDatabaseConfigurations =
@@ -849,12 +919,11 @@ async function updateVCenterConfiguration(args) {
849
919
  }
850
920
  }
851
921
 
852
- const client = await getOpsCompassClient();
853
- const vCenterConfiguration =
854
- await client.licenseManager.updateVCenterConfiguration(
855
- callParams.id,
856
- callParams
857
- );
922
+ const vCenterConfiguration = await updateMaskedConfig(
923
+ arguments.callee.name,
924
+ callParams.id,
925
+ callParams
926
+ );
858
927
  console.log(JSON.stringify(vCenterConfiguration, null, 2));
859
928
  }
860
929
 
@@ -866,8 +935,14 @@ async function updateVCenterConfigurations(args) {
866
935
 
867
936
  /* Process bulk update with JSON */
868
937
  if (jsonIndex !== -1) {
869
- const jsonString = args[jsonIndex + 1];
870
- callParamsArray = JSON.parse(jsonString);
938
+ const jsonString = args[jsonIndex + 1] || (await utils.readStdin());
939
+ if (!jsonString) {
940
+ if (process.stdin.isTTY) {
941
+ console.error("No JSON vCenter string provided as argument or stdin");
942
+ return console.log("");
943
+ }
944
+ }
945
+ callParamsArray = parseConfigurationJson(jsonString);
871
946
  } else if (idIndex !== -1) {
872
947
  /* If no '--json-update' flag, process bulk update with parameter flags (e.g. --id, --name, etc.) */
873
948
  for (let i = 0; i < args.length - 1; i++) {
@@ -899,6 +974,11 @@ async function updateVCenterConfigurations(args) {
899
974
  console.warn("Invalid input, please see help for examples.");
900
975
  return console.log("");
901
976
  }
977
+ // In case the cut/paste from an local config with values hashed
978
+ utils.decryptValues(callParamsArray);
979
+
980
+ // Here we need to mask the callParamsArray object
981
+ await maskValues.maskObjValues(callParamsArray);
902
982
 
903
983
  /* Call the API and print to console */
904
984
  const client = await getOpsCompassClient();
@@ -941,8 +1021,9 @@ async function updateMsqlConfiguration(args) {
941
1021
  break;
942
1022
  }
943
1023
  }
944
- const client = await getOpsCompassClient();
945
- const msqlConfiguration = await client.licenseManager.updateMsqlConfiguration(
1024
+
1025
+ const msqlConfiguration = await updateMaskedConfig(
1026
+ arguments.callee.name,
946
1027
  callParams.id,
947
1028
  callParams
948
1029
  );
@@ -957,9 +1038,16 @@ async function updateMsqlConfigurations(args) {
957
1038
 
958
1039
  /* Process bulk update with JSON */
959
1040
  if (jsonIndex !== -1) {
960
- const jsonString = args[jsonIndex + 1];
961
- callParamsArray = JSON.parse(jsonString);
962
-
1041
+ const jsonString = args[jsonIndex + 1] || (await utils.readStdin());
1042
+ if (!jsonString) {
1043
+ if (process.stdin.isTTY) {
1044
+ console.error(
1045
+ "No JSON Microsoft DB string provided as argument or stdin"
1046
+ );
1047
+ return console.log("");
1048
+ }
1049
+ }
1050
+ callParamsArray = parseConfigurationJson(jsonString);
963
1051
  /* If no '--json-updates' flag, process bulk update with parameter flags (e.g. --id, --name, etc.) */
964
1052
  } else if (idIndex !== -1) {
965
1053
  for (let i = 0; i < args.length - 1; i++) {
@@ -998,6 +1086,11 @@ async function updateMsqlConfigurations(args) {
998
1086
  console.warn("Invalid input, please see help for examples.");
999
1087
  return console.log("");
1000
1088
  }
1089
+ // In case the cut/paste from an local config with values hashed
1090
+ utils.decryptValues(callParamsArray);
1091
+
1092
+ // Here we need to mask the callParamsArray object
1093
+ await maskValues.maskObjValues(callParamsArray);
1001
1094
 
1002
1095
  /* Call the API and print to console */
1003
1096
  const client = await getOpsCompassClient();
@@ -1007,18 +1100,9 @@ async function updateMsqlConfigurations(args) {
1007
1100
  }
1008
1101
 
1009
1102
  async function getMssqlEntitlementComponents(args) {
1010
- let company = undefined;
1011
- for (let i = 0; i < args.length - 1; i++) {
1012
- switch (args[i].toLowerCase()) {
1013
- case "--company":
1014
- company = args[++i];
1015
- break;
1016
- }
1017
- }
1018
-
1019
1103
  const client = await getOpsCompassClient();
1020
1104
  const entitlementComponents =
1021
- await client.licenseManager.getMssqlEntitlementComponents(company);
1105
+ await client.licenseManager.getMssqlEntitlementComponents(global.company);
1022
1106
  console.log(JSON.stringify(entitlementComponents, null, 2));
1023
1107
  }
1024
1108
 
@@ -1083,31 +1167,34 @@ async function updateNetworkDiscoveryConfiguration(args) {
1083
1167
  }
1084
1168
  }
1085
1169
 
1086
- const client = await getOpsCompassClient();
1170
+ const networkDiscoveryConfig = {
1171
+ subnets: subnets || undefined,
1172
+ dns_servers: dns_servers || undefined,
1173
+ ports: ports || undefined,
1174
+ };
1175
+
1176
+ // Mask the data
1177
+ await maskValues.maskObjValues(networkDiscoveryConfig);
1087
1178
 
1088
- const networkDiscoveryConfig =
1179
+ const client = await getOpsCompassClient();
1180
+ const updatedDiscoveryConfig =
1089
1181
  await client.licenseManager.updateNetworkDiscoveryConfiguration(
1090
1182
  id,
1091
- subnets || undefined,
1092
- dns_servers || undefined,
1093
- ports || undefined
1183
+ networkDiscoveryConfig.subnets,
1184
+ networkDiscoveryConfig.dns_servers,
1185
+ networkDiscoveryConfig.ports
1094
1186
  );
1095
-
1096
- console.log(JSON.stringify(networkDiscoveryConfig, null, 2));
1187
+ console.log(JSON.stringify(updatedDiscoveryConfig, null, 2));
1097
1188
  }
1098
1189
 
1099
1190
  async function createNetworkDiscoveryConfiguration(args) {
1100
- let id = undefined;
1101
1191
  let currentSubnet = {};
1102
1192
  let subnets = [];
1103
1193
  let dns_servers = [];
1104
1194
  let ports = {};
1195
+
1105
1196
  for (let i = 0; i < args.length - 1; i++) {
1106
1197
  switch (args[i].toLowerCase()) {
1107
- case "--monitoringconfigurationid":
1108
- case "--monitoring-configuration-id":
1109
- id = args[++i];
1110
- break;
1111
1198
  case "--oracle-ports":
1112
1199
  case "--oracleports":
1113
1200
  ports["oracle_ports"] = args[++i];
@@ -1142,21 +1229,27 @@ async function createNetworkDiscoveryConfiguration(args) {
1142
1229
  }
1143
1230
  }
1144
1231
 
1145
- const client = await getOpsCompassClient();
1232
+ const networkDiscoveryConfig = {
1233
+ subnets: subnets || undefined,
1234
+ dns_servers: dns_servers || undefined,
1235
+ ports: ports || undefined,
1236
+ };
1146
1237
 
1147
- const networkDiscoveryConfig =
1238
+ // Mask the data
1239
+ await maskValues.maskObjValues(networkDiscoveryConfig);
1240
+
1241
+ const client = await getOpsCompassClient();
1242
+ const createdDiscoveryConfig =
1148
1243
  await client.licenseManager.createNetworkDiscoveryConfiguration(
1149
- id,
1150
- subnets || undefined,
1151
- dns_servers || undefined,
1152
- ports || undefined
1244
+ global.monitoringConfig,
1245
+ networkDiscoveryConfig.subnets,
1246
+ networkDiscoveryConfig.dns_servers,
1247
+ networkDiscoveryConfig.ports
1153
1248
  );
1154
-
1155
- console.log(JSON.stringify(networkDiscoveryConfig, null, 2));
1249
+ console.log(JSON.stringify(createdDiscoveryConfig, null, 2));
1156
1250
  }
1157
1251
 
1158
1252
  async function createMssqlEntitlement(args) {
1159
- let company = undefined;
1160
1253
  let newRecord = {
1161
1254
  purchaseDate: undefined,
1162
1255
  quantity: undefined,
@@ -1169,9 +1262,6 @@ async function createMssqlEntitlement(args) {
1169
1262
  };
1170
1263
  for (let i = 0; i < args.length - 1; i++) {
1171
1264
  switch (args[i].toLowerCase()) {
1172
- case "--company":
1173
- company = args[++i];
1174
- break;
1175
1265
  case "--purchase-date":
1176
1266
  case "--purchasedate":
1177
1267
  newRecord.purchaseDate = args[++i];
@@ -1208,14 +1298,13 @@ async function createMssqlEntitlement(args) {
1208
1298
 
1209
1299
  const client = await getOpsCompassClient();
1210
1300
  const response = await client.licenseManager.createMssqlEntitlements(
1211
- company,
1301
+ global.company,
1212
1302
  [newRecord]
1213
1303
  );
1214
1304
  console.log(JSON.stringify(response, null, 2));
1215
1305
  }
1216
1306
 
1217
1307
  async function updateMssqlEntitlement(args) {
1218
- let company = undefined;
1219
1308
  let updateRecord = {
1220
1309
  id: undefined,
1221
1310
  purchaseDate: undefined,
@@ -1229,9 +1318,6 @@ async function updateMssqlEntitlement(args) {
1229
1318
  };
1230
1319
  for (let i = 0; i < args.length - 1; i++) {
1231
1320
  switch (args[i].toLowerCase()) {
1232
- case "--company":
1233
- company = args[++i];
1234
- break;
1235
1321
  case "--id":
1236
1322
  updateRecord.id = args[++i];
1237
1323
  break;
@@ -1271,24 +1357,17 @@ async function updateMssqlEntitlement(args) {
1271
1357
 
1272
1358
  const client = await getOpsCompassClient();
1273
1359
  const response = await client.licenseManager.updateMssqlEntitlements(
1274
- company,
1360
+ global.company,
1275
1361
  [updateRecord]
1276
1362
  );
1277
1363
  console.log(JSON.stringify(response, null, 2));
1278
1364
  }
1279
1365
 
1280
1366
  async function listMssqlAssessments(args) {
1281
- let company = undefined;
1282
- for (let i = 0; i < args.length - 1; i++) {
1283
- switch (args[i].toLowerCase()) {
1284
- case "--company":
1285
- company = args[++i];
1286
- break;
1287
- }
1288
- }
1289
-
1290
1367
  const client = await getOpsCompassClient();
1291
- const response = await client.licenseManager.listMssqlAssessments(company);
1368
+ const response = await client.licenseManager.listMssqlAssessments(
1369
+ global.company
1370
+ );
1292
1371
 
1293
1372
  console.log(JSON.stringify(response, null, 2));
1294
1373
  }
@@ -1373,16 +1452,12 @@ async function getMssqlAssessmentResources(args) {
1373
1452
  }
1374
1453
 
1375
1454
  async function checkMssqlConfigMetadata(args) {
1376
-
1377
1455
  for (let i = 0; i < args.length - 1; i++) {
1378
1456
  switch (args[i].toLowerCase()) {
1379
- case "--account-id":
1457
+ case "--account-id":
1380
1458
  case "--accountid":
1381
1459
  callParams.accountId = args[++i];
1382
1460
  break;
1383
- case "--company":
1384
- callParams.company = args[++i];
1385
- break;
1386
1461
  case "--last-collected-before":
1387
1462
  case "--lastcollectedbefore":
1388
1463
  callParams.lastCollectedBefore = args[++i];
@@ -1390,23 +1465,22 @@ async function checkMssqlConfigMetadata(args) {
1390
1465
  }
1391
1466
  }
1392
1467
 
1393
- const client = await getOpsCompassClient();
1394
- const response = await client.licenseManager.checkMssqlConfigMetadata(callParams.accountId, callParams.company, callParams.lastCollectedBefore);
1395
-
1468
+ const client = await getOpsCompassClient();
1469
+ const response = await client.licenseManager.checkMssqlConfigMetadata(
1470
+ callParams.accountId,
1471
+ global.company,
1472
+ callParams.lastCollectedBefore
1473
+ );
1396
1474
  console.log(JSON.stringify(response, null, 2));
1397
1475
  }
1398
1476
 
1399
1477
  async function checkOracleConfigMetadata(args) {
1400
-
1401
1478
  for (let i = 0; i < args.length - 1; i++) {
1402
1479
  switch (args[i].toLowerCase()) {
1403
- case "--account-id":
1480
+ case "--account-id":
1404
1481
  case "--accountid":
1405
1482
  callParams.accountId = args[++i];
1406
1483
  break;
1407
- case "--company":
1408
- callParams.company = args[++i];
1409
- break;
1410
1484
  case "--last-collected-before":
1411
1485
  case "--lastcollectedbefore":
1412
1486
  callParams.lastCollectedBefore = args[++i];
@@ -1414,13 +1488,15 @@ async function checkOracleConfigMetadata(args) {
1414
1488
  }
1415
1489
  }
1416
1490
 
1417
- const client = await getOpsCompassClient();
1418
- const response = await client.licenseManager.checkOracleConfigMetadata(callParams.accountId, callParams.company, callParams.lastCollectedBefore);
1419
-
1491
+ const client = await getOpsCompassClient();
1492
+ const response = await client.licenseManager.checkOracleConfigMetadata(
1493
+ callParams.accountId,
1494
+ global.company,
1495
+ callParams.lastCollectedBefore
1496
+ );
1420
1497
  console.log(JSON.stringify(response, null, 2));
1421
1498
  }
1422
1499
 
1423
-
1424
1500
  async function printHelp() {
1425
1501
  console.log("Actions available for license-manager:");
1426
1502
  console.log();
@@ -1507,15 +1583,35 @@ async function printHelp() {
1507
1583
  "Lists all of the monitoring configurations associated with the given company."
1508
1584
  );
1509
1585
  console.log("Parameters:");
1510
- console.log("--company [company_slug]");
1586
+ console.log(`--company [company_slug] (default: ${global.company})\n`);
1511
1587
  console.log();
1588
+ console.log(
1589
+ "mask-monitoring-configurations,",
1590
+ "Tools for managing sensitive data associated with the given company."
1591
+ );
1592
+ console.log("Parameters:");
1593
+ console.log(`--company [company_slug] (default: ${global.company})\n`);
1594
+ maskValues.printHelp();
1512
1595
  console.log(
1513
1596
  "get-monitoring-configuration",
1514
1597
  "Get a single monitoring configuration associated with the given company."
1515
1598
  );
1516
1599
  console.log("Parameters:");
1517
1600
  console.log("--id [monitoring_configuration_id]");
1518
- console.log("--asFile (optional) [true | false]");
1601
+ console.log(
1602
+ "--asFile (optional) {true|false} - fetch configuration as a file"
1603
+ );
1604
+ console.log(
1605
+ "--saveFile (optional) {true|false} [save-path] - save configuration (implies asFile)"
1606
+ );
1607
+ console.log();
1608
+ console.log(
1609
+ "read-monitoring-configuration",
1610
+ "Reads a local monitoring configuration associated with the given company."
1611
+ );
1612
+ console.log("Parameters:");
1613
+ console.log("--id [monitoring_configuration_id]");
1614
+ console.log("--list-details - return the file metadata");
1519
1615
  console.log();
1520
1616
  console.log(
1521
1617
  "get-network-discovery-configuration",
@@ -1529,10 +1625,14 @@ async function printHelp() {
1529
1625
  "Create a single monitoring configuration associated with the given company."
1530
1626
  );
1531
1627
  console.log("Parameters:");
1532
- console.log("--company [company_slug]");
1628
+ console.log(`--company [company_slug] (default: ${global.company})\n`);
1533
1629
  console.log("--configurationName [configuration name]");
1534
- console.log("--autoUpdateScripts (optional) [true | false] automatically update all scripts when the scripts are run.");
1535
- console.log("--autoUpdateConfigurations (optional) [true | false] automatically update all configurations when scripts are run.");
1630
+ console.log(
1631
+ "--autoUpdateScripts (optional) [true | false] automatically update all scripts when the scripts are run."
1632
+ );
1633
+ console.log(
1634
+ "--autoUpdateConfigurations (optional) [true | false] automatically update all configurations when scripts are run."
1635
+ );
1536
1636
  console.log();
1537
1637
  console.log(
1538
1638
  "create-network-discovery-configuration",
@@ -1639,7 +1739,7 @@ async function printHelp() {
1639
1739
  );
1640
1740
  console.log("Parameters:");
1641
1741
  console.log("--monitoring-configuration-id [monitoring_configuration_id]");
1642
- console.log("--configurationName [unique name]");
1742
+ console.log("--name or --configuration-name [unique name]");
1643
1743
  console.log(
1644
1744
  `--action (optional) pass multiple times to define which actions this connection can take e.g. --action "skip" --action "dbcompliance"`
1645
1745
  );
@@ -1661,7 +1761,7 @@ async function printHelp() {
1661
1761
  );
1662
1762
  console.log("Parameters:");
1663
1763
  console.log("--monitoring-configuration-id [monitoring_configuration_id]");
1664
- console.log("--name [unique name]");
1764
+ console.log("--configuration-name [unique name]");
1665
1765
  console.log(
1666
1766
  `--action (optional) pass multiple times to define which actions this connection can take e.g. --action "skip" --action "dbcompliance"`
1667
1767
  );
@@ -1857,14 +1957,14 @@ async function printHelp() {
1857
1957
  "Gets the components that can be used to build MSSql entitlement objects."
1858
1958
  );
1859
1959
  console.log("Parameters:");
1860
- console.log("--company [company_slug]");
1960
+ console.log(`--company [company_slug] (default: ${global.company})\n`);
1861
1961
  console.log();
1862
1962
  console.log(
1863
1963
  "create-mssql-entitlement",
1864
1964
  "Creates a Mssql Entitlement record."
1865
1965
  );
1866
1966
  console.log("Parameters:");
1867
- console.log("--company [company_slug]");
1967
+ console.log(`--company [company_slug] (default: ${global.company})\n`);
1868
1968
  console.log("--purchase-date [Date] the date of purchase.");
1869
1969
  console.log(
1870
1970
  "Format: UTC, example: '2022-08-23T17:00:00Z' to set August 8th, 2022 at 17:00 UTC."
@@ -1898,7 +1998,7 @@ async function printHelp() {
1898
1998
  "Creates a Mssql Entitlement record."
1899
1999
  );
1900
2000
  console.log("Parameters:");
1901
- console.log("--company [company_slug]");
2001
+ console.log(`--company [company_slug] (default: ${global.company})\n`);
1902
2002
  console.log("--id [number] the mssql entitlement record id");
1903
2003
  console.log("--purchase-date [Date] the date of purchase.");
1904
2004
  console.log(
@@ -1933,14 +2033,14 @@ async function printHelp() {
1933
2033
  "Deletes Mssql Entitlement records."
1934
2034
  );
1935
2035
  console.log("Parameters:");
1936
- console.log("--company [string] The slug of the company.");
2036
+ console.log(`--company [company_slug] (default: ${global.company})\n`);
1937
2037
  console.log(
1938
2038
  "--id [string] Use parameter multiple times to delete multiple records."
1939
2039
  );
1940
2040
  console.log();
1941
2041
  console.log("list-mssql-assessments", "Lists MSSQL Assessments");
1942
2042
  console.log("Parameters:");
1943
- console.log("--company [string] The slug of the company.");
2043
+ console.log(`--company [company_slug] (default: ${global.company})\n`);
1944
2044
  console.log();
1945
2045
  console.log("get-mssql-assessment", "Get Full MSSQL Assessment");
1946
2046
  console.log("Parameters:");
@@ -1954,14 +2054,14 @@ async function printHelp() {
1954
2054
  console.log("--assessmentId [number] The id of the assessment to retrieve.");
1955
2055
  console.log();
1956
2056
  console.log(
1957
- "get-mssql-assessment-license-usage-maps",
2057
+ "(DEPRECATED) get-mssql-assessment-license-usage-maps",
1958
2058
  "Gets LicenseUsageMaps for an MSSQL Assessment"
1959
2059
  );
1960
2060
  console.log("Parameters:");
1961
2061
  console.log("--assessmentId [number] The id of the assessment to retrieve.");
1962
2062
  console.log();
1963
2063
  console.log(
1964
- "get-mssql-assessment-resources",
2064
+ "(DEPRECATED) get-mssql-assessment-resources",
1965
2065
  "Gets Resources for an MSSQL Assessment"
1966
2066
  );
1967
2067
  console.log("Parameters:");
@@ -1973,8 +2073,10 @@ async function printHelp() {
1973
2073
  );
1974
2074
  console.log("Parameters:");
1975
2075
  console.log("--accountId [string] The account id for the company.");
1976
- console.log("--company [string] The company slug.");
1977
- console.log("--lastCollectedBefore [string] (optional) Only returns records that have not been collected since the given date. Format: UTC, example: '2022-08-23T17:00:00Z'");
2076
+ console.log(`--company [company_slug] (default: ${global.company})\n`);
2077
+ console.log(
2078
+ "--lastCollectedBefore [string] (optional) Only returns records that have not been collected since the given date. Format: UTC, example: '2022-08-23T17:00:00Z'"
2079
+ );
1978
2080
  console.log();
1979
2081
  console.log(
1980
2082
  "check-oracle-config-metadata",
@@ -1982,12 +2084,15 @@ async function printHelp() {
1982
2084
  );
1983
2085
  console.log("Parameters:");
1984
2086
  console.log("--accountId [string] The account id for the company.");
1985
- console.log("--company [string] The company slug.");
1986
- console.log("--lastCollectedBefore [string] (optional) Only returns records that have not been collected since the given date. Format: UTC, example: '2022-08-23T17:00:00Z'");
2087
+ console.log(`--company [company_slug] (default: ${global.company})\n`);
2088
+ console.log(
2089
+ "--lastCollectedBefore [string] (optional) Only returns records that have not been collected since the given date. Format: UTC, example: '2022-08-23T17:00:00Z'"
2090
+ );
1987
2091
  console.log();
1988
2092
  }
1989
2093
 
1990
2094
  const licenseManagerModule = (action, ...args) => {
2095
+ utils.processStandardArgs(args);
1991
2096
  switch (action?.toLowerCase() ?? "") {
1992
2097
  case "create-oracle-shared-credential":
1993
2098
  return createOracleSharedCredential(args);
@@ -2023,8 +2128,12 @@ const licenseManagerModule = (action, ...args) => {
2023
2128
  return getSecretForConfiguration(args);
2024
2129
  case "list-monitoring-configurations":
2025
2130
  return listMonitoringConfigurations(args);
2131
+ case "mask-monitoring-configurations":
2132
+ return maskMonitoringConfigurations(args);
2026
2133
  case "get-monitoring-configuration":
2027
2134
  return getMonitoringConfiguration(args);
2135
+ case "read-monitoring-configuration":
2136
+ return readMonitoringConfiguration(args);
2028
2137
  case "create-monitoring-configuration":
2029
2138
  return createMonitoringConfiguration(args);
2030
2139
  case "list-vcenter-configurations":