@ibm-cloud/cd-tools 1.6.0 → 1.6.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.
- package/cmd/copy-toolchain.js +1 -4
- package/cmd/utils/terraform.js +2 -1
- package/create-s2s-script.js +14 -5
- package/package.json +1 -1
- package/test/copy-toolchain/functionalities.test.js +13 -13
- package/test/copy-toolchain/input-validation.test.js +5 -2
- package/test/copy-toolchain/tf-import.test.js +2 -3
- package/test/copy-toolchain/tool-validation.test.js +0 -1
package/cmd/copy-toolchain.js
CHANGED
|
@@ -322,10 +322,7 @@ async function main(options) {
|
|
|
322
322
|
}
|
|
323
323
|
|
|
324
324
|
// create toolchain, which invokes script to create s2s if applicable
|
|
325
|
-
await runTerraformApply(true, outputDir, verbosity, `ibm_cd_toolchain.${toolchainTfName}`)
|
|
326
|
-
logger.error(err, LOG_STAGES.tf);
|
|
327
|
-
applyErrors = true;
|
|
328
|
-
});
|
|
325
|
+
await runTerraformApply(true, outputDir, verbosity, `ibm_cd_toolchain.${toolchainTfName}`);
|
|
329
326
|
|
|
330
327
|
// create the rest
|
|
331
328
|
await runTerraformApply(skipUserConfirmation, outputDir, verbosity).catch((err) => {
|
package/cmd/utils/terraform.js
CHANGED
|
@@ -192,7 +192,7 @@ async function setupTerraformFiles({ token, srcRegion, targetRegion, targetTag,
|
|
|
192
192
|
// prompt user
|
|
193
193
|
const validateGritUrlPrompt = async (str) => {
|
|
194
194
|
if (!str) {
|
|
195
|
-
logger.print('Skipping... (URL will remain unchanged in the
|
|
195
|
+
logger.print('Skipping... (URL will remain unchanged in the generated Terraform configuration)');
|
|
196
196
|
return '';
|
|
197
197
|
}
|
|
198
198
|
const newUrl = (GIT_BASE_URL || `https://${targetRegion}.git.cloud.ibm.com`) + `/${str}.git`;
|
|
@@ -492,6 +492,7 @@ function replaceDependsOn(str) {
|
|
|
492
492
|
function addS2sScriptToToolchainTf(str) {
|
|
493
493
|
const provisionerStr = (tfName) => `\n\n provisioner "local-exec" {
|
|
494
494
|
command = "node create-s2s-script.cjs"
|
|
495
|
+
on_failure = fail
|
|
495
496
|
environment = {
|
|
496
497
|
IBMCLOUD_API_KEY = var.ibmcloud_api_key
|
|
497
498
|
TARGET_TOOLCHAIN_ID = ibm_cd_toolchain.${tfName}.id
|
package/create-s2s-script.js
CHANGED
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
|
|
10
10
|
const fs = require('node:fs');
|
|
11
11
|
const { resolve } = require('node:path');
|
|
12
|
+
const { exit } = require('node:process');
|
|
12
13
|
|
|
13
14
|
const API_KEY = process.env['IBMCLOUD_API_KEY'];
|
|
14
15
|
if (!API_KEY) throw Error(`Missing 'IBMCLOUD_API_KEY'`);
|
|
@@ -103,21 +104,29 @@ async function createS2sAuthPolicy(bearer, item) {
|
|
|
103
104
|
});
|
|
104
105
|
|
|
105
106
|
if (!response.ok) {
|
|
106
|
-
|
|
107
|
+
return Promise.reject(`Failed to create service-to-service authorization policy for ${item['serviceId']} '${item['parameters']['label'] ?? item['parameters']['name']}' with status: ${response.status} ${response.statusText}`);
|
|
107
108
|
}
|
|
108
109
|
|
|
109
110
|
console.log(`CREATING AUTH POLICY... ${response.status}, ${response.statusText}`);
|
|
110
111
|
} catch (error) {
|
|
111
|
-
|
|
112
|
+
return Promise.reject(error.message);
|
|
112
113
|
}
|
|
113
114
|
}
|
|
114
115
|
|
|
115
116
|
// main
|
|
116
117
|
|
|
117
|
-
getBearer().then((bearer) => {
|
|
118
|
+
getBearer().then(async (bearer) => {
|
|
118
119
|
const inputArr = JSON.parse(fs.readFileSync(resolve(INPUT_PATH)));
|
|
119
120
|
|
|
120
|
-
|
|
121
|
-
|
|
121
|
+
const promises = [];
|
|
122
|
+
inputArr.forEach((item) => {
|
|
123
|
+
promises.push(createS2sAuthPolicy(bearer, item));
|
|
122
124
|
});
|
|
125
|
+
|
|
126
|
+
try {
|
|
127
|
+
await Promise.all(promises);
|
|
128
|
+
} catch (e) {
|
|
129
|
+
console.error(e)
|
|
130
|
+
exit(1);
|
|
131
|
+
}
|
|
123
132
|
});
|
package/package.json
CHANGED
|
@@ -37,10 +37,19 @@ describe('copy-toolchain: Test functionalities', function () {
|
|
|
37
37
|
const testCases = [
|
|
38
38
|
{
|
|
39
39
|
name: 'Terraform Version Verification',
|
|
40
|
-
cmd: [CLI_PATH, COMMAND, '-c', TEST_TOOLCHAINS['empty'].crn, '-r',
|
|
40
|
+
cmd: [CLI_PATH, COMMAND, '-c', TEST_TOOLCHAINS['empty'].crn, '-r', TEST_TOOLCHAINS['empty'].region],
|
|
41
41
|
expected: /✔ Terraform Version:/,
|
|
42
42
|
options: {
|
|
43
|
-
exitCondition:
|
|
43
|
+
exitCondition: `(Recommended) Edit the cloned toolchain's name [default: ${TEST_TOOLCHAINS['empty'].name}] (Ctrl-C to abort):`,
|
|
44
|
+
timeout: 10000
|
|
45
|
+
}
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
name: 'CLI Version Verification',
|
|
49
|
+
cmd: [CLI_PATH, COMMAND, '-c', TEST_TOOLCHAINS['empty'].crn, '-r', TEST_TOOLCHAINS['empty'].region],
|
|
50
|
+
expected: /✔ cd-tools Version:/,
|
|
51
|
+
options: {
|
|
52
|
+
exitCondition: `(Recommended) Edit the cloned toolchain's name [default: ${TEST_TOOLCHAINS['empty'].name}] (Ctrl-C to abort):`,
|
|
44
53
|
timeout: 10000
|
|
45
54
|
}
|
|
46
55
|
},
|
|
@@ -56,10 +65,10 @@ describe('copy-toolchain: Test functionalities', function () {
|
|
|
56
65
|
},
|
|
57
66
|
{
|
|
58
67
|
name: 'Log file is created successfully',
|
|
59
|
-
cmd: [CLI_PATH, COMMAND, '-c', TEST_TOOLCHAINS['empty'].crn, '-r',
|
|
68
|
+
cmd: [CLI_PATH, COMMAND, '-c', TEST_TOOLCHAINS['empty'].crn, '-r', TEST_TOOLCHAINS['empty'].region],
|
|
60
69
|
expected: null,
|
|
61
70
|
options: {
|
|
62
|
-
exitCondition:
|
|
71
|
+
exitCondition: `(Recommended) Edit the cloned toolchain's name [default: ${TEST_TOOLCHAINS['empty'].name}] (Ctrl-C to abort):`,
|
|
63
72
|
timeout: 10000,
|
|
64
73
|
cwd: TEMP_DIR + '/' + 'log-file-is-created-successfully'
|
|
65
74
|
},
|
|
@@ -81,15 +90,6 @@ describe('copy-toolchain: Test functionalities', function () {
|
|
|
81
90
|
assert.isTrue(toolchainData.id === toolchainId, 'Was toolchain created successfully without any confirmations?');
|
|
82
91
|
}
|
|
83
92
|
},
|
|
84
|
-
{
|
|
85
|
-
name: 'Prompt User when toolchain name already exists in resource group',
|
|
86
|
-
cmd: [CLI_PATH, COMMAND, '-c', TEST_TOOLCHAINS['empty'].crn, '-r', TARGET_REGIONS[0]],
|
|
87
|
-
expected: new RegExp(`Warning! A toolchain named \'${TEST_TOOLCHAINS['empty'].name}\' already exists in:[\\s\\S]*?Resource Group:[\\s\\S]*?${R2R_CLI_RG_ID}`),
|
|
88
|
-
options: {
|
|
89
|
-
exitCondition: '(Recommended) Add a tag to the cloned toolchain (Ctrl-C to abort):',
|
|
90
|
-
timeout: 10000
|
|
91
|
-
}
|
|
92
|
-
},
|
|
93
93
|
{
|
|
94
94
|
name: 'Prompt User when toolchain name already exists in region',
|
|
95
95
|
cmd: [CLI_PATH, COMMAND, '-c', TEST_TOOLCHAINS['empty'].crn, '-r', TEST_TOOLCHAINS['empty'].region, '-g', DEFAULT_RG_ID],
|
|
@@ -125,10 +125,13 @@ describe('copy-toolchain: Test user input handling', function () {
|
|
|
125
125
|
const invalidUserInputCases = [
|
|
126
126
|
{
|
|
127
127
|
name: 'Invalid Toolchain tag is provided',
|
|
128
|
-
cmd: [CLI_PATH, COMMAND, '-c', TEST_TOOLCHAINS['empty'].crn, '-r',
|
|
128
|
+
cmd: [CLI_PATH, COMMAND, '-c', TEST_TOOLCHAINS['empty'].crn, '-r', TEST_TOOLCHAINS['empty'].region],
|
|
129
129
|
expected: /Provided tag is invalid/,
|
|
130
130
|
options: {
|
|
131
|
-
questionAnswerMap: {
|
|
131
|
+
questionAnswerMap: {
|
|
132
|
+
[`(Recommended) Edit the cloned toolchain's name [default: ${TEST_TOOLCHAINS['empty'].name}] (Ctrl-C to abort):`]: '',
|
|
133
|
+
'(Recommended) Add a tag to the cloned toolchain (Ctrl-C to abort):': mocks.invalidTag
|
|
134
|
+
},
|
|
132
135
|
exitCondition: 'Validation failed',
|
|
133
136
|
timeout: 10000
|
|
134
137
|
}
|
|
@@ -43,12 +43,12 @@ describe('copy-toolchain: Test import-terraform output', function () {
|
|
|
43
43
|
ibm_cd_tekton_pipeline_trigger: 1,
|
|
44
44
|
ibm_cd_tekton_pipeline_trigger_property: 1,
|
|
45
45
|
ibm_cd_toolchain: 1,
|
|
46
|
+
ibm_cd_toolchain_tool_cos: 1,
|
|
46
47
|
ibm_cd_toolchain_tool_custom: 1,
|
|
47
48
|
ibm_cd_toolchain_tool_githubconsolidated: 1,
|
|
48
49
|
ibm_cd_toolchain_tool_pipeline: 1,
|
|
49
50
|
ibm_cd_toolchain_tool_secretsmanager: 1,
|
|
50
51
|
ibm_cd_toolchain_tool_slack: 1,
|
|
51
|
-
ibm_iam_authorization_policy: 1
|
|
52
52
|
});
|
|
53
53
|
}
|
|
54
54
|
},
|
|
@@ -68,12 +68,12 @@ describe('copy-toolchain: Test import-terraform output', function () {
|
|
|
68
68
|
ibm_cd_tekton_pipeline_trigger: 1,
|
|
69
69
|
ibm_cd_tekton_pipeline_trigger_property: 1,
|
|
70
70
|
ibm_cd_toolchain: 1,
|
|
71
|
+
ibm_cd_toolchain_tool_cos: 1,
|
|
71
72
|
ibm_cd_toolchain_tool_custom: 1,
|
|
72
73
|
ibm_cd_toolchain_tool_githubconsolidated: 1,
|
|
73
74
|
ibm_cd_toolchain_tool_pipeline: 1,
|
|
74
75
|
ibm_cd_toolchain_tool_secretsmanager: 1,
|
|
75
76
|
ibm_cd_toolchain_tool_slack: 1,
|
|
76
|
-
ibm_iam_authorization_policy: 1
|
|
77
77
|
});
|
|
78
78
|
}
|
|
79
79
|
},
|
|
@@ -99,7 +99,6 @@ describe('copy-toolchain: Test import-terraform output', function () {
|
|
|
99
99
|
ibm_cd_toolchain_tool_pipeline: 1,
|
|
100
100
|
ibm_cd_toolchain_tool_secretsmanager: 1,
|
|
101
101
|
ibm_cd_toolchain_tool_slack: 1,
|
|
102
|
-
ibm_iam_authorization_policy: 1
|
|
103
102
|
})
|
|
104
103
|
}
|
|
105
104
|
},
|
|
@@ -56,7 +56,6 @@ describe('copy-toolchain: Test tool validation', function () {
|
|
|
56
56
|
},
|
|
57
57
|
assertionFunc: (output) => {
|
|
58
58
|
expect(output).to.match(/Warning! The following tools contain secrets that cannot be migrated/);
|
|
59
|
-
expect(output).to.match(/cloudobjectstorage[\s\S]*?cos_api_key/);
|
|
60
59
|
expect(output).to.match(/slack[\s\S]*?api_token/);
|
|
61
60
|
expect(output).to.match(/pipeline[\s\S]*?properties.doi-ibmcloud-api-key/);
|
|
62
61
|
}
|