Skip to content

Commit

Permalink
feat: [M3-6727] – Include firewall_id field as part of Linode Create …
Browse files Browse the repository at this point in the history
…object (#9453)
  • Loading branch information
dwiley-akamai authored Aug 24, 2023
1 parent 0ee5152 commit 0af88ff
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 18 deletions.
5 changes: 5 additions & 0 deletions packages/api-v4/.changeset/pr-9453-changed-1691514440186.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@linode/api-v4": Changed
---

Include 'firewall_id' field as optional in CreateLinodeRequest ([#9453](https://github.com/linode/manager/pull/9453))
1 change: 1 addition & 0 deletions packages/api-v4/src/linodes/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,7 @@ export interface CreateLinodeRequest {
authorized_users?: string[];
interfaces?: Interface[];
metadata?: UserData;
firewall_id?: number;
}

export type RescueRequestObject = Pick<
Expand Down
6 changes: 5 additions & 1 deletion packages/manager/src/utilities/subnets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,11 @@ export const validateSubnets = (
}
if (
determineIPType(subnet.ip.ipv4 ?? '') !== 'ipv4' ||
!vpcsValidateIP(subnet.ip.ipv4, true)
!vpcsValidateIP({
mustBeIPMask: false,
shouldHaveIPMask: true,
value: subnet.ip.ipv4,
})
) {
const errorIP = { ...subnet.ip, ipv4Error: '' };
errorIP['ipv4Error'] = options?.ipv4Error ?? DEFAULT_IPV4_ERROR;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@linode/validation": Changed
---

Include 'firewall_id' field as optional in CreateLinodeSchema ([#9453](https://github.com/linode/manager/pull/9453))
19 changes: 14 additions & 5 deletions packages/validation/src/linodes.schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,11 @@ const test_vpcsValidateIP = (value?: string | null) => {
return true;
}

return vpcsValidateIP(value, false);
return vpcsValidateIP({
value,
shouldHaveIPMask: false,
mustBeIPMask: false,
});
};

// Utils
Expand All @@ -38,6 +42,10 @@ const testmessageDisallowedBasedOnPurpose = (
) =>
`${field} is not allowed for interfaces that do not have a purpose set to ${allowedPurpose}.`;

// Constants
const LINODE_LABEL_CHAR_REQUIREMENT =
'Label must contain between 3 and 64 characters.';

// Schemas
const stackscript_data = array().of(object()).nullable(true);

Expand Down Expand Up @@ -253,8 +261,8 @@ export const CreateLinodeSchema = object({
label: string()
.transform((v) => (v === '' ? undefined : v))
.notRequired()
.min(3, 'Label must contain between 3 and 64 characters.')
.max(64, 'Label must contain between 3 and 64 characters.'),
.min(3, LINODE_LABEL_CHAR_REQUIREMENT)
.max(64, LINODE_LABEL_CHAR_REQUIREMENT),
tags: array().of(string()).notRequired(),
private_ip: boolean().notRequired(),
authorized_users: array().of(string()).notRequired(),
Expand All @@ -268,6 +276,7 @@ export const CreateLinodeSchema = object({
}),
interfaces: linodeInterfaceSchema,
metadata: MetadataSchema,
firewall_id: number().notRequired(),
});

const alerts = object({
Expand Down Expand Up @@ -323,8 +332,8 @@ export const UpdateLinodeSchema = object({
label: string()
.transform((v) => (v === '' ? undefined : v))
.notRequired()
.min(3, 'Label must contain between 3 and 64 characters.')
.max(64, 'Label must contain between 3 and 64 characters.'),
.min(3, LINODE_LABEL_CHAR_REQUIREMENT)
.max(64, LINODE_LABEL_CHAR_REQUIREMENT),
tags: array().of(string()).notRequired(),
watchdog_enabled: boolean().notRequired(),
alerts,
Expand Down
49 changes: 37 additions & 12 deletions packages/validation/src/vpcs.schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,20 @@ export const determineIPType = (ip: string) => {
/**
* VPC-related IP validation that handles for single IPv4 and IPv6 addresses as well as
* IPv4 ranges in CIDR format and IPv6 ranges with prefix lengths.
* @param value - the IP address string to be validated
* @param shouldHaveIPMask - a boolean indicating whether the value should have a mask (e.g., /32) or not
* @param mustBeIPMask - a boolean indicating whether the value MUST be an IP mask/prefix length or not
* @param { value } - the IP address string to be validated
* @param { shouldHaveIPMask } - a boolean indicating whether the value should have a mask (e.g., /32) or not
* @param { mustBeIPMask } - a boolean indicating whether the value MUST be an IP mask/prefix length or not
*/
export const vpcsValidateIP = (
value?: string | null,
shouldHaveIPMask?: boolean,
mustBeIPMask?: boolean
): boolean => {

export const vpcsValidateIP = ({
value,
shouldHaveIPMask,
mustBeIPMask,
}: {
value: string | undefined | null;
shouldHaveIPMask: boolean;
mustBeIPMask: boolean;
}): boolean => {
if (!value) {
return false;
}
Expand Down Expand Up @@ -126,7 +131,12 @@ export const createSubnetSchema = object().shape(
.test({
name: 'IPv4 CIDR format',
message: 'The IPv4 range must be in CIDR format',
test: (value) => vpcsValidateIP(value, true, false),
test: (value) =>
vpcsValidateIP({
value,
shouldHaveIPMask: true,
mustBeIPMask: false,
}),
}),
otherwise: lazy((value: string | undefined) => {
switch (typeof value) {
Expand All @@ -139,7 +149,12 @@ export const createSubnetSchema = object().shape(
.test({
name: 'IPv4 CIDR format',
message: 'The IPv4 range must be in CIDR format',
test: (value) => vpcsValidateIP(value, true, false),
test: (value) =>
vpcsValidateIP({
value,
shouldHaveIPMask: true,
mustBeIPMask: false,
}),
});

default:
Expand All @@ -154,7 +169,12 @@ export const createSubnetSchema = object().shape(
.test({
name: 'IPv6 prefix length',
message: 'Must be the prefix length (64-125) of the IP, e.g. /64',
test: (value) => vpcsValidateIP(value, true, true),
test: (value) =>
vpcsValidateIP({
value,
shouldHaveIPMask: true,
mustBeIPMask: true,
}),
}),
otherwise: lazy((value: string | undefined) => {
switch (typeof value) {
Expand All @@ -168,7 +188,12 @@ export const createSubnetSchema = object().shape(
name: 'IPv6 prefix length',
message:
'Must be the prefix length (64-125) of the IP, e.g. /64',
test: (value) => vpcsValidateIP(value, true, true),
test: (value) =>
vpcsValidateIP({
value,
shouldHaveIPMask: true,
mustBeIPMask: true,
}),
});

default:
Expand Down

0 comments on commit 0af88ff

Please sign in to comment.