Files
opspul/src/validator.ts
T
lyrgb 41c37156af now uses formatters instead of hardcoded chain off individual configs
added formatter type to associate a service with their templates and
filepaths
2026-07-16 02:04:04 +02:00

27 lines
663 B
TypeScript

import type { Service } from "./types";
/**
should validate config, for now just checks for port collisions
**/
export class ConfigValidator {
static validatecaddyfile(services: Service[]){
const hostports = new Map<string, Set<number>>();
for (const service of services) {
const hostip = service.host.ip;
if (!hostports.has(hostip)) {
hostports.set(hostip, new Set());
}
const ports = hostports.get(hostip)!;
if (ports.has(service.port)) {
throw new Error(`port collision: host ${hostip} already has a service on ${service.port}(${service.name})`)
}
ports.add(service.port);
}
console.log("validated collision");
}
}