mobbdev 0.0.6 → 0.0.7
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/package.json +2 -1
- package/src/snyk.mjs +56 -15
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mobbdev",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.7",
|
|
4
4
|
"description": "Automated secure code remediation tool",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -15,6 +15,7 @@
|
|
|
15
15
|
"author": "",
|
|
16
16
|
"license": "MIT",
|
|
17
17
|
"dependencies": {
|
|
18
|
+
"colors": "1.4.0",
|
|
18
19
|
"configstore": "6.0.0",
|
|
19
20
|
"dotenv": "16.0.3",
|
|
20
21
|
"extract-zip": "2.0.1",
|
package/src/snyk.mjs
CHANGED
|
@@ -1,41 +1,82 @@
|
|
|
1
1
|
import cp from 'node:child_process';
|
|
2
2
|
import { createRequire } from 'node:module';
|
|
3
|
+
import readline from 'node:readline';
|
|
4
|
+
import { stdout } from 'colors/lib/system/supports-colors.js';
|
|
5
|
+
import open from 'open';
|
|
6
|
+
import * as process from 'process';
|
|
3
7
|
|
|
4
8
|
const require = createRequire(import.meta.url);
|
|
5
9
|
const SNYK_PATH = require.resolve('snyk/bin/snyk');
|
|
6
10
|
|
|
7
|
-
async function forkSnyk(args,
|
|
11
|
+
async function forkSnyk(args, display) {
|
|
8
12
|
return new Promise((resolve, reject) => {
|
|
9
13
|
const child = cp.fork(SNYK_PATH, args, {
|
|
10
|
-
stdio,
|
|
14
|
+
stdio: ['inherit', 'pipe', 'pipe', 'ipc'],
|
|
15
|
+
env: { FORCE_COLOR: stdout.level },
|
|
11
16
|
});
|
|
12
17
|
let out = '';
|
|
18
|
+
const onData = (chunk) => {
|
|
19
|
+
out += chunk;
|
|
20
|
+
};
|
|
13
21
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
22
|
+
child.stdout.on('data', onData);
|
|
23
|
+
child.stderr.on('data', onData);
|
|
24
|
+
|
|
25
|
+
if (display) {
|
|
26
|
+
child.stdout.pipe(process.stdout);
|
|
27
|
+
child.stderr.pipe(process.stderr);
|
|
18
28
|
}
|
|
19
29
|
|
|
20
30
|
child.on('exit', () => {
|
|
21
31
|
resolve(out);
|
|
22
32
|
});
|
|
33
|
+
child.on('error', (err) => {
|
|
34
|
+
reject(err);
|
|
35
|
+
});
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
async function question(questionString) {
|
|
40
|
+
const rl = readline.createInterface({
|
|
41
|
+
input: process.stdin,
|
|
42
|
+
output: process.stdout,
|
|
43
|
+
});
|
|
23
44
|
|
|
24
|
-
|
|
45
|
+
return new Promise((resolve) => {
|
|
46
|
+
rl.question(`${questionString} `, (answer) => {
|
|
47
|
+
rl.close();
|
|
48
|
+
resolve(answer);
|
|
49
|
+
});
|
|
25
50
|
});
|
|
26
51
|
}
|
|
27
52
|
|
|
28
53
|
export async function getSnykReport(reportPath, repoRoot) {
|
|
29
|
-
const config = await forkSnyk(['config'],
|
|
54
|
+
const config = await forkSnyk(['config'], false);
|
|
30
55
|
|
|
31
56
|
if (!config.includes('api: ')) {
|
|
32
|
-
await forkSnyk(['auth']);
|
|
57
|
+
await forkSnyk(['auth'], true);
|
|
33
58
|
}
|
|
34
59
|
|
|
35
|
-
await forkSnyk(
|
|
36
|
-
'code',
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
60
|
+
const out = await forkSnyk(
|
|
61
|
+
['code', 'test', `--sarif-file-output=${reportPath}`, repoRoot],
|
|
62
|
+
true
|
|
63
|
+
);
|
|
64
|
+
|
|
65
|
+
if (
|
|
66
|
+
out.includes(
|
|
67
|
+
'Snyk Code is not supported for org: enable in Settings > Snyk Code'
|
|
68
|
+
)
|
|
69
|
+
) {
|
|
70
|
+
const answer = await question(
|
|
71
|
+
"Do you want to be taken to the relevant Snyk's online article? (Y/N)"
|
|
72
|
+
);
|
|
73
|
+
|
|
74
|
+
if (['y', 'yes', ''].includes(answer.toLowerCase())) {
|
|
75
|
+
await open(
|
|
76
|
+
'https://docs.snyk.io/scan-application-code/snyk-code/getting-started-with-snyk-code/activating-snyk-code-using-the-web-ui/step-1-enabling-the-snyk-code-option'
|
|
77
|
+
);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
process.exit(0);
|
|
81
|
+
}
|
|
41
82
|
}
|