Docker images / prepare-release (push) Successful in 10s
Docker images / backend-test (push) Successful in 10m38s
Docker images / frontend-image (push) Successful in 2m14s
Docker images / updater-image (push) Successful in 40s
Docker images / netflow-agent-image (push) Successful in 35s
Docker images / backend-image (push) Successful in 2m2s
Docker images / publish-release (push) Successful in 12s
Docker images / notify-webhook (push) Successful in 2s
253 lines
7.9 KiB
TypeScript
253 lines
7.9 KiB
TypeScript
import { z } from "zod"
|
|
export * from "./ix-bond-management.js"
|
|
export * from "./ix-bond.js"
|
|
|
|
const key = z.string().regex(/^[a-z][a-z0-9-]{0,23}$/)
|
|
const interfaceName = z.string().regex(/^[A-Za-z0-9_.-]{1,48}$/)
|
|
const address = z.union([z.ipv4(), z.ipv6()])
|
|
const prefix = z.union([z.cidrv4(), z.cidrv6()])
|
|
const serverId = z.number().int().positive().safe()
|
|
const asn = z.number().int().min(1).max(4294967295)
|
|
const community = z.string().regex(/^\d{1,5}:\d{1,5}$/)
|
|
.refine(value => value.split(":").every(part => Number(part) <= 65535))
|
|
.transform(value => value.split(":").map(Number).join(":"))
|
|
|
|
const path = z.object({
|
|
interface: interfaceName,
|
|
nextHop: address,
|
|
probe: address,
|
|
viaMain: z.boolean().optional(),
|
|
}).strict()
|
|
|
|
const group = z.object({
|
|
id: key,
|
|
gateway: address,
|
|
primary: path,
|
|
backup: path.optional(),
|
|
onFailure: z.enum(["block", "segment-exit"]).default("block"),
|
|
}).strict()
|
|
|
|
const wireguardProvision = z.object({
|
|
peerPublicKey: z.string().regex(/^[A-Za-z0-9+/]{43}=$/),
|
|
credentialId: z.string().uuid().optional(),
|
|
listenPort: z.number().int().min(1).max(65535),
|
|
localAddress: prefix,
|
|
peerAddress: address,
|
|
hubEndpoint: address.optional(),
|
|
endpointPort: z.number().int().min(1).max(65535).optional(),
|
|
}).strict()
|
|
|
|
const greProvision = z.object({
|
|
localAddress: prefix,
|
|
peerAddress: address,
|
|
credentialId: z.string().uuid(),
|
|
}).strict()
|
|
|
|
const linuxPolicy = z.object({
|
|
name: z.string().trim().min(1).max(80),
|
|
clientId: z.string().uuid().optional(),
|
|
enabled: z.boolean(),
|
|
destinations: z.array(prefix).max(64),
|
|
tunnelMtu: z.number().int().min(1280).max(1420).optional(),
|
|
exit: key.optional(),
|
|
peerEndpoint: address.optional(),
|
|
}).strict()
|
|
|
|
const transitProvision = z.object({
|
|
localEndpoint: z.ipv4(),
|
|
remoteEndpoint: z.ipv4(),
|
|
localAddress: prefix,
|
|
remoteAddress: address,
|
|
localPort: wireguardProvision.shape.listenPort,
|
|
remotePort: wireguardProvision.shape.listenPort,
|
|
remoteWan: path,
|
|
credentialId: z.string().uuid(),
|
|
}).strict()
|
|
|
|
const interfaceBinding = z.object({
|
|
name: interfaceName,
|
|
kind: z.enum(["wireguard", "gre-ipsec", "uplink"]),
|
|
peerServerId: serverId.optional(),
|
|
localEndpoint: address.optional(),
|
|
endpoint: address.optional(),
|
|
natIpv4: z.boolean().optional(),
|
|
provisionWireguard: wireguardProvision.optional(),
|
|
provisionGre: greProvision.optional(),
|
|
provisionTransit: transitProvision.optional(),
|
|
linux: linuxPolicy.optional(),
|
|
prefixes: z.array(prefix).max(128).default([]),
|
|
}).strict()
|
|
|
|
const rule = z.object({
|
|
community,
|
|
group: key,
|
|
}).strict()
|
|
|
|
const neighbor = z.object({
|
|
id: key,
|
|
type: z.enum(["public-feed", "member", "exchange"]),
|
|
address,
|
|
localAddress: address,
|
|
remoteAs: asn,
|
|
binding: interfaceName,
|
|
group: key.optional(),
|
|
prefixes: z.array(prefix).max(128).default([]),
|
|
exportPrefixes: z.array(prefix).max(128).default([]),
|
|
rules: z.array(rule).max(100).default([]),
|
|
limit: z.union([z.literal(10), z.literal(100), z.literal(1000), z.literal(10000)]).default(1000),
|
|
}).strict()
|
|
|
|
const site = z.object({
|
|
serverId,
|
|
autonomousSystem: asn,
|
|
routerId: z.ipv4(),
|
|
autoRouterId: z.boolean().optional(),
|
|
interfaces: z.array(interfaceBinding).max(80).default([]),
|
|
groups: z.array(group).max(24).default([]),
|
|
exits: z.array(key).max(2).default([]),
|
|
routes: z.array(z.object({ prefix, group: key }).strict()).max(250).default([]),
|
|
neighbors: z.array(neighbor).max(16).default([]),
|
|
discardNetworks: z.array(prefix).max(250).default([]),
|
|
}).strict()
|
|
|
|
export const ixSegmentConfigurationSchema = z.object({
|
|
name: key,
|
|
sites: z.array(site).min(1).max(2),
|
|
}).strict()
|
|
|
|
export const ixChangeSchema = z.object({
|
|
id: z.string().uuid().optional(),
|
|
revision: z.number().int().nonnegative(),
|
|
configuration: ixSegmentConfigurationSchema,
|
|
}).strict().refine(input => Boolean(input.id) === (input.revision > 0), {
|
|
message: "Для новой точки укажите ревизию 0, для существующей — её текущую ревизию",
|
|
})
|
|
|
|
export type IxSite = z.infer<typeof site>
|
|
export type IxConfiguration = z.infer<typeof ixSegmentConfigurationSchema>
|
|
export type IxChange = z.infer<typeof ixChangeSchema>
|
|
|
|
const ixTransitOptions = z.object({
|
|
targetServerId: serverId,
|
|
name: key,
|
|
localEndpoint: z.ipv4(),
|
|
remoteEndpoint: z.ipv4(),
|
|
family: z.union([z.literal(4), z.literal(6)]).default(4),
|
|
probe: address.optional(),
|
|
}).strict()
|
|
|
|
export const ixLinuxClientRequest = z.object({
|
|
revision: z.number().int().positive(),
|
|
serverId,
|
|
interfaceName: interfaceName.optional(),
|
|
name: linuxPolicy.shape.name,
|
|
enabled: z.boolean().default(true),
|
|
kind: z.enum(["wireguard", "gre-ipsec"]),
|
|
additionalGre: z.boolean().optional(),
|
|
vpsClientId: z.uuid().optional(),
|
|
companionOf: interfaceName.optional(),
|
|
hubEndpoint: address,
|
|
peerEndpoint: address.optional(),
|
|
peerPublicKey: wireguardProvision.shape.peerPublicKey.optional(),
|
|
localAddress: prefix.optional(),
|
|
peerAddress: address.optional(),
|
|
prefixes: z.array(prefix).max(64).default([]),
|
|
destinations: linuxPolicy.shape.destinations.default([]),
|
|
tunnelMtu: linuxPolicy.shape.tunnelMtu,
|
|
exit: key.optional(),
|
|
transit: ixTransitOptions.optional(),
|
|
rotate: z.boolean().optional(),
|
|
}).strict().refine(input => !input.transit || !input.exit || input.exit === input.transit.name,
|
|
{ path: ["exit"], message: "Выход клиента должен совпадать с выбранным транзитом" })
|
|
.refine(input => !input.vpsClientId || !input.companionOf,
|
|
"Новый туннель наследует VPS исходного подключения.")
|
|
.refine(input => (!input.companionOf || !input.interfaceName) &&
|
|
(!input.additionalGre || input.kind === "wireguard" && !input.interfaceName && !input.companionOf),
|
|
"Оба протокола можно создать для нового клиента. Для существующего добавьте второй протокол.")
|
|
|
|
export type IxLinuxClientRequest = z.infer<typeof ixLinuxClientRequest>
|
|
|
|
export const ixTransitRequest = ixTransitOptions.extend({
|
|
revision: z.number().int().positive(),
|
|
serverId,
|
|
})
|
|
|
|
export type IxTransitRequest = z.infer<typeof ixTransitRequest>
|
|
|
|
export interface IxNodeInventory {
|
|
observedAt: string
|
|
routerId: string | null
|
|
interfaces: Array<{
|
|
name: string
|
|
type: string
|
|
running: boolean
|
|
disabled: boolean
|
|
addresses: string[]
|
|
restriction: string | null
|
|
}>
|
|
wireguardPorts: number[]
|
|
defaultRoutes: Array<{ family: 4 | 6; gateway: string; interface: string }>
|
|
}
|
|
|
|
export interface IxSegment {
|
|
id: string
|
|
revision: number
|
|
appliedRevision: number | null
|
|
configuration: IxConfiguration
|
|
updatedAt: string
|
|
}
|
|
|
|
export interface IxRouterObject {
|
|
serverId: number
|
|
path: string
|
|
fields: Record<string, string>
|
|
}
|
|
|
|
export interface IxWebPlan {
|
|
revision: number
|
|
digest: string
|
|
resume?: boolean
|
|
changes: Array<IxRouterObject & { action: "create" | "update" | "delete"; target?: string; placeBefore?: string }>
|
|
}
|
|
|
|
export interface IxLinuxBinding {
|
|
serverId: number
|
|
interfaceName: string
|
|
kind: "wireguard" | "gre-ipsec"
|
|
name?: string
|
|
managedWireguard?: boolean
|
|
enabled?: boolean
|
|
policy?: IxSite["interfaces"][number]["linux"]
|
|
connection?: { state: "connected" | "waiting" | "unknown"; observedAt: string; rx?: string; tx?: string }
|
|
}
|
|
|
|
export interface IxLinuxAccess {
|
|
hubPublicKey?: string
|
|
kind: IxLinuxBinding["kind"]
|
|
revision: number
|
|
filename: string
|
|
template: string
|
|
setup?: string
|
|
bgp?: {
|
|
localAs: number
|
|
remoteAs: number
|
|
neighbor: string
|
|
advertisedPrefixes: string[]
|
|
}
|
|
}
|
|
|
|
export interface IxSiteObservation {
|
|
serverId: number
|
|
observedAt: string
|
|
available: boolean
|
|
routes: Array<{ prefix: string; gateway: string; immediateGateway: string | null; active: boolean }>
|
|
neighbors: Array<{ name: string; established: boolean }>
|
|
}
|
|
|
|
export interface IxLinuxPath {
|
|
observedAt: string
|
|
table: string
|
|
policy: string | null
|
|
routes: IxSiteObservation["routes"]
|
|
}
|