fix(auth): support ${ENV_VAR} syntax expansion and prioritize CCLOAD_API_KEY in image provider
This commit is contained in:
1 parent
723882b974
commit
7472270e1f
4 files changed
+28
-8
No files matched your search
+8
-3
@@ -52,7 +52,12 @@ export interface ImagePluginConfig {
|
||||
|
||||
export function resolvePluginApiKey(rawKey: string | SecretRefObject | undefined): string | undefined {
|
||||
if (typeof rawKey === "string") {
|
||||
return normalizeOptionalString(rawKey);
|
||||
const trimmed = rawKey.trim();
|
||||
const envMatch = trimmed.match(/^\$\{([A-Za-z0-9_]+)\}$/);
|
||||
if (envMatch) {
|
||||
return normalizeOptionalString(process.env[envMatch[1]]);
|
||||
}
|
||||
return normalizeOptionalString(trimmed);
|
||||
}
|
||||
if (rawKey && typeof rawKey === "object" && typeof rawKey.id === "string") {
|
||||
return normalizeOptionalString(process.env[rawKey.id]);
|
||||
@@ -133,8 +138,8 @@ export function buildOpenAIImageGenerationProvider({
|
||||
resolvePluginApiKey(pluginCfg?.apiKey) ||
|
||||
Boolean(pluginCfg?.apiKey) ||
|
||||
normalizeOptionalString(process.env.OPENAI_IMAGE_API_KEY) ||
|
||||
normalizeOptionalString(process.env.BIFROST_API_KEY) ||
|
||||
normalizeOptionalString(process.env.CCLOAD_API_KEY) ||
|
||||
normalizeOptionalString(process.env.BIFROST_API_KEY) ||
|
||||
normalizeOptionalString(process.env.OPENAI_API_KEY)
|
||||
) {
|
||||
return true;
|
||||
@@ -175,8 +180,8 @@ export function buildOpenAIImageGenerationProvider({
|
||||
const explicitApiKey =
|
||||
resolvePluginApiKey(pluginCfg?.apiKey) ??
|
||||
normalizeOptionalString(process.env.OPENAI_IMAGE_API_KEY) ??
|
||||
normalizeOptionalString(process.env.BIFROST_API_KEY) ??
|
||||
normalizeOptionalString(process.env.CCLOAD_API_KEY) ??
|
||||
normalizeOptionalString(process.env.BIFROST_API_KEY) ??
|
||||
normalizeOptionalString(process.env.OPENAI_API_KEY);
|
||||
|
||||
let apiKey = explicitApiKey;
|
||||
|
||||
Reference in new issue
Block a user