Skip to content

GOCli check provider region - #15474

Merged
JinHai-CN merged 5 commits into
infiniflow:mainfrom
Harry-Hz-Zhang:cli-check-provider-region
Jun 2, 2026
Merged

JinHai-CN merged 5 commits into
infiniflow:mainfrom
Harry-Hz-Zhang:cli-check-provider-region

Conversation

@Harry-Hz-Zhang

@Harry-Hz-Zhang Harry-Hz-Zhang commented Jun 1, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • add CLI command CHECK PROVIDER 'provider_name' REGION 'region_name' KEY 'api_key';
  • route the command through CLI parser and command dispatcher
  • call GET /api/v1/providers/:provider_name/connection with region and api_key

Testing

  • go test ./internal/cli/...
  • manually verified CLI command parsing and request flow

@dosubot dosubot Bot added the size:L This PR changes 100-499 lines, ignoring generated files. label Jun 1, 2026
@coderabbitai

coderabbitai Bot commented Jun 1, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 5382485d-f4a8-4849-a6f1-6af716028cd8

📥 Commits

Reviewing files that changed from the base of the PR and between 0c59aba and 86b8b1f.

📒 Files selected for processing (2)
  • internal/cli/user_command.go
  • internal/cli/user_parser.go
🚧 Files skipped from review as they are similar to previous changes (2)
  • internal/cli/user_command.go
  • internal/cli/user_parser.go

📝 Walkthrough

Walkthrough

This PR adds a new CLI command form that validates provider connectivity using an API key. The parser now routes CHECK PROVIDER <name> REGION <region> KEY <api_key> to a dedicated handler, and the execution layer implements the corresponding API call with authentication and response parsing.

Changes

Provider connectivity check by API key

Layer / File(s) Summary
CLI parser for provider-by-key command
internal/cli/user_parser.go
parseCheckCommand is refactored to dispatch based on the next token. A new parseCheckProviderByKeyCommand parses the PROVIDER <name> REGION <region> KEY <api_key> syntax, validates token order and EOF termination, and builds a check_provider_with_key command.
CLI command execution and routing
internal/cli/user_command.go, internal/cli/client.go
CheckProviderWithKey method enforces USER mode and presence of authentication tokens, extracts provider_name, region, and api_key parameters (mapping empty key to null), optionally includes base_url, issues a GET request to /providers/{provider}/connection with API auth, unmarshals the SimpleResponse, propagates HTTP duration, and returns the result. ExecuteUserCommand routes the check_provider_with_key command type to this handler.

"I'm a rabbit on the CLI trail,
I parse the tokens, set the sail,
A key, a region, one small ping,
Providers answer—health they bring.
Hoppity hops, the check's a win!" 🐇✨

🎯 3 (Moderate) | ⏱️ ~20 minutes

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description includes a summary and testing info but does not follow the required template with 'What problem does this PR solve?' section and explicit 'Type of change' checkbox selection. Follow the template by adding a 'What problem does this PR solve?' section with context and selecting the appropriate change type checkbox.
Title check ❓ Inconclusive The title is vague and doesn't clearly convey what the change implements; 'GOCli check provider region' reads like an incomplete command reference rather than describing the feature being added. Use a more descriptive title like 'Add CLI command to check provider connection with API key' to clearly summarize the main change.
✅ Passed checks (3 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ 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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 win

Add the new provider-level connection handler instead of only renaming the instance one.

After this rename, ProviderHandler.CheckProviderConnection no longer exists in this file, but the router now registers that method for GET /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

📥 Commits

Reviewing files that changed from the base of the PR and between 82202fa and 8e14a8f.

📒 Files selected for processing (5)
  • internal/cli/client.go
  • internal/cli/user_command.go
  • internal/cli/user_parser.go
  • internal/handler/providers.go
  • internal/router/router.go

Comment on lines +2554 to +2581
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)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

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.

@Haruko386 Haruko386 added the ci Continue Integration label Jun 2, 2026
@Haruko386
Haruko386 marked this pull request as draft June 2, 2026 03:45
@Haruko386
Haruko386 marked this pull request as ready for review June 2, 2026 03:45
@codecov

codecov Bot commented Jun 2, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.16%. Comparing base (12579db) to head (86b8b1f).
⚠️ Report is 37 commits behind head on main.

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@JinHai-CN
JinHai-CN merged commit 9799f33 into infiniflow:main Jun 2, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci Continue Integration size:L This PR changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants