Docker images / prepare-release (push) Successful in 12s
Docker images / backend-test (push) Successful in 11m40s
Docker images / frontend-image (push) Successful in 3m56s
Docker images / updater-image (push) Successful in 2m38s
Docker images / netflow-agent-image (push) Successful in 33s
Docker images / backend-image (push) Successful in 5m2s
Docker images / publish-release (push) Successful in 11s
Docker images / notify-webhook (push) Successful in 2s
51 lines
2.5 KiB
TypeScript
51 lines
2.5 KiB
TypeScript
import { z } from "zod"
|
|
|
|
const ip = z.union([z.ipv4(), z.ipv6()])
|
|
const cidr = z.union([z.cidrv4(), z.cidrv6()])
|
|
export const ixWireguardPublicKey = z.string().regex(/^[A-Za-z0-9+/]{42}[AEIMQUYcgkosw048]=$/)
|
|
.refine(key => key !== "A".repeat(43) + "=", "Недопустимый нулевой ключ WireGuard")
|
|
export const ixBondModeSchema = z.enum(["failover", "equal", "weighted"])
|
|
const member = z.object({
|
|
interfaceName: z.string().regex(/^[a-zA-Z0-9_=-][a-zA-Z0-9_.=-]{0,14}$/),
|
|
kind: z.enum(["wireguard", "gre-ipsec"]),
|
|
address: ip,
|
|
probe: ip,
|
|
endpoint: ip,
|
|
weight: z.number().int().min(1).max(100),
|
|
// A 32-byte WireGuard key ends with two zero padding bits and one '='.
|
|
peerPublicKey: ixWireguardPublicKey.optional(),
|
|
}).strict()
|
|
|
|
export const ixBondBundleSchema = z.object({
|
|
version: z.literal(1),
|
|
id: z.string().uuid(),
|
|
revision: z.number().int().positive().safe(),
|
|
clientId: z.string().uuid(),
|
|
name: z.string().trim().min(1).max(80).regex(/^[^\x00-\x1f\x7f]+$/),
|
|
mode: ixBondModeSchema,
|
|
destinations: z.array(cidr).min(1).max(64),
|
|
directCidrs: z.array(cidr).max(64),
|
|
members: z.array(member).min(2).max(16),
|
|
}).strict().superRefine((group, ctx) => {
|
|
const problem = (message: string) => ctx.addIssue({ code: "custom", message })
|
|
const names = new Set<string>()
|
|
const hosts = new Set<string>()
|
|
const ipv6 = group.destinations[0]?.includes(":")
|
|
if (group.destinations.some(prefix => prefix.includes(":") !== ipv6)) problem("Назначения должны быть одного семейства")
|
|
for (const path of group.members) {
|
|
if (names.has(path.interfaceName)) problem("Интерфейс повторяется в группе")
|
|
names.add(path.interfaceName)
|
|
for (const address of [path.address, path.probe]) {
|
|
if (address.includes(":") !== ipv6) problem("Адрес туннеля и назначения должны быть одного семейства")
|
|
const canonical = ipv6 && z.ipv6().safeParse(address).success ? new URL("http://[" + address + "]").hostname : address
|
|
if (hosts.has(canonical)) problem("Внутренние адреса путей должны быть уникальны")
|
|
hosts.add(canonical)
|
|
}
|
|
if (path.kind === "gre-ipsec" && path.peerPublicKey) problem("Ключ WireGuard указан для GRE")
|
|
}
|
|
})
|
|
|
|
export type IxBondMode = z.infer<typeof ixBondModeSchema>
|
|
export type IxBondBundle = z.infer<typeof ixBondBundleSchema>
|
|
export type IxBondMember = z.infer<typeof member>
|