@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
package/index.js
CHANGED
|
@@ -1,10 +1,40 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
3
|
const modules = require("./modules.js");
|
|
4
|
-
const handleError = require(
|
|
4
|
+
const handleError = require("./error.js");
|
|
5
5
|
const { canReadStoredCredentials } = require("./credentials.js");
|
|
6
|
-
const { versionCheck } = require("./updates.js");
|
|
7
|
-
const { isLocal } = require("./environment/current.js");
|
|
6
|
+
const { versionCheck } = require("./updates.js");
|
|
7
|
+
const { isLocal, opscompassHome } = require("./environment/current.js");
|
|
8
|
+
const fs = require("fs");
|
|
9
|
+
const path = require("path");
|
|
10
|
+
|
|
11
|
+
let defaultParams = JSON.parse("{}");
|
|
12
|
+
|
|
13
|
+
function checkDefaults() {
|
|
14
|
+
const defaultsPath = path.join(opscompassHome, 'defaults.json');
|
|
15
|
+
let rawdata;
|
|
16
|
+
try {
|
|
17
|
+
rawdata = fs.readFileSync(defaultsPath);
|
|
18
|
+
defaultParams = JSON.parse(rawdata);
|
|
19
|
+
} catch (err) {
|
|
20
|
+
// We just want to catch the error, no logging necessary
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* When an individual string is passed to the API, default param will be provided if it exists.
|
|
24
|
+
* Default value is overwritten when explicitly included in CLI command.
|
|
25
|
+
*/
|
|
26
|
+
companySlug = defaultParams.company;
|
|
27
|
+
company = defaultParams.company;
|
|
28
|
+
account = defaultParams.account;
|
|
29
|
+
monitoringConfig = defaultParams.monitoringConfiguration;
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* When a callParams object is passed to the API rather than one of the above strings, default values will be used unless explicitly replaced.
|
|
33
|
+
* Other properties can still be added to the callParams object. Unneeded default parameters may be included, but are ignored by the API.
|
|
34
|
+
*/
|
|
35
|
+
callParams = defaultParams;
|
|
36
|
+
|
|
37
|
+
}
|
|
8
38
|
|
|
9
39
|
function requiresLogin() {
|
|
10
40
|
console.log("You aren't logged in. Please run `opscompass login` to log in.");
|
|
@@ -18,7 +48,9 @@ function help() {
|
|
|
18
48
|
console.log("OpsCompass Command-Line Interface");
|
|
19
49
|
console.log();
|
|
20
50
|
console.log("Command format:");
|
|
21
|
-
console.log(
|
|
51
|
+
console.log(
|
|
52
|
+
" opscompass module action --parameter1 value --parameter2 value"
|
|
53
|
+
);
|
|
22
54
|
console.log();
|
|
23
55
|
console.log("Available modules:");
|
|
24
56
|
console.log();
|
|
@@ -29,10 +61,13 @@ function help() {
|
|
|
29
61
|
}
|
|
30
62
|
}
|
|
31
63
|
|
|
32
|
-
(async function() {
|
|
64
|
+
(async function () {
|
|
33
65
|
if (!isLocal) {
|
|
34
66
|
versionCheck();
|
|
35
67
|
}
|
|
68
|
+
|
|
69
|
+
checkDefaults();
|
|
70
|
+
|
|
36
71
|
const [proc, command, commandModule, ...args] = process.argv;
|
|
37
72
|
const moduleName = commandModule?.toLowerCase() ?? "";
|
|
38
73
|
if (moduleName === "" || moduleName === "help") {
|
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
|
+
};
|
package/modules/accounts.js
CHANGED
package/modules/compliance.js
CHANGED
|
@@ -17,6 +17,14 @@ const { getCredentials } = require("../credentials.js");
|
|
|
17
17
|
console.log(JSON.stringify(response, null, 2));
|
|
18
18
|
}
|
|
19
19
|
|
|
20
|
+
async function transferNetworkDiscoveryMetadata(args) {
|
|
21
|
+
const callParams = genericMetadataTrasfer(args);
|
|
22
|
+
const client = await getOpsCompassClient();
|
|
23
|
+
const response = await client.compliance.transferNetworkDiscoveryMetadata(callParams.company, callParams.filePath);
|
|
24
|
+
|
|
25
|
+
console.log(JSON.stringify(response, null, 2));
|
|
26
|
+
}
|
|
27
|
+
|
|
20
28
|
async function transferSqlServerDatabaseMetadata(args) {
|
|
21
29
|
const callParams = genericMetadataTrasfer(args);
|
|
22
30
|
const client = await getOpsCompassClient();
|
|
@@ -26,7 +34,7 @@ const { getCredentials } = require("../credentials.js");
|
|
|
26
34
|
}
|
|
27
35
|
|
|
28
36
|
function genericMetadataTrasfer(args) {
|
|
29
|
-
|
|
37
|
+
|
|
30
38
|
for (let i = 0; i < args.length - 1; i++) {
|
|
31
39
|
switch (args[i].toLowerCase()) {
|
|
32
40
|
case "--type":
|
|
@@ -122,7 +130,6 @@ const { getCredentials } = require("../credentials.js");
|
|
|
122
130
|
}
|
|
123
131
|
|
|
124
132
|
async function updateComplianceException(args) {
|
|
125
|
-
const callParams = {};
|
|
126
133
|
for (let i = 0; i < args.length - 1; i++) {
|
|
127
134
|
switch (args[i].toLowerCase()) {
|
|
128
135
|
case "--id":
|
|
@@ -153,7 +160,6 @@ const { getCredentials } = require("../credentials.js");
|
|
|
153
160
|
let callParamsArray = [];
|
|
154
161
|
let jsonIndex = args.indexOf('--json-updates');
|
|
155
162
|
let idIndex = args.indexOf('--id');
|
|
156
|
-
let callParams = {};
|
|
157
163
|
|
|
158
164
|
/* Process bulk update with JSON */
|
|
159
165
|
if (jsonIndex !== -1) {
|
|
@@ -244,6 +250,11 @@ const { getCredentials } = require("../credentials.js");
|
|
|
244
250
|
console.log("--type [licensing | compliance]")
|
|
245
251
|
console.log("--filePath [path] Path of the file to transfer to OpsCompass for processing.");
|
|
246
252
|
console.log();
|
|
253
|
+
console.log("transfer-network-discovery-metadata", "Transfers OpsCompass Network Discovery metadata into OpsCompass for processing");
|
|
254
|
+
console.log("Parameters:");
|
|
255
|
+
console.log("--company [company_slug]");
|
|
256
|
+
console.log("--filePath [path] Path of the file to transfer to OpsCompass for processing.");
|
|
257
|
+
console.log();
|
|
247
258
|
console.log("list-compliance-exceptions", "Gets list of policy exceptions and mitigations");
|
|
248
259
|
console.log("Parameters:");
|
|
249
260
|
console.log("--company [company_slug]");
|
|
@@ -294,6 +305,8 @@ const { getCredentials } = require("../credentials.js");
|
|
|
294
305
|
|
|
295
306
|
const complianceModule = (action, ...args) => {
|
|
296
307
|
switch (action?.toLowerCase() ?? "") {
|
|
308
|
+
case "transfer-network-discovery-metadata":
|
|
309
|
+
return transferNetworkDiscoveryMetadata(args);
|
|
297
310
|
case "transfer-vmware-vsphere-metadata":
|
|
298
311
|
return transferVMwareVsphereMetadata(args);
|
|
299
312
|
case "transfer-oracle-database-metadata":
|
|
@@ -1,24 +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");
|
|
13
|
+
const { readDefaults, writeDefaults, checkDefaults } = require("./defaults");
|
|
14
|
+
const { opscompassHome } = require("../environment/current.js");
|
|
15
|
+
|
|
5
16
|
const semver = require("semver");
|
|
6
17
|
const path = require("path");
|
|
7
18
|
const fs = require("fs-extra");
|
|
8
|
-
const util = require(
|
|
9
|
-
const exec = util.promisify(require(
|
|
19
|
+
const util = require("util");
|
|
20
|
+
const exec = util.promisify(require("child_process").exec);
|
|
10
21
|
|
|
11
22
|
/**
|
|
12
|
-
*
|
|
23
|
+
* Lists script types that are locally installed
|
|
13
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
|
+
}
|
|
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
|
+
}
|
|
14
63
|
|
|
64
|
+
/**
|
|
65
|
+
* Downloads data gathering scripts based on the given scriptType.
|
|
66
|
+
*/
|
|
15
67
|
async function downloadScripts(args) {
|
|
16
|
-
|
|
68
|
+
const defaultsPath = path.join(opscompassHome, "defaults.json");
|
|
17
69
|
let scriptType = undefined;
|
|
18
|
-
let scriptVersion = undefined
|
|
70
|
+
let scriptVersion = undefined;
|
|
19
71
|
for (let i = 0; i < args.length - 1; i++) {
|
|
20
72
|
switch (args[i].toLowerCase()) {
|
|
21
|
-
case "--company":
|
|
73
|
+
case "--company":
|
|
22
74
|
companySlug = args[++i];
|
|
23
75
|
break;
|
|
24
76
|
case "--script-type":
|
|
@@ -29,7 +81,7 @@ async function downloadScripts(args) {
|
|
|
29
81
|
case "--scriptversion":
|
|
30
82
|
scriptVersion = args[++i];
|
|
31
83
|
break;
|
|
32
|
-
|
|
84
|
+
}
|
|
33
85
|
}
|
|
34
86
|
|
|
35
87
|
// If script type is not supported, we do not want to continue.
|
|
@@ -43,7 +95,7 @@ async function downloadScripts(args) {
|
|
|
43
95
|
const client = await getOpsCompassClient();
|
|
44
96
|
|
|
45
97
|
await downloadScriptsToHome(scriptType, scriptVersion, companySlug, client);
|
|
46
|
-
|
|
98
|
+
|
|
47
99
|
console.log("Download Successful!");
|
|
48
100
|
} catch (err) {
|
|
49
101
|
console.log("Download failed...");
|
|
@@ -55,18 +107,17 @@ async function downloadScripts(args) {
|
|
|
55
107
|
* Checks the installed scripts version against the latest scripts version for a given scriptType.
|
|
56
108
|
*/
|
|
57
109
|
async function checkScriptUpdates(args) {
|
|
58
|
-
let companySlug = undefined;
|
|
59
110
|
let scriptType = undefined;
|
|
60
111
|
for (let i = 0; i < args.length - 1; i++) {
|
|
61
112
|
switch (args[i].toLowerCase()) {
|
|
62
|
-
case "--company":
|
|
113
|
+
case "--company":
|
|
63
114
|
companySlug = args[++i];
|
|
64
115
|
break;
|
|
65
116
|
case "--script-type":
|
|
66
117
|
case "--scripttype":
|
|
67
118
|
scriptType = args[++i];
|
|
68
119
|
break;
|
|
69
|
-
|
|
120
|
+
}
|
|
70
121
|
}
|
|
71
122
|
|
|
72
123
|
// If script type is not supported, we do not want to continue.
|
|
@@ -80,37 +131,51 @@ async function checkScriptUpdates(args) {
|
|
|
80
131
|
const currentScriptVersion = await getInstalledScriptVersion(scriptType);
|
|
81
132
|
|
|
82
133
|
if (!currentScriptVersion) {
|
|
83
|
-
console.log(
|
|
134
|
+
console.log(
|
|
135
|
+
`Local scripts for type ${scriptType} not found. Please make sure they are installed.`
|
|
136
|
+
);
|
|
84
137
|
console.log("If the issue persists, please contact your OpsCompass rep.");
|
|
85
138
|
return;
|
|
86
139
|
}
|
|
87
140
|
|
|
88
|
-
const latestScriptVersion =
|
|
141
|
+
const latestScriptVersion =
|
|
142
|
+
await client.dataGatheringScripts.checkScriptUpdates(
|
|
143
|
+
companySlug,
|
|
144
|
+
scriptType
|
|
145
|
+
);
|
|
89
146
|
|
|
90
|
-
//Semver returns true if the latest version is higher than the currentScriptVersion.
|
|
91
|
-
if (semver.gt(latestScriptVersion.scriptVersion, currentScriptVersion)) {
|
|
92
|
-
console.log(
|
|
93
|
-
|
|
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
|
+
);
|
|
94
157
|
console.log();
|
|
95
158
|
} else {
|
|
96
|
-
console.log(
|
|
159
|
+
console.log(
|
|
160
|
+
greenText,
|
|
161
|
+
`You are already using the latest version of ${scriptType} script, ${latestScriptVersion.scriptVersion}.`
|
|
162
|
+
);
|
|
97
163
|
console.log();
|
|
98
164
|
}
|
|
99
165
|
}
|
|
100
166
|
|
|
101
167
|
async function autoCheckScriptUpdates(args) {
|
|
102
|
-
let companySlug = undefined;
|
|
103
168
|
let scriptType = undefined;
|
|
104
169
|
for (let i = 0; i < args.length - 1; i++) {
|
|
105
170
|
switch (args[i].toLowerCase()) {
|
|
106
|
-
case "--company":
|
|
171
|
+
case "--company":
|
|
107
172
|
companySlug = args[++i];
|
|
108
173
|
break;
|
|
109
174
|
case "--script-type":
|
|
110
175
|
case "--scripttype":
|
|
111
176
|
scriptType = args[++i];
|
|
112
177
|
break;
|
|
113
|
-
|
|
178
|
+
}
|
|
114
179
|
}
|
|
115
180
|
|
|
116
181
|
// Check to see if script type has been previously downloaded. If it has, continue with the version check.
|
|
@@ -120,20 +185,32 @@ async function autoCheckScriptUpdates(args) {
|
|
|
120
185
|
const client = await getOpsCompassClient();
|
|
121
186
|
const currentScriptVersion = await getInstalledScriptVersion(scriptType);
|
|
122
187
|
if (!currentScriptVersion) {
|
|
123
|
-
console.log(
|
|
188
|
+
console.log(
|
|
189
|
+
`Local scripts for type ${scriptType} not found. Please make sure they are installed.`
|
|
190
|
+
);
|
|
124
191
|
console.log("If the issue persists, please contact your OpsCompass rep.");
|
|
125
192
|
return;
|
|
126
193
|
}
|
|
127
194
|
|
|
128
|
-
const latestScriptVersion =
|
|
195
|
+
const latestScriptVersion =
|
|
196
|
+
await client.dataGatheringScripts.checkScriptUpdates(
|
|
197
|
+
companySlug,
|
|
198
|
+
scriptType
|
|
199
|
+
);
|
|
129
200
|
|
|
130
|
-
//Semver returns true if the latest version is higher than the currentScriptVersion.
|
|
131
|
-
if (semver.gt(latestScriptVersion.scriptVersion, currentScriptVersion)) {
|
|
132
|
-
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
|
+
);
|
|
133
207
|
console.log();
|
|
134
|
-
console.log(
|
|
208
|
+
console.log(
|
|
209
|
+
greenText,
|
|
210
|
+
` ${cliCommand} data-gathering-scripts download-scripts --company ${companySlug} --scriptType ${scriptType} `
|
|
211
|
+
);
|
|
135
212
|
console.log();
|
|
136
|
-
}
|
|
213
|
+
}
|
|
137
214
|
}
|
|
138
215
|
|
|
139
216
|
/**
|
|
@@ -142,14 +219,19 @@ async function autoCheckScriptUpdates(args) {
|
|
|
142
219
|
*/
|
|
143
220
|
async function manuallyRunScripts() {
|
|
144
221
|
try {
|
|
145
|
-
const baseScriptFolderPath = findOrCreateScriptTypeFolder(
|
|
146
|
-
|
|
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
|
+
);
|
|
147
230
|
|
|
148
231
|
if (canReadFile(runAllFilePath)) {
|
|
149
|
-
const runAllScript = await fs.readFile(
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
);
|
|
232
|
+
const runAllScript = await fs.readFile(runAllFilePath, {
|
|
233
|
+
encoding: "utf-8",
|
|
234
|
+
});
|
|
153
235
|
|
|
154
236
|
const { stdout, stderr } = await exec(runAllScript);
|
|
155
237
|
if (!!stderr) {
|
|
@@ -168,35 +250,61 @@ async function manuallyRunScripts() {
|
|
|
168
250
|
async function printHelp() {
|
|
169
251
|
console.log("Actions available for data-gathering-scripts:");
|
|
170
252
|
console.log();
|
|
171
|
-
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
|
+
);
|
|
172
262
|
console.log("Parameters:");
|
|
173
263
|
console.log("--company [company_slug]");
|
|
174
|
-
console.log(
|
|
175
|
-
|
|
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
|
+
);
|
|
176
270
|
console.log();
|
|
177
|
-
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
|
+
);
|
|
178
275
|
console.log("Parameters:");
|
|
179
276
|
console.log("--company [company_slug]");
|
|
180
|
-
console.log(
|
|
277
|
+
console.log(
|
|
278
|
+
"--script-type ['oracle-compliance', 'oracle-features', 'vsphere', 'msql-license', 'msql-compliance']"
|
|
279
|
+
);
|
|
181
280
|
console.log();
|
|
182
|
-
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
|
+
);
|
|
183
285
|
console.log();
|
|
184
286
|
}
|
|
185
287
|
|
|
186
288
|
const dataGatheringScriptsModule = (action, ...args) => {
|
|
187
|
-
// 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.
|
|
188
|
-
if (
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
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
|
+
|
|
193
299
|
switch (action?.toLowerCase() ?? "") {
|
|
194
|
-
case "download-scripts":
|
|
300
|
+
case "download-scripts":
|
|
195
301
|
return downloadScripts(args);
|
|
196
|
-
case "check-script-updates":
|
|
302
|
+
case "check-script-updates":
|
|
197
303
|
return checkScriptUpdates(args);
|
|
304
|
+
case "list-local":
|
|
305
|
+
return listLocalScripts();
|
|
198
306
|
case "manually-run-scripts":
|
|
199
|
-
return manuallyRunScripts()
|
|
307
|
+
return manuallyRunScripts();
|
|
200
308
|
case "help":
|
|
201
309
|
case "":
|
|
202
310
|
return printHelp();
|
|
@@ -207,6 +315,7 @@ const dataGatheringScriptsModule = (action, ...args) => {
|
|
|
207
315
|
};
|
|
208
316
|
|
|
209
317
|
dataGatheringScriptsModule.requiresLogin = true;
|
|
210
|
-
dataGatheringScriptsModule.description =
|
|
318
|
+
dataGatheringScriptsModule.description =
|
|
319
|
+
"Provides access to OpsCompass data gathering scripts.";
|
|
211
320
|
|
|
212
321
|
module.exports = dataGatheringScriptsModule;
|