From 02a28429d648d0b5134a46b057ef446dacf46478 Mon Sep 17 00:00:00 2001 From: Hana Xu Date: Tue, 12 Sep 2023 16:12:18 -0400 Subject: [PATCH 1/3] fix metadata cli command --- packages/manager/src/utilities/generate-cli.ts | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/packages/manager/src/utilities/generate-cli.ts b/packages/manager/src/utilities/generate-cli.ts index f8988d6aaab..48b6cbdbde3 100644 --- a/packages/manager/src/utilities/generate-cli.ts +++ b/packages/manager/src/utilities/generate-cli.ts @@ -1,3 +1,5 @@ +import { UserData } from '@linode/api-v4/lib/linodes/types'; + // Credit: https://github.com/xxorax/node-shell-escape function escapeStringForCLI(s: string): string { if (/[^A-Za-z0-9_\/:=-]/.test(s)) { @@ -50,12 +52,18 @@ const parseString = (key: string, value: string) => { const dataEntriesReduce = (acc: string[], [key, value]: JSONFieldToArray) => { if (value === undefined || value === null) { return acc; - } else if (Array.isArray(value)) { + } + if (Array.isArray(value)) { if (value.length === 0) { return acc; } acc.push(parseArray(key, value)); return acc; + } + + if (key === 'metadata') { + const userData = value as UserData; + acc.push(` --${key}.user_data="${userData.user_data}"`); } else if (typeof value === 'object') { const valueAsString = convertObjectToCLIArg(value); acc.push(` --${key} ${valueAsString}`); From 7eece2c852b2da01a149130bc428cf35a5389f8f Mon Sep 17 00:00:00 2001 From: Hana Xu Date: Tue, 12 Sep 2023 16:45:06 -0400 Subject: [PATCH 2/3] update unit test --- .../src/utilities/generate-cli.test.ts | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/packages/manager/src/utilities/generate-cli.test.ts b/packages/manager/src/utilities/generate-cli.test.ts index 708c10bd8b3..21063300478 100644 --- a/packages/manager/src/utilities/generate-cli.test.ts +++ b/packages/manager/src/utilities/generate-cli.test.ts @@ -8,6 +8,9 @@ const linodeData = { ...linodeRequest, authorized_users: ['Linny', 'Gritty'], backup_id: undefined, + metadata: { + user_data: 'cmVrbmpnYmloZXVma2xkbQpqZXZia2Y=', + }, stackscript_data: { gh_username: 'linode', }, @@ -15,16 +18,18 @@ const linodeData = { }; const linodeDataForCLI = ` + linode-cli linodes create \\ + --booted ${linodeRequest.booted} \\ + --image ${linodeRequest.image} \\ --label ${linodeRequest.label} \\ + --region ${linodeRequest.region} \\ --root_pass ${linodeRequest.root_pass} \\ - --image ${linodeRequest.image} \\ --type ${linodeRequest.type} \\ - --region ${linodeRequest.region} \\ - --booted ${linodeRequest.booted} \\ - --stackscript_id 10079 \\ - --stackscript_data '{"gh_username": "linode"}' \\ --authorized_users Linny \\ - --authorized_users Gritty + --authorized_users Gritty \\ + --metadata.user_data="cmVrbmpnYmloZXVma2xkbQpqZXZia2Y=" \\ + --stackscript_data '{"gh_username": "linode"}' \\ + --stackscript_id 10079 `.trim(); const generatedCommand = generateCLICommand(linodeData); @@ -36,7 +41,7 @@ describe('generateCLICommand', () => { ).toBeTruthy(); }); - it.skip('should return a linode-cli command with the data provided formatted as arguments', () => { + it('should return a linode-cli command with the data provided formatted as arguments', () => { expect(generatedCommand).toMatch(linodeDataForCLI); }); From 2749be07f33f58d4d3db206f3ea879778a606b2d Mon Sep 17 00:00:00 2001 From: Hana Xu Date: Tue, 12 Sep 2023 17:01:46 -0400 Subject: [PATCH 3/3] Added changeset: Metadata CLI command --- packages/manager/.changeset/pr-9665-fixed-1694552506393.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 packages/manager/.changeset/pr-9665-fixed-1694552506393.md diff --git a/packages/manager/.changeset/pr-9665-fixed-1694552506393.md b/packages/manager/.changeset/pr-9665-fixed-1694552506393.md new file mode 100644 index 00000000000..ff90eef0ebd --- /dev/null +++ b/packages/manager/.changeset/pr-9665-fixed-1694552506393.md @@ -0,0 +1,5 @@ +--- +"@linode/manager": Fixed +--- + +Metadata CLI command ([#9665](https://github.com/linode/manager/pull/9665))