Skip to content

fix(auth): recognize API keys and bearer token in 'pup auth status'#484

Merged
platinummonkey merged 1 commit into
mainfrom
fix/auth-status-api-keys
May 9, 2026
Merged

fix(auth): recognize API keys and bearer token in 'pup auth status'#484
platinummonkey merged 1 commit into
mainfrom
fix/auth-status-api-keys

Conversation

@platinummonkey
Copy link
Copy Markdown
Collaborator

@platinummonkey platinummonkey commented May 9, 2026

Summary

pup auth status only inspected OAuth2 token storage. When a user authenticated via DD_API_KEY+DD_APP_KEY (or DD_ACCESS_TOKEN), the command reported ❌ Not authenticated even though every other command worked — confusing agents that wrap pup into thinking auth was broken.

Status now reports the credentials it actually finds, matching the auth headers the client puts on the wire.

Changes

  • src/commands/auth.rs — extract build_non_oauth_status() for the no-OAuth-tokens arm of status(). The helper delegates auth-type detection to client::get_auth_type so this command can never disagree with the client about which credentials are in use.
  • The JSON output gains an auth_method field (bearer_token / api_keys) on the two new authenticated branches; the unauthenticated payload is unchanged for backward compatibility.

Behavior

Before, with DD_API_KEY/DD_APP_KEY set:

❌ Not authenticated for site: datadoghq.com
{ "authenticated": false, "status": "no token", ... }

After:

✅ Authenticated for site: datadoghq.com (DD_API_KEY + DD_APP_KEY)
{ "authenticated": true, "auth_method": "api_keys", "status": "valid", ... }

Testing

  • 6 new unit tests cover every branch of build_non_oauth_status, including bearer-takes-precedence-over-api-keys (matches client::get_auth_type) and partial-key (lone DD_API_KEY) rejection.
  • 2 new tokio::test integration tests cover the status() wiring on the api-key and bearer paths.
  • All 39 commands::auth tests pass; cargo fmt --check and cargo clippy --all-targets -- -D warnings are clean.

Test plan

  • cargo test --bin pup commands::auth
  • Manually run pup auth status with only DD_API_KEY+DD_APP_KEY set and confirm authenticated output
  • Manually run pup auth status with only DD_ACCESS_TOKEN set and confirm authenticated output
  • Confirm pup auth status after pup auth login still shows OAuth token details unchanged

🤖 Generated with Claude Code

`pup auth status` previously only inspected OAuth2 token storage. When a
user authenticated via DD_API_KEY+DD_APP_KEY (or DD_ACCESS_TOKEN), the
command reported `❌ Not authenticated` / `"status": "no token"` even
though every command worked — confusing wrapping agents into believing
auth was broken.

Status now delegates auth-type detection to `client::get_auth_type`, so
the reported method is guaranteed to match the headers the client puts
on the wire. The JSON gains an `auth_method` field (`bearer_token` /
`api_keys`) on the new authenticated branches; the unauthenticated shape
is unchanged.

- Extract `build_non_oauth_status()` helper for the no-OAuth-tokens arm
- Six unit tests cover every branch including bearer-over-api-keys
  precedence and partial-key (lone DD_API_KEY) rejection
- Two `tokio::test` integration tests cover the `status()` wiring on the
  api-key and bearer paths

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@platinummonkey platinummonkey requested a review from a team as a code owner May 9, 2026 14:34
@platinummonkey platinummonkey merged commit bbb8eb3 into main May 9, 2026
7 checks passed
@platinummonkey platinummonkey deleted the fix/auth-status-api-keys branch May 9, 2026 14:57
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.

1 participant