Skip to content

Commit 20704ff

Browse files
committed
fix(cli): 优化鉴权逻辑以支持显式API-Key和AK/SK优先级
- 优先使用显式提供的API-Key进行鉴权 - 在无显式API-Key时优先采用显式AK/SK鉴权 - 保持对无显式鉴权信息情况下的自动鉴权兼容 - 重构鉴权判断逻辑以提高代码清晰度和可维护性
1 parent 6317da8 commit 20704ff

1 file changed

Lines changed: 18 additions & 10 deletions

File tree

packages/cli/src/commands/knowledge/retrieve.ts

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -81,19 +81,27 @@ export default defineCommand({
8181

8282
const format = detectOutputFormat(config.output);
8383

84-
// Determine auth: prefer API-KEY, fall back to AK/SK (deprecated)
85-
let useApiKey = false;
86-
try {
87-
await resolveCredential(config);
88-
useApiKey = true;
89-
} catch {
90-
// No API-KEY credential available
91-
}
84+
const hasExplicitApiKey = !!config.apiKey;
85+
const hasExplicitAkSk = !!(flags.accessKeyId && flags.accessKeySecret);
9286

93-
if (useApiKey) {
87+
if (hasExplicitApiKey) {
9488
await runWithApiKey(config, flags, indexId, query, format);
95-
} else {
89+
} else if (hasExplicitAkSk) {
9690
await runWithAkSk(config, flags, indexId, query, format);
91+
} else {
92+
let useApiKey = false;
93+
try {
94+
await resolveCredential(config);
95+
useApiKey = true;
96+
} catch {
97+
// No API-KEY credential available
98+
}
99+
100+
if (useApiKey) {
101+
await runWithApiKey(config, flags, indexId, query, format);
102+
} else {
103+
await runWithAkSk(config, flags, indexId, query, format);
104+
}
97105
}
98106
},
99107
});

0 commit comments

Comments
 (0)