mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-09 13:07:39 +00:00
refactor: unify shared utility normalization helpers
This commit is contained in:
@@ -155,6 +155,16 @@ function pickTailnetIPv4(
|
||||
return pickIPv4Matching(networkInterfaces, isTailnetIPv4);
|
||||
}
|
||||
|
||||
function resolveGatewayTokenFromEnv(env: NodeJS.ProcessEnv): string | undefined {
|
||||
return env.OPENCLAW_GATEWAY_TOKEN?.trim() || env.CLAWDBOT_GATEWAY_TOKEN?.trim() || undefined;
|
||||
}
|
||||
|
||||
function resolveGatewayPasswordFromEnv(env: NodeJS.ProcessEnv): string | undefined {
|
||||
return (
|
||||
env.OPENCLAW_GATEWAY_PASSWORD?.trim() || env.CLAWDBOT_GATEWAY_PASSWORD?.trim() || undefined
|
||||
);
|
||||
}
|
||||
|
||||
function resolveAuth(cfg: OpenClawConfig, env: NodeJS.ProcessEnv): ResolveAuthResult {
|
||||
const mode = cfg.gateway?.auth?.mode;
|
||||
const defaults = cfg.secrets?.defaults;
|
||||
@@ -166,13 +176,12 @@ function resolveAuth(cfg: OpenClawConfig, env: NodeJS.ProcessEnv): ResolveAuthRe
|
||||
value: cfg.gateway?.auth?.password,
|
||||
defaults,
|
||||
}).ref;
|
||||
const envToken = resolveGatewayTokenFromEnv(env);
|
||||
const envPassword = resolveGatewayPasswordFromEnv(env);
|
||||
const token =
|
||||
env.OPENCLAW_GATEWAY_TOKEN?.trim() ||
|
||||
env.CLAWDBOT_GATEWAY_TOKEN?.trim() ||
|
||||
(tokenRef ? undefined : normalizeSecretInputString(cfg.gateway?.auth?.token));
|
||||
envToken || (tokenRef ? undefined : normalizeSecretInputString(cfg.gateway?.auth?.token));
|
||||
const password =
|
||||
env.OPENCLAW_GATEWAY_PASSWORD?.trim() ||
|
||||
env.CLAWDBOT_GATEWAY_PASSWORD?.trim() ||
|
||||
envPassword ||
|
||||
(passwordRef ? undefined : normalizeSecretInputString(cfg.gateway?.auth?.password));
|
||||
|
||||
if (mode === "password") {
|
||||
@@ -208,9 +217,7 @@ async function resolveGatewayTokenSecretRef(
|
||||
if (!ref) {
|
||||
return cfg;
|
||||
}
|
||||
const hasTokenEnvCandidate = Boolean(
|
||||
env.OPENCLAW_GATEWAY_TOKEN?.trim() || env.CLAWDBOT_GATEWAY_TOKEN?.trim(),
|
||||
);
|
||||
const hasTokenEnvCandidate = Boolean(resolveGatewayTokenFromEnv(env));
|
||||
if (hasTokenEnvCandidate) {
|
||||
return cfg;
|
||||
}
|
||||
@@ -258,9 +265,7 @@ async function resolveGatewayPasswordSecretRef(
|
||||
if (!ref) {
|
||||
return cfg;
|
||||
}
|
||||
const hasPasswordEnvCandidate = Boolean(
|
||||
env.OPENCLAW_GATEWAY_PASSWORD?.trim() || env.CLAWDBOT_GATEWAY_PASSWORD?.trim(),
|
||||
);
|
||||
const hasPasswordEnvCandidate = Boolean(resolveGatewayPasswordFromEnv(env));
|
||||
if (hasPasswordEnvCandidate) {
|
||||
return cfg;
|
||||
}
|
||||
@@ -270,7 +275,7 @@ async function resolveGatewayPasswordSecretRef(
|
||||
}
|
||||
if (mode !== "password") {
|
||||
const hasTokenCandidate =
|
||||
Boolean(env.OPENCLAW_GATEWAY_TOKEN?.trim() || env.CLAWDBOT_GATEWAY_TOKEN?.trim()) ||
|
||||
Boolean(resolveGatewayTokenFromEnv(env)) ||
|
||||
hasConfiguredSecretInput(cfg.gateway?.auth?.token, cfg.secrets?.defaults);
|
||||
if (hasTokenCandidate) {
|
||||
return cfg;
|
||||
|
||||
Reference in New Issue
Block a user