Skip to content

Commit

Permalink
update validatoon schemas
Browse files Browse the repository at this point in the history
  • Loading branch information
bnussman committed Dec 3, 2024
1 parent 4110171 commit 0166ed1
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 12 deletions.
17 changes: 11 additions & 6 deletions packages/api-v4/src/nodebalancers/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,15 @@ export interface NodeBalancer {
label: string;
hostname: string;
/**
* The connections per second throttle for TCP and HTTP connections
* Maximum number of new TCP connections that a client (identified by a specific source IP)
* is allowed to initiate every second.
*/
client_conn_throttle: number;
/**
* The connections per second throttle for UDP sessions
* Maximum number of new UDP sessions that a client (identified by a specific source IP)
* is allowed to initiate every second.
*
* @todo optional until UDP is GA
* @todo Remove optionality once UDP support is live
*/
client_udp_sess_throttle?: number;
region: string;
Expand Down Expand Up @@ -77,12 +79,13 @@ export interface NodeBalancerConfig {
check_body: string;
check_path: string;
/**
* @todo Optional until UDP is GA
* @todo Remove optionality once UDP support is live
*/
udp_check_port?: number;
/**
* @readonly this is returned but not editable
* @todo Optional until UDP is GA
* @readonly This is returned by the API but *not* editable
* @todo Remove optionality once UDP support is live
* @default 16
*/
udp_session_timeout?: number;
proxy_protocol: NodeBalancerProxyProtocol;
Expand Down Expand Up @@ -194,12 +197,14 @@ export interface CreateNodeBalancerPayload {
* The connections per second throttle for TCP and HTTP connections
*
* Must be between 0 and 20. Set to 0 to disable throttling.
* @default 0
*/
client_conn_throttle?: number;
/**
* The connections per second throttle for UDP sessions
*
* Must be between 0 and 20. Set to 0 to disable throttling.
* @default 0
*/
client_udp_sess_throttle?: number;
configs: CreateNodeBalancerConfig[];
Expand Down
31 changes: 25 additions & 6 deletions packages/validation/src/nodebalancers.schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,15 @@ export const nodeBalancerConfigNodeSchema = object({
.min(1, `Weight must be between 1 and 255.`)
.max(255, `Weight must be between 1 and 255.`),

mode: mixed().oneOf(['accept', 'reject', 'backup', 'drain']),
mode: string().oneOf(['accept', 'reject', 'backup', 'drain']),
});

export const createNodeBalancerConfigSchema = object({
algorithm: mixed().oneOf(['roundrobin', 'leastconn', 'source']),
algorithm: string().when('protocol', {
is: 'udp',
then: (schema) => schema.oneOf(['roundrobin', 'leastconn', 'ring_hash']),
otherwise: (schema) => schema.oneOf(['roundrobin', 'leastconn', 'source']),
}),
check_attempts: number()
.min(
CHECK_ATTEMPTS.MIN,
Expand Down Expand Up @@ -106,7 +110,7 @@ export const createNodeBalancerConfigSchema = object({
.required('Port is required')
.min(1, PORT_WARNING)
.max(65535, PORT_WARNING),
protocol: mixed().oneOf(['http', 'https', 'tcp']),
protocol: string().oneOf(['http', 'https', 'tcp', 'udp']),
ssl_key: string().when('protocol', {
is: 'https',
then: (schema) => schema.required('SSL key is required when using HTTPS.'),
Expand All @@ -116,7 +120,12 @@ export const createNodeBalancerConfigSchema = object({
then: (schema) =>
schema.required('SSL certificate is required when using HTTPS.'),
}),
stickiness: mixed().oneOf(['none', 'table', 'http_cookie']),
stickiness: string().when('protocol', {
is: 'udp',
then: (schema) => schema.oneOf(['none', 'source_ip', 'session']),
otherwise: (schema) => schema.oneOf(['none', 'table', 'http_cookie']),
}),
udp_check_port: number().min(1).max(65535),
nodes: array()
.of(nodeBalancerConfigNodeSchema)
.required()
Expand Down Expand Up @@ -203,7 +212,12 @@ export const NodeBalancerSchema = object({
"Label can't contain special characters or spaces."
),

client_conn_throttle: number().typeError('Must be a number.'),
client_conn_throttle: number().min(0).max(20).typeError('Must be a number.'),

client_udp_sess_throttle: number()
.min(0)
.max(20)
.typeError('Must be a number.'),

region: string().required('Region is required.'),

Expand Down Expand Up @@ -250,7 +264,12 @@ export const UpdateNodeBalancerSchema = object({
"Label can't contain special characters or spaces."
),

client_conn_throttle: number().typeError('Must be a number.'),
client_conn_throttle: number().min(0).max(20).typeError('Must be a number.'),

client_udp_sess_throttle: number()
.min(0)
.max(20)
.typeError('Must be a number.'),

region: string(),
});

0 comments on commit 0166ed1

Please sign in to comment.