@contrast/contrast 1.0.19 → 1.0.21

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 (66) hide show
  1. package/dist/audit/report/commonReportingFunctions.js +3 -4
  2. package/dist/audit/report/models/reportListModel.js +2 -1
  3. package/dist/audit/report/reportingFeature.js +1 -1
  4. package/dist/audit/report/utils/reportUtils.js +30 -11
  5. package/dist/cliConstants.js +13 -6
  6. package/dist/commands/audit/auditConfig.js +1 -2
  7. package/dist/commands/audit/help.js +2 -1
  8. package/dist/commands/audit/processAudit.js +1 -1
  9. package/dist/commands/fingerprint/fingerprintConfig.js +12 -0
  10. package/dist/commands/fingerprint/processFingerprint.js +14 -0
  11. package/dist/commands/learn/learn.js +9 -0
  12. package/dist/commands/learn/processLearn.js +10 -0
  13. package/dist/common/commonHelp.js +8 -1
  14. package/dist/constants/constants.js +1 -1
  15. package/dist/constants/locales.js +14 -3
  16. package/dist/index.js +8 -0
  17. package/dist/lambda/help.js +2 -1
  18. package/dist/scaAnalysis/common/auditReport.js +16 -60
  19. package/dist/scaAnalysis/common/commonReportingFunctionsSca.js +154 -0
  20. package/dist/scaAnalysis/common/models/ScaReportModel.js +45 -0
  21. package/dist/scaAnalysis/common/scaServicesUpload.js +4 -3
  22. package/dist/scaAnalysis/common/utils/reportUtilsSca.js +76 -0
  23. package/dist/scaAnalysis/java/analysis.js +1 -28
  24. package/dist/scaAnalysis/java/index.js +1 -13
  25. package/dist/scaAnalysis/scaAnalysis.js +155 -0
  26. package/dist/scan/autoDetection.js +2 -2
  27. package/dist/scan/fileUtils.js +2 -2
  28. package/dist/scan/formatScanOutput.js +19 -13
  29. package/dist/scan/help.js +2 -1
  30. package/dist/utils/paramsUtil/configStoreParams.js +1 -12
  31. package/dist/utils/paramsUtil/paramHandler.js +1 -7
  32. package/package.json +5 -1
  33. package/src/audit/report/commonReportingFunctions.js +7 -5
  34. package/src/audit/report/models/reportListModel.ts +12 -2
  35. package/src/audit/report/reportingFeature.ts +1 -1
  36. package/src/audit/report/utils/reportUtils.ts +4 -4
  37. package/src/cliConstants.js +15 -6
  38. package/src/commands/audit/auditConfig.js +1 -2
  39. package/src/commands/audit/help.js +2 -1
  40. package/src/commands/audit/processAudit.js +1 -1
  41. package/src/commands/fingerprint/fingerprintConfig.js +19 -0
  42. package/src/commands/fingerprint/processFingerprint.js +21 -0
  43. package/src/commands/learn/learn.js +10 -0
  44. package/src/commands/learn/processLearn.js +13 -0
  45. package/src/common/commonHelp.js +11 -1
  46. package/src/constants/constants.js +1 -1
  47. package/src/constants/locales.js +22 -3
  48. package/src/index.ts +11 -0
  49. package/src/lambda/help.ts +2 -1
  50. package/src/scaAnalysis/common/auditReport.js +25 -80
  51. package/src/scaAnalysis/common/commonReportingFunctionsSca.js +276 -0
  52. package/src/scaAnalysis/common/models/ScaReportModel.ts +81 -0
  53. package/src/scaAnalysis/common/scaServicesUpload.js +5 -3
  54. package/src/scaAnalysis/common/utils/reportUtilsSca.ts +123 -0
  55. package/src/scaAnalysis/java/analysis.js +1 -28
  56. package/src/scaAnalysis/java/index.js +1 -18
  57. package/src/scaAnalysis/scaAnalysis.js +206 -0
  58. package/src/scan/autoDetection.js +2 -2
  59. package/src/scan/fileUtils.js +2 -2
  60. package/src/scan/formatScanOutput.ts +28 -17
  61. package/src/scan/help.js +2 -1
  62. package/src/utils/getConfig.ts +0 -1
  63. package/src/utils/paramsUtil/configStoreParams.js +1 -14
  64. package/src/utils/paramsUtil/paramHandler.js +1 -9
  65. package/dist/commands/scan/sca/scaAnalysis.js +0 -155
  66. package/src/commands/scan/sca/scaAnalysis.js +0 -206
@@ -0,0 +1,206 @@
1
+ const {
2
+ supportedLanguages: { JAVA, GO, PYTHON, RUBY, JAVASCRIPT, NODE, PHP, DOTNET }
3
+ } = require('../constants/constants')
4
+ const {
5
+ pollForSnapshotCompletion
6
+ } = require('../audit/languageAnalysisEngine/sendSnapshot')
7
+ const {
8
+ returnOra,
9
+ startSpinner,
10
+ succeedSpinner
11
+ } = require('../utils/oraWrapper')
12
+ const { vulnerabilityReportV2 } = require('../audit/report/reportingFeature')
13
+ const autoDetection = require('../scan/autoDetection')
14
+ const treeUpload = require('./common/treeUpload')
15
+ const auditController = require('../commands/audit/auditController')
16
+ const rootFile = require('../audit/languageAnalysisEngine/getProjectRootFilenames')
17
+ const path = require('path')
18
+ const i18n = require('i18n')
19
+ const auditSave = require('../audit/save')
20
+ const { auditUsageGuide } = require('../commands/audit/help')
21
+ const repoMode = require('./repoMode')
22
+ const { dotNetAnalysis } = require('./dotnet')
23
+ const { goAnalysis } = require('./go/goAnalysis')
24
+ const { phpAnalysis } = require('./php')
25
+ const { rubyAnalysis } = require('./ruby')
26
+ const { pythonAnalysis } = require('./python')
27
+ const javaAnalysis = require('./java')
28
+ const jsAnalysis = require('./javascript')
29
+ const auditReport = require('./common/auditReport')
30
+ const scaUpload = require('./common/scaServicesUpload')
31
+ const settingsHelper = require('../utils/settingsHelper')
32
+ const chalk = require('chalk')
33
+ const saveResults = require('../scan/saveResults')
34
+ const {
35
+ convertGenericToTypedReportModelSca
36
+ } = require('./common/utils/reportUtilsSca')
37
+
38
+ const processSca = async config => {
39
+ //checks to see whether to use old TS / new SCA path
40
+ config = await settingsHelper.getSettings(config)
41
+
42
+ const startTime = performance.now()
43
+ let filesFound
44
+
45
+ if (config.help) {
46
+ console.log(auditUsageGuide)
47
+ process.exit(0)
48
+ }
49
+
50
+ const projectStats = await rootFile.getProjectStats(config.file)
51
+ let pathWithFile = projectStats.isFile()
52
+
53
+ config.fileName = config.file
54
+ config.file = pathWithFile
55
+ ? rootFile.getDirectoryFromPathGiven(config.file).concat('/')
56
+ : config.file
57
+
58
+ filesFound = await autoDetection.autoDetectAuditFilesAndLanguages(config.file)
59
+
60
+ autoDetection.dealWithMultiJava(filesFound)
61
+
62
+ if (filesFound.length > 1 && pathWithFile) {
63
+ filesFound = filesFound.filter(i =>
64
+ Object.values(i)[0].includes(path.basename(config.fileName))
65
+ )
66
+ }
67
+
68
+ // files found looks like [ { javascript: [ Array ] } ]
69
+ //check we have the language and call the right analyser
70
+ let messageToSend = undefined
71
+ if (filesFound.length === 1) {
72
+ switch (Object.keys(filesFound[0])[0]) {
73
+ case JAVA:
74
+ config.language = JAVA
75
+
76
+ if (config.mode === 'repo') {
77
+ try {
78
+ return repoMode.buildRepo(config, filesFound[0])
79
+ } catch (e) {
80
+ throw new Error(
81
+ 'Unable to build in repository mode. Check your project file'
82
+ )
83
+ }
84
+ } else {
85
+ messageToSend = await javaAnalysis.javaAnalysis(config, filesFound[0])
86
+ }
87
+ break
88
+ case JAVASCRIPT:
89
+ messageToSend = await jsAnalysis.jsAnalysis(config, filesFound[0])
90
+ config.language = NODE
91
+ break
92
+ case PYTHON:
93
+ messageToSend = pythonAnalysis(config, filesFound[0])
94
+ config.language = PYTHON
95
+ break
96
+ case RUBY:
97
+ messageToSend = rubyAnalysis(config, filesFound[0])
98
+ config.language = RUBY
99
+ break
100
+ case PHP:
101
+ messageToSend = phpAnalysis(config, filesFound[0])
102
+ config.language = PHP
103
+ break
104
+ case GO:
105
+ messageToSend = goAnalysis(config, filesFound[0])
106
+ config.language = GO
107
+ break
108
+ case DOTNET:
109
+ if (config.experimental) {
110
+ console.log(
111
+ `${chalk.bold(
112
+ '\n.NET project found\n'
113
+ )} Language type is unsupported.`
114
+ )
115
+ return
116
+ } else {
117
+ messageToSend = dotNetAnalysis(config, filesFound[0])
118
+ config.language = DOTNET
119
+ break
120
+ }
121
+ default:
122
+ //something is wrong
123
+ console.log('No supported language detected in project path')
124
+ return
125
+ }
126
+
127
+ if (!config.applicationId) {
128
+ config.applicationId = await auditController.dealWithNoAppId(config)
129
+ }
130
+
131
+ if (config.experimental) {
132
+ console.log('') //empty log for space before spinner
133
+ const reportSpinner = returnOra(i18n.__('auditSCAAnalysisBegins'))
134
+ startSpinner(reportSpinner)
135
+ const { reportArray, reportId } = await scaUpload.scaTreeUpload(
136
+ messageToSend,
137
+ config
138
+ )
139
+
140
+ const reportModelLibraryList =
141
+ convertGenericToTypedReportModelSca(reportArray)
142
+ auditReport.processAuditReport(config, reportModelLibraryList)
143
+ succeedSpinner(reportSpinner, i18n.__('auditSCAAnalysisComplete'))
144
+
145
+ if (config.save !== undefined) {
146
+ await auditSave.auditSave(config, reportId)
147
+ } else {
148
+ console.log('Use contrast audit --save to generate an SBOM')
149
+ }
150
+
151
+ const endTime = performance.now() - startTime
152
+ const scanDurationMs = endTime - startTime
153
+ console.log(
154
+ `----- completed in ${(scanDurationMs / 1000).toFixed(2)}s -----`
155
+ )
156
+ } else {
157
+ console.log('') //empty log for space before spinner
158
+ //send message to TS
159
+ const reportSpinner = returnOra(i18n.__('auditSCAAnalysisBegins'))
160
+ startSpinner(reportSpinner)
161
+ const snapshotResponse = await treeUpload.commonSendSnapShot(
162
+ messageToSend,
163
+ config
164
+ )
165
+
166
+ // poll for completion
167
+ await pollForSnapshotCompletion(
168
+ config,
169
+ snapshotResponse.id,
170
+ reportSpinner
171
+ )
172
+ succeedSpinner(reportSpinner, i18n.__('auditSCAAnalysisComplete'))
173
+
174
+ await vulnerabilityReportV2(config, snapshotResponse.id)
175
+ if (config.save !== undefined) {
176
+ await auditSave.auditSave(config)
177
+ } else {
178
+ console.log('\nUse contrast audit --save to generate an SBOM')
179
+ }
180
+ const endTime = performance.now() - startTime
181
+ const scanDurationMs = endTime - startTime
182
+
183
+ console.log(
184
+ `----- completed in ${(scanDurationMs / 1000).toFixed(2)}s -----`
185
+ )
186
+ }
187
+ } else {
188
+ if (filesFound.length === 0) {
189
+ console.log(i18n.__('languageAnalysisNoLanguage'))
190
+ console.log(i18n.__('languageAnalysisNoLanguageHelpLine'))
191
+ throw new Error()
192
+ } else {
193
+ console.log(chalk.bold(`\nMultiple language files detected \n`))
194
+ filesFound.forEach(file => {
195
+ console.log(`${Object.keys(file)[0]} : `, Object.values(file)[0])
196
+ })
197
+ throw new Error(
198
+ `Please use --file to audit one language only. \nExample: contrast audit --file package-lock.json`
199
+ )
200
+ }
201
+ }
202
+ }
203
+
204
+ module.exports = {
205
+ processSca
206
+ }
@@ -1,8 +1,8 @@
1
1
  const i18n = require('i18n')
2
2
  const fileFinder = require('./fileUtils')
3
3
 
4
- const autoDetectFingerprintInfo = async filePath => {
5
- let complexObj = await fileFinder.findAllFiles(filePath)
4
+ const autoDetectFingerprintInfo = async (filePath, depth) => {
5
+ let complexObj = await fileFinder.findAllFiles(filePath, depth)
6
6
  let result = []
7
7
  let count = 0
8
8
  complexObj.forEach(i => {
@@ -11,7 +11,7 @@ const findFile = async () => {
11
11
  })
12
12
  }
13
13
 
14
- const findAllFiles = async filePath => {
14
+ const findAllFiles = async (filePath, depth = 2) => {
15
15
  const result = await fg(
16
16
  [
17
17
  '**/pom.xml',
@@ -25,7 +25,7 @@ const findAllFiles = async filePath => {
25
25
  ],
26
26
  {
27
27
  dot: false,
28
- deep: 2,
28
+ deep: depth,
29
29
  onlyFiles: true,
30
30
  absolute: true,
31
31
  cwd: filePath ? filePath : process.cwd()
@@ -1,7 +1,4 @@
1
- import {
2
- ScanResultsInstances,
3
- ScanResultsModel
4
- } from './models/scanResultsModel'
1
+ import { ScanResultsModel } from './models/scanResultsModel'
5
2
  import i18n from 'i18n'
6
3
  import chalk from 'chalk'
7
4
  import { ResultContent } from './models/resultContentModel'
@@ -13,7 +10,8 @@ import {
13
10
  HIGH_COLOUR,
14
11
  LOW_COLOUR,
15
12
  MEDIUM_COLOUR,
16
- NOTE_COLOUR
13
+ NOTE_COLOUR,
14
+ supportedLanguagesScan
17
15
  } from '../constants/constants'
18
16
  import {
19
17
  getSeverityCounts,
@@ -21,27 +19,28 @@ import {
21
19
  } from '../audit/report/commonReportingFunctions'
22
20
 
23
21
  export function formatScanOutput(scanResults: ScanResultsModel) {
24
- const { scanResultsInstances } = scanResults
22
+ const { content } = scanResults.scanResultsInstances
23
+ const { language } = scanResults.scanDetail
25
24
 
26
- const projectOverview = getSeverityCounts(scanResultsInstances.content)
27
- if (scanResultsInstances.content.length === 0) {
25
+ const severityCounts = getSeverityCounts(content)
26
+ if (content.length === 0) {
28
27
  console.log(i18n.__('scanNoVulnerabilitiesFound'))
29
28
  console.log(i18n.__('scanNoVulnerabilitiesFoundSecureCode'))
30
29
  console.log(i18n.__('scanNoVulnerabilitiesFoundGoodWork'))
31
30
  } else {
32
31
  const message =
33
- projectOverview.critical || projectOverview.high
32
+ severityCounts.critical || severityCounts.high
34
33
  ? 'Here are your top priorities to fix'
35
34
  : "No major issues, here's what we found"
36
35
  console.log(chalk.bold(message))
37
36
  console.log()
38
37
 
39
- let defaultView = getDefaultView(scanResultsInstances.content)
38
+ const defaultView = getDefaultView(content, language)
40
39
 
41
40
  let count = 0
42
41
  defaultView.forEach(entry => {
43
42
  count++
44
- let table = new Table({
43
+ const table = new Table({
45
44
  chars: {
46
45
  top: '',
47
46
  'top-mid': '',
@@ -64,6 +63,7 @@ export function formatScanOutput(scanResults: ScanResultsModel) {
64
63
  wordWrap: true,
65
64
  colWidths: [12, 1, 100]
66
65
  })
66
+
67
67
  let learnRow: string[] = []
68
68
  let adviceRow = []
69
69
  const headerColour = chalk.hex(entry.colour)
@@ -107,9 +107,9 @@ export function formatScanOutput(scanResults: ScanResultsModel) {
107
107
  console.log()
108
108
  })
109
109
  }
110
- printVulnInfo(projectOverview)
110
+ printVulnInfo(severityCounts)
111
111
 
112
- return projectOverview
112
+ return severityCounts
113
113
  }
114
114
 
115
115
  export function formatLinks(objName: string, entry: any[]) {
@@ -124,7 +124,7 @@ export function formatLinks(objName: string, entry: any[]) {
124
124
  }
125
125
  }
126
126
 
127
- export function getDefaultView(content: ResultContent[]) {
127
+ export function getDefaultView(content: ResultContent[], language: string) {
128
128
  const groupTypeResults = [] as GroupedResultsModel[]
129
129
 
130
130
  content.forEach(resultEntry => {
@@ -136,8 +136,7 @@ export function getDefaultView(content: ResultContent[]) {
136
136
  groupResultsObj.learn = resultEntry.learn
137
137
  groupResultsObj.message = resultEntry.message?.text
138
138
  ? editVulName(resultEntry.message.text) +
139
- ':' +
140
- getSourceLineNumber(resultEntry)
139
+ doAddSourceLineNumber(resultEntry, language)
141
140
  : ''
142
141
  groupResultsObj.codePath = getLocationsSyncInfo(resultEntry)
143
142
  groupTypeResults.push(groupResultsObj)
@@ -146,9 +145,21 @@ export function getDefaultView(content: ResultContent[]) {
146
145
 
147
146
  return sortBy(groupTypeResults, ['priority'])
148
147
  }
148
+
149
+ export function doAddSourceLineNumber(
150
+ resultEntry: ResultContent,
151
+ language: string
152
+ ) {
153
+ //only add source line num if not JS
154
+ return language !== supportedLanguagesScan.JAVASCRIPT
155
+ ? ':' + getSourceLineNumber(resultEntry)
156
+ : ''
157
+ }
158
+
149
159
  export function editVulName(message: string) {
150
160
  return message.substring(message.indexOf(' in '))
151
161
  }
162
+
152
163
  export function getLocationsSyncInfo(resultEntry: ResultContent) {
153
164
  const locationsMessage =
154
165
  resultEntry.locations[0]?.physicalLocation?.artifactLocation?.uri || ''
@@ -165,7 +176,7 @@ export function getLocationsSyncInfo(resultEntry: ResultContent) {
165
176
  export function getSourceLineNumber(resultEntry: ResultContent) {
166
177
  const locationsLineNumber =
167
178
  resultEntry.locations[0]?.physicalLocation?.region?.startLine || ''
168
- let codeFlowLineNumber = getCodeFlowInfo(resultEntry)
179
+ const codeFlowLineNumber = getCodeFlowInfo(resultEntry)
169
180
 
170
181
  return codeFlowLineNumber ? codeFlowLineNumber : locationsLineNumber
171
182
  }
package/src/scan/help.js CHANGED
@@ -44,7 +44,8 @@ const scanUsageGuide = commandLineUsage([
44
44
  constants.commandLineDefinitions.scanAdvancedOptionDefinitionsForHelp
45
45
  },
46
46
  commonHelpLinks()[0],
47
- commonHelpLinks()[1]
47
+ commonHelpLinks()[1],
48
+ commonHelpLinks()[2]
48
49
  ])
49
50
 
50
51
  module.exports = {
@@ -8,7 +8,6 @@ type ContrastConfOptions = Partial<{
8
8
  orgId: string
9
9
  authHeader: string
10
10
  numOfRuns: number
11
- javaAgreement: boolean
12
11
  }>
13
12
 
14
13
  type ContrastConf = Conf<ContrastConfOptions>
@@ -16,17 +16,4 @@ const getAuth = () => {
16
16
  return ContrastConfToUse
17
17
  }
18
18
 
19
- const getAgreement = () => {
20
- const ContrastConf = config.localConfig(APP_NAME, APP_VERSION)
21
- let ContrastConfToUse = {}
22
- ContrastConfToUse.javaAgreement = ContrastConf.get('javaAgreement')
23
- return ContrastConfToUse
24
- }
25
-
26
- const setAgreement = agreement => {
27
- const ContrastConf = config.localConfig(APP_NAME, APP_VERSION)
28
- ContrastConf.set('javaAgreement', agreement)
29
- return agreement
30
- }
31
-
32
- module.exports = { getAuth, getAgreement, setAgreement }
19
+ module.exports = { getAuth }
@@ -21,12 +21,4 @@ const getAuth = params => {
21
21
  }
22
22
  }
23
23
 
24
- const getAgreement = () => {
25
- return configStoreParams.getAgreement()
26
- }
27
-
28
- const setAgreement = answer => {
29
- return configStoreParams.setAgreement(answer)
30
- }
31
-
32
- module.exports = { getAuth, getAgreement, setAgreement }
24
+ module.exports = { getAuth }
@@ -1,155 +0,0 @@
1
- "use strict";
2
- const { supportedLanguages: { JAVA, GO, PYTHON, RUBY, JAVASCRIPT, NODE, PHP, DOTNET } } = require('../../../constants/constants');
3
- const { pollForSnapshotCompletion } = require('../../../audit/languageAnalysisEngine/sendSnapshot');
4
- const { returnOra, startSpinner, succeedSpinner } = require('../../../utils/oraWrapper');
5
- const { vulnerabilityReportV2 } = require('../../../audit/report/reportingFeature');
6
- const autoDetection = require('../../../scan/autoDetection');
7
- const treeUpload = require('../../../scaAnalysis/common/treeUpload');
8
- const auditController = require('../../audit/auditController');
9
- const rootFile = require('../../../audit/languageAnalysisEngine/getProjectRootFilenames');
10
- const path = require('path');
11
- const i18n = require('i18n');
12
- const auditSave = require('../../../audit/save');
13
- const { auditUsageGuide } = require('../../audit/help');
14
- const repoMode = require('../../../scaAnalysis/repoMode/index');
15
- const { dotNetAnalysis } = require('../../../scaAnalysis/dotnet');
16
- const { goAnalysis } = require('../../../scaAnalysis/go/goAnalysis');
17
- const { phpAnalysis } = require('../../../scaAnalysis/php/index');
18
- const { rubyAnalysis } = require('../../../scaAnalysis/ruby');
19
- const { pythonAnalysis } = require('../../../scaAnalysis/python');
20
- const javaAnalysis = require('../../../scaAnalysis/java');
21
- const jsAnalysis = require('../../../scaAnalysis/javascript');
22
- const auditReport = require('../../../scaAnalysis/common/auditReport');
23
- const scaUpload = require('../../../scaAnalysis/common/scaServicesUpload');
24
- const settingsHelper = require('../../../utils/settingsHelper');
25
- const chalk = require('chalk');
26
- const saveResults = require('../../../scan/saveResults');
27
- const processSca = async (config) => {
28
- config = await settingsHelper.getSettings(config);
29
- const startTime = performance.now();
30
- let filesFound;
31
- if (config.help) {
32
- console.log(auditUsageGuide);
33
- process.exit(0);
34
- }
35
- const projectStats = await rootFile.getProjectStats(config.file);
36
- let pathWithFile = projectStats.isFile();
37
- config.fileName = config.file;
38
- config.file = pathWithFile
39
- ? rootFile.getDirectoryFromPathGiven(config.file).concat('/')
40
- : config.file;
41
- if (config.fingerprint && config.experimental) {
42
- let fingerprint = await autoDetection.autoDetectFingerprintInfo(config.file);
43
- let idArray = fingerprint.map(x => x.id);
44
- await saveResults.writeResultsToFile(fingerprint, 'fingerPrintInfo.json');
45
- console.log(idArray);
46
- }
47
- else {
48
- filesFound = await autoDetection.autoDetectAuditFilesAndLanguages(config.file);
49
- autoDetection.dealWithMultiJava(filesFound);
50
- if (filesFound.length > 1 && pathWithFile) {
51
- filesFound = filesFound.filter(i => Object.values(i)[0].includes(path.basename(config.fileName)));
52
- }
53
- let messageToSend = undefined;
54
- if (filesFound.length === 1) {
55
- switch (Object.keys(filesFound[0])[0]) {
56
- case JAVA:
57
- config.language = JAVA;
58
- if (config.mode === 'repo') {
59
- try {
60
- return repoMode.buildRepo(config, filesFound[0]);
61
- }
62
- catch (e) {
63
- throw new Error('Unable to build in repository mode. Check your project file');
64
- }
65
- }
66
- else {
67
- messageToSend = await javaAnalysis.javaAnalysis(config, filesFound[0]);
68
- }
69
- break;
70
- case JAVASCRIPT:
71
- messageToSend = await jsAnalysis.jsAnalysis(config, filesFound[0]);
72
- config.language = NODE;
73
- break;
74
- case PYTHON:
75
- messageToSend = pythonAnalysis(config, filesFound[0]);
76
- config.language = PYTHON;
77
- break;
78
- case RUBY:
79
- messageToSend = rubyAnalysis(config, filesFound[0]);
80
- config.language = RUBY;
81
- break;
82
- case PHP:
83
- messageToSend = phpAnalysis(config, filesFound[0]);
84
- config.language = PHP;
85
- break;
86
- case GO:
87
- messageToSend = goAnalysis(config, filesFound[0]);
88
- config.language = GO;
89
- break;
90
- case DOTNET:
91
- messageToSend = dotNetAnalysis(config, filesFound[0]);
92
- config.language = DOTNET;
93
- break;
94
- default:
95
- console.log('No supported language detected in project path');
96
- return;
97
- }
98
- if (!config.applicationId) {
99
- config.applicationId = await auditController.dealWithNoAppId(config);
100
- }
101
- if (config.experimental) {
102
- console.log('');
103
- const reportSpinner = returnOra(i18n.__('auditSCAAnalysisBegins'));
104
- startSpinner(reportSpinner);
105
- const [reports, reportId] = await scaUpload.scaTreeUpload(messageToSend, config);
106
- auditReport.processAuditReport(config, reports[0]);
107
- succeedSpinner(reportSpinner, i18n.__('auditSCAAnalysisComplete'));
108
- if (config.save !== undefined) {
109
- await auditSave.auditSave(config, reportId);
110
- }
111
- else {
112
- console.log('Use contrast audit --save to generate an SBOM');
113
- }
114
- const endTime = performance.now() - startTime;
115
- const scanDurationMs = endTime - startTime;
116
- console.log(`----- completed in ${(scanDurationMs / 1000).toFixed(2)}s -----`);
117
- }
118
- else {
119
- console.log('');
120
- const reportSpinner = returnOra(i18n.__('auditSCAAnalysisBegins'));
121
- startSpinner(reportSpinner);
122
- const snapshotResponse = await treeUpload.commonSendSnapShot(messageToSend, config);
123
- await pollForSnapshotCompletion(config, snapshotResponse.id, reportSpinner);
124
- succeedSpinner(reportSpinner, i18n.__('auditSCAAnalysisComplete'));
125
- await vulnerabilityReportV2(config, snapshotResponse.id);
126
- if (config.save !== undefined) {
127
- await auditSave.auditSave(config);
128
- }
129
- else {
130
- console.log('\nUse contrast audit --save to generate an SBOM');
131
- }
132
- const endTime = performance.now() - startTime;
133
- const scanDurationMs = endTime - startTime;
134
- console.log(`----- completed in ${(scanDurationMs / 1000).toFixed(2)}s -----`);
135
- }
136
- }
137
- else {
138
- if (filesFound.length === 0) {
139
- console.log(i18n.__('languageAnalysisNoLanguage'));
140
- console.log(i18n.__('languageAnalysisNoLanguageHelpLine'));
141
- throw new Error();
142
- }
143
- else {
144
- console.log(chalk.bold(`\nMultiple language files detected \n`));
145
- filesFound.forEach(file => {
146
- console.log(`${Object.keys(file)[0]} : `, Object.values(file)[0]);
147
- });
148
- throw new Error(`Please use --file to audit one language only. \nExample: contrast audit --file package-lock.json`);
149
- }
150
- }
151
- }
152
- };
153
- module.exports = {
154
- processSca
155
- };