Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: [M3-6727] – Include firewall field as part of Linode Create object #9453

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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