import type { OpenClawConfig } from "../config/types.openclaw.js"; import { createGatewayCredentialPlan } from "../gateway/credential-planner.js"; import type { SecretDefaults } from "./runtime-shared.js"; import { isRecord } from "./shared.js";
export function evaluateGatewayAuthSurfaceStates(params: {
config: OpenClawConfig;
env: NodeJS.ProcessEnv;
defaults?: SecretDefaults;
}): GatewayAuthSurfaceStateMap { const gateway = params.config.gateway as Record<string, unknown> | undefined; if (!isRecord(gateway)) { return { "gateway.auth.token": createState({
path: "gateway.auth.token",
active: false,
reason: "gateway configuration is not set.",
hasSecretRef: false,
}), "gateway.auth.password": createState({
path: "gateway.auth.password",
active: false,
reason: "gateway configuration is not set.",
hasSecretRef: false,
}), "gateway.remote.token": createState({
path: "gateway.remote.token",
active: false,
reason: "gateway configuration is not set.",
hasSecretRef: false,
}), "gateway.remote.password": createState({
path: "gateway.remote.password",
active: false,
reason: "gateway configuration is not set.",
hasSecretRef: false,
}),
};
} const auth = isRecord(gateway?.auth) ? gateway.auth : undefined; const remote = isRecord(gateway?.remote) ? gateway.remote : undefined; const plan = createGatewayCredentialPlan({
config: params.config,
env: params.env,
defaults: params.defaults,
});
const authPasswordReason = (() => { if (!auth) { return"gateway.auth is not configured.";
} if (plan.passwordCanWin) { return plan.authMode === "password"
? 'gateway.auth.mode is "password".'
: "no token source can win, so password auth can win.";
} if (
plan.authMode === "token" ||
plan.authMode === "none" ||
plan.authMode === "trusted-proxy"
) { return `gateway.auth.mode is "${plan.authMode}".`;
} if (plan.envToken) { return"gateway token env var is configured.";
} if (plan.localToken.configured) { return"gateway.auth.token is configured.";
} if (plan.remoteToken.configured) { return"gateway.remote.token is configured.";
} return"token auth can win.";
})();
const authTokenReason = (() => { if (!auth) { return"gateway.auth is not configured.";
} if (plan.authMode === "token") { return plan.envToken
? "gateway token env var is configured."
: 'gateway.auth.mode is "token".';
} if (
plan.authMode === "password" ||
plan.authMode === "none" ||
plan.authMode === "trusted-proxy"
) { return `gateway.auth.mode is "${plan.authMode}".`;
} if (plan.envToken) { return"gateway token env var is configured.";
} if (plan.envPassword) { return"gateway password env var is configured.";
} if (plan.localPassword.configured) { return"gateway.auth.password is configured.";
} return"token auth can win (mode is unset and no password source is configured).";
})();
const remoteTokenReason = (() => { if (!remote) { return"gateway.remote is not configured.";
} if (plan.remoteConfiguredSurface) { return `remote surface is active: ${remoteSurfaceReason}.`;
} if (plan.remoteTokenFallbackActive) { return"local token auth can win and no env/auth token is configured.";
} if (!plan.localTokenCanWin) { return `token auth cannot win with gateway.auth.mode="${formatAuthMode(plan.authMode)}".`;
} if (plan.envToken) { return"gateway token env var is configured.";
} if (plan.localToken.configured) { return"gateway.auth.token is configured.";
} return"remote token fallback is not active.";
})();
const remotePasswordReason = (() => { if (!remote) { return"gateway.remote is not configured.";
} if (plan.remoteConfiguredSurface) { return `remote surface is active: ${remoteSurfaceReason}.`;
} if (plan.remotePasswordFallbackActive) { return"password auth can win and no env/auth password is configured.";
} if (!plan.passwordCanWin) { if (
plan.authMode === "token" ||
plan.authMode === "none" ||
plan.authMode === "trusted-proxy"
) { return `password auth cannot win with gateway.auth.mode="${plan.authMode}".`;
} return"a token source can win, so password auth cannot win.";
} if (plan.envPassword) { return"gateway password env var is configured.";
} if (plan.localPassword.configured) { return"gateway.auth.password is configured.";
} return"remote password fallback is not active.";
})();
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.