Repository navigation
Go: fix CLI logout command - #14672
Conversation
Signed-off-by: Jin Hai <[email protected]>
📝 WalkthroughWalkthroughThis PR updates the CLI authentication flow by changing the admin logout endpoint from ChangesCLI Authentication and Command Parsing
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related PRs
Suggested labels
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 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.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (2)
internal/cli/common_command.go (2)
204-231:⚠️ Potential issue | 🟡 Minor | ⚡ Quick winClear
LoginTokenafter a successful logout.After a successful server-side logout,
c.HTTPClient.LoginTokenis never zeroed. This means:
Logout()can be called again without hitting the "not logged in" guard.- Any subsequent method that uses the HTTP client will send the now-invalidated token and receive a server-side auth error instead of a clear "not logged in" client-side error.
🐛 Proposed fix
if result.Code != 0 { return nil, fmt.Errorf("login failed: %s", result.Message) } + c.HTTPClient.LoginToken = "" return &result, nil }🤖 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/common_command.go` around lines 204 - 231, The Logout() method in RAGFlowClient doesn't clear c.HTTPClient.LoginToken after a successful server-side logout; update Logout (after unmarshalling into result and verifying result.Code == 0) to set c.HTTPClient.LoginToken = "" (clear the token on success) before returning the SimpleResponse so subsequent calls hit the client-side "not logged in" guard and no stale token is sent; modify the Logout function around the result SimpleResponse handling to perform this token zeroing.
222-227:⚠️ Potential issue | 🟡 Minor | ⚡ Quick winStale "login failed" error messages inside
Logout().Both error returns in the logout path copy the wording from
loginUser, making failures harder to diagnose.🐛 Proposed fix
if err = json.Unmarshal(resp.Body, &result); err != nil { - return nil, fmt.Errorf("login failed: invalid JSON (%w)", err) + return nil, fmt.Errorf("logout failed: invalid JSON (%w)", err) } if result.Code != 0 { - return nil, fmt.Errorf("login failed: %s", result.Message) + return nil, fmt.Errorf("logout failed: %s", result.Message) }🤖 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/common_command.go` around lines 222 - 227, The error messages in the Logout() path incorrectly say "login failed" and should reflect logout; update the two error returns in the logout flow (the json.Unmarshal error check that currently returns fmt.Errorf("login failed: invalid JSON (%w)", err) and the result.Code != 0 branch that returns fmt.Errorf("login failed: %s", result.Message)) to use "logout failed" and preserve the wrapped error/detail (e.g., "logout failed: invalid JSON (%w)" and "logout failed: %s") so failures are correctly attributed to Logout() rather than loginUser.
🤖 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.
Outside diff comments:
In `@internal/cli/common_command.go`:
- Around line 204-231: The Logout() method in RAGFlowClient doesn't clear
c.HTTPClient.LoginToken after a successful server-side logout; update Logout
(after unmarshalling into result and verifying result.Code == 0) to set
c.HTTPClient.LoginToken = "" (clear the token on success) before returning the
SimpleResponse so subsequent calls hit the client-side "not logged in" guard and
no stale token is sent; modify the Logout function around the result
SimpleResponse handling to perform this token zeroing.
- Around line 222-227: The error messages in the Logout() path incorrectly say
"login failed" and should reflect logout; update the two error returns in the
logout flow (the json.Unmarshal error check that currently returns
fmt.Errorf("login failed: invalid JSON (%w)", err) and the result.Code != 0
branch that returns fmt.Errorf("login failed: %s", result.Message)) to use
"logout failed" and preserve the wrapped error/detail (e.g., "logout failed:
invalid JSON (%w)" and "logout failed: %s") so failures are correctly attributed
to Logout() rather than loginUser.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 9ffacf3b-d219-4761-b93f-2261edebb0b0
📒 Files selected for processing (2)
internal/cli/common_command.gointernal/cli/user_parser.go
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #14672 +/- ##
=======================================
Coverage 94.16% 94.16%
=======================================
Files 10 10
Lines 703 703
Branches 112 112
=======================================
Hits 662 662
Misses 25 25
Partials 16 16 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
### What problem does this PR solve? ``` RAGFlow(user)> logout; SUCCESS ``` ### Type of change - [x] Bug Fix (non-breaking change which fixes an issue) Signed-off-by: Jin Hai <[email protected]>
### What problem does this PR solve? ``` RAGFlow(user)> logout; SUCCESS ``` ### Type of change - [x] Bug Fix (non-breaking change which fixes an issue) Signed-off-by: Jin Hai <[email protected]>
What problem does this PR solve?
Type of change