@contrast/contrast 1.0.23 → 2.0.1

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.
Files changed (75) hide show
  1. package/README.md +21 -138
  2. package/dist/audit/languageAnalysisEngine/sendSnapshot.js +2 -19
  3. package/dist/audit/save.js +6 -1
  4. package/dist/cliConstants.js +49 -0
  5. package/dist/commands/audit/auditController.js +2 -1
  6. package/dist/commands/audit/help.js +2 -3
  7. package/dist/commands/audit/processAudit.js +2 -0
  8. package/dist/commands/audit/saveFile.js +5 -1
  9. package/dist/commands/{fingerprint → github}/processFingerprint.js +6 -2
  10. package/dist/commands/github/projectGroup.js +174 -0
  11. package/dist/commands/github/repoServices.js +70 -0
  12. package/dist/common/HTTPClient.js +165 -13
  13. package/dist/common/errorHandling.js +1 -1
  14. package/dist/constants/constants.js +3 -5
  15. package/dist/constants/locales.js +7 -3
  16. package/dist/index.js +4 -4
  17. package/dist/lambda/lambda.js +3 -1
  18. package/dist/scaAnalysis/common/commonReportingFunctionsSca.js +3 -3
  19. package/dist/scaAnalysis/common/scaServicesUpload.js +77 -7
  20. package/dist/scaAnalysis/common/treeUpload.js +19 -5
  21. package/dist/scaAnalysis/go/goAnalysis.js +6 -1
  22. package/dist/scaAnalysis/java/index.js +6 -1
  23. package/dist/scaAnalysis/javascript/index.js +5 -2
  24. package/dist/scaAnalysis/legacy/legacyFlow.js +33 -0
  25. package/dist/scaAnalysis/php/index.js +8 -2
  26. package/dist/scaAnalysis/processServicesFlow.js +39 -0
  27. package/dist/scaAnalysis/python/analysis.js +10 -4
  28. package/dist/scaAnalysis/python/index.js +6 -1
  29. package/dist/scaAnalysis/repoMode/index.js +2 -2
  30. package/dist/scaAnalysis/ruby/analysis.js +10 -1
  31. package/dist/scaAnalysis/ruby/index.js +6 -1
  32. package/dist/scaAnalysis/scaAnalysis.js +47 -25
  33. package/dist/scan/autoDetection.js +47 -4
  34. package/dist/scan/fileUtils.js +5 -4
  35. package/dist/utils/commonApi.js +26 -1
  36. package/dist/utils/settingsHelper.js +14 -0
  37. package/package.json +8 -5
  38. package/src/audit/languageAnalysisEngine/sendSnapshot.js +3 -22
  39. package/src/audit/save.js +10 -1
  40. package/src/cliConstants.js +52 -0
  41. package/src/commands/audit/auditController.js +2 -1
  42. package/src/commands/audit/help.js +2 -3
  43. package/src/commands/audit/processAudit.js +2 -0
  44. package/src/commands/audit/saveFile.js +6 -1
  45. package/src/commands/{fingerprint → github}/processFingerprint.js +8 -2
  46. package/src/commands/github/projectGroup.js +198 -0
  47. package/src/commands/github/repoServices.js +80 -0
  48. package/src/common/HTTPClient.js +221 -13
  49. package/src/common/errorHandling.js +2 -2
  50. package/src/constants/constants.js +3 -5
  51. package/src/constants/locales.js +9 -3
  52. package/src/index.ts +5 -5
  53. package/src/lambda/lambda.ts +3 -1
  54. package/src/lambda/lambdaUtils.ts +1 -1
  55. package/src/scaAnalysis/common/commonReportingFunctionsSca.js +3 -3
  56. package/src/scaAnalysis/common/scaServicesUpload.js +92 -7
  57. package/src/scaAnalysis/common/treeUpload.js +20 -5
  58. package/src/scaAnalysis/go/goAnalysis.js +6 -1
  59. package/src/scaAnalysis/java/index.js +6 -1
  60. package/src/scaAnalysis/javascript/index.js +6 -4
  61. package/src/scaAnalysis/legacy/legacyFlow.js +48 -0
  62. package/src/scaAnalysis/php/index.js +8 -2
  63. package/src/scaAnalysis/processServicesFlow.js +61 -0
  64. package/src/scaAnalysis/python/analysis.js +10 -4
  65. package/src/scaAnalysis/python/index.js +6 -1
  66. package/src/scaAnalysis/repoMode/index.js +2 -2
  67. package/src/scaAnalysis/ruby/analysis.js +11 -1
  68. package/src/scaAnalysis/ruby/index.js +6 -1
  69. package/src/scaAnalysis/scaAnalysis.js +61 -37
  70. package/src/scan/autoDetection.js +50 -5
  71. package/src/scan/fileUtils.js +5 -4
  72. package/src/utils/commonApi.js +29 -1
  73. package/src/utils/settingsHelper.js +16 -0
  74. /package/dist/commands/{fingerprint → github}/fingerprintConfig.js +0 -0
  75. /package/src/commands/{fingerprint → github}/fingerprintConfig.js +0 -0
@@ -1,16 +1,22 @@
1
1
  const fingerprintConfig = require('./fingerprintConfig')
2
+ const repoServices = require('./repoServices')
3
+ const settingsHelper = require('../../utils/settingsHelper')
2
4
  const autoDetection = require('../../scan/autoDetection')
3
5
  const saveResults = require('../../scan/saveResults')
4
6
  const processFingerprint = async (contrastConf, argvMain) => {
5
- const config = await fingerprintConfig.getFingerprintConfig(
7
+ let config = await fingerprintConfig.getFingerprintConfig(
6
8
  contrastConf,
7
9
  'fingerprint',
8
10
  argvMain
9
11
  )
12
+ config = await settingsHelper.getSettings(config)
13
+ config.repositoryId = await repoServices.getRepoId(config)
10
14
  let fingerprint = await autoDetection.autoDetectFingerprintInfo(
11
15
  config.file,
12
- config.depth
16
+ config.depth,
17
+ config
13
18
  )
19
+
14
20
  let idArray = fingerprint.map(x => x.id)
15
21
  await saveResults.writeResultsToFile(fingerprint, 'fingerPrintInfo.json')
16
22
  return console.log(idArray)
@@ -0,0 +1,198 @@
1
+ const commonApi = require('../../utils/commonApi')
2
+ const { getAppName } = require('../audit/auditController')
3
+
4
+ const getProjectIdByOrg = async config => {
5
+ const client = await commonApi.getHttpClient(config)
6
+ config.language = config.language === 'NODE' ? 'JAVASCRIPT' : config.language
7
+ let projectId = ''
8
+
9
+ let projectByOrg = await retrieveProjectByOrganization(config, client)
10
+
11
+ if (projectByOrg?.length > 0) {
12
+ projectId = getProjectIdFromArray(config, projectByOrg)
13
+ }
14
+
15
+ return projectId
16
+ }
17
+
18
+ const createNewProjectGroupBody = async config => {
19
+ let body = {
20
+ organizationId: config.organizationId,
21
+ name: config.name ? config.name : config.file //has to be unique per project
22
+ }
23
+ if (config.repo || config?.repositoryId) {
24
+ body.repositoryId = config.repositoryId
25
+ body.type = 'REPOSITORY'
26
+ } else {
27
+ body.repositoryId = null
28
+ body.type = 'CLI'
29
+ }
30
+ return body
31
+ }
32
+
33
+ const registerNewProjectGroup = async config => {
34
+ let body = await createNewProjectGroupBody(config)
35
+
36
+ const client = await commonApi.getHttpClient(config)
37
+ body.projects = createProjects([config])
38
+
39
+ let projectGroupInfo = await client
40
+ .registerProjectGroup(config, body)
41
+ .then(res => {
42
+ if (config.debug || config.verbose) {
43
+ console.log('\nRegister ProjectGroup')
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('registerProjectGroup - response')
50
+ console.log('response', res.body)
51
+ }
52
+ return res?.body?.projectGroupId
53
+ }
54
+
55
+ if (res.statusCode === 409) {
56
+ return []
57
+ }
58
+ })
59
+ .catch(err => {
60
+ console.log('\nError Registering Project Group')
61
+ console.log(err.statusCode)
62
+ })
63
+
64
+ return projectGroupInfo
65
+ }
66
+
67
+ const createProjects = params => {
68
+ let projectsArray = []
69
+ let projects = {}
70
+
71
+ params.forEach(param => {
72
+ projects = {
73
+ path: param.file,
74
+ name: param.name ? param.name : param.file,
75
+ source: 'SCA',
76
+ language: param.language,
77
+ packageManager: 'MAVEN',
78
+ target: 'SCA',
79
+ sourceId: '' // this is appID at the moment and scaID in future
80
+ }
81
+ projectsArray.push(projects)
82
+ })
83
+
84
+ return projectsArray
85
+ }
86
+
87
+ const getExistingGroupProjectId = (config, projectGroupsInfoEx) => {
88
+ let existingGroupProjectId = ''
89
+ projectGroupsInfoEx.forEach(i => {
90
+ if (i.name === config.name) {
91
+ existingGroupProjectId = i.projectGroupId
92
+ }
93
+ })
94
+ return existingGroupProjectId
95
+ }
96
+
97
+ const getProjectIdFromArray = (config, array) => {
98
+ let projectId = ''
99
+ array?.forEach(i => {
100
+ if (i.name === config.name) {
101
+ projectId = i.projectId
102
+ }
103
+ })
104
+ return projectId
105
+ }
106
+
107
+ const registerProjectIdOnCliServices = async (config, projectId) => {
108
+ const client = commonApi.getHttpClient(config)
109
+
110
+ let cliServicesBody = {
111
+ projectId: projectId,
112
+ name: config.name
113
+ }
114
+
115
+ let result = await client
116
+ .registerOnCliServices(config, cliServicesBody)
117
+ .then(res => {
118
+ if (config.debug || config.verbose) {
119
+ console.log('\nregistration on cli services')
120
+ console.log(res.statusCode)
121
+ }
122
+ if (res.statusCode === 201 || res.statusCode === 200) {
123
+ return res.body
124
+ } else {
125
+ return []
126
+ }
127
+ })
128
+
129
+ return result
130
+ }
131
+
132
+ const retrieveExistingProjectIdWithProjectGroupId = async (
133
+ config,
134
+ client,
135
+ projectGroupId
136
+ ) => {
137
+ let groups = await client
138
+ .retrieveExistingProjectIdByProjectGroupId(config, projectGroupId)
139
+ .then(res => {
140
+ if (config.debug || config.verbose) {
141
+ console.log('\nRetrieve Existing ProjectId By ProjectGroupId')
142
+ console.log(res.statusCode)
143
+ console.log(res.body)
144
+ }
145
+
146
+ if (res.statusCode === 200) {
147
+ return res.body
148
+ } else {
149
+ return []
150
+ }
151
+ })
152
+
153
+ return getProjectIdFromArray(config, groups)
154
+ }
155
+
156
+ const retrieveProjectByOrganization = async (config, client) => {
157
+ return await client.retrieveProjectByOrganizationId(config).then(res => {
158
+ if (config.debug || config.verbose) {
159
+ console.log('\nRetrieve Project By OrganizationId')
160
+ console.log(res.statusCode)
161
+ console.log(res.body)
162
+ }
163
+
164
+ if (res.statusCode === 201 || res.statusCode === 200) {
165
+ return res.body
166
+ } else {
167
+ return []
168
+ }
169
+ })
170
+ }
171
+
172
+ const retrieveExistingProjectGroups = async (config, client) => {
173
+ return await client.retrieveExistingProjectGroupsByOrg(config).then(res => {
174
+ if (res.statusCode === 201 || res.statusCode === 200) {
175
+ return res.body
176
+ } else {
177
+ return []
178
+ }
179
+ })
180
+ }
181
+
182
+ const dealWithNoName = async config => {
183
+ try {
184
+ config.name = getAppName(config.file)
185
+ } catch (e) {
186
+ console.log(e.message.toString())
187
+ process.exit(1)
188
+ }
189
+ return config
190
+ }
191
+
192
+ module.exports = {
193
+ getProjectIdByOrg,
194
+ registerProjectIdOnCliServices,
195
+ dealWithNoName,
196
+ registerNewProjectGroup,
197
+ createNewProjectGroupBody
198
+ }
@@ -0,0 +1,80 @@
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.repoUrl ? config.repoUrl : '',
27
+ externalScmName: config.repoName,
28
+ externalId: config.externalId ? config.externalId : '',
29
+ primaryLanguage: config.language,
30
+ defaultBranch: 'develop'
31
+ }
32
+
33
+ const client = await commonApi.getHttpClient(config)
34
+
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
+
51
+ if (res.statusCode === 409) {
52
+ return ''
53
+ }
54
+ })
55
+ .catch(err => {
56
+ console.log('\nError Registering Repository')
57
+ console.log(err.statusCode)
58
+ })
59
+
60
+ return result
61
+ }
62
+
63
+ const getRepoId = async config => {
64
+ let repoId = ''
65
+ if (config.repositoryId === '' || config.repositoryId === undefined) {
66
+ repoId = await retrieveRepoId(config)
67
+ }
68
+
69
+ if (repoId === '') {
70
+ repoId = await registerNewRepo(config)
71
+ }
72
+
73
+ return repoId
74
+ }
75
+
76
+ module.exports = {
77
+ retrieveRepoId,
78
+ registerNewRepo,
79
+ getRepoId
80
+ }
@@ -224,6 +224,24 @@ HTTPClient.prototype.scaServiceIngest = function scaServiceIngest(
224
224
  let url = createScaServiceIngestURL(config)
225
225
  options.url = url
226
226
  options.body = requestBody
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
+ return requestUtils.sendRequest({ method: 'post', options })
235
+ }
236
+
237
+ HTTPClient.prototype.noProjectIdUpload = function scaServiceIngest(
238
+ requestBody,
239
+ config
240
+ ) {
241
+ const options = _.cloneDeep(this.requestOptions)
242
+ let url = createScaServiceNoProjectIdURL(config)
243
+ options.url = url
244
+ options.body = requestBody
227
245
  return requestUtils.sendRequest({ method: 'post', options })
228
246
  }
229
247
 
@@ -237,23 +255,47 @@ HTTPClient.prototype.scaServiceReport = function scaServiceReport(
237
255
  return requestUtils.sendRequest({ method: 'get', options })
238
256
  }
239
257
 
240
- HTTPClient.prototype.scaServiceReportStatus = function scaServiceReport(
258
+ HTTPClient.prototype.scaServiceReportNoProjectId = function scaServiceReport(
241
259
  config,
242
260
  reportId
243
261
  ) {
244
262
  const options = _.cloneDeep(this.requestOptions)
245
- let url = createScaServiceReportStatusURL(config, reportId)
246
- options.url = url
263
+ options.url = createScaServiceReportNoProjectIdURL(config, reportId)
264
+ if (config.debug || config.verbose) {
265
+ console.log('createScaServiceReportNoProjectIdURL', options.url)
266
+ }
247
267
  return requestUtils.sendRequest({ method: 'get', options })
248
268
  }
249
269
 
250
- HTTPClient.prototype.scaServiceIngests = function scaServiceIngests(config) {
270
+ HTTPClient.prototype.scaServiceReportStatus = function scaServiceReport(
271
+ config,
272
+ reportId
273
+ ) {
251
274
  const options = _.cloneDeep(this.requestOptions)
252
- let url = createScaServiceIngestsURL(config)
253
- options.url = url
275
+ options.url = createScaServiceReportStatusURL(config, reportId)
276
+ if (config.debug || config.verbose) {
277
+ console.log('createScaServiceReportStatusURL', options.url)
278
+ }
254
279
  return requestUtils.sendRequest({ method: 'get', options })
255
280
  }
256
281
 
282
+ HTTPClient.prototype.scaServiceNoProjectIdReportStatus =
283
+ function scaServiceReport(config, reportId) {
284
+ const options = _.cloneDeep(this.requestOptions)
285
+ options.url = createScaServiceReportStatusURL(config, reportId)
286
+ if (config.debug || config.verbose) {
287
+ console.log('createScaServiceReportStatusURL', options.url)
288
+ }
289
+ return requestUtils.sendRequest({ method: 'get', options })
290
+ }
291
+
292
+ // HTTPClient.prototype.scaServiceIngests = function scaServiceIngests(config) {
293
+ // const options = _.cloneDeep(this.requestOptions)
294
+ // let url = createScaServiceIngestsURL(config)
295
+ // options.url = url
296
+ // return requestUtils.sendRequest({ method: 'get', options })
297
+ // }
298
+
257
299
  HTTPClient.prototype.scaServiceHealth = function scaServiceIngests(config) {
258
300
  const options = _.cloneDeep(this.requestOptions)
259
301
  let url = createScaServiceHealthURL(config)
@@ -296,6 +338,100 @@ HTTPClient.prototype.getAppId = function getAppId(config) {
296
338
  return requestUtils.sendRequest({ method: 'get', options })
297
339
  }
298
340
 
341
+ HTTPClient.prototype.registerRepo = function registerRepo(config, requestBody) {
342
+ const options = _.cloneDeep(this.requestOptions)
343
+ let url = createRepositoryUrl(config)
344
+ options.url = url
345
+ options.body = requestBody
346
+ return requestUtils.sendRequest({ method: 'post', options })
347
+ }
348
+
349
+ HTTPClient.prototype.registerProjectGroup = function (config, requestBody) {
350
+ const options = _.cloneDeep(this.requestOptions)
351
+ let url = registerProjectGroupUrl(config)
352
+ options.url = url
353
+ options.body = requestBody
354
+
355
+ if (config.debug || config.verbose) {
356
+ console.log('registerProjectGroup')
357
+ console.log('url', options.url)
358
+ console.log('body', options.body)
359
+ }
360
+
361
+ return requestUtils.sendRequest({ method: 'post', options })
362
+ }
363
+
364
+ HTTPClient.prototype.registerProject = function (config, projectGroupId) {
365
+ const options = _.cloneDeep(this.requestOptions)
366
+ let url = registerProjectUrl(config, projectGroupId)
367
+ options.url = url
368
+ return requestUtils.sendRequest({ method: 'get', options })
369
+ }
370
+ HTTPClient.prototype.retrieveSourcesViaRepositoryId = function (
371
+ config,
372
+ repositoryId
373
+ ) {
374
+ const options = _.cloneDeep(this.requestOptions)
375
+ let url = retrieveSourcesUrl(config, repositoryId)
376
+ options.url = url
377
+ return requestUtils.sendRequest({ method: 'get', options })
378
+ }
379
+
380
+ HTTPClient.prototype.retrieveRepoByOrgAndGitURL = function (config) {
381
+ const options = _.cloneDeep(this.requestOptions)
382
+ let url = retrieveRepoByOrgAndGitURL(config)
383
+ options.url = url
384
+ return requestUtils.sendRequest({ method: 'get', options })
385
+ }
386
+
387
+ HTTPClient.prototype.registerOnCliServices = function (config, project) {
388
+ const options = _.cloneDeep(this.requestOptions)
389
+ let url = retrieveRegisterOnCliServicesUrl(config)
390
+ options.url = url
391
+ options.body = project
392
+
393
+ if (config.debug || config.verbose) {
394
+ console.log('registerOnCliServices')
395
+ console.log('url', options.url)
396
+ console.log('body', options.body)
397
+ }
398
+
399
+ return requestUtils.sendRequest({ method: 'post', options })
400
+ }
401
+
402
+ HTTPClient.prototype.retrieveProjectByOrganizationId = function registerRepo(
403
+ config
404
+ ) {
405
+ const options = _.cloneDeep(this.requestOptions)
406
+ let url = retrieveProjectByOrganizationIdUrl(config)
407
+ options.url = url
408
+ return requestUtils.sendRequest({ method: 'get', options })
409
+ }
410
+
411
+ HTTPClient.prototype.retrieveExistingProjectGroupsByOrg = function registerRepo(
412
+ config
413
+ ) {
414
+ const options = _.cloneDeep(this.requestOptions)
415
+ let url = retrieveExistingGroupProjectsByOrgUrl(config)
416
+ options.url = url
417
+ return requestUtils.sendRequest({ method: 'get', options })
418
+ }
419
+
420
+ HTTPClient.prototype.retrieveExistingProjectIdByProjectGroupId =
421
+ function registerRepo(config, projectGroupId) {
422
+ const options = _.cloneDeep(this.requestOptions)
423
+ let url = retrieveExistingGroupProjectsByGroupIdUrl(config, projectGroupId)
424
+ options.url = url
425
+ return requestUtils.sendRequest({ method: 'get', options })
426
+ }
427
+
428
+ HTTPClient.prototype.retrieveExistingRepo = function registerRepo(config) {
429
+ const options = _.cloneDeep(this.requestOptions)
430
+ let url = retrieveExistingRepoUrl(config)
431
+ options.url = url
432
+ return requestUtils.sendRequest({ method: 'get', options })
433
+ }
434
+
299
435
  // HTTPClient.prototype.getDependencyTree = function getReport(
300
436
  // orgUuid,
301
437
  // appId,
@@ -468,26 +604,51 @@ function createSnapshotURL(config) {
468
604
  }
469
605
 
470
606
  function createScaServiceReportURL(config, reportId) {
471
- let baseUrl = `${config.host}/Contrast/api/sca/organizations/${config.organizationId}/applications/${config.applicationId}/libraries/reports/${reportId}`
607
+ let baseUrl = `${config.host}/Contrast/api/sca/organizations/${config.organizationId}/projects/${config.projectId}/libraries/reports/${reportId}`
608
+ baseUrl = config.ignoreDev ? baseUrl.concat('?nodesToInclude=PROD') : baseUrl
609
+ return baseUrl
610
+ }
611
+
612
+ function createScaServiceReportNoProjectIdURL(config, reportId) {
613
+ let baseUrl = `${config.host}/Contrast/api/sca/organizations/${config.organizationId}/libraries/reports/${reportId}`
472
614
  baseUrl = config.ignoreDev ? baseUrl.concat('?nodesToInclude=PROD') : baseUrl
473
615
  return baseUrl
474
616
  }
475
617
 
476
618
  function createScaServiceReportStatusURL(config, reportId) {
477
- return `${config.host}/Contrast/api/sca/organizations/${config.organizationId}/applications/${config.applicationId}/libraries/ingests/${reportId}/status`
619
+ return `${config.host}/Contrast/api/sca/organizations/${config.organizationId}/libraries/ingests/${reportId}/status`
478
620
  }
479
621
 
480
- function createScaServiceIngestsURL(config) {
481
- return `${config.host}/Contrast/api/sca/organizations/${config.organizationId}/applications/${config.applicationId}/libraries/ingests`
622
+ function createScaServiceNoProjectIdURL(config) {
623
+ return `${config.host}/Contrast/api/sca/organizations/${
624
+ config.organizationId
625
+ }/libraries/ingests/tree${config.repo ? '?incomplete=true' : ''}`
482
626
  }
483
627
 
628
+ // function createScaServiceIngestsURL(config) {
629
+ // return `${config.host}/Contrast/api/sca/organizations/${config.organizationId}/applications/${config.applicationId}/libraries/ingests`
630
+ // }
631
+
484
632
  function createScaServiceHealthURL(config) {
485
633
  return `${config.host}/Contrast/api/sca/organizations/${config.organizationId}/health`
486
634
  }
487
635
 
488
636
  function createScaServiceIngestURL(config) {
489
- let baseUrl = `${config.host}/Contrast/api/sca/organizations/${config.organizationId}/applications/${config.applicationId}/libraries/ingests/tree`
490
- baseUrl = config.track ? baseUrl.concat('?persist=true') : baseUrl
637
+ let optionalParams = []
638
+ config.repo ? optionalParams.push('incomplete=true') : null
639
+ config.track ? optionalParams.push('persist=true') : null
640
+
641
+ let params = '?'
642
+ optionalParams.forEach(param => {
643
+ params = params.concat(param)
644
+ params = params.concat('&')
645
+ })
646
+
647
+ let baseUrl = `${config.host}/Contrast/api/sca/organizations/${config.organizationId}/projects/${config.projectId}/libraries/ingests/tree${params}`
648
+
649
+ if (config.debug) {
650
+ console.log('createScaServiceIngestURL', baseUrl)
651
+ }
491
652
  return baseUrl
492
653
  }
493
654
 
@@ -499,6 +660,51 @@ const createAppNameUrl = config => {
499
660
  return `${config.host}/Contrast/api/ng/${config.organizationId}/applications/name?filterText=${config.applicationName}`
500
661
  }
501
662
 
663
+ const registerProjectGroupUrl = config => {
664
+ return `${config.host}/api/v4/organizations/${config.organizationId}/project-groups`
665
+ }
666
+
667
+ const registerProjectUrl = (config, projectGroupId) => {
668
+ return `${config.host}/api/v4/organizations/${config.organizationId}/project-groups/${projectGroupId}/projects`
669
+ }
670
+
671
+ const retrieveRegisterOnCliServicesUrl = config => {
672
+ return `${config.host}/Contrast/api/sca/organizations/${config.organizationId}/projects`
673
+ }
674
+
675
+ const retrieveSourcesUrl = (config, repositoryId) => {
676
+ return `${config.host}/projects/v1/repositories/${repositoryId}/sources`
677
+ }
678
+
679
+ const retrieveRepoByOrgAndGitURL = config => {
680
+ return `${config.host}/api/v4/organizations/${config.organizationId}/repositories/external-url?externalRepoUrl=${config.repoUrl}`
681
+ }
682
+
683
+ const retrieveProjectByOrganizationIdUrl = config => {
684
+ let baseUrl = `${config.host}/api/v4/organizations/${config.organizationId}/projects`
685
+ baseUrl = config.name ? baseUrl.concat(`?name=${config.name}`) : baseUrl
686
+ baseUrl = config.language
687
+ ? baseUrl.concat(`&language=${config.language}`)
688
+ : baseUrl
689
+ baseUrl = config.language ? baseUrl.concat(`&source=SCA`) : baseUrl
690
+ return baseUrl
691
+ }
692
+
693
+ const retrieveExistingGroupProjectsByOrgUrl = config => {
694
+ return `${config.host}/api/v4/organizations/${config.organizationId}/project-groups`
695
+ }
696
+
697
+ const retrieveExistingGroupProjectsByGroupIdUrl = (config, projectGroupId) => {
698
+ return `${config.host}/api/v4/organizations/${config.organizationId}/projects/${projectGroupId}/projects`
699
+ }
700
+ const retrieveExistingRepoUrl = config => {
701
+ return `${config.host}/projects/v4/organizations/${config.organizationId}/repositories`
702
+ }
703
+
704
+ function createRepositoryUrl(config) {
705
+ return `${config.host}/api/v4/organizations/${config.organizationId}/repositories`
706
+ }
707
+
502
708
  function createLibraryVulnerabilitiesUrl(config) {
503
709
  return `${config.host}/Contrast/api/ng/${config.organizationId}/libraries/artifactsByGroupNameVersion`
504
710
  }
@@ -526,7 +732,9 @@ function createSbomUrl(config, type) {
526
732
  }
527
733
 
528
734
  function createSCASbomUrl(config, type, reportId) {
529
- return `${config.host}/Contrast/api/sca/organizations/${config.organizationId}/libraries/applications/${config.applicationId}/sbom/${reportId}?toolType=${type}`
735
+ return config.projectId
736
+ ? `${config.host}/Contrast/api/sca/organizations/${config.organizationId}/projects/${config.projectId}/libraries/sbom/${reportId}?toolType=${type}`
737
+ : `${config.host}/Contrast/api/sca/organizations/${config.organizationId}/libraries/sbom/${reportId}?toolType=${type}`
530
738
  }
531
739
 
532
740
  function createTelemetryEventUrl(config) {
@@ -51,8 +51,8 @@ const maxAppError = () => {
51
51
 
52
52
  const parametersError = () => {
53
53
  generalError(
54
- `Values not recognised`,
55
- 'Check your command & keys again for hidden characters.\nFor more information use contrast help.'
54
+ `Credentials not recognized`,
55
+ 'Check your command & keys again for hidden characters / verify that the credentials are correct.\nFor more information use contrast help.'
56
56
  )
57
57
  process.exit(1)
58
58
  }
@@ -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 = '1.0.23'
17
+ const APP_VERSION = '2.0.1'
18
18
  const TIMEOUT = 120000
19
19
  const HIGH_COLOUR = '#ff9900'
20
20
  const CRITICAL_COLOUR = '#e35858'
@@ -30,14 +30,13 @@ const NOTE_PRIORITY = 5
30
30
  const AUTH_UI_URL = 'https://cli-auth.contrastsecurity.com'
31
31
  const AUTH_CALLBACK_URL = 'https://cli-auth-api.contrastsecurity.com'
32
32
  const SARIF_FILE = 'SARIF'
33
- const SBOM_CYCLONE_DX_FILE = 'cyclonedx'
34
- const SBOM_SPDX_FILE = 'spdx'
33
+ const SBOM_CYCLONE_DX_FILE = 'CYCLONEDX'
34
+ const SBOM_SPDX_FILE = 'SPDX'
35
35
  const CE_URL = 'https://ce.contrastsecurity.com'
36
36
 
37
37
  //configuration
38
38
  const SAAS = 'SAAS'
39
39
  const EOP = 'EOP'
40
- const MODE_BUILD = 'BUILD'
41
40
  const MODE_REPO = 'REPO'
42
41
 
43
42
  module.exports = {
@@ -68,6 +67,5 @@ module.exports = {
68
67
  SBOM_SPDX_FILE,
69
68
  SAAS,
70
69
  EOP,
71
- MODE_BUILD,
72
70
  MODE_REPO
73
71
  }
@@ -76,7 +76,7 @@ const en_locales = () => {
76
76
  constantsDoNotWaitForScan:
77
77
  'Fire and forget. Do not wait for the result of the scan.',
78
78
  constantsProjectName:
79
- 'Contrast project name. If not specified, Contrast uses contrast.settings to identify the project or creates a project.',
79
+ 'Contrast project name. If not specified, Contrast uses the file / folder name to identify the project or creates a new project.',
80
80
  constantsProjectId:
81
81
  'The ID associated with a scan project. Replace <ProjectID> with the ID for the scan project. To find the ID, select a scan project in Contrast and locate the last number in the URL.',
82
82
  failThresholdOptionErrorMessage: 'More than 0 vulnerabilities found',
@@ -190,9 +190,15 @@ const en_locales = () => {
190
190
  scanOptionsFileNameSummary:
191
191
  'Path of the file you want to scan. If no file is specified, Contrast searches for a .jar, .war, .exe or .zip file in the working directory.',
192
192
  scanOptionsVerboseSummary: ' Returns extended information to the terminal.',
193
- auditOptionsTrackSummary: ' Save the results to the UI.',
193
+ auditOptionsTrackSummary:
194
+ ' Send your dependency audit to Contrast to see results in the UI and start automating security checks. For instance when running local SCA checks you may not need or want to track the results.',
194
195
  auditOptionsBranchSummary:
195
196
  ' Set the branch name to associate the library results to.',
197
+ auditOptionsLegacySummary:
198
+ ' Creates an application in Contrast (a legacy workflow) - displays a dependency tree for your piece of code, utilizes metatdata.' +
199
+ '\n' +
200
+ '.NET is only supported using --legacy\n',
201
+ auditOptionsRepoSummary: ' Run in repo mode.',
196
202
  authSuccessMessage: 'Authentication successful',
197
203
  runAuthSuccessMessage:
198
204
  chalk.bold('CodeSec by Contrast') +
@@ -275,7 +281,7 @@ const en_locales = () => {
275
281
  ${chalk.bold(
276
282
  '.NET framework and .NET core:'
277
283
  )} MSBuild 15.0 or greater and a packages.lock.json file.
278
- Note: If the packages.lock.json file is unavailable it can be generated by setting RestorePackagesWithLockFile to true within each *.csproj file and running dotnet build.\n`,
284
+ Note: If the packages.lock.json file is unavailable it can be generated by setting RestorePackagesWithLockFile to true within each *.csproj file and running dotnet build. Only supported with the --legacy flag, an older workflow\n`,
279
285
  constantsAuditPrerequisitesContentNodeMessage: `${chalk.bold(
280
286
  'Node:'
281
287
  )} package.json and a lock file (either .package-lock.json or .yarn.lock.)\n`,