added load balancing settings
This commit is contained in:
@@ -21,6 +21,98 @@ const DEFAULT_AUTHENTIK_HEADERS = [
|
||||
|
||||
const DEFAULT_AUTHENTIK_TRUSTED_PROXIES = ["private_ranges"];
|
||||
|
||||
// Load Balancer Types
|
||||
export type LoadBalancingPolicy = "random" | "round_robin" | "least_conn" | "ip_hash" | "first" | "header" | "cookie" | "uri_hash";
|
||||
|
||||
export type LoadBalancerActiveHealthCheck = {
|
||||
enabled: boolean;
|
||||
uri: string | null;
|
||||
port: number | null;
|
||||
interval: string | null;
|
||||
timeout: string | null;
|
||||
status: number | null;
|
||||
body: string | null;
|
||||
};
|
||||
|
||||
export type LoadBalancerPassiveHealthCheck = {
|
||||
enabled: boolean;
|
||||
failDuration: string | null;
|
||||
maxFails: number | null;
|
||||
unhealthyStatus: number[] | null;
|
||||
unhealthyLatency: string | null;
|
||||
};
|
||||
|
||||
export type LoadBalancerConfig = {
|
||||
enabled: boolean;
|
||||
policy: LoadBalancingPolicy;
|
||||
policyHeaderField: string | null;
|
||||
policyCookieName: string | null;
|
||||
policyCookieSecret: string | null;
|
||||
tryDuration: string | null;
|
||||
tryInterval: string | null;
|
||||
retries: number | null;
|
||||
activeHealthCheck: LoadBalancerActiveHealthCheck | null;
|
||||
passiveHealthCheck: LoadBalancerPassiveHealthCheck | null;
|
||||
};
|
||||
|
||||
export type LoadBalancerInput = {
|
||||
enabled?: boolean;
|
||||
policy?: LoadBalancingPolicy;
|
||||
policyHeaderField?: string | null;
|
||||
policyCookieName?: string | null;
|
||||
policyCookieSecret?: string | null;
|
||||
tryDuration?: string | null;
|
||||
tryInterval?: string | null;
|
||||
retries?: number | null;
|
||||
activeHealthCheck?: {
|
||||
enabled?: boolean;
|
||||
uri?: string | null;
|
||||
port?: number | null;
|
||||
interval?: string | null;
|
||||
timeout?: string | null;
|
||||
status?: number | null;
|
||||
body?: string | null;
|
||||
} | null;
|
||||
passiveHealthCheck?: {
|
||||
enabled?: boolean;
|
||||
failDuration?: string | null;
|
||||
maxFails?: number | null;
|
||||
unhealthyStatus?: number[] | null;
|
||||
unhealthyLatency?: string | null;
|
||||
} | null;
|
||||
};
|
||||
|
||||
type LoadBalancerActiveHealthCheckMeta = {
|
||||
enabled?: boolean;
|
||||
uri?: string;
|
||||
port?: number;
|
||||
interval?: string;
|
||||
timeout?: string;
|
||||
status?: number;
|
||||
body?: string;
|
||||
};
|
||||
|
||||
type LoadBalancerPassiveHealthCheckMeta = {
|
||||
enabled?: boolean;
|
||||
fail_duration?: string;
|
||||
max_fails?: number;
|
||||
unhealthy_status?: number[];
|
||||
unhealthy_latency?: string;
|
||||
};
|
||||
|
||||
type LoadBalancerMeta = {
|
||||
enabled?: boolean;
|
||||
policy?: string;
|
||||
policy_header_field?: string;
|
||||
policy_cookie_name?: string;
|
||||
policy_cookie_secret?: string;
|
||||
try_duration?: string;
|
||||
try_interval?: string;
|
||||
retries?: number;
|
||||
active_health_check?: LoadBalancerActiveHealthCheckMeta;
|
||||
passive_health_check?: LoadBalancerPassiveHealthCheckMeta;
|
||||
};
|
||||
|
||||
export type ProxyHostAuthentikConfig = {
|
||||
enabled: boolean;
|
||||
outpostDomain: string | null;
|
||||
@@ -58,6 +150,7 @@ type ProxyHostMeta = {
|
||||
custom_reverse_proxy_json?: string;
|
||||
custom_pre_handlers_json?: string;
|
||||
authentik?: ProxyHostAuthentikMeta;
|
||||
load_balancer?: LoadBalancerMeta;
|
||||
};
|
||||
|
||||
export type ProxyHost = {
|
||||
@@ -79,6 +172,7 @@ export type ProxyHost = {
|
||||
custom_reverse_proxy_json: string | null;
|
||||
custom_pre_handlers_json: string | null;
|
||||
authentik: ProxyHostAuthentikConfig | null;
|
||||
load_balancer: LoadBalancerConfig | null;
|
||||
};
|
||||
|
||||
export type ProxyHostInput = {
|
||||
@@ -97,6 +191,7 @@ export type ProxyHostInput = {
|
||||
custom_reverse_proxy_json?: string | null;
|
||||
custom_pre_handlers_json?: string | null;
|
||||
authentik?: ProxyHostAuthentikInput | null;
|
||||
load_balancer?: LoadBalancerInput | null;
|
||||
};
|
||||
|
||||
type ProxyHostRow = typeof proxyHosts.$inferSelect;
|
||||
@@ -163,6 +258,114 @@ function sanitizeAuthentikMeta(meta: ProxyHostAuthentikMeta | undefined): ProxyH
|
||||
return Object.keys(normalized).length > 0 ? normalized : undefined;
|
||||
}
|
||||
|
||||
const VALID_LB_POLICIES: LoadBalancingPolicy[] = ["random", "round_robin", "least_conn", "ip_hash", "first", "header", "cookie", "uri_hash"];
|
||||
|
||||
function sanitizeLoadBalancerMeta(meta: LoadBalancerMeta | undefined): LoadBalancerMeta | undefined {
|
||||
if (!meta) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
const normalized: LoadBalancerMeta = {};
|
||||
|
||||
if (meta.enabled !== undefined) {
|
||||
normalized.enabled = Boolean(meta.enabled);
|
||||
}
|
||||
|
||||
if (meta.policy && VALID_LB_POLICIES.includes(meta.policy as LoadBalancingPolicy)) {
|
||||
normalized.policy = meta.policy;
|
||||
}
|
||||
|
||||
const headerField = normalizeMetaValue(meta.policy_header_field ?? null);
|
||||
if (headerField) {
|
||||
normalized.policy_header_field = headerField;
|
||||
}
|
||||
|
||||
const cookieName = normalizeMetaValue(meta.policy_cookie_name ?? null);
|
||||
if (cookieName) {
|
||||
normalized.policy_cookie_name = cookieName;
|
||||
}
|
||||
|
||||
const cookieSecret = normalizeMetaValue(meta.policy_cookie_secret ?? null);
|
||||
if (cookieSecret) {
|
||||
normalized.policy_cookie_secret = cookieSecret;
|
||||
}
|
||||
|
||||
const tryDuration = normalizeMetaValue(meta.try_duration ?? null);
|
||||
if (tryDuration) {
|
||||
normalized.try_duration = tryDuration;
|
||||
}
|
||||
|
||||
const tryInterval = normalizeMetaValue(meta.try_interval ?? null);
|
||||
if (tryInterval) {
|
||||
normalized.try_interval = tryInterval;
|
||||
}
|
||||
|
||||
if (typeof meta.retries === "number" && Number.isFinite(meta.retries) && meta.retries >= 0) {
|
||||
normalized.retries = meta.retries;
|
||||
}
|
||||
|
||||
if (meta.active_health_check) {
|
||||
const ahc: LoadBalancerActiveHealthCheckMeta = {};
|
||||
if (meta.active_health_check.enabled !== undefined) {
|
||||
ahc.enabled = Boolean(meta.active_health_check.enabled);
|
||||
}
|
||||
const uri = normalizeMetaValue(meta.active_health_check.uri ?? null);
|
||||
if (uri) {
|
||||
ahc.uri = uri;
|
||||
}
|
||||
if (typeof meta.active_health_check.port === "number" && Number.isFinite(meta.active_health_check.port) && meta.active_health_check.port > 0) {
|
||||
ahc.port = meta.active_health_check.port;
|
||||
}
|
||||
const interval = normalizeMetaValue(meta.active_health_check.interval ?? null);
|
||||
if (interval) {
|
||||
ahc.interval = interval;
|
||||
}
|
||||
const timeout = normalizeMetaValue(meta.active_health_check.timeout ?? null);
|
||||
if (timeout) {
|
||||
ahc.timeout = timeout;
|
||||
}
|
||||
if (typeof meta.active_health_check.status === "number" && Number.isFinite(meta.active_health_check.status) && meta.active_health_check.status >= 100) {
|
||||
ahc.status = meta.active_health_check.status;
|
||||
}
|
||||
const body = normalizeMetaValue(meta.active_health_check.body ?? null);
|
||||
if (body) {
|
||||
ahc.body = body;
|
||||
}
|
||||
if (Object.keys(ahc).length > 0) {
|
||||
normalized.active_health_check = ahc;
|
||||
}
|
||||
}
|
||||
|
||||
if (meta.passive_health_check) {
|
||||
const phc: LoadBalancerPassiveHealthCheckMeta = {};
|
||||
if (meta.passive_health_check.enabled !== undefined) {
|
||||
phc.enabled = Boolean(meta.passive_health_check.enabled);
|
||||
}
|
||||
const failDuration = normalizeMetaValue(meta.passive_health_check.fail_duration ?? null);
|
||||
if (failDuration) {
|
||||
phc.fail_duration = failDuration;
|
||||
}
|
||||
if (typeof meta.passive_health_check.max_fails === "number" && Number.isFinite(meta.passive_health_check.max_fails) && meta.passive_health_check.max_fails >= 0) {
|
||||
phc.max_fails = meta.passive_health_check.max_fails;
|
||||
}
|
||||
if (Array.isArray(meta.passive_health_check.unhealthy_status)) {
|
||||
const statuses = meta.passive_health_check.unhealthy_status.filter((s): s is number => typeof s === "number" && Number.isFinite(s) && s >= 100);
|
||||
if (statuses.length > 0) {
|
||||
phc.unhealthy_status = statuses;
|
||||
}
|
||||
}
|
||||
const unhealthyLatency = normalizeMetaValue(meta.passive_health_check.unhealthy_latency ?? null);
|
||||
if (unhealthyLatency) {
|
||||
phc.unhealthy_latency = unhealthyLatency;
|
||||
}
|
||||
if (Object.keys(phc).length > 0) {
|
||||
normalized.passive_health_check = phc;
|
||||
}
|
||||
}
|
||||
|
||||
return Object.keys(normalized).length > 0 ? normalized : undefined;
|
||||
}
|
||||
|
||||
function serializeMeta(meta: ProxyHostMeta | null | undefined) {
|
||||
if (!meta) {
|
||||
return null;
|
||||
@@ -183,6 +386,11 @@ function serializeMeta(meta: ProxyHostMeta | null | undefined) {
|
||||
normalized.authentik = authentik;
|
||||
}
|
||||
|
||||
const loadBalancer = sanitizeLoadBalancerMeta(meta.load_balancer);
|
||||
if (loadBalancer) {
|
||||
normalized.load_balancer = loadBalancer;
|
||||
}
|
||||
|
||||
return Object.keys(normalized).length > 0 ? JSON.stringify(normalized) : null;
|
||||
}
|
||||
|
||||
@@ -195,7 +403,8 @@ function parseMeta(value: string | null): ProxyHostMeta {
|
||||
return {
|
||||
custom_reverse_proxy_json: normalizeMetaValue(parsed.custom_reverse_proxy_json ?? null) ?? undefined,
|
||||
custom_pre_handlers_json: normalizeMetaValue(parsed.custom_pre_handlers_json ?? null) ?? undefined,
|
||||
authentik: sanitizeAuthentikMeta(parsed.authentik)
|
||||
authentik: sanitizeAuthentikMeta(parsed.authentik),
|
||||
load_balancer: sanitizeLoadBalancerMeta(parsed.load_balancer)
|
||||
};
|
||||
} catch (error) {
|
||||
console.warn("Failed to parse proxy host meta", error);
|
||||
@@ -291,6 +500,204 @@ function normalizeAuthentikInput(
|
||||
return Object.keys(next).length > 0 ? next : undefined;
|
||||
}
|
||||
|
||||
function normalizeLoadBalancerInput(
|
||||
input: LoadBalancerInput | null | undefined,
|
||||
existing: LoadBalancerMeta | undefined
|
||||
): LoadBalancerMeta | undefined {
|
||||
if (input === undefined) {
|
||||
return existing;
|
||||
}
|
||||
if (input === null) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
const next: LoadBalancerMeta = { ...(existing ?? {}) };
|
||||
|
||||
if (input.enabled !== undefined) {
|
||||
next.enabled = Boolean(input.enabled);
|
||||
}
|
||||
|
||||
if (input.policy !== undefined) {
|
||||
if (input.policy && VALID_LB_POLICIES.includes(input.policy)) {
|
||||
next.policy = input.policy;
|
||||
} else {
|
||||
delete next.policy;
|
||||
}
|
||||
}
|
||||
|
||||
if (input.policyHeaderField !== undefined) {
|
||||
const val = normalizeMetaValue(input.policyHeaderField ?? null);
|
||||
if (val) {
|
||||
next.policy_header_field = val;
|
||||
} else {
|
||||
delete next.policy_header_field;
|
||||
}
|
||||
}
|
||||
|
||||
if (input.policyCookieName !== undefined) {
|
||||
const val = normalizeMetaValue(input.policyCookieName ?? null);
|
||||
if (val) {
|
||||
next.policy_cookie_name = val;
|
||||
} else {
|
||||
delete next.policy_cookie_name;
|
||||
}
|
||||
}
|
||||
|
||||
if (input.policyCookieSecret !== undefined) {
|
||||
const val = normalizeMetaValue(input.policyCookieSecret ?? null);
|
||||
if (val) {
|
||||
next.policy_cookie_secret = val;
|
||||
} else {
|
||||
delete next.policy_cookie_secret;
|
||||
}
|
||||
}
|
||||
|
||||
if (input.tryDuration !== undefined) {
|
||||
const val = normalizeMetaValue(input.tryDuration ?? null);
|
||||
if (val) {
|
||||
next.try_duration = val;
|
||||
} else {
|
||||
delete next.try_duration;
|
||||
}
|
||||
}
|
||||
|
||||
if (input.tryInterval !== undefined) {
|
||||
const val = normalizeMetaValue(input.tryInterval ?? null);
|
||||
if (val) {
|
||||
next.try_interval = val;
|
||||
} else {
|
||||
delete next.try_interval;
|
||||
}
|
||||
}
|
||||
|
||||
if (input.retries !== undefined) {
|
||||
if (typeof input.retries === "number" && Number.isFinite(input.retries) && input.retries >= 0) {
|
||||
next.retries = input.retries;
|
||||
} else {
|
||||
delete next.retries;
|
||||
}
|
||||
}
|
||||
|
||||
if (input.activeHealthCheck !== undefined) {
|
||||
if (input.activeHealthCheck === null) {
|
||||
delete next.active_health_check;
|
||||
} else {
|
||||
const ahc: LoadBalancerActiveHealthCheckMeta = { ...(existing?.active_health_check ?? {}) };
|
||||
|
||||
if (input.activeHealthCheck.enabled !== undefined) {
|
||||
ahc.enabled = Boolean(input.activeHealthCheck.enabled);
|
||||
}
|
||||
if (input.activeHealthCheck.uri !== undefined) {
|
||||
const val = normalizeMetaValue(input.activeHealthCheck.uri ?? null);
|
||||
if (val) {
|
||||
ahc.uri = val;
|
||||
} else {
|
||||
delete ahc.uri;
|
||||
}
|
||||
}
|
||||
if (input.activeHealthCheck.port !== undefined) {
|
||||
if (typeof input.activeHealthCheck.port === "number" && Number.isFinite(input.activeHealthCheck.port) && input.activeHealthCheck.port > 0) {
|
||||
ahc.port = input.activeHealthCheck.port;
|
||||
} else {
|
||||
delete ahc.port;
|
||||
}
|
||||
}
|
||||
if (input.activeHealthCheck.interval !== undefined) {
|
||||
const val = normalizeMetaValue(input.activeHealthCheck.interval ?? null);
|
||||
if (val) {
|
||||
ahc.interval = val;
|
||||
} else {
|
||||
delete ahc.interval;
|
||||
}
|
||||
}
|
||||
if (input.activeHealthCheck.timeout !== undefined) {
|
||||
const val = normalizeMetaValue(input.activeHealthCheck.timeout ?? null);
|
||||
if (val) {
|
||||
ahc.timeout = val;
|
||||
} else {
|
||||
delete ahc.timeout;
|
||||
}
|
||||
}
|
||||
if (input.activeHealthCheck.status !== undefined) {
|
||||
if (typeof input.activeHealthCheck.status === "number" && Number.isFinite(input.activeHealthCheck.status) && input.activeHealthCheck.status >= 100) {
|
||||
ahc.status = input.activeHealthCheck.status;
|
||||
} else {
|
||||
delete ahc.status;
|
||||
}
|
||||
}
|
||||
if (input.activeHealthCheck.body !== undefined) {
|
||||
const val = normalizeMetaValue(input.activeHealthCheck.body ?? null);
|
||||
if (val) {
|
||||
ahc.body = val;
|
||||
} else {
|
||||
delete ahc.body;
|
||||
}
|
||||
}
|
||||
|
||||
if (Object.keys(ahc).length > 0) {
|
||||
next.active_health_check = ahc;
|
||||
} else {
|
||||
delete next.active_health_check;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (input.passiveHealthCheck !== undefined) {
|
||||
if (input.passiveHealthCheck === null) {
|
||||
delete next.passive_health_check;
|
||||
} else {
|
||||
const phc: LoadBalancerPassiveHealthCheckMeta = { ...(existing?.passive_health_check ?? {}) };
|
||||
|
||||
if (input.passiveHealthCheck.enabled !== undefined) {
|
||||
phc.enabled = Boolean(input.passiveHealthCheck.enabled);
|
||||
}
|
||||
if (input.passiveHealthCheck.failDuration !== undefined) {
|
||||
const val = normalizeMetaValue(input.passiveHealthCheck.failDuration ?? null);
|
||||
if (val) {
|
||||
phc.fail_duration = val;
|
||||
} else {
|
||||
delete phc.fail_duration;
|
||||
}
|
||||
}
|
||||
if (input.passiveHealthCheck.maxFails !== undefined) {
|
||||
if (typeof input.passiveHealthCheck.maxFails === "number" && Number.isFinite(input.passiveHealthCheck.maxFails) && input.passiveHealthCheck.maxFails >= 0) {
|
||||
phc.max_fails = input.passiveHealthCheck.maxFails;
|
||||
} else {
|
||||
delete phc.max_fails;
|
||||
}
|
||||
}
|
||||
if (input.passiveHealthCheck.unhealthyStatus !== undefined) {
|
||||
if (Array.isArray(input.passiveHealthCheck.unhealthyStatus)) {
|
||||
const statuses = input.passiveHealthCheck.unhealthyStatus.filter((s): s is number => typeof s === "number" && Number.isFinite(s) && s >= 100);
|
||||
if (statuses.length > 0) {
|
||||
phc.unhealthy_status = statuses;
|
||||
} else {
|
||||
delete phc.unhealthy_status;
|
||||
}
|
||||
} else {
|
||||
delete phc.unhealthy_status;
|
||||
}
|
||||
}
|
||||
if (input.passiveHealthCheck.unhealthyLatency !== undefined) {
|
||||
const val = normalizeMetaValue(input.passiveHealthCheck.unhealthyLatency ?? null);
|
||||
if (val) {
|
||||
phc.unhealthy_latency = val;
|
||||
} else {
|
||||
delete phc.unhealthy_latency;
|
||||
}
|
||||
}
|
||||
|
||||
if (Object.keys(phc).length > 0) {
|
||||
next.passive_health_check = phc;
|
||||
} else {
|
||||
delete next.passive_health_check;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return Object.keys(next).length > 0 ? next : undefined;
|
||||
}
|
||||
|
||||
function buildMeta(existing: ProxyHostMeta, input: Partial<ProxyHostInput>): string | null {
|
||||
const next: ProxyHostMeta = { ...existing };
|
||||
|
||||
@@ -321,6 +728,15 @@ function buildMeta(existing: ProxyHostMeta, input: Partial<ProxyHostInput>): str
|
||||
}
|
||||
}
|
||||
|
||||
if (input.load_balancer !== undefined) {
|
||||
const loadBalancer = normalizeLoadBalancerInput(input.load_balancer, existing.load_balancer);
|
||||
if (loadBalancer) {
|
||||
next.load_balancer = loadBalancer;
|
||||
} else {
|
||||
delete next.load_balancer;
|
||||
}
|
||||
}
|
||||
|
||||
return serializeMeta(next);
|
||||
}
|
||||
|
||||
@@ -389,6 +805,149 @@ function dehydrateAuthentik(config: ProxyHostAuthentikConfig | null): ProxyHostA
|
||||
return meta;
|
||||
}
|
||||
|
||||
function hydrateLoadBalancer(meta: LoadBalancerMeta | undefined): LoadBalancerConfig | null {
|
||||
if (!meta) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const enabled = Boolean(meta.enabled);
|
||||
const policy: LoadBalancingPolicy = (meta.policy && VALID_LB_POLICIES.includes(meta.policy as LoadBalancingPolicy))
|
||||
? (meta.policy as LoadBalancingPolicy)
|
||||
: "random";
|
||||
|
||||
const policyHeaderField = normalizeMetaValue(meta.policy_header_field ?? null);
|
||||
const policyCookieName = normalizeMetaValue(meta.policy_cookie_name ?? null);
|
||||
const policyCookieSecret = normalizeMetaValue(meta.policy_cookie_secret ?? null);
|
||||
const tryDuration = normalizeMetaValue(meta.try_duration ?? null);
|
||||
const tryInterval = normalizeMetaValue(meta.try_interval ?? null);
|
||||
const retries = typeof meta.retries === "number" && Number.isFinite(meta.retries) && meta.retries >= 0 ? meta.retries : null;
|
||||
|
||||
let activeHealthCheck: LoadBalancerActiveHealthCheck | null = null;
|
||||
if (meta.active_health_check) {
|
||||
activeHealthCheck = {
|
||||
enabled: Boolean(meta.active_health_check.enabled),
|
||||
uri: normalizeMetaValue(meta.active_health_check.uri ?? null),
|
||||
port: typeof meta.active_health_check.port === "number" && Number.isFinite(meta.active_health_check.port) && meta.active_health_check.port > 0
|
||||
? meta.active_health_check.port
|
||||
: null,
|
||||
interval: normalizeMetaValue(meta.active_health_check.interval ?? null),
|
||||
timeout: normalizeMetaValue(meta.active_health_check.timeout ?? null),
|
||||
status: typeof meta.active_health_check.status === "number" && Number.isFinite(meta.active_health_check.status) && meta.active_health_check.status >= 100
|
||||
? meta.active_health_check.status
|
||||
: null,
|
||||
body: normalizeMetaValue(meta.active_health_check.body ?? null)
|
||||
};
|
||||
}
|
||||
|
||||
let passiveHealthCheck: LoadBalancerPassiveHealthCheck | null = null;
|
||||
if (meta.passive_health_check) {
|
||||
const unhealthyStatus = Array.isArray(meta.passive_health_check.unhealthy_status)
|
||||
? meta.passive_health_check.unhealthy_status.filter((s): s is number => typeof s === "number" && Number.isFinite(s) && s >= 100)
|
||||
: null;
|
||||
|
||||
passiveHealthCheck = {
|
||||
enabled: Boolean(meta.passive_health_check.enabled),
|
||||
failDuration: normalizeMetaValue(meta.passive_health_check.fail_duration ?? null),
|
||||
maxFails: typeof meta.passive_health_check.max_fails === "number" && Number.isFinite(meta.passive_health_check.max_fails) && meta.passive_health_check.max_fails >= 0
|
||||
? meta.passive_health_check.max_fails
|
||||
: null,
|
||||
unhealthyStatus: unhealthyStatus && unhealthyStatus.length > 0 ? unhealthyStatus : null,
|
||||
unhealthyLatency: normalizeMetaValue(meta.passive_health_check.unhealthy_latency ?? null)
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
enabled,
|
||||
policy,
|
||||
policyHeaderField,
|
||||
policyCookieName,
|
||||
policyCookieSecret,
|
||||
tryDuration,
|
||||
tryInterval,
|
||||
retries,
|
||||
activeHealthCheck,
|
||||
passiveHealthCheck
|
||||
};
|
||||
}
|
||||
|
||||
function dehydrateLoadBalancer(config: LoadBalancerConfig | null): LoadBalancerMeta | undefined {
|
||||
if (!config) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
const meta: LoadBalancerMeta = {
|
||||
enabled: config.enabled
|
||||
};
|
||||
|
||||
if (config.policy) {
|
||||
meta.policy = config.policy;
|
||||
}
|
||||
if (config.policyHeaderField) {
|
||||
meta.policy_header_field = config.policyHeaderField;
|
||||
}
|
||||
if (config.policyCookieName) {
|
||||
meta.policy_cookie_name = config.policyCookieName;
|
||||
}
|
||||
if (config.policyCookieSecret) {
|
||||
meta.policy_cookie_secret = config.policyCookieSecret;
|
||||
}
|
||||
if (config.tryDuration) {
|
||||
meta.try_duration = config.tryDuration;
|
||||
}
|
||||
if (config.tryInterval) {
|
||||
meta.try_interval = config.tryInterval;
|
||||
}
|
||||
if (config.retries !== null) {
|
||||
meta.retries = config.retries;
|
||||
}
|
||||
|
||||
if (config.activeHealthCheck) {
|
||||
const ahc: LoadBalancerActiveHealthCheckMeta = {
|
||||
enabled: config.activeHealthCheck.enabled
|
||||
};
|
||||
if (config.activeHealthCheck.uri) {
|
||||
ahc.uri = config.activeHealthCheck.uri;
|
||||
}
|
||||
if (config.activeHealthCheck.port !== null) {
|
||||
ahc.port = config.activeHealthCheck.port;
|
||||
}
|
||||
if (config.activeHealthCheck.interval) {
|
||||
ahc.interval = config.activeHealthCheck.interval;
|
||||
}
|
||||
if (config.activeHealthCheck.timeout) {
|
||||
ahc.timeout = config.activeHealthCheck.timeout;
|
||||
}
|
||||
if (config.activeHealthCheck.status !== null) {
|
||||
ahc.status = config.activeHealthCheck.status;
|
||||
}
|
||||
if (config.activeHealthCheck.body) {
|
||||
ahc.body = config.activeHealthCheck.body;
|
||||
}
|
||||
meta.active_health_check = ahc;
|
||||
}
|
||||
|
||||
if (config.passiveHealthCheck) {
|
||||
const phc: LoadBalancerPassiveHealthCheckMeta = {
|
||||
enabled: config.passiveHealthCheck.enabled
|
||||
};
|
||||
if (config.passiveHealthCheck.failDuration) {
|
||||
phc.fail_duration = config.passiveHealthCheck.failDuration;
|
||||
}
|
||||
if (config.passiveHealthCheck.maxFails !== null) {
|
||||
phc.max_fails = config.passiveHealthCheck.maxFails;
|
||||
}
|
||||
if (config.passiveHealthCheck.unhealthyStatus && config.passiveHealthCheck.unhealthyStatus.length > 0) {
|
||||
phc.unhealthy_status = [...config.passiveHealthCheck.unhealthyStatus];
|
||||
}
|
||||
if (config.passiveHealthCheck.unhealthyLatency) {
|
||||
phc.unhealthy_latency = config.passiveHealthCheck.unhealthyLatency;
|
||||
}
|
||||
meta.passive_health_check = phc;
|
||||
}
|
||||
|
||||
return meta;
|
||||
}
|
||||
|
||||
function parseProxyHost(row: ProxyHostRow): ProxyHost {
|
||||
const meta = parseMeta(row.meta ?? null);
|
||||
return {
|
||||
@@ -409,7 +968,8 @@ function parseProxyHost(row: ProxyHostRow): ProxyHost {
|
||||
updated_at: toIso(row.updatedAt)!,
|
||||
custom_reverse_proxy_json: meta.custom_reverse_proxy_json ?? null,
|
||||
custom_pre_handlers_json: meta.custom_pre_handlers_json ?? null,
|
||||
authentik: hydrateAuthentik(meta.authentik)
|
||||
authentik: hydrateAuthentik(meta.authentik),
|
||||
load_balancer: hydrateLoadBalancer(meta.load_balancer)
|
||||
};
|
||||
}
|
||||
|
||||
@@ -485,7 +1045,8 @@ export async function updateProxyHost(id: number, input: Partial<ProxyHostInput>
|
||||
const existingMeta: ProxyHostMeta = {
|
||||
custom_reverse_proxy_json: existing.custom_reverse_proxy_json ?? undefined,
|
||||
custom_pre_handlers_json: existing.custom_pre_handlers_json ?? undefined,
|
||||
authentik: dehydrateAuthentik(existing.authentik)
|
||||
authentik: dehydrateAuthentik(existing.authentik),
|
||||
load_balancer: dehydrateLoadBalancer(existing.load_balancer)
|
||||
};
|
||||
const meta = buildMeta(existingMeta, input);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user