Skip to content
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@linode/validation": Upcoming Features
---

Update validation schemas for the changes in endpoints /v4/nodebalancers & /v4/nodebalancers/configs/{configId}/nodes for NB Dual Stack Support ([#12421](https://github.com/linode/manager/pull/12421))
36 changes: 34 additions & 2 deletions packages/validation/src/nodebalancers.schema.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { array, boolean, mixed, number, object, string } from 'yup';

import { vpcsValidateIP } from './vpcs.schema';
import { determineIPType, vpcsValidateIP } from './vpcs.schema';

const PORT_WARNING = 'Port must be between 1 and 65535.';
const LABEL_WARNING = 'Label must be between 3 and 32 characters.';
Expand Down Expand Up @@ -44,7 +44,39 @@
address: string()
.typeError('IP address is required.')
.required('IP address is required.')
.matches(PRIVATE_IPV4_REGEX, PRIVATE_IPV4_WARNING),
.test(
'IP validation',
'Must be a private IPv4 or a valid IPv6 address',
function (value) {
const type = determineIPType(value);
const isIPv4 = type === 'ipv4';
const isIPv6 = type === 'ipv6';

if (!isIPv4 && !isIPv6) {
// @TODO- NB Dual Stack Support(IPv6): Edit the error message to cover IPv6 addresses

Check warning on line 56 in packages/validation/src/nodebalancers.schema.ts

View workflow job for this annotation

GitHub Actions / ESLint Review (validation)

[eslint] reported by reviewdog 🐢 Complete the task associated to this "TODO" comment. Raw Output: {"ruleId":"sonarjs/todo-tag","severity":1,"message":"Complete the task associated to this \"TODO\" comment.","line":56,"column":15,"nodeType":null,"messageId":"completeTODO","endLine":56,"endColumn":19}
return this.createError({
message: PRIVATE_IPV4_WARNING,
});
}

if (isIPv4) {
if (!PRIVATE_IPV4_REGEX.test(value)) {
return this.createError({
message: PRIVATE_IPV4_WARNING,
});
}
return true;
}

if (isIPv6) {
return true;
}

return this.createError({
message: 'Unexpected error during IP address validation',
});
},
),

subnet_id: number().when('vpcs', {
is: (vpcs: (typeof createNodeBalancerVPCsSchema)[]) => vpcs !== undefined,
Expand Down