feat(cli): add gander auth — install a new API token - #52
Merged
Conversation
Adds a new subcommand for installing a rotated or re-issued API token without redoing the full signup flow. The new token is validated against GET /api/me before overwriting ~/.gander; email, api_url, and the local shares map are preserved. Help text, shell completions, the man page, and README subcommand list are updated to advertise the command only when the user is already signed up. Tests cover the happy path (validation + persist + preservation), the invalid-token path (no config rewrite on 401), the not-signed-up guard, and bad usage (zero/extra args).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
gander auth <api_token>subcommand installs a rotated / re-issuedAPI token without redoing the full signup flow.
GET /api/me(paired gandermd endpoint)before
~/.ganderis rewritten;email,api_url, and the localsharesmap are preserved on success.subcommand list advertise
authonly when the user is already signedup. The command itself refuses to run otherwise, reusing the existing
requireAuth()guard.Related Issue
Closes #51
Testing
auth_test.go:TestRunAuthRequiresAuth— empty config → "not signed up" error.TestRunAuthRejectsBadUsage— 0 or 2 args → usage error.TestRunAuthValidatesAndPersists— mock 200 on/api/me; assertsthe bearer header carries the new token and
APIToken/Email/APIURLare correctly (re)written.TestRunAuthRejectsInvalidToken— mock 401 on/api/me; asserts~/.ganderis byte-for-byte unchanged.cli_test.go,signup_test.go,manage_test.go,completion_test.go,manpage_test.go) pass; manpage test gained"gander auth"in its must-render list.Commands run:
All clean.
Notes
GET /api/me) needs to ship on the serverside as a paired change. Per
AGENTS.md"CLI pairing", this PR isintended to land alongside the server-side addition.
gander auth "") is a usageerror, matching
runManage's pattern of validating args first.~/.ganderis rewritten atomically by the existingWriteConfighelper (mutex + 0600), so a crash mid-rewrite can never leave a
half-written token on disk.