@contrast/contrast 1.0.22 → 2.0.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 (77) hide show
  1. package/README.md +21 -138
  2. package/dist/audit/languageAnalysisEngine/sendSnapshot.js +2 -19
  3. package/dist/audit/report/commonReportingFunctions.js +1 -1
  4. package/dist/audit/save.js +16 -5
  5. package/dist/cliConstants.js +29 -0
  6. package/dist/commands/audit/auditController.js +2 -1
  7. package/dist/commands/audit/help.js +3 -3
  8. package/dist/commands/audit/processAudit.js +3 -1
  9. package/dist/commands/audit/saveFile.js +5 -1
  10. package/dist/commands/github/projectGroup.js +164 -0
  11. package/dist/common/HTTPClient.js +165 -13
  12. package/dist/constants/constants.js +3 -5
  13. package/dist/constants/locales.js +7 -3
  14. package/dist/index.js +0 -4
  15. package/dist/lambda/lambda.js +3 -1
  16. package/dist/sbom/generateSbom.js +7 -0
  17. package/dist/scaAnalysis/common/commonReportingFunctionsSca.js +6 -6
  18. package/dist/scaAnalysis/common/scaServicesUpload.js +77 -7
  19. package/dist/scaAnalysis/common/treeUpload.js +1 -1
  20. package/dist/scaAnalysis/go/goAnalysis.js +1 -1
  21. package/dist/scaAnalysis/java/analysis.js +24 -32
  22. package/dist/scaAnalysis/java/index.js +1 -1
  23. package/dist/scaAnalysis/javascript/index.js +3 -3
  24. package/dist/scaAnalysis/legacy/legacyFlow.js +33 -0
  25. package/dist/scaAnalysis/php/index.js +1 -1
  26. package/dist/scaAnalysis/processServicesFlow.js +21 -0
  27. package/dist/scaAnalysis/python/analysis.js +1 -1
  28. package/dist/scaAnalysis/python/index.js +1 -1
  29. package/dist/scaAnalysis/repoMode/index.js +2 -2
  30. package/dist/scaAnalysis/ruby/analysis.js +1 -1
  31. package/dist/scaAnalysis/ruby/index.js +1 -1
  32. package/dist/scaAnalysis/scaAnalysis.js +16 -36
  33. package/dist/scan/autoDetection.js +41 -2
  34. package/dist/scan/fileUtils.js +5 -4
  35. package/dist/utils/commonApi.js +26 -1
  36. package/dist/utils/settingsHelper.js +7 -17
  37. package/package.json +6 -6
  38. package/src/audit/languageAnalysisEngine/sendSnapshot.js +3 -22
  39. package/src/audit/report/commonReportingFunctions.js +1 -1
  40. package/src/audit/save.js +21 -10
  41. package/src/cliConstants.js +32 -0
  42. package/src/commands/audit/auditController.js +2 -1
  43. package/src/commands/audit/help.js +3 -3
  44. package/src/commands/audit/processAudit.js +4 -5
  45. package/src/commands/audit/saveFile.js +6 -1
  46. package/src/commands/github/projectGroup.js +187 -0
  47. package/src/common/HTTPClient.js +221 -13
  48. package/src/constants/constants.js +3 -5
  49. package/src/constants/locales.js +9 -3
  50. package/src/index.ts +0 -5
  51. package/src/lambda/lambda.ts +3 -1
  52. package/src/lambda/lambdaUtils.ts +1 -1
  53. package/src/sbom/generateSbom.ts +8 -0
  54. package/src/scaAnalysis/common/commonReportingFunctionsSca.js +6 -6
  55. package/src/scaAnalysis/common/scaServicesUpload.js +92 -7
  56. package/src/scaAnalysis/common/treeUpload.js +1 -1
  57. package/src/scaAnalysis/go/goAnalysis.js +1 -1
  58. package/src/scaAnalysis/java/analysis.js +29 -34
  59. package/src/scaAnalysis/java/index.js +1 -1
  60. package/src/scaAnalysis/javascript/index.js +3 -6
  61. package/src/scaAnalysis/legacy/legacyFlow.js +48 -0
  62. package/src/scaAnalysis/php/index.js +1 -1
  63. package/src/scaAnalysis/processServicesFlow.js +29 -0
  64. package/src/scaAnalysis/python/analysis.js +1 -1
  65. package/src/scaAnalysis/python/index.js +1 -1
  66. package/src/scaAnalysis/repoMode/index.js +2 -2
  67. package/src/scaAnalysis/ruby/analysis.js +1 -1
  68. package/src/scaAnalysis/ruby/index.js +1 -1
  69. package/src/scaAnalysis/scaAnalysis.js +21 -57
  70. package/src/scan/autoDetection.js +44 -3
  71. package/src/scan/fileUtils.js +5 -4
  72. package/src/utils/commonApi.js +29 -1
  73. package/src/utils/settingsHelper.js +8 -18
  74. package/dist/commands/fingerprint/processFingerprint.js +0 -14
  75. package/src/commands/fingerprint/processFingerprint.js +0 -21
  76. /package/dist/commands/{fingerprint → github}/fingerprintConfig.js +0 -0
  77. /package/src/commands/{fingerprint → github}/fingerprintConfig.js +0 -0
package/README.md CHANGED
@@ -1,152 +1,35 @@
1
- # CodeSec by Contrast Security
1
+ # Contrast CLI
2
2
 
3
- CodeSec delivers:
3
+ Use the ‘contrast’ command for fast and accurate security analysis of your applications, APIs, serverless functions, and libraries.
4
4
 
5
- - The fastest and most accurate SAST scanner.
6
- - Immediate and actionable results — scan code and serverless environments.
7
- - A frictionless and seamless sign-in process with GitHub or Google Account. From start to finish in minutes.
8
- - By running a scan on your lambda functions, you can find: Least privilege identity and access management (IAM) vulnerabilities (over permissive policies) and remediation.
5
+ ## Supported
9
6
 
10
- ## Install
7
+ <p><b>Code</b>: Java, .NET, .NET Core, JavaScript</p>
8
+ <p><b>Serverless</b>: AWS Lambda - Java, Python</p>
9
+ <p><b>Libraries</b>: Java, .NET, Node, Ruby, Python, Go, PHP</p>
11
10
 
12
- ```shell
13
- npm install --location=global @contrast/contrast
14
- ```
15
-
16
- ## Authenticate
17
-
18
- Authenticate by entering contrast auth in the terminal.
19
-
20
- In the resulting browser window, log in and authenticate with your GitHub or Google credentials.
21
-
22
- ## Run a scan
23
-
24
- ### SAST scan
11
+ ## What can I do?
25
12
 
26
- #### Scan Requirements
13
+ <p><code>contrast audit</code> to run a security audit of your dependencies and see results.</p>
14
+ <p><code>contrast scan</code> to run Contrast's industry leading SAST scanner and see results.</p>
15
+ <p><code>contrast lambda</code> to secure your AWS serverless functions.</p>
16
+ <p><code>contrast learn</code> launches Contrast's Secure Code Learning Hub.</p>
17
+ <p><code>contrast help</code> for full list of commands, options & support.</p>
27
18
 
28
- Make sure you have the correct file types to scan.
19
+ ### New CodeSec user?
29
20
 
30
- - Upload a .jar or .war file to scan a Java project for analysis
31
- - Upload a .js or .zip file to scan a JavaScript project for analysis
32
- - Upload a .exe. or .zip file to scan a .NET c# web forms project
33
-
34
- Start scanning
35
-
36
- Use the Contrast scan command `contrast scan`
37
-
38
- ### Lambda function scan
39
-
40
- #### Lambda Requirements
41
-
42
- - Currently supports Java and Python functions on AWS.
43
- Configure AWS credentials on your local environment by running the commands with your credentials:
21
+ Get going:
44
22
 
45
23
  ```shell
46
- export AWS_DEFAULT_REGION=<YOUR_AWS_REGION>
47
- export AWS_ACCESS_KEY_ID=<YOUR_ACCESS_KEY_ID>
48
- export AWS_SECRET_ACCESS_KEY=<YOUR_SECRET_ACCESS_KEY>
24
+ npm install --location=global @contrast/contrast@1
49
25
  ```
50
26
 
51
- - AWS credentials should be available on your local configure (usually **~/.aws/credentials**). You have an option to run a lambda scan with your aws-profile to pass --profile. You also can export different credentials.
52
-
53
- - These permissions are required to gather all required information on an AWS Lambda to use the `contrast lambda` command:
54
-
55
- - Lambda: [GetFunction](https://docs.aws.amazon.com/lambda/latest/dg/API_GetFunction.html) | [GetLayerVersion](https://docs.aws.amazon.com/lambda/latest/dg/API_GetLayerVersion.html) | [ListFunctions](https://docs.aws.amazon.com/lambda/latest/dg/API_ListFunctions.html)
56
- - IAM: [GetRolePolicy](https://docs.aws.amazon.com/IAM/latest/APIReference/API_GetRolePolicy.html) | [GetPolicy](https://docs.aws.amazon.com/IAM/latest/APIReference/API_GetPolicy.html) | [GetPolicyVersion](https://docs.aws.amazon.com/IAM/latest/APIReference/API_GetPolicyVersion.html) | [ListRolePolicies](https://docs.aws.amazon.com/IAM/latest/APIReference/API_ListRolePolicies.html) | [ListAttachedRolePolicies](https://docs.aws.amazon.com/IAM/latest/APIReference/API_ListAttachedRolePolicies.html)
57
-
58
- ### Start scanning
59
-
60
- Use contrast lambda to scan your AWS Lambda functions.
61
- `contrast lambda --function-name MyFunctionName --region my-aws-region`
62
-
63
- ## Contrast commands
64
-
65
- ### auth
66
-
67
- Authenticate Contrast using your GitHub or Google account. A new browser window will open for login.
68
-
69
- **Usage:** `contrast auth`
70
-
71
- ### config
72
-
73
- Displays stored credentials.
74
-
75
- **Usage:** `contrast config`
76
-
77
- **Options:**
78
-
79
- - **-c, --clear** - Removes stored credentials.
27
+ <p>Read more: https://www.contrastsecurity.com/developer/codesec</p>
80
28
 
81
- ### scan
29
+ ### Contrast existing Enterprise user?
82
30
 
83
- Performs a security SAST scan.
84
-
85
- **Usage:** `contrast scan [option]`
86
-
87
- **Options:**
88
-
89
- - **contrast scan --file**
90
-
91
- - Path of the file you want to scan. Contrast searches for a .jar, .war, .js. or .zip file in the working directory if a file is not specified.
92
- - Alias: **--f**
93
-
94
- - **contrast scan --name**
95
-
96
- - Contrast project name. If not specified, Contrast uses contrast.settings to identify the project or creates a project.
97
- - Alias: **–n**
98
-
99
- - **contrast scan --save**
100
-
101
- - Download the results to a Static Analysis Results Interchange Format (SARIF) file. The file is downloaded to the current working directory with a default name of results.sarif. You can view the file with any text editor.
102
- - Alias: **-s**
103
-
104
- - **contrast scan --timeout**
105
- - Time in seconds to wait for the scan to complete. Default value is 300 seconds.
106
- - Alias: **-t**
107
-
108
- ### lambda
109
-
110
- Name of AWS lambda function to scan.
111
-
112
- **Usage:** `contrast lambda --function-name`
113
-
114
- **Options:**
115
-
116
- - **contrast lambda --list-functions**
117
- Lists all available lambda functions to scan.
118
-
119
- - **contrast lambda --function-name --endpoint-url**
120
- AWS Endpoint override. Similar to AWS CLI.
121
- Alias: **-e**
122
-
123
- - **contrast lambda --function-name --region**
124
- Region override. Defaults to AWS_DEFAULT_REGION. Similar to AWS CLI.
125
- Alias: **-r**
126
-
127
- - **contrast lambda --function-name --profile**
128
- AWS configuration profile override. Similar to AWS CLI.
129
- Alias: **-p**
130
-
131
- - **contrast lambda --function-name --json**
132
- Return response in JSON (versus default human-readable format).
133
- Alias: **-j**
134
-
135
- - **contrast lambda -–function-name -–verbose**
136
- Returns extended information to the terminal.
137
- Alias: **-v**
138
-
139
- - **contrast lambda --function-name -–help**
140
- Displays usage guide.
141
- Alias: **-h**
142
-
143
- ### help
144
-
145
- Displays usage guide. To list detailed help for any CLI command, add the -h or --help flag to the command.
146
- **Usage:** `contrast scan --help`
147
- Alias: **-h**
148
-
149
- ### version
31
+ ```shell
32
+ npm install --location=global @contrast/contrast@2
33
+ ```
150
34
 
151
- Displays version of Contrast CLI.
152
- **Usage:** `contrast version` Alias: **-v**, **--version**
35
+ Read more: https://docs.contrastsecurity.com/en/install-contrast-cli.html
@@ -17,21 +17,10 @@ const pollSnapshotResults = async (config, snapshotId, client) => {
17
17
  console.log(err);
18
18
  });
19
19
  };
20
- const getTimeout = config => {
21
- if (config.timeout) {
22
- return config.timeout;
23
- }
24
- else {
25
- if (config.verbose) {
26
- console.log('Timeout set to 5 minutes');
27
- }
28
- return 300;
29
- }
30
- };
31
20
  const pollForSnapshotCompletion = async (config, snapshotId, reportSpinner) => {
32
21
  const client = commonApi.getHttpClient(config);
33
22
  const startTime = performance.now();
34
- const timeout = getTimeout(config);
23
+ const timeout = commonApi.getTimeout(config);
35
24
  let complete = false;
36
25
  if (!_.isNil(snapshotId)) {
37
26
  while (!complete) {
@@ -52,13 +41,7 @@ const pollForSnapshotCompletion = async (config, snapshotId, reportSpinner) => {
52
41
  process.exit(1);
53
42
  }
54
43
  }
55
- const endTime = performance.now() - startTime;
56
- if (requestUtils.millisToSeconds(endTime) > timeout) {
57
- oraFunctions.failSpinner(reportSpinner, 'Contrast audit timed out at the specified timeout of ' +
58
- timeout +
59
- ' seconds.');
60
- throw new Error('You can update the timeout using --timeout');
61
- }
44
+ commonApi.handleTimeout(startTime, timeout, reportSpinner);
62
45
  }
63
46
  }
64
47
  };
@@ -122,7 +122,7 @@ function buildHeader(highestSeverity, contrastHeaderNum, libraryName, version, n
122
122
  function buildBody(cveArray, advice) {
123
123
  const orderedCvesWithSeverityAssigned = orderByHighestPriority(cveArray.map(cve => findCVESeverity(cve)));
124
124
  const issueMessage = getIssueRow(orderedCvesWithSeverityAssigned);
125
- const minOrMax = advice.maximum ? advice.maximum : advice.minimum;
125
+ const minOrMax = advice.minimum ? advice.minimum : advice.maximum;
126
126
  const displayAdvice = minOrMax
127
127
  ? `Change to version ${chalk.bold(minOrMax)}`
128
128
  : 'No recommendation is available according to our data. Upgrade to the latest stable is the best advice we can give.';
@@ -7,6 +7,7 @@ const sbom = require('../sbom/generateSbom');
7
7
  const { SBOM_CYCLONE_DX_FILE, SBOM_SPDX_FILE } = require('../constants/constants');
8
8
  async function auditSave(config, reportId) {
9
9
  let fileFormat;
10
+ config.save = config.save ? config.save.toUpperCase() : config.save;
10
11
  switch (config.save) {
11
12
  case null:
12
13
  case SBOM_CYCLONE_DX_FILE:
@@ -19,18 +20,28 @@ async function auditSave(config, reportId) {
19
20
  break;
20
21
  }
21
22
  if (fileFormat) {
22
- if (config.experimental) {
23
- save.saveFile(config, fileFormat, await sbom.generateSCASbom(config, fileFormat, reportId));
23
+ if (config.legacy === false) {
24
+ const sbomResponse = await sbom.generateSCASbom(config, fileFormat, reportId);
25
+ if (sbomResponse) {
26
+ save.saveFile(config, fileFormat, sbomResponse);
27
+ }
24
28
  }
25
29
  else {
26
- save.saveFile(config, fileFormat, await sbom.generateSbom(config, fileFormat));
30
+ const sbomResponse = await sbom.generateSbom(config, fileFormat);
31
+ if (sbomResponse) {
32
+ save.saveFile(config, fileFormat, sbomResponse);
33
+ }
27
34
  }
28
- const filename = `${config.applicationId}-sbom-${fileFormat}.json`;
35
+ let fileStart = config.legacy ? config.applicationId : config.projectId;
36
+ if (fileStart === undefined) {
37
+ fileStart = 'my';
38
+ }
39
+ const filename = `${fileStart}-sbom-${fileFormat}.json`;
29
40
  if (fs.existsSync(filename)) {
30
41
  console.log(i18n.__('auditSBOMSaveSuccess') + ` - ${filename}`);
31
42
  }
32
43
  else {
33
- console.log(chalk.yellow.bold(`\n Unable to save ${filename} Software Bill of Materials (SBOM)`));
44
+ console.log(chalk.yellow.bold(`\nUnable to save ${filename} Software Bill of Materials (SBOM)`));
34
45
  }
35
46
  }
36
47
  else {
@@ -224,6 +224,13 @@ const auditAdvancedOptionDefinitionsForHelp = [
224
224
  '}: ' +
225
225
  i18n.__('constantsApplicationName')
226
226
  },
227
+ {
228
+ name: 'name',
229
+ description: '{bold ' +
230
+ i18n.__('constantsOptional') +
231
+ '}: ' +
232
+ i18n.__('constantsProjectName')
233
+ },
227
234
  {
228
235
  name: 'app-groups',
229
236
  description: '{bold ' +
@@ -353,6 +360,23 @@ const auditOptionDefinitions = [
353
360
  i18n.__('constantsOptional') +
354
361
  '}:' +
355
362
  i18n.__('auditOptionsBranchSummary')
363
+ },
364
+ {
365
+ name: 'legacy',
366
+ alias: 'l',
367
+ type: Boolean,
368
+ description: '{bold ' +
369
+ i18n.__('constantsOptional') +
370
+ '}:' +
371
+ i18n.__('auditOptionsLegacySummary')
372
+ },
373
+ {
374
+ name: 'repo',
375
+ type: Boolean,
376
+ description: '{bold ' +
377
+ i18n.__('constantsOptional') +
378
+ '}:' +
379
+ i18n.__('auditOptionsRepoSummary')
356
380
  }
357
381
  ];
358
382
  const fingerprintOptionDefinitions = [
@@ -361,6 +385,11 @@ const fingerprintOptionDefinitions = [
361
385
  name: 'depth',
362
386
  type: Number,
363
387
  description: '{bold ' + i18n.__('constantsOptional') + '}: ' + i18n.__('depthOption')
388
+ },
389
+ {
390
+ name: 'repoUrl',
391
+ type: String,
392
+ description: ''
364
393
  }
365
394
  ];
366
395
  const mainUsageGuide = commandLineUsage([
@@ -39,5 +39,6 @@ const removeLastChar = str => {
39
39
  return str.substring(0, str.length - 1);
40
40
  };
41
41
  module.exports = {
42
- dealWithNoAppId
42
+ dealWithNoAppId,
43
+ getAppName
43
44
  };
@@ -51,12 +51,12 @@ const auditUsageGuide = commandLineUsage([
51
51
  'code',
52
52
  'maven-settings-path',
53
53
  'language',
54
- 'experimental',
55
54
  'app-groups',
56
55
  'metadata',
57
- 'track',
58
56
  'fingerprint',
59
- 'branch'
57
+ 'branch',
58
+ 'repo',
59
+ 'name'
60
60
  ]
61
61
  },
62
62
  {
@@ -4,12 +4,14 @@ 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');
7
8
  const processAudit = async (contrastConf, argvMain) => {
8
9
  if (argvMain.indexOf('--help') !== -1) {
9
10
  printHelpMessage();
10
11
  process.exit(0);
11
12
  }
12
- const config = await auditConfig.getAuditConfig(contrastConf, 'audit', argvMain);
13
+ let config = await auditConfig.getAuditConfig(contrastConf, 'audit', argvMain);
14
+ config = await settingsHelper.getSettings(config);
13
15
  await scaController.processSca(config);
14
16
  if (!config.fingerprint) {
15
17
  postRunMessage('audit');
@@ -1,7 +1,11 @@
1
1
  "use strict";
2
2
  const fs = require('fs');
3
3
  const saveFile = (config, type, rawResults) => {
4
- const fileName = `${config.applicationId}-sbom-${type}.json`;
4
+ let fileStart = config.legacy ? config.applicationId : config.projectId;
5
+ if (fileStart === undefined) {
6
+ fileStart = 'my';
7
+ }
8
+ const fileName = `${fileStart}-sbom-${type}.json`;
5
9
  fs.writeFileSync(fileName, JSON.stringify(rawResults));
6
10
  };
7
11
  module.exports = {
@@ -0,0 +1,164 @@
1
+ "use strict";
2
+ const commonApi = require('../../utils/commonApi');
3
+ const { getAppName } = require('../audit/auditController');
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
+ let projectByOrg = await retrieveProjectByOrganization(config, client);
9
+ if (projectByOrg?.length > 0) {
10
+ projectId = getProjectIdFromArray(config, projectByOrg);
11
+ }
12
+ return projectId;
13
+ };
14
+ const registerNewProjectGroup = async (config) => {
15
+ let projectId = '';
16
+ let body = {
17
+ organizationId: config.organizationId,
18
+ name: config.name ? config.name : config.file,
19
+ repositoryId: null,
20
+ type: 'CLI'
21
+ };
22
+ const client = await commonApi.getHttpClient(config);
23
+ body.projects = createProjects([config]);
24
+ let projectGroupInfo = await client
25
+ .registerProjectGroup(config, body)
26
+ .then(res => {
27
+ if (config.debug || config.verbose) {
28
+ console.log('\nRegister ProjectGroup');
29
+ console.log(res.statusCode);
30
+ console.log(res.body);
31
+ }
32
+ if (res.statusCode === 201 || res.statusCode === 200) {
33
+ if (config.debug || config.verbose) {
34
+ console.log('registerProjectGroup - response');
35
+ console.log('response', res.body);
36
+ }
37
+ return res?.body?.projectGroupId;
38
+ }
39
+ if (res.statusCode === 409) {
40
+ return [];
41
+ }
42
+ })
43
+ .catch(err => {
44
+ console.log('\nError Registering Project Group');
45
+ console.log(err.statusCode);
46
+ });
47
+ return projectGroupInfo;
48
+ };
49
+ const createProjects = params => {
50
+ let projectsArray = [];
51
+ let projects = {};
52
+ 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
+ };
62
+ projectsArray.push(projects);
63
+ });
64
+ return projectsArray;
65
+ };
66
+ const getExistingGroupProjectId = (config, projectGroupsInfoEx) => {
67
+ let existingGroupProjectId = '';
68
+ projectGroupsInfoEx.forEach(i => {
69
+ if (i.name === config.name) {
70
+ existingGroupProjectId = i.projectGroupId;
71
+ }
72
+ });
73
+ return existingGroupProjectId;
74
+ };
75
+ const getProjectIdFromArray = (config, array) => {
76
+ let projectId = '';
77
+ array?.forEach(i => {
78
+ if (i.name === config.name) {
79
+ projectId = i.projectId;
80
+ }
81
+ });
82
+ return projectId;
83
+ };
84
+ const registerProjectIdOnCliServices = async (config, projectId) => {
85
+ const client = commonApi.getHttpClient(config);
86
+ let cliServicesBody = {
87
+ projectId: projectId,
88
+ name: config.name
89
+ };
90
+ let result = await client
91
+ .registerOnCliServices(config, cliServicesBody)
92
+ .then(res => {
93
+ if (config.debug || config.verbose) {
94
+ console.log('\nregistration on cli services');
95
+ console.log(res.statusCode);
96
+ }
97
+ if (res.statusCode === 201 || res.statusCode === 200) {
98
+ return res.body;
99
+ }
100
+ else {
101
+ return [];
102
+ }
103
+ });
104
+ return result;
105
+ };
106
+ const retrieveExistingProjectIdWithProjectGroupId = async (config, client, projectGroupId) => {
107
+ let groups = await client
108
+ .retrieveExistingProjectIdByProjectGroupId(config, projectGroupId)
109
+ .then(res => {
110
+ if (config.debug || config.verbose) {
111
+ console.log('\nRetrieve Existing ProjectId By ProjectGroupId');
112
+ console.log(res.statusCode);
113
+ console.log(res.body);
114
+ }
115
+ if (res.statusCode === 200) {
116
+ return res.body;
117
+ }
118
+ else {
119
+ return [];
120
+ }
121
+ });
122
+ return getProjectIdFromArray(config, groups);
123
+ };
124
+ const retrieveProjectByOrganization = async (config, client) => {
125
+ return await client.retrieveProjectByOrganizationId(config).then(res => {
126
+ if (config.debug || config.verbose) {
127
+ console.log('\nRetrieve Project By OrganizationId');
128
+ console.log(res.statusCode);
129
+ console.log(res.body);
130
+ }
131
+ if (res.statusCode === 201 || res.statusCode === 200) {
132
+ return res.body;
133
+ }
134
+ else {
135
+ return [];
136
+ }
137
+ });
138
+ };
139
+ const retrieveExistingProjectGroups = async (config, client) => {
140
+ return await client.retrieveExistingProjectGroupsByOrg(config).then(res => {
141
+ if (res.statusCode === 201 || res.statusCode === 200) {
142
+ return res.body;
143
+ }
144
+ else {
145
+ return [];
146
+ }
147
+ });
148
+ };
149
+ const dealWithNoName = async (config) => {
150
+ try {
151
+ config.name = getAppName(config.file);
152
+ }
153
+ catch (e) {
154
+ console.log(e.message.toString());
155
+ process.exit(1);
156
+ }
157
+ return config;
158
+ };
159
+ module.exports = {
160
+ getProjectIdByOrg,
161
+ registerProjectIdOnCliServices,
162
+ dealWithNoName,
163
+ registerNewProjectGroup
164
+ };