fix(cli): 优化鉴权逻辑以支持显式API-Key和AK/SK优先级

- 优先使用显式提供的API-Key进行鉴权
- 在无显式API-Key时优先采用显式AK/SK鉴权
- 保持对无显式鉴权信息情况下的自动鉴权兼容
- 重构鉴权判断逻辑以提高代码清晰度和可维护性
This commit is contained in:
zeyu.fz
2026-06-09 15:25:15 +08:00
parent 6317da8454
commit 20704ff1c6
+18 -10
View File
@@ -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);
}
}
},
});