feat: add TOWER_API_KEY support for API key authentication#235
feat: add TOWER_API_KEY support for API key authentication#235codingcyclist merged 7 commits intodevelopfrom
Conversation
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
Add `api_key` field to Config, populated from the TOWER_API_KEY env var. When set, make_api_configuration() uses the X-API-Key header instead of Bearer JWT auth, skipping session-based authentication entirely. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
When TOWER_API_KEY env var is present, skip JWT validation and session.json loading entirely. The API key is self-contained and doesn't need a persisted session. Priority order: TOWER_API_KEY > TOWER_JWT > session.json Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Show a yellow warning explaining that the API key will continue to take precedence over the session created by the login flow. Prompt the user to confirm before proceeding. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Add cli_api_key_auth.feature with scenarios for: - Listing apps with API key (verifies JSON output, no session.json created) - Listing teams with API key (verifies no session.json created) - Login warning when TOWER_API_KEY is set Add "via CLI with API key" step that uses TOWER_API_KEY env var with a temp HOME (no session.json) to prove API key auth works standalone. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
When authenticating via API key, call the /teams API endpoint directly instead of refreshing the session (which requires a session.json). Add list_teams API wrapper and ResponseEntity impl for ListTeamsSuccess. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
When authenticating via API key, call the /teams endpoint directly instead of refreshing the session. Mirrors the same fix applied to the CLI teams list command. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
8795323 to
ec41e8a
Compare
bradhe
left a comment
There was a problem hiding this comment.
Looks good, let's ship it.
| // When TOWER_API_KEY is set, skip session entirely — the API key is self-contained | ||
| // and authenticates via X-API-Key header rather than Bearer JWT. | ||
| let session = if std::env::var("TOWER_API_KEY").is_ok() { | ||
| None | ||
| } else if let Ok(token) = std::env::var("TOWER_JWT") { | ||
| // Load session from a JWT token for programmatic use cases | ||
| Session::from_jwt(&token).ok() | ||
| } else { | ||
| Session::from_config_dir().ok() | ||
| }; | ||
|
|
||
| Self { | ||
| cmd, | ||
| session, | ||
| args: None, | ||
| } |
There was a problem hiding this comment.
Hmm doesn't the session have the tower-url on it?
Summary
TOWER_API_KEYenv var as a new authentication method. When set, the CLI uses theX-API-Keyheader instead of Bearer JWT, skipping session creation entirely.TOWER_API_KEY>TOWER_JWT>session.jsontower teams listand MCPtower_teams_listcall the/teamsAPI directly when using API key auth (no session refresh needed)tower loginwarns that the API key will take precedence over the session and prompts to continueTest plan
TOWER_API_KEY=sk-... tower apps listauthenticates via X-API-Key headersession.jsonis created when using API key authtower teams listreturns the key's teamtower loginwithTOWER_API_KEYset shows warning and promptsTOWER_JWTandtower loginflows are unaffectedcli_api_key_auth.featureintegration tests🤖 Generated with Claude Code