@contrast/contrast 1.0.6 → 1.0.9

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 (221) hide show
  1. package/.prettierignore +0 -6
  2. package/dist/audit/catalogueApplication/catalogueApplication.js +23 -5
  3. package/dist/audit/languageAnalysisEngine/getProjectRootFilenames.js +10 -19
  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 +46 -16
  10. package/dist/audit/languageAnalysisEngine/sendSnapshot.js +57 -19
  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 +3 -3
  16. package/dist/commands/audit/saveFile.js +8 -4
  17. package/dist/commands/scan/sca/scaAnalysis.js +55 -10
  18. package/dist/common/HTTPClient.js +64 -23
  19. package/dist/common/errorHandling.js +6 -1
  20. package/dist/common/versionChecker.js +20 -5
  21. package/dist/constants/constants.js +7 -2
  22. package/dist/constants/locales.js +35 -38
  23. package/dist/constants.js +20 -13
  24. package/dist/index.js +55 -45
  25. package/dist/lambda/analytics.js +11 -0
  26. package/dist/lambda/lambda.js +38 -4
  27. package/dist/lambda/types.js +13 -0
  28. package/dist/sbom/generateSbom.js +5 -4
  29. package/dist/scaAnalysis/common/formatMessage.js +44 -1
  30. package/dist/scaAnalysis/common/treeUpload.js +4 -6
  31. package/dist/scaAnalysis/dotnet/analysis.js +43 -0
  32. package/dist/scaAnalysis/dotnet/index.js +10 -0
  33. package/dist/scaAnalysis/go/goReadDepFile.js +1 -3
  34. package/dist/scaAnalysis/java/analysis.js +5 -8
  35. package/dist/scaAnalysis/java/index.js +2 -2
  36. package/dist/scaAnalysis/javascript/analysis.js +107 -0
  37. package/dist/scaAnalysis/javascript/index.js +50 -0
  38. package/dist/scaAnalysis/php/analysis.js +70 -0
  39. package/dist/scaAnalysis/php/index.js +17 -0
  40. package/dist/scaAnalysis/python/analysis.js +42 -0
  41. package/dist/scaAnalysis/python/index.js +10 -0
  42. package/dist/scaAnalysis/ruby/analysis.js +218 -0
  43. package/dist/scaAnalysis/ruby/index.js +10 -0
  44. package/dist/scan/autoDetection.js +23 -22
  45. package/dist/scan/fileUtils.js +57 -20
  46. package/dist/scan/formatScanOutput.js +12 -14
  47. package/dist/scan/models/groupedResultsModel.js +1 -1
  48. package/dist/scan/models/scanResultsModel.js +3 -1
  49. package/dist/scan/populateProjectIdAndProjectName.js +2 -1
  50. package/dist/scan/scan.js +1 -0
  51. package/dist/scan/scanConfig.js +8 -3
  52. package/dist/scan/scanController.js +16 -3
  53. package/dist/scan/scanResults.js +5 -1
  54. package/dist/utils/commonApi.js +4 -1
  55. package/dist/utils/filterProjectPath.js +7 -2
  56. package/dist/utils/getConfig.js +1 -6
  57. package/package.json +12 -9
  58. package/src/audit/catalogueApplication/catalogueApplication.js +28 -7
  59. package/src/audit/languageAnalysisEngine/getProjectRootFilenames.js +10 -39
  60. package/src/audit/languageAnalysisEngine/report/commonReportingFunctions.ts +183 -68
  61. package/src/audit/languageAnalysisEngine/report/models/reportLibraryModel.ts +3 -3
  62. package/src/audit/languageAnalysisEngine/report/models/reportListModel.ts +18 -11
  63. package/src/audit/languageAnalysisEngine/report/models/reportOutputModel.ts +11 -5
  64. package/src/audit/languageAnalysisEngine/report/models/reportSeverityModel.ts +6 -1
  65. package/src/audit/languageAnalysisEngine/report/models/severityCountModel.ts +4 -0
  66. package/src/audit/languageAnalysisEngine/report/reportingFeature.ts +86 -32
  67. package/src/audit/languageAnalysisEngine/report/utils/reportUtils.ts +87 -32
  68. package/src/audit/languageAnalysisEngine/sendSnapshot.js +69 -20
  69. package/src/audit/save.js +48 -0
  70. package/src/commands/audit/auditConfig.ts +0 -25
  71. package/src/commands/audit/auditController.ts +18 -20
  72. package/src/commands/audit/help.ts +31 -25
  73. package/src/commands/audit/processAudit.ts +3 -6
  74. package/src/commands/audit/saveFile.ts +6 -2
  75. package/src/commands/scan/processScan.js +0 -1
  76. package/src/commands/scan/sca/scaAnalysis.js +84 -30
  77. package/src/common/HTTPClient.js +81 -34
  78. package/src/common/errorHandling.ts +10 -1
  79. package/src/common/versionChecker.ts +24 -5
  80. package/src/constants/constants.js +9 -3
  81. package/src/constants/locales.js +58 -43
  82. package/src/constants.js +21 -14
  83. package/src/index.ts +70 -58
  84. package/src/lambda/analytics.ts +9 -0
  85. package/src/lambda/arn.ts +2 -1
  86. package/src/lambda/lambda.ts +40 -17
  87. package/src/lambda/types.ts +36 -0
  88. package/src/lambda/utils.ts +2 -7
  89. package/src/sbom/generateSbom.ts +2 -2
  90. package/src/scaAnalysis/common/formatMessage.js +48 -1
  91. package/src/scaAnalysis/common/treeUpload.js +4 -6
  92. package/src/scaAnalysis/dotnet/analysis.js +54 -0
  93. package/src/scaAnalysis/dotnet/index.js +11 -0
  94. package/src/scaAnalysis/go/goAnalysis.js +2 -3
  95. package/src/scaAnalysis/go/goReadDepFile.js +1 -3
  96. package/src/scaAnalysis/java/analysis.js +7 -8
  97. package/src/scaAnalysis/java/index.js +2 -2
  98. package/src/scaAnalysis/javascript/analysis.js +126 -0
  99. package/src/scaAnalysis/javascript/index.js +72 -0
  100. package/src/scaAnalysis/php/analysis.js +78 -0
  101. package/src/scaAnalysis/php/index.js +22 -0
  102. package/src/scaAnalysis/python/analysis.js +49 -0
  103. package/src/scaAnalysis/python/index.js +11 -0
  104. package/src/scaAnalysis/ruby/analysis.js +273 -0
  105. package/src/scaAnalysis/ruby/index.js +11 -0
  106. package/src/scan/autoDetection.js +24 -26
  107. package/src/scan/fileUtils.js +60 -20
  108. package/src/scan/formatScanOutput.ts +14 -15
  109. package/src/scan/models/groupedResultsModel.ts +3 -3
  110. package/src/scan/models/resultContentModel.ts +1 -1
  111. package/src/scan/models/scanResultsModel.ts +5 -2
  112. package/src/scan/populateProjectIdAndProjectName.js +3 -1
  113. package/src/scan/scan.ts +1 -0
  114. package/src/scan/scanConfig.js +7 -5
  115. package/src/scan/scanController.js +18 -4
  116. package/src/scan/scanResults.js +10 -0
  117. package/src/utils/commonApi.js +4 -1
  118. package/src/utils/filterProjectPath.js +6 -2
  119. package/src/utils/getConfig.ts +1 -12
  120. package/dist/audit/AnalysisEngine.js +0 -37
  121. package/dist/audit/autodetection/autoDetectLanguage.js +0 -32
  122. package/dist/audit/dotnetAnalysisEngine/index.js +0 -25
  123. package/dist/audit/dotnetAnalysisEngine/parseLockFileContents.js +0 -35
  124. package/dist/audit/dotnetAnalysisEngine/parseProjectFileContents.js +0 -15
  125. package/dist/audit/dotnetAnalysisEngine/readLockFileContents.js +0 -18
  126. package/dist/audit/dotnetAnalysisEngine/readProjectFileContents.js +0 -14
  127. package/dist/audit/dotnetAnalysisEngine/sanitizer.js +0 -9
  128. package/dist/audit/goAnalysisEngine/index.js +0 -17
  129. package/dist/audit/goAnalysisEngine/parseProjectFileContents.js +0 -164
  130. package/dist/audit/goAnalysisEngine/readProjectFileContents.js +0 -21
  131. package/dist/audit/goAnalysisEngine/sanitizer.js +0 -5
  132. package/dist/audit/javaAnalysisEngine/index.js +0 -34
  133. package/dist/audit/javaAnalysisEngine/parseMavenProjectFileContents.js +0 -153
  134. package/dist/audit/javaAnalysisEngine/parseProjectFileContents.js +0 -353
  135. package/dist/audit/javaAnalysisEngine/readProjectFileContents.js +0 -98
  136. package/dist/audit/javaAnalysisEngine/sanitizer.js +0 -5
  137. package/dist/audit/languageAnalysisEngine/checkForMultipleIdentifiedLanguages.js +0 -24
  138. package/dist/audit/languageAnalysisEngine/checkForMultipleIdentifiedProjectFiles.js +0 -24
  139. package/dist/audit/languageAnalysisEngine/checkIdentifiedLanguageHasLockFile.js +0 -35
  140. package/dist/audit/languageAnalysisEngine/checkIdentifiedLanguageHasProjectFile.js +0 -23
  141. package/dist/audit/languageAnalysisEngine/constants.js +0 -20
  142. package/dist/audit/languageAnalysisEngine/getIdentifiedLanguageInfo.js +0 -25
  143. package/dist/audit/languageAnalysisEngine/index.js +0 -39
  144. package/dist/audit/languageAnalysisEngine/languageAnalysisFactory.js +0 -87
  145. package/dist/audit/languageAnalysisEngine/reduceIdentifiedLanguages.js +0 -150
  146. package/dist/audit/nodeAnalysisEngine/handleNPMLockFileV2.js +0 -40
  147. package/dist/audit/nodeAnalysisEngine/index.js +0 -31
  148. package/dist/audit/nodeAnalysisEngine/parseNPMLockFileContents.js +0 -18
  149. package/dist/audit/nodeAnalysisEngine/parseYarnLockFileContents.js +0 -18
  150. package/dist/audit/nodeAnalysisEngine/readNPMLockFileContents.js +0 -17
  151. package/dist/audit/nodeAnalysisEngine/readProjectFileContents.js +0 -14
  152. package/dist/audit/nodeAnalysisEngine/readYarnLockFileContents.js +0 -24
  153. package/dist/audit/nodeAnalysisEngine/sanitizer.js +0 -9
  154. package/dist/audit/phpAnalysisEngine/index.js +0 -23
  155. package/dist/audit/phpAnalysisEngine/parseLockFileContents.js +0 -52
  156. package/dist/audit/phpAnalysisEngine/readLockFileContents.js +0 -13
  157. package/dist/audit/phpAnalysisEngine/readProjectFileContents.js +0 -16
  158. package/dist/audit/phpAnalysisEngine/sanitizer.js +0 -5
  159. package/dist/audit/pythonAnalysisEngine/index.js +0 -25
  160. package/dist/audit/pythonAnalysisEngine/parsePipfileLockContents.js +0 -17
  161. package/dist/audit/pythonAnalysisEngine/parseProjectFileContents.js +0 -21
  162. package/dist/audit/pythonAnalysisEngine/readPipfileLockFileContents.js +0 -13
  163. package/dist/audit/pythonAnalysisEngine/readPythonProjectFileContents.js +0 -14
  164. package/dist/audit/pythonAnalysisEngine/sanitizer.js +0 -7
  165. package/dist/audit/rubyAnalysisEngine/index.js +0 -25
  166. package/dist/audit/rubyAnalysisEngine/parseGemfileLockContents.js +0 -176
  167. package/dist/audit/rubyAnalysisEngine/parsedGemfile.js +0 -22
  168. package/dist/audit/rubyAnalysisEngine/readGemfileContents.js +0 -14
  169. package/dist/audit/rubyAnalysisEngine/readGemfileLockContents.js +0 -14
  170. package/dist/audit/rubyAnalysisEngine/sanitizer.js +0 -6
  171. package/src/audit/AnalysisEngine.js +0 -103
  172. package/src/audit/autodetection/autoDetectLanguage.ts +0 -40
  173. package/src/audit/dotnetAnalysisEngine/index.js +0 -26
  174. package/src/audit/dotnetAnalysisEngine/parseLockFileContents.js +0 -47
  175. package/src/audit/dotnetAnalysisEngine/parseProjectFileContents.js +0 -29
  176. package/src/audit/dotnetAnalysisEngine/readLockFileContents.js +0 -30
  177. package/src/audit/dotnetAnalysisEngine/readProjectFileContents.js +0 -26
  178. package/src/audit/dotnetAnalysisEngine/sanitizer.js +0 -11
  179. package/src/audit/goAnalysisEngine/index.js +0 -18
  180. package/src/audit/goAnalysisEngine/parseProjectFileContents.js +0 -209
  181. package/src/audit/goAnalysisEngine/readProjectFileContents.js +0 -31
  182. package/src/audit/goAnalysisEngine/sanitizer.js +0 -7
  183. package/src/audit/javaAnalysisEngine/index.js +0 -41
  184. package/src/audit/javaAnalysisEngine/parseMavenProjectFileContents.js +0 -222
  185. package/src/audit/javaAnalysisEngine/parseProjectFileContents.js +0 -420
  186. package/src/audit/javaAnalysisEngine/readProjectFileContents.js +0 -141
  187. package/src/audit/javaAnalysisEngine/sanitizer.js +0 -6
  188. package/src/audit/languageAnalysisEngine/checkForMultipleIdentifiedLanguages.js +0 -35
  189. package/src/audit/languageAnalysisEngine/checkForMultipleIdentifiedProjectFiles.js +0 -41
  190. package/src/audit/languageAnalysisEngine/checkIdentifiedLanguageHasLockFile.js +0 -54
  191. package/src/audit/languageAnalysisEngine/checkIdentifiedLanguageHasProjectFile.js +0 -32
  192. package/src/audit/languageAnalysisEngine/constants.js +0 -23
  193. package/src/audit/languageAnalysisEngine/getIdentifiedLanguageInfo.js +0 -41
  194. package/src/audit/languageAnalysisEngine/index.js +0 -45
  195. package/src/audit/languageAnalysisEngine/languageAnalysisFactory.js +0 -116
  196. package/src/audit/languageAnalysisEngine/reduceIdentifiedLanguages.js +0 -249
  197. package/src/audit/nodeAnalysisEngine/handleNPMLockFileV2.js +0 -49
  198. package/src/audit/nodeAnalysisEngine/index.js +0 -35
  199. package/src/audit/nodeAnalysisEngine/parseNPMLockFileContents.js +0 -20
  200. package/src/audit/nodeAnalysisEngine/parseYarnLockFileContents.js +0 -26
  201. package/src/audit/nodeAnalysisEngine/readNPMLockFileContents.js +0 -23
  202. package/src/audit/nodeAnalysisEngine/readProjectFileContents.js +0 -27
  203. package/src/audit/nodeAnalysisEngine/readYarnLockFileContents.js +0 -36
  204. package/src/audit/nodeAnalysisEngine/sanitizer.js +0 -11
  205. package/src/audit/phpAnalysisEngine/index.js +0 -27
  206. package/src/audit/phpAnalysisEngine/parseLockFileContents.js +0 -60
  207. package/src/audit/phpAnalysisEngine/readLockFileContents.js +0 -14
  208. package/src/audit/phpAnalysisEngine/readProjectFileContents.js +0 -25
  209. package/src/audit/phpAnalysisEngine/sanitizer.js +0 -4
  210. package/src/audit/pythonAnalysisEngine/index.js +0 -55
  211. package/src/audit/pythonAnalysisEngine/parsePipfileLockContents.js +0 -23
  212. package/src/audit/pythonAnalysisEngine/parseProjectFileContents.js +0 -33
  213. package/src/audit/pythonAnalysisEngine/readPipfileLockFileContents.js +0 -16
  214. package/src/audit/pythonAnalysisEngine/readPythonProjectFileContents.js +0 -22
  215. package/src/audit/pythonAnalysisEngine/sanitizer.js +0 -9
  216. package/src/audit/rubyAnalysisEngine/index.js +0 -30
  217. package/src/audit/rubyAnalysisEngine/parseGemfileLockContents.js +0 -215
  218. package/src/audit/rubyAnalysisEngine/parsedGemfile.js +0 -39
  219. package/src/audit/rubyAnalysisEngine/readGemfileContents.js +0 -18
  220. package/src/audit/rubyAnalysisEngine/readGemfileLockContents.js +0 -17
  221. package/src/audit/rubyAnalysisEngine/sanitizer.js +0 -8
package/src/constants.js CHANGED
@@ -49,7 +49,6 @@ const scanOptionDefinitions = [
49
49
  },
50
50
  {
51
51
  name: 'project-path',
52
- alias: 'i',
53
52
  description:
54
53
  '{bold ' +
55
54
  i18n.__('constantsOptional') +
@@ -212,13 +211,14 @@ const auditOptionDefinitions = [
212
211
  i18n.__('constantsApplicationName')
213
212
  },
214
213
  {
215
- name: 'project-path',
216
- defaultValue: process.env.PWD,
214
+ name: 'file',
215
+ alias: 'f',
216
+ defaultValue: process.cwd(),
217
217
  description:
218
218
  '{bold ' +
219
219
  i18n.__('constantsOptional') +
220
220
  '}: ' +
221
- i18n.__('constantsProjectPath')
221
+ i18n.__('constantsFilePath')
222
222
  },
223
223
  {
224
224
  name: 'app-groups',
@@ -266,15 +266,6 @@ const auditOptionDefinitions = [
266
266
  {
267
267
  name: 'maven-settings-path'
268
268
  },
269
- {
270
- name: 'language',
271
- alias: 'l',
272
- description:
273
- '{bold ' +
274
- i18n.__('constantsRequiredCatalogue') +
275
- '}: ' +
276
- i18n.__('constantsLanguage')
277
- },
278
269
  {
279
270
  name: 'organization-id',
280
271
  alias: 'o',
@@ -333,7 +324,23 @@ const auditOptionDefinitions = [
333
324
  '{bold ' +
334
325
  i18n.__('constantsOptional') +
335
326
  '}: ' +
336
- i18n.__('auditOptionsSaveDescription')
327
+ i18n.__('auditOptionsSaveDescription') +
328
+ i18n.__('auditOptionsSaveOptionsDescription')
329
+ },
330
+ {
331
+ name: 'experimental',
332
+ alias: 'e',
333
+ type: Boolean
334
+ },
335
+ {
336
+ name: 'timeout',
337
+ alias: 't',
338
+ type: Number,
339
+ description:
340
+ '{bold ' +
341
+ i18n.__('constantsOptional') +
342
+ '}: ' +
343
+ i18n.__('scanOptionsTimeoutSummary')
337
344
  }
338
345
  ]
339
346
 
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
 
@@ -0,0 +1,9 @@
1
+ import { getHttpClient } from '../utils/commonApi'
2
+ import { getAuth } from '../utils/paramsUtil/paramHandler'
3
+ import { AnalyticsOption } from './types'
4
+
5
+ export const postAnalytics = (data: AnalyticsOption, provider = 'aws') => {
6
+ const config = getAuth()
7
+ const client = getHttpClient(config)
8
+ return client.postAnalyticsFunction(config, provider, data)
9
+ }
package/src/lambda/arn.ts CHANGED
@@ -10,7 +10,8 @@ type ARN = {
10
10
  resourceId?: string
11
11
  }
12
12
 
13
- const ARN_REGEX = /arn:(?<partition>[^:\n]*):(?<service>[^:\n]*):(?<region>[^:\n]*):(?<accountId>[^:\n]*):(?<ignore>(?<resource>[^:/\n]*)[:/])?(?<resourceId>.*)/
13
+ const ARN_REGEX =
14
+ /arn:(?<partition>[^:\n]*):(?<service>[^:\n]*):(?<region>[^:\n]*):(?<accountId>[^:\n]*):(?<ignore>(?<resource>[^:/\n]*)[:/])?(?<resourceId>.*)/
14
15
 
15
16
  const parseARN = (arn: string | undefined) => {
16
17
  if (!arn) {
@@ -14,18 +14,9 @@ import { printResults } from './utils'
14
14
  import { getAllLambdas, printAvailableLambdas } from './lambdaUtils'
15
15
  import { sleep } from '../utils/requestUtils'
16
16
  import ora from '../utils/oraWrapper'
17
-
18
- type LambdaOptions = {
19
- functionName?: string
20
- listFunctions?: boolean
21
- region?: string
22
- endpointUrl?: string
23
- profile?: string
24
- help?: boolean
25
- verbose?: boolean
26
- jsonOutput?: boolean
27
- _unknown?: string[]
28
- }
17
+ import { postAnalytics } from './analytics'
18
+ import { LambdaOptions, AnalyticsOption, StatusType, EventType } from './types'
19
+ import { APP_VERSION } from '../constants/constants'
29
20
 
30
21
  type ApiParams = {
31
22
  organizationId: string
@@ -74,10 +65,21 @@ const getLambdaOptions = (argv: string[]) => {
74
65
  }
75
66
 
76
67
  const processLambda = async (argv: string[]) => {
68
+ let errorMsg
69
+ let scanInfo: { functionArn: string; scanId: string } | undefined
70
+ const commandSessionId = Date.now().toString(36)
77
71
  try {
78
72
  const lambdaOptions = getLambdaOptions(argv)
79
73
  const { help } = lambdaOptions
80
-
74
+ const startCommandAnalytics: AnalyticsOption = {
75
+ arguments: lambdaOptions,
76
+ sessionId: commandSessionId,
77
+ eventType: EventType.START,
78
+ packageVersion: APP_VERSION
79
+ }
80
+ postAnalytics(startCommandAnalytics).catch((error: Error) => {
81
+ /* ignore */
82
+ })
81
83
  if (help) {
82
84
  return handleLambdaHelp()
83
85
  }
@@ -87,15 +89,34 @@ const processLambda = async (argv: string[]) => {
87
89
  if (lambdaOptions.listFunctions) {
88
90
  await getAvailableFunctions(lambdaOptions)
89
91
  } else {
90
- await actualProcessLambda(lambdaOptions)
92
+ scanInfo = await actualProcessLambda(lambdaOptions)
91
93
  }
92
94
  } catch (error) {
93
95
  if (error instanceof CliError) {
94
- console.error(error.getErrorMessage())
96
+ errorMsg = error.getErrorMessage()
95
97
  } else if (error instanceof Error) {
96
- console.error(error.message)
98
+ errorMsg = error.message
99
+ }
100
+ } finally {
101
+ const endCommandAnalytics: AnalyticsOption = {
102
+ sessionId: commandSessionId,
103
+ eventType: EventType.END,
104
+ status: errorMsg ? StatusType.FAILED : StatusType.SUCCESS,
105
+ packageVersion: APP_VERSION
106
+ }
107
+ if (errorMsg) {
108
+ endCommandAnalytics.errorMsg = errorMsg
109
+ console.error(errorMsg)
110
+ }
111
+ if (scanInfo) {
112
+ endCommandAnalytics.scanFunctionData = scanInfo
113
+ }
114
+ await postAnalytics(endCommandAnalytics).catch((error: Error) => {
115
+ /* ignore */
116
+ })
117
+ if (errorMsg) {
118
+ process.exit(1)
97
119
  }
98
- process.exit(1)
99
120
  }
100
121
  }
101
122
 
@@ -162,6 +183,8 @@ const actualProcessLambda = async (lambdaOptions: LambdaOptions) => {
162
183
  if (results?.length) {
163
184
  printResults(results)
164
185
  }
186
+
187
+ return { functionArn, scanId }
165
188
  }
166
189
 
167
190
  const validateRequiredLambdaParams = (options: LambdaOptions) => {
@@ -0,0 +1,36 @@
1
+ export enum StatusType {
2
+ FAILED = 'failed',
3
+ SUCCESS = 'success'
4
+ }
5
+
6
+ export enum EventType {
7
+ START = 'start_command_session',
8
+ END = 'end_command_session'
9
+ }
10
+
11
+ export type LambdaOptions = {
12
+ functionName?: string
13
+ listFunctions?: boolean
14
+ region?: string
15
+ endpointUrl?: string
16
+ profile?: string
17
+ help?: boolean
18
+ verbose?: boolean
19
+ jsonOutput?: boolean
20
+ _unknown?: string[]
21
+ }
22
+
23
+ type ScanFunctionData = {
24
+ functionArn: string
25
+ scanId: string
26
+ }
27
+
28
+ export type AnalyticsOption = {
29
+ sessionId: string
30
+ eventType: EventType
31
+ packageVersion: string
32
+ arguments?: LambdaOptions
33
+ scanFunctionData?: ScanFunctionData
34
+ status?: StatusType
35
+ errorMsg?: string
36
+ }
@@ -19,13 +19,8 @@ class PrintVulnerability {
19
19
  whatHappened: string
20
20
 
21
21
  constructor(index: number, vulnerability: any, group?: any[]) {
22
- const {
23
- severityText,
24
- title,
25
- description,
26
- remediation,
27
- categoryText
28
- } = vulnerability
22
+ const { severityText, title, description, remediation, categoryText } =
23
+ vulnerability
29
24
 
30
25
  this.group = group
31
26
  this.vulnerability = vulnerability
@@ -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: {
@@ -14,7 +29,39 @@ const createGoTSMessage = goTree => {
14
29
  }
15
30
  }
16
31
 
32
+ const createRubyTSMessage = rubyTree => {
33
+ return {
34
+ ruby: rubyTree
35
+ }
36
+ }
37
+
38
+ const createPythonTSMessage = pythonTree => {
39
+ return {
40
+ python: pythonTree
41
+ }
42
+ }
43
+
44
+ const createPhpTSMessage = phpTree => {
45
+ return {
46
+ php: {
47
+ composerJSON: phpTree.composerJSON,
48
+ lockFile: phpTree.lockFile
49
+ }
50
+ }
51
+ }
52
+
53
+ const createDotNetTSMessage = dotnetTree => {
54
+ return {
55
+ dotnet: dotnetTree
56
+ }
57
+ }
58
+
17
59
  module.exports = {
60
+ createJavaScriptTSMessage,
18
61
  createJavaTSMessage,
19
- createGoTSMessage
62
+ createGoTSMessage,
63
+ createPhpTSMessage,
64
+ createRubyTSMessage,
65
+ createPythonTSMessage,
66
+ createDotNetTSMessage
20
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
+ }
@@ -5,9 +5,8 @@ const goParseDeps = require('./goParseDeps')
5
5
  const goAnalysis = (config, languageFiles) => {
6
6
  try {
7
7
  const rawGoDependencies = goReadDepFile.getGoDependencies(config)
8
- const parsedGoDependencies = goParseDeps.parseGoDependencies(
9
- rawGoDependencies
10
- )
8
+ const parsedGoDependencies =
9
+ goParseDeps.parseGoDependencies(rawGoDependencies)
11
10
 
12
11
  return createGoTSMessage(parsedGoDependencies)
13
12
  } catch (e) {
@@ -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,21 +6,20 @@ 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')) {
13
13
  projectData.projectType = MAVEN
14
- projectData.cwd = projectPath
15
- ? projectPath
16
- : files[0].replace('pom.xml', '')
17
14
  } else if (files[0].includes('build.gradle')) {
18
15
  projectData.projectType = GRADLE
19
- projectData.cwd = projectPath
20
- ? projectPath
21
- : files[0].replace('pom.xml', '')
22
16
  }
23
17
 
18
+ //clean up the path to be a folder not a file
19
+ projectData.cwd = file
20
+ ? file.replace('pom.xml', '').replace('build.gradle', '')
21
+ : file
22
+
24
23
  return projectData
25
24
  }
26
25
 
@@ -125,7 +124,7 @@ const getJavaBuildDeps = (config, files) => {
125
124
  }
126
125
 
127
126
  try {
128
- const projectData = determineProjectTypeAndCwd(files, config.projectPath)
127
+ const projectData = determineProjectTypeAndCwd(files, config.file)
129
128
  if (projectData.projectType === MAVEN) {
130
129
  output.mvnDependancyTreeOutput = buildMaven(config, projectData, timeout)
131
130
  } else if (projectData.projectType === GRADLE) {
@@ -3,11 +3,11 @@ const { parseBuildDeps } = require('./javaBuildDepsParser')
3
3
  const { createJavaTSMessage } = require('../common/formatMessage')
4
4
 
5
5
  const javaAnalysis = (config, languageFiles) => {
6
- languageFiles.java.forEach(file => {
6
+ languageFiles.JAVA.forEach(file => {
7
7
  file.replace('build.gradle.kts', 'build.gradle')
8
8
  })
9
9
 
10
- const javaDeps = buildJavaTree(config, languageFiles.java)
10
+ const javaDeps = buildJavaTree(config, languageFiles.JAVA)
11
11
  return createJavaTSMessage(javaDeps)
12
12
  }
13
13