[DX-261] Fix auth keys get formatting and add ABLY_API_KEY override warning#171
[DX-261] Fix auth keys get formatting and add ABLY_API_KEY override warning#171umair-ably wants to merge 1 commit intomainfrom
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
Important Review skippedAuto incremental reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Repository 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:
WalkthroughEnhanced the auth:keys:get command to detect and display when ABLY_API_KEY environment variables override the current API key. Updated output formatting to use structured helpers and added progress feedback. Added corresponding test coverage for override scenarios. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 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)
📝 Coding Plan
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
src/commands/auth/keys/get.ts (1)
119-127: Consider usinglogToStderrfor warning output.Per project conventions, warning messages should use
this.logToStderr(formatWarning(...))to avoid mixing warnings with stdout data when output is piped.Proposed fix
if (hasEnvOverride) { - this.log(""); - this.log( + this.logToStderr(""); + this.logToStderr( formatWarning( `ABLY_API_KEY environment variable is set to a different key (${envKeyPrefix}). ` + `The env var overrides this key for product API commands.`, ), ); }Based on learnings: "Always use this.logToStderr(formatWarning('...')) for warning messages".
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/commands/auth/keys/get.ts` around lines 119 - 127, The warning block in the get key command currently writes to stdout using this.log, which can pollute piped output; change the calls that output the environment-override warning to use this.logToStderr(formatWarning(...)) instead of this.log so warnings go to stderr. Update the branch where hasEnvOverride is true (the code that references envKeyPrefix and calls formatWarning) to call this.logToStderr for the blank line and the formatted warning message, preserving the existing wording and use of formatWarning.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@src/commands/auth/keys/get.ts`:
- Line 43: The call to this.showAuthInfoIfNeeded(flags) is missing an await,
causing possible output ordering issues and swallowed errors; update the call in
the get keys command to await this.showAuthInfoIfNeeded(flags) so the method
completes before continuing (ensuring any thrown errors propagate) — look for
the invocation of showAuthInfoIfNeeded in the get/keys flow and make it await
the async method.
---
Nitpick comments:
In `@src/commands/auth/keys/get.ts`:
- Around line 119-127: The warning block in the get key command currently writes
to stdout using this.log, which can pollute piped output; change the calls that
output the environment-override warning to use
this.logToStderr(formatWarning(...)) instead of this.log so warnings go to
stderr. Update the branch where hasEnvOverride is true (the code that references
envKeyPrefix and calls formatWarning) to call this.logToStderr for the blank
line and the formatted warning message, preserving the existing wording and use
of formatWarning.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: 1c62105a-3a66-45b9-bd6b-8f8fe2e87c2d
📒 Files selected for processing (2)
src/commands/auth/keys/get.tstest/unit/commands/auth/keys/get.test.ts
There was a problem hiding this comment.
Pull request overview
This PR improves the auth keys get CLI command output formatting and adds detection + user-facing warnings when ABLY_API_KEY is set to a different key than the currently configured key (including JSON output support), with accompanying unit tests.
Changes:
- Add formatted, structured non-JSON output and a “Fetching key details” progress line.
- Detect
ABLY_API_KEYoverrides for the current key and surface a warning /envKeyOverrideJSON field. - Add unit tests covering warning/no-warning and JSON behavior, including env var setup/teardown.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
src/commands/auth/keys/get.ts |
Adds formatted output and env override warning/JSON field for auth keys get. |
test/unit/commands/auth/keys/get.test.ts |
Adds tests for ABLY_API_KEY override warning behavior and JSON output. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review. Take the survey.
4f2ca65 to
27529c0
Compare
27529c0 to
77cb6ba
Compare
There was a problem hiding this comment.
We support env. first authentication ABLY_API_KEY, ABLY_TOKEN, ABLY_ACCESS_TOKEN as per #146.
So, for security reasons, we shouldn't be passing full key to any of the command
For keys get --help command
pnpm cli auth keys get --help
we get
USAGE
$ ably auth keys get KEYNAMEORVALUE [-v] [--json | --pretty-json] [--app <value>]
ARGUMENTS
KEYNAMEORVALUE Key name (APP_ID.KEY_ID), key ID, key label (e.g. Root), or full key value to get details for
Since Full key will be visible on logs, ideally USAGE guide should be
USAGE
$ ably auth keys get KEYNAME [-v] [--json | --pretty-json] [--app <value>]
ARGUMENTS
KEYNAME Key name is `KEY_ID` or `APP_ID.KEY_ID` or key label (e.g. Root)
Will share full auth keys security review 👍
Summary
--appflag on allauth keyscommands to resolve app names to IDs viarequireAppId()/resolveAppIdFromNameOrId()instead of passing the value directly to the Control API URL--appflag descriptions to say "The app ID or name" where they previously said "The app ID"mockAppResolution()test helper for mocking the app name resolution flowlist.test.tsTest plan
pnpm preparesucceedspnpm exec eslint .— 0 errorspnpm test:unit— all 1748 tests pass--app "AppName"resolves correctly via new test caseFixes #172