@contrast/contrast 2.0.2-beta.1 → 2.0.2-beta.2
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/cliConstants.js +1 -0
- package/dist/commands/github/processFingerprint.js +1 -1
- package/dist/commands/github/projectGroup.js +6 -6
- package/dist/commands/github/repoServices.js +1 -1
- package/dist/{scan → common}/autoDetection.js +33 -9
- package/dist/constants/constants.js +1 -1
- package/dist/scaAnalysis/common/scaServicesUpload.js +3 -0
- package/dist/scaAnalysis/processServicesFlow.js +5 -3
- package/dist/scaAnalysis/repoMode/mavenParser.js +0 -1
- package/dist/scaAnalysis/scaAnalysis.js +2 -2
- package/dist/scan/fileUtils.js +14 -9
- package/dist/scan/scanController.js +1 -1
- package/package.json +1 -1
- package/src/cliConstants.js +1 -0
- package/src/commands/github/processFingerprint.js +1 -1
- package/src/commands/github/projectGroup.js +9 -5
- package/src/commands/github/repoServices.js +1 -1
- package/src/{scan → common}/autoDetection.js +44 -10
- package/src/constants/constants.js +1 -1
- package/src/scaAnalysis/common/scaServicesUpload.js +4 -0
- package/src/scaAnalysis/processServicesFlow.js +10 -3
- package/src/scaAnalysis/repoMode/mavenParser.js +0 -1
- package/src/scaAnalysis/scaAnalysis.js +3 -2
- package/src/scan/fileUtils.js +21 -9
- package/src/scan/scanController.js +1 -1
package/dist/cliConstants.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
const fingerprintConfig = require('./fingerprintConfig');
|
|
3
3
|
const repoServices = require('./repoServices');
|
|
4
|
-
const autoDetection = require('../../
|
|
4
|
+
const autoDetection = require('../../common/autoDetection');
|
|
5
5
|
const saveResults = require('../../scan/saveResults');
|
|
6
6
|
const projectConfig = require('./projectGroup');
|
|
7
7
|
const processFingerprint = async (contrastConf, argvMain) => {
|
|
@@ -79,10 +79,10 @@ const createProjectsArray = params => {
|
|
|
79
79
|
});
|
|
80
80
|
return projectsArray;
|
|
81
81
|
};
|
|
82
|
-
const createProject = param => {
|
|
82
|
+
const createProject = (param, shortenedProjectName) => {
|
|
83
83
|
return {
|
|
84
84
|
path: param.fileName,
|
|
85
|
-
name: param.repo ?
|
|
85
|
+
name: param.repo ? shortenedProjectName : getProjectName(param),
|
|
86
86
|
source: 'SCA',
|
|
87
87
|
language: param.language,
|
|
88
88
|
packageManager: param.packageManager,
|
|
@@ -121,11 +121,11 @@ const addAdditionalData = (body, data) => {
|
|
|
121
121
|
body.projectLanguage = data.projectLanguage ? data.projectLanguage : null;
|
|
122
122
|
body.projectType = data.projectType ? data.projectType : null;
|
|
123
123
|
};
|
|
124
|
-
const registerProjectIdOnCliServices = async (config, projectId, additionalData = undefined) => {
|
|
124
|
+
const registerProjectIdOnCliServices = async (config, projectId, shortenedProjectName, additionalData = undefined) => {
|
|
125
125
|
const client = commonApi.getHttpClient(config);
|
|
126
126
|
let cliServicesBody = {
|
|
127
127
|
projectId: projectId,
|
|
128
|
-
name: config.repo ?
|
|
128
|
+
name: config.repo ? shortenedProjectName : getProjectName(config)
|
|
129
129
|
};
|
|
130
130
|
if (additionalData) {
|
|
131
131
|
addAdditionalData(cliServicesBody, additionalData);
|
|
@@ -149,10 +149,10 @@ const registerProjectIdOnCliServices = async (config, projectId, additionalData
|
|
|
149
149
|
});
|
|
150
150
|
return result;
|
|
151
151
|
};
|
|
152
|
-
const registerProjectWithGroupProjectId = async (config) => {
|
|
152
|
+
const registerProjectWithGroupProjectId = async (config, shortenedProjectName) => {
|
|
153
153
|
const client = commonApi.getHttpClient(config);
|
|
154
154
|
config.language = config.language === 'NODE' ? 'JAVASCRIPT' : config.language;
|
|
155
|
-
let body = createProject(config);
|
|
155
|
+
let body = createProject(config, shortenedProjectName);
|
|
156
156
|
let result = await client.registerProject(config, body).then(res => {
|
|
157
157
|
if (config.debug || config.verbose) {
|
|
158
158
|
console.log('\nregister Project With Group ProjectId');
|
|
@@ -68,7 +68,7 @@ const registerNewRepo = async (config) => {
|
|
|
68
68
|
return result;
|
|
69
69
|
};
|
|
70
70
|
const retrieveProjectInfoViaRepoId = async (config) => {
|
|
71
|
-
const client =
|
|
71
|
+
const client = commonApi.getHttpClient(config);
|
|
72
72
|
let result = await client
|
|
73
73
|
.retrieveProjectByRepoId(config)
|
|
74
74
|
.then(res => {
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
const i18n = require('i18n');
|
|
3
|
-
const fileFinder = require('
|
|
4
|
-
const { supportedLanguages: { JAVA, GO, PYTHON, RUBY, JAVASCRIPT,
|
|
3
|
+
const fileFinder = require('../scan/fileUtils');
|
|
4
|
+
const { supportedLanguages: { JAVA, GO, PYTHON, RUBY, JAVASCRIPT, DOTNET } } = require('../constants/constants');
|
|
5
|
+
const { shortenFilePath } = require('../scan/fileUtils');
|
|
5
6
|
const autoDetectFingerprintInfo = async (filePath, depth, config) => {
|
|
6
7
|
let complexObj = await fileFinder.findAllFiles(filePath, depth);
|
|
7
8
|
let result = [];
|
|
@@ -10,6 +11,7 @@ const autoDetectFingerprintInfo = async (filePath, depth, config) => {
|
|
|
10
11
|
count++;
|
|
11
12
|
if (!i.includes('package.json')) {
|
|
12
13
|
result.push({
|
|
14
|
+
name: shortenFilePath(i),
|
|
13
15
|
filePath: i,
|
|
14
16
|
id: count.toString(),
|
|
15
17
|
repositoryId: config.repositoryId,
|
|
@@ -100,18 +102,40 @@ const hasWhiteSpace = s => {
|
|
|
100
102
|
const filename = s.split('/').pop();
|
|
101
103
|
return filename.indexOf(' ') >= 0;
|
|
102
104
|
};
|
|
103
|
-
const dealWithMultiJava = filesFound => {
|
|
104
|
-
|
|
105
|
-
return (
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
105
|
+
const dealWithMultiJava = (filesFound, config, isFile) => {
|
|
106
|
+
if (isFile) {
|
|
107
|
+
return multiJavaFilePathFullySpecified(filesFound, config);
|
|
108
|
+
}
|
|
109
|
+
else {
|
|
110
|
+
return multiJavaNoFilePathFullySpecified(filesFound);
|
|
111
|
+
}
|
|
112
|
+
};
|
|
113
|
+
const multiJavaNoFilePathFullySpecified = filesFound => {
|
|
114
|
+
const hasMultiJava = filesFound.filter(data => Object.keys(data)[0] === JAVA &&
|
|
115
|
+
Object.values(data)[0].includes('build.gradle') &&
|
|
116
|
+
Object.values(data)[0].includes('pom.xml')).length > 0;
|
|
109
117
|
if (hasMultiJava) {
|
|
110
118
|
console.log('Multiple Java language dependency files detected');
|
|
111
119
|
console.log('Please use --file to audit one only. \nExample: contrast audit --file pom.xml');
|
|
112
120
|
process.exit(1);
|
|
113
121
|
}
|
|
114
|
-
return
|
|
122
|
+
return filesFound;
|
|
123
|
+
};
|
|
124
|
+
const multiJavaFilePathFullySpecified = (filesFound, config) => {
|
|
125
|
+
const filteredFiles = filesFound[0].JAVA.filter(fileTypes => config.fileName.endsWith(fileTypes));
|
|
126
|
+
filesFound[0].JAVA = filteredFiles;
|
|
127
|
+
filesFound[0].filePath = filteredFiles[0];
|
|
128
|
+
if (filteredFiles[0] === 'pom.xml') {
|
|
129
|
+
filesFound[0].packageManager = 'MAVEN';
|
|
130
|
+
}
|
|
131
|
+
else {
|
|
132
|
+
filesFound[0].packageManager = 'GRADLE';
|
|
133
|
+
}
|
|
134
|
+
if (config.debug || config.verbose) {
|
|
135
|
+
console.log('\nAuto detection - detected multiple Java files');
|
|
136
|
+
console.log(`\nAuto detection - using ${filesFound[0].filePath} as based on full file path`);
|
|
137
|
+
}
|
|
138
|
+
return filesFound;
|
|
115
139
|
};
|
|
116
140
|
const errorOnFileDetection = entries => {
|
|
117
141
|
if (entries.length > 1) {
|
|
@@ -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 = '2.0.2-beta.
|
|
15
|
+
const APP_VERSION = '2.0.2-beta.2';
|
|
16
16
|
const TIMEOUT = 120000;
|
|
17
17
|
const HIGH_COLOUR = '#ff9900';
|
|
18
18
|
const CRITICAL_COLOUR = '#e35858';
|
|
@@ -22,6 +22,9 @@ const scaTreeUpload = async (analysis, config, reportSpinner) => {
|
|
|
22
22
|
version: APP_VERSION
|
|
23
23
|
}
|
|
24
24
|
};
|
|
25
|
+
if (config.debug || config.verbose) {
|
|
26
|
+
console.log('requestBody', requestBody);
|
|
27
|
+
}
|
|
25
28
|
if (config.branch) {
|
|
26
29
|
requestBody.branchName = config.branch;
|
|
27
30
|
}
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
const projectConfig = require('../commands/github/projectGroup');
|
|
3
3
|
const repoService = require('../commands/github/repoServices');
|
|
4
4
|
const scaServicesUpload = require('../scaAnalysis/common/scaServicesUpload');
|
|
5
|
+
const { shortenFilePath } = require('../scan/fileUtils');
|
|
5
6
|
const dealWithNoProjectId = async (analysis, config, reportSpinner) => {
|
|
6
7
|
await projectConfig.registerNewProjectGroup(config);
|
|
7
8
|
let projectId = await projectConfig.getProjectIdByOrg(config);
|
|
@@ -18,18 +19,19 @@ const repoProcess = async (analysis, config, reportSpinner) => {
|
|
|
18
19
|
console.log('Failed to retrieve Repository Id');
|
|
19
20
|
process.exit(1);
|
|
20
21
|
}
|
|
22
|
+
let shortenedProjectName = shortenFilePath(config.fileName);
|
|
21
23
|
let repoInfo = await repoService.retrieveProjectInfoViaRepoId(config);
|
|
22
24
|
repoInfo = repoInfo.find(element => config.fileName === element.path &&
|
|
23
|
-
|
|
25
|
+
shortenedProjectName === element.name &&
|
|
24
26
|
config.projectGroupId === element.projectGroupId);
|
|
25
27
|
if (config.projectGroupId &&
|
|
26
28
|
!repoInfo?.projectId &&
|
|
27
29
|
(repoInfo === undefined || repoInfo.length === 0)) {
|
|
28
30
|
console.log('*** has projectGroupId, no projectId and repo has no project found that matches');
|
|
29
|
-
repoInfo = await projectConfig.registerProjectWithGroupProjectId(config);
|
|
31
|
+
repoInfo = await projectConfig.registerProjectWithGroupProjectId(config, shortenedProjectName);
|
|
30
32
|
console.log('new registered group', repoInfo);
|
|
31
33
|
const language = repoInfo.language === 'JAVASCRIPT' ? 'NODE' : repoInfo.language;
|
|
32
|
-
await projectConfig.registerProjectIdOnCliServices(config, repoInfo.projectId);
|
|
34
|
+
await projectConfig.registerProjectIdOnCliServices(config, repoInfo.projectId, shortenedProjectName);
|
|
33
35
|
}
|
|
34
36
|
config.projectId = repoInfo.projectId;
|
|
35
37
|
return await scaServicesUpload.scaTreeUpload(analysis, config, reportSpinner);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
const { supportedLanguages: { JAVA, GO, PYTHON, RUBY, JAVASCRIPT, NODE, PHP, DOTNET } } = require('../constants/constants');
|
|
3
3
|
const { returnOra, startSpinner, succeedSpinner } = require('../utils/oraWrapper');
|
|
4
|
-
const autoDetection = require('../
|
|
4
|
+
const autoDetection = require('../common/autoDetection');
|
|
5
5
|
const rootFile = require('../audit/languageAnalysisEngine/getProjectRootFilenames');
|
|
6
6
|
const path = require('path');
|
|
7
7
|
const i18n = require('i18n');
|
|
@@ -35,7 +35,7 @@ const processSca = async (config) => {
|
|
|
35
35
|
: config.file;
|
|
36
36
|
filesFound = await autoDetection.autoDetectAuditFilesAndLanguages(config.file);
|
|
37
37
|
filesFound = await autoDetection.detectPackageManager(filesFound);
|
|
38
|
-
autoDetection.dealWithMultiJava(filesFound);
|
|
38
|
+
autoDetection.dealWithMultiJava(filesFound, config, pathWithFile);
|
|
39
39
|
if (filesFound.length > 1 && pathWithFile) {
|
|
40
40
|
filesFound = filesFound.filter(i => Object.values(i)[0].includes(path.basename(config.fileName)));
|
|
41
41
|
}
|
package/dist/scan/fileUtils.js
CHANGED
|
@@ -10,19 +10,14 @@ const findFile = async () => {
|
|
|
10
10
|
onlyFiles: true
|
|
11
11
|
});
|
|
12
12
|
};
|
|
13
|
-
const findAllFiles = async (filePath, depth =
|
|
13
|
+
const findAllFiles = async (filePath, depth = 3) => {
|
|
14
14
|
const result = await fg([
|
|
15
15
|
'**/pom.xml',
|
|
16
|
-
'**/build.gradle',
|
|
17
|
-
'**/build.gradle.kts',
|
|
18
16
|
'**/package.json',
|
|
19
17
|
'**/package-lock.json',
|
|
20
|
-
'**/yarn.lock'
|
|
21
|
-
'**/Pipfile',
|
|
22
|
-
'**/*.csproj',
|
|
23
|
-
'**/Gemfile',
|
|
24
|
-
'**/go.mod'
|
|
18
|
+
'**/yarn.lock'
|
|
25
19
|
], {
|
|
20
|
+
ignore: ['**/node_modules/**', '**/target/**', '**/bin/**'],
|
|
26
21
|
dot: false,
|
|
27
22
|
deep: depth,
|
|
28
23
|
onlyFiles: true,
|
|
@@ -162,6 +157,15 @@ const fileIsEmpty = path => {
|
|
|
162
157
|
}
|
|
163
158
|
return false;
|
|
164
159
|
};
|
|
160
|
+
const shortenFilePath = filePath => {
|
|
161
|
+
let splitPath = filePath.split('home/runner/work/');
|
|
162
|
+
if (splitPath.length > 1) {
|
|
163
|
+
let splitPath2 = splitPath[1].split('/');
|
|
164
|
+
splitPath2.shift();
|
|
165
|
+
return splitPath2.join('/').toString();
|
|
166
|
+
}
|
|
167
|
+
return filePath;
|
|
168
|
+
};
|
|
165
169
|
module.exports = {
|
|
166
170
|
findFile,
|
|
167
171
|
fileExists,
|
|
@@ -174,5 +178,6 @@ module.exports = {
|
|
|
174
178
|
findFilesRuby,
|
|
175
179
|
findFilesDotNet,
|
|
176
180
|
fileIsEmpty,
|
|
177
|
-
findAllFiles
|
|
181
|
+
findAllFiles,
|
|
182
|
+
shortenFilePath
|
|
178
183
|
};
|
|
@@ -4,7 +4,7 @@ const { returnOra, startSpinner, succeedSpinner, stopSpinner } = require('../uti
|
|
|
4
4
|
const populateProjectIdAndProjectName = require('./populateProjectIdAndProjectName');
|
|
5
5
|
const scan = require('./scan');
|
|
6
6
|
const scanResults = require('./scanResults');
|
|
7
|
-
const autoDetection = require('
|
|
7
|
+
const autoDetection = require('../common/autoDetection');
|
|
8
8
|
const fileFunctions = require('./fileUtils');
|
|
9
9
|
const { performance } = require('perf_hooks');
|
|
10
10
|
const getTimeout = config => {
|
package/package.json
CHANGED
package/src/cliConstants.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
const fingerprintConfig = require('./fingerprintConfig')
|
|
2
2
|
const repoServices = require('./repoServices')
|
|
3
|
-
const autoDetection = require('../../
|
|
3
|
+
const autoDetection = require('../../common/autoDetection')
|
|
4
4
|
const saveResults = require('../../scan/saveResults')
|
|
5
5
|
const projectConfig = require('./projectGroup')
|
|
6
6
|
const processFingerprint = async (contrastConf, argvMain) => {
|
|
@@ -91,10 +91,10 @@ const createProjectsArray = params => {
|
|
|
91
91
|
return projectsArray
|
|
92
92
|
}
|
|
93
93
|
|
|
94
|
-
const createProject = param => {
|
|
94
|
+
const createProject = (param, shortenedProjectName) => {
|
|
95
95
|
return {
|
|
96
96
|
path: param.fileName,
|
|
97
|
-
name: param.repo ?
|
|
97
|
+
name: param.repo ? shortenedProjectName : getProjectName(param),
|
|
98
98
|
source: 'SCA',
|
|
99
99
|
language: param.language,
|
|
100
100
|
packageManager: param.packageManager,
|
|
@@ -143,13 +143,14 @@ const addAdditionalData = (body, data) => {
|
|
|
143
143
|
const registerProjectIdOnCliServices = async (
|
|
144
144
|
config,
|
|
145
145
|
projectId,
|
|
146
|
+
shortenedProjectName,
|
|
146
147
|
additionalData = undefined
|
|
147
148
|
) => {
|
|
148
149
|
const client = commonApi.getHttpClient(config)
|
|
149
150
|
|
|
150
151
|
let cliServicesBody = {
|
|
151
152
|
projectId: projectId,
|
|
152
|
-
name: config.repo ?
|
|
153
|
+
name: config.repo ? shortenedProjectName : getProjectName(config)
|
|
153
154
|
}
|
|
154
155
|
|
|
155
156
|
if (additionalData) {
|
|
@@ -176,11 +177,14 @@ const registerProjectIdOnCliServices = async (
|
|
|
176
177
|
return result
|
|
177
178
|
}
|
|
178
179
|
|
|
179
|
-
const registerProjectWithGroupProjectId = async
|
|
180
|
+
const registerProjectWithGroupProjectId = async (
|
|
181
|
+
config,
|
|
182
|
+
shortenedProjectName
|
|
183
|
+
) => {
|
|
180
184
|
const client = commonApi.getHttpClient(config)
|
|
181
185
|
config.language = config.language === 'NODE' ? 'JAVASCRIPT' : config.language
|
|
182
186
|
|
|
183
|
-
let body = createProject(config)
|
|
187
|
+
let body = createProject(config, shortenedProjectName)
|
|
184
188
|
let result = await client.registerProject(config, body).then(res => {
|
|
185
189
|
if (config.debug || config.verbose) {
|
|
186
190
|
console.log('\nregister Project With Group ProjectId')
|
|
@@ -75,7 +75,7 @@ const registerNewRepo = async config => {
|
|
|
75
75
|
}
|
|
76
76
|
|
|
77
77
|
const retrieveProjectInfoViaRepoId = async config => {
|
|
78
|
-
const client =
|
|
78
|
+
const client = commonApi.getHttpClient(config)
|
|
79
79
|
|
|
80
80
|
let result = await client
|
|
81
81
|
.retrieveProjectByRepoId(config)
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
const i18n = require('i18n')
|
|
2
|
-
const fileFinder = require('
|
|
2
|
+
const fileFinder = require('../scan/fileUtils')
|
|
3
3
|
const {
|
|
4
|
-
supportedLanguages: { JAVA, GO, PYTHON, RUBY, JAVASCRIPT,
|
|
4
|
+
supportedLanguages: { JAVA, GO, PYTHON, RUBY, JAVASCRIPT, DOTNET }
|
|
5
5
|
} = require('../constants/constants')
|
|
6
|
+
const { shortenFilePath } = require('../scan/fileUtils')
|
|
7
|
+
|
|
6
8
|
const autoDetectFingerprintInfo = async (filePath, depth, config) => {
|
|
7
9
|
let complexObj = await fileFinder.findAllFiles(filePath, depth)
|
|
8
10
|
let result = []
|
|
@@ -11,6 +13,7 @@ const autoDetectFingerprintInfo = async (filePath, depth, config) => {
|
|
|
11
13
|
count++
|
|
12
14
|
if (!i.includes('package.json')) {
|
|
13
15
|
result.push({
|
|
16
|
+
name: shortenFilePath(i),
|
|
14
17
|
filePath: i,
|
|
15
18
|
id: count.toString(),
|
|
16
19
|
repositoryId: config.repositoryId,
|
|
@@ -18,7 +21,6 @@ const autoDetectFingerprintInfo = async (filePath, depth, config) => {
|
|
|
18
21
|
})
|
|
19
22
|
}
|
|
20
23
|
})
|
|
21
|
-
|
|
22
24
|
return result
|
|
23
25
|
}
|
|
24
26
|
|
|
@@ -114,15 +116,23 @@ const hasWhiteSpace = s => {
|
|
|
114
116
|
return filename.indexOf(' ') >= 0
|
|
115
117
|
}
|
|
116
118
|
|
|
117
|
-
const dealWithMultiJava = filesFound => {
|
|
118
|
-
|
|
119
|
-
filesFound
|
|
120
|
-
|
|
119
|
+
const dealWithMultiJava = (filesFound, config, isFile) => {
|
|
120
|
+
if (isFile) {
|
|
121
|
+
return multiJavaFilePathFullySpecified(filesFound, config)
|
|
122
|
+
} else {
|
|
123
|
+
return multiJavaNoFilePathFullySpecified(filesFound)
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
const multiJavaNoFilePathFullySpecified = filesFound => {
|
|
128
|
+
const hasMultiJava =
|
|
129
|
+
filesFound.filter(
|
|
130
|
+
data =>
|
|
121
131
|
Object.keys(data)[0] === JAVA &&
|
|
122
132
|
Object.values(data)[0].includes('build.gradle') &&
|
|
123
133
|
Object.values(data)[0].includes('pom.xml')
|
|
124
|
-
|
|
125
|
-
|
|
134
|
+
).length > 0
|
|
135
|
+
|
|
126
136
|
if (hasMultiJava) {
|
|
127
137
|
console.log('Multiple Java language dependency files detected')
|
|
128
138
|
console.log(
|
|
@@ -130,7 +140,31 @@ const dealWithMultiJava = filesFound => {
|
|
|
130
140
|
)
|
|
131
141
|
process.exit(1)
|
|
132
142
|
}
|
|
133
|
-
|
|
143
|
+
|
|
144
|
+
return filesFound
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
const multiJavaFilePathFullySpecified = (filesFound, config) => {
|
|
148
|
+
const filteredFiles = filesFound[0].JAVA.filter(fileTypes =>
|
|
149
|
+
config.fileName.endsWith(fileTypes)
|
|
150
|
+
)
|
|
151
|
+
filesFound[0].JAVA = filteredFiles
|
|
152
|
+
filesFound[0].filePath = filteredFiles[0]
|
|
153
|
+
|
|
154
|
+
if (filteredFiles[0] === 'pom.xml') {
|
|
155
|
+
filesFound[0].packageManager = 'MAVEN'
|
|
156
|
+
} else {
|
|
157
|
+
filesFound[0].packageManager = 'GRADLE'
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
if (config.debug || config.verbose) {
|
|
161
|
+
console.log('\nAuto detection - detected multiple Java files')
|
|
162
|
+
console.log(
|
|
163
|
+
`\nAuto detection - using ${filesFound[0].filePath} as based on full file path`
|
|
164
|
+
)
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
return filesFound
|
|
134
168
|
}
|
|
135
169
|
|
|
136
170
|
const errorOnFileDetection = entries => {
|
|
@@ -14,7 +14,7 @@ const HIGH = 'HIGH'
|
|
|
14
14
|
const CRITICAL = 'CRITICAL'
|
|
15
15
|
// App
|
|
16
16
|
const APP_NAME = 'contrast'
|
|
17
|
-
const APP_VERSION = '2.0.2-beta.
|
|
17
|
+
const APP_VERSION = '2.0.2-beta.2'
|
|
18
18
|
const TIMEOUT = 120000
|
|
19
19
|
const HIGH_COLOUR = '#ff9900'
|
|
20
20
|
const CRITICAL_COLOUR = '#e35858'
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
const projectConfig = require('../commands/github/projectGroup')
|
|
2
2
|
const repoService = require('../commands/github/repoServices')
|
|
3
3
|
const scaServicesUpload = require('../scaAnalysis/common/scaServicesUpload')
|
|
4
|
+
const { shortenFilePath } = require('../scan/fileUtils')
|
|
4
5
|
|
|
5
6
|
const dealWithNoProjectId = async (analysis, config, reportSpinner) => {
|
|
6
7
|
await projectConfig.registerNewProjectGroup(config)
|
|
@@ -20,12 +21,14 @@ const repoProcess = async (analysis, config, reportSpinner) => {
|
|
|
20
21
|
process.exit(1)
|
|
21
22
|
}
|
|
22
23
|
|
|
24
|
+
let shortenedProjectName = shortenFilePath(config.fileName)
|
|
25
|
+
|
|
23
26
|
let repoInfo = await repoService.retrieveProjectInfoViaRepoId(config)
|
|
24
27
|
|
|
25
28
|
repoInfo = repoInfo.find(
|
|
26
29
|
element =>
|
|
27
30
|
config.fileName === element.path &&
|
|
28
|
-
|
|
31
|
+
shortenedProjectName === element.name &&
|
|
29
32
|
config.projectGroupId === element.projectGroupId
|
|
30
33
|
)
|
|
31
34
|
|
|
@@ -57,7 +60,10 @@ const repoProcess = async (analysis, config, reportSpinner) => {
|
|
|
57
60
|
console.log(
|
|
58
61
|
'*** has projectGroupId, no projectId and repo has no project found that matches'
|
|
59
62
|
)
|
|
60
|
-
repoInfo = await projectConfig.registerProjectWithGroupProjectId(
|
|
63
|
+
repoInfo = await projectConfig.registerProjectWithGroupProjectId(
|
|
64
|
+
config,
|
|
65
|
+
shortenedProjectName
|
|
66
|
+
)
|
|
61
67
|
console.log('new registered group', repoInfo)
|
|
62
68
|
const language =
|
|
63
69
|
repoInfo.language === 'JAVASCRIPT' ? 'NODE' : repoInfo.language
|
|
@@ -71,7 +77,8 @@ const repoProcess = async (analysis, config, reportSpinner) => {
|
|
|
71
77
|
|
|
72
78
|
await projectConfig.registerProjectIdOnCliServices(
|
|
73
79
|
config,
|
|
74
|
-
repoInfo.projectId
|
|
80
|
+
repoInfo.projectId,
|
|
81
|
+
shortenedProjectName
|
|
75
82
|
)
|
|
76
83
|
}
|
|
77
84
|
config.projectId = repoInfo.projectId
|
|
@@ -6,7 +6,7 @@ const {
|
|
|
6
6
|
startSpinner,
|
|
7
7
|
succeedSpinner
|
|
8
8
|
} = require('../utils/oraWrapper')
|
|
9
|
-
const autoDetection = require('../
|
|
9
|
+
const autoDetection = require('../common/autoDetection')
|
|
10
10
|
const rootFile = require('../audit/languageAnalysisEngine/getProjectRootFilenames')
|
|
11
11
|
const path = require('path')
|
|
12
12
|
const i18n = require('i18n')
|
|
@@ -48,7 +48,8 @@ const processSca = async config => {
|
|
|
48
48
|
|
|
49
49
|
filesFound = await autoDetection.autoDetectAuditFilesAndLanguages(config.file)
|
|
50
50
|
filesFound = await autoDetection.detectPackageManager(filesFound)
|
|
51
|
-
|
|
51
|
+
|
|
52
|
+
autoDetection.dealWithMultiJava(filesFound, config, pathWithFile)
|
|
52
53
|
|
|
53
54
|
if (filesFound.length > 1 && pathWithFile) {
|
|
54
55
|
filesFound = filesFound.filter(i =>
|
package/src/scan/fileUtils.js
CHANGED
|
@@ -11,21 +11,22 @@ const findFile = async () => {
|
|
|
11
11
|
})
|
|
12
12
|
}
|
|
13
13
|
|
|
14
|
-
const findAllFiles = async (filePath, depth =
|
|
14
|
+
const findAllFiles = async (filePath, depth = 3) => {
|
|
15
15
|
const result = await fg(
|
|
16
16
|
[
|
|
17
17
|
'**/pom.xml',
|
|
18
|
-
'**/build.gradle',
|
|
19
|
-
'**/build.gradle.kts',
|
|
18
|
+
// '**/build.gradle',
|
|
19
|
+
// '**/build.gradle.kts',
|
|
20
20
|
'**/package.json',
|
|
21
21
|
'**/package-lock.json',
|
|
22
|
-
'**/yarn.lock'
|
|
23
|
-
'**/Pipfile',
|
|
24
|
-
'**/*.csproj',
|
|
25
|
-
'**/Gemfile',
|
|
26
|
-
'**/go.mod'
|
|
22
|
+
'**/yarn.lock'
|
|
23
|
+
// '**/Pipfile',
|
|
24
|
+
// '**/*.csproj',
|
|
25
|
+
// '**/Gemfile',
|
|
26
|
+
// '**/go.mod'
|
|
27
27
|
],
|
|
28
28
|
{
|
|
29
|
+
ignore: ['**/node_modules/**', '**/target/**', '**/bin/**'],
|
|
29
30
|
dot: false,
|
|
30
31
|
deep: depth,
|
|
31
32
|
onlyFiles: true,
|
|
@@ -190,6 +191,16 @@ const fileIsEmpty = path => {
|
|
|
190
191
|
return false
|
|
191
192
|
}
|
|
192
193
|
|
|
194
|
+
const shortenFilePath = filePath => {
|
|
195
|
+
let splitPath = filePath.split('home/runner/work/')
|
|
196
|
+
if (splitPath.length > 1) {
|
|
197
|
+
let splitPath2 = splitPath[1].split('/')
|
|
198
|
+
splitPath2.shift()
|
|
199
|
+
return splitPath2.join('/').toString()
|
|
200
|
+
}
|
|
201
|
+
return filePath
|
|
202
|
+
}
|
|
203
|
+
|
|
193
204
|
module.exports = {
|
|
194
205
|
findFile,
|
|
195
206
|
fileExists,
|
|
@@ -202,5 +213,6 @@ module.exports = {
|
|
|
202
213
|
findFilesRuby,
|
|
203
214
|
findFilesDotNet,
|
|
204
215
|
fileIsEmpty,
|
|
205
|
-
findAllFiles
|
|
216
|
+
findAllFiles,
|
|
217
|
+
shortenFilePath
|
|
206
218
|
}
|
|
@@ -8,7 +8,7 @@ const {
|
|
|
8
8
|
const populateProjectIdAndProjectName = require('./populateProjectIdAndProjectName')
|
|
9
9
|
const scan = require('./scan')
|
|
10
10
|
const scanResults = require('./scanResults')
|
|
11
|
-
const autoDetection = require('
|
|
11
|
+
const autoDetection = require('../common/autoDetection')
|
|
12
12
|
const fileFunctions = require('./fileUtils')
|
|
13
13
|
const { performance } = require('perf_hooks')
|
|
14
14
|
|