@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
@@ -12,7 +12,7 @@ const MEDIUM = 'MEDIUM';
12
12
  const HIGH = 'HIGH';
13
13
  const CRITICAL = 'CRITICAL';
14
14
  const APP_NAME = 'contrast';
15
- const APP_VERSION = '1.0.6';
15
+ const APP_VERSION = '1.0.9';
16
16
  const TIMEOUT = 120000;
17
17
  const HIGH_COLOUR = '#ff9900';
18
18
  const CRITICAL_COLOUR = '#e35858';
@@ -27,9 +27,12 @@ const NOTE_PRIORITY = 5;
27
27
  const AUTH_UI_URL = 'https://cli-auth.contrastsecurity.com';
28
28
  const AUTH_CALLBACK_URL = 'https://cli-auth-api.contrastsecurity.com';
29
29
  const SARIF_FILE = 'SARIF';
30
+ const SBOM_CYCLONE_DX_FILE = 'cyclonedx';
31
+ const SBOM_SPDX_FILE = 'spdx';
30
32
  const CE_URL = 'https://ce.contrastsecurity.com/';
31
33
  module.exports = {
32
34
  supportedLanguages: { NODE, DOTNET, JAVA, RUBY, PYTHON, GO, PHP, JAVASCRIPT },
35
+ supportedLanguagesScan: { JAVASCRIPT, DOTNET, JAVA },
33
36
  LOW,
34
37
  MEDIUM,
35
38
  HIGH,
@@ -50,5 +53,7 @@ module.exports = {
50
53
  HIGH_PRIORITY,
51
54
  MEDIUM_PRIORITY,
52
55
  LOW_PRIORITY,
53
- NOTE_PRIORITY
56
+ NOTE_PRIORITY,
57
+ SBOM_CYCLONE_DX_FILE,
58
+ SBOM_SPDX_FILE
54
59
  };
@@ -12,7 +12,7 @@ const en_locales = () => {
12
12
  vulnerabilitiesFailureMessage: 'Unable to retrieve library vulnerabilities',
13
13
  catchErrorMessage: 'Contrast UI error: ',
14
14
  dependenciesNote: 'Please Note: We currently only support projects with one .csproj AND *.package.lock.json',
15
- languageAnalysisFailureMessage: 'SCA Analysis Failure',
15
+ languageAnalysisFailureMessage: 'SCA audit Failure',
16
16
  languageAnalysisFactoryFailureHeader: 'FAIL',
17
17
  libraryAnalysisError: 'Please ensure the language parameter is set in accordance to the language specified on the project path.\nContrast CLI must be run in the same directory as the project manifest file OR the project_path parameter must be used to identify the directory containing the project manifest file.\n\nFor further information please read our usage guide, which can be accessed with the following command:\n\ncontrast-cli --help',
18
18
  yamlMissingParametersHeader: 'Missing Parameters',
@@ -38,20 +38,22 @@ const en_locales = () => {
38
38
  languageAnalysisMultipleLanguages2: 'Please specify which project file you would like analyzed with the %s CLI option.',
39
39
  languageAnalysisProjectFiles: "Identified project language as '%s' but found multiple project files: %s. Please specify which project file you would like analyzed with the %s CLI option.",
40
40
  languageAnalysisHasNoLockFile: "Identified project language as '%s' but no project lock file was found.",
41
- languageAnalysisHasMultipleLockFiles: "Identified project language as '%s' but multiple project lock files were found: %s \n",
41
+ languageAnalysisHasNoPackageJsonFile: 'Identified project language as javascript but no package.json file was found.',
42
+ languageAnalysisHasMultipleLockFiles: "Identified project language as '%s' but multiple project lock files were found.",
42
43
  languageAnalysisProjectFileError: "Identified project language as '%s' but no project file was found.",
43
44
  languageAnalysisProjectRootFileNameReadError: 'Failed to read the contents of the directory @ %s because: ',
44
45
  languageAnalysisProjectRootFileNameMissingError: "%s isn't a file or directory",
45
46
  languageAnalysisProjectRootFileNameFailure: 'Failed to get information about the file or directory @ %s because: ',
46
47
  languageAnalysisFailure: ' analysis failed because: ',
47
- languageAnalysisNoLanguage: 'No language detected in project path @ %s',
48
+ languageAnalysisNoLanguage: 'We cannot detect a project, use --f <path> to specify a file or folder to analyze.',
49
+ languageAnalysisNoLanguageHelpLine: `${chalk.bold('contrast audit --help')} for more information.`,
48
50
  NodeAnalysisFailure: 'NODE analysis failed because: ',
49
51
  phpAnalysisFailure: 'PHP analysis failed because: ',
50
- NodeParseNPM: "Failed to parse NODE package-lock.json file @ '%s' because: ",
52
+ NodeParseNPM: 'Failed to parse NODE package-lock.json file because: ',
51
53
  phpParseComposerLock: "Failed to parse PHP composer.lock file @ '%s' because: ",
52
54
  NodeReadNpmError: 'Failed to read the package-lock.json file @ "%s" because: ',
53
55
  phpReadError: 'Failed to read the composer.lock file @ "%s" because: ',
54
- NodeParseYarn: "Failed to parse Node yarn.lock version 1 @ '%s' because: ",
56
+ NodeParseYarn: 'Failed to parse yarn.lock version %s because: ',
55
57
  NodeParseYarn2: "Failed to parse Node yarn.lock version 2 @ '%s' because: ",
56
58
  nodeReadProjectFileError: 'Failed to read the NODE project file @ "%s" because: ',
57
59
  phpReadProjectFileError: 'Failed to read the PHP project file @ "%s" because: ',
@@ -78,7 +80,7 @@ const en_locales = () => {
78
80
  constantsApplicationName: 'The name of the application cataloged by Contrast UI',
79
81
  constantsCatalogueApplication: 'Provide this if you want to catalogue an application',
80
82
  constantsLanguage: 'Valid values are JAVA, DOTNET, NODE, PYTHON and RUBY. If there are multiple project configuration files in the project_path, language is also required. Also, provide this when cataloguing an application',
81
- constantsProjectPath: 'The directory root of a project/application that you would like analyzed. Defaults to current directory.',
83
+ constantsFilePath: `Path of the file you want to perform an SCA audit on. If no folder is specified, Contrast searches for dependency files in the working directory.`,
82
84
  constantsSilent: 'Silences JSON output.',
83
85
  constantsAppGroups: 'Assign your application to one or more pre-existing groups when using the catalogue command. Group lists should be comma separated.',
84
86
  constantsVersion: 'Displays CLI Version you are currently on.',
@@ -90,13 +92,13 @@ const en_locales = () => {
90
92
  constantsProjectName: 'Contrast project name. If not specified, Contrast uses contrast.settings to identify the project or creates a project.',
91
93
  constantsProjectId: 'The ID associated with a scan project. Replace <ProjectID> with the ID for the scan project. To find the ID, select a scan project in Contrast and locate the last number in the URL.',
92
94
  constantsReport: 'Display vulnerability information for this application',
93
- constantsFail: 'Set the process to fail if this option is set in combination with the --report and --cve_severity.',
94
- failOptionErrorMessage: " FAIL - CVE's have been detected that match at least the cve_severity or cve_threshold option specified.",
95
- constantsSeverity: 'Combined with the --report command, allows the user to report libraries with vulnerabilities above a chosen severity level. For example, cve_severity medium only reports libraries with vulnerabilities at medium or higher severity. Values for level are high, medium or low.',
96
- constantsCount: "The number of CVE's that must be exceeded to fail a build",
95
+ constantsFail: 'Set the process to fail if this option is set in combination with --cve_severity.',
96
+ failOptionErrorMessage: ' FAIL - CVEs have been detected that match at least the cve_severity or cve_threshold option specified.',
97
+ constantsSeverity: 'Allows the user to report libraries with vulnerabilities above a chosen severity level. For example, cve_severity medium only reports libraries with vulnerabilities at medium or higher severity. Values for level are high, medium or low.',
98
+ constantsCount: 'The number of CVEs that must be exceeded to fail a build',
97
99
  constantsHeader: 'CodeSec by Contrast Security',
98
- constantsPrerequisitesContentScanLanguages: 'Java & JavaScript supported',
99
- constantsContrastContent: 'Use the Contrast CLI to run a scan (Java, JavaScript and .NET ) or lambda command (Java and Python) to find your vulnerabilities and start securing your code.',
100
+ constantsPrerequisitesContentScanLanguages: 'Java, Javascript and .NET supported',
101
+ constantsContrastContent: "Use the 'contrast' command for fast and accurate security analysis of your applications and APIs (Java, JavaScript and .NET ) as well as serverless functions (AWS lambda, Java and Python).",
100
102
  constantsUsageGuideContentRecommendation: 'Our recommendation is that this is invoked as part of a CI pipeline so that running the cli is automated as part of your build process.',
101
103
  constantsPrerequisitesHeader: 'Pre-requisites',
102
104
  constantsAuthUsageHeader: 'Usage',
@@ -162,7 +164,7 @@ const en_locales = () => {
162
164
  constantsIgnoreCertErrors: 'For EOP users with a local Teamserver install, this will bypass the SSL certificate and recognise a self signed certificate.',
163
165
  constantsSave: 'Saves the Scan Results SARIF to file.',
164
166
  scanLabel: "adds a label to the scan - defaults to 'Started by CLI tool at current date'",
165
- constantsIgnoreDev: 'Combined with the --report command excludes developer dependencies from the vulnerabilities report. By default all dependencies are included in a report.',
167
+ constantsIgnoreDev: 'Excludes developer dependencies from the results. All dependencies are included by default.',
166
168
  constantsCommands: 'Commands',
167
169
  constantsScanOptions: 'Scan Options',
168
170
  sbomError: 'All required parameters are not present.',
@@ -247,40 +249,34 @@ const en_locales = () => {
247
249
  redirectAuth: '\nOpening the authentication page in your web browser.\nSign in and complete the steps.\nReturn here to start using Contrast.\n\nIf your browser has trouble loading, try this:\n%s \n',
248
250
  scanZipError: 'A .zip archive can be used for Javascript Scan. Archive found %s does not contain .JS files for Scan.',
249
251
  fileNotExist: 'File specified does not exist, please check and try again.',
252
+ scanFileIsEmpty: 'File specified is empty. Please choose another.',
250
253
  fileHasWhiteSpacesError: 'File cannot have spaces, please rename or choose another file to Scan.',
251
254
  zipFileException: 'Error reading zip file',
252
255
  connectionError: 'An error has occurred when trying to get the Project Id please check your internet connection or provide the Project Id manually',
253
256
  internalServerErrorHeader: '500 error - Internal server error',
254
257
  resourceLockedErrorHeader: '423 error - Resource is locked',
255
- auditHeader: 'Contrast Audit',
256
- auditHeaderMessage: `
257
- Performs software composition analysis (SCA) on your application/code time to show you the dependencies between open source libraries, including where vulnerabilities were introduced.\n
258
- Our recommendation is that this is invoked as part of a CI pipeline so that running the cli is automated as part of your build process.`,
258
+ auditHeader: 'Contrast audit help',
259
+ auditHeaderMessage: "Use 'contrast audit' to analyze a project’s dependencies for vulnerabilities.",
259
260
  constantsAuditPrerequisitesContentSupportedLanguages: 'Supported languages and their requirements are:',
260
- constantsAuditPrerequisitesContentJava: 'Java: ',
261
- constantsAuditPrerequisitesContentMessage: `
262
- pom.xml AND Maven build platform, including the dependency plugin.
263
- For a Gradle project (v4.8+) use build.gradle. A gradle-wrapper.properties file is also required.
264
- Kotlin is also supported requiring a build.gradle.kts file.`,
265
- constantsAuditPrerequisitesContentDotNet: '.NET framework and .NET core: ',
261
+ constantsAuditPrerequisitesJavaContentMessage: `
262
+ ${chalk.bold('Java:')} pom.xml ${chalk.bold('and')} Maven build platform including the dependency plugin.
263
+ ${chalk.bold('Or')} build.gradle ${chalk.bold('and')} gradle dependencies or ./gradlew dependencies must be supported`,
266
264
  constantsAuditPrerequisitesContentDotNetMessage: `
267
- MSBuild 15.0 or greater and have a packages.lock.json file are supported.\n
268
- Note: If the packages.lock.json file is unavailable it can be generated by setting RestorePackagesWithLockFile to true within each *.csproj file and running dotnet build.\n`,
269
- constantsAuditPrerequisitesContentLanguageNode: 'Node: ',
270
- constantsAuditPrerequisitesContentLanguageRuby: 'Ruby: ',
271
- constantsAuditPrerequisitesContentLanguagePython: 'Python: ',
272
- constantsAuditPrerequisitesContentLanguageNodeMessage: '*.package.json AND a lock file either *.package-lock.json or *.yarn.lock',
273
- constantsAuditPrerequisitesContentLanguageRubyMessage: 'gemfile AND gemfile.lock',
274
- constantsAuditPrerequisitesContentLanguagePythonMessage: 'pipfile AND pipfile.lock',
265
+ ${chalk.bold('.NET framework and .NET core:')} MSBuild 15.0 or greater and a packages.lock.json file.
266
+ Note: If the packages.lock.json file is unavailable it can be generated by setting RestorePackagesWithLockFile to true within each *.csproj file and running dotnet build.\n`,
267
+ constantsAuditPrerequisitesContentNodeMessage: `${chalk.bold('Node:')} package.json and a lock file (either .package-lock.json or .yarn.lock.)\n`,
268
+ constantsAuditPrerequisitesContentRubyMessage: `${chalk.bold('Ruby:')} gemfile and gemfile.lock\n`,
269
+ constantsAuditPrerequisitesContentPythonMessage: `${chalk.bold('Python:')} pipfile and pipfile.lock\n`,
270
+ constantsAuditPrerequisitesContentGoMessage: `${chalk.bold('Go:')} go.mod\n`,
271
+ constantsAuditPrerequisitesContentPHPMessage: `${chalk.bold('PHP:')} composer.json and composer.lock\n`,
275
272
  constantsAuditOptions: 'Audit Options',
276
- auditOptionsIgnoreDevDependencies: '-igd, --ignore-dev',
277
- auditOptionsIgnoreDevDependenciesDescription: 'ignores DevDependencies',
278
- auditOptionsSave: '-s, --save',
279
- auditOptionsSaveDescription: 'saves the output in specified format Txt text, sbom',
273
+ auditOptionsSaveDescription: 'Generate and save an SBOM (Software Bill of Materials)\n',
274
+ auditOptionsSaveOptionsDescription: 'Valid options are: spdx, cyclonedx (cycloneDX is the default format)',
280
275
  scanNotCompleted: 'Scan not completed. Check for framework and language support here: %s',
281
- scanNoVulnerabilitiesFound: '👏 No vulnerabilities found',
276
+ auditNotCompleted: 'audit not completed. Please try again',
277
+ scanNoVulnerabilitiesFound: '🎉 No vulnerabilities found.',
282
278
  scanNoVulnerabilitiesFoundSecureCode: '👍 Your code looks secure.',
283
- scanNoVulnerabilitiesFoundGoodWork: '👏 Keep up the good work.',
279
+ scanNoVulnerabilitiesFoundGoodWork: ' Keep up the good work.',
284
280
  scanNoFiletypeSpecifiedForSave: 'Please specify file type to save results to, accepted value is SARIF',
285
281
  auditSBOMSaveSuccess: '\n Software Bill of Materials (SBOM) saved successfully',
286
282
  auditNoFiletypeSpecifiedForSave: `\n ${chalk.yellow.bold('No file type specified for --save option to save audit results to. Use audit --help to see valid --save options.')}`,
@@ -289,7 +285,8 @@ const en_locales = () => {
289
285
  auditReportFail: 'Report Retrieval Failed, please try again',
290
286
  auditReportSuccessMessage: 'Report successfully retrieved',
291
287
  auditReportFailureMessage: 'Unable to generate library report',
292
- auditSCAAnalysisBegins: 'Contrast SCA analysis begins',
288
+ auditSCAAnalysisBegins: 'Contrast SCA audit started',
289
+ auditSCAAnalysisComplete: 'Contrast audit complete',
293
290
  ...lambda
294
291
  };
295
292
  };
package/dist/constants.js CHANGED
@@ -43,7 +43,6 @@ const scanOptionDefinitions = [
43
43
  },
44
44
  {
45
45
  name: 'project-path',
46
- alias: 'i',
47
46
  description: '{bold ' +
48
47
  i18n.__('constantsOptional') +
49
48
  '}: ' +
@@ -188,12 +187,13 @@ const auditOptionDefinitions = [
188
187
  i18n.__('constantsApplicationName')
189
188
  },
190
189
  {
191
- name: 'project-path',
192
- defaultValue: process.env.PWD,
190
+ name: 'file',
191
+ alias: 'f',
192
+ defaultValue: process.cwd(),
193
193
  description: '{bold ' +
194
194
  i18n.__('constantsOptional') +
195
195
  '}: ' +
196
- i18n.__('constantsProjectPath')
196
+ i18n.__('constantsFilePath')
197
197
  },
198
198
  {
199
199
  name: 'app-groups',
@@ -235,14 +235,6 @@ const auditOptionDefinitions = [
235
235
  {
236
236
  name: 'maven-settings-path'
237
237
  },
238
- {
239
- name: 'language',
240
- alias: 'l',
241
- description: '{bold ' +
242
- i18n.__('constantsRequiredCatalogue') +
243
- '}: ' +
244
- i18n.__('constantsLanguage')
245
- },
246
238
  {
247
239
  name: 'organization-id',
248
240
  alias: 'o',
@@ -294,7 +286,22 @@ const auditOptionDefinitions = [
294
286
  description: '{bold ' +
295
287
  i18n.__('constantsOptional') +
296
288
  '}: ' +
297
- i18n.__('auditOptionsSaveDescription')
289
+ i18n.__('auditOptionsSaveDescription') +
290
+ i18n.__('auditOptionsSaveOptionsDescription')
291
+ },
292
+ {
293
+ name: 'experimental',
294
+ alias: 'e',
295
+ type: Boolean
296
+ },
297
+ {
298
+ name: 'timeout',
299
+ alias: 't',
300
+ type: Number,
301
+ description: '{bold ' +
302
+ i18n.__('constantsOptional') +
303
+ '}: ' +
304
+ i18n.__('scanOptionsTimeoutSummary')
298
305
  }
299
306
  ];
300
307
  const mainUsageGuide = commandLineUsage([
package/dist/index.js CHANGED
@@ -1,3 +1,4 @@
1
+ #!/usr/bin/env node
1
2
  "use strict";
2
3
  var __importDefault = (this && this.__importDefault) || function (mod) {
3
4
  return (mod && mod.__esModule) ? mod : { "default": mod };
@@ -29,55 +30,64 @@ const getMainOption = () => {
29
30
  };
30
31
  };
31
32
  const start = async () => {
32
- if (await (0, versionChecker_1.isCorrectNodeVersion)(process.version)) {
33
- const { mainOptions, argv: argvMain } = getMainOption();
34
- const command = mainOptions.command != undefined ? mainOptions.command.toLowerCase() : '';
35
- if (command === 'version' ||
36
- argvMain.includes('--v') ||
37
- argvMain.includes('--version')) {
38
- console.log(constants_2.APP_VERSION);
39
- await (0, versionChecker_1.findLatestCLIVersion)(config.get('updateMessageHidden'));
40
- return;
41
- }
42
- config.set('numOfRuns', config.get('numOfRuns') + 1);
43
- if (config.get('numOfRuns') >= 5) {
44
- await (0, versionChecker_1.findLatestCLIVersion)(config.get('updateMessageHidden'));
45
- config.set('numOfRuns', 0);
46
- }
47
- if (command === 'config') {
48
- return (0, config_1.processConfig)(argvMain, config);
49
- }
50
- if (command === 'auth') {
51
- return await (0, auth_1.processAuth)(argvMain, config);
52
- }
53
- if (command === 'lambda') {
54
- return await (0, lambda_1.processLambda)(argvMain);
55
- }
56
- if (command === 'scan') {
57
- return await (0, processScan_1.processScan)(argvMain);
58
- }
59
- if (command === 'audit') {
60
- return await (0, processAudit_1.processAudit)(argvMain);
61
- }
62
- if (command === 'help' ||
63
- argvMain.includes('--help') ||
64
- Object.keys(mainOptions).length === 0) {
65
- console.log(mainUsageGuide);
66
- }
67
- else if (mainOptions._unknown !== undefined) {
68
- const foundCommand = (0, errorHandling_1.findCommandOnError)(mainOptions._unknown);
69
- foundCommand
70
- ? console.log(`Unknown Command: Did you mean "${foundCommand}"? \nUse "${foundCommand} --help" for the full list of options`)
71
- : console.log(`Unknown Command: ${command} \nUse --help for the full list`);
33
+ try {
34
+ if (await (0, versionChecker_1.isCorrectNodeVersion)(process.version)) {
35
+ const { mainOptions, argv: argvMain } = getMainOption();
36
+ const command = mainOptions.command != undefined
37
+ ? mainOptions.command.toLowerCase()
38
+ : '';
39
+ if (command === 'version' ||
40
+ argvMain.includes('--v') ||
41
+ argvMain.includes('--version')) {
42
+ console.log(constants_2.APP_VERSION);
43
+ await (0, versionChecker_1.findLatestCLIVersion)(config);
44
+ return;
45
+ }
46
+ config.set('numOfRuns', config.get('numOfRuns') + 1);
47
+ if (config.get('numOfRuns') >= 1) {
48
+ await (0, versionChecker_1.findLatestCLIVersion)(config);
49
+ config.set('numOfRuns', 0);
50
+ }
51
+ if (command === 'config') {
52
+ return (0, config_1.processConfig)(argvMain, config);
53
+ }
54
+ if (command === 'auth') {
55
+ return await (0, auth_1.processAuth)(argvMain, config);
56
+ }
57
+ if (command === 'lambda') {
58
+ return await (0, lambda_1.processLambda)(argvMain);
59
+ }
60
+ if (command === 'scan') {
61
+ return await (0, processScan_1.processScan)(argvMain);
62
+ }
63
+ if (command === 'audit') {
64
+ return await (0, processAudit_1.processAudit)(argvMain);
65
+ }
66
+ if (command === 'help' ||
67
+ argvMain.includes('--help') ||
68
+ Object.keys(mainOptions).length === 0) {
69
+ console.log(mainUsageGuide);
70
+ }
71
+ else if (mainOptions._unknown !== undefined) {
72
+ const foundCommand = (0, errorHandling_1.findCommandOnError)(mainOptions._unknown);
73
+ foundCommand
74
+ ? console.log(`Unknown Command: Did you mean "${foundCommand}"? \nUse "${foundCommand} --help" for the full list of options`)
75
+ : console.log(`Unknown Command: ${command} \nUse --help for the full list`);
76
+ }
77
+ else {
78
+ console.log(`Unknown Command: ${command} \nUse --help for the full list`);
79
+ }
80
+ process.exit(9);
72
81
  }
73
82
  else {
74
- console.log(`Unknown Command: ${command} \nUse --help for the full list`);
83
+ console.log('Contrast supports Node versions >=16.13.2 <17. Please use one of those versions.');
84
+ process.exit(9);
75
85
  }
76
- process.exit(9);
77
86
  }
78
- else {
79
- console.log('Contrast supports Node versions >=16.13.2 <17. Please use one of those versions.');
80
- process.exit(9);
87
+ catch (err) {
88
+ console.log();
89
+ console.log(err.message.toString());
90
+ process.exit(1);
81
91
  }
82
92
  };
83
93
  start();
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.postAnalytics = void 0;
4
+ const commonApi_1 = require("../utils/commonApi");
5
+ const paramHandler_1 = require("../utils/paramsUtil/paramHandler");
6
+ const postAnalytics = (data, provider = 'aws') => {
7
+ const config = (0, paramHandler_1.getAuth)();
8
+ const client = (0, commonApi_1.getHttpClient)(config);
9
+ return client.postAnalyticsFunction(config, provider, data);
10
+ };
11
+ exports.postAnalytics = postAnalytics;
@@ -20,6 +20,9 @@ const utils_1 = require("./utils");
20
20
  const lambdaUtils_1 = require("./lambdaUtils");
21
21
  const requestUtils_1 = require("../utils/requestUtils");
22
22
  const oraWrapper_1 = __importDefault(require("../utils/oraWrapper"));
23
+ const analytics_1 = require("./analytics");
24
+ const types_1 = require("./types");
25
+ const constants_2 = require("../constants/constants");
23
26
  const failedStates = [
24
27
  'UNSUPPORTED',
25
28
  'EXCLUDED',
@@ -57,9 +60,20 @@ const getLambdaOptions = (argv) => {
57
60
  }
58
61
  };
59
62
  const processLambda = async (argv) => {
63
+ let errorMsg;
64
+ let scanInfo;
65
+ const commandSessionId = Date.now().toString(36);
60
66
  try {
61
67
  const lambdaOptions = getLambdaOptions(argv);
62
68
  const { help } = lambdaOptions;
69
+ const startCommandAnalytics = {
70
+ arguments: lambdaOptions,
71
+ sessionId: commandSessionId,
72
+ eventType: types_1.EventType.START,
73
+ packageVersion: constants_2.APP_VERSION
74
+ };
75
+ (0, analytics_1.postAnalytics)(startCommandAnalytics).catch((error) => {
76
+ });
63
77
  if (help) {
64
78
  return handleLambdaHelp();
65
79
  }
@@ -68,17 +82,36 @@ const processLambda = async (argv) => {
68
82
  await getAvailableFunctions(lambdaOptions);
69
83
  }
70
84
  else {
71
- await actualProcessLambda(lambdaOptions);
85
+ scanInfo = await actualProcessLambda(lambdaOptions);
72
86
  }
73
87
  }
74
88
  catch (error) {
75
89
  if (error instanceof cliError_1.CliError) {
76
- console.error(error.getErrorMessage());
90
+ errorMsg = error.getErrorMessage();
77
91
  }
78
92
  else if (error instanceof Error) {
79
- console.error(error.message);
93
+ errorMsg = error.message;
94
+ }
95
+ }
96
+ finally {
97
+ const endCommandAnalytics = {
98
+ sessionId: commandSessionId,
99
+ eventType: types_1.EventType.END,
100
+ status: errorMsg ? types_1.StatusType.FAILED : types_1.StatusType.SUCCESS,
101
+ packageVersion: constants_2.APP_VERSION
102
+ };
103
+ if (errorMsg) {
104
+ endCommandAnalytics.errorMsg = errorMsg;
105
+ console.error(errorMsg);
106
+ }
107
+ if (scanInfo) {
108
+ endCommandAnalytics.scanFunctionData = scanInfo;
109
+ }
110
+ await (0, analytics_1.postAnalytics)(endCommandAnalytics).catch((error) => {
111
+ });
112
+ if (errorMsg) {
113
+ process.exit(1);
80
114
  }
81
- process.exit(1);
82
115
  }
83
116
  };
84
117
  exports.processLambda = processLambda;
@@ -127,6 +160,7 @@ const actualProcessLambda = async (lambdaOptions) => {
127
160
  if (results?.length) {
128
161
  (0, utils_1.printResults)(results);
129
162
  }
163
+ return { functionArn, scanId };
130
164
  };
131
165
  const validateRequiredLambdaParams = (options) => {
132
166
  if (options._unknown?.length) {
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.EventType = exports.StatusType = void 0;
4
+ var StatusType;
5
+ (function (StatusType) {
6
+ StatusType["FAILED"] = "failed";
7
+ StatusType["SUCCESS"] = "success";
8
+ })(StatusType = exports.StatusType || (exports.StatusType = {}));
9
+ var EventType;
10
+ (function (EventType) {
11
+ EventType["START"] = "start_command_session";
12
+ EventType["END"] = "end_command_session";
13
+ })(EventType = exports.EventType || (exports.EventType = {}));
@@ -1,10 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.generateSbom = void 0;
3
4
  const commonApi_1 = require("../utils/commonApi");
4
- function generateSbom(config) {
5
+ const generateSbom = (config, type) => {
5
6
  const client = (0, commonApi_1.getHttpClient)(config);
6
7
  return client
7
- .getSbom(config)
8
+ .getSbom(config, type)
8
9
  .then((res) => {
9
10
  if (res.statusCode === 200) {
10
11
  return res.body;
@@ -16,5 +17,5 @@ function generateSbom(config) {
16
17
  .catch((err) => {
17
18
  console.log(err);
18
19
  });
19
- }
20
- exports.default = generateSbom;
20
+ };
21
+ exports.generateSbom = generateSbom;
@@ -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
+ }
19
+ else {
20
+ message.node.npmLockFile = js.npmLockFile;
21
+ }
22
+ return message;
23
+ };
9
24
  const createGoTSMessage = goTree => {
10
25
  return {
11
26
  go: {
@@ -13,7 +28,35 @@ const createGoTSMessage = goTree => {
13
28
  }
14
29
  };
15
30
  };
31
+ const createRubyTSMessage = rubyTree => {
32
+ return {
33
+ ruby: rubyTree
34
+ };
35
+ };
36
+ const createPythonTSMessage = pythonTree => {
37
+ return {
38
+ python: pythonTree
39
+ };
40
+ };
41
+ const createPhpTSMessage = phpTree => {
42
+ return {
43
+ php: {
44
+ composerJSON: phpTree.composerJSON,
45
+ lockFile: phpTree.lockFile
46
+ }
47
+ };
48
+ };
49
+ const createDotNetTSMessage = dotnetTree => {
50
+ return {
51
+ dotnet: dotnetTree
52
+ };
53
+ };
16
54
  module.exports = {
55
+ createJavaScriptTSMessage,
17
56
  createJavaTSMessage,
18
- createGoTSMessage
57
+ createGoTSMessage,
58
+ createPhpTSMessage,
59
+ createRubyTSMessage,
60
+ createPythonTSMessage,
61
+ createDotNetTSMessage
19
62
  };
@@ -1,5 +1,5 @@
1
1
  "use strict";
2
- const { getHttpClient } = require('../../utils/commonApi');
2
+ const commonApi = require('../../utils/commonApi');
3
3
  const { APP_VERSION } = require('../../constants/constants');
4
4
  const commonSendSnapShot = async (analysis, config) => {
5
5
  const requestBody = {
@@ -7,21 +7,19 @@ const commonSendSnapShot = async (analysis, config) => {
7
7
  cliVersion: APP_VERSION,
8
8
  snapshot: analysis
9
9
  };
10
- const client = getHttpClient(config);
10
+ const client = commonApi.getHttpClient(config);
11
11
  return client
12
12
  .sendSnapshot(requestBody, config)
13
13
  .then(res => {
14
14
  if (res.statusCode === 201) {
15
- console.log('dependencies processed successfully');
16
15
  return res.body;
17
16
  }
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
  module.exports = {
@@ -0,0 +1,43 @@
1
+ "use strict";
2
+ const fs = require('fs');
3
+ const xml2js = require('xml2js');
4
+ const i18n = require('i18n');
5
+ const readAndParseProjectFile = projectFilePath => {
6
+ const projectFile = fs.readFileSync(projectFilePath);
7
+ return new xml2js.Parser({
8
+ explicitArray: false,
9
+ mergeAttrs: true
10
+ }).parseString(projectFile);
11
+ };
12
+ const readAndParseLockFile = lockFilePath => {
13
+ const lockFile = JSON.parse(fs.readFileSync(lockFilePath).toString());
14
+ let count = 0;
15
+ for (const dependenciesNode in lockFile.dependencies) {
16
+ for (const innerNode in lockFile.dependencies[dependenciesNode]) {
17
+ const nodeValidation = JSON.stringify(lockFile.dependencies[dependenciesNode][innerNode]);
18
+ if (nodeValidation.includes('"type":"Project"')) {
19
+ count += 1;
20
+ delete lockFile.dependencies[dependenciesNode][innerNode];
21
+ lockFile.additionalInfo = 'dependenciesNote';
22
+ }
23
+ }
24
+ }
25
+ if (count > 0) {
26
+ const multiLevelProjectWarning = () => {
27
+ console.log('');
28
+ console.log(i18n.__('dependenciesNote'));
29
+ };
30
+ setTimeout(multiLevelProjectWarning, 7000);
31
+ }
32
+ return lockFile;
33
+ };
34
+ const getDotNetDeps = (filePath, languageFiles) => {
35
+ const projectFile = readAndParseProjectFile(filePath + `/${languageFiles[0]}`);
36
+ const lockFile = readAndParseLockFile(filePath + `/${languageFiles[1]}`);
37
+ return { projectFile, lockFile };
38
+ };
39
+ module.exports = {
40
+ getDotNetDeps,
41
+ readAndParseProjectFile,
42
+ readAndParseLockFile
43
+ };
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ const { getDotNetDeps } = require('./analysis');
3
+ const { createDotNetTSMessage } = require('../common/formatMessage');
4
+ const dotNetAnalysis = (config, languageFiles) => {
5
+ const dotNetDeps = getDotNetDeps(config.file, languageFiles.DOTNET);
6
+ return createDotNetTSMessage(dotNetDeps);
7
+ };
8
+ module.exports = {
9
+ dotNetAnalysis
10
+ };
@@ -3,9 +3,7 @@ const child_process = require('child_process');
3
3
  const i18n = require('i18n');
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
  try {
10
8
  cmdStdout = child_process.execSync('go mod graph', { cwd });
11
9
  return cmdStdout.toString();