@contrast/contrast 1.0.16 → 1.0.17
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.
- package/dist/audit/catalogueApplication/catalogueApplication.js +1 -1
- package/dist/cliConstants.js +6 -1
- package/dist/commands/audit/auditConfig.js +10 -12
- package/dist/commands/audit/auditController.js +12 -16
- package/dist/commands/audit/help.js +24 -26
- package/dist/commands/audit/processAudit.js +16 -22
- package/dist/commands/audit/saveFile.js +3 -9
- package/dist/commands/scan/processScan.js +5 -7
- package/dist/commands/scan/sca/scaAnalysis.js +104 -88
- package/dist/common/commonHelp.js +35 -17
- package/dist/common/errorHandling.js +28 -57
- package/dist/common/versionChecker.js +24 -27
- package/dist/constants/constants.js +1 -1
- package/dist/constants/locales.js +6 -3
- package/dist/lambda/help.js +2 -1
- package/dist/lambda/lambda.js +2 -7
- package/dist/scaAnalysis/java/analysis.js +40 -5
- package/dist/scaAnalysis/java/index.js +15 -2
- package/dist/scan/autoDetection.js +12 -3
- package/dist/scan/fileUtils.js +24 -1
- package/dist/scan/help.js +2 -1
- package/dist/scan/saveResults.js +1 -1
- package/dist/utils/commonApi.js +10 -1
- package/dist/utils/generalAPI.js +1 -2
- package/dist/utils/paramsUtil/configStoreParams.js +12 -1
- package/dist/utils/paramsUtil/paramHandler.js +7 -1
- package/dist/utils/saveFile.js +2 -1
- package/package.json +2 -1
- package/src/audit/catalogueApplication/catalogueApplication.js +1 -1
- package/src/cliConstants.js +6 -1
- package/src/commands/audit/auditConfig.js +19 -0
- package/src/commands/audit/{auditController.ts → auditController.js} +17 -12
- package/src/commands/audit/{help.ts → help.js} +10 -7
- package/src/commands/audit/processAudit.js +37 -0
- package/src/commands/audit/{saveFile.ts → saveFile.js} +2 -2
- package/src/commands/scan/processScan.js +4 -10
- package/src/commands/scan/sca/scaAnalysis.js +134 -116
- package/src/common/commonHelp.js +43 -0
- package/src/common/{errorHandling.ts → errorHandling.js} +6 -31
- package/src/common/{versionChecker.ts → versionChecker.js} +15 -10
- package/src/constants/constants.js +1 -1
- package/src/constants/locales.js +7 -3
- package/src/lambda/help.ts +2 -1
- package/src/lambda/lambda.ts +2 -10
- package/src/scaAnalysis/java/analysis.js +43 -10
- package/src/scaAnalysis/java/index.js +19 -2
- package/src/scan/autoDetection.js +14 -3
- package/src/scan/fileUtils.js +29 -1
- package/src/scan/help.js +2 -1
- package/src/scan/saveResults.js +1 -1
- package/src/utils/commonApi.js +13 -1
- package/src/utils/generalAPI.js +1 -2
- package/src/utils/getConfig.ts +1 -0
- package/src/utils/paramsUtil/configStoreParams.js +14 -1
- package/src/utils/paramsUtil/paramHandler.js +9 -1
- package/src/utils/saveFile.js +2 -1
- package/src/commands/audit/auditConfig.ts +0 -21
- package/src/commands/audit/processAudit.ts +0 -40
- package/src/common/commonHelp.ts +0 -13
|
@@ -1,23 +1,24 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
const catalogue = require('../../audit/catalogueApplication/catalogueApplication')
|
|
2
|
+
const commonApi = require('../../audit/languageAnalysisEngine/commonApi')
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
let appID
|
|
4
|
+
const dealWithNoAppId = async config => {
|
|
5
|
+
let appID
|
|
6
6
|
try {
|
|
7
|
-
// @ts-ignore
|
|
8
7
|
appID = await commonApi.returnAppId(config)
|
|
8
|
+
|
|
9
9
|
if (!appID && config.applicationName) {
|
|
10
|
-
return await catalogueApplication(config)
|
|
10
|
+
return await catalogue.catalogueApplication(config)
|
|
11
11
|
}
|
|
12
|
+
|
|
12
13
|
if (!appID && !config.applicationName) {
|
|
13
|
-
config.applicationName = getAppName(config.file)
|
|
14
|
-
// @ts-ignore
|
|
14
|
+
config.applicationName = getAppName(config.file)
|
|
15
15
|
appID = await commonApi.returnAppId(config)
|
|
16
|
+
|
|
16
17
|
if (!appID) {
|
|
17
|
-
return await catalogueApplication(config)
|
|
18
|
+
return await catalogue.catalogueApplication(config)
|
|
18
19
|
}
|
|
19
20
|
}
|
|
20
|
-
} catch (e
|
|
21
|
+
} catch (e) {
|
|
21
22
|
if (e.toString().includes('tunneling socket could not be established')) {
|
|
22
23
|
console.log(e.message.toString())
|
|
23
24
|
console.log(
|
|
@@ -29,7 +30,7 @@ export const dealWithNoAppId = async (config: { [x: string]: string }) => {
|
|
|
29
30
|
return appID
|
|
30
31
|
}
|
|
31
32
|
|
|
32
|
-
|
|
33
|
+
const getAppName = file => {
|
|
33
34
|
const last = file.charAt(file.length - 1)
|
|
34
35
|
if (last !== '/') {
|
|
35
36
|
return file.split('/').pop()
|
|
@@ -39,6 +40,10 @@ export const getAppName = (file: string) => {
|
|
|
39
40
|
}
|
|
40
41
|
}
|
|
41
42
|
|
|
42
|
-
const removeLastChar =
|
|
43
|
+
const removeLastChar = str => {
|
|
43
44
|
return str.substring(0, str.length - 1)
|
|
44
45
|
}
|
|
46
|
+
|
|
47
|
+
module.exports = {
|
|
48
|
+
dealWithNoAppId
|
|
49
|
+
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
const commandLineUsage = require('command-line-usage')
|
|
2
|
+
const i18n = require('i18n')
|
|
3
|
+
const constants = require('../../cliConstants')
|
|
4
|
+
const { commonHelpLinks } = require('../../common/commonHelp')
|
|
5
5
|
|
|
6
6
|
const auditUsageGuide = commandLineUsage([
|
|
7
7
|
{
|
|
@@ -49,10 +49,13 @@ const auditUsageGuide = commandLineUsage([
|
|
|
49
49
|
'app-groups',
|
|
50
50
|
'metadata',
|
|
51
51
|
'track',
|
|
52
|
-
'
|
|
52
|
+
'fingerprint'
|
|
53
53
|
]
|
|
54
54
|
},
|
|
55
|
-
commonHelpLinks()
|
|
55
|
+
commonHelpLinks()[0],
|
|
56
|
+
commonHelpLinks()[1]
|
|
56
57
|
])
|
|
57
58
|
|
|
58
|
-
|
|
59
|
+
module.exports = {
|
|
60
|
+
auditUsageGuide
|
|
61
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
const auditConfig = require('./auditConfig')
|
|
2
|
+
const { auditUsageGuide } = require('./help')
|
|
3
|
+
const scaController = require('../scan/sca/scaAnalysis')
|
|
4
|
+
const { sendTelemetryConfigAsObject } = require('../../telemetry/telemetry')
|
|
5
|
+
const { postRunMessage } = require('../../common/commonHelp')
|
|
6
|
+
|
|
7
|
+
const processAudit = async (contrastConf, argvMain) => {
|
|
8
|
+
if (argvMain.indexOf('--help') !== -1) {
|
|
9
|
+
printHelpMessage()
|
|
10
|
+
process.exit(0)
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
const config = await auditConfig.getAuditConfig(
|
|
14
|
+
contrastConf,
|
|
15
|
+
'audit',
|
|
16
|
+
argvMain
|
|
17
|
+
)
|
|
18
|
+
await scaController.processSca(config)
|
|
19
|
+
if (!config.fingerprint) {
|
|
20
|
+
postRunMessage('audit')
|
|
21
|
+
await sendTelemetryConfigAsObject(
|
|
22
|
+
config,
|
|
23
|
+
'audit',
|
|
24
|
+
argvMain,
|
|
25
|
+
'SUCCESS',
|
|
26
|
+
config.language
|
|
27
|
+
)
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const printHelpMessage = () => {
|
|
32
|
+
console.log(auditUsageGuide)
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
module.exports = {
|
|
36
|
+
processAudit
|
|
37
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
const fs = require('fs')
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
const saveFile = (config, type, rawResults) => {
|
|
4
4
|
const fileName = `${config.applicationId}-sbom-${type}.json`
|
|
5
5
|
fs.writeFileSync(fileName, JSON.stringify(rawResults))
|
|
6
6
|
}
|
|
@@ -5,7 +5,7 @@ const { ScanResultsModel } = require('../../scan/models/scanResultsModel')
|
|
|
5
5
|
const { formatScanOutput } = require('../../scan/formatScanOutput')
|
|
6
6
|
const common = require('../../common/fail')
|
|
7
7
|
const { sendTelemetryConfigAsObject } = require('../../telemetry/telemetry')
|
|
8
|
-
const
|
|
8
|
+
const { postRunMessage } = require('../../common/commonHelp')
|
|
9
9
|
|
|
10
10
|
const processScan = async (contrastConf, argv) => {
|
|
11
11
|
let config = await scanConfig.getScanConfig(contrastConf, 'scan', argv)
|
|
@@ -26,21 +26,15 @@ const processScan = async (contrastConf, argv) => {
|
|
|
26
26
|
|
|
27
27
|
if (config.save !== undefined) {
|
|
28
28
|
await saveScanFile(config, scanResults)
|
|
29
|
+
} else {
|
|
30
|
+
console.log('\nUse contrast scan --save to save results as a SARIF')
|
|
29
31
|
}
|
|
30
32
|
|
|
31
33
|
if (config.fail) {
|
|
32
34
|
common.processFail(config, output)
|
|
33
35
|
}
|
|
34
36
|
|
|
35
|
-
postRunMessage()
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
const postRunMessage = () => {
|
|
39
|
-
console.log('\n' + chalk.underline.bold('Other Codesec Features:'))
|
|
40
|
-
console.log(
|
|
41
|
-
"'contrast audit' to find vulnerabilities in your open source dependencies"
|
|
42
|
-
)
|
|
43
|
-
console.log("'contrast lambda' to secure your AWS serverless functions\n")
|
|
37
|
+
postRunMessage('scan')
|
|
44
38
|
}
|
|
45
39
|
|
|
46
40
|
module.exports = {
|
|
@@ -20,7 +20,7 @@ const path = require('path')
|
|
|
20
20
|
const i18n = require('i18n')
|
|
21
21
|
const auditSave = require('../../../audit/save')
|
|
22
22
|
const { auditUsageGuide } = require('../../audit/help')
|
|
23
|
-
const
|
|
23
|
+
const repoMode = require('../../../scaAnalysis/repoMode/index')
|
|
24
24
|
const { dotNetAnalysis } = require('../../../scaAnalysis/dotnet')
|
|
25
25
|
const { goAnalysis } = require('../../../scaAnalysis/go/goAnalysis')
|
|
26
26
|
const { phpAnalysis } = require('../../../scaAnalysis/php/index')
|
|
@@ -32,6 +32,7 @@ const auditReport = require('../../../scaAnalysis/common/auditReport')
|
|
|
32
32
|
const scaUpload = require('../../../scaAnalysis/common/scaServicesUpload')
|
|
33
33
|
const settingsHelper = require('../../../utils/settingsHelper')
|
|
34
34
|
const chalk = require('chalk')
|
|
35
|
+
const saveResults = require('../../../scan/saveResults')
|
|
35
36
|
|
|
36
37
|
const processSca = async config => {
|
|
37
38
|
//checks to see whether to use old TS / new SCA path
|
|
@@ -53,130 +54,147 @@ const processSca = async config => {
|
|
|
53
54
|
? rootFile.getDirectoryFromPathGiven(config.file).concat('/')
|
|
54
55
|
: config.file
|
|
55
56
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
57
|
+
if (config.fingerprint && config.experimental) {
|
|
58
|
+
let fingerprint = await autoDetection.autoDetectFingerprintInfo(config.file)
|
|
59
|
+
let idArray = fingerprint.map(x => x.id)
|
|
60
|
+
await saveResults.writeResultsToFile(fingerprint, 'fingerPrintInfo.json')
|
|
61
|
+
console.log(idArray)
|
|
62
|
+
} else {
|
|
63
|
+
filesFound = await autoDetection.autoDetectAuditFilesAndLanguages(
|
|
64
|
+
config.file
|
|
61
65
|
)
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
// files found looks like [ { javascript: [ Array ] } ]
|
|
65
|
-
//check we have the language and call the right analyser
|
|
66
|
-
//refactor new analyser and see if we can clean it up
|
|
67
|
-
if (config.mode === 'repo') {
|
|
68
|
-
try {
|
|
69
|
-
return buildRepo(config, filesFound[0])
|
|
70
|
-
} catch (e) {
|
|
71
|
-
console.log('Unable to build in repository mode. Check your project file')
|
|
72
|
-
process.exit(0)
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
66
|
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
case JAVA:
|
|
80
|
-
messageToSend = javaAnalysis.javaAnalysis(config, filesFound[0])
|
|
81
|
-
config.language = JAVA
|
|
82
|
-
break
|
|
83
|
-
case JAVASCRIPT:
|
|
84
|
-
messageToSend = await jsAnalysis.jsAnalysis(config, filesFound[0])
|
|
85
|
-
config.language = NODE
|
|
86
|
-
break
|
|
87
|
-
case PYTHON:
|
|
88
|
-
messageToSend = pythonAnalysis(config, filesFound[0])
|
|
89
|
-
config.language = PYTHON
|
|
90
|
-
break
|
|
91
|
-
case RUBY:
|
|
92
|
-
messageToSend = rubyAnalysis(config, filesFound[0])
|
|
93
|
-
config.language = RUBY
|
|
94
|
-
break
|
|
95
|
-
case PHP:
|
|
96
|
-
messageToSend = phpAnalysis(config, filesFound[0])
|
|
97
|
-
config.language = PHP
|
|
98
|
-
break
|
|
99
|
-
case GO:
|
|
100
|
-
messageToSend = goAnalysis(config, filesFound[0])
|
|
101
|
-
config.language = GO
|
|
102
|
-
break
|
|
103
|
-
case DOTNET:
|
|
104
|
-
messageToSend = dotNetAnalysis(config, filesFound[0])
|
|
105
|
-
config.language = DOTNET
|
|
106
|
-
break
|
|
107
|
-
default:
|
|
108
|
-
//something is wrong
|
|
109
|
-
console.log('No supported language detected in project path')
|
|
110
|
-
return
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
if (!config.applicationId) {
|
|
114
|
-
config.applicationId = await auditController.dealWithNoAppId(config)
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
if (config.experimental) {
|
|
118
|
-
console.log('') //empty log for space before spinner
|
|
119
|
-
const reportSpinner = returnOra(i18n.__('auditSCAAnalysisBegins'))
|
|
120
|
-
startSpinner(reportSpinner)
|
|
121
|
-
const [reports, reportId] = await scaUpload.scaTreeUpload(
|
|
122
|
-
messageToSend,
|
|
123
|
-
config
|
|
67
|
+
if (filesFound.length > 1 && pathWithFile) {
|
|
68
|
+
filesFound = filesFound.filter(i =>
|
|
69
|
+
Object.values(i)[0].includes(path.basename(config.fileName))
|
|
124
70
|
)
|
|
71
|
+
}
|
|
125
72
|
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
73
|
+
// files found looks like [ { javascript: [ Array ] } ]
|
|
74
|
+
//check we have the language and call the right analyser
|
|
75
|
+
let messageToSend = undefined
|
|
76
|
+
if (filesFound.length === 1) {
|
|
77
|
+
switch (Object.keys(filesFound[0])[0]) {
|
|
78
|
+
case JAVA:
|
|
79
|
+
config.language = JAVA
|
|
80
|
+
|
|
81
|
+
if (config.mode === 'repo') {
|
|
82
|
+
try {
|
|
83
|
+
return repoMode.buildRepo(config, filesFound[0])
|
|
84
|
+
} catch (e) {
|
|
85
|
+
throw new Error(
|
|
86
|
+
'Unable to build in repository mode. Check your project file'
|
|
87
|
+
)
|
|
88
|
+
}
|
|
89
|
+
} else {
|
|
90
|
+
messageToSend = await javaAnalysis.javaAnalysis(
|
|
91
|
+
config,
|
|
92
|
+
filesFound[0]
|
|
93
|
+
)
|
|
94
|
+
}
|
|
95
|
+
break
|
|
96
|
+
case JAVASCRIPT:
|
|
97
|
+
messageToSend = await jsAnalysis.jsAnalysis(config, filesFound[0])
|
|
98
|
+
config.language = NODE
|
|
99
|
+
break
|
|
100
|
+
case PYTHON:
|
|
101
|
+
messageToSend = pythonAnalysis(config, filesFound[0])
|
|
102
|
+
config.language = PYTHON
|
|
103
|
+
break
|
|
104
|
+
case RUBY:
|
|
105
|
+
messageToSend = rubyAnalysis(config, filesFound[0])
|
|
106
|
+
config.language = RUBY
|
|
107
|
+
break
|
|
108
|
+
case PHP:
|
|
109
|
+
messageToSend = phpAnalysis(config, filesFound[0])
|
|
110
|
+
config.language = PHP
|
|
111
|
+
break
|
|
112
|
+
case GO:
|
|
113
|
+
messageToSend = goAnalysis(config, filesFound[0])
|
|
114
|
+
config.language = GO
|
|
115
|
+
break
|
|
116
|
+
case DOTNET:
|
|
117
|
+
messageToSend = dotNetAnalysis(config, filesFound[0])
|
|
118
|
+
config.language = DOTNET
|
|
119
|
+
break
|
|
120
|
+
default:
|
|
121
|
+
//something is wrong
|
|
122
|
+
console.log('No supported language detected in project path')
|
|
123
|
+
return
|
|
131
124
|
}
|
|
132
125
|
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
console.log(
|
|
136
|
-
`----- completed in ${(scanDurationMs / 1000).toFixed(2)}s -----`
|
|
137
|
-
)
|
|
138
|
-
} else {
|
|
139
|
-
console.log('') //empty log for space before spinner
|
|
140
|
-
//send message to TS
|
|
141
|
-
const reportSpinner = returnOra(i18n.__('auditSCAAnalysisBegins'))
|
|
142
|
-
startSpinner(reportSpinner)
|
|
143
|
-
const snapshotResponse = await treeUpload.commonSendSnapShot(
|
|
144
|
-
messageToSend,
|
|
145
|
-
config
|
|
146
|
-
)
|
|
147
|
-
|
|
148
|
-
// poll for completion
|
|
149
|
-
await pollForSnapshotCompletion(
|
|
150
|
-
config,
|
|
151
|
-
snapshotResponse.id,
|
|
152
|
-
reportSpinner
|
|
153
|
-
)
|
|
154
|
-
succeedSpinner(reportSpinner, i18n.__('auditSCAAnalysisComplete'))
|
|
155
|
-
|
|
156
|
-
await vulnerabilityReportV2(config, snapshotResponse.id)
|
|
157
|
-
if (config.save !== undefined) {
|
|
158
|
-
await auditSave.auditSave(config)
|
|
126
|
+
if (!config.applicationId) {
|
|
127
|
+
config.applicationId = await auditController.dealWithNoAppId(config)
|
|
159
128
|
}
|
|
160
|
-
const endTime = performance.now() - startTime
|
|
161
|
-
const scanDurationMs = endTime - startTime
|
|
162
129
|
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
130
|
+
if (config.experimental) {
|
|
131
|
+
console.log('') //empty log for space before spinner
|
|
132
|
+
const reportSpinner = returnOra(i18n.__('auditSCAAnalysisBegins'))
|
|
133
|
+
startSpinner(reportSpinner)
|
|
134
|
+
const [reports, reportId] = await scaUpload.scaTreeUpload(
|
|
135
|
+
messageToSend,
|
|
136
|
+
config
|
|
137
|
+
)
|
|
138
|
+
|
|
139
|
+
auditReport.processAuditReport(config, reports[0])
|
|
140
|
+
succeedSpinner(reportSpinner, i18n.__('auditSCAAnalysisComplete'))
|
|
141
|
+
|
|
142
|
+
if (config.save !== undefined) {
|
|
143
|
+
await auditSave.auditSave(config, reportId)
|
|
144
|
+
} else {
|
|
145
|
+
console.log('Use contrast audit --save to generate an SBOM')
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
const endTime = performance.now() - startTime
|
|
149
|
+
const scanDurationMs = endTime - startTime
|
|
150
|
+
console.log(
|
|
151
|
+
`----- completed in ${(scanDurationMs / 1000).toFixed(2)}s -----`
|
|
152
|
+
)
|
|
153
|
+
} else {
|
|
154
|
+
console.log('') //empty log for space before spinner
|
|
155
|
+
//send message to TS
|
|
156
|
+
const reportSpinner = returnOra(i18n.__('auditSCAAnalysisBegins'))
|
|
157
|
+
startSpinner(reportSpinner)
|
|
158
|
+
const snapshotResponse = await treeUpload.commonSendSnapShot(
|
|
159
|
+
messageToSend,
|
|
160
|
+
config
|
|
161
|
+
)
|
|
162
|
+
|
|
163
|
+
// poll for completion
|
|
164
|
+
await pollForSnapshotCompletion(
|
|
165
|
+
config,
|
|
166
|
+
snapshotResponse.id,
|
|
167
|
+
reportSpinner
|
|
168
|
+
)
|
|
169
|
+
succeedSpinner(reportSpinner, i18n.__('auditSCAAnalysisComplete'))
|
|
170
|
+
|
|
171
|
+
await vulnerabilityReportV2(config, snapshotResponse.id)
|
|
172
|
+
if (config.save !== undefined) {
|
|
173
|
+
await auditSave.auditSave(config)
|
|
174
|
+
} else {
|
|
175
|
+
console.log('\nUse contrast audit --save to generate an SBOM')
|
|
176
|
+
}
|
|
177
|
+
const endTime = performance.now() - startTime
|
|
178
|
+
const scanDurationMs = endTime - startTime
|
|
179
|
+
|
|
180
|
+
console.log(
|
|
181
|
+
`----- completed in ${(scanDurationMs / 1000).toFixed(2)}s -----`
|
|
182
|
+
)
|
|
183
|
+
}
|
|
172
184
|
} else {
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
console.log(
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
185
|
+
if (filesFound.length === 0) {
|
|
186
|
+
console.log(i18n.__('languageAnalysisNoLanguage'))
|
|
187
|
+
console.log(i18n.__('languageAnalysisNoLanguageHelpLine'))
|
|
188
|
+
throw new Error()
|
|
189
|
+
} else {
|
|
190
|
+
console.log(chalk.bold(`\nMultiple language files detected \n`))
|
|
191
|
+
filesFound.forEach(file => {
|
|
192
|
+
console.log(`${Object.keys(file)[0]} : `, Object.values(file)[0])
|
|
193
|
+
})
|
|
194
|
+
throw new Error(
|
|
195
|
+
`Please use --file to audit one language only. \nExample: contrast audit --file package-lock.json`
|
|
196
|
+
)
|
|
197
|
+
}
|
|
180
198
|
}
|
|
181
199
|
}
|
|
182
200
|
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
const i18n = require('i18n')
|
|
2
|
+
const chalk = require('chalk')
|
|
3
|
+
|
|
4
|
+
const commonHelpLinks = () => {
|
|
5
|
+
return [
|
|
6
|
+
{
|
|
7
|
+
header: i18n.__('commonHelpHeader'),
|
|
8
|
+
content: [
|
|
9
|
+
i18n.__('commonHelpCheckOutHeader') + i18n.__('commonHelpCheckOutText'),
|
|
10
|
+
i18n.__('commonHelpLearnMoreHeader') +
|
|
11
|
+
i18n.__('commonHelpLearnMoreText'),
|
|
12
|
+
i18n.__('commonHelpJoinDiscussionHeader') +
|
|
13
|
+
i18n.__('commonHelpJoinDiscussionText')
|
|
14
|
+
]
|
|
15
|
+
},
|
|
16
|
+
{
|
|
17
|
+
header: i18n.__('commonHelpEnterpriseHeader'),
|
|
18
|
+
content: [
|
|
19
|
+
i18n.__('commonHelpLearnMoreEnterpriseHeader') +
|
|
20
|
+
i18n.__('commonHelpLearnMoreEnterpriseText')
|
|
21
|
+
]
|
|
22
|
+
}
|
|
23
|
+
]
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const postRunMessage = commandName => {
|
|
27
|
+
console.log('\n' + chalk.underline.bold('Other Features:'))
|
|
28
|
+
if (commandName !== 'scan')
|
|
29
|
+
console.log(
|
|
30
|
+
"'contrast scan' to run Contrasts’ industry leading SAST scanner"
|
|
31
|
+
)
|
|
32
|
+
if (commandName !== 'audit')
|
|
33
|
+
console.log(
|
|
34
|
+
"'contrast audit' to find vulnerabilities in your open source dependencies"
|
|
35
|
+
)
|
|
36
|
+
if (commandName !== 'lambda')
|
|
37
|
+
console.log("'contrast lambda' to secure your AWS serverless functions")
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
module.exports = {
|
|
41
|
+
commonHelpLinks,
|
|
42
|
+
postRunMessage
|
|
43
|
+
}
|
|
@@ -1,26 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
const handleResponseErrors = (res: any, api: string) => {
|
|
4
|
-
if (res.statusCode === 400) {
|
|
5
|
-
api === 'catalogue' ? badRequestError(true) : badRequestError(false)
|
|
6
|
-
} else if (res.statusCode === 401) {
|
|
7
|
-
unauthenticatedError()
|
|
8
|
-
} else if (res.statusCode === 403) {
|
|
9
|
-
forbiddenError()
|
|
10
|
-
} else if (res.statusCode === 407) {
|
|
11
|
-
proxyError()
|
|
12
|
-
} else {
|
|
13
|
-
if (api === 'snapshot' || api === 'catalogue') {
|
|
14
|
-
snapshotFailureError()
|
|
15
|
-
}
|
|
16
|
-
if (api === 'vulnerabilities') {
|
|
17
|
-
vulnerabilitiesFailureError()
|
|
18
|
-
}
|
|
19
|
-
if (api === 'report') {
|
|
20
|
-
reportFailureError()
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
}
|
|
1
|
+
const i18n = require('i18n')
|
|
24
2
|
|
|
25
3
|
const libraryAnalysisError = () => {
|
|
26
4
|
console.log(i18n.__('libraryAnalysisError'))
|
|
@@ -47,7 +25,7 @@ const unauthenticatedError = () => {
|
|
|
47
25
|
generalError('unauthenticatedErrorHeader', 'unauthenticatedErrorMessage')
|
|
48
26
|
}
|
|
49
27
|
|
|
50
|
-
const badRequestError =
|
|
28
|
+
const badRequestError = catalogue => {
|
|
51
29
|
catalogue === true
|
|
52
30
|
? generalError('badRequestErrorHeader', 'badRequestCatalogueErrorMessage')
|
|
53
31
|
: generalError('badRequestErrorHeader', 'badRequestErrorMessage')
|
|
@@ -86,7 +64,7 @@ const failOptionError = () => {
|
|
|
86
64
|
* @param message message for the error
|
|
87
65
|
* @returns error in general format
|
|
88
66
|
*/
|
|
89
|
-
const getErrorMessage = (header
|
|
67
|
+
const getErrorMessage = (header, message) => {
|
|
90
68
|
// prettier-ignore
|
|
91
69
|
const title = `******************************** ${i18n.__(header)} ********************************`
|
|
92
70
|
const multiLine = message?.includes('\n')
|
|
@@ -102,12 +80,12 @@ const getErrorMessage = (header: string, message?: string) => {
|
|
|
102
80
|
return `${title}${finalMessage}`
|
|
103
81
|
}
|
|
104
82
|
|
|
105
|
-
const generalError = (header
|
|
83
|
+
const generalError = (header, message) => {
|
|
106
84
|
const finalMessage = getErrorMessage(header, message)
|
|
107
85
|
console.log(finalMessage)
|
|
108
86
|
}
|
|
109
87
|
|
|
110
|
-
const findCommandOnError =
|
|
88
|
+
const findCommandOnError = unknownOptions => {
|
|
111
89
|
const commandKeywords = {
|
|
112
90
|
auth: 'auth',
|
|
113
91
|
audit: 'audit',
|
|
@@ -117,13 +95,11 @@ const findCommandOnError = (unknownOptions: string[]) => {
|
|
|
117
95
|
}
|
|
118
96
|
|
|
119
97
|
const containsCommandKeyword = unknownOptions.some(
|
|
120
|
-
// @ts-ignore
|
|
121
98
|
command => commandKeywords[command]
|
|
122
99
|
)
|
|
123
100
|
|
|
124
101
|
if (containsCommandKeyword) {
|
|
125
102
|
const foundCommands = unknownOptions.filter(
|
|
126
|
-
// @ts-ignore
|
|
127
103
|
command => commandKeywords[command]
|
|
128
104
|
)
|
|
129
105
|
|
|
@@ -132,7 +108,7 @@ const findCommandOnError = (unknownOptions: string[]) => {
|
|
|
132
108
|
}
|
|
133
109
|
}
|
|
134
110
|
|
|
135
|
-
|
|
111
|
+
module.exports = {
|
|
136
112
|
genericError,
|
|
137
113
|
unauthenticatedError,
|
|
138
114
|
badRequestError,
|
|
@@ -141,7 +117,6 @@ export {
|
|
|
141
117
|
failOptionError,
|
|
142
118
|
generalError,
|
|
143
119
|
getErrorMessage,
|
|
144
|
-
handleResponseErrors,
|
|
145
120
|
libraryAnalysisError,
|
|
146
121
|
findCommandOnError,
|
|
147
122
|
snapshotFailureError,
|
|
@@ -1,12 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
import { ContrastConf } from '../utils/getConfig'
|
|
1
|
+
const { APP_VERSION } = require('../constants/constants')
|
|
2
|
+
const boxen = require('boxen')
|
|
3
|
+
const chalk = require('chalk')
|
|
4
|
+
const semver = require('semver')
|
|
5
|
+
const commonApi = require('../utils/commonApi')
|
|
6
|
+
const { constants } = require('http2')
|
|
8
7
|
|
|
9
|
-
|
|
8
|
+
const getLatestVersion = async config => {
|
|
10
9
|
const client = commonApi.getHttpClient(config)
|
|
11
10
|
try {
|
|
12
11
|
const res = await client.getLatestVersion()
|
|
@@ -18,7 +17,7 @@ export const getLatestVersion = async (config: ContrastConf) => {
|
|
|
18
17
|
}
|
|
19
18
|
}
|
|
20
19
|
|
|
21
|
-
|
|
20
|
+
const findLatestCLIVersion = async config => {
|
|
22
21
|
const isCI = process.env.CONTRAST_CODESEC_CI
|
|
23
22
|
? JSON.parse(process.env.CONTRAST_CODESEC_CI.toLowerCase())
|
|
24
23
|
: false
|
|
@@ -65,6 +64,12 @@ export async function findLatestCLIVersion(config: ContrastConf) {
|
|
|
65
64
|
}
|
|
66
65
|
}
|
|
67
66
|
|
|
68
|
-
|
|
67
|
+
const isCorrectNodeVersion = async currentVersion => {
|
|
69
68
|
return semver.satisfies(currentVersion, '>=16')
|
|
70
69
|
}
|
|
70
|
+
|
|
71
|
+
module.exports = {
|
|
72
|
+
getLatestVersion,
|
|
73
|
+
findLatestCLIVersion,
|
|
74
|
+
isCorrectNodeVersion
|
|
75
|
+
}
|
package/src/constants/locales.js
CHANGED
|
@@ -209,11 +209,11 @@ const en_locales = () => {
|
|
|
209
209
|
constantsProxyCaCert: 'Path to the CaCert file',
|
|
210
210
|
goReadProjectFile: 'Failed to read the project file @ "%s" because: "%s"',
|
|
211
211
|
mavenDependencyTreeNonZero:
|
|
212
|
-
'Building maven
|
|
212
|
+
'Building maven dependency tree failed with a non 0 exit code',
|
|
213
213
|
gradleWrapperUnavailable:
|
|
214
214
|
'Gradle wrapper not found in root of project. Please ensure gradlew or gradlew.bat is in root of the project.',
|
|
215
215
|
gradleDependencyTreeNonZero:
|
|
216
|
-
"Building gradle
|
|
216
|
+
"Building gradle dependency tree failed with a non 0 exit code. \n Please check you have the correct version of Java installed to compile your project? \n If running against a muti module project ensure you are using the '--sub-project' flag",
|
|
217
217
|
constantsMetadata:
|
|
218
218
|
'Define a set of key=value pairs (which conforms to RFC 2253) for specifying user-defined metadata associated with the application.',
|
|
219
219
|
constantsTags:
|
|
@@ -415,10 +415,14 @@ const en_locales = () => {
|
|
|
415
415
|
auditSCAAnalysisBegins: 'Contrast SCA audit started',
|
|
416
416
|
auditSCAAnalysisComplete: 'Contrast audit complete',
|
|
417
417
|
commonHelpHeader: 'Need More Help?',
|
|
418
|
+
commonHelpEnterpriseHeader: 'Existing Contrast user?',
|
|
418
419
|
commonHelpCheckOutHeader: chalk.hex('#9DC184')('Check out:'),
|
|
419
420
|
commonHelpCheckOutText: ' https://support.contrastsecurity.com',
|
|
420
421
|
commonHelpLearnMoreHeader: chalk.hex('#9DC184')('Learn more at:'),
|
|
421
|
-
|
|
422
|
+
commonHelpLearnMoreEnterpriseHeader: chalk.hex('#9DC184')('Read our docs:'),
|
|
423
|
+
commonHelpLearnMoreText: ' https://www.contrastsecurity.com/developer ',
|
|
424
|
+
commonHelpLearnMoreEnterpriseText:
|
|
425
|
+
' https://docs.contrastsecurity.com/en/run-contrast-cli.html ',
|
|
422
426
|
commonHelpJoinDiscussionHeader: chalk.hex('#9DC184')(
|
|
423
427
|
'Join the discussion:'
|
|
424
428
|
),
|
package/src/lambda/help.ts
CHANGED