@@ -5,7 +5,77 @@ const chalk = require("chalk");
5
5
6
6
var ROOT = "https://snyk.io" ;
7
7
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
+ }
9
79
10
80
function displayResult ( res , options ) {
11
81
debug ( "options: " + options ) ;
@@ -209,3 +279,24 @@ function metaForDisplay(res, options) {
209
279
210
280
return meta . join ( "\n" ) ;
211
281
}
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
+ }
0 commit comments