@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
package/src/cliConstants.js
CHANGED
|
@@ -412,6 +412,7 @@ const auditOptionDefinitions = [
|
|
|
412
412
|
name: 'legacy',
|
|
413
413
|
alias: 'l',
|
|
414
414
|
type: Boolean,
|
|
415
|
+
defaultValue: false,
|
|
415
416
|
description:
|
|
416
417
|
'{bold ' +
|
|
417
418
|
i18n.__('constantsOptional') +
|
|
@@ -426,6 +427,16 @@ const auditOptionDefinitions = [
|
|
|
426
427
|
i18n.__('constantsOptional') +
|
|
427
428
|
'}:' +
|
|
428
429
|
i18n.__('auditOptionsRepoSummary')
|
|
430
|
+
},
|
|
431
|
+
{
|
|
432
|
+
name: 'repository-id',
|
|
433
|
+
type: String,
|
|
434
|
+
description: ''
|
|
435
|
+
},
|
|
436
|
+
{
|
|
437
|
+
name: 'project-group-id',
|
|
438
|
+
type: String,
|
|
439
|
+
description: ''
|
|
429
440
|
}
|
|
430
441
|
]
|
|
431
442
|
|
|
@@ -438,7 +449,17 @@ const fingerprintOptionDefinitions = [
|
|
|
438
449
|
'{bold ' + i18n.__('constantsOptional') + '}: ' + i18n.__('depthOption')
|
|
439
450
|
},
|
|
440
451
|
{
|
|
441
|
-
name: '
|
|
452
|
+
name: 'repository-url',
|
|
453
|
+
type: String,
|
|
454
|
+
description: ''
|
|
455
|
+
},
|
|
456
|
+
{
|
|
457
|
+
name: 'external-id',
|
|
458
|
+
type: String,
|
|
459
|
+
description: ''
|
|
460
|
+
},
|
|
461
|
+
{
|
|
462
|
+
name: 'repository-name',
|
|
442
463
|
type: String,
|
|
443
464
|
description: ''
|
|
444
465
|
}
|
|
@@ -3,7 +3,6 @@ const { auditUsageGuide } = require('./help')
|
|
|
3
3
|
const scaController = require('../../scaAnalysis/scaAnalysis')
|
|
4
4
|
const { sendTelemetryConfigAsObject } = require('../../telemetry/telemetry')
|
|
5
5
|
const { postRunMessage } = require('../../common/commonHelp')
|
|
6
|
-
const settingsHelper = require('../../utils/settingsHelper')
|
|
7
6
|
|
|
8
7
|
const processAudit = async (contrastConf, argvMain) => {
|
|
9
8
|
if (argvMain.indexOf('--help') !== -1) {
|
|
@@ -12,7 +11,6 @@ const processAudit = async (contrastConf, argvMain) => {
|
|
|
12
11
|
}
|
|
13
12
|
|
|
14
13
|
let config = await auditConfig.getAuditConfig(contrastConf, 'audit', argvMain)
|
|
15
|
-
config = await settingsHelper.getSettings(config)
|
|
16
14
|
|
|
17
15
|
await scaController.processSca(config)
|
|
18
16
|
if (!config.fingerprint) {
|
|
@@ -3,14 +3,14 @@ const constants = require('../../cliConstants')
|
|
|
3
3
|
const paramHandler = require('../../utils/paramsUtil/paramHandler')
|
|
4
4
|
|
|
5
5
|
const getFingerprintConfig = async (contrastConf, command, argv) => {
|
|
6
|
-
|
|
6
|
+
let fingerprintParameters = await parsedCLIOptions.getCommandLineArgsCustom(
|
|
7
7
|
contrastConf,
|
|
8
8
|
command,
|
|
9
9
|
argv,
|
|
10
10
|
constants.commandLineDefinitions.fingerprintOptionDefinitions
|
|
11
11
|
)
|
|
12
12
|
const paramsAuth = paramHandler.getAuth(fingerprintParameters)
|
|
13
|
-
|
|
13
|
+
fingerprintParameters = paramHandler.getFingerprint(fingerprintParameters)
|
|
14
14
|
return { ...paramsAuth, ...fingerprintParameters }
|
|
15
15
|
}
|
|
16
16
|
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
const fingerprintConfig = require('./fingerprintConfig')
|
|
2
|
+
const repoServices = require('./repoServices')
|
|
3
|
+
const autoDetection = require('../../scan/autoDetection')
|
|
4
|
+
const saveResults = require('../../scan/saveResults')
|
|
5
|
+
const projectConfig = require('./projectGroup')
|
|
6
|
+
const processFingerprint = async (contrastConf, argvMain) => {
|
|
7
|
+
let config = await fingerprintConfig.getFingerprintConfig(
|
|
8
|
+
contrastConf,
|
|
9
|
+
'fingerprint',
|
|
10
|
+
argvMain
|
|
11
|
+
)
|
|
12
|
+
config.repositoryId = await repoServices.getRepoId(config)
|
|
13
|
+
if (config.repositoryId !== '') {
|
|
14
|
+
config.projectGroupId = await projectConfig.getProjectGroupId(config)
|
|
15
|
+
let fingerprint = await autoDetection.autoDetectFingerprintInfo(
|
|
16
|
+
config.file,
|
|
17
|
+
config.depth,
|
|
18
|
+
config
|
|
19
|
+
)
|
|
20
|
+
|
|
21
|
+
if (fingerprint.length === 0) {
|
|
22
|
+
console.log('No supported manifests found')
|
|
23
|
+
process.exit(0)
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
let idArray = fingerprint.map(x => x.id)
|
|
27
|
+
await saveResults.writeResultsToFile(fingerprint, 'fingerPrintInfo.json')
|
|
28
|
+
return console.log(idArray)
|
|
29
|
+
} else {
|
|
30
|
+
console.log('No repository Id found')
|
|
31
|
+
process.exit(1)
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
module.exports = {
|
|
36
|
+
processFingerprint: processFingerprint
|
|
37
|
+
}
|
|
@@ -15,17 +15,43 @@ const getProjectIdByOrg = async config => {
|
|
|
15
15
|
return projectId
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
-
const
|
|
19
|
-
let projectId = ''
|
|
18
|
+
const createNewProjectGroupBody = async config => {
|
|
20
19
|
let body = {
|
|
21
|
-
organizationId: config.organizationId
|
|
22
|
-
name: config.name ? config.name : config.file, //has to be unique per project
|
|
23
|
-
repositoryId: null,
|
|
24
|
-
type: 'CLI'
|
|
20
|
+
organizationId: config.organizationId
|
|
25
21
|
}
|
|
26
|
-
|
|
27
|
-
|
|
22
|
+
if (config.repo || config?.repositoryId) {
|
|
23
|
+
body.repositoryId = config.repositoryId
|
|
24
|
+
body.type = 'REPOSITORY'
|
|
25
|
+
body.name = getProjectGroupNameRepo(config)
|
|
26
|
+
} else {
|
|
27
|
+
body.repositoryId = null
|
|
28
|
+
body.type = 'CLI'
|
|
29
|
+
body.name = getProjectGroupNameCLI(config)
|
|
30
|
+
}
|
|
31
|
+
return body
|
|
32
|
+
}
|
|
28
33
|
|
|
34
|
+
const getProjectGroupNameRepo = config => {
|
|
35
|
+
return config.repositoryName
|
|
36
|
+
}
|
|
37
|
+
const getProjectGroupNameCLI = config => {
|
|
38
|
+
// file here is actually folder name
|
|
39
|
+
return config.name ? config.name : config.file
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const getProjectName = config => {
|
|
43
|
+
return config.name ? config.name : config.fileName
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const registerNewProjectGroup = async config => {
|
|
47
|
+
let body = await createNewProjectGroupBody(config)
|
|
48
|
+
|
|
49
|
+
const client = await commonApi.getHttpClient(config)
|
|
50
|
+
if (config.repositoryId) {
|
|
51
|
+
body.projects = []
|
|
52
|
+
} else {
|
|
53
|
+
body.projects = createProjectsArray([config])
|
|
54
|
+
}
|
|
29
55
|
let projectGroupInfo = await client
|
|
30
56
|
.registerProjectGroup(config, body)
|
|
31
57
|
.then(res => {
|
|
@@ -43,7 +69,7 @@ const registerNewProjectGroup = async config => {
|
|
|
43
69
|
}
|
|
44
70
|
|
|
45
71
|
if (res.statusCode === 409) {
|
|
46
|
-
return
|
|
72
|
+
return ''
|
|
47
73
|
}
|
|
48
74
|
})
|
|
49
75
|
.catch(err => {
|
|
@@ -54,30 +80,33 @@ const registerNewProjectGroup = async config => {
|
|
|
54
80
|
return projectGroupInfo
|
|
55
81
|
}
|
|
56
82
|
|
|
57
|
-
const
|
|
83
|
+
const createProjectsArray = params => {
|
|
58
84
|
let projectsArray = []
|
|
59
85
|
let projects = {}
|
|
60
|
-
|
|
61
86
|
params.forEach(param => {
|
|
62
|
-
projects =
|
|
63
|
-
path: param.file,
|
|
64
|
-
name: param.name ? param.name : param.file,
|
|
65
|
-
source: 'SCA',
|
|
66
|
-
language: param.language,
|
|
67
|
-
packageManager: 'MAVEN',
|
|
68
|
-
target: 'SCA',
|
|
69
|
-
sourceId: '' // this is appID at the moment and scaID in future
|
|
70
|
-
}
|
|
87
|
+
projects = createProject(param)
|
|
71
88
|
projectsArray.push(projects)
|
|
72
89
|
})
|
|
73
90
|
|
|
74
91
|
return projectsArray
|
|
75
92
|
}
|
|
76
93
|
|
|
94
|
+
const createProject = param => {
|
|
95
|
+
return {
|
|
96
|
+
path: param.fileName,
|
|
97
|
+
name: param.repo ? param.fileName : getProjectName(param),
|
|
98
|
+
source: 'SCA',
|
|
99
|
+
language: param.language,
|
|
100
|
+
packageManager: param.packageManager,
|
|
101
|
+
target: 'SCA',
|
|
102
|
+
sourceId: ''
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
77
106
|
const getExistingGroupProjectId = (config, projectGroupsInfoEx) => {
|
|
78
107
|
let existingGroupProjectId = ''
|
|
79
108
|
projectGroupsInfoEx.forEach(i => {
|
|
80
|
-
if (i.
|
|
109
|
+
if (i.repositoryId === config.repositoryId) {
|
|
81
110
|
existingGroupProjectId = i.projectGroupId
|
|
82
111
|
}
|
|
83
112
|
})
|
|
@@ -85,21 +114,46 @@ const getExistingGroupProjectId = (config, projectGroupsInfoEx) => {
|
|
|
85
114
|
}
|
|
86
115
|
|
|
87
116
|
const getProjectIdFromArray = (config, array) => {
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
117
|
+
if (array.length === 1) {
|
|
118
|
+
return array[0].projectId
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
if (config.name) {
|
|
122
|
+
for (const i of array) {
|
|
123
|
+
//match on name
|
|
124
|
+
if (i.name === config.name) return i.projectId
|
|
92
125
|
}
|
|
93
|
-
}
|
|
94
|
-
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
for (const i of array) {
|
|
129
|
+
//match on fileName
|
|
130
|
+
if (i.name === config.fileName) return i.projectId
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
return ''
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
const addAdditionalData = (body, data) => {
|
|
137
|
+
body.projectGroupId = data.projectGroupId ? data.projectGroupId : null
|
|
138
|
+
body.projectGroupName = data.projectGroupName ? data.projectGroupName : null
|
|
139
|
+
body.projectLanguage = data.projectLanguage ? data.projectLanguage : null
|
|
140
|
+
body.projectType = data.projectType ? data.projectType : null
|
|
95
141
|
}
|
|
96
142
|
|
|
97
|
-
const registerProjectIdOnCliServices = async (
|
|
143
|
+
const registerProjectIdOnCliServices = async (
|
|
144
|
+
config,
|
|
145
|
+
projectId,
|
|
146
|
+
additionalData = undefined
|
|
147
|
+
) => {
|
|
98
148
|
const client = commonApi.getHttpClient(config)
|
|
99
149
|
|
|
100
150
|
let cliServicesBody = {
|
|
101
151
|
projectId: projectId,
|
|
102
|
-
name: config.
|
|
152
|
+
name: config.repo ? config.fileName : getProjectName(config)
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
if (additionalData) {
|
|
156
|
+
addAdditionalData(cliServicesBody, additionalData)
|
|
103
157
|
}
|
|
104
158
|
|
|
105
159
|
let result = await client
|
|
@@ -107,24 +161,48 @@ const registerProjectIdOnCliServices = async (config, projectId) => {
|
|
|
107
161
|
.then(res => {
|
|
108
162
|
if (config.debug || config.verbose) {
|
|
109
163
|
console.log('\nregistration on cli services')
|
|
110
|
-
console.log(
|
|
164
|
+
console.log('request body', cliServicesBody)
|
|
165
|
+
console.log('response code', res.statusCode)
|
|
111
166
|
}
|
|
112
167
|
if (res.statusCode === 201 || res.statusCode === 200) {
|
|
113
168
|
return res.body
|
|
114
169
|
} else {
|
|
115
|
-
|
|
170
|
+
console.log('Failed to Register On Cli Services')
|
|
171
|
+
console.log(res.statusCode)
|
|
172
|
+
process.exit(1)
|
|
116
173
|
}
|
|
117
174
|
})
|
|
118
175
|
|
|
119
176
|
return result
|
|
120
177
|
}
|
|
121
178
|
|
|
179
|
+
const registerProjectWithGroupProjectId = async config => {
|
|
180
|
+
const client = commonApi.getHttpClient(config)
|
|
181
|
+
config.language = config.language === 'NODE' ? 'JAVASCRIPT' : config.language
|
|
182
|
+
|
|
183
|
+
let body = createProject(config)
|
|
184
|
+
let result = await client.registerProject(config, body).then(res => {
|
|
185
|
+
if (config.debug || config.verbose) {
|
|
186
|
+
console.log('\nregister Project With Group ProjectId')
|
|
187
|
+
console.log(res.statusCode)
|
|
188
|
+
console.log(res.body)
|
|
189
|
+
}
|
|
190
|
+
if (res.statusCode === 201 || res.statusCode === 200) {
|
|
191
|
+
return res.body
|
|
192
|
+
} else {
|
|
193
|
+
return []
|
|
194
|
+
}
|
|
195
|
+
})
|
|
196
|
+
|
|
197
|
+
return result
|
|
198
|
+
}
|
|
199
|
+
|
|
122
200
|
const retrieveExistingProjectIdWithProjectGroupId = async (
|
|
123
201
|
config,
|
|
124
202
|
client,
|
|
125
203
|
projectGroupId
|
|
126
204
|
) => {
|
|
127
|
-
|
|
205
|
+
return await client
|
|
128
206
|
.retrieveExistingProjectIdByProjectGroupId(config, projectGroupId)
|
|
129
207
|
.then(res => {
|
|
130
208
|
if (config.debug || config.verbose) {
|
|
@@ -136,11 +214,9 @@ const retrieveExistingProjectIdWithProjectGroupId = async (
|
|
|
136
214
|
if (res.statusCode === 200) {
|
|
137
215
|
return res.body
|
|
138
216
|
} else {
|
|
139
|
-
return
|
|
217
|
+
return ''
|
|
140
218
|
}
|
|
141
219
|
})
|
|
142
|
-
|
|
143
|
-
return getProjectIdFromArray(config, groups)
|
|
144
220
|
}
|
|
145
221
|
|
|
146
222
|
const retrieveProjectByOrganization = async (config, client) => {
|
|
@@ -159,16 +235,41 @@ const retrieveProjectByOrganization = async (config, client) => {
|
|
|
159
235
|
})
|
|
160
236
|
}
|
|
161
237
|
|
|
162
|
-
const retrieveExistingProjectGroups = async
|
|
238
|
+
const retrieveExistingProjectGroups = async config => {
|
|
239
|
+
const client = commonApi.getHttpClient(config)
|
|
163
240
|
return await client.retrieveExistingProjectGroupsByOrg(config).then(res => {
|
|
241
|
+
if (config.debug || config.verbose) {
|
|
242
|
+
console.log('retrieve Existing ProjectGroups By Org')
|
|
243
|
+
console.log(res.statusCode)
|
|
244
|
+
console.log(res.body)
|
|
245
|
+
}
|
|
164
246
|
if (res.statusCode === 201 || res.statusCode === 200) {
|
|
165
|
-
|
|
247
|
+
let correctGroupID = res?.body?.filter(
|
|
248
|
+
i => i.repositoryId === config.repositoryId
|
|
249
|
+
)
|
|
250
|
+
|
|
251
|
+
if (correctGroupID.length > 0) {
|
|
252
|
+
return correctGroupID[0].projectGroupId
|
|
253
|
+
}
|
|
254
|
+
return ''
|
|
166
255
|
} else {
|
|
167
|
-
return
|
|
256
|
+
return ''
|
|
168
257
|
}
|
|
169
258
|
})
|
|
170
259
|
}
|
|
171
260
|
|
|
261
|
+
const getProjectGroupId = async config => {
|
|
262
|
+
let projectGroupId = ''
|
|
263
|
+
if (config.projectGroupId === '' || config.projectGroupId === undefined) {
|
|
264
|
+
projectGroupId = await retrieveExistingProjectGroups(config)
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
if (projectGroupId === '') {
|
|
268
|
+
projectGroupId = await registerNewProjectGroup(config)
|
|
269
|
+
}
|
|
270
|
+
return projectGroupId
|
|
271
|
+
}
|
|
272
|
+
|
|
172
273
|
const dealWithNoName = async config => {
|
|
173
274
|
try {
|
|
174
275
|
config.name = getAppName(config.file)
|
|
@@ -183,5 +284,11 @@ module.exports = {
|
|
|
183
284
|
getProjectIdByOrg,
|
|
184
285
|
registerProjectIdOnCliServices,
|
|
185
286
|
dealWithNoName,
|
|
186
|
-
registerNewProjectGroup
|
|
287
|
+
registerNewProjectGroup,
|
|
288
|
+
createNewProjectGroupBody,
|
|
289
|
+
registerProjectWithGroupProjectId,
|
|
290
|
+
getExistingGroupProjectId,
|
|
291
|
+
getProjectGroupId,
|
|
292
|
+
retrieveExistingProjectGroups,
|
|
293
|
+
createProject
|
|
187
294
|
}
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
const commonApi = require('../../utils/commonApi')
|
|
2
|
+
const retrieveRepoId = async config => {
|
|
3
|
+
const client = await commonApi.getHttpClient(config)
|
|
4
|
+
|
|
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
|
+
|
|
14
|
+
if (res.statusCode === 201 || res.statusCode === 200) {
|
|
15
|
+
return res.body.repositoryId
|
|
16
|
+
} else {
|
|
17
|
+
return ''
|
|
18
|
+
}
|
|
19
|
+
})
|
|
20
|
+
|
|
21
|
+
return repositoryId
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const registerNewRepo = async config => {
|
|
25
|
+
let body = {
|
|
26
|
+
externalScmUrl: config.repositoryUrl,
|
|
27
|
+
externalScmName: config.repositoryName,
|
|
28
|
+
externalId: config.externalId,
|
|
29
|
+
primaryLanguage: config.language,
|
|
30
|
+
defaultBranch: 'develop'
|
|
31
|
+
}
|
|
32
|
+
if (config.debug || config.verbose) {
|
|
33
|
+
console.log('registerNewRepo')
|
|
34
|
+
console.log(body)
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const client = await commonApi.getHttpClient(config)
|
|
38
|
+
|
|
39
|
+
let result = await client
|
|
40
|
+
.registerRepo(config, body)
|
|
41
|
+
.then(res => {
|
|
42
|
+
if (config.debug || config.verbose) {
|
|
43
|
+
console.log('\nRegister Repository')
|
|
44
|
+
console.log(res.statusCode)
|
|
45
|
+
console.log(res.body)
|
|
46
|
+
}
|
|
47
|
+
if (res.statusCode === 201 || res.statusCode === 200) {
|
|
48
|
+
if (config.debug || config.verbose) {
|
|
49
|
+
console.log('registerRepository - response')
|
|
50
|
+
console.log('response', res.body)
|
|
51
|
+
}
|
|
52
|
+
return res?.body?.repositoryId
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
if (res.statusCode === 409) {
|
|
56
|
+
return ''
|
|
57
|
+
}
|
|
58
|
+
if (res.statusCode === 400) {
|
|
59
|
+
if (config.debug || config.verbose) {
|
|
60
|
+
console.log('\nError Registering Repository - Bad request')
|
|
61
|
+
console.log(res.statusCode)
|
|
62
|
+
console.log(res.message)
|
|
63
|
+
}
|
|
64
|
+
process.exit(1)
|
|
65
|
+
}
|
|
66
|
+
})
|
|
67
|
+
.catch(err => {
|
|
68
|
+
console.log('\nError Registering Repository')
|
|
69
|
+
console.log(err.statusCode)
|
|
70
|
+
console.log(err.message)
|
|
71
|
+
process.exit(1)
|
|
72
|
+
})
|
|
73
|
+
|
|
74
|
+
return result
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
const retrieveProjectInfoViaRepoId = async config => {
|
|
78
|
+
const client = await commonApi.getHttpClient(config)
|
|
79
|
+
|
|
80
|
+
let result = await client
|
|
81
|
+
.retrieveProjectByRepoId(config)
|
|
82
|
+
.then(res => {
|
|
83
|
+
if (config.debug || config.verbose) {
|
|
84
|
+
console.log('\nRetrieve Project By RepoId')
|
|
85
|
+
console.log(res.statusCode)
|
|
86
|
+
console.log(res.body)
|
|
87
|
+
}
|
|
88
|
+
if (res.statusCode === 201 || res.statusCode === 200) {
|
|
89
|
+
return res?.body
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
if (res.statusCode === 409) {
|
|
93
|
+
return []
|
|
94
|
+
}
|
|
95
|
+
})
|
|
96
|
+
.catch(err => {
|
|
97
|
+
console.log('\nError Retrieve Project By RepoId')
|
|
98
|
+
console.log(err.statusCode)
|
|
99
|
+
})
|
|
100
|
+
|
|
101
|
+
return result
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
const getRepoId = async config => {
|
|
105
|
+
let repoId = ''
|
|
106
|
+
if (config.repositoryId === '' || config.repositoryId === undefined) {
|
|
107
|
+
repoId = await retrieveRepoId(config)
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
if (repoId === '') {
|
|
111
|
+
repoId = await registerNewRepo(config)
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
return repoId
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
module.exports = {
|
|
118
|
+
retrieveRepoId,
|
|
119
|
+
registerNewRepo,
|
|
120
|
+
getRepoId,
|
|
121
|
+
retrieveProjectInfoViaRepoId
|
|
122
|
+
}
|
package/src/common/HTTPClient.js
CHANGED
|
@@ -225,12 +225,6 @@ HTTPClient.prototype.scaServiceIngest = function scaServiceIngest(
|
|
|
225
225
|
options.url = url
|
|
226
226
|
options.body = requestBody
|
|
227
227
|
|
|
228
|
-
if (config.debug || config.verbose) {
|
|
229
|
-
console.log('scaServiceIngest')
|
|
230
|
-
console.log('url', options.url)
|
|
231
|
-
console.log('body', options.body)
|
|
232
|
-
}
|
|
233
|
-
|
|
234
228
|
return requestUtils.sendRequest({ method: 'post', options })
|
|
235
229
|
}
|
|
236
230
|
|
|
@@ -346,6 +340,17 @@ HTTPClient.prototype.registerRepo = function registerRepo(config, requestBody) {
|
|
|
346
340
|
return requestUtils.sendRequest({ method: 'post', options })
|
|
347
341
|
}
|
|
348
342
|
|
|
343
|
+
HTTPClient.prototype.retrieveProjectByRepoId = function retrieveProjectByRepoId(
|
|
344
|
+
config,
|
|
345
|
+
requestBody
|
|
346
|
+
) {
|
|
347
|
+
const options = _.cloneDeep(this.requestOptions)
|
|
348
|
+
let url = createRepoProjectUrl(config)
|
|
349
|
+
options.url = url
|
|
350
|
+
options.body = requestBody
|
|
351
|
+
return requestUtils.sendRequest({ method: 'get', options })
|
|
352
|
+
}
|
|
353
|
+
|
|
349
354
|
HTTPClient.prototype.registerProjectGroup = function (config, requestBody) {
|
|
350
355
|
const options = _.cloneDeep(this.requestOptions)
|
|
351
356
|
let url = registerProjectGroupUrl(config)
|
|
@@ -355,17 +360,18 @@ HTTPClient.prototype.registerProjectGroup = function (config, requestBody) {
|
|
|
355
360
|
if (config.debug || config.verbose) {
|
|
356
361
|
console.log('registerProjectGroup')
|
|
357
362
|
console.log('url', options.url)
|
|
358
|
-
console.log('body', options.body)
|
|
363
|
+
// console.log('body', options.body)
|
|
359
364
|
}
|
|
360
365
|
|
|
361
366
|
return requestUtils.sendRequest({ method: 'post', options })
|
|
362
367
|
}
|
|
363
368
|
|
|
364
|
-
HTTPClient.prototype.registerProject = function (config,
|
|
369
|
+
HTTPClient.prototype.registerProject = function (config, body) {
|
|
365
370
|
const options = _.cloneDeep(this.requestOptions)
|
|
366
|
-
let url = registerProjectUrl(config
|
|
371
|
+
let url = registerProjectUrl(config)
|
|
367
372
|
options.url = url
|
|
368
|
-
|
|
373
|
+
options.body = body
|
|
374
|
+
return requestUtils.sendRequest({ method: 'post', options })
|
|
369
375
|
}
|
|
370
376
|
HTTPClient.prototype.retrieveSourcesViaRepositoryId = function (
|
|
371
377
|
config,
|
|
@@ -405,6 +411,9 @@ HTTPClient.prototype.retrieveProjectByOrganizationId = function registerRepo(
|
|
|
405
411
|
const options = _.cloneDeep(this.requestOptions)
|
|
406
412
|
let url = retrieveProjectByOrganizationIdUrl(config)
|
|
407
413
|
options.url = url
|
|
414
|
+
if (config.debug || config.verbose) {
|
|
415
|
+
console.log(url)
|
|
416
|
+
}
|
|
408
417
|
return requestUtils.sendRequest({ method: 'get', options })
|
|
409
418
|
}
|
|
410
419
|
|
|
@@ -412,8 +421,15 @@ HTTPClient.prototype.retrieveExistingProjectGroupsByOrg = function registerRepo(
|
|
|
412
421
|
config
|
|
413
422
|
) {
|
|
414
423
|
const options = _.cloneDeep(this.requestOptions)
|
|
415
|
-
let url =
|
|
424
|
+
let url =
|
|
425
|
+
retrieveExistingGroupProjectsByOrgUrl(config) +
|
|
426
|
+
'?name=' +
|
|
427
|
+
config.repositoryName +
|
|
428
|
+
'&type=REPOSITORY'
|
|
416
429
|
options.url = url
|
|
430
|
+
if (config.debug || config.verbose) {
|
|
431
|
+
console.log(options.url)
|
|
432
|
+
}
|
|
417
433
|
return requestUtils.sendRequest({ method: 'get', options })
|
|
418
434
|
}
|
|
419
435
|
|
|
@@ -622,7 +638,9 @@ function createScaServiceReportStatusURL(config, reportId) {
|
|
|
622
638
|
function createScaServiceNoProjectIdURL(config) {
|
|
623
639
|
return `${config.host}/Contrast/api/sca/organizations/${
|
|
624
640
|
config.organizationId
|
|
625
|
-
}/libraries/ingests/tree${
|
|
641
|
+
}/libraries/ingests/tree${
|
|
642
|
+
config.repo && config.language === 'JAVA?' ? 'incomplete=true' : ''
|
|
643
|
+
}`
|
|
626
644
|
}
|
|
627
645
|
|
|
628
646
|
// function createScaServiceIngestsURL(config) {
|
|
@@ -635,7 +653,9 @@ function createScaServiceHealthURL(config) {
|
|
|
635
653
|
|
|
636
654
|
function createScaServiceIngestURL(config) {
|
|
637
655
|
let optionalParams = []
|
|
638
|
-
config.repo
|
|
656
|
+
config.repo && config.language === 'JAVA'
|
|
657
|
+
? optionalParams.push('incomplete=true')
|
|
658
|
+
: null
|
|
639
659
|
config.track ? optionalParams.push('persist=true') : null
|
|
640
660
|
|
|
641
661
|
let params = '?'
|
|
@@ -664,8 +684,8 @@ const registerProjectGroupUrl = config => {
|
|
|
664
684
|
return `${config.host}/api/v4/organizations/${config.organizationId}/project-groups`
|
|
665
685
|
}
|
|
666
686
|
|
|
667
|
-
const registerProjectUrl =
|
|
668
|
-
return `${config.host}/api/v4/organizations/${config.organizationId}/project-groups/${projectGroupId}/projects`
|
|
687
|
+
const registerProjectUrl = config => {
|
|
688
|
+
return `${config.host}/api/v4/organizations/${config.organizationId}/project-groups/${config.projectGroupId}/projects`
|
|
669
689
|
}
|
|
670
690
|
|
|
671
691
|
const retrieveRegisterOnCliServicesUrl = config => {
|
|
@@ -677,16 +697,21 @@ const retrieveSourcesUrl = (config, repositoryId) => {
|
|
|
677
697
|
}
|
|
678
698
|
|
|
679
699
|
const retrieveRepoByOrgAndGitURL = config => {
|
|
680
|
-
return `${config.host}/api/v4/organizations/${config.organizationId}/
|
|
700
|
+
return `${config.host}/api/v4/organizations/${config.organizationId}/repositories/external-url?externalRepoUrl=${config.repositoryUrl}`
|
|
681
701
|
}
|
|
682
702
|
|
|
683
703
|
const retrieveProjectByOrganizationIdUrl = config => {
|
|
684
704
|
let baseUrl = `${config.host}/api/v4/organizations/${config.organizationId}/projects`
|
|
685
|
-
baseUrl = config.name
|
|
705
|
+
baseUrl = config.name
|
|
706
|
+
? baseUrl.concat(`?name=${config.name}`)
|
|
707
|
+
: baseUrl.concat(`?name=${config.fileName}`)
|
|
686
708
|
baseUrl = config.language
|
|
687
709
|
? baseUrl.concat(`&language=${config.language}`)
|
|
688
710
|
: baseUrl
|
|
689
711
|
baseUrl = config.language ? baseUrl.concat(`&source=SCA`) : baseUrl
|
|
712
|
+
baseUrl = config.repo
|
|
713
|
+
? baseUrl.concat(`&type=REPOSITORY`)
|
|
714
|
+
: baseUrl.concat(`&type=CLI`)
|
|
690
715
|
return baseUrl
|
|
691
716
|
}
|
|
692
717
|
|
|
@@ -702,7 +727,11 @@ const retrieveExistingRepoUrl = config => {
|
|
|
702
727
|
}
|
|
703
728
|
|
|
704
729
|
function createRepositoryUrl(config) {
|
|
705
|
-
return `${config.host}/
|
|
730
|
+
return `${config.host}/api/v4/organizations/${config.organizationId}/repositories`
|
|
731
|
+
}
|
|
732
|
+
|
|
733
|
+
function createRepoProjectUrl(config) {
|
|
734
|
+
return `${config.host}/api/v4/organizations/${config.organizationId}/repositories/${config.repositoryId}/projects`
|
|
706
735
|
}
|
|
707
736
|
|
|
708
737
|
function createLibraryVulnerabilitiesUrl(config) {
|