refactor: centralize gateway auth env credential readers

This commit is contained in:
Peter Steinberger
2026-03-07 20:58:09 +00:00
parent f0b05869fc
commit a91731a831
9 changed files with 47 additions and 110 deletions

View File

@@ -2,6 +2,7 @@ import type { Command } from "commander";
import qrcode from "qrcode-terminal";
import { loadConfig } from "../config/config.js";
import { hasConfiguredSecretInput, resolveSecretInputRef } from "../config/types.secrets.js";
import { readGatewayPasswordEnv, readGatewayTokenEnv } from "../gateway/credentials.js";
import { resolvePairingSetupFromConfig, encodePairingSetupCode } from "../pairing/setup-code.js";
import { runCommandWithTimeout } from "../process/exec.js";
import { defaultRuntime } from "../runtime.js";
@@ -40,32 +41,6 @@ function readDevicePairPublicUrlFromConfig(cfg: ReturnType<typeof loadConfig>):
return trimmed.length > 0 ? trimmed : undefined;
}
function readGatewayTokenEnv(env: NodeJS.ProcessEnv): string | undefined {
const primary = typeof env.OPENCLAW_GATEWAY_TOKEN === "string" ? env.OPENCLAW_GATEWAY_TOKEN : "";
if (primary.trim().length > 0) {
return primary.trim();
}
const legacy = typeof env.CLAWDBOT_GATEWAY_TOKEN === "string" ? env.CLAWDBOT_GATEWAY_TOKEN : "";
if (legacy.trim().length > 0) {
return legacy.trim();
}
return undefined;
}
function readGatewayPasswordEnv(env: NodeJS.ProcessEnv): string | undefined {
const primary =
typeof env.OPENCLAW_GATEWAY_PASSWORD === "string" ? env.OPENCLAW_GATEWAY_PASSWORD : "";
if (primary.trim().length > 0) {
return primary.trim();
}
const legacy =
typeof env.CLAWDBOT_GATEWAY_PASSWORD === "string" ? env.CLAWDBOT_GATEWAY_PASSWORD : "";
if (legacy.trim().length > 0) {
return legacy.trim();
}
return undefined;
}
function shouldResolveLocalGatewayPasswordSecret(
cfg: ReturnType<typeof loadConfig>,
env: NodeJS.ProcessEnv,