@contrast/contrast 2.0.0 → 2.0.2-beta.0
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/report/reportingFeature.js +7 -0
- package/dist/cliConstants.js +22 -1
- package/dist/commands/audit/help.js +1 -3
- package/dist/commands/audit/processAudit.js +0 -2
- package/dist/commands/github/fingerprintConfig.js +2 -1
- package/dist/commands/github/processFingerprint.js +28 -0
- package/dist/commands/github/projectGroup.js +124 -34
- package/dist/commands/github/repoServices.js +108 -0
- package/dist/common/HTTPClient.js +38 -17
- package/dist/common/baseRequest.js +74 -0
- package/dist/common/errorHandling.js +1 -1
- package/dist/constants/constants.js +1 -1
- package/dist/index.js +4 -0
- package/dist/scaAnalysis/common/auditReport.js +8 -1
- package/dist/scaAnalysis/common/scaServicesUpload.js +3 -1
- package/dist/scaAnalysis/go/goReadDepFile.js +5 -1
- package/dist/scaAnalysis/java/analysis.js +1 -1
- package/dist/scaAnalysis/java/javaBuildDepsParser.js +11 -1
- package/dist/scaAnalysis/legacy/legacyFlow.js +0 -6
- package/dist/scaAnalysis/processServicesFlow.js +49 -10
- package/dist/scaAnalysis/repoMode/mavenParser.js +19 -1
- package/dist/scaAnalysis/scaAnalysis.js +4 -8
- package/dist/scan/autoDetection.js +14 -3
- package/dist/scan/fileUtils.js +33 -19
- package/dist/utils/paramsUtil/paramHandler.js +11 -2
- package/dist/utils/validationCheck.js +5 -1
- package/package.json +6 -3
- package/src/audit/report/reportingFeature.ts +7 -0
- package/src/cliConstants.js +22 -1
- package/src/commands/audit/help.js +1 -3
- package/src/commands/audit/processAudit.js +0 -2
- package/src/commands/github/fingerprintConfig.js +2 -2
- package/src/commands/github/processFingerprint.js +37 -0
- package/src/commands/github/projectGroup.js +146 -39
- package/src/commands/github/repoServices.js +122 -0
- package/src/common/HTTPClient.js +47 -18
- package/src/common/baseRequest.ts +83 -0
- package/src/common/errorHandling.js +2 -2
- package/src/constants/constants.js +1 -1
- package/src/index.ts +5 -0
- package/src/scaAnalysis/common/auditReport.js +8 -1
- package/src/scaAnalysis/common/scaServicesUpload.js +5 -1
- package/src/scaAnalysis/go/goReadDepFile.js +5 -1
- package/src/scaAnalysis/java/analysis.js +1 -1
- package/src/scaAnalysis/java/javaBuildDepsParser.js +17 -1
- package/src/scaAnalysis/legacy/legacyFlow.js +0 -5
- package/src/scaAnalysis/processServicesFlow.js +107 -17
- package/src/scaAnalysis/repoMode/mavenParser.js +24 -1
- package/src/scaAnalysis/scaAnalysis.js +9 -8
- package/src/scan/autoDetection.js +14 -3
- package/src/scan/fileUtils.js +33 -19
- package/src/utils/paramsUtil/paramHandler.js +16 -2
- package/src/utils/validationCheck.js +6 -1
- package/dist/utils/settingsHelper.js +0 -14
- package/src/utils/settingsHelper.js +0 -16
|
@@ -29,6 +29,7 @@ const reportUtils_1 = require("./utils/reportUtils");
|
|
|
29
29
|
const constants = __importStar(require("../../constants/constants"));
|
|
30
30
|
const severityCountModel_1 = require("./models/severityCountModel");
|
|
31
31
|
const common = __importStar(require("../../common/fail"));
|
|
32
|
+
const save_1 = require("../save");
|
|
32
33
|
function convertKeysToStandardFormat(config, guidance) {
|
|
33
34
|
let convertedGuidance = guidance;
|
|
34
35
|
switch (config.language) {
|
|
@@ -83,6 +84,12 @@ async function vulnerabilityReportV2(config, reportId) {
|
|
|
83
84
|
const output = formatVulnerabilityOutput(reportResponse.vulnerabilities, config.applicationId, config, reportResponse.remediationGuidance
|
|
84
85
|
? reportResponse.remediationGuidance
|
|
85
86
|
: {});
|
|
87
|
+
if (config.save !== undefined) {
|
|
88
|
+
await (0, save_1.auditSave)(config);
|
|
89
|
+
}
|
|
90
|
+
else {
|
|
91
|
+
console.log('\nUse contrast audit --save to generate an SBOM');
|
|
92
|
+
}
|
|
86
93
|
if (config.fail) {
|
|
87
94
|
common.processFail(config, output[2]);
|
|
88
95
|
}
|
package/dist/cliConstants.js
CHANGED
|
@@ -365,6 +365,7 @@ const auditOptionDefinitions = [
|
|
|
365
365
|
name: 'legacy',
|
|
366
366
|
alias: 'l',
|
|
367
367
|
type: Boolean,
|
|
368
|
+
defaultValue: false,
|
|
368
369
|
description: '{bold ' +
|
|
369
370
|
i18n.__('constantsOptional') +
|
|
370
371
|
'}:' +
|
|
@@ -377,6 +378,16 @@ const auditOptionDefinitions = [
|
|
|
377
378
|
i18n.__('constantsOptional') +
|
|
378
379
|
'}:' +
|
|
379
380
|
i18n.__('auditOptionsRepoSummary')
|
|
381
|
+
},
|
|
382
|
+
{
|
|
383
|
+
name: 'repository-id',
|
|
384
|
+
type: String,
|
|
385
|
+
description: ''
|
|
386
|
+
},
|
|
387
|
+
{
|
|
388
|
+
name: 'project-group-id',
|
|
389
|
+
type: String,
|
|
390
|
+
description: ''
|
|
380
391
|
}
|
|
381
392
|
];
|
|
382
393
|
const fingerprintOptionDefinitions = [
|
|
@@ -387,7 +398,17 @@ const fingerprintOptionDefinitions = [
|
|
|
387
398
|
description: '{bold ' + i18n.__('constantsOptional') + '}: ' + i18n.__('depthOption')
|
|
388
399
|
},
|
|
389
400
|
{
|
|
390
|
-
name: '
|
|
401
|
+
name: 'repository-url',
|
|
402
|
+
type: String,
|
|
403
|
+
description: ''
|
|
404
|
+
},
|
|
405
|
+
{
|
|
406
|
+
name: 'external-id',
|
|
407
|
+
type: String,
|
|
408
|
+
description: ''
|
|
409
|
+
},
|
|
410
|
+
{
|
|
411
|
+
name: 'repository-name',
|
|
391
412
|
type: String,
|
|
392
413
|
description: ''
|
|
393
414
|
}
|
|
@@ -4,14 +4,12 @@ const { auditUsageGuide } = require('./help');
|
|
|
4
4
|
const scaController = require('../../scaAnalysis/scaAnalysis');
|
|
5
5
|
const { sendTelemetryConfigAsObject } = require('../../telemetry/telemetry');
|
|
6
6
|
const { postRunMessage } = require('../../common/commonHelp');
|
|
7
|
-
const settingsHelper = require('../../utils/settingsHelper');
|
|
8
7
|
const processAudit = async (contrastConf, argvMain) => {
|
|
9
8
|
if (argvMain.indexOf('--help') !== -1) {
|
|
10
9
|
printHelpMessage();
|
|
11
10
|
process.exit(0);
|
|
12
11
|
}
|
|
13
12
|
let config = await auditConfig.getAuditConfig(contrastConf, 'audit', argvMain);
|
|
14
|
-
config = await settingsHelper.getSettings(config);
|
|
15
13
|
await scaController.processSca(config);
|
|
16
14
|
if (!config.fingerprint) {
|
|
17
15
|
postRunMessage('audit');
|
|
@@ -3,8 +3,9 @@ const parsedCLIOptions = require('../../utils/parsedCLIOptions');
|
|
|
3
3
|
const constants = require('../../cliConstants');
|
|
4
4
|
const paramHandler = require('../../utils/paramsUtil/paramHandler');
|
|
5
5
|
const getFingerprintConfig = async (contrastConf, command, argv) => {
|
|
6
|
-
|
|
6
|
+
let fingerprintParameters = await parsedCLIOptions.getCommandLineArgsCustom(contrastConf, command, argv, constants.commandLineDefinitions.fingerprintOptionDefinitions);
|
|
7
7
|
const paramsAuth = paramHandler.getAuth(fingerprintParameters);
|
|
8
|
+
fingerprintParameters = paramHandler.getFingerprint(fingerprintParameters);
|
|
8
9
|
return { ...paramsAuth, ...fingerprintParameters };
|
|
9
10
|
};
|
|
10
11
|
module.exports = {
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
const fingerprintConfig = require('./fingerprintConfig');
|
|
3
|
+
const repoServices = require('./repoServices');
|
|
4
|
+
const autoDetection = require('../../scan/autoDetection');
|
|
5
|
+
const saveResults = require('../../scan/saveResults');
|
|
6
|
+
const projectConfig = require('./projectGroup');
|
|
7
|
+
const processFingerprint = async (contrastConf, argvMain) => {
|
|
8
|
+
let config = await fingerprintConfig.getFingerprintConfig(contrastConf, 'fingerprint', argvMain);
|
|
9
|
+
config.repositoryId = await repoServices.getRepoId(config);
|
|
10
|
+
if (config.repositoryId !== '') {
|
|
11
|
+
config.projectGroupId = await projectConfig.getProjectGroupId(config);
|
|
12
|
+
let fingerprint = await autoDetection.autoDetectFingerprintInfo(config.file, config.depth, config);
|
|
13
|
+
if (fingerprint.length === 0) {
|
|
14
|
+
console.log('No supported manifests found');
|
|
15
|
+
process.exit(0);
|
|
16
|
+
}
|
|
17
|
+
let idArray = fingerprint.map(x => x.id);
|
|
18
|
+
await saveResults.writeResultsToFile(fingerprint, 'fingerPrintInfo.json');
|
|
19
|
+
return console.log(idArray);
|
|
20
|
+
}
|
|
21
|
+
else {
|
|
22
|
+
console.log('No repository Id found');
|
|
23
|
+
process.exit(1);
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
module.exports = {
|
|
27
|
+
processFingerprint: processFingerprint
|
|
28
|
+
};
|
|
@@ -11,16 +11,40 @@ const getProjectIdByOrg = async (config) => {
|
|
|
11
11
|
}
|
|
12
12
|
return projectId;
|
|
13
13
|
};
|
|
14
|
-
const
|
|
15
|
-
let projectId = '';
|
|
14
|
+
const createNewProjectGroupBody = async (config) => {
|
|
16
15
|
let body = {
|
|
17
|
-
organizationId: config.organizationId
|
|
18
|
-
name: config.name ? config.name : config.file,
|
|
19
|
-
repositoryId: null,
|
|
20
|
-
type: 'CLI'
|
|
16
|
+
organizationId: config.organizationId
|
|
21
17
|
};
|
|
18
|
+
if (config.repo || config?.repositoryId) {
|
|
19
|
+
body.repositoryId = config.repositoryId;
|
|
20
|
+
body.type = 'REPOSITORY';
|
|
21
|
+
body.name = getProjectGroupNameRepo(config);
|
|
22
|
+
}
|
|
23
|
+
else {
|
|
24
|
+
body.repositoryId = null;
|
|
25
|
+
body.type = 'CLI';
|
|
26
|
+
body.name = getProjectGroupNameCLI(config);
|
|
27
|
+
}
|
|
28
|
+
return body;
|
|
29
|
+
};
|
|
30
|
+
const getProjectGroupNameRepo = config => {
|
|
31
|
+
return config.repositoryName;
|
|
32
|
+
};
|
|
33
|
+
const getProjectGroupNameCLI = config => {
|
|
34
|
+
return config.name ? config.name : config.file;
|
|
35
|
+
};
|
|
36
|
+
const getProjectName = config => {
|
|
37
|
+
return config.name ? config.name : config.fileName;
|
|
38
|
+
};
|
|
39
|
+
const registerNewProjectGroup = async (config) => {
|
|
40
|
+
let body = await createNewProjectGroupBody(config);
|
|
22
41
|
const client = await commonApi.getHttpClient(config);
|
|
23
|
-
|
|
42
|
+
if (config.repositoryId) {
|
|
43
|
+
body.projects = [];
|
|
44
|
+
}
|
|
45
|
+
else {
|
|
46
|
+
body.projects = createProjectsArray([config]);
|
|
47
|
+
}
|
|
24
48
|
let projectGroupInfo = await client
|
|
25
49
|
.registerProjectGroup(config, body)
|
|
26
50
|
.then(res => {
|
|
@@ -37,7 +61,7 @@ const registerNewProjectGroup = async (config) => {
|
|
|
37
61
|
return res?.body?.projectGroupId;
|
|
38
62
|
}
|
|
39
63
|
if (res.statusCode === 409) {
|
|
40
|
-
return
|
|
64
|
+
return '';
|
|
41
65
|
}
|
|
42
66
|
})
|
|
43
67
|
.catch(err => {
|
|
@@ -46,53 +70,94 @@ const registerNewProjectGroup = async (config) => {
|
|
|
46
70
|
});
|
|
47
71
|
return projectGroupInfo;
|
|
48
72
|
};
|
|
49
|
-
const
|
|
73
|
+
const createProjectsArray = params => {
|
|
50
74
|
let projectsArray = [];
|
|
51
75
|
let projects = {};
|
|
52
76
|
params.forEach(param => {
|
|
53
|
-
projects =
|
|
54
|
-
path: param.file,
|
|
55
|
-
name: param.name ? param.name : param.file,
|
|
56
|
-
source: 'SCA',
|
|
57
|
-
language: param.language,
|
|
58
|
-
packageManager: 'MAVEN',
|
|
59
|
-
target: 'SCA',
|
|
60
|
-
sourceId: ''
|
|
61
|
-
};
|
|
77
|
+
projects = createProject(param);
|
|
62
78
|
projectsArray.push(projects);
|
|
63
79
|
});
|
|
64
80
|
return projectsArray;
|
|
65
81
|
};
|
|
82
|
+
const createProject = param => {
|
|
83
|
+
return {
|
|
84
|
+
path: param.fileName,
|
|
85
|
+
name: param.repo ? param.fileName : getProjectName(param),
|
|
86
|
+
source: 'SCA',
|
|
87
|
+
language: param.language,
|
|
88
|
+
packageManager: param.packageManager,
|
|
89
|
+
target: 'SCA',
|
|
90
|
+
sourceId: ''
|
|
91
|
+
};
|
|
92
|
+
};
|
|
66
93
|
const getExistingGroupProjectId = (config, projectGroupsInfoEx) => {
|
|
67
94
|
let existingGroupProjectId = '';
|
|
68
95
|
projectGroupsInfoEx.forEach(i => {
|
|
69
|
-
if (i.
|
|
96
|
+
if (i.repositoryId === config.repositoryId) {
|
|
70
97
|
existingGroupProjectId = i.projectGroupId;
|
|
71
98
|
}
|
|
72
99
|
});
|
|
73
100
|
return existingGroupProjectId;
|
|
74
101
|
};
|
|
75
102
|
const getProjectIdFromArray = (config, array) => {
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
103
|
+
if (array.length === 1) {
|
|
104
|
+
return array[0].projectId;
|
|
105
|
+
}
|
|
106
|
+
if (config.name) {
|
|
107
|
+
for (const i of array) {
|
|
108
|
+
if (i.name === config.name)
|
|
109
|
+
return i.projectId;
|
|
80
110
|
}
|
|
81
|
-
}
|
|
82
|
-
|
|
111
|
+
}
|
|
112
|
+
for (const i of array) {
|
|
113
|
+
if (i.name === config.fileName)
|
|
114
|
+
return i.projectId;
|
|
115
|
+
}
|
|
116
|
+
return '';
|
|
117
|
+
};
|
|
118
|
+
const addAdditionalData = (body, data) => {
|
|
119
|
+
body.projectGroupId = data.projectGroupId ? data.projectGroupId : null;
|
|
120
|
+
body.projectGroupName = data.projectGroupName ? data.projectGroupName : null;
|
|
121
|
+
body.projectLanguage = data.projectLanguage ? data.projectLanguage : null;
|
|
122
|
+
body.projectType = data.projectType ? data.projectType : null;
|
|
83
123
|
};
|
|
84
|
-
const registerProjectIdOnCliServices = async (config, projectId) => {
|
|
124
|
+
const registerProjectIdOnCliServices = async (config, projectId, additionalData = undefined) => {
|
|
85
125
|
const client = commonApi.getHttpClient(config);
|
|
86
126
|
let cliServicesBody = {
|
|
87
127
|
projectId: projectId,
|
|
88
|
-
name: config.
|
|
128
|
+
name: config.repo ? config.fileName : getProjectName(config)
|
|
89
129
|
};
|
|
130
|
+
if (additionalData) {
|
|
131
|
+
addAdditionalData(cliServicesBody, additionalData);
|
|
132
|
+
}
|
|
90
133
|
let result = await client
|
|
91
134
|
.registerOnCliServices(config, cliServicesBody)
|
|
92
135
|
.then(res => {
|
|
93
136
|
if (config.debug || config.verbose) {
|
|
94
137
|
console.log('\nregistration on cli services');
|
|
138
|
+
console.log('request body', cliServicesBody);
|
|
139
|
+
console.log('response code', res.statusCode);
|
|
140
|
+
}
|
|
141
|
+
if (res.statusCode === 201 || res.statusCode === 200) {
|
|
142
|
+
return res.body;
|
|
143
|
+
}
|
|
144
|
+
else {
|
|
145
|
+
console.log('Failed to Register On Cli Services');
|
|
146
|
+
console.log(res.statusCode);
|
|
147
|
+
process.exit(1);
|
|
148
|
+
}
|
|
149
|
+
});
|
|
150
|
+
return result;
|
|
151
|
+
};
|
|
152
|
+
const registerProjectWithGroupProjectId = async (config) => {
|
|
153
|
+
const client = commonApi.getHttpClient(config);
|
|
154
|
+
config.language = config.language === 'NODE' ? 'JAVASCRIPT' : config.language;
|
|
155
|
+
let body = createProject(config);
|
|
156
|
+
let result = await client.registerProject(config, body).then(res => {
|
|
157
|
+
if (config.debug || config.verbose) {
|
|
158
|
+
console.log('\nregister Project With Group ProjectId');
|
|
95
159
|
console.log(res.statusCode);
|
|
160
|
+
console.log(res.body);
|
|
96
161
|
}
|
|
97
162
|
if (res.statusCode === 201 || res.statusCode === 200) {
|
|
98
163
|
return res.body;
|
|
@@ -104,7 +169,7 @@ const registerProjectIdOnCliServices = async (config, projectId) => {
|
|
|
104
169
|
return result;
|
|
105
170
|
};
|
|
106
171
|
const retrieveExistingProjectIdWithProjectGroupId = async (config, client, projectGroupId) => {
|
|
107
|
-
|
|
172
|
+
return await client
|
|
108
173
|
.retrieveExistingProjectIdByProjectGroupId(config, projectGroupId)
|
|
109
174
|
.then(res => {
|
|
110
175
|
if (config.debug || config.verbose) {
|
|
@@ -116,10 +181,9 @@ const retrieveExistingProjectIdWithProjectGroupId = async (config, client, proje
|
|
|
116
181
|
return res.body;
|
|
117
182
|
}
|
|
118
183
|
else {
|
|
119
|
-
return
|
|
184
|
+
return '';
|
|
120
185
|
}
|
|
121
186
|
});
|
|
122
|
-
return getProjectIdFromArray(config, groups);
|
|
123
187
|
};
|
|
124
188
|
const retrieveProjectByOrganization = async (config, client) => {
|
|
125
189
|
return await client.retrieveProjectByOrganizationId(config).then(res => {
|
|
@@ -136,16 +200,36 @@ const retrieveProjectByOrganization = async (config, client) => {
|
|
|
136
200
|
}
|
|
137
201
|
});
|
|
138
202
|
};
|
|
139
|
-
const retrieveExistingProjectGroups = async (config
|
|
203
|
+
const retrieveExistingProjectGroups = async (config) => {
|
|
204
|
+
const client = commonApi.getHttpClient(config);
|
|
140
205
|
return await client.retrieveExistingProjectGroupsByOrg(config).then(res => {
|
|
206
|
+
if (config.debug || config.verbose) {
|
|
207
|
+
console.log('retrieve Existing ProjectGroups By Org');
|
|
208
|
+
console.log(res.statusCode);
|
|
209
|
+
console.log(res.body);
|
|
210
|
+
}
|
|
141
211
|
if (res.statusCode === 201 || res.statusCode === 200) {
|
|
142
|
-
|
|
212
|
+
let correctGroupID = res?.body?.filter(i => i.repositoryId === config.repositoryId);
|
|
213
|
+
if (correctGroupID.length > 0) {
|
|
214
|
+
return correctGroupID[0].projectGroupId;
|
|
215
|
+
}
|
|
216
|
+
return '';
|
|
143
217
|
}
|
|
144
218
|
else {
|
|
145
|
-
return
|
|
219
|
+
return '';
|
|
146
220
|
}
|
|
147
221
|
});
|
|
148
222
|
};
|
|
223
|
+
const getProjectGroupId = async (config) => {
|
|
224
|
+
let projectGroupId = '';
|
|
225
|
+
if (config.projectGroupId === '' || config.projectGroupId === undefined) {
|
|
226
|
+
projectGroupId = await retrieveExistingProjectGroups(config);
|
|
227
|
+
}
|
|
228
|
+
if (projectGroupId === '') {
|
|
229
|
+
projectGroupId = await registerNewProjectGroup(config);
|
|
230
|
+
}
|
|
231
|
+
return projectGroupId;
|
|
232
|
+
};
|
|
149
233
|
const dealWithNoName = async (config) => {
|
|
150
234
|
try {
|
|
151
235
|
config.name = getAppName(config.file);
|
|
@@ -160,5 +244,11 @@ module.exports = {
|
|
|
160
244
|
getProjectIdByOrg,
|
|
161
245
|
registerProjectIdOnCliServices,
|
|
162
246
|
dealWithNoName,
|
|
163
|
-
registerNewProjectGroup
|
|
247
|
+
registerNewProjectGroup,
|
|
248
|
+
createNewProjectGroupBody,
|
|
249
|
+
registerProjectWithGroupProjectId,
|
|
250
|
+
getExistingGroupProjectId,
|
|
251
|
+
getProjectGroupId,
|
|
252
|
+
retrieveExistingProjectGroups,
|
|
253
|
+
createProject
|
|
164
254
|
};
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
const commonApi = require('../../utils/commonApi');
|
|
3
|
+
const retrieveRepoId = async (config) => {
|
|
4
|
+
const client = await commonApi.getHttpClient(config);
|
|
5
|
+
let repositoryId = await client
|
|
6
|
+
.retrieveRepoByOrgAndGitURL(config)
|
|
7
|
+
.then(res => {
|
|
8
|
+
if (config.debug || config.verbose) {
|
|
9
|
+
console.log('\nRetrieve RepoId By retrieveRepoByOrgAndGitURL');
|
|
10
|
+
console.log(res.statusCode);
|
|
11
|
+
console.log(res.body);
|
|
12
|
+
}
|
|
13
|
+
if (res.statusCode === 201 || res.statusCode === 200) {
|
|
14
|
+
return res.body.repositoryId;
|
|
15
|
+
}
|
|
16
|
+
else {
|
|
17
|
+
return '';
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
return repositoryId;
|
|
21
|
+
};
|
|
22
|
+
const registerNewRepo = async (config) => {
|
|
23
|
+
let body = {
|
|
24
|
+
externalScmUrl: config.repositoryUrl,
|
|
25
|
+
externalScmName: config.repositoryName,
|
|
26
|
+
externalId: config.externalId,
|
|
27
|
+
primaryLanguage: config.language,
|
|
28
|
+
defaultBranch: 'develop'
|
|
29
|
+
};
|
|
30
|
+
if (config.debug || config.verbose) {
|
|
31
|
+
console.log('registerNewRepo');
|
|
32
|
+
console.log(body);
|
|
33
|
+
}
|
|
34
|
+
const client = await commonApi.getHttpClient(config);
|
|
35
|
+
let result = await client
|
|
36
|
+
.registerRepo(config, body)
|
|
37
|
+
.then(res => {
|
|
38
|
+
if (config.debug || config.verbose) {
|
|
39
|
+
console.log('\nRegister Repository');
|
|
40
|
+
console.log(res.statusCode);
|
|
41
|
+
console.log(res.body);
|
|
42
|
+
}
|
|
43
|
+
if (res.statusCode === 201 || res.statusCode === 200) {
|
|
44
|
+
if (config.debug || config.verbose) {
|
|
45
|
+
console.log('registerRepository - response');
|
|
46
|
+
console.log('response', res.body);
|
|
47
|
+
}
|
|
48
|
+
return res?.body?.repositoryId;
|
|
49
|
+
}
|
|
50
|
+
if (res.statusCode === 409) {
|
|
51
|
+
return '';
|
|
52
|
+
}
|
|
53
|
+
if (res.statusCode === 400) {
|
|
54
|
+
if (config.debug || config.verbose) {
|
|
55
|
+
console.log('\nError Registering Repository - Bad request');
|
|
56
|
+
console.log(res.statusCode);
|
|
57
|
+
console.log(res.message);
|
|
58
|
+
}
|
|
59
|
+
process.exit(1);
|
|
60
|
+
}
|
|
61
|
+
})
|
|
62
|
+
.catch(err => {
|
|
63
|
+
console.log('\nError Registering Repository');
|
|
64
|
+
console.log(err.statusCode);
|
|
65
|
+
console.log(err.message);
|
|
66
|
+
process.exit(1);
|
|
67
|
+
});
|
|
68
|
+
return result;
|
|
69
|
+
};
|
|
70
|
+
const retrieveProjectInfoViaRepoId = async (config) => {
|
|
71
|
+
const client = await commonApi.getHttpClient(config);
|
|
72
|
+
let result = await client
|
|
73
|
+
.retrieveProjectByRepoId(config)
|
|
74
|
+
.then(res => {
|
|
75
|
+
if (config.debug || config.verbose) {
|
|
76
|
+
console.log('\nRetrieve Project By RepoId');
|
|
77
|
+
console.log(res.statusCode);
|
|
78
|
+
console.log(res.body);
|
|
79
|
+
}
|
|
80
|
+
if (res.statusCode === 201 || res.statusCode === 200) {
|
|
81
|
+
return res?.body;
|
|
82
|
+
}
|
|
83
|
+
if (res.statusCode === 409) {
|
|
84
|
+
return [];
|
|
85
|
+
}
|
|
86
|
+
})
|
|
87
|
+
.catch(err => {
|
|
88
|
+
console.log('\nError Retrieve Project By RepoId');
|
|
89
|
+
console.log(err.statusCode);
|
|
90
|
+
});
|
|
91
|
+
return result;
|
|
92
|
+
};
|
|
93
|
+
const getRepoId = async (config) => {
|
|
94
|
+
let repoId = '';
|
|
95
|
+
if (config.repositoryId === '' || config.repositoryId === undefined) {
|
|
96
|
+
repoId = await retrieveRepoId(config);
|
|
97
|
+
}
|
|
98
|
+
if (repoId === '') {
|
|
99
|
+
repoId = await registerNewRepo(config);
|
|
100
|
+
}
|
|
101
|
+
return repoId;
|
|
102
|
+
};
|
|
103
|
+
module.exports = {
|
|
104
|
+
retrieveRepoId,
|
|
105
|
+
registerNewRepo,
|
|
106
|
+
getRepoId,
|
|
107
|
+
retrieveProjectInfoViaRepoId
|
|
108
|
+
};
|
|
@@ -171,11 +171,6 @@ HTTPClient.prototype.scaServiceIngest = function scaServiceIngest(requestBody, c
|
|
|
171
171
|
let url = createScaServiceIngestURL(config);
|
|
172
172
|
options.url = url;
|
|
173
173
|
options.body = requestBody;
|
|
174
|
-
if (config.debug || config.verbose) {
|
|
175
|
-
console.log('scaServiceIngest');
|
|
176
|
-
console.log('url', options.url);
|
|
177
|
-
console.log('body', options.body);
|
|
178
|
-
}
|
|
179
174
|
return requestUtils.sendRequest({ method: 'post', options });
|
|
180
175
|
};
|
|
181
176
|
HTTPClient.prototype.noProjectIdUpload = function scaServiceIngest(requestBody, config) {
|
|
@@ -257,6 +252,13 @@ HTTPClient.prototype.registerRepo = function registerRepo(config, requestBody) {
|
|
|
257
252
|
options.body = requestBody;
|
|
258
253
|
return requestUtils.sendRequest({ method: 'post', options });
|
|
259
254
|
};
|
|
255
|
+
HTTPClient.prototype.retrieveProjectByRepoId = function retrieveProjectByRepoId(config, requestBody) {
|
|
256
|
+
const options = _.cloneDeep(this.requestOptions);
|
|
257
|
+
let url = createRepoProjectUrl(config);
|
|
258
|
+
options.url = url;
|
|
259
|
+
options.body = requestBody;
|
|
260
|
+
return requestUtils.sendRequest({ method: 'get', options });
|
|
261
|
+
};
|
|
260
262
|
HTTPClient.prototype.registerProjectGroup = function (config, requestBody) {
|
|
261
263
|
const options = _.cloneDeep(this.requestOptions);
|
|
262
264
|
let url = registerProjectGroupUrl(config);
|
|
@@ -265,15 +267,15 @@ HTTPClient.prototype.registerProjectGroup = function (config, requestBody) {
|
|
|
265
267
|
if (config.debug || config.verbose) {
|
|
266
268
|
console.log('registerProjectGroup');
|
|
267
269
|
console.log('url', options.url);
|
|
268
|
-
console.log('body', options.body);
|
|
269
270
|
}
|
|
270
271
|
return requestUtils.sendRequest({ method: 'post', options });
|
|
271
272
|
};
|
|
272
|
-
HTTPClient.prototype.registerProject = function (config,
|
|
273
|
+
HTTPClient.prototype.registerProject = function (config, body) {
|
|
273
274
|
const options = _.cloneDeep(this.requestOptions);
|
|
274
|
-
let url = registerProjectUrl(config
|
|
275
|
+
let url = registerProjectUrl(config);
|
|
275
276
|
options.url = url;
|
|
276
|
-
|
|
277
|
+
options.body = body;
|
|
278
|
+
return requestUtils.sendRequest({ method: 'post', options });
|
|
277
279
|
};
|
|
278
280
|
HTTPClient.prototype.retrieveSourcesViaRepositoryId = function (config, repositoryId) {
|
|
279
281
|
const options = _.cloneDeep(this.requestOptions);
|
|
@@ -303,12 +305,21 @@ HTTPClient.prototype.retrieveProjectByOrganizationId = function registerRepo(con
|
|
|
303
305
|
const options = _.cloneDeep(this.requestOptions);
|
|
304
306
|
let url = retrieveProjectByOrganizationIdUrl(config);
|
|
305
307
|
options.url = url;
|
|
308
|
+
if (config.debug || config.verbose) {
|
|
309
|
+
console.log(url);
|
|
310
|
+
}
|
|
306
311
|
return requestUtils.sendRequest({ method: 'get', options });
|
|
307
312
|
};
|
|
308
313
|
HTTPClient.prototype.retrieveExistingProjectGroupsByOrg = function registerRepo(config) {
|
|
309
314
|
const options = _.cloneDeep(this.requestOptions);
|
|
310
|
-
let url = retrieveExistingGroupProjectsByOrgUrl(config)
|
|
315
|
+
let url = retrieveExistingGroupProjectsByOrgUrl(config) +
|
|
316
|
+
'?name=' +
|
|
317
|
+
config.repositoryName +
|
|
318
|
+
'&type=REPOSITORY';
|
|
311
319
|
options.url = url;
|
|
320
|
+
if (config.debug || config.verbose) {
|
|
321
|
+
console.log(options.url);
|
|
322
|
+
}
|
|
312
323
|
return requestUtils.sendRequest({ method: 'get', options });
|
|
313
324
|
};
|
|
314
325
|
HTTPClient.prototype.retrieveExistingProjectIdByProjectGroupId =
|
|
@@ -450,14 +461,16 @@ function createScaServiceReportStatusURL(config, reportId) {
|
|
|
450
461
|
return `${config.host}/Contrast/api/sca/organizations/${config.organizationId}/libraries/ingests/${reportId}/status`;
|
|
451
462
|
}
|
|
452
463
|
function createScaServiceNoProjectIdURL(config) {
|
|
453
|
-
return `${config.host}/Contrast/api/sca/organizations/${config.organizationId}/libraries/ingests/tree${config.repo ? '
|
|
464
|
+
return `${config.host}/Contrast/api/sca/organizations/${config.organizationId}/libraries/ingests/tree${config.repo && config.language === 'JAVA?' ? 'incomplete=true' : ''}`;
|
|
454
465
|
}
|
|
455
466
|
function createScaServiceHealthURL(config) {
|
|
456
467
|
return `${config.host}/Contrast/api/sca/organizations/${config.organizationId}/health`;
|
|
457
468
|
}
|
|
458
469
|
function createScaServiceIngestURL(config) {
|
|
459
470
|
let optionalParams = [];
|
|
460
|
-
config.repo
|
|
471
|
+
config.repo && config.language === 'JAVA'
|
|
472
|
+
? optionalParams.push('incomplete=true')
|
|
473
|
+
: null;
|
|
461
474
|
config.track ? optionalParams.push('persist=true') : null;
|
|
462
475
|
let params = '?';
|
|
463
476
|
optionalParams.forEach(param => {
|
|
@@ -479,8 +492,8 @@ const createAppNameUrl = config => {
|
|
|
479
492
|
const registerProjectGroupUrl = config => {
|
|
480
493
|
return `${config.host}/api/v4/organizations/${config.organizationId}/project-groups`;
|
|
481
494
|
};
|
|
482
|
-
const registerProjectUrl =
|
|
483
|
-
return `${config.host}/api/v4/organizations/${config.organizationId}/project-groups/${projectGroupId}/projects`;
|
|
495
|
+
const registerProjectUrl = config => {
|
|
496
|
+
return `${config.host}/api/v4/organizations/${config.organizationId}/project-groups/${config.projectGroupId}/projects`;
|
|
484
497
|
};
|
|
485
498
|
const retrieveRegisterOnCliServicesUrl = config => {
|
|
486
499
|
return `${config.host}/Contrast/api/sca/organizations/${config.organizationId}/projects`;
|
|
@@ -489,15 +502,20 @@ const retrieveSourcesUrl = (config, repositoryId) => {
|
|
|
489
502
|
return `${config.host}/projects/v1/repositories/${repositoryId}/sources`;
|
|
490
503
|
};
|
|
491
504
|
const retrieveRepoByOrgAndGitURL = config => {
|
|
492
|
-
return `${config.host}/api/v4/organizations/${config.organizationId}/
|
|
505
|
+
return `${config.host}/api/v4/organizations/${config.organizationId}/repositories/external-url?externalRepoUrl=${config.repositoryUrl}`;
|
|
493
506
|
};
|
|
494
507
|
const retrieveProjectByOrganizationIdUrl = config => {
|
|
495
508
|
let baseUrl = `${config.host}/api/v4/organizations/${config.organizationId}/projects`;
|
|
496
|
-
baseUrl = config.name
|
|
509
|
+
baseUrl = config.name
|
|
510
|
+
? baseUrl.concat(`?name=${config.name}`)
|
|
511
|
+
: baseUrl.concat(`?name=${config.fileName}`);
|
|
497
512
|
baseUrl = config.language
|
|
498
513
|
? baseUrl.concat(`&language=${config.language}`)
|
|
499
514
|
: baseUrl;
|
|
500
515
|
baseUrl = config.language ? baseUrl.concat(`&source=SCA`) : baseUrl;
|
|
516
|
+
baseUrl = config.repo
|
|
517
|
+
? baseUrl.concat(`&type=REPOSITORY`)
|
|
518
|
+
: baseUrl.concat(`&type=CLI`);
|
|
501
519
|
return baseUrl;
|
|
502
520
|
};
|
|
503
521
|
const retrieveExistingGroupProjectsByOrgUrl = config => {
|
|
@@ -510,7 +528,10 @@ const retrieveExistingRepoUrl = config => {
|
|
|
510
528
|
return `${config.host}/projects/v4/organizations/${config.organizationId}/repositories`;
|
|
511
529
|
};
|
|
512
530
|
function createRepositoryUrl(config) {
|
|
513
|
-
return `${config.host}/
|
|
531
|
+
return `${config.host}/api/v4/organizations/${config.organizationId}/repositories`;
|
|
532
|
+
}
|
|
533
|
+
function createRepoProjectUrl(config) {
|
|
534
|
+
return `${config.host}/api/v4/organizations/${config.organizationId}/repositories/${config.repositoryId}/projects`;
|
|
514
535
|
}
|
|
515
536
|
function createLibraryVulnerabilitiesUrl(config) {
|
|
516
537
|
return `${config.host}/Contrast/api/ng/${config.organizationId}/libraries/artifactsByGroupNameVersion`;
|