@opscompass/opscompass-cli 1.0.15 → 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/lib/homeInteraction.js +46 -25
- package/modules/data-gathering-scripts.js +157 -50
- package/modules/license-manager.js +119 -0
- package/package.json +2 -2
package/lib/homeInteraction.js
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
const fs = require("fs-extra");
|
|
2
2
|
const path = require("path");
|
|
3
|
-
const {
|
|
3
|
+
const {
|
|
4
|
+
opscompassHome,
|
|
5
|
+
ScriptType,
|
|
6
|
+
OpsCompassClient,
|
|
7
|
+
} = require("../environment/current.js");
|
|
4
8
|
const {
|
|
5
9
|
findOrCreateFolder,
|
|
6
10
|
deleteDirectory,
|
|
@@ -11,7 +15,7 @@ const {
|
|
|
11
15
|
writeFile,
|
|
12
16
|
canReadFile,
|
|
13
17
|
FilePermissions,
|
|
14
|
-
getAllFilesInFolder
|
|
18
|
+
getAllFilesInFolder,
|
|
15
19
|
} = require("./cliHelpers.js");
|
|
16
20
|
|
|
17
21
|
const SRC_FOLDER_NAME = "src";
|
|
@@ -36,7 +40,8 @@ async function writeFileToHome(fileName, data, mode) {
|
|
|
36
40
|
path.join(opscompassHome, fileName),
|
|
37
41
|
JSON.stringify(data),
|
|
38
42
|
{ mode: mode },
|
|
39
|
-
() => resolve()
|
|
43
|
+
() => resolve()
|
|
44
|
+
);
|
|
40
45
|
} catch (ex) {
|
|
41
46
|
reject(ex);
|
|
42
47
|
}
|
|
@@ -49,7 +54,7 @@ async function writeFileToHome(fileName, data, mode) {
|
|
|
49
54
|
*/
|
|
50
55
|
function findOrCreateScriptTypeFolder(scriptType) {
|
|
51
56
|
findOrCreateScriptsFolder();
|
|
52
|
-
const folderPath = scriptTypeFolderPath(scriptType)
|
|
57
|
+
const folderPath = scriptTypeFolderPath(scriptType);
|
|
53
58
|
findOrCreateFolder(folderPath);
|
|
54
59
|
return folderPath;
|
|
55
60
|
}
|
|
@@ -89,10 +94,7 @@ async function getScriptMetadata(scriptType) {
|
|
|
89
94
|
return;
|
|
90
95
|
}
|
|
91
96
|
|
|
92
|
-
const fileContents = await fs.readFile(
|
|
93
|
-
metadataPath,
|
|
94
|
-
{ encoding: "utf-8" }
|
|
95
|
-
);
|
|
97
|
+
const fileContents = await fs.readFile(metadataPath, { encoding: "utf-8" });
|
|
96
98
|
return JSON.parse(fileContents);
|
|
97
99
|
} catch (err) {
|
|
98
100
|
throw err;
|
|
@@ -118,38 +120,59 @@ function scriptTypeFolderPath(scriptType) {
|
|
|
118
120
|
}
|
|
119
121
|
|
|
120
122
|
/**
|
|
121
|
-
*
|
|
122
|
-
* @param {string} scriptType script type to use when downloading scripts
|
|
123
|
+
*
|
|
124
|
+
* @param {string} scriptType script type to use when downloading scripts
|
|
123
125
|
* @param {string} scriptVersion script version to use when downloading scripts. If undefined, downloads latest.
|
|
124
126
|
* @param {string} companySlug company slug to use when downloading scripts
|
|
125
127
|
* @param {OpsCompassClient} client client to use to call OpsCompass api
|
|
126
128
|
*/
|
|
127
|
-
async function downloadScriptsToHome(
|
|
129
|
+
async function downloadScriptsToHome(
|
|
130
|
+
scriptType,
|
|
131
|
+
scriptVersion,
|
|
132
|
+
companySlug,
|
|
133
|
+
client
|
|
134
|
+
) {
|
|
128
135
|
// Ensure base scripts are downloaded/updated
|
|
129
136
|
if (scriptType !== ScriptType.baseScripts) {
|
|
130
|
-
await downloadScriptsToHome(
|
|
137
|
+
await downloadScriptsToHome(
|
|
138
|
+
ScriptType.baseScripts,
|
|
139
|
+
undefined,
|
|
140
|
+
companySlug,
|
|
141
|
+
client
|
|
142
|
+
);
|
|
131
143
|
}
|
|
132
144
|
|
|
133
145
|
// Download specific script
|
|
134
|
-
const scriptDownloadInfo = await client.dataGatheringScripts.getScriptsUrl(
|
|
146
|
+
const scriptDownloadInfo = await client.dataGatheringScripts.getScriptsUrl(
|
|
147
|
+
companySlug,
|
|
148
|
+
scriptType,
|
|
149
|
+
scriptVersion
|
|
150
|
+
);
|
|
135
151
|
const scriptTypeFolderPath = findOrCreateScriptTypeFolder(scriptType);
|
|
136
152
|
const fileName = scriptDownloadInfo.fileName;
|
|
137
153
|
scriptVersion = fileName.replace(".zip", "");
|
|
138
154
|
|
|
139
155
|
removeCurrentlyInstalledScript(scriptType);
|
|
140
|
-
await downloadFile(
|
|
156
|
+
await downloadFile(
|
|
157
|
+
scriptDownloadInfo.downloadUrl,
|
|
158
|
+
scriptTypeFolderPath,
|
|
159
|
+
fileName
|
|
160
|
+
);
|
|
141
161
|
await unzipFile(scriptTypeFolderPath, fileName);
|
|
142
|
-
|
|
162
|
+
|
|
143
163
|
// Move contents from script version folder to src
|
|
144
164
|
const destinationPath = path.join(scriptTypeFolderPath, SRC_FOLDER_NAME);
|
|
145
|
-
await moveFolder(
|
|
165
|
+
await moveFolder(
|
|
166
|
+
path.join(scriptTypeFolderPath, scriptVersion),
|
|
167
|
+
destinationPath
|
|
168
|
+
);
|
|
146
169
|
|
|
147
170
|
// Set all files to mode 600, if they are .sh set to 700.
|
|
148
171
|
const allFilePaths = getAllFilesInFolder(destinationPath);
|
|
149
|
-
allFilePaths.forEach(function(filePath) {
|
|
172
|
+
allFilePaths.forEach(function (filePath) {
|
|
150
173
|
var fileExtension = path.extname(filePath);
|
|
151
174
|
|
|
152
|
-
if (fileExtension ===
|
|
175
|
+
if (fileExtension === ".sh") {
|
|
153
176
|
fs.chmodSync(filePath, 0o700);
|
|
154
177
|
} else {
|
|
155
178
|
fs.chmodSync(filePath, 0o600);
|
|
@@ -183,7 +206,7 @@ function previousScriptsDownloaded(scriptType) {
|
|
|
183
206
|
*/
|
|
184
207
|
async function setScriptMetadata(scriptFolderPath, scriptVersion) {
|
|
185
208
|
const scriptMetadata = {
|
|
186
|
-
version: scriptVersion
|
|
209
|
+
version: scriptVersion,
|
|
187
210
|
};
|
|
188
211
|
|
|
189
212
|
const metadataFilePath = path.join(scriptFolderPath, METADATA_FILE_NAME);
|
|
@@ -193,10 +216,7 @@ async function setScriptMetadata(scriptFolderPath, scriptVersion) {
|
|
|
193
216
|
deleteFile(metadataFilePath);
|
|
194
217
|
}
|
|
195
218
|
|
|
196
|
-
await writeFile(
|
|
197
|
-
metadataFilePath,
|
|
198
|
-
scriptMetadata
|
|
199
|
-
);
|
|
219
|
+
await writeFile(metadataFilePath, scriptMetadata);
|
|
200
220
|
}
|
|
201
221
|
|
|
202
222
|
module.exports = {
|
|
@@ -204,8 +224,9 @@ module.exports = {
|
|
|
204
224
|
BASE_SCRIPTS_RUN_ALL_RELATIVE_PATH,
|
|
205
225
|
writeFileToHome,
|
|
206
226
|
findOrCreateScriptTypeFolder,
|
|
227
|
+
findOrCreateScriptsFolder,
|
|
207
228
|
getInstalledScriptVersion,
|
|
208
229
|
removeCurrentlyInstalledScript,
|
|
209
230
|
downloadScriptsToHome,
|
|
210
|
-
previousScriptsDownloaded
|
|
211
|
-
};
|
|
231
|
+
previousScriptsDownloaded,
|
|
232
|
+
};
|
|
@@ -1,28 +1,76 @@
|
|
|
1
1
|
const { getOpsCompassClient } = require("../opscompass.js");
|
|
2
2
|
const { ScriptType, cliCommand } = require("../environment/current.js");
|
|
3
|
-
const {
|
|
3
|
+
const {
|
|
4
|
+
downloadScriptsToHome,
|
|
5
|
+
findOrCreateScriptTypeFolder,
|
|
6
|
+
findOrCreateScriptsFolder,
|
|
7
|
+
SRC_FOLDER_NAME,
|
|
8
|
+
BASE_SCRIPTS_RUN_ALL_RELATIVE_PATH,
|
|
9
|
+
getInstalledScriptVersion,
|
|
10
|
+
previousScriptsDownloaded,
|
|
11
|
+
} = require("../lib/homeInteraction.js");
|
|
4
12
|
const { canReadFile } = require("../lib/cliHelpers.js");
|
|
5
|
-
const { readDefaults, writeDefaults, checkDefaults} = require
|
|
13
|
+
const { readDefaults, writeDefaults, checkDefaults } = require("./defaults");
|
|
6
14
|
const { opscompassHome } = require("../environment/current.js");
|
|
7
15
|
|
|
8
16
|
const semver = require("semver");
|
|
9
17
|
const path = require("path");
|
|
10
18
|
const fs = require("fs-extra");
|
|
11
|
-
const util = require(
|
|
12
|
-
const exec = util.promisify(require(
|
|
19
|
+
const util = require("util");
|
|
20
|
+
const exec = util.promisify(require("child_process").exec);
|
|
13
21
|
|
|
14
22
|
/**
|
|
15
|
-
*
|
|
23
|
+
* Lists script types that are locally installed
|
|
16
24
|
*/
|
|
25
|
+
async function listLocalScripts(args) {
|
|
26
|
+
const scriptTypes = Object.values(ScriptType);
|
|
27
|
+
let scriptsLocal;
|
|
28
|
+
|
|
29
|
+
try {
|
|
30
|
+
const baseScriptFolderPath = findOrCreateScriptsFolder();
|
|
31
|
+
scriptsLocal = { path: baseScriptFolderPath, versions: [] };
|
|
32
|
+
const items = fs.readdirSync(baseScriptFolderPath, { withFileTypes: true });
|
|
33
|
+
|
|
34
|
+
for (const item of items) {
|
|
35
|
+
if (scriptTypes.includes(item.name) && item.isDirectory()) {
|
|
36
|
+
let metaFile = path.join(
|
|
37
|
+
baseScriptFolderPath,
|
|
38
|
+
item.name,
|
|
39
|
+
"metadata.json"
|
|
40
|
+
);
|
|
41
|
+
if (fs.existsSync(metaFile)) {
|
|
42
|
+
const data = fs.readFileSync(metaFile);
|
|
43
|
+
const metaVersion = JSON.parse(data.toString());
|
|
44
|
+
|
|
45
|
+
scriptsLocal.versions.push({
|
|
46
|
+
scriptType: item.name,
|
|
47
|
+
scriptVersion: metaVersion.version,
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
17
52
|
|
|
53
|
+
if (items.length > 0) {
|
|
54
|
+
console.log(scriptsLocal);
|
|
55
|
+
} else {
|
|
56
|
+
throw "Cannot list scripts. Make sure the scripts are downloaded.\nIf the issue persists, contact your OpsCompass rep.";
|
|
57
|
+
}
|
|
58
|
+
} catch (err) {
|
|
59
|
+
console.log(err);
|
|
60
|
+
}
|
|
61
|
+
return scriptsLocal;
|
|
62
|
+
}
|
|
18
63
|
|
|
64
|
+
/**
|
|
65
|
+
* Downloads data gathering scripts based on the given scriptType.
|
|
66
|
+
*/
|
|
19
67
|
async function downloadScripts(args) {
|
|
20
|
-
const defaultsPath =
|
|
68
|
+
const defaultsPath = path.join(opscompassHome, "defaults.json");
|
|
21
69
|
let scriptType = undefined;
|
|
22
|
-
let scriptVersion = undefined
|
|
70
|
+
let scriptVersion = undefined;
|
|
23
71
|
for (let i = 0; i < args.length - 1; i++) {
|
|
24
72
|
switch (args[i].toLowerCase()) {
|
|
25
|
-
case "--company":
|
|
73
|
+
case "--company":
|
|
26
74
|
companySlug = args[++i];
|
|
27
75
|
break;
|
|
28
76
|
case "--script-type":
|
|
@@ -33,7 +81,7 @@ async function downloadScripts(args) {
|
|
|
33
81
|
case "--scriptversion":
|
|
34
82
|
scriptVersion = args[++i];
|
|
35
83
|
break;
|
|
36
|
-
|
|
84
|
+
}
|
|
37
85
|
}
|
|
38
86
|
|
|
39
87
|
// If script type is not supported, we do not want to continue.
|
|
@@ -47,7 +95,7 @@ async function downloadScripts(args) {
|
|
|
47
95
|
const client = await getOpsCompassClient();
|
|
48
96
|
|
|
49
97
|
await downloadScriptsToHome(scriptType, scriptVersion, companySlug, client);
|
|
50
|
-
|
|
98
|
+
|
|
51
99
|
console.log("Download Successful!");
|
|
52
100
|
} catch (err) {
|
|
53
101
|
console.log("Download failed...");
|
|
@@ -62,14 +110,14 @@ async function checkScriptUpdates(args) {
|
|
|
62
110
|
let scriptType = undefined;
|
|
63
111
|
for (let i = 0; i < args.length - 1; i++) {
|
|
64
112
|
switch (args[i].toLowerCase()) {
|
|
65
|
-
case "--company":
|
|
113
|
+
case "--company":
|
|
66
114
|
companySlug = args[++i];
|
|
67
115
|
break;
|
|
68
116
|
case "--script-type":
|
|
69
117
|
case "--scripttype":
|
|
70
118
|
scriptType = args[++i];
|
|
71
119
|
break;
|
|
72
|
-
|
|
120
|
+
}
|
|
73
121
|
}
|
|
74
122
|
|
|
75
123
|
// If script type is not supported, we do not want to continue.
|
|
@@ -83,20 +131,35 @@ async function checkScriptUpdates(args) {
|
|
|
83
131
|
const currentScriptVersion = await getInstalledScriptVersion(scriptType);
|
|
84
132
|
|
|
85
133
|
if (!currentScriptVersion) {
|
|
86
|
-
console.log(
|
|
134
|
+
console.log(
|
|
135
|
+
`Local scripts for type ${scriptType} not found. Please make sure they are installed.`
|
|
136
|
+
);
|
|
87
137
|
console.log("If the issue persists, please contact your OpsCompass rep.");
|
|
88
138
|
return;
|
|
89
139
|
}
|
|
90
140
|
|
|
91
|
-
const latestScriptVersion =
|
|
141
|
+
const latestScriptVersion =
|
|
142
|
+
await client.dataGatheringScripts.checkScriptUpdates(
|
|
143
|
+
companySlug,
|
|
144
|
+
scriptType
|
|
145
|
+
);
|
|
92
146
|
|
|
93
|
-
//Semver returns true if the latest version is higher than the currentScriptVersion.
|
|
94
|
-
if (semver.gt(latestScriptVersion.scriptVersion, currentScriptVersion)) {
|
|
95
|
-
console.log(
|
|
96
|
-
|
|
147
|
+
//Semver returns true if the latest version is higher than the currentScriptVersion.
|
|
148
|
+
if (semver.gt(latestScriptVersion.scriptVersion, currentScriptVersion)) {
|
|
149
|
+
console.log(
|
|
150
|
+
yellowText,
|
|
151
|
+
`Warning! You are using version ${currentScriptVersion} of the the ${scriptType} scripts, but the latest version is ${latestScriptVersion.scriptVersion}. To update to the latest version, please run:`
|
|
152
|
+
);
|
|
153
|
+
console.log(
|
|
154
|
+
greenText,
|
|
155
|
+
` ${cliCommand} data-gathering-scripts download-scripts --company ${companySlug} --scriptType ${scriptType} `
|
|
156
|
+
);
|
|
97
157
|
console.log();
|
|
98
158
|
} else {
|
|
99
|
-
console.log(
|
|
159
|
+
console.log(
|
|
160
|
+
greenText,
|
|
161
|
+
`You are already using the latest version of ${scriptType} script, ${latestScriptVersion.scriptVersion}.`
|
|
162
|
+
);
|
|
100
163
|
console.log();
|
|
101
164
|
}
|
|
102
165
|
}
|
|
@@ -105,14 +168,14 @@ async function autoCheckScriptUpdates(args) {
|
|
|
105
168
|
let scriptType = undefined;
|
|
106
169
|
for (let i = 0; i < args.length - 1; i++) {
|
|
107
170
|
switch (args[i].toLowerCase()) {
|
|
108
|
-
case "--company":
|
|
171
|
+
case "--company":
|
|
109
172
|
companySlug = args[++i];
|
|
110
173
|
break;
|
|
111
174
|
case "--script-type":
|
|
112
175
|
case "--scripttype":
|
|
113
176
|
scriptType = args[++i];
|
|
114
177
|
break;
|
|
115
|
-
|
|
178
|
+
}
|
|
116
179
|
}
|
|
117
180
|
|
|
118
181
|
// Check to see if script type has been previously downloaded. If it has, continue with the version check.
|
|
@@ -122,20 +185,32 @@ async function autoCheckScriptUpdates(args) {
|
|
|
122
185
|
const client = await getOpsCompassClient();
|
|
123
186
|
const currentScriptVersion = await getInstalledScriptVersion(scriptType);
|
|
124
187
|
if (!currentScriptVersion) {
|
|
125
|
-
console.log(
|
|
188
|
+
console.log(
|
|
189
|
+
`Local scripts for type ${scriptType} not found. Please make sure they are installed.`
|
|
190
|
+
);
|
|
126
191
|
console.log("If the issue persists, please contact your OpsCompass rep.");
|
|
127
192
|
return;
|
|
128
193
|
}
|
|
129
194
|
|
|
130
|
-
const latestScriptVersion =
|
|
195
|
+
const latestScriptVersion =
|
|
196
|
+
await client.dataGatheringScripts.checkScriptUpdates(
|
|
197
|
+
companySlug,
|
|
198
|
+
scriptType
|
|
199
|
+
);
|
|
131
200
|
|
|
132
|
-
//Semver returns true if the latest version is higher than the currentScriptVersion.
|
|
133
|
-
if (semver.gt(latestScriptVersion.scriptVersion, currentScriptVersion)) {
|
|
134
|
-
console.log(
|
|
201
|
+
//Semver returns true if the latest version is higher than the currentScriptVersion.
|
|
202
|
+
if (semver.gt(latestScriptVersion.scriptVersion, currentScriptVersion)) {
|
|
203
|
+
console.log(
|
|
204
|
+
yellowText,
|
|
205
|
+
`Warning! You are using version ${currentScriptVersion} of the the ${scriptType} scripts, but the latest version is ${latestScriptVersion.scriptVersion}. To update to the latest version, please run:`
|
|
206
|
+
);
|
|
135
207
|
console.log();
|
|
136
|
-
console.log(
|
|
208
|
+
console.log(
|
|
209
|
+
greenText,
|
|
210
|
+
` ${cliCommand} data-gathering-scripts download-scripts --company ${companySlug} --scriptType ${scriptType} `
|
|
211
|
+
);
|
|
137
212
|
console.log();
|
|
138
|
-
}
|
|
213
|
+
}
|
|
139
214
|
}
|
|
140
215
|
|
|
141
216
|
/**
|
|
@@ -144,14 +219,19 @@ async function autoCheckScriptUpdates(args) {
|
|
|
144
219
|
*/
|
|
145
220
|
async function manuallyRunScripts() {
|
|
146
221
|
try {
|
|
147
|
-
const baseScriptFolderPath = findOrCreateScriptTypeFolder(
|
|
148
|
-
|
|
222
|
+
const baseScriptFolderPath = findOrCreateScriptTypeFolder(
|
|
223
|
+
ScriptType.baseScripts
|
|
224
|
+
);
|
|
225
|
+
const runAllFilePath = path.join(
|
|
226
|
+
baseScriptFolderPath,
|
|
227
|
+
SRC_FOLDER_NAME,
|
|
228
|
+
BASE_SCRIPTS_RUN_ALL_RELATIVE_PATH
|
|
229
|
+
);
|
|
149
230
|
|
|
150
231
|
if (canReadFile(runAllFilePath)) {
|
|
151
|
-
const runAllScript = await fs.readFile(
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
);
|
|
232
|
+
const runAllScript = await fs.readFile(runAllFilePath, {
|
|
233
|
+
encoding: "utf-8",
|
|
234
|
+
});
|
|
155
235
|
|
|
156
236
|
const { stdout, stderr } = await exec(runAllScript);
|
|
157
237
|
if (!!stderr) {
|
|
@@ -170,35 +250,61 @@ async function manuallyRunScripts() {
|
|
|
170
250
|
async function printHelp() {
|
|
171
251
|
console.log("Actions available for data-gathering-scripts:");
|
|
172
252
|
console.log();
|
|
173
|
-
console.log(
|
|
253
|
+
console.log(
|
|
254
|
+
"list-local",
|
|
255
|
+
"Lists all locally downloaded script types and versions"
|
|
256
|
+
);
|
|
257
|
+
console.log();
|
|
258
|
+
console.log(
|
|
259
|
+
"download-scripts",
|
|
260
|
+
"Downloads scripts for the passed script type."
|
|
261
|
+
);
|
|
174
262
|
console.log("Parameters:");
|
|
175
263
|
console.log("--company [company_slug]");
|
|
176
|
-
console.log(
|
|
177
|
-
|
|
264
|
+
console.log(
|
|
265
|
+
"--script-type ['discovery-tools', 'oracle-compliance', 'oracle-features', 'vsphere', 'msql-license', 'msql-compliance']"
|
|
266
|
+
);
|
|
267
|
+
console.log(
|
|
268
|
+
"--script-version (optional) [version] if not provided, the latest script will be downloaded"
|
|
269
|
+
);
|
|
178
270
|
console.log();
|
|
179
|
-
console.log(
|
|
271
|
+
console.log(
|
|
272
|
+
"check-script-updates",
|
|
273
|
+
"Checks locally installed script version against the latest published version for the passed script type."
|
|
274
|
+
);
|
|
180
275
|
console.log("Parameters:");
|
|
181
276
|
console.log("--company [company_slug]");
|
|
182
|
-
console.log(
|
|
277
|
+
console.log(
|
|
278
|
+
"--script-type ['oracle-compliance', 'oracle-features', 'vsphere', 'msql-license', 'msql-compliance']"
|
|
279
|
+
);
|
|
183
280
|
console.log();
|
|
184
|
-
console.log(
|
|
281
|
+
console.log(
|
|
282
|
+
"manually-run-scripts",
|
|
283
|
+
"Do not run this unless you know what you are doing. This manually runs all the scripts."
|
|
284
|
+
);
|
|
185
285
|
console.log();
|
|
186
286
|
}
|
|
187
287
|
|
|
188
288
|
const dataGatheringScriptsModule = (action, ...args) => {
|
|
189
|
-
// If it is a module with no arguments or if user is manually checking the version, do not run the auto version check. If user is already trying to download the latest versionm they do not need to be told to do so.
|
|
190
|
-
if (
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
289
|
+
// If it is a module with no arguments or if user is manually checking the version, do not run the auto version check. If user is already trying to download the latest versionm they do not need to be told to do so.
|
|
290
|
+
if (
|
|
291
|
+
args.length > 0 &&
|
|
292
|
+
action !== "check-script-updates" &&
|
|
293
|
+
action !== "download-scripts" &&
|
|
294
|
+
!args.includes("--script-version")
|
|
295
|
+
) {
|
|
296
|
+
autoCheckScriptUpdates(args);
|
|
297
|
+
}
|
|
298
|
+
|
|
195
299
|
switch (action?.toLowerCase() ?? "") {
|
|
196
|
-
case "download-scripts":
|
|
300
|
+
case "download-scripts":
|
|
197
301
|
return downloadScripts(args);
|
|
198
|
-
case "check-script-updates":
|
|
302
|
+
case "check-script-updates":
|
|
199
303
|
return checkScriptUpdates(args);
|
|
304
|
+
case "list-local":
|
|
305
|
+
return listLocalScripts();
|
|
200
306
|
case "manually-run-scripts":
|
|
201
|
-
return manuallyRunScripts()
|
|
307
|
+
return manuallyRunScripts();
|
|
202
308
|
case "help":
|
|
203
309
|
case "":
|
|
204
310
|
return printHelp();
|
|
@@ -209,6 +315,7 @@ const dataGatheringScriptsModule = (action, ...args) => {
|
|
|
209
315
|
};
|
|
210
316
|
|
|
211
317
|
dataGatheringScriptsModule.requiresLogin = true;
|
|
212
|
-
dataGatheringScriptsModule.description =
|
|
318
|
+
dataGatheringScriptsModule.description =
|
|
319
|
+
"Provides access to OpsCompass data gathering scripts.";
|
|
213
320
|
|
|
214
321
|
module.exports = dataGatheringScriptsModule;
|
|
@@ -781,6 +781,94 @@ async function updateMssqlEntitlement(args) {
|
|
|
781
781
|
console.log(JSON.stringify(response, null, 2));
|
|
782
782
|
}
|
|
783
783
|
|
|
784
|
+
async function listMssqlAssessments(args){
|
|
785
|
+
let company = undefined;
|
|
786
|
+
for (let i = 0; i < args.length - 1; i++) {
|
|
787
|
+
switch (args[i].toLowerCase()) {
|
|
788
|
+
case "--company":
|
|
789
|
+
company = args[++i];
|
|
790
|
+
break;
|
|
791
|
+
}
|
|
792
|
+
}
|
|
793
|
+
|
|
794
|
+
const client = await getOpsCompassClient();
|
|
795
|
+
const response = await client.licenseManager.listMssqlAssessments(company);
|
|
796
|
+
|
|
797
|
+
console.log(JSON.stringify(response, null, 2));
|
|
798
|
+
}
|
|
799
|
+
|
|
800
|
+
async function getMssqlAssessment(args) {
|
|
801
|
+
let assessmentId = undefined;
|
|
802
|
+
for (let i = 0; i < args.length - 1; i++) {
|
|
803
|
+
switch (args[i].toLowerCase()) {
|
|
804
|
+
case "--assessmentId":
|
|
805
|
+
case "--id":
|
|
806
|
+
case "--assessmentid":
|
|
807
|
+
assessmentId = args[++i];
|
|
808
|
+
break;
|
|
809
|
+
}
|
|
810
|
+
}
|
|
811
|
+
|
|
812
|
+
const client = await getOpsCompassClient();
|
|
813
|
+
const response = await client.licenseManager.getMssqlAssessment(assessmentId);
|
|
814
|
+
|
|
815
|
+
console.log(JSON.stringify(response, null, 2));
|
|
816
|
+
}
|
|
817
|
+
|
|
818
|
+
async function getMssqlAssessmentEntitlements(args) {
|
|
819
|
+
let assessmentId = undefined;
|
|
820
|
+
for (let i = 0; i < args.length - 1; i++) {
|
|
821
|
+
switch (args[i].toLowerCase()) {
|
|
822
|
+
case "--assessmentId":
|
|
823
|
+
case "--id":
|
|
824
|
+
case "--assessmentid":
|
|
825
|
+
assessmentId = args[++i];
|
|
826
|
+
break;
|
|
827
|
+
}
|
|
828
|
+
}
|
|
829
|
+
|
|
830
|
+
const client = await getOpsCompassClient();
|
|
831
|
+
const response = await client.licenseManager.getMssqlAssessmentEntitlements(assessmentId);
|
|
832
|
+
|
|
833
|
+
console.log(JSON.stringify(response, null, 2));
|
|
834
|
+
}
|
|
835
|
+
|
|
836
|
+
async function getMssqlAssessmentLicenseUsageMaps(args) {
|
|
837
|
+
let assessmentId = undefined;
|
|
838
|
+
for (let i = 0; i < args.length - 1; i++) {
|
|
839
|
+
switch (args[i].toLowerCase()) {
|
|
840
|
+
case "--assessmentId":
|
|
841
|
+
case "--id":
|
|
842
|
+
case "--assessmentid":
|
|
843
|
+
assessmentId = args[++i];
|
|
844
|
+
break;
|
|
845
|
+
}
|
|
846
|
+
}
|
|
847
|
+
|
|
848
|
+
const client = await getOpsCompassClient();
|
|
849
|
+
const response = await client.licenseManager.getMssqlAssessmentLicenseUsageMaps(assessmentId);
|
|
850
|
+
|
|
851
|
+
console.log(JSON.stringify(response, null, 2));
|
|
852
|
+
}
|
|
853
|
+
|
|
854
|
+
async function getMssqlAssessmentResources(args) {
|
|
855
|
+
let assessmentId = undefined;
|
|
856
|
+
for (let i = 0; i < args.length - 1; i++) {
|
|
857
|
+
switch (args[i].toLowerCase()) {
|
|
858
|
+
case "--assessmentId":
|
|
859
|
+
case "--id":
|
|
860
|
+
case "--assessmentid":
|
|
861
|
+
assessmentId = args[++i];
|
|
862
|
+
break;
|
|
863
|
+
}
|
|
864
|
+
}
|
|
865
|
+
|
|
866
|
+
const client = await getOpsCompassClient();
|
|
867
|
+
const response = await client.licenseManager.getMssqlAssessmentResources(assessmentId);
|
|
868
|
+
|
|
869
|
+
console.log(JSON.stringify(response, null, 2));
|
|
870
|
+
}
|
|
871
|
+
|
|
784
872
|
async function printHelp() {
|
|
785
873
|
console.log("Actions available for license-manager:");
|
|
786
874
|
console.log();
|
|
@@ -986,10 +1074,41 @@ async function printHelp() {
|
|
|
986
1074
|
console.log("Parameters:");
|
|
987
1075
|
console.log("--company [string] The slug of the company.");
|
|
988
1076
|
console.log("--id [string] Use parameter multiple times to delete multiple records.");
|
|
1077
|
+
console.log();
|
|
1078
|
+
console.log("list-mssql-assessments", "Lists MSSQL Assessments")
|
|
1079
|
+
console.log("Parameters:");
|
|
1080
|
+
console.log("--company [string] The slug of the company.");
|
|
1081
|
+
console.log();
|
|
1082
|
+
console.log("get-mssql-assessment", "Get Full MSSQL Assessment")
|
|
1083
|
+
console.log("Parameters:");
|
|
1084
|
+
console.log("--assessmentId [number] The id of the assessment to retrieve.");
|
|
1085
|
+
console.log();
|
|
1086
|
+
console.log("get-mssql-assessment-entitlements", "Gets Entitlements for an MSSQL Assessment")
|
|
1087
|
+
console.log("Parameters:");
|
|
1088
|
+
console.log("--assessmentId [number] The id of the assessment to retrieve.");
|
|
1089
|
+
console.log();
|
|
1090
|
+
console.log("get-mssql-assessment-license-usage-maps", "Gets LicenseUsageMaps for an MSSQL Assessment")
|
|
1091
|
+
console.log("Parameters:");
|
|
1092
|
+
console.log("--assessmentId [number] The id of the assessment to retrieve.");
|
|
1093
|
+
console.log();
|
|
1094
|
+
console.log("get-mssql-assessment-resources", "Gets Resources for an MSSQL Assessment")
|
|
1095
|
+
console.log("Parameters:");
|
|
1096
|
+
console.log("--assessmentId [number] The id of the assessment to retrieve.");
|
|
1097
|
+
console.log();
|
|
989
1098
|
}
|
|
990
1099
|
|
|
991
1100
|
const licenseManagerModule = (action, ...args) => {
|
|
992
1101
|
switch (action?.toLowerCase() ?? "") {
|
|
1102
|
+
case 'list-mssql-assessments':
|
|
1103
|
+
return listMssqlAssessments(args);
|
|
1104
|
+
case 'get-mssql-assessment':
|
|
1105
|
+
return getMssqlAssessment(args);
|
|
1106
|
+
case 'get-mssql-assessment-entitlements':
|
|
1107
|
+
return getMssqlAssessmentEntitlements(args);
|
|
1108
|
+
case 'get-mssql-assessment-license-usage-maps':
|
|
1109
|
+
return getMssqlAssessmentLicenseUsageMaps(args);
|
|
1110
|
+
case 'get-mssql-assessment-resources':
|
|
1111
|
+
return getMssqlAssessmentResources(args);
|
|
993
1112
|
case "get-secret-for-configuration":
|
|
994
1113
|
return getSecretForConfiguration(args);
|
|
995
1114
|
case "list-monitoring-configurations":
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@opscompass/opscompass-cli",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.16",
|
|
4
4
|
"description": "Calls OpsCompass's APIs",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
"author": "opscompass",
|
|
16
16
|
"license": "SEE LICENSE IN license.txt",
|
|
17
17
|
"dependencies": {
|
|
18
|
-
"@opscompass/opscompass-api": "^1.0.
|
|
18
|
+
"@opscompass/opscompass-api": "^1.0.16",
|
|
19
19
|
"adm-zip": "^0.5.9",
|
|
20
20
|
"axios": "^0.21.1",
|
|
21
21
|
"fs-extra": "^10.1.0",
|