@contrast/contrast 2.0.1 → 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.
Files changed (49) hide show
  1. package/dist/audit/report/reportingFeature.js +7 -0
  2. package/dist/cliConstants.js +9 -8
  3. package/dist/commands/audit/processAudit.js +0 -2
  4. package/dist/commands/github/fingerprintConfig.js +2 -1
  5. package/dist/commands/github/processFingerprint.js +17 -7
  6. package/dist/commands/github/projectGroup.js +110 -30
  7. package/dist/commands/github/repoServices.js +42 -4
  8. package/dist/common/HTTPClient.js +37 -16
  9. package/dist/common/baseRequest.js +74 -0
  10. package/dist/constants/constants.js +1 -1
  11. package/dist/scaAnalysis/common/auditReport.js +8 -1
  12. package/dist/scaAnalysis/common/scaServicesUpload.js +3 -1
  13. package/dist/scaAnalysis/go/goReadDepFile.js +5 -1
  14. package/dist/scaAnalysis/java/analysis.js +1 -1
  15. package/dist/scaAnalysis/java/javaBuildDepsParser.js +11 -1
  16. package/dist/scaAnalysis/legacy/legacyFlow.js +0 -6
  17. package/dist/scaAnalysis/processServicesFlow.js +38 -17
  18. package/dist/scaAnalysis/repoMode/mavenParser.js +19 -1
  19. package/dist/scaAnalysis/scaAnalysis.js +4 -8
  20. package/dist/scan/autoDetection.js +12 -5
  21. package/dist/scan/fileUtils.js +33 -19
  22. package/dist/utils/paramsUtil/paramHandler.js +11 -2
  23. package/dist/utils/validationCheck.js +5 -1
  24. package/package.json +6 -3
  25. package/src/audit/report/reportingFeature.ts +7 -0
  26. package/src/cliConstants.js +9 -8
  27. package/src/commands/audit/processAudit.js +0 -2
  28. package/src/commands/github/fingerprintConfig.js +2 -2
  29. package/src/commands/github/processFingerprint.js +21 -11
  30. package/src/commands/github/projectGroup.js +131 -35
  31. package/src/commands/github/repoServices.js +46 -4
  32. package/src/common/HTTPClient.js +46 -17
  33. package/src/common/baseRequest.ts +83 -0
  34. package/src/constants/constants.js +1 -1
  35. package/src/scaAnalysis/common/auditReport.js +8 -1
  36. package/src/scaAnalysis/common/scaServicesUpload.js +5 -1
  37. package/src/scaAnalysis/go/goReadDepFile.js +5 -1
  38. package/src/scaAnalysis/java/analysis.js +1 -1
  39. package/src/scaAnalysis/java/javaBuildDepsParser.js +17 -1
  40. package/src/scaAnalysis/legacy/legacyFlow.js +0 -5
  41. package/src/scaAnalysis/processServicesFlow.js +82 -24
  42. package/src/scaAnalysis/repoMode/mavenParser.js +24 -1
  43. package/src/scaAnalysis/scaAnalysis.js +9 -8
  44. package/src/scan/autoDetection.js +12 -5
  45. package/src/scan/fileUtils.js +33 -19
  46. package/src/utils/paramsUtil/paramHandler.js +16 -2
  47. package/src/utils/validationCheck.js +6 -1
  48. package/dist/utils/settingsHelper.js +0 -14
  49. 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
  }
@@ -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
  '}:' +
@@ -379,7 +380,12 @@ const auditOptionDefinitions = [
379
380
  i18n.__('auditOptionsRepoSummary')
380
381
  },
381
382
  {
382
- name: 'repo-id',
383
+ name: 'repository-id',
384
+ type: String,
385
+ description: ''
386
+ },
387
+ {
388
+ name: 'project-group-id',
383
389
  type: String,
384
390
  description: ''
385
391
  }
@@ -392,7 +398,7 @@ const fingerprintOptionDefinitions = [
392
398
  description: '{bold ' + i18n.__('constantsOptional') + '}: ' + i18n.__('depthOption')
393
399
  },
394
400
  {
395
- name: 'repo-url',
401
+ name: 'repository-url',
396
402
  type: String,
397
403
  description: ''
398
404
  },
@@ -402,12 +408,7 @@ const fingerprintOptionDefinitions = [
402
408
  description: ''
403
409
  },
404
410
  {
405
- name: 'repo-name',
406
- type: String,
407
- description: ''
408
- },
409
- {
410
- name: 'language',
411
+ name: 'repository-name',
411
412
  type: String,
412
413
  description: ''
413
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
- const fingerprintParameters = await parsedCLIOptions.getCommandLineArgsCustom(contrastConf, command, argv, constants.commandLineDefinitions.fingerprintOptionDefinitions);
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 = {
@@ -1,18 +1,28 @@
1
1
  "use strict";
2
2
  const fingerprintConfig = require('./fingerprintConfig');
3
3
  const repoServices = require('./repoServices');
4
- const settingsHelper = require('../../utils/settingsHelper');
5
4
  const autoDetection = require('../../scan/autoDetection');
6
5
  const saveResults = require('../../scan/saveResults');
6
+ const projectConfig = require('./projectGroup');
7
7
  const processFingerprint = async (contrastConf, argvMain) => {
8
8
  let config = await fingerprintConfig.getFingerprintConfig(contrastConf, 'fingerprint', argvMain);
9
- config = await settingsHelper.getSettings(config);
10
9
  config.repositoryId = await repoServices.getRepoId(config);
11
- let fingerprint = await autoDetection.autoDetectFingerprintInfo(config.file, config.depth, config);
12
- let idArray = fingerprint.map(x => x.id);
13
- await saveResults.writeResultsToFile(fingerprint, 'fingerPrintInfo.json');
14
- return console.log(idArray);
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
+ }
15
25
  };
16
26
  module.exports = {
17
- processFingerprint
27
+ processFingerprint: processFingerprint
18
28
  };
@@ -13,23 +13,38 @@ const getProjectIdByOrg = async (config) => {
13
13
  };
14
14
  const createNewProjectGroupBody = async (config) => {
15
15
  let body = {
16
- organizationId: config.organizationId,
17
- name: config.name ? config.name : config.file
16
+ organizationId: config.organizationId
18
17
  };
19
18
  if (config.repo || config?.repositoryId) {
20
19
  body.repositoryId = config.repositoryId;
21
20
  body.type = 'REPOSITORY';
21
+ body.name = getProjectGroupNameRepo(config);
22
22
  }
23
23
  else {
24
24
  body.repositoryId = null;
25
25
  body.type = 'CLI';
26
+ body.name = getProjectGroupNameCLI(config);
26
27
  }
27
28
  return body;
28
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
+ };
29
39
  const registerNewProjectGroup = async (config) => {
30
40
  let body = await createNewProjectGroupBody(config);
31
41
  const client = await commonApi.getHttpClient(config);
32
- body.projects = createProjects([config]);
42
+ if (config.repositoryId) {
43
+ body.projects = [];
44
+ }
45
+ else {
46
+ body.projects = createProjectsArray([config]);
47
+ }
33
48
  let projectGroupInfo = await client
34
49
  .registerProjectGroup(config, body)
35
50
  .then(res => {
@@ -46,7 +61,7 @@ const registerNewProjectGroup = async (config) => {
46
61
  return res?.body?.projectGroupId;
47
62
  }
48
63
  if (res.statusCode === 409) {
49
- return [];
64
+ return '';
50
65
  }
51
66
  })
52
67
  .catch(err => {
@@ -55,53 +70,94 @@ const registerNewProjectGroup = async (config) => {
55
70
  });
56
71
  return projectGroupInfo;
57
72
  };
58
- const createProjects = params => {
73
+ const createProjectsArray = params => {
59
74
  let projectsArray = [];
60
75
  let projects = {};
61
76
  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: ''
70
- };
77
+ projects = createProject(param);
71
78
  projectsArray.push(projects);
72
79
  });
73
80
  return projectsArray;
74
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
+ };
75
93
  const getExistingGroupProjectId = (config, projectGroupsInfoEx) => {
76
94
  let existingGroupProjectId = '';
77
95
  projectGroupsInfoEx.forEach(i => {
78
- if (i.name === config.name) {
96
+ if (i.repositoryId === config.repositoryId) {
79
97
  existingGroupProjectId = i.projectGroupId;
80
98
  }
81
99
  });
82
100
  return existingGroupProjectId;
83
101
  };
84
102
  const getProjectIdFromArray = (config, array) => {
85
- let projectId = '';
86
- array?.forEach(i => {
87
- if (i.name === config.name) {
88
- projectId = i.projectId;
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;
89
110
  }
90
- });
91
- return projectId;
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;
92
123
  };
93
- const registerProjectIdOnCliServices = async (config, projectId) => {
124
+ const registerProjectIdOnCliServices = async (config, projectId, additionalData = undefined) => {
94
125
  const client = commonApi.getHttpClient(config);
95
126
  let cliServicesBody = {
96
127
  projectId: projectId,
97
- name: config.name
128
+ name: config.repo ? config.fileName : getProjectName(config)
98
129
  };
130
+ if (additionalData) {
131
+ addAdditionalData(cliServicesBody, additionalData);
132
+ }
99
133
  let result = await client
100
134
  .registerOnCliServices(config, cliServicesBody)
101
135
  .then(res => {
102
136
  if (config.debug || config.verbose) {
103
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');
104
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');
159
+ console.log(res.statusCode);
160
+ console.log(res.body);
105
161
  }
106
162
  if (res.statusCode === 201 || res.statusCode === 200) {
107
163
  return res.body;
@@ -113,7 +169,7 @@ const registerProjectIdOnCliServices = async (config, projectId) => {
113
169
  return result;
114
170
  };
115
171
  const retrieveExistingProjectIdWithProjectGroupId = async (config, client, projectGroupId) => {
116
- let groups = await client
172
+ return await client
117
173
  .retrieveExistingProjectIdByProjectGroupId(config, projectGroupId)
118
174
  .then(res => {
119
175
  if (config.debug || config.verbose) {
@@ -125,10 +181,9 @@ const retrieveExistingProjectIdWithProjectGroupId = async (config, client, proje
125
181
  return res.body;
126
182
  }
127
183
  else {
128
- return [];
184
+ return '';
129
185
  }
130
186
  });
131
- return getProjectIdFromArray(config, groups);
132
187
  };
133
188
  const retrieveProjectByOrganization = async (config, client) => {
134
189
  return await client.retrieveProjectByOrganizationId(config).then(res => {
@@ -145,16 +200,36 @@ const retrieveProjectByOrganization = async (config, client) => {
145
200
  }
146
201
  });
147
202
  };
148
- const retrieveExistingProjectGroups = async (config, client) => {
203
+ const retrieveExistingProjectGroups = async (config) => {
204
+ const client = commonApi.getHttpClient(config);
149
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
+ }
150
211
  if (res.statusCode === 201 || res.statusCode === 200) {
151
- return res.body;
212
+ let correctGroupID = res?.body?.filter(i => i.repositoryId === config.repositoryId);
213
+ if (correctGroupID.length > 0) {
214
+ return correctGroupID[0].projectGroupId;
215
+ }
216
+ return '';
152
217
  }
153
218
  else {
154
- return [];
219
+ return '';
155
220
  }
156
221
  });
157
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
+ };
158
233
  const dealWithNoName = async (config) => {
159
234
  try {
160
235
  config.name = getAppName(config.file);
@@ -170,5 +245,10 @@ module.exports = {
170
245
  registerProjectIdOnCliServices,
171
246
  dealWithNoName,
172
247
  registerNewProjectGroup,
173
- createNewProjectGroupBody
248
+ createNewProjectGroupBody,
249
+ registerProjectWithGroupProjectId,
250
+ getExistingGroupProjectId,
251
+ getProjectGroupId,
252
+ retrieveExistingProjectGroups,
253
+ createProject
174
254
  };
@@ -21,12 +21,16 @@ const retrieveRepoId = async (config) => {
21
21
  };
22
22
  const registerNewRepo = async (config) => {
23
23
  let body = {
24
- externalScmUrl: config.repoUrl ? config.repoUrl : '',
25
- externalScmName: config.repoName,
26
- externalId: config.externalId ? config.externalId : '',
24
+ externalScmUrl: config.repositoryUrl,
25
+ externalScmName: config.repositoryName,
26
+ externalId: config.externalId,
27
27
  primaryLanguage: config.language,
28
28
  defaultBranch: 'develop'
29
29
  };
30
+ if (config.debug || config.verbose) {
31
+ console.log('registerNewRepo');
32
+ console.log(body);
33
+ }
30
34
  const client = await commonApi.getHttpClient(config);
31
35
  let result = await client
32
36
  .registerRepo(config, body)
@@ -46,10 +50,43 @@ const registerNewRepo = async (config) => {
46
50
  if (res.statusCode === 409) {
47
51
  return '';
48
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
+ }
49
61
  })
50
62
  .catch(err => {
51
63
  console.log('\nError Registering Repository');
52
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);
53
90
  });
54
91
  return result;
55
92
  };
@@ -66,5 +103,6 @@ const getRepoId = async (config) => {
66
103
  module.exports = {
67
104
  retrieveRepoId,
68
105
  registerNewRepo,
69
- getRepoId
106
+ getRepoId,
107
+ retrieveProjectInfoViaRepoId
70
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, projectGroupId) {
273
+ HTTPClient.prototype.registerProject = function (config, body) {
273
274
  const options = _.cloneDeep(this.requestOptions);
274
- let url = registerProjectUrl(config, projectGroupId);
275
+ let url = registerProjectUrl(config);
275
276
  options.url = url;
276
- return requestUtils.sendRequest({ method: 'get', options });
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 ? '?incomplete=true' : ''}`;
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 ? optionalParams.push('incomplete=true') : null;
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 = (config, projectGroupId) => {
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}/repositories/external-url?externalRepoUrl=${config.repoUrl}`;
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 ? baseUrl.concat(`?name=${config.name}`) : baseUrl;
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 => {
@@ -512,6 +530,9 @@ const retrieveExistingRepoUrl = config => {
512
530
  function createRepositoryUrl(config) {
513
531
  return `${config.host}/api/v4/organizations/${config.organizationId}/repositories`;
514
532
  }
533
+ function createRepoProjectUrl(config) {
534
+ return `${config.host}/api/v4/organizations/${config.organizationId}/repositories/${config.repositoryId}/projects`;
535
+ }
515
536
  function createLibraryVulnerabilitiesUrl(config) {
516
537
  return `${config.host}/Contrast/api/ng/${config.organizationId}/libraries/artifactsByGroupNameVersion`;
517
538
  }
@@ -0,0 +1,74 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.buildBaseRequestOptions = exports.gotInstance = void 0;
7
+ const hpagent_1 = require("hpagent");
8
+ const fs_1 = __importDefault(require("fs"));
9
+ const got_1 = __importDefault(require("got"));
10
+ function gotInstance(config) {
11
+ return got_1.default.extend({ retry: { limit: 0 }, ...buildBaseRequestOptions(config) });
12
+ }
13
+ exports.gotInstance = gotInstance;
14
+ function buildBaseRequestOptions(config) {
15
+ const { apiKey, authorization } = config;
16
+ const rejectUnauthorized = !config.certSelfSigned;
17
+ const superApiKey = config.superApiKey;
18
+ const superAuthToken = config.superAuthorization;
19
+ const requestOptions = {
20
+ responseType: 'json',
21
+ forever: true,
22
+ uri: config.host,
23
+ followRedirect: false,
24
+ headers: {
25
+ 'Content-Type': 'application/json; charset=utf-8',
26
+ Authorization: authorization,
27
+ 'API-Key': apiKey,
28
+ SuperAuthorization: superAuthToken,
29
+ 'Super-API-Key': superApiKey,
30
+ 'User-Agent': 'contrast-cli-v2'
31
+ },
32
+ agent: getAgent(config)
33
+ };
34
+ requestOptions.https = {
35
+ rejectUnauthorized: rejectUnauthorized
36
+ };
37
+ maybeAddCertsToRequest(config, requestOptions.https);
38
+ return requestOptions;
39
+ }
40
+ exports.buildBaseRequestOptions = buildBaseRequestOptions;
41
+ function getAgent(config) {
42
+ return config.proxy
43
+ ? new hpagent_1.HttpsProxyAgent({ proxy: config.proxy })
44
+ : false;
45
+ }
46
+ function maybeAddCertsToRequest(config, https) {
47
+ const caCertFilePath = config.cacert;
48
+ if (caCertFilePath) {
49
+ try {
50
+ https.certificateAuthority = fs_1.default.readFileSync(caCertFilePath);
51
+ }
52
+ catch (error) {
53
+ throw new Error(`Unable to read CA from ${caCertFilePath}, msg: ${error.message}`);
54
+ }
55
+ }
56
+ const certPath = config.cert;
57
+ if (certPath) {
58
+ try {
59
+ https.certificate = fs_1.default.readFileSync(certPath);
60
+ }
61
+ catch (error) {
62
+ throw new Error(`Unable to read Certificate PEM file from config option contrast.api.certificate.cert_file='${certPath}', msg: ${error.message}`);
63
+ }
64
+ }
65
+ const keyPath = config.key;
66
+ if (keyPath) {
67
+ try {
68
+ https.key = fs_1.default.readFileSync(keyPath);
69
+ }
70
+ catch (error) {
71
+ throw new Error(`Unable to read Key PEM file from config option contrast.api.certificate.key_file='${keyPath}', msg: ${error.message}`);
72
+ }
73
+ }
74
+ }
@@ -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.1';
15
+ const APP_VERSION = '2.0.2-beta.0';
16
16
  const TIMEOUT = 120000;
17
17
  const HIGH_COLOUR = '#ff9900';
18
18
  const CRITICAL_COLOUR = '#e35858';
@@ -2,11 +2,18 @@
2
2
  const { getSeverityCounts, printNoVulnFoundMsg } = require('../../audit/report/commonReportingFunctions');
3
3
  const common = require('../../common/fail');
4
4
  const { printFormattedOutputSca } = require('./commonReportingFunctionsSca');
5
- const processAuditReport = (config, reportModelList) => {
5
+ const { auditSave } = require('../../audit/save');
6
+ const processAuditReport = async (config, reportModelList, reportId) => {
6
7
  let severityCounts = {};
7
8
  if (reportModelList !== undefined) {
8
9
  severityCounts = formatScaServicesReport(config, reportModelList);
9
10
  }
11
+ if (config.save !== undefined) {
12
+ await auditSave(config, reportId);
13
+ }
14
+ else {
15
+ console.log('Use contrast audit --save to generate an SBOM');
16
+ }
10
17
  if (config.fail) {
11
18
  common.processFail(config, severityCounts);
12
19
  }