@opscompass/opscompass-cli 1.0.20 → 1.0.22

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
@@ -1,12 +1,14 @@
1
- const fs = require('fs-extra');
2
- const https = require('https');
1
+ const fs = require("fs-extra");
2
+ const https = require("https");
3
3
  const path = require("path");
4
- const AdmZip = require('adm-zip');
4
+ const AdmZip = require("adm-zip");
5
5
 
6
6
  let httpsProxyAgent;
7
7
  if (process.env.https_proxy || process.env.HTTPS_PROXY) {
8
8
  const createHttpsProxyAgent = require("https-proxy-agent");
9
- httpsProxyAgent = createHttpsProxyAgent(process.env.https_proxy || process.env.HTTPS_PROXY);
9
+ httpsProxyAgent = createHttpsProxyAgent(
10
+ process.env.https_proxy || process.env.HTTPS_PROXY
11
+ );
10
12
  }
11
13
 
12
14
  /**
@@ -24,7 +26,7 @@ function setArgumentArrays(argumentNames, args) {
24
26
  let capturingArgument = false;
25
27
 
26
28
  // Filter args down to array of values that match the current argument name
27
- const argumentArray = args.filter(function(value, index) {
29
+ const argumentArray = args.filter(function (value, index) {
28
30
  // The args array elements first have the argument name, and the element following is the value.
29
31
  if (value === argumentName) {
30
32
  // we want to mark this element for future deletion because it is a matching argument name,
@@ -49,7 +51,7 @@ function setArgumentArrays(argumentNames, args) {
49
51
  });
50
52
 
51
53
  // Now that we are done, we want to delete all elements that match the CLI array argument structure
52
- args = args.filter(function(value, index) {
54
+ args = args.filter(function (value, index) {
53
55
  return indexesToRemove.indexOf(index) == -1;
54
56
  });
55
57
 
@@ -85,7 +87,7 @@ function deleteFile(deleteFilePath) {
85
87
  }
86
88
 
87
89
  /**
88
- * Deletes a directory based on the passed parameters.
90
+ * Deletes a directory based on the passed parameters.
89
91
  * Recursively force deletes contents.
90
92
  * @param {string} directoryPath the path to the directory to delete
91
93
  */
@@ -113,23 +115,26 @@ async function downloadFile(downloadUrl, downloadFilePath, downloadName) {
113
115
  }
114
116
 
115
117
  // Download the file
116
- https.get(downloadUrl, getOptions, (res) => {
117
-
118
- // Open file in local filesystem
119
- const file = fs.createWriteStream(path.join(downloadFilePath, downloadName));
120
-
121
- // Write data into local file
122
- res.pipe(file);
123
-
124
- // Close the file
125
- file.on('finish', () => {
118
+ https
119
+ .get(downloadUrl, getOptions, (res) => {
120
+ // Open file in local filesystem
121
+ const file = fs.createWriteStream(
122
+ path.join(downloadFilePath, downloadName)
123
+ );
124
+
125
+ // Write data into local file
126
+ res.pipe(file);
127
+
128
+ // Close the file
129
+ file.on("finish", () => {
126
130
  file.close();
127
131
  resolve();
128
- });
129
- }).on("error", (err) => {
132
+ });
133
+ })
134
+ .on("error", (err) => {
130
135
  console.log("downloadFile failed...");
131
136
  reject(err);
132
- });
137
+ });
133
138
  });
134
139
  }
135
140
 
@@ -143,10 +148,11 @@ async function unzipFile(unzipFileLocation, unzipFileName) {
143
148
  const zipFileLocation = path.join(unzipFileLocation, unzipFileName);
144
149
  try {
145
150
  const zip = new AdmZip(zipFileLocation);
146
- zip.extractAllTo(unzipFileLocation);
151
+ // Overwrite and keepOriginalPermissions
152
+ zip.extractAllTo(unzipFileLocation, true, true);
147
153
  } catch (err) {
148
154
  deleteFile(zipFileLocation);
149
- throw("Something went wrong during unzipping.\nIf you specified a script version, confirm it is correct.\nIf the error continues, contact your OpsCompass rep.");
155
+ throw "Something went wrong during unzipping.\nIf you specified a script version, confirm it is correct.\nIf the error continues, contact your OpsCompass rep.";
150
156
  }
151
157
  }
152
158
 
@@ -160,9 +166,9 @@ function getAllFilesInFolder(dirPath) {
160
166
 
161
167
  var arrayOfFiles = arrayOfFiles || [];
162
168
 
163
- files.forEach(function(file) {
169
+ files.forEach(function (file) {
164
170
  const filePathToCheck = path.join(dirPath, file);
165
- if (fs.lstatSync(filePathToCheck).isDirectory() ) {
171
+ if (fs.lstatSync(filePathToCheck).isDirectory()) {
166
172
  const folderFiles = getAllFilesInFolder(filePathToCheck);
167
173
  arrayOfFiles = arrayOfFiles.concat(folderFiles);
168
174
  } else {
@@ -170,7 +176,7 @@ function getAllFilesInFolder(dirPath) {
170
176
  }
171
177
  });
172
178
 
173
- return arrayOfFiles
179
+ return arrayOfFiles;
174
180
  }
175
181
 
176
182
  /**
@@ -182,7 +188,7 @@ async function moveFolder(sourcePath, destinationPath) {
182
188
  try {
183
189
  await fs.move(sourcePath, destinationPath);
184
190
  } catch (err) {
185
- throw (err);
191
+ throw err;
186
192
  }
187
193
  }
188
194
 
@@ -191,7 +197,7 @@ async function moveFolder(sourcePath, destinationPath) {
191
197
  * @param {string} folderPath the path to the folder to find or create
192
198
  * @returns {string} The path to the found or created folder
193
199
  */
194
- function findOrCreateFolder(folderPath) {
200
+ function findOrCreateFolder(folderPath) {
195
201
  try {
196
202
  fs.accessSync(folderPath);
197
203
  } catch {
@@ -218,12 +224,12 @@ function canReadFile(filePath) {
218
224
 
219
225
  /**
220
226
  * Object that makes file permissions a bit more user friendly.
221
- *
227
+ *
222
228
  * mode 600: the user can read/write (and not execute)
223
229
  * but only the user can interact with the file
224
230
  */
225
231
  const FilePermissions = {
226
- userReadWrite: 600
232
+ userReadWrite: 600,
227
233
  };
228
234
 
229
235
  module.exports = {
@@ -237,5 +243,5 @@ module.exports = {
237
243
  canReadFile,
238
244
  moveFolder,
239
245
  getAllFilesInFolder,
240
- FilePermissions
246
+ FilePermissions,
241
247
  };
@@ -17,6 +17,7 @@ const {
17
17
  FilePermissions,
18
18
  getAllFilesInFolder,
19
19
  } = require("./cliHelpers.js");
20
+ const { nextTick } = require("process");
20
21
 
21
22
  const SRC_FOLDER_NAME = "src";
22
23
  const METADATA_FILE_NAME = "metadata.json";
@@ -167,15 +168,28 @@ async function downloadScriptsToHome(
167
168
  destinationPath
168
169
  );
169
170
 
170
- // Set all files to mode 600, if they are .sh set to 700.
171
+ // File permissions should be set by the pipeline that builds the distribution bundle
172
+ // However, remove them if "other" has permissions - typically want just user and group
171
173
  const allFilePaths = getAllFilesInFolder(destinationPath);
172
174
  allFilePaths.forEach(function (filePath) {
173
- var fileExtension = path.extname(filePath);
174
-
175
- if (fileExtension === ".sh") {
176
- fs.chmodSync(filePath, 0o700);
175
+ // Skip files we don't care about ({hidden}, bat, txt, ...)
176
+ if (path.basename(filePath).match(/^\./)) {
177
+ return;
177
178
  } else {
178
- fs.chmodSync(filePath, 0o600);
179
+ var fileExtension = path.extname(filePath);
180
+ if (fileExtension.match(/bat|txt|pl/)) {
181
+ return;
182
+ }
183
+ }
184
+
185
+ var fileStat = fs.lstatSync(filePath);
186
+ if (fileStat.mode & 0o007) {
187
+ // console.error(
188
+ // "Warning: loose permissions (0o%s) on %s",
189
+ // (fileStat.mode & 0o777).toString(8),
190
+ // filePath
191
+ // );
192
+ fs.chmodSync(filePath, fileStat.mode & 0o770);
179
193
  }
180
194
  });
181
195
 
@@ -419,21 +419,53 @@ const { getCredentials } = require("../credentials.js");
419
419
  console.log();
420
420
  }
421
421
 
422
- async function listBreaches(args) {
423
- for (let i = 0; i < args.length; i++) {
424
- switch (args[i].toLowerCase()) {
425
- case "--company":
426
- callParams.company = args[i+1];
427
- break;
428
- }
429
- }
430
-
431
-
432
- const client = await getOpsCompassClient();
433
- const response = await client.compliance.listBreaches(callParams.company);
434
-
435
- console.log(JSON.stringify(response, null, 2));
436
- }
422
+ async function listBreaches(args) {
423
+ for (let i = 0; i < args.length; i++) {
424
+ switch (args[i].toLowerCase()) {
425
+ case "--company":
426
+ callParams.company = args[i+1];
427
+ break;
428
+ }
429
+ }
430
+
431
+
432
+ const client = await getOpsCompassClient();
433
+ const response = await client.compliance.listBreaches(callParams.company);
434
+
435
+ console.log(JSON.stringify(response, null, 2));
436
+ }
437
+
438
+ async function listBreachedEmails(args) {
439
+ for (let i = 0; i < args.length; i++) {
440
+ switch (args[i].toLowerCase()) {
441
+ case "--company":
442
+ callParams.company = args[i+1];
443
+ break;
444
+ }
445
+ }
446
+
447
+
448
+ const client = await getOpsCompassClient();
449
+ const response = await client.compliance.listBreachedEmails(callParams.company);
450
+
451
+ console.log(JSON.stringify(response, null, 2));
452
+ }
453
+
454
+ async function listBreachedEmailsOfConcern(args) {
455
+ for (let i = 0; i < args.length; i++) {
456
+ switch (args[i].toLowerCase()) {
457
+ case "--company":
458
+ callParams.company = args[i+1];
459
+ break;
460
+ }
461
+ }
462
+
463
+
464
+ const client = await getOpsCompassClient();
465
+ const response = await client.compliance.listBreachedEmailsOfConcern(callParams.company);
466
+
467
+ console.log(JSON.stringify(response, null, 2));
468
+ }
437
469
 
438
470
 
439
471
  async function printHelp() {
@@ -545,7 +577,15 @@ const { getCredentials } = require("../credentials.js");
545
577
  console.log("--expires-at (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.");
546
578
  console.log("Format: UTC, example: '2022-08-23T17:00:00Z' to expire August 8th, 2022 at 17:00 UTC.");
547
579
  console.log();
548
- console.log("list-breaches", "Retrieves the list of breaches company emails have been involved in");
580
+ console.log("list-breaches", "Retrieves the list of breaches company emails have been involved in.");
581
+ console.log("Parameters:");
582
+ console.log("--company [company_slug]");
583
+ console.log();
584
+ console.log("list-breached-emails", "Retrieves the list of breached emails associated with a provided company");
585
+ console.log("Parameters:");
586
+ console.log("--company [company_slug]");
587
+ console.log();
588
+ console.log("list-breached-emails-of-concern", "Retrieves the list of breached emails that have not performed a password reset since a data breach.");
549
589
  console.log("Parameters:");
550
590
  console.log("--company [company_slug]");
551
591
  console.log();
@@ -586,6 +626,10 @@ const { getCredentials } = require("../credentials.js");
586
626
  return createComplianceResourceCheckException(args);
587
627
  case "list-breaches":
588
628
  return listBreaches(args);
629
+ case "list-breached-emails":
630
+ return listBreachedEmails(args);
631
+ case "list-breached-emails-of-concern":
632
+ return listBreachedEmailsOfConcern(args);
589
633
  case "help":
590
634
  case "":
591
635
  return printHelp();