mirror of
https://github.com/fosrl/pangolin.git
synced 2026-06-06 15:50:42 +00:00
Make the destination optional
This commit is contained in:
@@ -398,7 +398,7 @@ export const PrivateResourceSchema = z
|
|||||||
// protocol: z.enum(["tcp", "udp"]).optional(),
|
// protocol: z.enum(["tcp", "udp"]).optional(),
|
||||||
// proxyPort: z.int().positive().optional(),
|
// proxyPort: z.int().positive().optional(),
|
||||||
"destination-port": z.int().positive().optional(),
|
"destination-port": z.int().positive().optional(),
|
||||||
destination: z.string().min(1),
|
destination: z.string().min(1).optional(),
|
||||||
// enabled: z.boolean().default(true),
|
// enabled: z.boolean().default(true),
|
||||||
"tcp-ports": portRangeStringSchema.optional().default("*"),
|
"tcp-ports": portRangeStringSchema.optional().default("*"),
|
||||||
"udp-ports": portRangeStringSchema.optional().default("*"),
|
"udp-ports": portRangeStringSchema.optional().default("*"),
|
||||||
@@ -424,9 +424,28 @@ export const PrivateResourceSchema = z
|
|||||||
machines: z.array(z.string()).optional().default([]),
|
machines: z.array(z.string()).optional().default([]),
|
||||||
"auth-daemon": AuthDaemonSchema.optional()
|
"auth-daemon": AuthDaemonSchema.optional()
|
||||||
})
|
})
|
||||||
|
.refine(
|
||||||
|
(data) => {
|
||||||
|
// destination is optional only for ssh+native; required for everything else
|
||||||
|
const isNativeSSH =
|
||||||
|
data.mode === "ssh" &&
|
||||||
|
(data["auth-daemon"] === undefined ||
|
||||||
|
data["auth-daemon"].mode === "native");
|
||||||
|
if (!isNativeSSH && !data.destination) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: ["destination"],
|
||||||
|
message:
|
||||||
|
"destination is required unless mode is 'ssh' with auth-daemon mode 'native'"
|
||||||
|
}
|
||||||
|
)
|
||||||
.refine(
|
.refine(
|
||||||
(data) => {
|
(data) => {
|
||||||
if (data.mode === "host") {
|
if (data.mode === "host") {
|
||||||
|
if (!data.destination) return true; // caught by the destination-required refine
|
||||||
// Check if it's a valid IP address using zod (v4 or v6)
|
// Check if it's a valid IP address using zod (v4 or v6)
|
||||||
const isValidIP = z
|
const isValidIP = z
|
||||||
.union([z.ipv4(), z.ipv6()])
|
.union([z.ipv4(), z.ipv6()])
|
||||||
@@ -454,6 +473,7 @@ export const PrivateResourceSchema = z
|
|||||||
.refine(
|
.refine(
|
||||||
(data) => {
|
(data) => {
|
||||||
if (data.mode === "cidr") {
|
if (data.mode === "cidr") {
|
||||||
|
if (!data.destination) return true; // caught by the destination-required refine
|
||||||
// Check if it's a valid CIDR (v4 or v6)
|
// Check if it's a valid CIDR (v4 or v6)
|
||||||
const isValidCIDR = z
|
const isValidCIDR = z
|
||||||
.union([z.cidrv4(), z.cidrv6()])
|
.union([z.cidrv4(), z.cidrv6()])
|
||||||
|
|||||||
Reference in New Issue
Block a user