@contrast/contrast 1.0.16 → 1.0.18
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 +91 -109
- package/dist/commands/audit/auditConfig.js +10 -12
- package/dist/commands/audit/auditController.js +12 -16
- package/dist/commands/audit/help.js +32 -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 +105 -88
- package/dist/common/HTTPClient.js +1 -1
- package/dist/common/commonHelp.js +35 -17
- package/dist/common/errorHandling.js +38 -57
- package/dist/common/versionChecker.js +24 -27
- package/dist/constants/constants.js +1 -1
- package/dist/constants/locales.js +20 -91
- 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 +14 -2
- package/dist/scan/autoDetection.js +26 -3
- package/dist/scan/fileUtils.js +24 -1
- package/dist/scan/help.js +11 -4
- package/dist/scan/saveResults.js +1 -1
- package/dist/utils/commonApi.js +16 -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 +96 -116
- 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} +19 -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 +135 -115
- package/src/common/HTTPClient.js +1 -1
- package/src/common/commonHelp.js +43 -0
- package/src/common/{errorHandling.ts → errorHandling.js} +25 -32
- package/src/common/{versionChecker.ts → versionChecker.js} +15 -10
- package/src/constants/constants.js +1 -1
- package/src/constants/locales.js +23 -129
- 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 +34 -3
- package/src/scan/fileUtils.js +29 -1
- package/src/scan/help.js +12 -4
- package/src/scan/saveResults.js +1 -1
- package/src/utils/commonApi.js +19 -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
|
@@ -11,7 +11,7 @@ const path = require('path');
|
|
|
11
11
|
const i18n = require('i18n');
|
|
12
12
|
const auditSave = require('../../../audit/save');
|
|
13
13
|
const { auditUsageGuide } = require('../../audit/help');
|
|
14
|
-
const
|
|
14
|
+
const repoMode = require('../../../scaAnalysis/repoMode/index');
|
|
15
15
|
const { dotNetAnalysis } = require('../../../scaAnalysis/dotnet');
|
|
16
16
|
const { goAnalysis } = require('../../../scaAnalysis/go/goAnalysis');
|
|
17
17
|
const { phpAnalysis } = require('../../../scaAnalysis/php/index');
|
|
@@ -23,6 +23,7 @@ const auditReport = require('../../../scaAnalysis/common/auditReport');
|
|
|
23
23
|
const scaUpload = require('../../../scaAnalysis/common/scaServicesUpload');
|
|
24
24
|
const settingsHelper = require('../../../utils/settingsHelper');
|
|
25
25
|
const chalk = require('chalk');
|
|
26
|
+
const saveResults = require('../../../scan/saveResults');
|
|
26
27
|
const processSca = async (config) => {
|
|
27
28
|
config = await settingsHelper.getSettings(config);
|
|
28
29
|
const startTime = performance.now();
|
|
@@ -37,99 +38,115 @@ const processSca = async (config) => {
|
|
|
37
38
|
config.file = pathWithFile
|
|
38
39
|
? rootFile.getDirectoryFromPathGiven(config.file).concat('/')
|
|
39
40
|
: config.file;
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
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);
|
|
43
46
|
}
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
console.log('Unable to build in repository mode. Check your project file');
|
|
50
|
-
process.exit(0);
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
let messageToSend = undefined;
|
|
54
|
-
if (filesFound.length === 1) {
|
|
55
|
-
switch (Object.keys(filesFound[0])[0]) {
|
|
56
|
-
case JAVA:
|
|
57
|
-
messageToSend = javaAnalysis.javaAnalysis(config, filesFound[0]);
|
|
58
|
-
config.language = JAVA;
|
|
59
|
-
break;
|
|
60
|
-
case JAVASCRIPT:
|
|
61
|
-
messageToSend = await jsAnalysis.jsAnalysis(config, filesFound[0]);
|
|
62
|
-
config.language = NODE;
|
|
63
|
-
break;
|
|
64
|
-
case PYTHON:
|
|
65
|
-
messageToSend = pythonAnalysis(config, filesFound[0]);
|
|
66
|
-
config.language = PYTHON;
|
|
67
|
-
break;
|
|
68
|
-
case RUBY:
|
|
69
|
-
messageToSend = rubyAnalysis(config, filesFound[0]);
|
|
70
|
-
config.language = RUBY;
|
|
71
|
-
break;
|
|
72
|
-
case PHP:
|
|
73
|
-
messageToSend = phpAnalysis(config, filesFound[0]);
|
|
74
|
-
config.language = PHP;
|
|
75
|
-
break;
|
|
76
|
-
case GO:
|
|
77
|
-
messageToSend = goAnalysis(config, filesFound[0]);
|
|
78
|
-
config.language = GO;
|
|
79
|
-
break;
|
|
80
|
-
case DOTNET:
|
|
81
|
-
messageToSend = dotNetAnalysis(config, filesFound[0]);
|
|
82
|
-
config.language = DOTNET;
|
|
83
|
-
break;
|
|
84
|
-
default:
|
|
85
|
-
console.log('No supported language detected in project path');
|
|
86
|
-
return;
|
|
87
|
-
}
|
|
88
|
-
if (!config.applicationId) {
|
|
89
|
-
config.applicationId = await auditController.dealWithNoAppId(config);
|
|
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)));
|
|
90
52
|
}
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
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;
|
|
100
97
|
}
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
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 -----`);
|
|
115
135
|
}
|
|
116
|
-
const endTime = performance.now() - startTime;
|
|
117
|
-
const scanDurationMs = endTime - startTime;
|
|
118
|
-
console.log(`----- completed in ${(scanDurationMs / 1000).toFixed(2)}s -----`);
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
else {
|
|
122
|
-
if (filesFound.length === 0) {
|
|
123
|
-
console.log(i18n.__('languageAnalysisNoLanguage'));
|
|
124
|
-
console.log(i18n.__('languageAnalysisNoLanguageHelpLine'));
|
|
125
|
-
throw new Error();
|
|
126
136
|
}
|
|
127
137
|
else {
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
console.log(
|
|
131
|
-
|
|
132
|
-
|
|
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
|
+
}
|
|
133
150
|
}
|
|
134
151
|
}
|
|
135
152
|
};
|
|
@@ -6,7 +6,7 @@ const { AUTH_CALLBACK_URL } = require('../constants/constants');
|
|
|
6
6
|
function HTTPClient(config) {
|
|
7
7
|
const apiKey = config.apiKey;
|
|
8
8
|
const authToken = config.authorization;
|
|
9
|
-
this.rejectUnauthorized = !config.
|
|
9
|
+
this.rejectUnauthorized = !config.certSelfSigned;
|
|
10
10
|
const superApiKey = config.superApiKey;
|
|
11
11
|
const superAuthToken = config.superAuthorization;
|
|
12
12
|
this.requestOptions = {
|
|
@@ -1,19 +1,37 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
const i18n = require('i18n');
|
|
3
|
+
const chalk = require('chalk');
|
|
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
|
+
const postRunMessage = commandName => {
|
|
26
|
+
console.log('\n' + chalk.underline.bold('Other Features:'));
|
|
27
|
+
if (commandName !== 'scan')
|
|
28
|
+
console.log("'contrast scan' to run Contrasts’ industry leading SAST scanner");
|
|
29
|
+
if (commandName !== 'audit')
|
|
30
|
+
console.log("'contrast audit' to find vulnerabilities in your open source dependencies");
|
|
31
|
+
if (commandName !== 'lambda')
|
|
32
|
+
console.log("'contrast lambda' to secure your AWS serverless functions");
|
|
33
|
+
};
|
|
34
|
+
module.exports = {
|
|
35
|
+
commonHelpLinks,
|
|
36
|
+
postRunMessage
|
|
4
37
|
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.commonHelpLinks = void 0;
|
|
7
|
-
const i18n_1 = __importDefault(require("i18n"));
|
|
8
|
-
function commonHelpLinks() {
|
|
9
|
-
return {
|
|
10
|
-
header: i18n_1.default.__('commonHelpHeader'),
|
|
11
|
-
content: [
|
|
12
|
-
i18n_1.default.__('commonHelpCheckOutHeader') + i18n_1.default.__('commonHelpCheckOutText'),
|
|
13
|
-
i18n_1.default.__('commonHelpLearnMoreHeader') + i18n_1.default.__('commonHelpLearnMoreText'),
|
|
14
|
-
i18n_1.default.__('commonHelpJoinDiscussionHeader') +
|
|
15
|
-
i18n_1.default.__('commonHelpJoinDiscussionText')
|
|
16
|
-
]
|
|
17
|
-
};
|
|
18
|
-
}
|
|
19
|
-
exports.commonHelpLinks = commonHelpLinks;
|
|
@@ -1,107 +1,71 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.maxAppError = exports.reportFailureError = exports.vulnerabilitiesFailureError = exports.snapshotFailureError = exports.findCommandOnError = exports.libraryAnalysisError = exports.handleResponseErrors = exports.getErrorMessage = exports.generalError = exports.failOptionError = exports.proxyError = exports.forbiddenError = exports.badRequestError = exports.unauthenticatedError = exports.genericError = void 0;
|
|
7
|
-
const i18n_1 = __importDefault(require("i18n"));
|
|
8
|
-
const handleResponseErrors = (res, api) => {
|
|
9
|
-
if (res.statusCode === 400) {
|
|
10
|
-
api === 'catalogue' ? badRequestError(true) : badRequestError(false);
|
|
11
|
-
}
|
|
12
|
-
else if (res.statusCode === 401) {
|
|
13
|
-
unauthenticatedError();
|
|
14
|
-
}
|
|
15
|
-
else if (res.statusCode === 403) {
|
|
16
|
-
forbiddenError();
|
|
17
|
-
}
|
|
18
|
-
else if (res.statusCode === 407) {
|
|
19
|
-
proxyError();
|
|
20
|
-
}
|
|
21
|
-
else {
|
|
22
|
-
if (api === 'snapshot' || api === 'catalogue') {
|
|
23
|
-
snapshotFailureError();
|
|
24
|
-
}
|
|
25
|
-
if (api === 'vulnerabilities') {
|
|
26
|
-
vulnerabilitiesFailureError();
|
|
27
|
-
}
|
|
28
|
-
if (api === 'report') {
|
|
29
|
-
reportFailureError();
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
};
|
|
33
|
-
exports.handleResponseErrors = handleResponseErrors;
|
|
2
|
+
const i18n = require('i18n');
|
|
34
3
|
const libraryAnalysisError = () => {
|
|
35
|
-
console.log(
|
|
4
|
+
console.log(i18n.__('libraryAnalysisError'));
|
|
36
5
|
};
|
|
37
|
-
exports.libraryAnalysisError = libraryAnalysisError;
|
|
38
6
|
const snapshotFailureError = () => {
|
|
39
|
-
console.log(
|
|
7
|
+
console.log(i18n.__('snapshotFailureMessage'));
|
|
40
8
|
};
|
|
41
|
-
exports.snapshotFailureError = snapshotFailureError;
|
|
42
9
|
const vulnerabilitiesFailureError = () => {
|
|
43
|
-
console.log(
|
|
10
|
+
console.log(i18n.__('vulnerabilitiesFailureMessage'));
|
|
44
11
|
};
|
|
45
|
-
exports.vulnerabilitiesFailureError = vulnerabilitiesFailureError;
|
|
46
12
|
const reportFailureError = () => {
|
|
47
|
-
console.log(
|
|
13
|
+
console.log(i18n.__('auditReportFailureMessage'));
|
|
48
14
|
};
|
|
49
|
-
exports.reportFailureError = reportFailureError;
|
|
50
15
|
const genericError = () => {
|
|
51
|
-
console.error(
|
|
16
|
+
console.error(i18n.__('genericErrorMessage'));
|
|
52
17
|
process.exit(1);
|
|
53
18
|
};
|
|
54
|
-
exports.genericError = genericError;
|
|
55
19
|
const unauthenticatedError = () => {
|
|
56
20
|
generalError('unauthenticatedErrorHeader', 'unauthenticatedErrorMessage');
|
|
57
21
|
};
|
|
58
|
-
|
|
59
|
-
const badRequestError = (catalogue) => {
|
|
22
|
+
const badRequestError = catalogue => {
|
|
60
23
|
catalogue === true
|
|
61
24
|
? generalError('badRequestErrorHeader', 'badRequestCatalogueErrorMessage')
|
|
62
25
|
: generalError('badRequestErrorHeader', 'badRequestErrorMessage');
|
|
63
26
|
};
|
|
64
|
-
exports.badRequestError = badRequestError;
|
|
65
27
|
const forbiddenError = () => {
|
|
66
28
|
generalError('forbiddenRequestErrorHeader', 'forbiddenRequestErrorMessage');
|
|
67
29
|
process.exit(1);
|
|
68
30
|
};
|
|
69
|
-
exports.forbiddenError = forbiddenError;
|
|
70
31
|
const proxyError = () => {
|
|
71
32
|
generalError('proxyErrorHeader', 'proxyErrorMessage');
|
|
72
33
|
};
|
|
73
|
-
exports.proxyError = proxyError;
|
|
74
34
|
const maxAppError = () => {
|
|
75
35
|
generalError('No applications remaining', 'You have reached the maximum number of application you can create.');
|
|
76
36
|
process.exit(1);
|
|
77
37
|
};
|
|
78
|
-
|
|
38
|
+
const parametersError = () => {
|
|
39
|
+
generalError(`Values not recognised`, 'Check your command & keys again for hidden characters.\nFor more information use contrast help.');
|
|
40
|
+
process.exit(1);
|
|
41
|
+
};
|
|
42
|
+
const invalidHostNameError = () => {
|
|
43
|
+
generalError(`Invalid host`, 'Check that the host parameter does not include a trailing "/".');
|
|
44
|
+
process.exit(1);
|
|
45
|
+
};
|
|
79
46
|
const failOptionError = () => {
|
|
80
47
|
console.log('\n ******************************** ' +
|
|
81
|
-
|
|
48
|
+
i18n.__('snapshotFailureHeader') +
|
|
82
49
|
' ********************************\n' +
|
|
83
|
-
|
|
50
|
+
i18n.__('failOptionErrorMessage'));
|
|
84
51
|
};
|
|
85
|
-
exports.failOptionError = failOptionError;
|
|
86
52
|
const getErrorMessage = (header, message) => {
|
|
87
|
-
const title = `******************************** ${
|
|
53
|
+
const title = `******************************** ${i18n.__(header)} ********************************`;
|
|
88
54
|
const multiLine = message?.includes('\n');
|
|
89
55
|
let finalMessage = '';
|
|
90
56
|
if (multiLine) {
|
|
91
57
|
finalMessage = `\n${message}`;
|
|
92
58
|
}
|
|
93
59
|
else if (message) {
|
|
94
|
-
finalMessage = `\n${
|
|
60
|
+
finalMessage = `\n${i18n.__(message)}`;
|
|
95
61
|
}
|
|
96
62
|
return `${title}${finalMessage}`;
|
|
97
63
|
};
|
|
98
|
-
exports.getErrorMessage = getErrorMessage;
|
|
99
64
|
const generalError = (header, message) => {
|
|
100
65
|
const finalMessage = getErrorMessage(header, message);
|
|
101
66
|
console.log(finalMessage);
|
|
102
67
|
};
|
|
103
|
-
|
|
104
|
-
const findCommandOnError = (unknownOptions) => {
|
|
68
|
+
const findCommandOnError = unknownOptions => {
|
|
105
69
|
const commandKeywords = {
|
|
106
70
|
auth: 'auth',
|
|
107
71
|
audit: 'audit',
|
|
@@ -115,4 +79,21 @@ const findCommandOnError = (unknownOptions) => {
|
|
|
115
79
|
return foundCommands[0];
|
|
116
80
|
}
|
|
117
81
|
};
|
|
118
|
-
exports
|
|
82
|
+
module.exports = {
|
|
83
|
+
genericError,
|
|
84
|
+
unauthenticatedError,
|
|
85
|
+
badRequestError,
|
|
86
|
+
forbiddenError,
|
|
87
|
+
proxyError,
|
|
88
|
+
failOptionError,
|
|
89
|
+
generalError,
|
|
90
|
+
getErrorMessage,
|
|
91
|
+
libraryAnalysisError,
|
|
92
|
+
findCommandOnError,
|
|
93
|
+
snapshotFailureError,
|
|
94
|
+
vulnerabilitiesFailureError,
|
|
95
|
+
reportFailureError,
|
|
96
|
+
maxAppError,
|
|
97
|
+
parametersError,
|
|
98
|
+
invalidHostNameError
|
|
99
|
+
};
|
|
@@ -1,20 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
const
|
|
8
|
-
const boxen_1 = __importDefault(require("boxen"));
|
|
9
|
-
const chalk_1 = __importDefault(require("chalk"));
|
|
10
|
-
const semver_1 = __importDefault(require("semver"));
|
|
11
|
-
const commonApi_1 = __importDefault(require("../utils/commonApi"));
|
|
12
|
-
const http2_1 = require("http2");
|
|
2
|
+
const { APP_VERSION } = require('../constants/constants');
|
|
3
|
+
const boxen = require('boxen');
|
|
4
|
+
const chalk = require('chalk');
|
|
5
|
+
const semver = require('semver');
|
|
6
|
+
const commonApi = require('../utils/commonApi');
|
|
7
|
+
const { constants } = require('http2');
|
|
13
8
|
const getLatestVersion = async (config) => {
|
|
14
|
-
const client =
|
|
9
|
+
const client = commonApi.getHttpClient(config);
|
|
15
10
|
try {
|
|
16
11
|
const res = await client.getLatestVersion();
|
|
17
|
-
if (res.statusCode ===
|
|
12
|
+
if (res.statusCode === constants.HTTP_STATUS_OK) {
|
|
18
13
|
return res.body;
|
|
19
14
|
}
|
|
20
15
|
}
|
|
@@ -22,24 +17,23 @@ const getLatestVersion = async (config) => {
|
|
|
22
17
|
return undefined;
|
|
23
18
|
}
|
|
24
19
|
};
|
|
25
|
-
|
|
26
|
-
async function findLatestCLIVersion(config) {
|
|
20
|
+
const findLatestCLIVersion = async (config) => {
|
|
27
21
|
const isCI = process.env.CONTRAST_CODESEC_CI
|
|
28
22
|
? JSON.parse(process.env.CONTRAST_CODESEC_CI.toLowerCase())
|
|
29
23
|
: false;
|
|
30
24
|
if (!isCI) {
|
|
31
|
-
let latestCLIVersion = await
|
|
25
|
+
let latestCLIVersion = await getLatestVersion(config);
|
|
32
26
|
if (latestCLIVersion === undefined) {
|
|
33
27
|
config.set('numOfRuns', 0);
|
|
34
28
|
console.log('Failed to retrieve latest version info. Continuing execution.');
|
|
35
29
|
return;
|
|
36
30
|
}
|
|
37
31
|
latestCLIVersion = latestCLIVersion.substring(8).replace('\n', '');
|
|
38
|
-
if (
|
|
39
|
-
const updateAvailableMessage = `Update available ${
|
|
40
|
-
const npmUpdateAvailableCommand = `Run ${
|
|
41
|
-
const homebrewUpdateAvailableCommand = `Run ${
|
|
42
|
-
console.log((
|
|
32
|
+
if (semver.lt(APP_VERSION, latestCLIVersion)) {
|
|
33
|
+
const updateAvailableMessage = `Update available ${chalk.yellow(APP_VERSION)} → ${chalk.green(latestCLIVersion)}`;
|
|
34
|
+
const npmUpdateAvailableCommand = `Run ${chalk.cyan('npm i @contrast/contrast -g')} to update via npm`;
|
|
35
|
+
const homebrewUpdateAvailableCommand = `Run ${chalk.cyan('brew install contrastsecurity/tap/contrast')} to update via brew`;
|
|
36
|
+
console.log(boxen(`${updateAvailableMessage}\n${npmUpdateAvailableCommand}\n\n${homebrewUpdateAvailableCommand}`, {
|
|
43
37
|
titleAlignment: 'center',
|
|
44
38
|
margin: 1,
|
|
45
39
|
padding: 1,
|
|
@@ -47,9 +41,12 @@ async function findLatestCLIVersion(config) {
|
|
|
47
41
|
}));
|
|
48
42
|
}
|
|
49
43
|
}
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
44
|
+
};
|
|
45
|
+
const isCorrectNodeVersion = async (currentVersion) => {
|
|
46
|
+
return semver.satisfies(currentVersion, '>=16');
|
|
47
|
+
};
|
|
48
|
+
module.exports = {
|
|
49
|
+
getLatestVersion,
|
|
50
|
+
findLatestCLIVersion,
|
|
51
|
+
isCorrectNodeVersion
|
|
52
|
+
};
|
|
@@ -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.
|
|
15
|
+
const APP_VERSION = '1.0.18';
|
|
16
16
|
const TIMEOUT = 120000;
|
|
17
17
|
const HIGH_COLOUR = '#ff9900';
|
|
18
18
|
const CRITICAL_COLOUR = '#e35858';
|