@contrast/contrast 1.0.3 → 1.0.6

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.
Files changed (107) hide show
  1. package/.prettierignore +4 -0
  2. package/README.md +20 -14
  3. package/dist/audit/autodetection/autoDetectLanguage.js +32 -0
  4. package/dist/audit/catalogueApplication/catalogueApplication.js +2 -11
  5. package/dist/audit/languageAnalysisEngine/{langugageAnalysisFactory.js → languageAnalysisFactory.js} +6 -14
  6. package/dist/audit/languageAnalysisEngine/reduceIdentifiedLanguages.js +29 -0
  7. package/dist/audit/languageAnalysisEngine/report/commonReportingFunctions.js +101 -234
  8. package/dist/audit/languageAnalysisEngine/report/models/reportLibraryModel.js +19 -0
  9. package/dist/audit/languageAnalysisEngine/report/models/reportListModel.js +24 -0
  10. package/dist/audit/languageAnalysisEngine/report/models/reportOutputModel.js +24 -0
  11. package/dist/audit/languageAnalysisEngine/report/models/reportSeverityModel.js +12 -0
  12. package/dist/audit/languageAnalysisEngine/report/models/severityCountModel.js +13 -0
  13. package/dist/audit/languageAnalysisEngine/report/reportingFeature.js +24 -129
  14. package/dist/audit/languageAnalysisEngine/report/utils/reportUtils.js +99 -0
  15. package/dist/audit/languageAnalysisEngine/sendSnapshot.js +2 -14
  16. package/dist/commands/audit/auditConfig.js +8 -2
  17. package/dist/commands/audit/auditController.js +14 -5
  18. package/dist/commands/scan/processScan.js +10 -6
  19. package/dist/commands/scan/sca/scaAnalysis.js +49 -0
  20. package/dist/common/HTTPClient.js +18 -26
  21. package/dist/common/errorHandling.js +7 -17
  22. package/dist/common/versionChecker.js +14 -12
  23. package/dist/constants/constants.js +24 -2
  24. package/dist/constants/lambda.js +3 -1
  25. package/dist/constants/locales.js +42 -42
  26. package/dist/constants.js +25 -1
  27. package/dist/index.js +2 -2
  28. package/dist/lambda/help.js +22 -14
  29. package/dist/lambda/lambda.js +6 -0
  30. package/dist/scaAnalysis/common/formatMessage.js +19 -0
  31. package/dist/scaAnalysis/common/treeUpload.js +29 -0
  32. package/dist/scaAnalysis/go/goAnalysis.js +17 -0
  33. package/dist/scaAnalysis/go/goParseDeps.js +158 -0
  34. package/dist/scaAnalysis/go/goReadDepFile.js +23 -0
  35. package/dist/scaAnalysis/java/analysis.js +108 -0
  36. package/dist/scaAnalysis/java/index.js +18 -0
  37. package/dist/scaAnalysis/java/javaBuildDepsParser.js +339 -0
  38. package/dist/scan/autoDetection.js +46 -1
  39. package/dist/scan/fileUtils.js +73 -1
  40. package/dist/scan/formatScanOutput.js +215 -0
  41. package/dist/scan/help.js +3 -1
  42. package/dist/scan/models/groupedResultsModel.js +11 -0
  43. package/dist/scan/models/resultContentModel.js +2 -0
  44. package/dist/scan/models/scanResultsModel.js +11 -0
  45. package/dist/scan/scan.js +27 -126
  46. package/dist/scan/scanConfig.js +1 -1
  47. package/dist/scan/scanController.js +11 -5
  48. package/dist/scan/scanResults.js +15 -19
  49. package/dist/utils/getConfig.js +3 -0
  50. package/dist/utils/oraWrapper.js +5 -1
  51. package/package.json +3 -2
  52. package/src/audit/autodetection/autoDetectLanguage.ts +40 -0
  53. package/src/audit/catalogueApplication/catalogueApplication.js +4 -16
  54. package/src/audit/languageAnalysisEngine/{langugageAnalysisFactory.js → languageAnalysisFactory.js} +11 -21
  55. package/src/audit/languageAnalysisEngine/reduceIdentifiedLanguages.js +72 -0
  56. package/src/audit/languageAnalysisEngine/report/commonReportingFunctions.ts +204 -0
  57. package/src/audit/languageAnalysisEngine/report/models/reportLibraryModel.ts +30 -0
  58. package/src/audit/languageAnalysisEngine/report/models/reportListModel.ts +32 -0
  59. package/src/audit/languageAnalysisEngine/report/models/reportOutputModel.ts +29 -0
  60. package/src/audit/languageAnalysisEngine/report/models/reportSeverityModel.ts +13 -0
  61. package/src/audit/languageAnalysisEngine/report/models/severityCountModel.ts +16 -0
  62. package/src/audit/languageAnalysisEngine/report/reportingFeature.ts +56 -0
  63. package/src/audit/languageAnalysisEngine/report/utils/reportUtils.ts +116 -0
  64. package/src/audit/languageAnalysisEngine/sendSnapshot.js +2 -22
  65. package/src/commands/audit/auditConfig.ts +12 -3
  66. package/src/commands/audit/auditController.ts +20 -5
  67. package/src/commands/audit/processAudit.ts +3 -0
  68. package/src/commands/scan/processScan.js +13 -9
  69. package/src/commands/scan/sca/scaAnalysis.js +75 -0
  70. package/src/common/HTTPClient.js +31 -38
  71. package/src/common/errorHandling.ts +7 -25
  72. package/src/common/versionChecker.ts +24 -22
  73. package/src/constants/constants.js +24 -2
  74. package/src/constants/lambda.js +3 -1
  75. package/src/constants/locales.js +47 -56
  76. package/src/constants.js +29 -1
  77. package/src/index.ts +2 -3
  78. package/src/lambda/help.ts +22 -14
  79. package/src/lambda/lambda.ts +8 -0
  80. package/src/scaAnalysis/common/formatMessage.js +20 -0
  81. package/src/scaAnalysis/common/treeUpload.js +30 -0
  82. package/src/scaAnalysis/go/goAnalysis.js +20 -0
  83. package/src/scaAnalysis/go/goParseDeps.js +203 -0
  84. package/src/scaAnalysis/go/goReadDepFile.js +32 -0
  85. package/src/scaAnalysis/java/analysis.js +143 -0
  86. package/src/scaAnalysis/java/index.js +21 -0
  87. package/src/scaAnalysis/java/javaBuildDepsParser.js +404 -0
  88. package/src/scan/autoDetection.js +54 -1
  89. package/src/scan/fileUtils.js +91 -1
  90. package/src/scan/formatScanOutput.ts +250 -0
  91. package/src/scan/help.js +3 -1
  92. package/src/scan/models/groupedResultsModel.ts +20 -0
  93. package/src/scan/models/resultContentModel.ts +86 -0
  94. package/src/scan/models/scanResultsModel.ts +52 -0
  95. package/src/scan/scan.ts +63 -0
  96. package/src/scan/scanConfig.js +1 -1
  97. package/src/scan/scanController.js +15 -7
  98. package/src/scan/scanResults.js +21 -18
  99. package/src/utils/getConfig.ts +10 -0
  100. package/src/utils/oraWrapper.js +6 -1
  101. package/dist/audit/languageAnalysisEngine/report/checkIgnoreDevDep.js +0 -17
  102. package/dist/audit/languageAnalysisEngine/report/newReportingFeature.js +0 -81
  103. package/src/audit/languageAnalysisEngine/report/checkIgnoreDevDep.js +0 -27
  104. package/src/audit/languageAnalysisEngine/report/commonReportingFunctions.js +0 -303
  105. package/src/audit/languageAnalysisEngine/report/newReportingFeature.js +0 -124
  106. package/src/audit/languageAnalysisEngine/report/reportingFeature.js +0 -190
  107. package/src/scan/scan.js +0 -195
@@ -0,0 +1,203 @@
1
+ const crypto = require('crypto')
2
+
3
+ const parseGoDependencies = goDeps => {
4
+ return parseGo(goDeps)
5
+ }
6
+
7
+ const parseGo = modGraphOutput => {
8
+ let splitLines = splitAllLinesIntoArray(modGraphOutput)
9
+ const directDepNames = getDirectDepNames(splitLines)
10
+ const uniqueTransitiveDepNames = getAllUniqueTransitiveDepNames(
11
+ splitLines,
12
+ directDepNames
13
+ )
14
+
15
+ let rootNodes = createRootNodes(splitLines)
16
+
17
+ createTransitiveDeps(uniqueTransitiveDepNames, splitLines, rootNodes)
18
+
19
+ return rootNodes
20
+ }
21
+
22
+ const splitAllLinesIntoArray = modGraphOutput => {
23
+ return modGraphOutput.split(/\r\n|\r|\n/)
24
+ }
25
+
26
+ const getAllDepsOfADepAsEdge = (dep, deps) => {
27
+ let edges = {}
28
+
29
+ const depRows = deps.filter(line => {
30
+ return line.startsWith(dep)
31
+ })
32
+
33
+ depRows.forEach(dep => {
34
+ const edgeName = dep.split(' ')[1]
35
+ edges[edgeName] = edgeName
36
+ })
37
+
38
+ return edges
39
+ }
40
+
41
+ const getAllDepsOfADepAsName = (dep, deps) => {
42
+ let edges = []
43
+
44
+ const depRows = deps.filter(line => {
45
+ return line.startsWith(dep)
46
+ })
47
+
48
+ depRows.forEach(dep => {
49
+ const edgeName = dep.split(' ')[1]
50
+ edges.push(edgeName)
51
+ })
52
+
53
+ return edges
54
+ }
55
+
56
+ const createRootNodes = deps => {
57
+ let rootDep = {}
58
+ const rootDeps = getRootDeps(deps)
59
+
60
+ const edges = rootDeps.map(dep => {
61
+ return dep.split(' ')[1]
62
+ })
63
+
64
+ rootDep[rootDeps[0].split(' ')[0]] = {}
65
+
66
+ edges.forEach(edge => {
67
+ const splitEdge = edge.split('@')
68
+ const splitGroupName = splitEdge[0].split('/')
69
+ const name = splitGroupName.pop()
70
+ const lastSlash = splitEdge[0].lastIndexOf('/')
71
+ let group = splitEdge[0].substring(0, lastSlash)
72
+ const hash = getHash(splitEdge[0])
73
+
74
+ group = checkGroupExists(group, name)
75
+
76
+ //get the edges of the root dependency
77
+ const edgesOfDep = getAllDepsOfADepAsEdge(edge, deps)
78
+
79
+ rootDep[rootDeps[0].split(' ')[0]][edge] = {
80
+ artifactID: name,
81
+ group: group,
82
+ version: splitEdge[1],
83
+ scope: '"compile',
84
+ type: 'direct',
85
+ hash: hash,
86
+ edges: edgesOfDep
87
+ }
88
+ })
89
+ return rootDep
90
+ }
91
+
92
+ const getRootDeps = deps => {
93
+ const rootDeps = deps.filter(dep => {
94
+ const parentDep = dep.split(' ')[0]
95
+ if (parentDep.split('@v').length === 1) {
96
+ return dep
97
+ }
98
+ })
99
+ return rootDeps
100
+ }
101
+
102
+ const getHash = library => {
103
+ let shaSum = crypto.createHash('sha1')
104
+ shaSum.update(library)
105
+ return shaSum.digest('hex')
106
+ }
107
+
108
+ const getDirectDepNames = deps => {
109
+ const directDepNames = []
110
+
111
+ deps.forEach(dep => {
112
+ const parentDep = dep.split(' ')[0]
113
+ if (parentDep.split('@v').length === 1) {
114
+ dep.split(' ')[1] !== undefined
115
+ ? directDepNames.push(dep.split(' ')[1])
116
+ : null
117
+ }
118
+ })
119
+ return directDepNames
120
+ }
121
+
122
+ const getAllUniqueTransitiveDepNames = (deps, directDepNames) => {
123
+ let uniqueDeps = []
124
+
125
+ deps.forEach(dep => {
126
+ const parentDep = dep.split(' ')[0]
127
+ if (parentDep.split('@v').length !== 1) {
128
+ if (!directDepNames.includes(parentDep)) {
129
+ if (!uniqueDeps.includes(parentDep)) {
130
+ parentDep.length > 1 ? uniqueDeps.push(parentDep) : null
131
+ }
132
+ }
133
+ }
134
+ })
135
+ return uniqueDeps
136
+ }
137
+
138
+ const checkGroupExists = (group, name) => {
139
+ if (group === null || group === '') {
140
+ return name
141
+ }
142
+ return group
143
+ }
144
+
145
+ const createTransitiveDeps = (transitiveDeps, splitLines, rootNodes) => {
146
+ transitiveDeps.forEach(dep => {
147
+ //create transitive dep
148
+ const splitEdge = dep.split('@')
149
+ const splitGroupName = splitEdge[0].split('/')
150
+ const name = splitGroupName.pop()
151
+ const lastSlash = splitEdge[0].lastIndexOf('/')
152
+ let group = splitEdge[0].substring(0, lastSlash)
153
+ const hash = getHash(splitEdge[0])
154
+
155
+ group = checkGroupExists(group, name)
156
+
157
+ const transitiveDep = {
158
+ artifactID: name,
159
+ group: group,
160
+ version: splitEdge[1],
161
+ scope: 'compile',
162
+ type: 'transitive',
163
+ hash: hash,
164
+ edges: {}
165
+ }
166
+
167
+ //add edges to transitiveDep
168
+ const edges = getAllDepsOfADepAsEdge(dep, splitLines)
169
+ transitiveDep.edges = edges
170
+
171
+ //add all edges as a transitive dependency to rootNodes
172
+ const edgesAsName = getAllDepsOfADepAsName(dep, splitLines)
173
+
174
+ edgesAsName.forEach(dep => {
175
+ const splitEdge = dep.split('@')
176
+ const splitGroupName = splitEdge[0].split('/')
177
+ const name = splitGroupName.pop()
178
+ const lastSlash = splitEdge[0].lastIndexOf('/')
179
+ let group = splitEdge[0].substring(0, lastSlash)
180
+ const hash = getHash(splitEdge[0])
181
+
182
+ group = checkGroupExists(group, name)
183
+
184
+ const transitiveDep = {
185
+ artifactID: name,
186
+ group: group,
187
+ version: splitEdge[1],
188
+ scope: 'compile',
189
+ type: 'transitive',
190
+ hash: hash,
191
+ edges: {}
192
+ }
193
+ rootNodes[Object.keys(rootNodes)[0]][dep] = transitiveDep
194
+ })
195
+
196
+ //add transitive dependency to rootNodes
197
+ rootNodes[Object.keys(rootNodes)[0]][dep] = transitiveDep
198
+ })
199
+ }
200
+
201
+ module.exports = {
202
+ parseGoDependencies
203
+ }
@@ -0,0 +1,32 @@
1
+ const child_process = require('child_process')
2
+ const i18n = require('i18n')
3
+
4
+ const getGoDependencies = config => {
5
+ let cmdStdout
6
+ let cwd = config.projectPath
7
+ ? config.projectPath.replace('go.mod', '')
8
+ : process.cwd()
9
+
10
+ try {
11
+ // A sample of this output can be found
12
+ // in the go test folder data/goModGraphResults.text
13
+ cmdStdout = child_process.execSync('go mod graph', { cwd })
14
+
15
+ return cmdStdout.toString()
16
+ } catch (err) {
17
+ if (err.message === 'spawnSync /bin/sh ENOENT') {
18
+ err.message =
19
+ '\n\n*************** No transitive dependencies ***************\n\nWe are unable to build a dependency tree view from your repository as there were no transitive dependencies found.'
20
+ }
21
+ console.log(
22
+ i18n.__('goReadProjectFile', cwd, `${err.message ? err.message : ''}`)
23
+ )
24
+ // throw new Error(
25
+ // i18n.__('goReadProjectFile', cwd, `${err.message ? err.message : ''}`)
26
+ // )
27
+ }
28
+ }
29
+
30
+ module.exports = {
31
+ getGoDependencies
32
+ }
@@ -0,0 +1,143 @@
1
+ const child_process = require('child_process')
2
+ const path = require('path')
3
+ const i18n = require('i18n')
4
+ const fs = require('fs')
5
+
6
+ const MAVEN = 'maven'
7
+ const GRADLE = 'gradle'
8
+
9
+ const determineProjectTypeAndCwd = (files, projectPath) => {
10
+ const projectData = {}
11
+
12
+ if (files[0].includes('pom.xml')) {
13
+ projectData.projectType = MAVEN
14
+ projectData.cwd = projectPath
15
+ ? projectPath
16
+ : files[0].replace('pom.xml', '')
17
+ } else if (files[0].includes('build.gradle')) {
18
+ projectData.projectType = GRADLE
19
+ projectData.cwd = projectPath
20
+ ? projectPath
21
+ : files[0].replace('pom.xml', '')
22
+ }
23
+
24
+ return projectData
25
+ }
26
+
27
+ const buildMaven = (config, projectData, timeout) => {
28
+ let cmdStdout
29
+ let mvn_settings = ''
30
+
31
+ try {
32
+ // Allow users to provide a custom location for their settings.xml
33
+ if (config.mavenSettingsPath) {
34
+ mvn_settings = ' -s ' + config.mavenSettingsPath
35
+ }
36
+ cmdStdout = child_process.execSync(
37
+ 'mvn dependency:tree -B' + mvn_settings,
38
+ {
39
+ cwd: projectData.cwd,
40
+ timeout
41
+ }
42
+ )
43
+ return cmdStdout.toString()
44
+ } catch (err) {
45
+ throw new Error(
46
+ i18n.__('mavenDependencyTreeNonZero', projectData.cwd, `${err.message}`)
47
+ )
48
+ }
49
+ }
50
+
51
+ const buildGradle = (config, projectData, timeout) => {
52
+ let cmdStdout
53
+ let output = {}
54
+
55
+ try {
56
+ // path.sep is user here to either execute as "./gradlew" for UNIX/Linux/MacOS
57
+ // & ".\gradlew" for Windows
58
+ // Check if the user has specified a sub-project
59
+ if (config.subProject) {
60
+ cmdStdout = child_process.execSync(
61
+ '.' +
62
+ path.sep +
63
+ 'gradlew :' +
64
+ config.subProject +
65
+ ':dependencies --configuration runtimeClasspath',
66
+ {
67
+ cwd: projectData.cwd,
68
+ timeout
69
+ }
70
+ )
71
+ } else {
72
+ cmdStdout = child_process.execSync(
73
+ '.' +
74
+ path.sep +
75
+ 'gradlew dependencies --configuration runtimeClasspath',
76
+ {
77
+ cwd: projectData.cwd,
78
+ timeout
79
+ }
80
+ )
81
+ }
82
+ if (
83
+ cmdStdout
84
+ .toString()
85
+ .includes(
86
+ "runtimeClasspath - Runtime classpath of source set 'main'.\n" +
87
+ 'No dependencies'
88
+ )
89
+ ) {
90
+ cmdStdout = child_process.execSync(
91
+ '.' + path.sep + 'gradlew dependencies',
92
+ {
93
+ cwd: projectData.cwd,
94
+ timeout
95
+ }
96
+ )
97
+ }
98
+ output = cmdStdout.toString()
99
+ return output
100
+ } catch (err) {
101
+ if (
102
+ fs.existsSync(projectData.cwd + 'gradlew') ||
103
+ fs.existsSync(projectData.cwd + 'gradlew.bat')
104
+ ) {
105
+ throw new Error(
106
+ i18n.__(
107
+ 'gradleDependencyTreeNonZero',
108
+ projectData.cwd,
109
+ `${err.message}`
110
+ )
111
+ )
112
+ } else {
113
+ throw new Error(
114
+ i18n.__('gradleWrapperUnavailable', projectData.cwd, `${err.message}`)
115
+ )
116
+ }
117
+ }
118
+ }
119
+
120
+ const getJavaBuildDeps = (config, files) => {
121
+ const timeout = 960000
122
+ let output = {
123
+ mvnDependancyTreeOutput: undefined,
124
+ projectType: undefined
125
+ }
126
+
127
+ try {
128
+ const projectData = determineProjectTypeAndCwd(files, config.projectPath)
129
+ if (projectData.projectType === MAVEN) {
130
+ output.mvnDependancyTreeOutput = buildMaven(config, projectData, timeout)
131
+ } else if (projectData.projectType === GRADLE) {
132
+ output.mvnDependancyTreeOutput = buildGradle(config, projectData, timeout)
133
+ }
134
+ output.projectType = projectData.projectType
135
+ return output
136
+ } catch (err) {
137
+ console.log(err.message.toString())
138
+ }
139
+ }
140
+
141
+ module.exports = {
142
+ getJavaBuildDeps
143
+ }
@@ -0,0 +1,21 @@
1
+ const analysis = require('./analysis')
2
+ const { parseBuildDeps } = require('./javaBuildDepsParser')
3
+ const { createJavaTSMessage } = require('../common/formatMessage')
4
+
5
+ const javaAnalysis = (config, languageFiles) => {
6
+ languageFiles.java.forEach(file => {
7
+ file.replace('build.gradle.kts', 'build.gradle')
8
+ })
9
+
10
+ const javaDeps = buildJavaTree(config, languageFiles.java)
11
+ return createJavaTSMessage(javaDeps)
12
+ }
13
+
14
+ const buildJavaTree = (config, files) => {
15
+ const javaBuildDeps = analysis.getJavaBuildDeps(config, files)
16
+ return parseBuildDeps(config, javaBuildDeps)
17
+ }
18
+
19
+ module.exports = {
20
+ javaAnalysis
21
+ }