@ibm-cloud/cd-tools 1.2.5 → 1.3.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/cmd/utils/requests.js +3 -4
- package/cmd/utils/terraform.js +18 -5
- package/cmd/utils/validate.js +26 -13
- package/package.json +1 -1
package/cmd/utils/requests.js
CHANGED
|
@@ -302,8 +302,8 @@ async function getGitOAuth(bearer, targetRegion, gitId) {
|
|
|
302
302
|
switch (response.status) {
|
|
303
303
|
case 200:
|
|
304
304
|
return response.data?.access_token;
|
|
305
|
-
case
|
|
306
|
-
throw Error(response.data?.authorizationURI);
|
|
305
|
+
case 401:
|
|
306
|
+
throw Error(response.data?.authorizationURI ?? 'Get git OAuth failed');
|
|
307
307
|
default:
|
|
308
308
|
throw Error('Get git OAuth failed');
|
|
309
309
|
}
|
|
@@ -332,14 +332,13 @@ async function getGritUserProject(privToken, region, user, projectName) {
|
|
|
332
332
|
}
|
|
333
333
|
|
|
334
334
|
async function getGritGroup(privToken, region, groupName) {
|
|
335
|
-
const url = `https://${region}.git.cloud.ibm.com/api/v4/groups`
|
|
335
|
+
const url = `https://${region}.git.cloud.ibm.com/api/v4/groups/${groupName}`
|
|
336
336
|
const options = {
|
|
337
337
|
url: url,
|
|
338
338
|
method: 'GET',
|
|
339
339
|
headers: {
|
|
340
340
|
'PRIVATE-TOKEN': privToken
|
|
341
341
|
},
|
|
342
|
-
params: { simple: true, search: groupName },
|
|
343
342
|
validateStatus: () => true
|
|
344
343
|
};
|
|
345
344
|
const response = await axios(options);
|
package/cmd/utils/terraform.js
CHANGED
|
@@ -146,6 +146,13 @@ async function setupTerraformFiles({ token, srcRegion, targetRegion, targetTag,
|
|
|
146
146
|
if (isCompact || resourceName === 'ibm_cd_toolchain_tool_hostedgit') {
|
|
147
147
|
if (newTfFileObj['resource']['ibm_cd_toolchain_tool_hostedgit']) {
|
|
148
148
|
for (const [k, v] of Object.entries(newTfFileObj['resource']['ibm_cd_toolchain_tool_hostedgit'])) {
|
|
149
|
+
try {
|
|
150
|
+
newTfFileObj['resource']['ibm_cd_toolchain_tool_hostedgit'][k]['parameters'][0]['auth_type'] = 'oauth';
|
|
151
|
+
delete newTfFileObj['resource']['ibm_cd_toolchain_tool_hostedgit'][k]['parameters'][0]['api_token'];
|
|
152
|
+
} catch {
|
|
153
|
+
// do nothing
|
|
154
|
+
}
|
|
155
|
+
|
|
149
156
|
try {
|
|
150
157
|
const thisUrl = v['initialization'][0]['repo_url'];
|
|
151
158
|
if (thisUrl in gritMapping) {
|
|
@@ -163,6 +170,10 @@ async function setupTerraformFiles({ token, srcRegion, targetRegion, targetTag,
|
|
|
163
170
|
} else {
|
|
164
171
|
// prompt user
|
|
165
172
|
const validateGritUrlPrompt = async (str) => {
|
|
173
|
+
if (!str) {
|
|
174
|
+
logger.print('Skipping... (URL will remain unchanged in the generatedTerraform configuration)');
|
|
175
|
+
return '';
|
|
176
|
+
}
|
|
166
177
|
const newUrl = `https://${targetRegion}.git.cloud.ibm.com/${str}.git`;
|
|
167
178
|
if (usedGritUrls.has(newUrl)) throw Error(`"${newUrl}" has already been used in another mapping entry`);
|
|
168
179
|
return validateGritUrl(token, targetRegion, str, false);
|
|
@@ -170,15 +181,17 @@ async function setupTerraformFiles({ token, srcRegion, targetRegion, targetTag,
|
|
|
170
181
|
|
|
171
182
|
if (!firstGritPrompt) {
|
|
172
183
|
firstGritPrompt = true;
|
|
173
|
-
logger.print('Please enter the new URLs for the following GRIT tool(s):\n');
|
|
184
|
+
logger.print('Please enter the new URLs for the following GRIT tool(s) (or submit empty input to skip):\n');
|
|
174
185
|
}
|
|
175
186
|
|
|
176
187
|
const newRepoSlug = await promptUserInput(`Old URL: ${thisUrl.slice(0, thisUrl.length - 4)}\nNew URL: https://${targetRegion}.git.cloud.ibm.com/`, '', validateGritUrlPrompt);
|
|
177
188
|
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
189
|
+
if (newRepoSlug) {
|
|
190
|
+
newUrl = `https://${targetRegion}.git.cloud.ibm.com/${newRepoSlug}.git`;
|
|
191
|
+
newTfFileObj['resource']['ibm_cd_toolchain_tool_hostedgit'][k]['initialization'][0]['repo_url'] = newUrl;
|
|
192
|
+
attemptAddUsedGritUrl(newUrl);
|
|
193
|
+
gritMapping[thisUrl] = newUrl;
|
|
194
|
+
}
|
|
182
195
|
}
|
|
183
196
|
}
|
|
184
197
|
catch (e) {
|
package/cmd/utils/validate.js
CHANGED
|
@@ -145,6 +145,7 @@ async function validateTools(token, tcId, region, skipPrompt) {
|
|
|
145
145
|
const nonConfiguredTools = [];
|
|
146
146
|
const toolsWithHashedParams = [];
|
|
147
147
|
const patTools = [];
|
|
148
|
+
const gheTools = [];
|
|
148
149
|
const classicPipelines = [];
|
|
149
150
|
|
|
150
151
|
for (const tool of allTools.tools) {
|
|
@@ -195,14 +196,24 @@ async function validateTools(token, tcId, region, skipPrompt) {
|
|
|
195
196
|
url: toolUrl
|
|
196
197
|
});
|
|
197
198
|
}
|
|
198
|
-
|
|
199
|
+
|
|
200
|
+
if (tool.tool_type_id === 'github_integrated') {
|
|
201
|
+
gheTools.push({
|
|
202
|
+
tool_name: toolName,
|
|
203
|
+
type: tool.tool_type_id,
|
|
204
|
+
url: toolUrl
|
|
205
|
+
});
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
if (tool.tool_type_id === 'pipeline' && tool.parameters?.type === 'classic') { // Check for Classic pipelines
|
|
199
209
|
classicPipelines.push({
|
|
200
210
|
tool_name: toolName,
|
|
201
211
|
type: 'classic pipeline',
|
|
202
212
|
url: toolUrl
|
|
203
213
|
});
|
|
204
214
|
}
|
|
205
|
-
|
|
215
|
+
|
|
216
|
+
if (['githubconsolidated', 'github_integrated', 'gitlab', 'hostedgit'].includes(tool.tool_type_id) && (tool.parameters?.auth_type === '' || tool.parameters?.auth_type === 'oauth')) { // Skip secret check iff it's GitHub/GitLab/GRIT integration with OAuth
|
|
206
217
|
continue;
|
|
207
218
|
}
|
|
208
219
|
else {
|
|
@@ -240,7 +251,7 @@ async function validateTools(token, tcId, region, skipPrompt) {
|
|
|
240
251
|
}
|
|
241
252
|
}
|
|
242
253
|
}
|
|
243
|
-
const hasInvalidConfig = nonConfiguredTools.length > 0 ||
|
|
254
|
+
const hasInvalidConfig = nonConfiguredTools.length > 0 || toolsWithHashedParams.length > 0;
|
|
244
255
|
|
|
245
256
|
if (classicPipelines.length > 0) {
|
|
246
257
|
logger.failSpinner('Unsupported tools found!');
|
|
@@ -257,10 +268,15 @@ async function validateTools(token, tcId, region, skipPrompt) {
|
|
|
257
268
|
}
|
|
258
269
|
|
|
259
270
|
if (patTools.length > 0) {
|
|
260
|
-
logger.warn('Warning! The following GRIT integration(s)
|
|
271
|
+
logger.warn('Warning! The following GRIT integration(s) with auth_type "pat" are unsupported during migration and will automatically be converted to auth_type "oauth": \n', LOG_STAGES.setup, true);
|
|
261
272
|
logger.table(patTools);
|
|
262
273
|
}
|
|
263
274
|
|
|
275
|
+
if (gheTools.length > 0) {
|
|
276
|
+
logger.warn('Warning! The following legacy GHE integration(s) are unsupported during migration will automatically be converted to equivalent GitHub integrations: \n', LOG_STAGES.setup, true);
|
|
277
|
+
logger.table(gheTools);
|
|
278
|
+
}
|
|
279
|
+
|
|
264
280
|
if (toolsWithHashedParams.length > 0) {
|
|
265
281
|
logger.warn('Warning! The following tools contain secrets that cannot be migrated, please use the \'check-secrets\' command to export the secrets: \n', LOG_STAGES.setup, true);
|
|
266
282
|
logger.table(toolsWithHashedParams);
|
|
@@ -353,12 +369,10 @@ async function validateOAuth(token, tools, targetRegion, skipPrompt) {
|
|
|
353
369
|
type: tool.tool_type_id + (isGHE ? ' (GHE)' : ''),
|
|
354
370
|
link: authorizeUrl?.message != 'Get git OAuth failed' ? 'See link below' : 'Get git OAuth failed',
|
|
355
371
|
})
|
|
356
|
-
if (
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
oauthLinks.push({ type: tool.tool_type_id, link: authorizeUrl?.message ?? 'Could not get OAuth link' });
|
|
361
|
-
}
|
|
372
|
+
if (isGHE) {
|
|
373
|
+
oauthLinks.push({ type: 'githubconsolidated (GHE)', link: authorizeUrl?.message });
|
|
374
|
+
} else {
|
|
375
|
+
oauthLinks.push({ type: tool.tool_type_id, link: authorizeUrl?.message });
|
|
362
376
|
}
|
|
363
377
|
}
|
|
364
378
|
}
|
|
@@ -376,7 +390,7 @@ async function validateOAuth(token, tools, targetRegion, skipPrompt) {
|
|
|
376
390
|
|
|
377
391
|
if (oauthLinks.length > 0) logger.print('Authorize using the following links:\n');
|
|
378
392
|
oauthLinks.forEach((o) => {
|
|
379
|
-
if (o.link === '
|
|
393
|
+
if (o.link === 'Get git OAuth failed') hasFailedLink = true;
|
|
380
394
|
logger.print(`${o.type}: \x1b[36m${o.link}\x1b[0m\n`);
|
|
381
395
|
});
|
|
382
396
|
|
|
@@ -447,8 +461,7 @@ async function validateGritUrl(token, region, url, validateFull) {
|
|
|
447
461
|
|
|
448
462
|
// try group
|
|
449
463
|
try {
|
|
450
|
-
|
|
451
|
-
await getGritGroupProject(accessToken, region, groupId, projectName);
|
|
464
|
+
await getGritGroupProject(accessToken, region, urlStart, projectName);
|
|
452
465
|
return trimmed;
|
|
453
466
|
} catch {
|
|
454
467
|
throw Error('Provided GRIT url not found');
|