mobbdev 0.0.48 → 0.0.50

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/dist/index.mjs CHANGED
@@ -756,12 +756,15 @@ import chalk from "chalk";
756
756
  import Debug6 from "debug";
757
757
  import { existsSync } from "fs";
758
758
  import { createSpinner as createSpinner2 } from "nanospinner";
759
+ import { type } from "os";
759
760
  import path4 from "path";
760
761
  var debug5 = Debug6("mobbdev:checkmarx");
761
762
  var require2 = createRequire(import.meta.url);
762
763
  var getCheckmarxPath = () => {
764
+ const os3 = type();
765
+ const cxFileName = os3 === "Windows_NT" ? "cx.exe" : "cx";
763
766
  try {
764
- return require2.resolve(".bin/cx");
767
+ return require2.resolve(`.bin/${cxFileName}`);
765
768
  } catch (e) {
766
769
  throw new CliError(cxOperatingSystemSupportMessage);
767
770
  }
@@ -802,7 +805,7 @@ async function forkCheckmarx(args, { display }) {
802
805
  { display }
803
806
  );
804
807
  }
805
- async function getCheckmarxReport({ reportPath, repositoryRoot, branch }, { skipPrompts = false }) {
808
+ async function getCheckmarxReport({ reportPath, repositoryRoot, branch, projectName }, { skipPrompts = false }) {
806
809
  debug5("get checkmarx report start %s %s", reportPath, repositoryRoot);
807
810
  const { code: loginCode } = await forkCheckmarx(VALIDATE_COMMAND, {
808
811
  display: false
@@ -822,7 +825,7 @@ async function getCheckmarxReport({ reportPath, repositoryRoot, branch }, { skip
822
825
  branch,
823
826
  filePath,
824
827
  fileName,
825
- projectName: "mobb_dev"
828
+ projectName
826
829
  });
827
830
  console.log("\u280B \u{1F50D} Initiating Checkmarx Scan ");
828
831
  const { code: scanCode } = await forkCheckmarx(
@@ -852,7 +855,7 @@ async function validateCheckamxCredentials() {
852
855
  Here's a suggestion for checkmarx configuation:
853
856
  ${chalk.bold("AST Base URI:")} https://ast.checkmarx.net
854
857
  ${chalk.bold("AST Base Auth URI (IAM):")} https://iam.checkmarx.net
855
- `);
858
+ `);
856
859
  await forkCheckmarx(CONFIGURE_COMMAND, { display: true });
857
860
  const { code: loginCode } = await forkCheckmarx(VALIDATE_COMMAND, {
858
861
  display: false
@@ -2149,7 +2152,8 @@ async function _scan({
2149
2152
  srcPath,
2150
2153
  commitHash,
2151
2154
  ref,
2152
- scanner
2155
+ scanner,
2156
+ cxProjectName
2153
2157
  }, { skipPrompts = false } = {}) {
2154
2158
  debug8("start %s %s", dirname, repo);
2155
2159
  const { createSpinner: createSpinner4 } = Spinner2({ ci });
@@ -2257,8 +2261,16 @@ async function _scan({
2257
2261
  await getSnykReport(reportPath2, repositoryRoot, { skipPrompts });
2258
2262
  break;
2259
2263
  case "checkmarx":
2264
+ if (!cxProjectName) {
2265
+ throw new Error("cxProjectName is required for checkmarx scanner");
2266
+ }
2260
2267
  await getCheckmarxReport(
2261
- { reportPath: reportPath2, repositoryRoot, branch: reference },
2268
+ {
2269
+ reportPath: reportPath2,
2270
+ repositoryRoot,
2271
+ branch: reference,
2272
+ projectName: cxProjectName
2273
+ },
2262
2274
  { skipPrompts }
2263
2275
  );
2264
2276
  break;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mobbdev",
3
- "version": "0.0.48",
3
+ "version": "0.0.50",
4
4
  "description": "Automated secure code remediation tool",
5
5
  "repository": "https://github.com/mobb-dev/bugsy",
6
6
  "main": "dist/index.js",
@@ -1,30 +1,65 @@
1
1
  // this file is based from 'binary-install' https://www.npmjs.com/package/binary-install
2
+ import AdmZip from 'adm-zip'
2
3
  import axios from 'axios'
3
4
  import { existsSync, mkdirSync } from 'fs'
4
5
  import { arch as _arch, type as _type } from 'os'
5
6
  import { join } from 'path'
6
7
  import tar from 'tar'
7
8
 
8
- const __dirname = process.env['PWD']
9
+ /**
10
+ * Options for showing a installParams.
11
+ * @typedef {Object} InstallParams
12
+ * @property {string} installParams.binaryName
13
+ * @property {string} installParams.url
14
+ */
15
+
16
+ /**
17
+ * @param {string} url
18
+ * @returns {string}
19
+ */
20
+ function getArchiveType(url) {
21
+ if (url.endsWith('.zip')) {
22
+ return 'zip'
23
+ }
24
+ if (url.endsWith('.tar.gz')) {
25
+ return 'tar'
26
+ }
27
+ throw Error(`Unknown archive type for ${url}`)
28
+ }
9
29
 
10
30
  /**
11
- * @param {Object} installParams
12
- * @param {string} installParams.binaryName
13
- * @param {string} installParams.url
31
+ * @param {InstallParams} opts
14
32
  * @returns {Promise<void>}
15
33
  */
34
+
16
35
  export async function install({ binaryName, url }) {
17
- if (!__dirname) {
18
- throw Error('pwd is undefiled')
19
- }
20
- const installDirectory = join(__dirname, 'node_modules', '.bin')
36
+ const installDirectory = join(process.cwd(), 'node_modules', '.bin')
21
37
  const binaryPath = join(installDirectory, binaryName)
22
38
  if (existsSync(binaryPath)) {
23
39
  console.log(`${binaryName} is already installed, skipping installation.`)
24
40
  return
25
41
  }
42
+ const archiveType = getArchiveType(url)
26
43
  mkdirSync(installDirectory, { recursive: true })
27
44
  console.log(`Downloading release from ${url}`)
45
+ archiveType === 'zip'
46
+ ? installZip({ binaryName, url, installDirectory })
47
+ : installTar({ binaryName, url, installDirectory })
48
+
49
+ console.log(`${binaryName} has been installed!`)
50
+ }
51
+
52
+ /**
53
+ * @typedef {object} InstallDirectory
54
+ * @property {string} installDirectory
55
+ * @typedef {InstallParams & InstallDirectory} ArchiveInstallParams
56
+ **/
57
+
58
+ /**
59
+ * @param {ArchiveInstallParams} opts
60
+ * @returns {Promise<void>}
61
+ */
62
+ async function installTar({ binaryName, url, installDirectory }) {
28
63
  const binaryStream = await axios({ url, responseType: 'stream' })
29
64
  await new Promise((resolve, reject) => {
30
65
  const sink = binaryStream.data.pipe(
@@ -38,5 +73,17 @@ export async function install({ binaryName, url }) {
38
73
  sink.on('finish', () => resolve(null))
39
74
  sink.on('error', (/** @type {Error} */ err) => reject(err))
40
75
  })
41
- console.log(`${binaryName} has been installed!`)
76
+ }
77
+
78
+ /**
79
+ * @param {ArchiveInstallParams} opts
80
+ * @returns {Promise<void>}
81
+ */
82
+ async function installZip({ binaryName, url, installDirectory }) {
83
+ const body = await axios.get(url, {
84
+ responseType: 'arraybuffer',
85
+ })
86
+
87
+ var zip = new AdmZip(body.data)
88
+ zip.extractEntryTo(binaryName, installDirectory)
42
89
  }
@@ -43,7 +43,7 @@ function installBinary() {
43
43
  const { target } = supportedPlatform
44
44
 
45
45
  const url = `https://github.com/Checkmarx/ast-cli/releases/download/2.0.55/ast-cli_${target}`
46
- const binaryName = 'cx'
46
+ const binaryName = supportedPlatform.type === 'Windows_NT' ? 'cx.exe' : 'cx'
47
47
 
48
48
  install({ binaryName, url })
49
49
  }