mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-10 02:32:44 +00:00
Node install: persist gateway token in service env (#31122)
* Node daemon: persist gateway token env * changelog: add credits for node gateway token fix * changelog: credit byungsker for node token service fix --------- Co-authored-by: Vincent Koc <vincentkoc@ieee.org>
This commit is contained in:
@@ -364,6 +364,42 @@ describe("buildNodeServiceEnvironment", () => {
|
||||
expect(env.HOME).toBe("/home/user");
|
||||
});
|
||||
|
||||
it("passes through OPENCLAW_GATEWAY_TOKEN for node services", () => {
|
||||
const env = buildNodeServiceEnvironment({
|
||||
env: { HOME: "/home/user", OPENCLAW_GATEWAY_TOKEN: " node-token " },
|
||||
});
|
||||
expect(env.OPENCLAW_GATEWAY_TOKEN).toBe("node-token");
|
||||
});
|
||||
|
||||
it("maps legacy CLAWDBOT_GATEWAY_TOKEN to OPENCLAW_GATEWAY_TOKEN for node services", () => {
|
||||
const env = buildNodeServiceEnvironment({
|
||||
env: { HOME: "/home/user", CLAWDBOT_GATEWAY_TOKEN: " legacy-token " },
|
||||
});
|
||||
expect(env.OPENCLAW_GATEWAY_TOKEN).toBe("legacy-token");
|
||||
});
|
||||
|
||||
it("prefers OPENCLAW_GATEWAY_TOKEN over legacy CLAWDBOT_GATEWAY_TOKEN", () => {
|
||||
const env = buildNodeServiceEnvironment({
|
||||
env: {
|
||||
HOME: "/home/user",
|
||||
OPENCLAW_GATEWAY_TOKEN: "openclaw-token",
|
||||
CLAWDBOT_GATEWAY_TOKEN: "legacy-token",
|
||||
},
|
||||
});
|
||||
expect(env.OPENCLAW_GATEWAY_TOKEN).toBe("openclaw-token");
|
||||
});
|
||||
|
||||
it("omits OPENCLAW_GATEWAY_TOKEN when both token env vars are empty", () => {
|
||||
const env = buildNodeServiceEnvironment({
|
||||
env: {
|
||||
HOME: "/home/user",
|
||||
OPENCLAW_GATEWAY_TOKEN: " ",
|
||||
CLAWDBOT_GATEWAY_TOKEN: " ",
|
||||
},
|
||||
});
|
||||
expect(env.OPENCLAW_GATEWAY_TOKEN).toBeUndefined();
|
||||
});
|
||||
|
||||
it("forwards proxy environment variables for node services", () => {
|
||||
const env = buildNodeServiceEnvironment({
|
||||
env: {
|
||||
|
||||
@@ -279,6 +279,8 @@ export function buildNodeServiceEnvironment(params: {
|
||||
}): Record<string, string | undefined> {
|
||||
const { env } = params;
|
||||
const platform = params.platform ?? process.platform;
|
||||
const gatewayToken =
|
||||
env.OPENCLAW_GATEWAY_TOKEN?.trim() || env.CLAWDBOT_GATEWAY_TOKEN?.trim() || undefined;
|
||||
const stateDir = env.OPENCLAW_STATE_DIR;
|
||||
const configPath = env.OPENCLAW_CONFIG_PATH;
|
||||
const tmpDir = env.TMPDIR?.trim() || os.tmpdir();
|
||||
@@ -296,6 +298,7 @@ export function buildNodeServiceEnvironment(params: {
|
||||
NODE_EXTRA_CA_CERTS: nodeCaCerts,
|
||||
OPENCLAW_STATE_DIR: stateDir,
|
||||
OPENCLAW_CONFIG_PATH: configPath,
|
||||
OPENCLAW_GATEWAY_TOKEN: gatewayToken,
|
||||
OPENCLAW_LAUNCHD_LABEL: resolveNodeLaunchAgentLabel(),
|
||||
OPENCLAW_SYSTEMD_UNIT: resolveNodeSystemdServiceName(),
|
||||
OPENCLAW_WINDOWS_TASK_NAME: resolveNodeWindowsTaskName(),
|
||||
|
||||
Reference in New Issue
Block a user