@opscompass/opscompass-cli 1.0.8 → 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/license.txt ADDED
@@ -0,0 +1,33 @@
1
+ OPCOMPASS™ COMMAND LINE INTERFACE
2
+ LICENSE AGREEMENT
3
+
4
+ IMPORTANT! READ CAREFULLY: THIS IS A LEGAL AGREEMENT. BY DOWNLOADING, INSTALLING, COPYING, SAVING ON YOUR COMPUTER, OR OTHERWISE USING THIS TOOL, YOU (LICENSEE, AS DEFINED BELOW) ARE BECOMING A PARTY TO THIS AGREEMENT AND YOU ARE CONSENTING TO BE BOUND BY ALL THE TERMS AND CONDITIONS OF THIS AGREEMENT.
5
+ IF YOU DO NOT AGREE TO THE TERMS AND CONDITIONS OF THIS AGREEMENT, YOU SHOULD NOT DOWNLOAD, INSTALL, OR USE THE TOOL.
6
+
7
+ 1. PARTIES
8
+ (a) "Licensor" means OpsCompass, Inc., having its principal place of business at 11422 Miracle Hills Dr #300, Omaha, NE 68154.
9
+ (b) "Licensee" means an individual or a legal entity entering into and exercising rights under this Agreement or future versions thereof. Licensee is also referred to herein as "You".
10
+
11
+ 2. DEFINITIONS
12
+ "Tool" means the software program known as the OpsCompass™ Command Line Interface in its delivered form, including its source code and documentation (if any).
13
+
14
+ 3. OWNERSHIP
15
+ The Tool is the property of Licensor. The Tool is licensed, not sold. Title and copyrights to the Tool, in whole and in part and all copies thereof, and all modifications, enhancements, derivatives and other alterations of the Tool regardless of who made any modifications, if any, are, and will remain, the sole and exclusive property of Licensor.
16
+
17
+ 4. GRANT OF LICENSE
18
+ Subject to the terms, conditions, and limitations set forth in this Agreement, including any amendments thereto, Licensor hereby grants to Licensee a limited, non-exclusive, perpetual license to install and use the Tool in accordance with the Tool documentation and pursuant to the terms and conditions of this Agreement.
19
+
20
+ 5. FEEDBACK
21
+ Licensee may, but is not obligated to, provide to Licensor or its subsidiaries suggestions, comments and feedback regarding the Tool, including but not limited to usability, bug reports and test results (collectively, "Feedback"). All right, title, and interest in the Feedback shall belong to Licensor for its unlimited use and Licensee agrees to perform any reasonable tasks necessary to document Licensor’s ownership in the same.
22
+
23
+ 6. NO WARRANTY
24
+ THE TOOL IS PROVIDED TO LICENSEE "AS IS" AND WITHOUT WARRANTIES. LICENSOR MAKES NO WARRANTY AS TO ITS USE OR PERFORMANCE. TO THE MAXIMUM EXTENT PERMITTED BY APPLICABLE LAW, LICENSOR AND ITS AFFILIATES, SUPPLIERS, AND RESELLERS, DISCLAIM ALL OTHER WARRANTIES AND CONDITIONS, EITHER EXPRESS OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE, AND NON-INFRINGEMENT, WITH REGARD TO THE TOOL, AND THE PROVISION OF OR FAILURE TO PROVIDE SUPPORT SERVICES.
25
+
26
+ 7. DISCLAIMER OF DAMAGES
27
+ (a) TO THE MAXIMUM EXTENT PERMITTED BY APPLICABLE LAW, IN NO EVENT WILL LICENSOR OR ITS AFFILIATES, LICENSORS, SUPPLIERS OR RESELLERS BE LIABLE TO LICENSEE UNDER ANY THEORY FOR ANY DAMAGES SUFFERED BY LICENSEE OR ANY USER OF THE TOOL, OR FOR ANY SPECIAL, INCIDENTAL, INDIRECT, CONSEQUENTIAL, OR SIMILAR DAMAGES (INCLUDING, BUT NOT LIMITED TO, DAMAGES FOR LOSS OF PROFITS OR CONFIDENTIAL OR OTHER INFORMATION, FOR BUSINESS INTERRUPTION, FOR PERSONAL INJURY, FOR LOSS OF PRIVACY, FOR FAILURE TO MEET ANY DUTY INCLUDING OF GOOD FAITH OR OF REASONABLE CARE, FOR NEGLIGENCE, AND FOR ANY OTHER PECUNIARY OR OTHER LOSS WHATSOEVER) ARISING OUT OF THE USE OR INABILITY TO USE THE TOOL, OR THE PROVISION OF OR FAILURE TO PROVIDE SUPPORT SERVICES, EVEN IF LICENSOR HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES, AND REGARDLESS OF THE LEGAL OR EQUITABLE THEORY (CONTRACT, TORT OR OTHERWISE) UPON WHICH THE CLAIM IS BASED.
28
+ (b) IN ANY CASE, LICENSOR'S ENTIRE LIABILITY UNDER ANY PROVISION OF THIS AGREEMENT WILL BE LIMITED TO THE AMOUNT ACTUALLY PAID BY LICENSEE FOR THE TOOL UNDER THIS AGREEMENT OR FIVE (5) USD, WHICHEVER IS GREATER.
29
+
30
+ 8. GENERAL
31
+ (a) Licensor reserves the right at any time to cease the support of the Tool and to alter features, specifications, capabilities, functions, licensing terms, release dates, general availability or other characteristics of the Tool.
32
+ (b) This Agreement constitutes the entire agreement between the parties concerning Licensee's use of the Tool, and supersedes any and all prior or contemporaneous oral or written representations, communications, or advertising with respect to the Tool.
33
+ (c) This Agreement will be governed by the laws of Nebraska, in the United States, without reference to conflict of laws principles. Licensee agrees that any litigation relating to this Agreement may only be brought in, and will be subject to the jurisdiction of, the state, local, and federal courts located in Douglas County, Nebraska.
@@ -0,0 +1,184 @@
1
+ const { getOpsCompassClient } = require("../opscompass.js");
2
+ const { getCredentials } = require("../credentials.js");
3
+
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) {
21
+ const callParams = {};
22
+ for (let i = 0; i < args.length - 1; i++) {
23
+ switch (args[i].toLowerCase()) {
24
+ case "--filepath":
25
+ callParams.filePath = args[++i];
26
+ break;
27
+ case "--company":
28
+ callParams.company = args[++i];
29
+ break;
30
+ }
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
+ }
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
+ }
73
+
74
+ const client = await getOpsCompassClient();
75
+ const complianceException = await client.compliance.updateComplianceException(callParams.id, callParams);
76
+ console.log(JSON.stringify(complianceException, null, 2));
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 = {};
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
+ }
120
+
121
+ async function printHelp() {
122
+ console.log("Actions available for compliance:");
123
+ console.log();
124
+ console.log("transfer-oracle-database-metadata", "Transfers OpsCompass Oracle Database metadata report into OpsCompass for processing");
125
+ console.log("Parameters:");
126
+ console.log("--company [company_slug]");
127
+ console.log("--filePath [path] Path of the file to transfer to OpsCompass for processing.");
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();
157
+ }
158
+
159
+
160
+ const complianceModule = (action, ...args) => {
161
+ switch (action?.toLowerCase() ?? "") {
162
+ case "transfer-oracle-database-metadata":
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);
172
+ case "help":
173
+ case "":
174
+ return printHelp();
175
+ default:
176
+ console.log("Unknown command:", action);
177
+ return printHelp();
178
+ }
179
+ };
180
+
181
+ complianceModule.requiresLogin = true;
182
+ complianceModule.description = "Provides access to details about resource Compliance in OpsCompass.";
183
+
184
+ module.exports = complianceModule;
@@ -0,0 +1,211 @@
1
+ const { getOpsCompassClient } = require("../opscompass.js");
2
+ const { ScriptType, cliCommand } = require("../environment/current.js");
3
+ const { downloadScriptsToHome, findOrCreateScriptTypeFolder, SRC_FOLDER_NAME, BASE_SCRIPTS_RUN_ALL_RELATIVE_PATH, getInstalledScriptVersion, previousScriptsDownloaded } = require("../lib/homeInteraction.js");
4
+ const { canReadFile } = require("../lib/cliHelpers.js");
5
+ const semver = require("semver");
6
+ const path = require("path");
7
+ const fs = require("fs-extra");
8
+ const util = require('util');
9
+ const exec = util.promisify(require('child_process').exec);
10
+
11
+ /**
12
+ * Downloads data gathering scripts based on the given scriptType.
13
+ */
14
+
15
+ async function downloadScripts(args) {
16
+ let companySlug = undefined;
17
+ let scriptType = undefined;
18
+ let scriptVersion = undefined
19
+ for (let i = 0; i < args.length - 1; i++) {
20
+ switch (args[i].toLowerCase()) {
21
+ case "--company":
22
+ companySlug = args[++i];
23
+ break;
24
+ case "--script-type":
25
+ case "--scripttype":
26
+ scriptType = args[++i];
27
+ break;
28
+ case "--script-version":
29
+ case "--scriptversion":
30
+ scriptVersion = args[++i];
31
+ break;
32
+ }
33
+ }
34
+
35
+ // If script type is not supported, we do not want to continue.
36
+ const scriptTypes = Object.values(ScriptType);
37
+ if (!scriptTypes.includes(scriptType)) {
38
+ console.log("Unsupported script type...");
39
+ return;
40
+ }
41
+
42
+ try {
43
+ const client = await getOpsCompassClient();
44
+
45
+ await downloadScriptsToHome(scriptType, scriptVersion, companySlug, client);
46
+
47
+ console.log("Download Successful!");
48
+ } catch (err) {
49
+ console.log("Download failed...");
50
+ console.log(err);
51
+ }
52
+ }
53
+
54
+ /**
55
+ * Checks the installed scripts version against the latest scripts version for a given scriptType.
56
+ */
57
+ async function checkScriptUpdates(args) {
58
+ let companySlug = undefined;
59
+ let scriptType = undefined;
60
+ for (let i = 0; i < args.length - 1; i++) {
61
+ switch (args[i].toLowerCase()) {
62
+ case "--company":
63
+ companySlug = args[++i];
64
+ break;
65
+ case "--script-type":
66
+ case "--scripttype":
67
+ scriptType = args[++i];
68
+ break;
69
+ }
70
+ }
71
+
72
+ // If script type is not supported, we do not want to continue.
73
+ const scriptTypes = Object.values(ScriptType);
74
+ if (!scriptTypes.includes(scriptType)) {
75
+ console.log("Unsupported script type...");
76
+ return;
77
+ }
78
+
79
+ const client = await getOpsCompassClient();
80
+ const currentScriptVersion = await getInstalledScriptVersion(scriptType);
81
+
82
+ if (!currentScriptVersion) {
83
+ console.log(`Local scripts for type ${scriptType} not found. Please make sure they are installed.`);
84
+ console.log("If the issue persists, please contact your OpsCompass rep.");
85
+ return;
86
+ }
87
+
88
+ const latestScriptVersion = await client.dataGatheringScripts.checkScriptUpdates(companySlug, scriptType);
89
+
90
+ //Semver returns true if the latest version is higher than the currentScriptVersion.
91
+ if (semver.gt(latestScriptVersion.scriptVersion, currentScriptVersion)) {
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();
95
+ } else {
96
+ console.log(greenText, `You are already using the latest version of ${scriptType} script, ${latestScriptVersion.scriptVersion}.`);
97
+ console.log();
98
+ }
99
+ }
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
+
139
+ /**
140
+ * Manually runs the installed scripts. The base scripts has a runall.sh file.
141
+ * This file runs all installed modules.
142
+ */
143
+ async function manuallyRunScripts() {
144
+ try {
145
+ const baseScriptFolderPath = findOrCreateScriptTypeFolder(ScriptType.baseScripts);
146
+ const runAllFilePath = path.join(baseScriptFolderPath, SRC_FOLDER_NAME, BASE_SCRIPTS_RUN_ALL_RELATIVE_PATH);
147
+
148
+ if (canReadFile(runAllFilePath)) {
149
+ const runAllScript = await fs.readFile(
150
+ runAllFilePath,
151
+ { encoding: "utf-8" }
152
+ );
153
+
154
+ const { stdout, stderr } = await exec(runAllScript);
155
+ if (!!stderr) {
156
+ console.log(`Error: ${stderr}`);
157
+ } else {
158
+ console.log(stdout);
159
+ }
160
+ } else {
161
+ throw "Cannot manually run scripts. Make sure the scripts are downloaded.\nIf the issue persists, contact your OpsCompass rep.";
162
+ }
163
+ } catch (err) {
164
+ console.log(err);
165
+ }
166
+ }
167
+
168
+ async function printHelp() {
169
+ console.log("Actions available for data-gathering-scripts:");
170
+ console.log();
171
+ console.log("download-scripts", "Downloads scripts for the passed script type.");
172
+ console.log("Parameters:");
173
+ console.log("--company [company_slug]");
174
+ console.log("--script-type ['oracle-compliance', 'oracle-features', 'vsphere', 'msql-license']");
175
+ console.log("--script-version (optional) [version] if not provided, the latest script will be downloaded");
176
+ console.log();
177
+ console.log("check-script-updates", "Checks locally installed script version against the latest published version for the passed script type.");
178
+ console.log("Parameters:");
179
+ console.log("--company [company_slug]");
180
+ console.log("--script-type ['oracle-compliance', 'oracle-features', 'vsphere', 'msql-license']");
181
+ console.log();
182
+ console.log("manually-run-scripts", "Do not run this unless you know what you are doing. This manually runs all the scripts.");
183
+ console.log();
184
+ }
185
+
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
+
192
+ switch (action?.toLowerCase() ?? "") {
193
+ case "download-scripts":
194
+ return downloadScripts(args);
195
+ case "check-script-updates":
196
+ return checkScriptUpdates(args);
197
+ case "manually-run-scripts":
198
+ return manuallyRunScripts()
199
+ case "help":
200
+ case "":
201
+ return printHelp();
202
+ default:
203
+ console.log("Unknown command:", action);
204
+ return printHelp();
205
+ }
206
+ };
207
+
208
+ dataGatheringScriptsModule.requiresLogin = true;
209
+ dataGatheringScriptsModule.description = "Provides access to OpsCompass data gathering scripts.";
210
+
211
+ module.exports = dataGatheringScriptsModule;