@contrast/contrast 1.0.20 → 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 (35) hide show
  1. package/dist/cliConstants.js +13 -6
  2. package/dist/commands/audit/help.js +2 -1
  3. package/dist/commands/audit/processAudit.js +1 -1
  4. package/dist/commands/fingerprint/fingerprintConfig.js +12 -0
  5. package/dist/commands/fingerprint/processFingerprint.js +14 -0
  6. package/dist/commands/learn/learn.js +9 -0
  7. package/dist/commands/learn/processLearn.js +10 -0
  8. package/dist/common/commonHelp.js +8 -1
  9. package/dist/constants/constants.js +1 -1
  10. package/dist/constants/locales.js +8 -1
  11. package/dist/index.js +8 -0
  12. package/dist/lambda/help.js +2 -1
  13. package/dist/scaAnalysis/scaAnalysis.js +155 -0
  14. package/dist/scan/autoDetection.js +2 -2
  15. package/dist/scan/fileUtils.js +2 -2
  16. package/dist/scan/help.js +2 -1
  17. package/package.json +1 -1
  18. package/src/cliConstants.js +15 -6
  19. package/src/commands/audit/help.js +2 -1
  20. package/src/commands/audit/processAudit.js +1 -1
  21. package/src/commands/fingerprint/fingerprintConfig.js +19 -0
  22. package/src/commands/fingerprint/processFingerprint.js +21 -0
  23. package/src/commands/learn/learn.js +10 -0
  24. package/src/commands/learn/processLearn.js +13 -0
  25. package/src/common/commonHelp.js +11 -1
  26. package/src/constants/constants.js +1 -1
  27. package/src/constants/locales.js +16 -1
  28. package/src/index.ts +11 -0
  29. package/src/lambda/help.ts +2 -1
  30. package/src/scaAnalysis/scaAnalysis.js +206 -0
  31. package/src/scan/autoDetection.js +2 -2
  32. package/src/scan/fileUtils.js +2 -2
  33. package/src/scan/help.js +2 -1
  34. package/dist/commands/scan/sca/scaAnalysis.js +0 -157
  35. package/src/commands/scan/sca/scaAnalysis.js +0 -211
package/src/index.ts CHANGED
@@ -5,6 +5,7 @@ import { processAudit } from './commands/audit/processAudit'
5
5
  import { processAuth } from './commands/auth/auth'
6
6
  import { processConfig } from './commands/config/config'
7
7
  import { processScan } from './commands/scan/processScan'
8
+ import { processFingerprint } from './commands/fingerprint/processFingerprint'
8
9
  import constants from './cliConstants'
9
10
  import { APP_NAME, APP_VERSION } from './constants/constants'
10
11
  import { processLambda } from './lambda/lambda'
@@ -15,6 +16,8 @@ import {
15
16
  } from './common/versionChecker'
16
17
  import { findCommandOnError } from './common/errorHandling'
17
18
  import { sendTelemetryConfigAsConfObj } from './telemetry/telemetry'
19
+ import { openLearnPage } from './commands/learn/learn'
20
+ import { processLearn } from './commands/learn/processLearn'
18
21
  const {
19
22
  commandLineDefinitions: { mainUsageGuide, mainDefinition }
20
23
  } = constants
@@ -82,6 +85,14 @@ const start = async () => {
82
85
  return await processAudit(config, argvMain)
83
86
  }
84
87
 
88
+ if (command === 'learn') {
89
+ return processLearn()
90
+ }
91
+
92
+ if (command === 'fingerprint') {
93
+ return await processFingerprint(config, argvMain)
94
+ }
95
+
85
96
  if (
86
97
  command === 'help' ||
87
98
  argvMain.includes('--help') ||
@@ -82,7 +82,8 @@ const lambdaUsageGuide = commandLineUsage([
82
82
  ]
83
83
  },
84
84
  commonHelpLinks()[0],
85
- commonHelpLinks()[1]
85
+ commonHelpLinks()[1],
86
+ commonHelpLinks()[2]
86
87
  ])
87
88
 
88
89
  export { lambdaUsageGuide }
@@ -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()
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 = {
@@ -1,157 +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 { convertGenericToTypedReportModelSca } = require('../../../scaAnalysis/common/utils/reportUtilsSca');
28
- const processSca = async (config) => {
29
- config = await settingsHelper.getSettings(config);
30
- const startTime = performance.now();
31
- let filesFound;
32
- if (config.help) {
33
- console.log(auditUsageGuide);
34
- process.exit(0);
35
- }
36
- const projectStats = await rootFile.getProjectStats(config.file);
37
- let pathWithFile = projectStats.isFile();
38
- config.fileName = config.file;
39
- config.file = pathWithFile
40
- ? rootFile.getDirectoryFromPathGiven(config.file).concat('/')
41
- : config.file;
42
- if (config.fingerprint && config.experimental) {
43
- let fingerprint = await autoDetection.autoDetectFingerprintInfo(config.file);
44
- let idArray = fingerprint.map(x => x.id);
45
- await saveResults.writeResultsToFile(fingerprint, 'fingerPrintInfo.json');
46
- console.log(idArray);
47
- }
48
- else {
49
- filesFound = await autoDetection.autoDetectAuditFilesAndLanguages(config.file);
50
- autoDetection.dealWithMultiJava(filesFound);
51
- if (filesFound.length > 1 && pathWithFile) {
52
- filesFound = filesFound.filter(i => Object.values(i)[0].includes(path.basename(config.fileName)));
53
- }
54
- let messageToSend = undefined;
55
- if (filesFound.length === 1) {
56
- switch (Object.keys(filesFound[0])[0]) {
57
- case JAVA:
58
- config.language = JAVA;
59
- if (config.mode === 'repo') {
60
- try {
61
- return repoMode.buildRepo(config, filesFound[0]);
62
- }
63
- catch (e) {
64
- throw new Error('Unable to build in repository mode. Check your project file');
65
- }
66
- }
67
- else {
68
- messageToSend = await javaAnalysis.javaAnalysis(config, filesFound[0]);
69
- }
70
- break;
71
- case JAVASCRIPT:
72
- messageToSend = await jsAnalysis.jsAnalysis(config, filesFound[0]);
73
- config.language = NODE;
74
- break;
75
- case PYTHON:
76
- messageToSend = pythonAnalysis(config, filesFound[0]);
77
- config.language = PYTHON;
78
- break;
79
- case RUBY:
80
- messageToSend = rubyAnalysis(config, filesFound[0]);
81
- config.language = RUBY;
82
- break;
83
- case PHP:
84
- messageToSend = phpAnalysis(config, filesFound[0]);
85
- config.language = PHP;
86
- break;
87
- case GO:
88
- messageToSend = goAnalysis(config, filesFound[0]);
89
- config.language = GO;
90
- break;
91
- case DOTNET:
92
- messageToSend = dotNetAnalysis(config, filesFound[0]);
93
- config.language = DOTNET;
94
- break;
95
- default:
96
- console.log('No supported language detected in project path');
97
- return;
98
- }
99
- if (!config.applicationId) {
100
- config.applicationId = await auditController.dealWithNoAppId(config);
101
- }
102
- if (config.experimental) {
103
- console.log('');
104
- const reportSpinner = returnOra(i18n.__('auditSCAAnalysisBegins'));
105
- startSpinner(reportSpinner);
106
- const { reportArray, reportId } = await scaUpload.scaTreeUpload(messageToSend, config);
107
- const reportModelLibraryList = convertGenericToTypedReportModelSca(reportArray);
108
- auditReport.processAuditReport(config, reportModelLibraryList);
109
- succeedSpinner(reportSpinner, i18n.__('auditSCAAnalysisComplete'));
110
- if (config.save !== undefined) {
111
- await auditSave.auditSave(config, reportId);
112
- }
113
- else {
114
- console.log('Use contrast audit --save to generate an SBOM');
115
- }
116
- const endTime = performance.now() - startTime;
117
- const scanDurationMs = endTime - startTime;
118
- console.log(`----- completed in ${(scanDurationMs / 1000).toFixed(2)}s -----`);
119
- }
120
- else {
121
- console.log('');
122
- const reportSpinner = returnOra(i18n.__('auditSCAAnalysisBegins'));
123
- startSpinner(reportSpinner);
124
- const snapshotResponse = await treeUpload.commonSendSnapShot(messageToSend, config);
125
- await pollForSnapshotCompletion(config, snapshotResponse.id, reportSpinner);
126
- succeedSpinner(reportSpinner, i18n.__('auditSCAAnalysisComplete'));
127
- await vulnerabilityReportV2(config, snapshotResponse.id);
128
- if (config.save !== undefined) {
129
- await auditSave.auditSave(config);
130
- }
131
- else {
132
- console.log('\nUse contrast audit --save to generate an SBOM');
133
- }
134
- const endTime = performance.now() - startTime;
135
- const scanDurationMs = endTime - startTime;
136
- console.log(`----- completed in ${(scanDurationMs / 1000).toFixed(2)}s -----`);
137
- }
138
- }
139
- else {
140
- if (filesFound.length === 0) {
141
- console.log(i18n.__('languageAnalysisNoLanguage'));
142
- console.log(i18n.__('languageAnalysisNoLanguageHelpLine'));
143
- throw new Error();
144
- }
145
- else {
146
- console.log(chalk.bold(`\nMultiple language files detected \n`));
147
- filesFound.forEach(file => {
148
- console.log(`${Object.keys(file)[0]} : `, Object.values(file)[0]);
149
- });
150
- throw new Error(`Please use --file to audit one language only. \nExample: contrast audit --file package-lock.json`);
151
- }
152
- }
153
- }
154
- };
155
- module.exports = {
156
- processSca
157
- };
@@ -1,211 +0,0 @@
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 {
13
- vulnerabilityReportV2
14
- } = require('../../../audit/report/reportingFeature')
15
- const autoDetection = require('../../../scan/autoDetection')
16
- const treeUpload = require('../../../scaAnalysis/common/treeUpload')
17
- const auditController = require('../../audit/auditController')
18
- const rootFile = require('../../../audit/languageAnalysisEngine/getProjectRootFilenames')
19
- const path = require('path')
20
- const i18n = require('i18n')
21
- const auditSave = require('../../../audit/save')
22
- const { auditUsageGuide } = require('../../audit/help')
23
- const repoMode = require('../../../scaAnalysis/repoMode/index')
24
- const { dotNetAnalysis } = require('../../../scaAnalysis/dotnet')
25
- const { goAnalysis } = require('../../../scaAnalysis/go/goAnalysis')
26
- const { phpAnalysis } = require('../../../scaAnalysis/php/index')
27
- const { rubyAnalysis } = require('../../../scaAnalysis/ruby')
28
- const { pythonAnalysis } = require('../../../scaAnalysis/python')
29
- const javaAnalysis = require('../../../scaAnalysis/java')
30
- const jsAnalysis = require('../../../scaAnalysis/javascript')
31
- const auditReport = require('../../../scaAnalysis/common/auditReport')
32
- const scaUpload = require('../../../scaAnalysis/common/scaServicesUpload')
33
- const settingsHelper = require('../../../utils/settingsHelper')
34
- const chalk = require('chalk')
35
- const saveResults = require('../../../scan/saveResults')
36
- const {
37
- convertGenericToTypedReportModelSca
38
- } = require('../../../scaAnalysis/common/utils/reportUtilsSca')
39
-
40
- const processSca = async config => {
41
- //checks to see whether to use old TS / new SCA path
42
- config = await settingsHelper.getSettings(config)
43
-
44
- const startTime = performance.now()
45
- let filesFound
46
-
47
- if (config.help) {
48
- console.log(auditUsageGuide)
49
- process.exit(0)
50
- }
51
-
52
- const projectStats = await rootFile.getProjectStats(config.file)
53
- let pathWithFile = projectStats.isFile()
54
-
55
- config.fileName = config.file
56
- config.file = pathWithFile
57
- ? rootFile.getDirectoryFromPathGiven(config.file).concat('/')
58
- : config.file
59
-
60
- if (config.fingerprint && config.experimental) {
61
- let fingerprint = await autoDetection.autoDetectFingerprintInfo(config.file)
62
- let idArray = fingerprint.map(x => x.id)
63
- await saveResults.writeResultsToFile(fingerprint, 'fingerPrintInfo.json')
64
- console.log(idArray)
65
- } else {
66
- filesFound = await autoDetection.autoDetectAuditFilesAndLanguages(
67
- config.file
68
- )
69
-
70
- autoDetection.dealWithMultiJava(filesFound)
71
-
72
- if (filesFound.length > 1 && pathWithFile) {
73
- filesFound = filesFound.filter(i =>
74
- Object.values(i)[0].includes(path.basename(config.fileName))
75
- )
76
- }
77
-
78
- // files found looks like [ { javascript: [ Array ] } ]
79
- //check we have the language and call the right analyser
80
- let messageToSend = undefined
81
- if (filesFound.length === 1) {
82
- switch (Object.keys(filesFound[0])[0]) {
83
- case JAVA:
84
- config.language = JAVA
85
-
86
- if (config.mode === 'repo') {
87
- try {
88
- return repoMode.buildRepo(config, filesFound[0])
89
- } catch (e) {
90
- throw new Error(
91
- 'Unable to build in repository mode. Check your project file'
92
- )
93
- }
94
- } else {
95
- messageToSend = await javaAnalysis.javaAnalysis(
96
- config,
97
- filesFound[0]
98
- )
99
- }
100
- break
101
- case JAVASCRIPT:
102
- messageToSend = await jsAnalysis.jsAnalysis(config, filesFound[0])
103
- config.language = NODE
104
- break
105
- case PYTHON:
106
- messageToSend = pythonAnalysis(config, filesFound[0])
107
- config.language = PYTHON
108
- break
109
- case RUBY:
110
- messageToSend = rubyAnalysis(config, filesFound[0])
111
- config.language = RUBY
112
- break
113
- case PHP:
114
- messageToSend = phpAnalysis(config, filesFound[0])
115
- config.language = PHP
116
- break
117
- case GO:
118
- messageToSend = goAnalysis(config, filesFound[0])
119
- config.language = GO
120
- break
121
- case DOTNET:
122
- messageToSend = dotNetAnalysis(config, filesFound[0])
123
- config.language = DOTNET
124
- break
125
- default:
126
- //something is wrong
127
- console.log('No supported language detected in project path')
128
- return
129
- }
130
-
131
- if (!config.applicationId) {
132
- config.applicationId = await auditController.dealWithNoAppId(config)
133
- }
134
-
135
- if (config.experimental) {
136
- console.log('') //empty log for space before spinner
137
- const reportSpinner = returnOra(i18n.__('auditSCAAnalysisBegins'))
138
- startSpinner(reportSpinner)
139
- const { reportArray, reportId } = await scaUpload.scaTreeUpload(
140
- messageToSend,
141
- config
142
- )
143
-
144
- const reportModelLibraryList =
145
- convertGenericToTypedReportModelSca(reportArray)
146
- auditReport.processAuditReport(config, reportModelLibraryList)
147
- succeedSpinner(reportSpinner, i18n.__('auditSCAAnalysisComplete'))
148
-
149
- if (config.save !== undefined) {
150
- await auditSave.auditSave(config, reportId)
151
- } else {
152
- console.log('Use contrast audit --save to generate an SBOM')
153
- }
154
-
155
- const endTime = performance.now() - startTime
156
- const scanDurationMs = endTime - startTime
157
- console.log(
158
- `----- completed in ${(scanDurationMs / 1000).toFixed(2)}s -----`
159
- )
160
- } else {
161
- console.log('') //empty log for space before spinner
162
- //send message to TS
163
- const reportSpinner = returnOra(i18n.__('auditSCAAnalysisBegins'))
164
- startSpinner(reportSpinner)
165
- const snapshotResponse = await treeUpload.commonSendSnapShot(
166
- messageToSend,
167
- config
168
- )
169
-
170
- // poll for completion
171
- await pollForSnapshotCompletion(
172
- config,
173
- snapshotResponse.id,
174
- reportSpinner
175
- )
176
- succeedSpinner(reportSpinner, i18n.__('auditSCAAnalysisComplete'))
177
-
178
- await vulnerabilityReportV2(config, snapshotResponse.id)
179
- if (config.save !== undefined) {
180
- await auditSave.auditSave(config)
181
- } else {
182
- console.log('\nUse contrast audit --save to generate an SBOM')
183
- }
184
- const endTime = performance.now() - startTime
185
- const scanDurationMs = endTime - startTime
186
-
187
- console.log(
188
- `----- completed in ${(scanDurationMs / 1000).toFixed(2)}s -----`
189
- )
190
- }
191
- } else {
192
- if (filesFound.length === 0) {
193
- console.log(i18n.__('languageAnalysisNoLanguage'))
194
- console.log(i18n.__('languageAnalysisNoLanguageHelpLine'))
195
- throw new Error()
196
- } else {
197
- console.log(chalk.bold(`\nMultiple language files detected \n`))
198
- filesFound.forEach(file => {
199
- console.log(`${Object.keys(file)[0]} : `, Object.values(file)[0])
200
- })
201
- throw new Error(
202
- `Please use --file to audit one language only. \nExample: contrast audit --file package-lock.json`
203
- )
204
- }
205
- }
206
- }
207
- }
208
-
209
- module.exports = {
210
- processSca
211
- }