mirror of
https://github.com/modelstudioai/cli.git
synced 2026-09-14 19:49:23 +08:00
fix(cli): 优化鉴权逻辑以支持显式API-Key和AK/SK优先级
- 优先使用显式提供的API-Key进行鉴权 - 在无显式API-Key时优先采用显式AK/SK鉴权 - 保持对无显式鉴权信息情况下的自动鉴权兼容 - 重构鉴权判断逻辑以提高代码清晰度和可维护性
This commit is contained in:
@@ -81,19 +81,27 @@ export default defineCommand({
|
||||
|
||||
const format = detectOutputFormat(config.output);
|
||||
|
||||
// Determine auth: prefer API-KEY, fall back to AK/SK (deprecated)
|
||||
let useApiKey = false;
|
||||
try {
|
||||
await resolveCredential(config);
|
||||
useApiKey = true;
|
||||
} catch {
|
||||
// No API-KEY credential available
|
||||
}
|
||||
const hasExplicitApiKey = !!config.apiKey;
|
||||
const hasExplicitAkSk = !!(flags.accessKeyId && flags.accessKeySecret);
|
||||
|
||||
if (useApiKey) {
|
||||
if (hasExplicitApiKey) {
|
||||
await runWithApiKey(config, flags, indexId, query, format);
|
||||
} else {
|
||||
} else if (hasExplicitAkSk) {
|
||||
await runWithAkSk(config, flags, indexId, query, format);
|
||||
} else {
|
||||
let useApiKey = false;
|
||||
try {
|
||||
await resolveCredential(config);
|
||||
useApiKey = true;
|
||||
} catch {
|
||||
// No API-KEY credential available
|
||||
}
|
||||
|
||||
if (useApiKey) {
|
||||
await runWithApiKey(config, flags, indexId, query, format);
|
||||
} else {
|
||||
await runWithAkSk(config, flags, indexId, query, format);
|
||||
}
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user