openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
48 lines (47 loc) • 1.82 kB
JavaScript
import { l as normalizeOptionalString } from "./string-coerce-CCIiB4H7.mjs";
import { r as resolveGatewayAuth } from "./auth-resolve-C6_i-P4T.mjs";
import "./auth-dV1bLOjr.mjs";
import { r as materializeGatewayAuthSecretRefs, t as canMaterializeGatewayAuthSecretRefsWithoutExec } from "./auth-config-utils-C9EXfOyf.mjs";
import { t as randomToken } from "./random-token-Sl4a6KEQ.mjs";
//#region src/commands/doctor/shared/hooks-token-reuse-repair.ts
/** Rotate hooks.token when it matches the active Gateway token/password shared secret. */
async function repairHooksTokenReuseGatewayAuth(e, t = process.env, n = randomToken) {
const r = normalizeOptionalString(e.hooks?.token) ?? "";
if (e.hooks?.enabled !== true || !r) return {
config: e,
changes: []
};
const i = {
cfg: e,
env: t,
mode: e.gateway?.auth?.mode,
hasTokenOverride: false,
hasPasswordOverride: false,
hasTokenFallback: Boolean(normalizeOptionalString(t.OPENCLAW_GATEWAY_TOKEN)),
hasPasswordFallback: Boolean(normalizeOptionalString(t.OPENCLAW_GATEWAY_PASSWORD))
};
const a = await (canMaterializeGatewayAuthSecretRefsWithoutExec(i) ? materializeGatewayAuthSecretRefs(i).catch(() => e) : e);
const o = resolveGatewayAuth({
authConfig: a.gateway?.auth,
tailscaleMode: a.gateway?.tailscale?.mode ?? "off",
env: t
});
const s = o.mode === "token" ? o.token : o.mode === "password" || o.mode === "trusted-proxy" ? o.password : void 0;
if (r !== (normalizeOptionalString(s) ?? "")) return {
config: e,
changes: []
};
const c = n();
return {
config: {
...e,
hooks: {
...e.hooks,
token: c
}
},
changes: ["Rotated hooks.token because it reused active Gateway shared-secret auth. Update external hook senders to use the new hooks.token."]
};
}
//#endregion
export { repairHooksTokenReuseGatewayAuth };