@contrast/contrast 1.0.7 → 1.0.10

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 (196) hide show
  1. package/README.md +1 -1
  2. package/dist/audit/catalogueApplication/catalogueApplication.js +23 -5
  3. package/dist/audit/languageAnalysisEngine/getProjectRootFilenames.js +17 -26
  4. package/dist/audit/languageAnalysisEngine/report/commonReportingFunctions.js +98 -37
  5. package/dist/audit/languageAnalysisEngine/report/models/reportListModel.js +2 -1
  6. package/dist/audit/languageAnalysisEngine/report/models/reportOutputModel.js +4 -3
  7. package/dist/audit/languageAnalysisEngine/report/models/severityCountModel.js +3 -0
  8. package/dist/audit/languageAnalysisEngine/report/reportingFeature.js +87 -19
  9. package/dist/audit/languageAnalysisEngine/report/utils/reportUtils.js +40 -7
  10. package/dist/audit/languageAnalysisEngine/sendSnapshot.js +6 -30
  11. package/dist/audit/save.js +37 -0
  12. package/dist/commands/audit/auditConfig.js +0 -16
  13. package/dist/commands/audit/auditController.js +18 -11
  14. package/dist/commands/audit/help.js +31 -25
  15. package/dist/commands/audit/processAudit.js +2 -2
  16. package/dist/commands/audit/saveFile.js +8 -4
  17. package/dist/commands/scan/sca/scaAnalysis.js +54 -16
  18. package/dist/common/HTTPClient.js +14 -8
  19. package/dist/common/errorHandling.js +2 -2
  20. package/dist/common/versionChecker.js +19 -4
  21. package/dist/constants/constants.js +7 -2
  22. package/dist/constants/locales.js +44 -44
  23. package/dist/constants.js +31 -14
  24. package/dist/index.js +55 -45
  25. package/dist/lambda/lambda.js +5 -2
  26. package/dist/sbom/generateSbom.js +5 -4
  27. package/dist/scaAnalysis/common/formatMessage.js +33 -6
  28. package/dist/scaAnalysis/common/treeUpload.js +4 -6
  29. package/dist/scaAnalysis/dotnet/analysis.js +43 -0
  30. package/dist/scaAnalysis/dotnet/index.js +10 -0
  31. package/dist/scaAnalysis/go/goReadDepFile.js +1 -3
  32. package/dist/scaAnalysis/java/analysis.js +5 -5
  33. package/dist/scaAnalysis/javascript/analysis.js +107 -0
  34. package/dist/scaAnalysis/javascript/index.js +53 -0
  35. package/dist/scaAnalysis/php/analysis.js +70 -0
  36. package/dist/scaAnalysis/php/index.js +17 -0
  37. package/dist/scaAnalysis/python/analysis.js +8 -7
  38. package/dist/scaAnalysis/ruby/analysis.js +8 -16
  39. package/dist/scaAnalysis/ruby/index.js +2 -2
  40. package/dist/scan/autoDetection.js +13 -24
  41. package/dist/scan/fileUtils.js +44 -14
  42. package/dist/scan/formatScanOutput.js +3 -3
  43. package/dist/scan/scanConfig.js +2 -2
  44. package/dist/utils/commonApi.js +1 -1
  45. package/dist/utils/filterProjectPath.js +7 -2
  46. package/dist/utils/getConfig.js +1 -6
  47. package/package.json +2 -3
  48. package/src/audit/catalogueApplication/catalogueApplication.js +28 -6
  49. package/src/audit/languageAnalysisEngine/getProjectRootFilenames.js +22 -58
  50. package/src/audit/languageAnalysisEngine/report/commonReportingFunctions.ts +157 -47
  51. package/src/audit/languageAnalysisEngine/report/models/reportListModel.ts +4 -1
  52. package/src/audit/languageAnalysisEngine/report/models/reportOutputModel.ts +11 -5
  53. package/src/audit/languageAnalysisEngine/report/models/severityCountModel.ts +4 -0
  54. package/src/audit/languageAnalysisEngine/report/reportingFeature.ts +86 -32
  55. package/src/audit/languageAnalysisEngine/report/utils/reportUtils.ts +44 -5
  56. package/src/audit/languageAnalysisEngine/sendSnapshot.js +6 -32
  57. package/src/audit/save.js +48 -0
  58. package/src/commands/audit/auditConfig.ts +0 -25
  59. package/src/commands/audit/auditController.ts +18 -20
  60. package/src/commands/audit/help.ts +31 -25
  61. package/src/commands/audit/processAudit.ts +2 -5
  62. package/src/commands/audit/saveFile.ts +6 -2
  63. package/src/commands/scan/processScan.js +0 -1
  64. package/src/commands/scan/sca/scaAnalysis.js +87 -32
  65. package/src/common/HTTPClient.js +16 -9
  66. package/src/common/errorHandling.ts +2 -3
  67. package/src/common/versionChecker.ts +23 -4
  68. package/src/constants/constants.js +9 -3
  69. package/src/constants/locales.js +72 -50
  70. package/src/constants.js +32 -15
  71. package/src/index.ts +70 -58
  72. package/src/lambda/lambda.ts +5 -2
  73. package/src/lambda/types.ts +1 -0
  74. package/src/sbom/generateSbom.ts +2 -2
  75. package/src/scaAnalysis/common/formatMessage.js +35 -6
  76. package/src/scaAnalysis/common/treeUpload.js +4 -6
  77. package/src/scaAnalysis/dotnet/analysis.js +54 -0
  78. package/src/scaAnalysis/dotnet/index.js +11 -0
  79. package/src/scaAnalysis/go/goReadDepFile.js +1 -3
  80. package/src/scaAnalysis/java/analysis.js +5 -5
  81. package/src/scaAnalysis/javascript/analysis.js +126 -0
  82. package/src/scaAnalysis/javascript/index.js +75 -0
  83. package/src/scaAnalysis/php/analysis.js +78 -0
  84. package/src/scaAnalysis/php/index.js +22 -0
  85. package/src/scaAnalysis/python/analysis.js +8 -7
  86. package/src/scaAnalysis/ruby/analysis.js +8 -17
  87. package/src/scaAnalysis/ruby/index.js +2 -2
  88. package/src/scan/autoDetection.js +14 -27
  89. package/src/scan/fileUtils.js +46 -14
  90. package/src/scan/formatScanOutput.ts +3 -3
  91. package/src/scan/scanConfig.js +2 -4
  92. package/src/utils/commonApi.js +1 -1
  93. package/src/utils/filterProjectPath.js +6 -2
  94. package/src/utils/getConfig.ts +1 -12
  95. package/dist/audit/AnalysisEngine.js +0 -37
  96. package/dist/audit/autodetection/autoDetectLanguage.js +0 -32
  97. package/dist/audit/dotnetAnalysisEngine/index.js +0 -25
  98. package/dist/audit/dotnetAnalysisEngine/parseLockFileContents.js +0 -35
  99. package/dist/audit/dotnetAnalysisEngine/parseProjectFileContents.js +0 -15
  100. package/dist/audit/dotnetAnalysisEngine/readLockFileContents.js +0 -18
  101. package/dist/audit/dotnetAnalysisEngine/readProjectFileContents.js +0 -14
  102. package/dist/audit/dotnetAnalysisEngine/sanitizer.js +0 -9
  103. package/dist/audit/goAnalysisEngine/index.js +0 -17
  104. package/dist/audit/goAnalysisEngine/parseProjectFileContents.js +0 -164
  105. package/dist/audit/goAnalysisEngine/readProjectFileContents.js +0 -21
  106. package/dist/audit/goAnalysisEngine/sanitizer.js +0 -5
  107. package/dist/audit/javaAnalysisEngine/index.js +0 -34
  108. package/dist/audit/javaAnalysisEngine/parseMavenProjectFileContents.js +0 -155
  109. package/dist/audit/javaAnalysisEngine/parseProjectFileContents.js +0 -353
  110. package/dist/audit/javaAnalysisEngine/readProjectFileContents.js +0 -98
  111. package/dist/audit/javaAnalysisEngine/sanitizer.js +0 -5
  112. package/dist/audit/languageAnalysisEngine/checkForMultipleIdentifiedLanguages.js +0 -25
  113. package/dist/audit/languageAnalysisEngine/checkForMultipleIdentifiedProjectFiles.js +0 -25
  114. package/dist/audit/languageAnalysisEngine/checkIdentifiedLanguageHasLockFile.js +0 -35
  115. package/dist/audit/languageAnalysisEngine/checkIdentifiedLanguageHasProjectFile.js +0 -24
  116. package/dist/audit/languageAnalysisEngine/constants.js +0 -20
  117. package/dist/audit/languageAnalysisEngine/getIdentifiedLanguageInfo.js +0 -25
  118. package/dist/audit/languageAnalysisEngine/index.js +0 -39
  119. package/dist/audit/languageAnalysisEngine/languageAnalysisFactory.js +0 -89
  120. package/dist/audit/languageAnalysisEngine/reduceIdentifiedLanguages.js +0 -159
  121. package/dist/audit/nodeAnalysisEngine/handleNPMLockFileV2.js +0 -40
  122. package/dist/audit/nodeAnalysisEngine/index.js +0 -31
  123. package/dist/audit/nodeAnalysisEngine/parseNPMLockFileContents.js +0 -18
  124. package/dist/audit/nodeAnalysisEngine/parseYarnLockFileContents.js +0 -18
  125. package/dist/audit/nodeAnalysisEngine/readNPMLockFileContents.js +0 -17
  126. package/dist/audit/nodeAnalysisEngine/readProjectFileContents.js +0 -14
  127. package/dist/audit/nodeAnalysisEngine/readYarnLockFileContents.js +0 -24
  128. package/dist/audit/nodeAnalysisEngine/sanitizer.js +0 -9
  129. package/dist/audit/phpAnalysisEngine/index.js +0 -23
  130. package/dist/audit/phpAnalysisEngine/parseLockFileContents.js +0 -52
  131. package/dist/audit/phpAnalysisEngine/readLockFileContents.js +0 -13
  132. package/dist/audit/phpAnalysisEngine/readProjectFileContents.js +0 -16
  133. package/dist/audit/phpAnalysisEngine/sanitizer.js +0 -5
  134. package/dist/audit/pythonAnalysisEngine/index.js +0 -25
  135. package/dist/audit/pythonAnalysisEngine/parsePipfileLockContents.js +0 -17
  136. package/dist/audit/pythonAnalysisEngine/parseProjectFileContents.js +0 -21
  137. package/dist/audit/pythonAnalysisEngine/readPipfileLockFileContents.js +0 -13
  138. package/dist/audit/pythonAnalysisEngine/readPythonProjectFileContents.js +0 -14
  139. package/dist/audit/pythonAnalysisEngine/sanitizer.js +0 -7
  140. package/dist/audit/rubyAnalysisEngine/index.js +0 -25
  141. package/dist/audit/rubyAnalysisEngine/parseGemfileLockContents.js +0 -176
  142. package/dist/audit/rubyAnalysisEngine/parsedGemfile.js +0 -22
  143. package/dist/audit/rubyAnalysisEngine/readGemfileContents.js +0 -14
  144. package/dist/audit/rubyAnalysisEngine/readGemfileLockContents.js +0 -14
  145. package/dist/audit/rubyAnalysisEngine/sanitizer.js +0 -6
  146. package/src/audit/AnalysisEngine.js +0 -103
  147. package/src/audit/autodetection/autoDetectLanguage.ts +0 -40
  148. package/src/audit/dotnetAnalysisEngine/index.js +0 -26
  149. package/src/audit/dotnetAnalysisEngine/parseLockFileContents.js +0 -47
  150. package/src/audit/dotnetAnalysisEngine/parseProjectFileContents.js +0 -29
  151. package/src/audit/dotnetAnalysisEngine/readLockFileContents.js +0 -30
  152. package/src/audit/dotnetAnalysisEngine/readProjectFileContents.js +0 -26
  153. package/src/audit/dotnetAnalysisEngine/sanitizer.js +0 -11
  154. package/src/audit/goAnalysisEngine/index.js +0 -18
  155. package/src/audit/goAnalysisEngine/parseProjectFileContents.js +0 -209
  156. package/src/audit/goAnalysisEngine/readProjectFileContents.js +0 -31
  157. package/src/audit/goAnalysisEngine/sanitizer.js +0 -7
  158. package/src/audit/javaAnalysisEngine/index.js +0 -41
  159. package/src/audit/javaAnalysisEngine/parseMavenProjectFileContents.js +0 -225
  160. package/src/audit/javaAnalysisEngine/parseProjectFileContents.js +0 -420
  161. package/src/audit/javaAnalysisEngine/readProjectFileContents.js +0 -141
  162. package/src/audit/javaAnalysisEngine/sanitizer.js +0 -6
  163. package/src/audit/languageAnalysisEngine/checkForMultipleIdentifiedLanguages.js +0 -36
  164. package/src/audit/languageAnalysisEngine/checkForMultipleIdentifiedProjectFiles.js +0 -42
  165. package/src/audit/languageAnalysisEngine/checkIdentifiedLanguageHasLockFile.js +0 -54
  166. package/src/audit/languageAnalysisEngine/checkIdentifiedLanguageHasProjectFile.js +0 -33
  167. package/src/audit/languageAnalysisEngine/constants.js +0 -23
  168. package/src/audit/languageAnalysisEngine/getIdentifiedLanguageInfo.js +0 -41
  169. package/src/audit/languageAnalysisEngine/index.js +0 -45
  170. package/src/audit/languageAnalysisEngine/languageAnalysisFactory.js +0 -124
  171. package/src/audit/languageAnalysisEngine/reduceIdentifiedLanguages.js +0 -250
  172. package/src/audit/nodeAnalysisEngine/handleNPMLockFileV2.js +0 -49
  173. package/src/audit/nodeAnalysisEngine/index.js +0 -35
  174. package/src/audit/nodeAnalysisEngine/parseNPMLockFileContents.js +0 -20
  175. package/src/audit/nodeAnalysisEngine/parseYarnLockFileContents.js +0 -26
  176. package/src/audit/nodeAnalysisEngine/readNPMLockFileContents.js +0 -23
  177. package/src/audit/nodeAnalysisEngine/readProjectFileContents.js +0 -27
  178. package/src/audit/nodeAnalysisEngine/readYarnLockFileContents.js +0 -36
  179. package/src/audit/nodeAnalysisEngine/sanitizer.js +0 -11
  180. package/src/audit/phpAnalysisEngine/index.js +0 -27
  181. package/src/audit/phpAnalysisEngine/parseLockFileContents.js +0 -60
  182. package/src/audit/phpAnalysisEngine/readLockFileContents.js +0 -14
  183. package/src/audit/phpAnalysisEngine/readProjectFileContents.js +0 -25
  184. package/src/audit/phpAnalysisEngine/sanitizer.js +0 -4
  185. package/src/audit/pythonAnalysisEngine/index.js +0 -55
  186. package/src/audit/pythonAnalysisEngine/parsePipfileLockContents.js +0 -23
  187. package/src/audit/pythonAnalysisEngine/parseProjectFileContents.js +0 -33
  188. package/src/audit/pythonAnalysisEngine/readPipfileLockFileContents.js +0 -16
  189. package/src/audit/pythonAnalysisEngine/readPythonProjectFileContents.js +0 -22
  190. package/src/audit/pythonAnalysisEngine/sanitizer.js +0 -9
  191. package/src/audit/rubyAnalysisEngine/index.js +0 -30
  192. package/src/audit/rubyAnalysisEngine/parseGemfileLockContents.js +0 -215
  193. package/src/audit/rubyAnalysisEngine/parsedGemfile.js +0 -39
  194. package/src/audit/rubyAnalysisEngine/readGemfileContents.js +0 -18
  195. package/src/audit/rubyAnalysisEngine/readGemfileLockContents.js +0 -17
  196. package/src/audit/rubyAnalysisEngine/sanitizer.js +0 -8
package/src/index.ts CHANGED
@@ -1,3 +1,5 @@
1
+ #!/usr/bin/env node
2
+
1
3
  import commandLineArgs from 'command-line-args'
2
4
  import { processAudit } from './commands/audit/processAudit'
3
5
  import { processAuth } from './commands/auth/auth'
@@ -34,74 +36,84 @@ const getMainOption = () => {
34
36
  }
35
37
 
36
38
  const start = async () => {
37
- if (await isCorrectNodeVersion(process.version)) {
38
- const { mainOptions, argv: argvMain } = getMainOption()
39
- const command =
40
- mainOptions.command != undefined ? mainOptions.command.toLowerCase() : ''
41
- if (
42
- command === 'version' ||
43
- argvMain.includes('--v') ||
44
- argvMain.includes('--version')
45
- ) {
46
- console.log(APP_VERSION)
47
- await findLatestCLIVersion(config.get('updateMessageHidden') as boolean)
48
- return
49
- }
39
+ try {
40
+ if (await isCorrectNodeVersion(process.version)) {
41
+ const { mainOptions, argv: argvMain } = getMainOption()
42
+ const command =
43
+ mainOptions.command != undefined
44
+ ? mainOptions.command.toLowerCase()
45
+ : ''
46
+ if (
47
+ command === 'version' ||
48
+ argvMain.includes('--v') ||
49
+ argvMain.includes('--version')
50
+ ) {
51
+ console.log(APP_VERSION)
52
+ await findLatestCLIVersion(config)
53
+ return
54
+ }
50
55
 
51
- // @ts-ignore
52
- config.set('numOfRuns', config.get('numOfRuns') + 1)
56
+ // @ts-ignore
57
+ config.set('numOfRuns', config.get('numOfRuns') + 1)
53
58
 
54
- // @ts-ignore
55
- if (config.get('numOfRuns') >= 5) {
56
- await findLatestCLIVersion(config.get('updateMessageHidden') as boolean)
57
- config.set('numOfRuns', 0)
58
- }
59
+ // @ts-ignore
60
+ if (config.get('numOfRuns') >= 1) {
61
+ await findLatestCLIVersion(config)
62
+ config.set('numOfRuns', 0)
63
+ }
59
64
 
60
- if (command === 'config') {
61
- return processConfig(argvMain, config)
62
- }
65
+ if (command === 'config') {
66
+ return processConfig(argvMain, config)
67
+ }
63
68
 
64
- if (command === 'auth') {
65
- return await processAuth(argvMain, config)
66
- }
69
+ if (command === 'auth') {
70
+ return await processAuth(argvMain, config)
71
+ }
67
72
 
68
- if (command === 'lambda') {
69
- return await processLambda(argvMain)
70
- }
73
+ if (command === 'lambda') {
74
+ return await processLambda(argvMain)
75
+ }
71
76
 
72
- if (command === 'scan') {
73
- return await processScan(argvMain)
74
- }
77
+ if (command === 'scan') {
78
+ return await processScan(argvMain)
79
+ }
75
80
 
76
- if (command === 'audit') {
77
- return await processAudit(argvMain)
78
- }
81
+ if (command === 'audit') {
82
+ return await processAudit(argvMain)
83
+ }
84
+
85
+ if (
86
+ command === 'help' ||
87
+ argvMain.includes('--help') ||
88
+ Object.keys(mainOptions).length === 0
89
+ ) {
90
+ console.log(mainUsageGuide)
91
+ } else if (mainOptions._unknown !== undefined) {
92
+ const foundCommand = findCommandOnError(mainOptions._unknown)
79
93
 
80
- if (
81
- command === 'help' ||
82
- argvMain.includes('--help') ||
83
- Object.keys(mainOptions).length === 0
84
- ) {
85
- console.log(mainUsageGuide)
86
- } else if (mainOptions._unknown !== undefined) {
87
- const foundCommand = findCommandOnError(mainOptions._unknown)
88
-
89
- foundCommand
90
- ? console.log(
91
- `Unknown Command: Did you mean "${foundCommand}"? \nUse "${foundCommand} --help" for the full list of options`
92
- )
93
- : console.log(
94
- `Unknown Command: ${command} \nUse --help for the full list`
95
- )
94
+ foundCommand
95
+ ? console.log(
96
+ `Unknown Command: Did you mean "${foundCommand}"? \nUse "${foundCommand} --help" for the full list of options`
97
+ )
98
+ : console.log(
99
+ `Unknown Command: ${command} \nUse --help for the full list`
100
+ )
101
+ } else {
102
+ console.log(
103
+ `Unknown Command: ${command} \nUse --help for the full list`
104
+ )
105
+ }
106
+ process.exit(9)
96
107
  } else {
97
- console.log(`Unknown Command: ${command} \nUse --help for the full list`)
108
+ console.log(
109
+ 'Contrast supports Node versions >=16.13.2 <17. Please use one of those versions.'
110
+ )
111
+ process.exit(9)
98
112
  }
99
- process.exit(9)
100
- } else {
101
- console.log(
102
- 'Contrast supports Node versions >=16.13.2 <17. Please use one of those versions.'
103
- )
104
- process.exit(9)
113
+ } catch (err: any) {
114
+ console.log()
115
+ console.log(err.message.toString())
116
+ process.exit(1)
105
117
  }
106
118
  }
107
119
 
@@ -16,6 +16,7 @@ import { sleep } from '../utils/requestUtils'
16
16
  import ora from '../utils/oraWrapper'
17
17
  import { postAnalytics } from './analytics'
18
18
  import { LambdaOptions, AnalyticsOption, StatusType, EventType } from './types'
19
+ import { APP_VERSION } from '../constants/constants'
19
20
 
20
21
  type ApiParams = {
21
22
  organizationId: string
@@ -73,7 +74,8 @@ const processLambda = async (argv: string[]) => {
73
74
  const startCommandAnalytics: AnalyticsOption = {
74
75
  arguments: lambdaOptions,
75
76
  sessionId: commandSessionId,
76
- eventType: EventType.START
77
+ eventType: EventType.START,
78
+ packageVersion: APP_VERSION
77
79
  }
78
80
  postAnalytics(startCommandAnalytics).catch((error: Error) => {
79
81
  /* ignore */
@@ -99,7 +101,8 @@ const processLambda = async (argv: string[]) => {
99
101
  const endCommandAnalytics: AnalyticsOption = {
100
102
  sessionId: commandSessionId,
101
103
  eventType: EventType.END,
102
- status: errorMsg ? StatusType.FAILED : StatusType.SUCCESS
104
+ status: errorMsg ? StatusType.FAILED : StatusType.SUCCESS,
105
+ packageVersion: APP_VERSION
103
106
  }
104
107
  if (errorMsg) {
105
108
  endCommandAnalytics.errorMsg = errorMsg
@@ -28,6 +28,7 @@ type ScanFunctionData = {
28
28
  export type AnalyticsOption = {
29
29
  sessionId: string
30
30
  eventType: EventType
31
+ packageVersion: string
31
32
  arguments?: LambdaOptions
32
33
  scanFunctionData?: ScanFunctionData
33
34
  status?: StatusType
@@ -1,9 +1,9 @@
1
1
  import { getHttpClient } from '../utils/commonApi'
2
2
 
3
- export default function generateSbom(config: any) {
3
+ export const generateSbom = (config: any, type: string) => {
4
4
  const client = getHttpClient(config)
5
5
  return client
6
- .getSbom(config)
6
+ .getSbom(config, type)
7
7
  .then((res: { statusCode: number; body: any }) => {
8
8
  if (res.statusCode === 200) {
9
9
  return res.body
@@ -6,6 +6,21 @@ const createJavaTSMessage = javaTree => {
6
6
  }
7
7
  }
8
8
 
9
+ const createJavaScriptTSMessage = js => {
10
+ let message = {
11
+ node: {
12
+ packageJSON: js.packageJSON
13
+ }
14
+ }
15
+ if (js.yarn !== undefined) {
16
+ message.node.yarnLockFile = js.yarn.yarnLockFile
17
+ message.node.yarnVersion = js.yarn.yarnVersion
18
+ } else {
19
+ message.node.npmLockFile = js.npmLockFile
20
+ }
21
+ return message
22
+ }
23
+
9
24
  const createGoTSMessage = goTree => {
10
25
  return {
11
26
  go: {
@@ -16,23 +31,37 @@ const createGoTSMessage = goTree => {
16
31
 
17
32
  const createRubyTSMessage = rubyTree => {
18
33
  return {
19
- ruby: {
20
- rubyDependencyTrees: rubyTree
21
- }
34
+ ruby: rubyTree
22
35
  }
23
36
  }
24
37
 
25
38
  const createPythonTSMessage = pythonTree => {
26
39
  return {
27
- python: {
28
- pythonDependencyTrees: pythonTree
40
+ python: pythonTree
41
+ }
42
+ }
43
+
44
+ const createPhpTSMessage = phpTree => {
45
+ return {
46
+ php: {
47
+ composerJSON: phpTree.composerJSON,
48
+ lockFile: phpTree.lockFile
29
49
  }
30
50
  }
31
51
  }
32
52
 
53
+ const createDotNetTSMessage = dotnetTree => {
54
+ return {
55
+ dotnet: dotnetTree
56
+ }
57
+ }
58
+
33
59
  module.exports = {
60
+ createJavaScriptTSMessage,
34
61
  createJavaTSMessage,
35
62
  createGoTSMessage,
63
+ createPhpTSMessage,
36
64
  createRubyTSMessage,
37
- createPythonTSMessage
65
+ createPythonTSMessage,
66
+ createDotNetTSMessage
38
67
  }
@@ -1,4 +1,4 @@
1
- const { getHttpClient } = require('../../utils/commonApi')
1
+ const commonApi = require('../../utils/commonApi')
2
2
  const { APP_VERSION } = require('../../constants/constants')
3
3
 
4
4
  const commonSendSnapShot = async (analysis, config) => {
@@ -8,20 +8,18 @@ const commonSendSnapShot = async (analysis, config) => {
8
8
  snapshot: analysis
9
9
  }
10
10
 
11
- const client = getHttpClient(config)
11
+ const client = commonApi.getHttpClient(config)
12
12
  return client
13
13
  .sendSnapshot(requestBody, config)
14
14
  .then(res => {
15
15
  if (res.statusCode === 201) {
16
- console.log('dependencies processed successfully')
17
16
  return res.body
18
17
  } else {
19
- console.log(res.statusCode)
20
- console.log('error processing dependencies')
18
+ throw new Error(res.statusCode + ` error processing dependencies`)
21
19
  }
22
20
  })
23
21
  .catch(err => {
24
- console.log(err)
22
+ throw err
25
23
  })
26
24
  }
27
25
 
@@ -0,0 +1,54 @@
1
+ const fs = require('fs')
2
+ const xml2js = require('xml2js')
3
+ const i18n = require('i18n')
4
+
5
+ const readAndParseProjectFile = projectFilePath => {
6
+ const projectFile = fs.readFileSync(projectFilePath)
7
+
8
+ return new xml2js.Parser({
9
+ explicitArray: false,
10
+ mergeAttrs: true
11
+ }).parseString(projectFile)
12
+ }
13
+
14
+ const readAndParseLockFile = lockFilePath => {
15
+ const lockFile = JSON.parse(fs.readFileSync(lockFilePath).toString())
16
+
17
+ let count = 0 // Used to test if some nodes are deleted
18
+
19
+ for (const dependenciesNode in lockFile.dependencies) {
20
+ for (const innerNode in lockFile.dependencies[dependenciesNode]) {
21
+ const nodeValidation = JSON.stringify(
22
+ lockFile.dependencies[dependenciesNode][innerNode]
23
+ )
24
+ if (nodeValidation.includes('"type":"Project"')) {
25
+ count += 1
26
+ delete lockFile.dependencies[dependenciesNode][innerNode]
27
+ lockFile.additionalInfo = 'dependenciesNote'
28
+ }
29
+ }
30
+ }
31
+
32
+ if (count > 0) {
33
+ const multiLevelProjectWarning = () => {
34
+ console.log('')
35
+ console.log(i18n.__('dependenciesNote'))
36
+ }
37
+ setTimeout(multiLevelProjectWarning, 7000)
38
+ }
39
+
40
+ return lockFile
41
+ }
42
+
43
+ const getDotNetDeps = (filePath, languageFiles) => {
44
+ const projectFile = readAndParseProjectFile(filePath + `/${languageFiles[0]}`)
45
+ const lockFile = readAndParseLockFile(filePath + `/${languageFiles[1]}`)
46
+
47
+ return { projectFile, lockFile }
48
+ }
49
+
50
+ module.exports = {
51
+ getDotNetDeps,
52
+ readAndParseProjectFile,
53
+ readAndParseLockFile
54
+ }
@@ -0,0 +1,11 @@
1
+ const { getDotNetDeps } = require('./analysis')
2
+ const { createDotNetTSMessage } = require('../common/formatMessage')
3
+
4
+ const dotNetAnalysis = (config, languageFiles) => {
5
+ const dotNetDeps = getDotNetDeps(config.file, languageFiles.DOTNET)
6
+ return createDotNetTSMessage(dotNetDeps)
7
+ }
8
+
9
+ module.exports = {
10
+ dotNetAnalysis
11
+ }
@@ -3,9 +3,7 @@ const i18n = require('i18n')
3
3
 
4
4
  const getGoDependencies = config => {
5
5
  let cmdStdout
6
- let cwd = config.projectPath
7
- ? config.projectPath.replace('go.mod', '')
8
- : process.cwd()
6
+ let cwd = config.file ? config.file.replace('go.mod', '') : process.cwd()
9
7
 
10
8
  try {
11
9
  // A sample of this output can be found
@@ -6,7 +6,7 @@ const fs = require('fs')
6
6
  const MAVEN = 'maven'
7
7
  const GRADLE = 'gradle'
8
8
 
9
- const determineProjectTypeAndCwd = (files, projectPath) => {
9
+ const determineProjectTypeAndCwd = (files, file) => {
10
10
  const projectData = {}
11
11
 
12
12
  if (files[0].includes('pom.xml')) {
@@ -16,9 +16,9 @@ const determineProjectTypeAndCwd = (files, projectPath) => {
16
16
  }
17
17
 
18
18
  //clean up the path to be a folder not a file
19
- projectData.cwd = projectPath
20
- ? projectPath.replace('pom.xml', '').replace('build.gradle', '')
21
- : projectPath
19
+ projectData.cwd = file
20
+ ? file.replace('pom.xml', '').replace('build.gradle', '')
21
+ : file
22
22
 
23
23
  return projectData
24
24
  }
@@ -124,7 +124,7 @@ const getJavaBuildDeps = (config, files) => {
124
124
  }
125
125
 
126
126
  try {
127
- const projectData = determineProjectTypeAndCwd(files, config.projectPath)
127
+ const projectData = determineProjectTypeAndCwd(files, config.file)
128
128
  if (projectData.projectType === MAVEN) {
129
129
  output.mvnDependancyTreeOutput = buildMaven(config, projectData, timeout)
130
130
  } else if (projectData.projectType === GRADLE) {
@@ -0,0 +1,126 @@
1
+ const fs = require('fs')
2
+ const yarnParser = require('@yarnpkg/lockfile')
3
+ const yaml = require('js-yaml')
4
+ const i18n = require('i18n')
5
+ const {
6
+ formatKey
7
+ } = require('../../audit/nodeAnalysisEngine/parseYarn2LockFileContents')
8
+
9
+ const readFile = async (config, languageFiles, nameOfFile) => {
10
+ const index = languageFiles.findIndex(v => v.includes(nameOfFile))
11
+
12
+ if (config.file) {
13
+ return fs.readFileSync(config.file.concat(languageFiles[index]), 'utf8')
14
+ } else {
15
+ throw new Error('could not find file')
16
+ }
17
+ }
18
+
19
+ const readYarn = async (config, languageFiles, nameOfFile) => {
20
+ let yarn = {
21
+ yarnVersion: 1,
22
+ rawYarnLockFileContents: ''
23
+ }
24
+
25
+ try {
26
+ let rawYarnLockFileContents = await readFile(
27
+ config,
28
+ languageFiles,
29
+ nameOfFile
30
+ )
31
+ yarn.rawYarnLockFileContents = rawYarnLockFileContents
32
+
33
+ if (
34
+ !yarn.rawYarnLockFileContents.includes('lockfile v1') ||
35
+ yarn.rawYarnLockFileContents.includes('__metadata')
36
+ ) {
37
+ yarn.rawYarnLockFileContents = yaml.load(rawYarnLockFileContents)
38
+ yarn.yarnVersion = 2
39
+ }
40
+
41
+ return yarn
42
+ } catch (err) {
43
+ throw new Error(i18n.__('nodeReadYarnLockFileError') + `${err.message}`)
44
+ }
45
+ }
46
+
47
+ const parseNpmLockFile = async js => {
48
+ try {
49
+ js.npmLockFile = JSON.parse(js.rawLockFileContents)
50
+ if (js.npmLockFile && js.npmLockFile.lockfileVersion > 1) {
51
+ const listOfTopDep = Object.keys(js.npmLockFile.dependencies)
52
+ Object.entries(js.npmLockFile.dependencies).forEach(([objKey, value]) => {
53
+ if (value.requires) {
54
+ const listOfRequiresDep = Object.keys(value.requires)
55
+ listOfRequiresDep.forEach(dep => {
56
+ if (!listOfTopDep.includes(dep)) {
57
+ addDepToLockFile(js, value['requires'], dep)
58
+ }
59
+ })
60
+ }
61
+
62
+ if (value.dependencies) {
63
+ Object.entries(value.dependencies).forEach(
64
+ ([objChildKey, childValue]) => {
65
+ if (childValue.requires) {
66
+ const listOfRequiresDep = Object.keys(childValue.requires)
67
+ listOfRequiresDep.forEach(dep => {
68
+ if (!listOfTopDep.includes(dep)) {
69
+ addDepToLockFile(js, childValue['requires'], dep)
70
+ }
71
+ })
72
+ }
73
+ }
74
+ )
75
+ }
76
+ })
77
+ return js.npmLockFile
78
+ } else {
79
+ return js.npmLockFile
80
+ }
81
+ } catch (err) {
82
+ throw new Error(i18n.__('NodeParseNPM') + `${err.message}`)
83
+ }
84
+ }
85
+
86
+ const addDepToLockFile = (js, depObj, key) => {
87
+ return (js.npmLockFile.dependencies[key] = { version: depObj[key] })
88
+ }
89
+ const parseYarnLockFile = async js => {
90
+ try {
91
+ js.yarn.yarnLockFile = {}
92
+ if (js.yarn.yarnVersion === 1) {
93
+ js.yarn.yarnLockFile = yarnParser.parse(js.yarn.rawYarnLockFileContents)
94
+ delete js.yarn.rawYarnLockFileContents
95
+ return js
96
+ } else {
97
+ js.yarn.yarnLockFile['object'] = js.yarn.rawYarnLockFileContents
98
+ delete js.yarn.yarnLockFile['object'].__metadata
99
+ js.yarn.yarnLockFile['type'] = 'success'
100
+
101
+ Object.entries(js.yarn.rawYarnLockFileContents).forEach(
102
+ ([key, value]) => {
103
+ const rawKeyNames = key.split(',')
104
+ const keyNames = formatKey(rawKeyNames)
105
+
106
+ keyNames.forEach(name => {
107
+ js.yarn.yarnLockFile.object[name] = value
108
+ })
109
+ }
110
+ )
111
+ return js
112
+ }
113
+ } catch (err) {
114
+ throw new Error(
115
+ i18n.__('NodeParseYarn', js.yarn.yarnVersion) + `${err.message}`
116
+ )
117
+ }
118
+ }
119
+
120
+ module.exports = {
121
+ readYarn,
122
+ parseYarnLockFile,
123
+ parseNpmLockFile,
124
+ readFile,
125
+ formatKey
126
+ }
@@ -0,0 +1,75 @@
1
+ const analysis = require('./analysis')
2
+ const i18n = require('i18n')
3
+ const formatMessage = require('../common/formatMessage')
4
+
5
+ const jsAnalysis = async (config, languageFiles) => {
6
+ checkForCorrectFiles(languageFiles)
7
+
8
+ if (!config.file.endsWith('/')) {
9
+ config.file = config.file.concat('/')
10
+ }
11
+ return buildNodeTree(config, languageFiles.JAVASCRIPT)
12
+ }
13
+ const buildNodeTree = async (config, files) => {
14
+ let analysis = await readFiles(config, files)
15
+ const rawNode = await parseFiles(config, files, analysis)
16
+ return formatMessage.createJavaScriptTSMessage(rawNode)
17
+ }
18
+
19
+ const readFiles = async (config, files) => {
20
+ let js = {}
21
+
22
+ js.packageJSON = JSON.parse(
23
+ await analysis.readFile(config, files, 'package.json')
24
+ )
25
+
26
+ if (files.includes('package-lock.json')) {
27
+ js.rawLockFileContents = await analysis.readFile(
28
+ config,
29
+ files,
30
+ 'package-lock.json'
31
+ )
32
+ }
33
+ if (files.includes('yarn.lock')) {
34
+ js.yarn = {}
35
+ js.yarn = await analysis.readYarn(config, files, 'yarn.lock')
36
+ }
37
+
38
+ return js
39
+ }
40
+
41
+ const parseFiles = async (config, files, js) => {
42
+ if (files.includes('package-lock.json')) {
43
+ js.npmLockFile = await analysis.parseNpmLockFile(js)
44
+ }
45
+ if (files.includes('yarn.lock')) {
46
+ js = await analysis.parseYarnLockFile(js)
47
+ }
48
+
49
+ return js
50
+ }
51
+
52
+ const checkForCorrectFiles = languageFiles => {
53
+ if (
54
+ languageFiles.JAVASCRIPT.includes('package-lock.json') &&
55
+ languageFiles.JAVASCRIPT.includes('yarn.lock')
56
+ ) {
57
+ throw new Error(
58
+ i18n.__('languageAnalysisHasMultipleLockFiles', 'javascript')
59
+ )
60
+ }
61
+
62
+ if (
63
+ !languageFiles.JAVASCRIPT.includes('package-lock.json') &&
64
+ !languageFiles.JAVASCRIPT.includes('yarn.lock')
65
+ ) {
66
+ throw new Error(i18n.__('languageAnalysisHasNoLockFile', 'javascript'))
67
+ }
68
+
69
+ if (!languageFiles.JAVASCRIPT.includes('package.json')) {
70
+ throw new Error(i18n.__('languageAnalysisHasNoPackageJsonFile'))
71
+ }
72
+ }
73
+ module.exports = {
74
+ jsAnalysis
75
+ }
@@ -0,0 +1,78 @@
1
+ const fs = require('fs')
2
+ const i18n = require('i18n')
3
+ const _ = require('lodash')
4
+
5
+ const readFile = (config, nameOfFile) => {
6
+ if (config.file) {
7
+ try {
8
+ return fs.readFileSync(config.file + '/' + nameOfFile)
9
+ } catch (error) {
10
+ console.log('Unable to find file')
11
+ console.log(error)
12
+ }
13
+ }
14
+ }
15
+
16
+ const parseProjectFiles = php => {
17
+ try {
18
+ // composer.json
19
+ php.composerJSON.dependencies = php.composerJSON.require
20
+ php.composerJSON.devDependencies = php.composerJSON['require-dev']
21
+
22
+ // composer.lock
23
+ php.lockFile = php.rawLockFileContents
24
+ let packages = _.keyBy(php.lockFile.packages, 'name')
25
+ let packagesDev = _.keyBy(php.lockFile['packages-dev'], 'name')
26
+ php.lockFile.dependencies = _.merge(packages, packagesDev)
27
+
28
+ const listOfTopDep = Object.keys(php.lockFile.dependencies)
29
+
30
+ Object.entries(php.lockFile.dependencies).forEach(([key, value]) => {
31
+ if (value.require) {
32
+ const listOfRequiresDep = Object.keys(value.require)
33
+ listOfRequiresDep.forEach(dep => {
34
+ if (!listOfTopDep.includes(dep)) {
35
+ addChildDepToLockFileAsOwnObj(php, value['require'], dep)
36
+ }
37
+ })
38
+ }
39
+
40
+ if (value['require-dev']) {
41
+ const listOfRequiresDep = Object.keys(value['require-dev'])
42
+ listOfRequiresDep.forEach(dep => {
43
+ if (!listOfTopDep.includes(dep)) {
44
+ addChildDepToLockFileAsOwnObj(php, value['require-dev'], dep)
45
+ }
46
+ })
47
+ }
48
+ })
49
+ formatParentDepToLockFile(php)
50
+ delete php.rawLockFileContents
51
+ return php
52
+ } catch (err) {
53
+ return console.log(i18n.__('phpParseComposerLock', php) + `${err.message}`) // not sure on this
54
+ }
55
+ }
56
+
57
+ function addChildDepToLockFileAsOwnObj(php, depObj, key) {
58
+ php.lockFile.dependencies[key] = { version: depObj[key] }
59
+ }
60
+
61
+ function formatParentDepToLockFile(php) {
62
+ for (const [key, value] of Object.entries(php.lockFile.dependencies)) {
63
+ let requires = {}
64
+ for (const [childKey, childValue] of Object.entries(value)) {
65
+ if (childKey === 'require' || childKey === 'require-dev') {
66
+ requires = _.merge(requires, childValue)
67
+ php.lockFile.dependencies[key].requires = requires
68
+ delete php.lockFile.dependencies[key].require
69
+ delete php.lockFile.dependencies[key]['require-dev']
70
+ }
71
+ }
72
+ }
73
+ }
74
+
75
+ module.exports = {
76
+ parseProjectFiles,
77
+ readFile
78
+ }