Skip to content

Commit

Permalink
fix: [M3-7638] - VPC arguments in Linode Create flow CLI (#10071)
Browse files Browse the repository at this point in the history
## Description 📝
The Linode CLI doesn't accept `interfaces.ipv4` as an object. Instead, it should be configured individually as `interfaces.ipv4.vpc` and `interfaces.ipv4.nat_1_1`. `interfaces.vpc_id` is also not a valid argument.

## Changes  🔄
- `interfaces.ipv4` object -> individual arguments 
- Removed `interfaces.vpc_id` from the Linode CLI command

## How to test 🧪

### Prerequisites
### Reproduction steps
(How to reproduce the issue, if applicable)
- On a different branch, go to `/linodes/create`. Fill out the form, add a VPC, and click the `Create Using Command Line` button. Notice how `--interfaces.ipv4` is an object.

### Verification steps 
(How to verify changes)
- Go to `/linodes/create`, fill out the form, add a VPC, and click the `Create Using Command Line` button. Notice how `--interfaces.ipv4` is no longer an object but separate arguments depending on the checkboxes selected
- There should be no regressions in terms of the data displayed (`nat_1_1` and `vpc`)
  • Loading branch information
hana-akamai authored Jan 18, 2024
1 parent e475c6b commit 995fa6e
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 1 deletion.
5 changes: 5 additions & 0 deletions packages/manager/.changeset/pr-10071-fixed-1705522697458.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@linode/manager": Fixed
---

VPC arguments in Linode Create flow CLI ([#10071](https://github.com/linode/manager/pull/10071))
15 changes: 15 additions & 0 deletions packages/manager/src/utilities/generate-cli.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,20 @@ const linodeData = {
...linodeRequest,
authorized_users: ['Linny', 'Gritty'],
backup_id: undefined,
interfaces: [
{
ipam_address: null,
ipv4: {
nat_1_1: 'any',
vpc: '123',
},
label: null,
primary: true,
purpose: 'vpc',
subnet_id: 8296,
vpc_id: 7403,
},
],
metadata: {
user_data: 'cmVrbmpnYmloZXVma2xkbQpqZXZia2Y=',
},
Expand All @@ -27,6 +41,7 @@ const linodeDataForCLI = `
--type ${linodeRequest.type} \\
--authorized_users Linny \\
--authorized_users Gritty \\
--interfaces.ipam_address null --interfaces.ipv4.nat_1_1 \"any\" --interfaces.ipv4.vpc \"123\" --interfaces.label null --interfaces.primary true --interfaces.purpose \"vpc\" --interfaces.subnet_id 8296 \\
--metadata.user_data="cmVrbmpnYmloZXVma2xkbQpqZXZia2Y=" \\
--stackscript_data '{"gh_username": "linode"}' \\
--stackscript_id 10079
Expand Down
27 changes: 26 additions & 1 deletion packages/manager/src/utilities/generate-cli.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import { UserData } from '@linode/api-v4/lib/linodes/types';
import {
ConfigInterfaceIPv4,
UserData,
} from '@linode/api-v4/lib/linodes/types';

// Credit: https://github.com/xxorax/node-shell-escape
function escapeStringForCLI(s: string): string {
Expand All @@ -18,10 +21,30 @@ const convertObjectToCLIArg = (data: {} | null) => {
};

const parseObject = (key: string, value: {}) => {
// M3-7638: The Linode CLI does not currently accept interfaces.ipv4 as an object so we need to make them separate arguments
const parseIpv4Object = (_key: string, _value: ConfigInterfaceIPv4) => {
const ipv4ValueStrings = [];
if (_value.nat_1_1) {
ipv4ValueStrings.push(
`--${key}.${_key}.nat_1_1 ${JSON.stringify(_value.nat_1_1)}`
);
}
if (_value.vpc) {
ipv4ValueStrings.push(
`--${key}.${_key}.vpc ${JSON.stringify(_value.vpc)}`
);
}
return ipv4ValueStrings.join(' ');
};

const result = Object.entries(value)
.map(([_key, _value]) => {
if (_key === 'ipv4') {
return parseIpv4Object(_key, _value as ConfigInterfaceIPv4);
}
return `--${key}.${_key} ${JSON.stringify(_value)}`;
})
.filter((string) => string.length > 0)
.join(' ');
return result.padStart(result.length + 2);
};
Expand All @@ -32,6 +55,8 @@ const parseArray = (key: string, value: any[]) => {
results.push(
value
.map((item) => {
// M3-7638: vpc_id is not a valid argument. The subnet_id will be used in the backend to implicitly determine the VPC ID
delete item.vpc_id;
return parseObject('interfaces', item);
})
.join('\\\n')
Expand Down

0 comments on commit 995fa6e

Please sign in to comment.