@ibm-cloud/cd-tools 1.15.4 → 1.15.6
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/copy-toolchain.js
CHANGED
|
@@ -109,13 +109,6 @@ async function main(options) {
|
|
|
109
109
|
bearer = await getBearerToken(apiKey);
|
|
110
110
|
const accountId = await getAccountId(bearer, apiKey);
|
|
111
111
|
|
|
112
|
-
// check for continuous delivery instance in target region
|
|
113
|
-
if (!await getCdInstanceByRegion(bearer, accountId, targetRegion)) {
|
|
114
|
-
// give users the option to bypass
|
|
115
|
-
logger.warn(`Warning! Could not find a Continuous Delivery instance in the target region ${targetRegion} or you do not have permission to view, please create one before proceeding if one does not exist already.`, LOG_STAGES.setup);
|
|
116
|
-
await promptUserConfirmation(`Do you want to proceed anyway?`, 'yes', 'Toolchain migration cancelled.');
|
|
117
|
-
}
|
|
118
|
-
|
|
119
112
|
// check for existing .tf files in output directory
|
|
120
113
|
if (fs.existsSync(outputDir)) {
|
|
121
114
|
let files = fs.readdirSync(outputDir, { recursive: true });
|
|
@@ -164,8 +157,20 @@ async function main(options) {
|
|
|
164
157
|
exit(1);
|
|
165
158
|
}
|
|
166
159
|
|
|
160
|
+
// check for continuous delivery instance in target region and resource group
|
|
161
|
+
const cdInstances = await getCdInstanceByRegion(bearer, accountId, targetRegion);
|
|
162
|
+
const cdInstanceFound = cdInstances?.some((instance) => {
|
|
163
|
+
return instance.doc?.resource_group_id === sourceToolchainData['resource_group_id'];
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
if (!cdInstanceFound) {
|
|
167
|
+
// give users the option to bypass
|
|
168
|
+
logger.warn(`Warning! Could not find a Continuous Delivery instance in the target region ${targetRegion} and toolchain's resource group or you do not have permission to view, please create one before proceeding if one does not exist already.`, LOG_STAGES.setup);
|
|
169
|
+
await promptUserConfirmation(`Do you want to proceed anyway?`, 'yes', 'Toolchain migration cancelled.');
|
|
170
|
+
}
|
|
171
|
+
|
|
167
172
|
const resourceGroups = await getResourceGroups(bearer, accountId, [targetRg || sourceToolchainData['resource_group_id']]);
|
|
168
|
-
({ id: targetRgId, name: targetRgName } = resourceGroups[0])
|
|
173
|
+
({ id: targetRgId, name: targetRgName } = resourceGroups[0]);
|
|
169
174
|
// reuse name if not provided
|
|
170
175
|
if (!targetToolchainName) targetToolchainName = sourceToolchainData['name'];
|
|
171
176
|
[targetToolchainName, targetTag] = await warnDuplicateName(bearer, accountId, targetToolchainName, sourceRegion, targetRegion, targetRgId, targetRgName, targetTag, skipUserConfirmation);
|
|
@@ -253,8 +253,21 @@ export async function importTerraform(token, apiKey, region, toolchainId, toolch
|
|
|
253
253
|
newTfFileObj['resource'][key][k]['value'] = `\${${toolIdMap[propValue].type}.${toolIdMap[propValue].name}.tool_id}`;
|
|
254
254
|
} else if (propValue) {
|
|
255
255
|
// escape newlines, double quotes and backslashes
|
|
256
|
-
|
|
257
|
-
|
|
256
|
+
|
|
257
|
+
let newValue = propValue;
|
|
258
|
+
|
|
259
|
+
const START_INDICATOR = '${jsonencode(';
|
|
260
|
+
const END_INDICATOR = ')}';
|
|
261
|
+
|
|
262
|
+
if (propValue.startsWith(START_INDICATOR) && propValue.endsWith(END_INDICATOR)) {
|
|
263
|
+
// skip substitution for jsonencode case, don't want to mangle it
|
|
264
|
+
} else {
|
|
265
|
+
if (propValue.includes('\n')) logger.warn(`Warning! Multi-line values for pipeline and trigger properties are not yet supported in the provider, newlines will be replaced with '\\\\n': "${k}"`, LOG_STAGES.import, true);
|
|
266
|
+
|
|
267
|
+
// TODO: remove extra backslash in newline replacement once provider is updated
|
|
268
|
+
newValue = newValue.replace(/\\/g, '\\\\').replace(/\n/g, '\\\\n').replace(/\r/g, '\\\\r').replace(/"/g, '\\"');
|
|
269
|
+
}
|
|
270
|
+
newTfFileObj['resource'][key][k]['value'] = newValue;
|
|
258
271
|
}
|
|
259
272
|
}
|
|
260
273
|
|
package/cmd/utils/requests.js
CHANGED
|
@@ -180,7 +180,7 @@ async function getCdInstanceByRegion(bearer, accountId, region) {
|
|
|
180
180
|
const response = await axios(options);
|
|
181
181
|
switch (response.status) {
|
|
182
182
|
case 200:
|
|
183
|
-
return response.data.items.length > 0;
|
|
183
|
+
return response.data.items.length > 0 ? response.data.items : null;
|
|
184
184
|
default:
|
|
185
185
|
throw Error('Get CD instance failed');
|
|
186
186
|
}
|
package/cmd/utils/terraform.js
CHANGED
|
@@ -341,8 +341,16 @@ async function setupTerraformFiles(config) {
|
|
|
341
341
|
newTfFileObj['resource']['ibm_cd_tekton_pipeline_property'][k]['value'] = `\${ibm_cd_toolchain_tool_githubconsolidated.${thisTfName}.tool_id}`;
|
|
342
342
|
} else if (thisValue) {
|
|
343
343
|
// escape newlines, double quotes and backslashes
|
|
344
|
-
|
|
345
|
-
|
|
344
|
+
|
|
345
|
+
const START_INDICATOR = '${jsonencode(';
|
|
346
|
+
const END_INDICATOR = ')}';
|
|
347
|
+
|
|
348
|
+
if (thisValue.startsWith(START_INDICATOR) && thisValue.endsWith(END_INDICATOR)) {
|
|
349
|
+
// skip newline substitution for jsonencode case, don't want to mangle it
|
|
350
|
+
} else {
|
|
351
|
+
// TODO: remove extra backslash in newline replacement once provider is updated
|
|
352
|
+
newTfFileObj['resource']['ibm_cd_tekton_pipeline_property'][k]['value'] = thisValue.replace(/\\/g, '\\\\').replace(/\n/g, '\\\\n').replace(/\r/g, '\\\\r').replace(/"/g, '\\"');
|
|
353
|
+
}
|
|
346
354
|
}
|
|
347
355
|
}
|
|
348
356
|
catch {
|
|
@@ -363,8 +371,16 @@ async function setupTerraformFiles(config) {
|
|
|
363
371
|
newTfFileObj['resource']['ibm_cd_tekton_pipeline_trigger_property'][k]['value'] = `\${ibm_cd_toolchain_tool_githubconsolidated.${thisTfName}.tool_id}`;
|
|
364
372
|
} else if (thisValue) {
|
|
365
373
|
// escape newlines, double quotes and backslashes
|
|
366
|
-
|
|
367
|
-
|
|
374
|
+
|
|
375
|
+
const START_INDICATOR = '${jsonencode(';
|
|
376
|
+
const END_INDICATOR = ')}';
|
|
377
|
+
|
|
378
|
+
if (thisValue.startsWith(START_INDICATOR) && thisValue.endsWith(END_INDICATOR)) {
|
|
379
|
+
// skip newline substitution for jsonencode case, don't want to mangle it
|
|
380
|
+
} else {
|
|
381
|
+
// TODO: remove extra backslash in newline replacement once provider is updated
|
|
382
|
+
newTfFileObj['resource']['ibm_cd_tekton_pipeline_trigger_property'][k]['value'] = thisValue.replace(/\\/g, '\\\\').replace(/\n/g, '\\\\n').replace(/\r/g, '\\\\r').replace(/"/g, '\\"');
|
|
383
|
+
}
|
|
368
384
|
}
|
|
369
385
|
}
|
|
370
386
|
catch {
|
package/package.json
CHANGED
|
@@ -168,7 +168,30 @@ describe('copy-toolchain: Test functionalities', function () {
|
|
|
168
168
|
'Only \'yes\' will be accepted to proceed. (Ctrl-C to abort)': 'yes'
|
|
169
169
|
},
|
|
170
170
|
}
|
|
171
|
-
}
|
|
171
|
+
},
|
|
172
|
+
{
|
|
173
|
+
name: 'Handles special characters in names',
|
|
174
|
+
cmd: [CLI_PATH, COMMAND, '-c', TEST_TOOLCHAINS['special-chars'].crn, '-r', TEST_TOOLCHAINS['special-chars'].region, '-D', '-f'],
|
|
175
|
+
expected: null,
|
|
176
|
+
options: {
|
|
177
|
+
timeout: 100000,
|
|
178
|
+
cwd: TEMP_DIR + '/' + 'special-chars'
|
|
179
|
+
},
|
|
180
|
+
assertionFunc: () => {
|
|
181
|
+
assert.isTrue(
|
|
182
|
+
areFilesInDir(TEMP_DIR + '/' + 'special-chars', [
|
|
183
|
+
'cd_tekton_pipeline.tf',
|
|
184
|
+
'cd_tekton_pipeline_definition.tf',
|
|
185
|
+
'cd_tekton_pipeline_property.tf',
|
|
186
|
+
'cd_tekton_pipeline_trigger.tf',
|
|
187
|
+
'cd_tekton_pipeline_trigger_property.tf',
|
|
188
|
+
'cd_toolchain.tf',
|
|
189
|
+
'cd_toolchain_tool_hostedgit.tf',
|
|
190
|
+
'cd_toolchain_tool_pipeline.tf',
|
|
191
|
+
])
|
|
192
|
+
);
|
|
193
|
+
}
|
|
194
|
+
},
|
|
172
195
|
];
|
|
173
196
|
|
|
174
197
|
for (const { name, cmd, expected, options, assertionFunc } of testCases) {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Licensed Materials - Property of IBM
|
|
3
|
-
* (c) Copyright IBM Corporation 2025. All Rights Reserved.
|
|
3
|
+
* (c) Copyright IBM Corporation 2025, 2026. All Rights Reserved.
|
|
4
4
|
*
|
|
5
5
|
* Note to U.S. Government Users Restricted Rights:
|
|
6
6
|
* Use, duplication or disclosure restricted by GSA ADP Schedule
|
|
@@ -52,6 +52,11 @@ export const TEST_TOOLCHAINS = {
|
|
|
52
52
|
name: 'KEEP-SINGLE-PIPELINE-TOOLCHAIN',
|
|
53
53
|
crn: 'crn:v1:bluemix:public:toolchain:us-east:a/9e8559fac61ee9fc74d3e595fa75d147:5ef88780-1e0f-4cda-94c7-f78909cc1140::',
|
|
54
54
|
region: 'us-east'
|
|
55
|
+
},
|
|
56
|
+
'special-chars': {
|
|
57
|
+
name: 'KEEP-SPECIAL-CHARS-_ .TOOLCHAIN',
|
|
58
|
+
crn: 'crn:v1:bluemix:public:toolchain:ca-tor:a/9e8559fac61ee9fc74d3e595fa75d147:bda05ed4-7092-4c7c-970a-7be53f1c1796::',
|
|
59
|
+
region: 'ca-tor'
|
|
55
60
|
}
|
|
56
61
|
};
|
|
57
62
|
|