Skip to content

Commit

Permalink
Add IP validation
Browse files Browse the repository at this point in the history
  • Loading branch information
zephraph committed Nov 14, 2023
1 parent 778968a commit f6a5183
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 15 deletions.
30 changes: 15 additions & 15 deletions client/validate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,9 @@ export const AddressLot = z.preprocess(
export const AddressLotBlock = z.preprocess(
processResponseBody,
z.object({
firstAddress: z.string(),
firstAddress: z.string().ip(),
id: z.string().uuid(),
lastAddress: z.string(),
lastAddress: z.string().ip(),
})
);

Expand All @@ -137,7 +137,7 @@ export const AddressLotBlock = z.preprocess(
*/
export const AddressLotBlockCreate = z.preprocess(
processResponseBody,
z.object({ firstAddress: z.string(), lastAddress: z.string() })
z.object({ firstAddress: z.string().ip(), lastAddress: z.string().ip() })
);

/**
Expand Down Expand Up @@ -191,7 +191,7 @@ export const Baseboard = z.preprocess(
export const BgpPeerConfig = z.preprocess(
processResponseBody,
z.object({
addr: z.string(),
addr: z.string().ip(),
bgpAnnounceSet: NameOrId,
bgpConfig: NameOrId,
interfaceName: z.string(),
Expand Down Expand Up @@ -519,7 +519,7 @@ export const IpKind = z.preprocess(

export const ExternalIp = z.preprocess(
processResponseBody,
z.object({ ip: z.string(), kind: IpKind })
z.object({ ip: z.string().ip(), kind: IpKind })
);

/**
Expand Down Expand Up @@ -785,7 +785,7 @@ export const InstanceNetworkInterfaceCreate = z.preprocess(
processResponseBody,
z.object({
description: z.string(),
ip: z.string().optional(),
ip: z.string().ip().optional(),
name: Name,
subnetName: Name,
vpcName: Name,
Expand Down Expand Up @@ -859,7 +859,7 @@ export const InstanceNetworkInterface = z.preprocess(
description: z.string(),
id: z.string().uuid(),
instanceId: z.string().uuid(),
ip: z.string(),
ip: z.string().ip(),
mac: MacAddr,
name: Name,
primary: SafeBoolean,
Expand Down Expand Up @@ -1045,7 +1045,7 @@ export const LoopbackAddress = z.preprocess(
export const LoopbackAddressCreate = z.preprocess(
processResponseBody,
z.object({
address: z.string(),
address: z.string().ip(),
addressLot: NameOrId,
anycast: SafeBoolean,
mask: z.number().min(0).max(255),
Expand Down Expand Up @@ -1243,7 +1243,7 @@ export const Route = z.preprocess(
processResponseBody,
z.object({
dst: IpNet,
gw: z.string(),
gw: z.string().ip(),
vid: z.number().min(0).max(65535).optional(),
})
);
Expand All @@ -1264,7 +1264,7 @@ export const RouteConfig = z.preprocess(
export const RouteDestination = z.preprocess(
processResponseBody,
z.union([
z.object({ type: z.enum(["ip"]), value: z.string() }),
z.object({ type: z.enum(["ip"]), value: z.string().ip() }),
z.object({ type: z.enum(["ip_net"]), value: IpNet }),
z.object({ type: z.enum(["vpc"]), value: Name }),
z.object({ type: z.enum(["subnet"]), value: Name }),
Expand All @@ -1277,7 +1277,7 @@ export const RouteDestination = z.preprocess(
export const RouteTarget = z.preprocess(
processResponseBody,
z.union([
z.object({ type: z.enum(["ip"]), value: z.string() }),
z.object({ type: z.enum(["ip"]), value: z.string().ip() }),
z.object({ type: z.enum(["vpc"]), value: Name }),
z.object({ type: z.enum(["subnet"]), value: Name }),
z.object({ type: z.enum(["instance"]), value: Name }),
Expand Down Expand Up @@ -1670,7 +1670,7 @@ export const SwitchPortApplySettings = z.preprocess(
export const SwitchPortBgpPeerConfig = z.preprocess(
processResponseBody,
z.object({
addr: z.string(),
addr: z.string().ip(),
bgpAnnounceSetId: z.string().uuid(),
bgpConfigId: z.string().uuid(),
interfaceName: z.string(),
Expand Down Expand Up @@ -1958,7 +1958,7 @@ export const VpcFirewallRuleHostFilter = z.preprocess(
z.object({ type: z.enum(["vpc"]), value: Name }),
z.object({ type: z.enum(["subnet"]), value: Name }),
z.object({ type: z.enum(["instance"]), value: Name }),
z.object({ type: z.enum(["ip"]), value: z.string() }),
z.object({ type: z.enum(["ip"]), value: z.string().ip() }),
z.object({ type: z.enum(["ip_net"]), value: IpNet }),
])
);
Expand Down Expand Up @@ -1997,7 +1997,7 @@ export const VpcFirewallRuleTarget = z.preprocess(
z.object({ type: z.enum(["vpc"]), value: Name }),
z.object({ type: z.enum(["subnet"]), value: Name }),
z.object({ type: z.enum(["instance"]), value: Name }),
z.object({ type: z.enum(["ip"]), value: z.string() }),
z.object({ type: z.enum(["ip"]), value: z.string().ip() }),
z.object({ type: z.enum(["ip_net"]), value: IpNet }),
])
);
Expand Down Expand Up @@ -3418,7 +3418,7 @@ export const NetworkingLoopbackAddressDeleteParams = z.preprocess(
processResponseBody,
z.object({
path: z.object({
address: z.string(),
address: z.string().ip(),
rackId: z.string().uuid(),
subnetMask: z.number().min(0).max(255),
switchLocation: Name,
Expand Down
3 changes: 3 additions & 0 deletions generator/schema/zod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ export const schemaToZod = makeSchemaGenerator({
if (schema.format === "uuid") {
w0(".uuid()");
}
if (schema.format === "ip") {
w0(".ip()");
}
if ("minLength" in schema) {
w0(`.min(${schema.minLength})`);
}
Expand Down

0 comments on commit f6a5183

Please sign in to comment.