Fix: add label to keyring entry #34
Conversation
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
| return s.ring.Set(keyring.Item{ | ||
| Key: keyringAuthTokenKey, | ||
| Data: []byte(token), | ||
| Label: keyringAuthTokenLabel, |
There was a problem hiding this comment.
The added Label is the fix.
|
Caution Review failedThe pull request is closed. 📝 WalkthroughWalkthroughThis pull request refactors token storage in the authentication module by replacing direct keyring interactions with a new Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Suggested reviewers
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (4)
internal/auth/auth.go (1)
57-64: Redundant error check—DeleteAuthToken()already handlesErrKeyNotFound.The
DeleteAuthToken()implementation inkeyring.go(lines 83-88) already returnsnilwhen the key is not found. This check duplicates that logic and leaks thekeyringpackage into the abstraction layer.♻️ Suggested simplification
// Logout removes the stored auth token from the keyring func (a *Auth) Logout() error { - err := a.tokenStorage.DeleteAuthToken() - if errors.Is(err, keyring.ErrKeyNotFound) { - return nil - } - return err + return a.tokenStorage.DeleteAuthToken() }This also allows removing the
"github.com/99designs/keyring"import from this file.test/integration/main_test.go (1)
19-25: Constants are intentionally duplicated from production code.The duplication is noted (line 38-39 mentions similar for
configDir), but if these constants diverge frominternal/auth/keyring.go, tests may not accurately reflect production behavior.Consider adding a comment noting these must stay in sync with
internal/auth/keyring.go, or alternatively, exporting the constants if test coverage of the exact values is important.internal/auth/keyring.go (1)
64-73: Custom error message hides the original error type.Returning
fmt.Errorf("credential not found")on line 68 loses the originalkeyring.ErrKeyNotFound. While this provides abstraction, callers cannot distinguish "key not found" from other errors without string matching.Consider wrapping with a sentinel error if callers need to handle "not found" differently:
♻️ Optional: Define a sentinel error for better error handling
// At package level var ErrTokenNotFound = errors.New("credential not found") // In GetAuthToken if errors.Is(err, keyring.ErrKeyNotFound) { return "", ErrTokenNotFound }This allows callers to use
errors.Is(err, auth.ErrTokenNotFound)without depending on the keyring package.internal/auth/mock_keyring_test.go (1)
1-10: Generated mock file – consider renaming to match the interface.The file is correctly generated, but the filename
mock_keyring_test.gono longer reflects the interface nameAuthTokenStorage. Consider updating the mockgen command to use-destination=mock_auth_token_storage_test.gofor clarity:-// mockgen -source=keyring.go -destination=mock_keyring_test.go -package=auth +// mockgen -source=keyring.go -destination=mock_auth_token_storage_test.go -package=auth
silv-io
left a comment
There was a problem hiding this comment.
LGTM! Got nothing besides the nitpicks that the rabbit already found
1aa968e to
6704a3c
Compare
With this change, macOS keychain users won't see an empty string in the pop-up:

Other changes
Keyringinterface is replaces with a purpose-specificAuthTokenStorageinterface. This removes the need for passing redundant key parameters.