@opscompass/opscompass-cli 1.0.10 → 1.0.11
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/credentials.js +1 -1
- package/lib/cliHelpers.js +24 -0
- package/lib/homeInteraction.js +32 -3
- package/modules/compliance.js +135 -3
- package/modules/data-gathering-scripts.js +51 -6
- package/modules/license-manager.js +40 -30
- package/package.json +2 -2
- package/updates.js +1 -1
package/credentials.js
CHANGED
|
@@ -24,7 +24,7 @@ async function storeCredentials(data) {
|
|
|
24
24
|
data.expires_at = new Date(Date.now() + (data.expires_in * 1000));
|
|
25
25
|
}
|
|
26
26
|
|
|
27
|
-
return writeFileToHome('tokens.json', data);
|
|
27
|
+
return writeFileToHome('tokens.json', data, 0o600);
|
|
28
28
|
}
|
|
29
29
|
|
|
30
30
|
async function getCredentials() {
|
package/lib/cliHelpers.js
CHANGED
|
@@ -138,6 +138,29 @@ async function unzipFile(unzipFileLocation, unzipFileName) {
|
|
|
138
138
|
}
|
|
139
139
|
}
|
|
140
140
|
|
|
141
|
+
/**
|
|
142
|
+
* We need to be able to get all file paths for a given directory. This returns all file paths in all sub folders as well.
|
|
143
|
+
* @param {string} dirPath the path to the directory to return all file paths for
|
|
144
|
+
* @returns {string[]} all file paths recursively for the passed in directory path
|
|
145
|
+
*/
|
|
146
|
+
function getAllFilesInFolder(dirPath) {
|
|
147
|
+
files = fs.readdirSync(dirPath);
|
|
148
|
+
|
|
149
|
+
var arrayOfFiles = arrayOfFiles || [];
|
|
150
|
+
|
|
151
|
+
files.forEach(function(file) {
|
|
152
|
+
const filePathToCheck = path.join(dirPath, file);
|
|
153
|
+
if (fs.lstatSync(filePathToCheck).isDirectory() ) {
|
|
154
|
+
const folderFiles = getAllFilesInFolder(filePathToCheck);
|
|
155
|
+
arrayOfFiles = arrayOfFiles.concat(folderFiles);
|
|
156
|
+
} else {
|
|
157
|
+
arrayOfFiles.push(filePathToCheck);
|
|
158
|
+
}
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
return arrayOfFiles
|
|
162
|
+
}
|
|
163
|
+
|
|
141
164
|
/**
|
|
142
165
|
* Moves a directory and contents from one location to another.
|
|
143
166
|
* @param {string} sourcePath the directory to move
|
|
@@ -201,5 +224,6 @@ module.exports = {
|
|
|
201
224
|
findOrCreateFolder,
|
|
202
225
|
canReadFile,
|
|
203
226
|
moveFolder,
|
|
227
|
+
getAllFilesInFolder,
|
|
204
228
|
FilePermissions
|
|
205
229
|
};
|
package/lib/homeInteraction.js
CHANGED
|
@@ -10,7 +10,8 @@ const {
|
|
|
10
10
|
moveFolder,
|
|
11
11
|
writeFile,
|
|
12
12
|
canReadFile,
|
|
13
|
-
FilePermissions
|
|
13
|
+
FilePermissions,
|
|
14
|
+
getAllFilesInFolder
|
|
14
15
|
} = require("./cliHelpers.js");
|
|
15
16
|
|
|
16
17
|
const SRC_FOLDER_NAME = "src";
|
|
@@ -140,7 +141,20 @@ async function downloadScriptsToHome(scriptType, scriptVersion, companySlug, cli
|
|
|
140
141
|
await unzipFile(scriptTypeFolderPath, fileName);
|
|
141
142
|
|
|
142
143
|
// Move contents from script version folder to src
|
|
143
|
-
|
|
144
|
+
const destinationPath = path.join(scriptTypeFolderPath, SRC_FOLDER_NAME);
|
|
145
|
+
await moveFolder(path.join(scriptTypeFolderPath, scriptVersion), destinationPath);
|
|
146
|
+
|
|
147
|
+
// Set all files to mode 600, if they are .sh set to 700.
|
|
148
|
+
const allFilePaths = getAllFilesInFolder(destinationPath);
|
|
149
|
+
allFilePaths.forEach(function(filePath) {
|
|
150
|
+
var fileExtension = path.extname(filePath);
|
|
151
|
+
|
|
152
|
+
if (fileExtension === '.sh') {
|
|
153
|
+
fs.chmodSync(filePath, 0o700);
|
|
154
|
+
} else {
|
|
155
|
+
fs.chmodSync(filePath, 0o600);
|
|
156
|
+
}
|
|
157
|
+
});
|
|
144
158
|
|
|
145
159
|
// Set the script's metadata
|
|
146
160
|
await setScriptMetadata(scriptTypeFolderPath, scriptVersion);
|
|
@@ -148,6 +162,20 @@ async function downloadScriptsToHome(scriptType, scriptVersion, companySlug, cli
|
|
|
148
162
|
deleteFile(path.join(scriptTypeFolderPath, fileName));
|
|
149
163
|
}
|
|
150
164
|
|
|
165
|
+
/**
|
|
166
|
+
* Returns boolean indicating if the script type has been downloaded previously, or if this is the first time.
|
|
167
|
+
* @param {string} scriptType the script type to check
|
|
168
|
+
* @return {boolean} indicates if script type has been previously downloaded
|
|
169
|
+
*/
|
|
170
|
+
function previousScriptsDownloaded(scriptType) {
|
|
171
|
+
const folderPath = scriptTypeFolderPath(scriptType);
|
|
172
|
+
try {
|
|
173
|
+
return fs.existsSync(folderPath);
|
|
174
|
+
} catch (err) {
|
|
175
|
+
return false;
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
|
|
151
179
|
/**
|
|
152
180
|
* Creates/updates a file that contains a specific script's metadata.
|
|
153
181
|
* @param {string} scriptFolderPath path to the script folder
|
|
@@ -178,5 +206,6 @@ module.exports = {
|
|
|
178
206
|
findOrCreateScriptTypeFolder,
|
|
179
207
|
getInstalledScriptVersion,
|
|
180
208
|
removeCurrentlyInstalledScript,
|
|
181
|
-
downloadScriptsToHome
|
|
209
|
+
downloadScriptsToHome,
|
|
210
|
+
previousScriptsDownloaded
|
|
182
211
|
};
|
package/modules/compliance.js
CHANGED
|
@@ -2,6 +2,22 @@ const { getOpsCompassClient } = require("../opscompass.js");
|
|
|
2
2
|
const { getCredentials } = require("../credentials.js");
|
|
3
3
|
|
|
4
4
|
async function transferOracleDatabaseMetadata(args) {
|
|
5
|
+
const callParams = genericMetadataTrasfer(args);
|
|
6
|
+
const client = await getOpsCompassClient();
|
|
7
|
+
const response = await client.compliance.transferOracleDatabaseMetadata(callParams.company, callParams.filePath);
|
|
8
|
+
|
|
9
|
+
console.log(JSON.stringify(response, null, 2));
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
async function transferSqlServerDatabaseMetadata(args) {
|
|
13
|
+
const callParams = genericMetadataTrasfer(args);
|
|
14
|
+
const client = await getOpsCompassClient();
|
|
15
|
+
const response = await client.compliance.transferSqlServerDatabaseMetadata(callParams.company, callParams.filePath);
|
|
16
|
+
|
|
17
|
+
console.log(JSON.stringify(response, null, 2));
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function genericMetadataTrasfer(args) {
|
|
5
21
|
const callParams = {};
|
|
6
22
|
for (let i = 0; i < args.length - 1; i++) {
|
|
7
23
|
switch (args[i].toLowerCase()) {
|
|
@@ -13,14 +29,94 @@ const { getCredentials } = require("../credentials.js");
|
|
|
13
29
|
break;
|
|
14
30
|
}
|
|
15
31
|
}
|
|
32
|
+
return callParams;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
async function listComplianceExceptions(args) {
|
|
36
|
+
let company = undefined;
|
|
37
|
+
for (let i = 0; i < args.length - 1; i++) {
|
|
38
|
+
switch (args[i].toLowerCase()) {
|
|
39
|
+
case "--company":
|
|
40
|
+
company = args[++i];
|
|
41
|
+
break;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const client = await getOpsCompassClient();
|
|
46
|
+
const complianceExceptions = await client.compliance.getComplianceExceptions(company);
|
|
47
|
+
|
|
48
|
+
console.log(JSON.stringify(complianceExceptions, null, 2));
|
|
49
|
+
}
|
|
16
50
|
|
|
51
|
+
async function updateComplianceException(args) {
|
|
52
|
+
const callParams = {};
|
|
53
|
+
for (let i = 0; i < args.length - 1; i++) {
|
|
54
|
+
switch (args[i].toLowerCase()) {
|
|
55
|
+
case "--id":
|
|
56
|
+
callParams.id = args[++i];
|
|
57
|
+
break;
|
|
58
|
+
case "--reason":
|
|
59
|
+
callParams.reason = args[++i];
|
|
60
|
+
break;
|
|
61
|
+
case "--expiresat":
|
|
62
|
+
case "--expires-at":
|
|
63
|
+
const expiresDate = args[++i];
|
|
64
|
+
if (expiresDate === 'null') {
|
|
65
|
+
callParams.expiresAt = null;
|
|
66
|
+
} else {
|
|
67
|
+
callParams.expiresAt = expiresDate;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
break;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
17
73
|
|
|
18
74
|
const client = await getOpsCompassClient();
|
|
19
|
-
const
|
|
20
|
-
|
|
21
|
-
console.log(JSON.stringify(response, null, 2));
|
|
75
|
+
const complianceException = await client.compliance.updateComplianceException(callParams.id, callParams);
|
|
76
|
+
console.log(JSON.stringify(complianceException, null, 2));
|
|
22
77
|
}
|
|
78
|
+
|
|
79
|
+
async function updateComplianceExceptions(args) {
|
|
80
|
+
let callParamsArray = [];
|
|
81
|
+
let jsonIndex = args.indexOf('--json-updates');
|
|
82
|
+
let idIndex = args.indexOf('--id');
|
|
83
|
+
let callParams = {};
|
|
23
84
|
|
|
85
|
+
/* Process bulk update with JSON */
|
|
86
|
+
if (jsonIndex !== -1) {
|
|
87
|
+
const jsonString = args[jsonIndex + 1];
|
|
88
|
+
callParamsArray = JSON.parse(jsonString);
|
|
89
|
+
} else if (idIndex !== -1) {
|
|
90
|
+
/* If no '--json-update' flag, process bulk update with parameter flags (e.g. --id, --name, etc.) */
|
|
91
|
+
for(let i = 0; i < args.length - 1; i++) {
|
|
92
|
+
const argument = args[i].toLowerCase();
|
|
93
|
+
if(argument === '--id') {
|
|
94
|
+
/* Reset callParams object when a second id is encountered */
|
|
95
|
+
callParams = {};
|
|
96
|
+
/* if theres an existing callParams object, toss it into the array and move on. */
|
|
97
|
+
callParamsArray.push(callParams)
|
|
98
|
+
/* Create the object's properties based on the index (e.g. if the index is --id, you'll find the value at the next index */
|
|
99
|
+
callParams.id = args[i + 1];
|
|
100
|
+
} else if(argument === '--reason') {
|
|
101
|
+
callParams.reason = args[i + 1];
|
|
102
|
+
} else if(argument === '--expiresat' || argument === '--expires-at') {
|
|
103
|
+
const expiresDate = args[i + 1];
|
|
104
|
+
if (expiresDate === 'null') {
|
|
105
|
+
callParams.expiresAt = null;
|
|
106
|
+
} else {
|
|
107
|
+
callParams.expiresAt = expiresDate;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
} else {
|
|
112
|
+
console.warn("Invalid input, please see help for examples.")
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/* Call the API and print to console */
|
|
116
|
+
const client = await getOpsCompassClient();
|
|
117
|
+
const vCenterConfigurations = await client.compliance.updateComplianceExceptions(callParamsArray);
|
|
118
|
+
console.log(JSON.stringify(vCenterConfigurations, null, 2));
|
|
119
|
+
}
|
|
24
120
|
|
|
25
121
|
async function printHelp() {
|
|
26
122
|
console.log("Actions available for compliance:");
|
|
@@ -30,6 +126,34 @@ const { getCredentials } = require("../credentials.js");
|
|
|
30
126
|
console.log("--company [company_slug]");
|
|
31
127
|
console.log("--filePath [path] Path of the file to transfer to OpsCompass for processing.");
|
|
32
128
|
console.log();
|
|
129
|
+
console.log("transfer-sql-server-database-metadata", "Transfers OpsCompass SQL Server Database metadata report into OpsCompass for processing");
|
|
130
|
+
console.log("Parameters:");
|
|
131
|
+
console.log("--company [company_slug]");
|
|
132
|
+
console.log("--filePath [path] Path of the file to transfer to OpsCompass for processing.");
|
|
133
|
+
console.log();
|
|
134
|
+
console.log("list-compliance-exceptions", "Gets list of policy exceptions and mitigations");
|
|
135
|
+
console.log("Parameters:");
|
|
136
|
+
console.log("--company [company_slug]");
|
|
137
|
+
console.log();
|
|
138
|
+
console.log("update-compliance-exception", "Updates single compliance exception record (i.e. mitigations and policy exceptions)");
|
|
139
|
+
console.log("Parameters:");
|
|
140
|
+
console.log("--id [record id]");
|
|
141
|
+
console.log("--reason [string] the reason for the compliance exception");
|
|
142
|
+
console.log("--expiresAt [string] the date at which to expire. If you want to remove a compliance exception from the list, set the expiresAt to todays date.");
|
|
143
|
+
console.log("Format: UTC, example: '2022-08-23T17:00:00Z' to expire August 8th, 2022 at 17:00 UTC. To remove this field, pass in null.");
|
|
144
|
+
console.log();
|
|
145
|
+
console.log("update-compliance-exceptions", "Updates multiple compliance exceptions (i.e. mitigations and policy exceptions)");
|
|
146
|
+
console.log("Parameters:");
|
|
147
|
+
console.log("--id [record id]");
|
|
148
|
+
console.log("--reason (optional) [string] the reason for the compliance exception");
|
|
149
|
+
console.log("--expiresAt (optional) [string] the date at which to expire. If you want to remove a compliance exception from the list, set the expiresAt to todays date.");
|
|
150
|
+
console.log("Format: UTC, example: '2022-08-23T17:00:00Z' to expire August 8th, 2022 at 17:00 UTC. To remove this field, pass in null.");
|
|
151
|
+
console.log("OR --json-updates [stringified json objects with your updates]");
|
|
152
|
+
console.log("For quick updates, you may use the above parameters");
|
|
153
|
+
console.log('e.g. opscompass compliance update-compliance-exceptions --id 18 --reason "Valid exception reason" --id 3 --expires-at "09/15/2022"');
|
|
154
|
+
console.log("For larger updates, JavaScript Object Notation (JSON) may be used with the --json-updates flag");
|
|
155
|
+
console.log(`e.g. opscompass compliance update-compliance-exceptions --json-updates '[{\"id\":\"18\",\"reason\":\"Valid exception reason\"},{\"id\":\"3\",\"expiresAt\":\"2022-08-23T17:00:00Z\"}]'`);
|
|
156
|
+
console.log();
|
|
33
157
|
}
|
|
34
158
|
|
|
35
159
|
|
|
@@ -37,6 +161,14 @@ const { getCredentials } = require("../credentials.js");
|
|
|
37
161
|
switch (action?.toLowerCase() ?? "") {
|
|
38
162
|
case "transfer-oracle-database-metadata":
|
|
39
163
|
return transferOracleDatabaseMetadata(args);
|
|
164
|
+
case "transfer-sql-server-database-metadata":
|
|
165
|
+
return transferSqlServerDatabaseMetadata(args);
|
|
166
|
+
case "list-compliance-exceptions":
|
|
167
|
+
return listComplianceExceptions(args);
|
|
168
|
+
case "update-compliance-exception":
|
|
169
|
+
return updateComplianceException(args);
|
|
170
|
+
case "update-compliance-exceptions":
|
|
171
|
+
return updateComplianceExceptions(args);
|
|
40
172
|
case "help":
|
|
41
173
|
case "":
|
|
42
174
|
return printHelp();
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
const { getOpsCompassClient } = require("../opscompass.js");
|
|
2
2
|
const { ScriptType, cliCommand } = require("../environment/current.js");
|
|
3
|
-
const { downloadScriptsToHome, findOrCreateScriptTypeFolder, SRC_FOLDER_NAME, BASE_SCRIPTS_RUN_ALL_RELATIVE_PATH, getInstalledScriptVersion } = require("../lib/homeInteraction.js");
|
|
3
|
+
const { downloadScriptsToHome, findOrCreateScriptTypeFolder, SRC_FOLDER_NAME, BASE_SCRIPTS_RUN_ALL_RELATIVE_PATH, getInstalledScriptVersion, previousScriptsDownloaded } = require("../lib/homeInteraction.js");
|
|
4
4
|
const { canReadFile } = require("../lib/cliHelpers.js");
|
|
5
5
|
const semver = require("semver");
|
|
6
6
|
const path = require("path");
|
|
@@ -11,6 +11,7 @@ const exec = util.promisify(require('child_process').exec);
|
|
|
11
11
|
/**
|
|
12
12
|
* Downloads data gathering scripts based on the given scriptType.
|
|
13
13
|
*/
|
|
14
|
+
|
|
14
15
|
async function downloadScripts(args) {
|
|
15
16
|
let companySlug = undefined;
|
|
16
17
|
let scriptType = undefined;
|
|
@@ -88,14 +89,53 @@ async function checkScriptUpdates(args) {
|
|
|
88
89
|
|
|
89
90
|
//Semver returns true if the latest version is higher than the currentScriptVersion.
|
|
90
91
|
if (semver.gt(latestScriptVersion.scriptVersion, currentScriptVersion)) {
|
|
91
|
-
console.log(yellowText, `Warning! You are using version ${currentScriptVersion} of the the ${scriptType} scripts, but the latest version is ${latestScriptVersion.scriptVersion}
|
|
92
|
-
console.log(
|
|
92
|
+
console.log(yellowText, `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:`);
|
|
93
|
+
console.log(greenText, ` ${cliCommand} data-gathering-scripts download-scripts --company ${companySlug} --scriptType ${scriptType} `);
|
|
94
|
+
console.log();
|
|
93
95
|
} else {
|
|
94
|
-
console.log(greenText, `You are using the latest version of ${scriptType} script, ${latestScriptVersion.scriptVersion}.`);
|
|
96
|
+
console.log(greenText, `You are already using the latest version of ${scriptType} script, ${latestScriptVersion.scriptVersion}.`);
|
|
95
97
|
console.log();
|
|
96
98
|
}
|
|
97
99
|
}
|
|
98
100
|
|
|
101
|
+
async function autoCheckScriptUpdates(args) {
|
|
102
|
+
let companySlug = undefined;
|
|
103
|
+
let scriptType = undefined;
|
|
104
|
+
for (let i = 0; i < args.length - 1; i++) {
|
|
105
|
+
switch (args[i].toLowerCase()) {
|
|
106
|
+
case "--company":
|
|
107
|
+
companySlug = args[++i];
|
|
108
|
+
break;
|
|
109
|
+
case "--script-type":
|
|
110
|
+
case "--scripttype":
|
|
111
|
+
scriptType = args[++i];
|
|
112
|
+
break;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
// Check to see if script type has been previously downloaded. If it has, continue with the version check.
|
|
117
|
+
const previouslyDownloadedScripts = previousScriptsDownloaded(scriptType);
|
|
118
|
+
if (!previouslyDownloadedScripts) return;
|
|
119
|
+
|
|
120
|
+
const client = await getOpsCompassClient();
|
|
121
|
+
const currentScriptVersion = await getInstalledScriptVersion(scriptType);
|
|
122
|
+
if (!currentScriptVersion) {
|
|
123
|
+
console.log(`Local scripts for type ${scriptType} not found. Please make sure they are installed.`);
|
|
124
|
+
console.log("If the issue persists, please contact your OpsCompass rep.");
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
const latestScriptVersion = await client.dataGatheringScripts.checkScriptUpdates(companySlug, scriptType);
|
|
129
|
+
|
|
130
|
+
//Semver returns true if the latest version is higher than the currentScriptVersion.
|
|
131
|
+
if (semver.gt(latestScriptVersion.scriptVersion, currentScriptVersion)) {
|
|
132
|
+
console.log(yellowText, `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:`);
|
|
133
|
+
console.log();
|
|
134
|
+
console.log(greenText, ` ${cliCommand} data-gathering-scripts download-scripts --company ${companySlug} --scriptType ${scriptType} `);
|
|
135
|
+
console.log();
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
|
|
99
139
|
/**
|
|
100
140
|
* Manually runs the installed scripts. The base scripts has a runall.sh file.
|
|
101
141
|
* This file runs all installed modules.
|
|
@@ -131,19 +171,24 @@ async function printHelp() {
|
|
|
131
171
|
console.log("download-scripts", "Downloads scripts for the passed script type.");
|
|
132
172
|
console.log("Parameters:");
|
|
133
173
|
console.log("--company [company_slug]");
|
|
134
|
-
console.log("--script-type ['oracle-
|
|
174
|
+
console.log("--script-type ['oracle-compliance', 'oracle-features', 'vsphere', 'msql-license']");
|
|
135
175
|
console.log("--script-version (optional) [version] if not provided, the latest script will be downloaded");
|
|
136
176
|
console.log();
|
|
137
177
|
console.log("check-script-updates", "Checks locally installed script version against the latest published version for the passed script type.");
|
|
138
178
|
console.log("Parameters:");
|
|
139
179
|
console.log("--company [company_slug]");
|
|
140
|
-
console.log("--script-type ['oracle-
|
|
180
|
+
console.log("--script-type ['oracle-compliance', 'oracle-features', 'vsphere', 'msql-license']");
|
|
141
181
|
console.log();
|
|
142
182
|
console.log("manually-run-scripts", "Do not run this unless you know what you are doing. This manually runs all the scripts.");
|
|
143
183
|
console.log();
|
|
144
184
|
}
|
|
145
185
|
|
|
146
186
|
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
|
|
188
|
+
if (action !== 'check-script-updates' && args.length > 0 ) {
|
|
189
|
+
autoCheckScriptUpdates(args)
|
|
190
|
+
}
|
|
191
|
+
|
|
147
192
|
switch (action?.toLowerCase() ?? "") {
|
|
148
193
|
case "download-scripts":
|
|
149
194
|
return downloadScripts(args);
|
|
@@ -193,7 +193,7 @@ async function getVCenterConfiguration(args) {
|
|
|
193
193
|
async function createVCenterConfiguration(args) {
|
|
194
194
|
let id = undefined;
|
|
195
195
|
let name = undefined;
|
|
196
|
-
let optionalParams = {
|
|
196
|
+
let optionalParams = { actions: undefined, connection: undefined, user: undefined, password: undefined };
|
|
197
197
|
for (let i = 0; i < args.length - 1; i++) {
|
|
198
198
|
switch (args[i].toLowerCase()) {
|
|
199
199
|
case "--monitoringconfigurationid":
|
|
@@ -203,7 +203,8 @@ async function createVCenterConfiguration(args) {
|
|
|
203
203
|
name = args[++i];
|
|
204
204
|
break;
|
|
205
205
|
case "--action":
|
|
206
|
-
optionalParams.
|
|
206
|
+
if (optionalParams.actions === undefined) optionalParams.actions = [];
|
|
207
|
+
optionalParams.actions.push(args[++i]);
|
|
207
208
|
break;
|
|
208
209
|
case "--connection":
|
|
209
210
|
optionalParams.connection = args[++i];;
|
|
@@ -226,7 +227,7 @@ async function createVCenterConfiguration(args) {
|
|
|
226
227
|
async function createOracleDatabaseConfiguration(args) {
|
|
227
228
|
let id = undefined;
|
|
228
229
|
let name = undefined;
|
|
229
|
-
let optionalParams = {
|
|
230
|
+
let optionalParams = { actions: undefined, connection: undefined };
|
|
230
231
|
for (let i = 0; i < args.length - 1; i++) {
|
|
231
232
|
switch (args[i].toLowerCase()) {
|
|
232
233
|
case "--monitoringconfigurationid":
|
|
@@ -236,7 +237,8 @@ async function createOracleDatabaseConfiguration(args) {
|
|
|
236
237
|
name = args[++i];
|
|
237
238
|
break;
|
|
238
239
|
case "--action":
|
|
239
|
-
optionalParams.
|
|
240
|
+
if (optionalParams.actions === undefined) optionalParams.actions = [];
|
|
241
|
+
optionalParams.actions.push(args[++i]);
|
|
240
242
|
break;
|
|
241
243
|
case "--connectionstring":
|
|
242
244
|
optionalParams.connection = args[++i];
|
|
@@ -307,7 +309,8 @@ async function updateOracleDatabaseConfiguration(args) {
|
|
|
307
309
|
callParams.name = args[++i];
|
|
308
310
|
break;
|
|
309
311
|
case "--action":
|
|
310
|
-
callParams.
|
|
312
|
+
if (callParams.actions === undefined) callParams.actions = [];
|
|
313
|
+
callParams.actions.push(args[++i]);
|
|
311
314
|
break;
|
|
312
315
|
case "--connectionstring":
|
|
313
316
|
callParams.connectionString = args[++i];
|
|
@@ -322,32 +325,34 @@ async function updateOracleDatabaseConfiguration(args) {
|
|
|
322
325
|
}
|
|
323
326
|
|
|
324
327
|
async function updateOracleDatabaseConfigurations(args) {
|
|
325
|
-
|
|
326
328
|
let callParamsArray = [];
|
|
327
329
|
let jsonIndex = args.indexOf('--json-updates')
|
|
328
330
|
let idIndex = args.indexOf('--id')
|
|
329
331
|
let callParams = {};
|
|
330
332
|
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
333
|
+
/* Process bulk update with JSON */
|
|
334
|
+
if (jsonIndex !== -1) {
|
|
335
|
+
const jsonString = args[jsonIndex + 1];
|
|
336
|
+
callParamsArray = JSON.parse(jsonString);
|
|
334
337
|
} else if (idIndex !== -1) {
|
|
335
338
|
/* If no '--json-update' flag, process bulk update with parameter flags (e.g. --id, --name, etc.) */
|
|
336
339
|
for(let i = 0; i < args.length - 1; i++) {
|
|
337
340
|
if(args[i] === '--id') {
|
|
338
341
|
/* Reset callParams object when a second id is encountered */
|
|
339
|
-
callParams = {
|
|
342
|
+
callParams = {
|
|
343
|
+
};
|
|
340
344
|
/* Push callParams into the array. */
|
|
341
345
|
callParamsArray.push(callParams)
|
|
342
346
|
/* Create the object's properties based on the index (e.g. if the index is --id, you'll find the value at the next index */
|
|
343
347
|
callParams.id = args[i + 1];
|
|
344
348
|
} else if(args[i] === '--configurationName') {
|
|
345
349
|
callParams.configurationName = args[i + 1];
|
|
346
|
-
} else if(args[i] === '--action') {
|
|
347
|
-
callParams.action = args[i + 1];
|
|
348
350
|
} else if(args[i] === '--connectionstring') {
|
|
349
351
|
callParams.connectionString = args[i + 1];
|
|
350
|
-
}
|
|
352
|
+
} else if(args[i] === '--action') {
|
|
353
|
+
if (callParams.actions === undefined) callParams.actions = [];
|
|
354
|
+
callParams.actions.push(args[i + 1]);
|
|
355
|
+
}
|
|
351
356
|
}
|
|
352
357
|
} else {
|
|
353
358
|
console.warn("Invalid input, please see help for examples.")
|
|
@@ -360,7 +365,8 @@ async function updateOracleDatabaseConfigurations(args) {
|
|
|
360
365
|
|
|
361
366
|
|
|
362
367
|
async function updateVCenterConfiguration(args) {
|
|
363
|
-
const callParams = {
|
|
368
|
+
const callParams = {
|
|
369
|
+
};
|
|
364
370
|
for (let i = 0; i < args.length - 1; i++) {
|
|
365
371
|
switch (args[i].toLowerCase()) {
|
|
366
372
|
case "--id":
|
|
@@ -370,7 +376,8 @@ async function updateVCenterConfiguration(args) {
|
|
|
370
376
|
callParams.name = args[++i];
|
|
371
377
|
break;
|
|
372
378
|
case "--action":
|
|
373
|
-
callParams.
|
|
379
|
+
if (callParams.actions === undefined) callParams.actions = [];
|
|
380
|
+
callParams.actions.push(args[++i]);
|
|
374
381
|
break;
|
|
375
382
|
case "--connection":
|
|
376
383
|
callParams.connection = args[++i];
|
|
@@ -396,15 +403,17 @@ async function updateVCenterConfigurations(args) {
|
|
|
396
403
|
let idIndex = args.indexOf('--id')
|
|
397
404
|
let callParams = {};
|
|
398
405
|
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
406
|
+
/* Process bulk update with JSON */
|
|
407
|
+
if (jsonIndex !== -1) {
|
|
408
|
+
const jsonString = args[jsonIndex + 1];
|
|
409
|
+
callParamsArray = JSON.parse(jsonString);
|
|
410
|
+
} else if (idIndex !== -1) {
|
|
403
411
|
/* If no '--json-update' flag, process bulk update with parameter flags (e.g. --id, --name, etc.) */
|
|
404
412
|
for(let i = 0; i < args.length - 1; i++) {
|
|
405
413
|
if(args[i] === '--id') {
|
|
406
414
|
/* Reset callParams object when a second id is encountered */
|
|
407
|
-
callParams = {
|
|
415
|
+
callParams = {
|
|
416
|
+
};
|
|
408
417
|
/* if theres an existing callParams object, toss it into the array and move on. */
|
|
409
418
|
callParamsArray.push(callParams)
|
|
410
419
|
/* Create the object's properties based on the index (e.g. if the index is --id, you'll find the value at the next index */
|
|
@@ -412,14 +421,15 @@ async function updateVCenterConfigurations(args) {
|
|
|
412
421
|
} else if(args[i] === '--configurationName') {
|
|
413
422
|
callParams.configurationName = args[i + 1];
|
|
414
423
|
} else if(args[i] === '--action') {
|
|
415
|
-
|
|
424
|
+
if (callParams.actions === undefined) callParams.actions = [];
|
|
425
|
+
callParams.actions = args[i + 1];
|
|
416
426
|
} else if(args[i] === '--connection') {
|
|
417
427
|
callParams.connection = args[i + 1];
|
|
418
428
|
} else if(args[i] === '--user') {
|
|
419
429
|
callParams.user = args[i + 1];
|
|
420
430
|
} else if(args[i] === '--password') {
|
|
421
431
|
callParams.password = args[i + 1];
|
|
422
|
-
}
|
|
432
|
+
}
|
|
423
433
|
}
|
|
424
434
|
} else {
|
|
425
435
|
console.warn("Invalid input, please see help for examples.")
|
|
@@ -473,7 +483,7 @@ async function printHelp() {
|
|
|
473
483
|
console.log("Parameters:");
|
|
474
484
|
console.log("--monitoringConfigurationId [monitoring_configuration_id]");
|
|
475
485
|
console.log("--name [unique name]");
|
|
476
|
-
console.log("--action (optional)
|
|
486
|
+
console.log("--action (optional) pass multiple times to define which actions this connection can take ['skip', 'inventory', 'vmotion']");
|
|
477
487
|
console.log("--connection (optional) [the hostname or ip address]");
|
|
478
488
|
console.log("--user (optional) [connection username]");
|
|
479
489
|
console.log("--password (optional) [connection password]");
|
|
@@ -482,7 +492,7 @@ async function printHelp() {
|
|
|
482
492
|
console.log("Parameters:");
|
|
483
493
|
console.log("--monitoringConfigurationId [monitoring_configuration_id]");
|
|
484
494
|
console.log("--name [unique name]");
|
|
485
|
-
console.log("--action (optional)
|
|
495
|
+
console.log("--action (optional) pass multiple times to define which actions this connection can take ['skip', 'compliance', 'dblicensing']");
|
|
486
496
|
console.log("--connectionString (optional) [the database connection string]");
|
|
487
497
|
console.log();
|
|
488
498
|
console.log("update-monitoring-configuration", "Update a single monitoring configuration.");
|
|
@@ -502,26 +512,26 @@ async function printHelp() {
|
|
|
502
512
|
console.log("Parameters:");
|
|
503
513
|
console.log("--id [configuration id]");
|
|
504
514
|
console.log("--name (optional) [unique name]");
|
|
505
|
-
console.log("--action (optional)
|
|
515
|
+
console.log("--action (optional) pass multiple times to define which actions this connection can take ['skip', 'compliance', 'dblicensing']");
|
|
506
516
|
console.log("--connectionString (optional) [the database connection string]");
|
|
507
517
|
console.log();
|
|
508
518
|
console.log("update-oracle-database-configurations", "Bulk update oracle database configurations.");
|
|
509
519
|
console.log("Parameters:");
|
|
510
520
|
console.log("--id [configuration id]");
|
|
511
521
|
console.log("--name (optional) [unique name]");
|
|
512
|
-
console.log("--action (optional)
|
|
522
|
+
console.log("--action (optional) pass multiple times to define which actions this connection can take ['skip', 'compliance', 'dblicensing']");
|
|
513
523
|
console.log("--connectionString (optional) [the database connection string]");
|
|
514
524
|
console.log("OR --json-updates [stringified json objects with your updates]");
|
|
515
525
|
console.log("For quick updates, you may use the above parameters");
|
|
516
526
|
console.log(`e.g. opscompass license-manager update-oracle-database-configurations --id 57 --configurationName "updatedName" --id 62 --configurationName "otherUpdatedName" --id 77 --configurationName "lastUpdatedName";`);
|
|
517
527
|
console.log("For larger updates, JavaScript Object Notation (JSON) may be used with the --json-updates flag");
|
|
518
|
-
console.log(`e.g. opscompass license-manager update-oracle-database-configurations --json-updates '[{"id"
|
|
528
|
+
console.log(`e.g. opscompass license-manager update-oracle-database-configurations --json-updates '[{\"id\":\"57\",\"configurationName\":\"updatedName\"},{\"id\":\"77\", \"configurationName\":\"otherUpdatedName\", \"action\":\"null\"},{\"id\":\"79\", \"configurationName\":\"lastUpdatedName\"}]'`);
|
|
519
529
|
console.log();
|
|
520
530
|
console.log("update-vcenter-configuration", "Update a single vcenter configuration.");
|
|
521
531
|
console.log("Parameters:");
|
|
522
532
|
console.log("--id [configuration id]");
|
|
523
533
|
console.log("--name (optional) [unique name]");
|
|
524
|
-
console.log("--action (optional)
|
|
534
|
+
console.log("--action (optional) pass multiple times to define which actions this connection can take ['skip', 'inventory', 'vmotion']");
|
|
525
535
|
console.log("--connection (optional) [the hostname or ip address]");
|
|
526
536
|
console.log("--user (optional) [connection username]");
|
|
527
537
|
console.log("--password (optional) [connection password]");
|
|
@@ -530,7 +540,7 @@ async function printHelp() {
|
|
|
530
540
|
console.log("Parameters:");
|
|
531
541
|
console.log("--id [configuration id]");
|
|
532
542
|
console.log("--name (optional) [unique name]");
|
|
533
|
-
console.log("--action (optional)
|
|
543
|
+
console.log("--action (optional) pass multiple times to define which actions this connection can take ['skip', 'inventory', 'vmotion']");
|
|
534
544
|
console.log("--connection (optional) [the hostname or ip address]");
|
|
535
545
|
console.log("--user (optional) [connection username]");
|
|
536
546
|
console.log("--password (optional) [connection password]");
|
|
@@ -538,7 +548,7 @@ async function printHelp() {
|
|
|
538
548
|
console.log("For quick updates, you may use the above parameters");
|
|
539
549
|
console.log(`e.g. opscompass license-manager update-vcenter-configurations --id 137 --configurationName "updatedName" --id 138 --configurationName "otherUpdatedName" --id 144 --configurationName "lastUpdatedName";`);
|
|
540
550
|
console.log("For larger updates, JavaScript Object Notation (JSON) may be used with the --json-updates flag");
|
|
541
|
-
console.log(`e.g. opscompass license-manager update-vcenter-configurations --json-updates '[{"id"
|
|
551
|
+
console.log(`e.g. opscompass license-manager update-vcenter-configurations --json-updates '[{\"id\":\"137\",\"configurationName\":\"updatedName\"},{\"id\":\"138\",\"configurationName\":\"otherUpdatedName\"},{\"id\":\"144\",\"configurationName\":\"lastUpdatedName\"}]'`);
|
|
542
552
|
console.log();
|
|
543
553
|
console.log("delete-monitoring-configuration", "Delete a monitoring configuration");
|
|
544
554
|
console.log("Parameters:");
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@opscompass/opscompass-cli",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.11",
|
|
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.11",
|
|
19
19
|
"adm-zip": "^0.5.9",
|
|
20
20
|
"axios": "^0.21.1",
|
|
21
21
|
"fs-extra": "^10.1.0",
|
package/updates.js
CHANGED
|
@@ -20,7 +20,7 @@ function versionCheck() {
|
|
|
20
20
|
};
|
|
21
21
|
/* Semver used to semantically compare version numbers */
|
|
22
22
|
if (semver.gt(latestVersion, pkg.version)) {
|
|
23
|
-
console.error(yellowText,
|
|
23
|
+
console.error(yellowText, `Warning! You are using CLI version ${pkg.version}, but the latest version is ${latestVersion}To upgrade to the latest version, please run:`);
|
|
24
24
|
/* Prompt user to upgrade to the correct package based on their current environment */
|
|
25
25
|
console.error(greenText, `\nnpm install -g ${pkg.name}@${latestVersion}\n`);
|
|
26
26
|
return;
|