mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-10 15:24:58 +00:00
29 lines
936 B
TypeScript
29 lines
936 B
TypeScript
export type NetworkModeBlockReason = "host" | "container_namespace_join";
|
|
|
|
export function normalizeNetworkMode(network: string | undefined): string | undefined {
|
|
const normalized = network?.trim().toLowerCase();
|
|
return normalized || undefined;
|
|
}
|
|
|
|
export function getBlockedNetworkModeReason(params: {
|
|
network: string | undefined;
|
|
allowContainerNamespaceJoin?: boolean;
|
|
}): NetworkModeBlockReason | null {
|
|
const normalized = normalizeNetworkMode(params.network);
|
|
if (!normalized) {
|
|
return null;
|
|
}
|
|
if (normalized === "host") {
|
|
return "host";
|
|
}
|
|
if (normalized.startsWith("container:") && params.allowContainerNamespaceJoin !== true) {
|
|
return "container_namespace_join";
|
|
}
|
|
return null;
|
|
}
|
|
|
|
export function isDangerousNetworkMode(network: string | undefined): boolean {
|
|
const normalized = normalizeNetworkMode(network);
|
|
return normalized === "host" || normalized?.startsWith("container:") === true;
|
|
}
|