forked from mtusi2026/mtusi2026lab7
29 lines
986 B
TypeScript
29 lines
986 B
TypeScript
import { requireThat, project } from "./runtime";
|
|
export function publicLBEndpoint(inspection: any): {
|
|
host: string;
|
|
port: number;
|
|
servername: string;
|
|
} {
|
|
requireThat(
|
|
inspection?.Config?.Labels?.["com.docker.compose.project"] === project &&
|
|
inspection?.Config?.Labels?.["com.docker.compose.service"] === "lb" &&
|
|
inspection?.State?.Running === true,
|
|
"LB_RESOURCE_GUARD_FAILED",
|
|
);
|
|
const bindings = inspection?.NetworkSettings?.Ports?.["8443/tcp"];
|
|
requireThat(
|
|
Array.isArray(bindings) && bindings.length === 1,
|
|
"LB_PUBLIC_TLS_BINDING_MISSING",
|
|
);
|
|
const binding = bindings[0];
|
|
requireThat(
|
|
binding.HostIp === "127.0.0.1" &&
|
|
typeof binding.HostPort === "string" &&
|
|
/^[0-9]{1,5}$/.test(binding.HostPort),
|
|
"LB_PUBLIC_TLS_BINDING_UNSAFE",
|
|
);
|
|
const port = Number(binding.HostPort);
|
|
requireThat(port >= 1 && port <= 65535, "LB_PUBLIC_TLS_PORT_INVALID");
|
|
return { host: "127.0.0.1", port, servername: "localhost" };
|
|
}
|