Repository navigation
GOCli check provider region - #15474
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (2)
📝 WalkthroughWalkthroughThis PR adds a new CLI command form that validates provider connectivity using an API key. The parser now routes ChangesProvider connectivity check by API key
🎯 3 (Moderate) | ⏱️ ~20 minutes 🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (1 warning, 1 inconclusive)
✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
internal/handler/providers.go (1)
390-425:⚠️ Potential issue | 🔴 Critical | ⚡ Quick winAdd the new provider-level connection handler instead of only renaming the instance one.
After this rename,
ProviderHandler.CheckProviderConnectionno longer exists in this file, but the router now registers that method forGET /providers/:provider_name/connection. That breaks compilation and leaves the new provider-by-key path unimplemented.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@internal/handler/providers.go` around lines 390 - 425, The router expects ProviderHandler.CheckProviderConnection but that method was removed/renamed; add a new CheckProviderConnection(c *gin.Context) on ProviderHandler (alongside the existing CheckInstanceConnection) that extracts provider_name and user_id, calls h.modelProviderService.CheckProviderConnection(providerName, /* no instance */ "", userID) (or the provider-level service method if available), and returns the same JSON error/success shapes as CheckInstanceConnection (use c.JSON with errorCode and err.Error() on failure, and code:0 message:"success" on success). Ensure the method signature and behavior match how the router registers GET /providers/:provider_name/connection so compilation and the provider-level path are implemented.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@internal/cli/user_command.go`:
- Around line 2554-2581: The request in CheckProviderWithKey uses a hardcoded
authKind "api" which breaks logged-in (session/login-token) users; change the
authKind passed to HTTPClient.Request to use the active session when available
(e.g., if c.HTTPClient.LoginToken != "" then use "login" or the equivalent
session auth string your HTTPClient expects, otherwise use "api"). Update the
call site where resp, err := c.HTTPClient.Request("GET", url, "api", nil,
payload) is invoked to compute authKind based on HTTPClient.LoginToken/APIToken
so the request is authenticated with the current active session.
---
Outside diff comments:
In `@internal/handler/providers.go`:
- Around line 390-425: The router expects
ProviderHandler.CheckProviderConnection but that method was removed/renamed; add
a new CheckProviderConnection(c *gin.Context) on ProviderHandler (alongside the
existing CheckInstanceConnection) that extracts provider_name and user_id, calls
h.modelProviderService.CheckProviderConnection(providerName, /* no instance */
"", userID) (or the provider-level service method if available), and returns the
same JSON error/success shapes as CheckInstanceConnection (use c.JSON with
errorCode and err.Error() on failure, and code:0 message:"success" on success).
Ensure the method signature and behavior match how the router registers GET
/providers/:provider_name/connection so compilation and the provider-level path
are implemented.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 3f5af855-9d44-4d18-af79-7c41f35a939f
📒 Files selected for processing (5)
internal/cli/client.gointernal/cli/user_command.gointernal/cli/user_parser.gointernal/handler/providers.gointernal/router/router.go
| func (c *RAGFlowClient) CheckProviderWithKey(cmd *Command) (ResponseIf, error) { | ||
| if c.HTTPClient.APIToken == "" && c.HTTPClient.LoginToken == "" { | ||
| return nil, fmt.Errorf("API token not set. Please login first") | ||
| } | ||
| if c.ServerType != "user" { | ||
| return nil, fmt.Errorf("this command is only allowed in USER mode") | ||
| } | ||
|
|
||
| providerName, ok := cmd.Params["provider_name"].(string) | ||
| if !ok || providerName == "" { | ||
| return nil, fmt.Errorf("provider name not provided") | ||
| } | ||
| region, ok := cmd.Params["region"].(string) | ||
| if !ok || region == "" { | ||
| return nil, fmt.Errorf("region not provided") | ||
| } | ||
| apiKey, ok := cmd.Params["api_key"].(string) | ||
| if !ok || apiKey == "" { | ||
| return nil, fmt.Errorf("api_key not provided") | ||
| } | ||
| url := fmt.Sprintf("/providers/%s/connection", providerName) | ||
|
|
||
| payload := map[string]interface{}{ | ||
| "region": region, | ||
| "api_key": apiKey, | ||
| } | ||
|
|
||
| resp, err := c.HTTPClient.Request("GET", url, "api", nil, payload) |
There was a problem hiding this comment.
Use the active session auth here instead of forcing API-token auth.
This method accepts either a login token or an API token at the top, but Line 2581 always sends the request with authKind="api". A user who is logged in via web auth and has not set a CLI API token will pass the precheck and then send an unauthenticated request.
Suggested fix
url := fmt.Sprintf("/providers/%s/connection", providerName)
payload := map[string]interface{}{
"region": region,
"api_key": apiKey,
}
- resp, err := c.HTTPClient.Request("GET", url, "api", nil, payload)
+ authKind := "web"
+ if c.HTTPClient.useAPIToken {
+ authKind = "api"
+ }
+ if c.HTTPClient.LoginToken != "" {
+ authKind = "web"
+ }
+
+ resp, err := c.HTTPClient.Request("GET", url, authKind, nil, payload)🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@internal/cli/user_command.go` around lines 2554 - 2581, The request in
CheckProviderWithKey uses a hardcoded authKind "api" which breaks logged-in
(session/login-token) users; change the authKind passed to HTTPClient.Request to
use the active session when available (e.g., if c.HTTPClient.LoginToken != ""
then use "login" or the equivalent session auth string your HTTPClient expects,
otherwise use "api"). Update the call site where resp, err :=
c.HTTPClient.Request("GET", url, "api", nil, payload) is invoked to compute
authKind based on HTTPClient.LoginToken/APIToken so the request is authenticated
with the current active session.
This reverts commit 8e14a8f.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #15474 +/- ##
=======================================
Coverage 93.16% 93.16%
=======================================
Files 10 10
Lines 717 717
Branches 118 118
=======================================
Hits 668 668
Misses 29 29
Partials 20 20 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Summary
CHECK PROVIDER 'provider_name' REGION 'region_name' KEY 'api_key';GET /api/v1/providers/:provider_name/connectionwithregionandapi_keyTesting
go test ./internal/cli/...