Skip to content

Commit f3ad28a

Browse files
authored
Merge pull request #75 from snyk-tech-services/develop
release changes
2 parents 0e9a1ae + a1abb0b commit f3ad28a

File tree

7 files changed

+2049
-546
lines changed

7 files changed

+2049
-546
lines changed

lib/snyk-display.js

Lines changed: 92 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,77 @@ const chalk = require("chalk");
55

66
var ROOT = "https://snyk.io";
77

8-
module.exports = { displayResult: displayResult };
8+
module.exports = {
9+
displayResult: displayResult,
10+
displayIACResult: displayIACResult,
11+
};
12+
13+
function displayIACResult(res, options, originalData) {
14+
debug("options: " + options);
15+
16+
var meta = metaForIACDisplay(res, options, originalData) + "\n\n";
17+
18+
var interIssueSep = `\n\n-----\n`;
19+
var summary = `Tested ${originalData.projectName} ${originalData.targetFile}/${originalData.projectType} for known issues\n`;
20+
21+
// handle errors by extracting their message
22+
if (res instanceof Error) {
23+
return res.message;
24+
}
25+
26+
if (res.length === 0) {
27+
summary += chalk.green("✓ No issues found");
28+
29+
if (options.severityThreshold) {
30+
summary += chalk.yellow(
31+
"\n\nCAUTION! Your severity setting might have hidden some issues below the threshold chosen. Make sure to review the unfiltered results."
32+
);
33+
}
34+
35+
return (
36+
chalk.bold("Testing " + options.path + "...\n") +
37+
meta +
38+
summary +
39+
interIssueSep
40+
);
41+
}
42+
43+
var count = `found ${res.length} issues `;
44+
45+
summary += chalk.red.bold(count);
46+
47+
var sep = "\n\n";
48+
49+
var issues = res;
50+
51+
var body =
52+
(issues || [])
53+
.map(function (issue) {
54+
var res = "";
55+
var name = issue.title;
56+
var severity = issue.severity.toUpperCase();
57+
res += chalk.red(
58+
"✗ " + severity + " severity issue found on " + name + "\n"
59+
);
60+
res += "- issue: " + issue.iacDescription.issue + "\n";
61+
res += "- impact: " + issue.iacDescription.impact + "\n";
62+
res += `- info: ${issue.id} of ${issue.subType}/${issue.type} type\n`;
63+
res += `- resolution: ${issue.iacDescription.resolve} \n`;
64+
65+
res += `- path: ${issue.path.join("=>")}\n`;
66+
res += `- line number: ${issue.lineNumber}`;
67+
68+
return res;
69+
})
70+
.filter(Boolean)
71+
.join(sep) +
72+
sep +
73+
meta +
74+
summary +
75+
interIssueSep;
76+
77+
return chalk.bold("\nTesting " + options.path + "...\n") + body;
78+
}
979

1080
function displayResult(res, options) {
1181
debug("options: " + options);
@@ -209,3 +279,24 @@ function metaForDisplay(res, options) {
209279

210280
return meta.join("\n");
211281
}
282+
283+
function metaForIACDisplay(res, options, originalData) {
284+
var meta = [
285+
chalk.bold("Organisation: ") + originalData.org,
286+
// chalk.bold('Package manager: ') +
287+
// (options.packageManager | res.packageManager),
288+
//chalk.bold('Target file: ') + options.file,
289+
//chalk.bold('Open source: ') + (res.isPrivate ? 'no' : 'yes'),
290+
];
291+
if (originalData.filesystemPolicy) {
292+
meta.push("Local Snyk policy found");
293+
if (
294+
originalData.ignoreSettings &&
295+
originalData.ignoreSettings.disregardFilesystemIgnores
296+
) {
297+
meta.push("Local Snyk policy ignores disregarded");
298+
}
299+
}
300+
301+
return meta.join("\n");
302+
}

lib/snyk-filter.js

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ const yaml = require("js-yaml");
44
const fs = require("fs");
55
const path = require("path");
66
const jq = require("node-jq");
7+
const chalk = require("chalk");
78

89
var snykDisplay = require("./snyk-display.js");
910
var customFilters; // = require('../sample-filters/filters.json');
@@ -23,7 +24,6 @@ function onDataCallback(data, reportCallback) {
2324
const jqFilterString = customFilters.filter;
2425
const jqPassString = customFilters.pass;
2526
const failMsg = customFilters.msg;
26-
2727
data = JSON.parse(data);
2828
if (Array.isArray(data)) {
2929
data.map((dataItem) => {
@@ -77,7 +77,6 @@ function run(source, reportCallback, filters, cliOptions = null) {
7777
readInputFromStdin(reportCallback);
7878
}
7979
} catch (error) {
80-
console.log("out");
8180
debug("error reading input: " + error);
8281
}
8382
}
@@ -87,10 +86,16 @@ function processResults(data, filterString, passString, failMsg) {
8786
//.then((filteredData) => aggregate(filteredData))
8887
//.then((processedData) => {reportCallback(processedData)})
8988
.then((processedData) => {
90-
//console.log(processedData);
9189
if (options && options.json) {
9290
console.warn("json output enabled");
9391
console.log(JSON.stringify(processedData, null, 2));
92+
} else if (data.infrastructureAsCodeIssues) {
93+
var response = snykDisplay.displayIACResult(
94+
processedData,
95+
options,
96+
data
97+
);
98+
console.log(response);
9499
} else {
95100
var response = snykDisplay.displayResult(processedData, options);
96101
console.log(response);
@@ -115,7 +120,6 @@ function filter(data, filterString) {
115120
//const filter = 'select(.vulnerabilities | map( select(.packageName | contains("bson") | not)))';
116121
const filter = filterString;
117122
const options = { input: "json", output: "json" };
118-
119123
jq.run(filter, data, options)
120124
.then((output) => {
121125
resolve(output);
@@ -150,10 +154,16 @@ function pass(data, passString, passFailMsg) {
150154
jq.run(query, data, options)
151155
.then((output) => {
152156
if (output == 0) {
153-
console.warn("No issues found after custom filtering");
157+
console.warn(
158+
`${chalk.yellow(
159+
data.projectName || data.path
160+
)} - No issues found after custom filtering`
161+
);
154162
resolve(true);
155163
} else {
156-
reject(passFailMsg);
164+
reject(
165+
`${chalk.yellow(data.projectName || data.path)} - ${passFailMsg}`
166+
);
157167
}
158168
})
159169
.catch((err) => {

0 commit comments

Comments
 (0)