mirror of
https://github.com/openclaw/openclaw.git
synced 2026-03-16 20:40:45 +00:00
42 lines
1.2 KiB
TypeScript
42 lines
1.2 KiB
TypeScript
import type { OpenClawConfig } from "../config/config.js";
|
|
import {
|
|
normalizeSecretInputString,
|
|
resolveSecretInputRef,
|
|
type SecretRef,
|
|
} from "../config/types.secrets.js";
|
|
import { resolveSecretRefString } from "./resolve.js";
|
|
|
|
type SecretDefaults = NonNullable<OpenClawConfig["secrets"]>["defaults"];
|
|
|
|
export async function resolveSecretInputString(params: {
|
|
config: OpenClawConfig;
|
|
value: unknown;
|
|
env: NodeJS.ProcessEnv;
|
|
defaults?: SecretDefaults;
|
|
normalize?: (value: unknown) => string | undefined;
|
|
onResolveRefError?: (error: unknown, ref: SecretRef) => never;
|
|
}): Promise<string | undefined> {
|
|
const normalize = params.normalize ?? normalizeSecretInputString;
|
|
const { ref } = resolveSecretInputRef({
|
|
value: params.value,
|
|
defaults: params.defaults ?? params.config.secrets?.defaults,
|
|
});
|
|
if (!ref) {
|
|
return normalize(params.value);
|
|
}
|
|
|
|
let resolved: string;
|
|
try {
|
|
resolved = await resolveSecretRefString(ref, {
|
|
config: params.config,
|
|
env: params.env,
|
|
});
|
|
} catch (error) {
|
|
if (params.onResolveRefError) {
|
|
return params.onResolveRefError(error, ref);
|
|
}
|
|
throw error;
|
|
}
|
|
return normalize(resolved);
|
|
}
|