@opscompass/opscompass-cli 1.0.14 → 1.0.16
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/index.js +40 -5
- package/lib/homeInteraction.js +46 -25
- package/modules/accounts.js +1 -1
- package/modules/compliance.js +16 -3
- package/modules/data-gathering-scripts.js +160 -51
- package/modules/defaults.js +91 -0
- package/modules/license-manager.js +436 -124
- package/modules/resources.js +67 -2
- package/modules.js +3 -1
- package/package.json +2 -2
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
const fs = require("fs");
|
|
2
|
+
const path = require("path");
|
|
3
|
+
const { opscompassHome } = require("../environment/current.js");
|
|
4
|
+
|
|
5
|
+
const defaultsPath = path.join(opscompassHome, 'defaults.json');
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
async function readDefaults() {
|
|
11
|
+
let rawdata;
|
|
12
|
+
let defaultParams = JSON.parse("{}");
|
|
13
|
+
try {
|
|
14
|
+
rawdata = fs.readFileSync(defaultsPath);
|
|
15
|
+
defaultParams = JSON.parse(rawdata);
|
|
16
|
+
} catch (err) {
|
|
17
|
+
if (err.code === "ENOENT") {
|
|
18
|
+
console.error("\nDefaults file not found: %s", defaultsPath);
|
|
19
|
+
} else {
|
|
20
|
+
//console.error(err);
|
|
21
|
+
console.error("\nError reading defaults: %s", defaultsPath);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
console.log(defaultParams, "\n");
|
|
25
|
+
return defaultParams;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
async function writeDefaults(args) {
|
|
29
|
+
let defaults = {
|
|
30
|
+
company: undefined,
|
|
31
|
+
account: undefined,
|
|
32
|
+
monitoringConfiguration: undefined,
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
for (let i = 0; i < args.length - 1; i++) {
|
|
36
|
+
if (args[i]?.toLowerCase() === "--company") {
|
|
37
|
+
defaults.company = args[++i];
|
|
38
|
+
} else if (args[i].toLowerCase() === "--account") {
|
|
39
|
+
defaults.account = args[++i];
|
|
40
|
+
} else if (args[i].toLowerCase() === "--monitoring-configuration-id") {
|
|
41
|
+
defaults.monitoringConfiguration = args[++i];
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const data = JSON.stringify(defaults);
|
|
46
|
+
|
|
47
|
+
fs.writeFileSync(defaultsPath, data);
|
|
48
|
+
console.log("Your default configuration is:");
|
|
49
|
+
readDefaults();
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function printHelp() {
|
|
53
|
+
console.log("Actions available for defaults:");
|
|
54
|
+
console.log();
|
|
55
|
+
console.log("list-defaults", "See current default settings.");
|
|
56
|
+
console.log("Parameters:");
|
|
57
|
+
console.log("None");
|
|
58
|
+
console.log();
|
|
59
|
+
console.log(
|
|
60
|
+
"set-defaults",
|
|
61
|
+
"Allows you to set default parameter such as company, account, or monitoring configuration."
|
|
62
|
+
);
|
|
63
|
+
console.log("Parameters:");
|
|
64
|
+
console.log(
|
|
65
|
+
"--company 'value' --account 'value' --monitoring-configuration-id 'value'"
|
|
66
|
+
);
|
|
67
|
+
console.log("e.g. opscompass defaults set-defaults --company 'opscompass' --account '231' --monitoring-configuration-id '34232'" )
|
|
68
|
+
console.log();
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
const defaultsModule = (action, ...args) => {
|
|
72
|
+
switch (action?.toLowerCase() ?? "") {
|
|
73
|
+
case "list-defaults":
|
|
74
|
+
return readDefaults();
|
|
75
|
+
case "set-defaults":
|
|
76
|
+
return writeDefaults(args);
|
|
77
|
+
case "help":
|
|
78
|
+
case "":
|
|
79
|
+
return printHelp();
|
|
80
|
+
default:
|
|
81
|
+
console.log("Unknown command:", action);
|
|
82
|
+
return printHelp();
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
defaultsModule.requiresLogin = false;
|
|
87
|
+
defaultsModule.description =
|
|
88
|
+
"View and set default parameters for OpsCompass CLI.";
|
|
89
|
+
|
|
90
|
+
module.exports = { readDefaults, writeDefaults, defaultsPath };
|
|
91
|
+
module.exports = defaultsModule;
|