mirror of
https://github.com/openclaw/openclaw.git
synced 2026-06-06 10:12:53 +00:00
Extract shared normalization/coercion helpers into private @openclaw/normalization-core workspace package while preserving existing plugin SDK helper subpaths.\n\nAlso keeps direct normalization-core imports internal, wires UI/build/loader resolution, and replaces the slow PR network CodeQL lane with a fast added-line boundary scan while retaining full CodeQL for scheduled/manual runs.\n\nVerification: local moved tests, plugin SDK boundary tests, extension loader tests, agents-support shard, UI build/test, build artifacts, lint, workflow guards, autoreview, and GitHub CI passed on PR head 963d893715.
60 lines
1.7 KiB
TypeScript
60 lines
1.7 KiB
TypeScript
import { normalizeOptionalString } from "@openclaw/normalization-core/string-coerce";
|
|
import { readSecretFromFile } from "../acp/secret-file.js";
|
|
import { defaultRuntime } from "../runtime.js";
|
|
|
|
function resolveGatewaySecretOption(params: {
|
|
direct?: unknown;
|
|
file?: unknown;
|
|
directFlag: string;
|
|
fileFlag: string;
|
|
label: string;
|
|
}): string | undefined {
|
|
const direct = normalizeOptionalString(params.direct);
|
|
const file = normalizeOptionalString(params.file);
|
|
if (direct && file) {
|
|
throw new Error(`Use either ${params.directFlag} or ${params.fileFlag} for ${params.label}.`);
|
|
}
|
|
if (file) {
|
|
return readSecretFromFile(file, params.label);
|
|
}
|
|
return direct || undefined;
|
|
}
|
|
|
|
function warnGatewaySecretCliFlag(flag: "--token" | "--password"): void {
|
|
defaultRuntime.error(
|
|
`Warning: ${flag} can be exposed via process listings. Prefer ${flag}-file or environment variables.`,
|
|
);
|
|
}
|
|
|
|
export function resolveGatewayAuthOptions(opts: {
|
|
token?: unknown;
|
|
tokenFile?: unknown;
|
|
password?: unknown;
|
|
passwordFile?: unknown;
|
|
}): {
|
|
gatewayToken?: string;
|
|
gatewayPassword?: string;
|
|
} {
|
|
const gatewayToken = resolveGatewaySecretOption({
|
|
direct: opts.token,
|
|
file: opts.tokenFile,
|
|
directFlag: "--token",
|
|
fileFlag: "--token-file",
|
|
label: "Gateway token",
|
|
});
|
|
const gatewayPassword = resolveGatewaySecretOption({
|
|
direct: opts.password,
|
|
file: opts.passwordFile,
|
|
directFlag: "--password",
|
|
fileFlag: "--password-file",
|
|
label: "Gateway password",
|
|
});
|
|
if (opts.token) {
|
|
warnGatewaySecretCliFlag("--token");
|
|
}
|
|
if (opts.password) {
|
|
warnGatewaySecretCliFlag("--password");
|
|
}
|
|
return { gatewayToken, gatewayPassword };
|
|
}
|