@opscompass/opscompass-cli 1.0.16 → 1.0.18

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/cliHelpers.js CHANGED
@@ -3,6 +3,12 @@ const https = require('https');
3
3
  const path = require("path");
4
4
  const AdmZip = require('adm-zip');
5
5
 
6
+ let httpsProxyAgent;
7
+ if (process.env.https_proxy || process.env.HTTPS_PROXY) {
8
+ const createHttpsProxyAgent = require("https-proxy-agent");
9
+ httpsProxyAgent = createHttpsProxyAgent(process.env.https_proxy || process.env.HTTPS_PROXY);
10
+ }
11
+
6
12
  /**
7
13
  * Users need to be able to enter array data into the CLI. They do this by submitting identical argument names with each element value.
8
14
  * This method consolidates all data associated with the specified argument names, and creates an array object.
@@ -100,8 +106,14 @@ function deleteDirectory(directoryPath) {
100
106
  */
101
107
  async function downloadFile(downloadUrl, downloadFilePath, downloadName) {
102
108
  return new Promise((resolve, reject) => {
109
+ const getOptions = {};
110
+
111
+ if (httpsProxyAgent) {
112
+ getOptions.agent = httpsProxyAgent;
113
+ }
114
+
103
115
  // Download the file
104
- https.get(downloadUrl, (res) => {
116
+ https.get(downloadUrl, getOptions, (res) => {
105
117
 
106
118
  // Open file in local filesystem
107
119
  const file = fs.createWriteStream(path.join(downloadFilePath, downloadName));
@@ -9,6 +9,196 @@ const { getCredentials } = require("../credentials.js");
9
9
  console.log(JSON.stringify(response, null, 2));
10
10
  }
11
11
 
12
+ async function getUpcomingExceptionInfo(args) {
13
+ for (let i = 0; i < args.length; i++) {
14
+ switch (args[i].toLowerCase()) {
15
+ case "--company":
16
+ callParams.company = args[++i];
17
+ break;
18
+ case "--frameworkid":
19
+ case "--framework-id":
20
+ callParams.frameworkId = args[++i];
21
+ break;
22
+ case "--accounts":
23
+ if (typeof callParams.accounts === "string") {
24
+ callParams.accounts = [callParams.accounts];
25
+ }
26
+ if (Array.isArray(callParams.accounts)) {
27
+ callParams.accounts.push(args[++i]);
28
+ } else {
29
+ callParams.accounts = args[++i];
30
+ }
31
+ break;
32
+ }
33
+ }
34
+ const client = await getOpsCompassClient();
35
+ const response = await client.compliance.getUpcomingExceptionInfo(callParams.company, callParams.accounts, callParams.frameworkId);
36
+
37
+ console.log(JSON.stringify(response, null, 2));
38
+ }
39
+
40
+ async function getCheckStatusOverview(args) {
41
+ for (let i = 0; i < args.length; i++) {
42
+ switch (args[i].toLowerCase()) {
43
+ case "--company":
44
+ callParams.company = args[++i];
45
+ break;
46
+ case "--frameworkid":
47
+ case "--framework-id":
48
+ callParams.frameworkId = args[++i];
49
+ break;
50
+ case "--accounts":
51
+ if (typeof callParams.accounts === "string") {
52
+ callParams.accounts = [callParams.accounts];
53
+ }
54
+ if (Array.isArray(callParams.accounts)) {
55
+ callParams.accounts.push(args[++i]);
56
+ } else {
57
+ callParams.accounts = args[++i];
58
+ }
59
+ break;
60
+ }
61
+ }
62
+ const client = await getOpsCompassClient();
63
+ const response = await client.compliance.getCheckStatusOverview(callParams.company, callParams.accounts, callParams.frameworkId);
64
+
65
+ console.log(JSON.stringify(response, null, 2));
66
+ }
67
+
68
+ async function getComplianceProblemsOverTime(args) {
69
+ for (let i = 0; i < args.length; i++) {
70
+ switch (args[i].toLowerCase()) {
71
+ case "--company":
72
+ callParams.company = args[i+1];
73
+ break;
74
+ case "--accounts":
75
+ if (typeof callParams.accounts === "string") {
76
+ callParams.accounts = [callParams.accounts];
77
+ }
78
+ if (Array.isArray(callParams.accounts)) {
79
+ callParams.accounts.push(args[++i]);
80
+ } else {
81
+ callParams.accounts = args[++i];
82
+ }
83
+ break;
84
+ case "--start-date":
85
+ case "--startdate":
86
+ callParams.startDate = args[++i];
87
+ break;
88
+ case "--end-date":
89
+ case "--enddate":
90
+ callParams.endDate = args[++i];
91
+ break;
92
+ case "--frameworkid":
93
+ case "--framework-id":
94
+ callParams.frameworkId = args[++i];
95
+ break;
96
+ }
97
+ }
98
+
99
+ const client = await getOpsCompassClient();
100
+ const response = await client.compliance.getComplianceProblemsOverTime(callParams.company, callParams.accounts, callParams.startDate, callParams.endDate, callParams.frameworkId);
101
+
102
+ console.log(JSON.stringify(response, null, 2));
103
+ }
104
+
105
+ async function listFrameworks(args) {
106
+ for (let i = 0; i < args.length; i++) {
107
+ switch (args[i].toLowerCase()) {
108
+ case "--company":
109
+ callParams.company = args[i+1];
110
+ break;
111
+ }
112
+ }
113
+
114
+
115
+ const client = await getOpsCompassClient();
116
+ const response = await client.compliance.listFrameworks(callParams.company);
117
+
118
+ console.log(JSON.stringify(response, null, 2));
119
+ }
120
+
121
+ async function listFrameworksWithDetails(args) {
122
+ for (let i = 0; i < args.length; i++) {
123
+ switch (args[i].toLowerCase()) {
124
+ case "--company":
125
+ callParams.company = args[i+1];
126
+ break;
127
+ case "--accounts":
128
+ if (typeof callParams.accounts === "string") {
129
+ callParams.accounts = [callParams.accounts];
130
+ }
131
+ if (Array.isArray(callParams.accounts)) {
132
+ callParams.accounts.push(args[++i]);
133
+ } else {
134
+ callParams.accounts = args[++i];
135
+ }
136
+ break;
137
+ }
138
+ }
139
+
140
+
141
+ const client = await getOpsCompassClient();
142
+ const response = await client.compliance.listFrameworksWithDetails(callParams.company, callParams.accounts);
143
+
144
+ console.log(JSON.stringify(response, null, 2));
145
+ }
146
+
147
+
148
+ async function listChecksWithDetails(args) {
149
+ for (let i = 0; i < args.length; i++) {
150
+ switch (args[i].toLowerCase()) {
151
+ case "--company":
152
+ callParams.company = args[i+1];
153
+ break;
154
+ case "--accounts":
155
+ if (typeof callParams.accounts === "string") {
156
+ callParams.accounts = [callParams.accounts];
157
+ }
158
+ if (Array.isArray(callParams.accounts)) {
159
+ callParams.accounts.push(args[++i]);
160
+ } else {
161
+ callParams.accounts = args[++i];
162
+ }
163
+ break;
164
+ }
165
+ }
166
+
167
+
168
+ const client = await getOpsCompassClient();
169
+ const response = await client.compliance.listChecksWithDetails(callParams.company, callParams.accounts);
170
+
171
+
172
+ console.log(JSON.stringify(response, null, 2));
173
+ }
174
+
175
+ async function listDisabledChecks(args) {
176
+ for (let i = 0; i < args.length; i++) {
177
+ switch (args[i].toLowerCase()) {
178
+ case "--company":
179
+ callParams.company = args[i+1];
180
+ break;
181
+ case "--accounts":
182
+ if (typeof callParams.accounts === "string") {
183
+ callParams.accounts = [callParams.accounts];
184
+ }
185
+ if (Array.isArray(callParams.accounts)) {
186
+ callParams.accounts.push(args[++i]);
187
+ } else {
188
+ callParams.accounts = args[++i];
189
+ }
190
+ break;
191
+ }
192
+ }
193
+
194
+
195
+ const client = await getOpsCompassClient();
196
+ const response = await client.compliance.listDisabledChecks(callParams.company, callParams.accounts);
197
+
198
+
199
+ console.log(JSON.stringify(response, null, 2));
200
+ }
201
+
12
202
  async function transferVMwareVsphereMetadata(args) {
13
203
  const callParams = genericMetadataTrasfer(args);
14
204
  const client = await getOpsCompassClient();
@@ -233,6 +423,45 @@ const { getCredentials } = require("../credentials.js");
233
423
  async function printHelp() {
234
424
  console.log("Actions available for compliance:");
235
425
  console.log();
426
+ console.log("list-checks-with-details", "Retrieves the list of compliance checks for the specified company, with the amount of active resource problems and compliance score impact for each check");
427
+ console.log("Parameters:");
428
+ console.log("--company [company_slug]");
429
+ console.log("--accounts (optional) [account_id]");
430
+ console.log();
431
+ console.log("list-disabled-checks", "Retrieves the list of disabled compliance checks for the specified company, with the amount of resources that each check is not scanning against.");
432
+ console.log("Parameters:");
433
+ console.log("--company [company_slug]");
434
+ console.log("--accounts (optional) [account_id]");
435
+ console.log();
436
+ console.log("list-frameworks", "Retrieves the list of compliance frameworks available for the specified company");
437
+ console.log("Parameters:");
438
+ console.log("--company [company_slug]");
439
+ console.log();
440
+ console.log("list-frameworks-with-details", "Retrieves the list of compliance frameworks available for the specified company, with the amount of active control problems and compliance score for each framework");
441
+ console.log("Parameters:");
442
+ console.log("--company [company_slug]");
443
+ console.log("--accounts [account_id]");
444
+ console.log();
445
+ console.log("get-upcoming-exception-info", "Retrieves the soon to be expiring compliance exception information for the specified company.");
446
+ console.log("Parameters:");
447
+ console.log("--company [company_slug]");
448
+ console.log("--accounts (optional) [account_id]");
449
+ console.log("--frameworkId (optional) [compliance_framework_id]");
450
+ console.log();
451
+ console.log("get-check-status-overview", "Retrieves an overview of compliance check statuses, associated with a company.");
452
+ console.log("Parameters:");
453
+ console.log("--company [company_slug]");
454
+ console.log("--accounts (optional) [account_id] Ex. --accounts account_123,account_456");
455
+ console.log("--frameworkId (optional) [compliance_framework_id] Ex. --frameworkId 28");
456
+ console.log();
457
+ console.log("get-compliance-problems-over-time", "Retrieves a list of aggregated information about compliance problems over a specified timeframe.");
458
+ console.log("Parameters:");
459
+ console.log("--company [company_slug]");
460
+ console.log("--start-date [2020-11-11 00:00:00.000]")
461
+ console.log("--end-date [2020-11-15 00:00:00.000")
462
+ console.log("--accounts (optional) [account_id] Ex. --accounts account_123,account_456");
463
+ console.log("--frameworkId (optional) [compliance_framework_id] Ex. --frameworkId 28");
464
+ console.log();
236
465
  console.log("transfer-oracle-database-metadata", "Transfers OpsCompass Oracle Database metadata report into OpsCompass for processing");
237
466
  console.log("Parameters:");
238
467
  console.log("--company [company_slug]");
@@ -305,6 +534,20 @@ const { getCredentials } = require("../credentials.js");
305
534
 
306
535
  const complianceModule = (action, ...args) => {
307
536
  switch (action?.toLowerCase() ?? "") {
537
+ case "list-checks-with-details":
538
+ return listChecksWithDetails(args);
539
+ case "list-disabled-checks":
540
+ return listDisabledChecks(args);
541
+ case "list-frameworks-with-details":
542
+ return listFrameworksWithDetails(args);
543
+ case "list-frameworks":
544
+ return listFrameworks(args);
545
+ case "get-upcoming-exception-info":
546
+ return getUpcomingExceptionInfo(args);
547
+ case "get-check-status-overview":
548
+ return getCheckStatusOverview(args);
549
+ case "get-compliance-problems-over-time":
550
+ return getComplianceProblemsOverTime(args);
308
551
  case "transfer-network-discovery-metadata":
309
552
  return transferNetworkDiscoveryMetadata(args);
310
553
  case "transfer-vmware-vsphere-metadata":
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opscompass/opscompass-cli",
3
- "version": "1.0.16",
3
+ "version": "1.0.18",
4
4
  "description": "Calls OpsCompass's APIs",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -15,10 +15,11 @@
15
15
  "author": "opscompass",
16
16
  "license": "SEE LICENSE IN license.txt",
17
17
  "dependencies": {
18
- "@opscompass/opscompass-api": "^1.0.16",
18
+ "@opscompass/opscompass-api": "^1.0.18",
19
19
  "adm-zip": "^0.5.9",
20
20
  "axios": "^0.21.1",
21
21
  "fs-extra": "^10.1.0",
22
+ "https-proxy-agent": "^5.0.1",
22
23
  "open": "^8.2.1",
23
24
  "semver": "^7.3.7"
24
25
  },