Skip to content

feat(cli): add gander auth — install a new API token - #52

Merged
scott merged 1 commit into
mainfrom
feat/51-gander-auth
Aug 19, 2026
Merged

feat(cli): add gander auth — install a new API token#52
scott merged 1 commit into
mainfrom
feat/51-gander-auth

Conversation

@scott

@scott scott commented Aug 19, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • New gander auth <api_token> subcommand installs a rotated / re-issued
    API token without redoing the full signup flow.
  • New token is validated against GET /api/me (paired gandermd endpoint)
    before ~/.gander is rewritten; email, api_url, and the local
    shares map are preserved on success.
  • Help text, bash/zsh completions, the man page, and the README
    subcommand list advertise auth only when the user is already signed
    up. The command itself refuses to run otherwise, reusing the existing
    requireAuth() guard.

Related Issue

Closes #51

Testing

  • New auth_test.go:
    • TestRunAuthRequiresAuth — empty config → "not signed up" error.
    • TestRunAuthRejectsBadUsage — 0 or 2 args → usage error.
    • TestRunAuthValidatesAndPersists — mock 200 on /api/me; asserts
      the bearer header carries the new token and APIToken /
      Email / APIURL are correctly (re)written.
    • TestRunAuthRejectsInvalidToken — mock 401 on /api/me; asserts
      ~/.gander is byte-for-byte unchanged.
  • Existing tests (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:

go vet ./...
go test ./...
CGO_ENABLED=0 go build -o /tmp/check .

All clean.

Notes

  • The validation endpoint (GET /api/me) needs to ship on the server
    side as a paired change. Per AGENTS.md "CLI pairing", this PR is
    intended to land alongside the server-side addition.
  • Behavior on an empty-string token (gander auth "") is a usage
    error, matching runManage's pattern of validating args first.
  • ~/.gander is rewritten atomically by the existing WriteConfig
    helper (mutex + 0600), so a crash mid-rewrite can never leave a
    half-written token on disk.

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).
@scott
scott merged commit 4a415e0 into main Aug 19, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat: add gander auth — install an API token from the CLI

1 participant