mirror of
https://github.com/infiniflow/ragflow.git
synced 2026-08-15 05:04:27 +08:00
Go CLI: fix key commands (#16306)
### What problem does this PR solve? ``` RAGFlow(api/default)> set key 'ragflow-JgnarFSCUiV99oOvvMDei7ZzZg1cVlqGd1AMHrHeKE4'; SUCCESS RAGFlow(api/default)> unset key; SUCCESS RAGFlow(api/default)> list provider 'zhipu-ai' instances; RAGFlow(api/default)> list providers; RAGFlow(api/default)> list available providers; RAGFlow(api/default)> list provider 'zhipu-ai' instance 'test' models; ``` ### Type of change - [x] Bug Fix (non-breaking change which fixes an issue) --------- Signed-off-by: Jin Hai <haijin.chn@gmail.com>
This commit is contained in:
@@ -32,13 +32,13 @@ type HTTPClient struct {
|
||||
Host string
|
||||
Port int
|
||||
APIVersion string
|
||||
APIToken *string
|
||||
APIKey *string
|
||||
LoginToken *string
|
||||
ConnectTimeout time.Duration
|
||||
ReadTimeout time.Duration
|
||||
VerifySSL bool
|
||||
client *http.Client
|
||||
useAPIToken bool
|
||||
useAPIKey bool
|
||||
}
|
||||
|
||||
// NewHTTPClient creates a new HTTP client
|
||||
@@ -85,8 +85,8 @@ func (c *HTTPClient) Headers(authKind string, extra map[string]string) map[strin
|
||||
|
||||
switch authKind {
|
||||
case "api":
|
||||
if c.APIToken != nil {
|
||||
headers["Authorization"] = fmt.Sprintf("Bearer %s", *c.APIToken)
|
||||
if c.APIKey != nil {
|
||||
headers["Authorization"] = fmt.Sprintf("Bearer %s", *c.APIKey)
|
||||
} else if c.LoginToken != nil {
|
||||
// Fallback to login token for API requests (user mode)
|
||||
headers["Authorization"] = fmt.Sprintf("Bearer %s", *c.LoginToken)
|
||||
@@ -287,8 +287,8 @@ func (c *HTTPClient) UploadMultipart(path string, contentType string, body io.Re
|
||||
|
||||
// Set headers
|
||||
req.Header.Set("Content-Type", contentType)
|
||||
if c.APIToken != nil {
|
||||
req.Header.Set("Authorization", fmt.Sprintf("Bearer %s", *c.APIToken))
|
||||
if c.APIKey != nil {
|
||||
req.Header.Set("Authorization", fmt.Sprintf("Bearer %s", *c.APIKey))
|
||||
} else if c.LoginToken != nil {
|
||||
req.Header.Set("Authorization", *c.LoginToken)
|
||||
}
|
||||
@@ -386,7 +386,7 @@ func (a *httpClientAdapter) Request(method, path string, authKind string, header
|
||||
// Auto-detect auth kind based on available tokens
|
||||
// If authKind is "auto" or empty, determine based on token availability
|
||||
if authKind == "auto" || authKind == "" {
|
||||
if a.client.useAPIToken && a.client.APIToken != nil {
|
||||
if a.client.useAPIKey && a.client.APIKey != nil {
|
||||
authKind = "api"
|
||||
} else if a.client.LoginToken != nil {
|
||||
authKind = "web"
|
||||
|
||||
Reference in New Issue
Block a user