Resolve API key from env var in config show#7
Conversation
There was a problem hiding this comment.
Pull request overview
Updates bitmovin config show to resolve and display the effective API key consistently with the CLI’s runtime behavior (env var vs config file), including a new apiKeySource field in JSON output.
Changes:
- Added shared API key resolution logic (
resolveApiKey) with source tracking (env/config-file/none/flag). - Updated
config showto display the resolved key (masked with…) and its source; addedapiKeySourcein--jsonoutput. - Expanded Vitest coverage for env/config/none paths and JSON output.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
src/lib/client.ts |
Introduces resolveApiKey and uses it in getClient() |
src/commands/config/show.ts |
Uses resolved API key + source for human/JSON output; updates masking |
test/commands/config.test.ts |
Adds tests for env precedence, none case, and JSON apiKeySource |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
LGTM with a couple of breaking-change call-outs. Strengths
Breaking changes worth calling out in release notes
Cross-PR consistencyThis PR uses `<=12 → ***` then `8 + … + 4`. PR #6 uses `<=8 → ***` then `4 + ... + 4`. Two mask functions, two styles. Pick one and put it in `lib/output.ts` (or similar) before both land. Tests cover all three resolution paths and the JSON `apiKeySource` field — coverage is solid. |
|
Heads-up: PR #6 just landed a shared |
`bitmovin config show` only inspected the config file, so it printed
"API Key: (not set)" even when the user was authenticated via the
BITMOVIN_API_KEY environment variable. The CLI's getClient() honors
the env var, so this disagreement was misleading: users (and tooling)
couldn't tell from `config show` whether they were authenticated.
Resolve the API key the same way getClient() does (env var first,
then config file) and report which source is in use ("BITMOVIN_API_KEY
env var" vs "config file"). Surface the source as `apiKeySource` in
--json output for scripting.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Extracts the env-var-first precedence chain into resolveApiKey() in client.ts so both call sites use the same source of truth. Also tightens describeSource exhaustiveness, removes a duplicate loadConfig() call, and snapshots BITMOVIN_API_KEY in test setup/teardown for isolation.
6b02271 to
e235795
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 5 out of 5 changed files in this pull request and generated 6 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
lukaskroepfl
left a comment
There was a problem hiding this comment.
All review points addressed plus a couple of thoughtful additions:
- Mask consistency — switched to the shared
maskSecret(4 + ... + 4). One mask format CLI-wide. ✅ - Breaking change documented — CHANGELOG entry calls out the
--jsonshape change explicitly. resolveApiKeyextracted tolib/api-key.ts— cleaner home thanclient.ts, no public-API impact.- Empty-string handling —
normalizeForDisplaytreatsBITMOVIN_API_KEY=""as "(not set)" whilegetClient('')still throws. Behavior matches the old??-chain semantics; nice that you caught this and locked it in with two regression tests. --api-keyflag precedence test — good addition.
The assertNever after the exhaustive switch is unreachable but harmless — leave it for future-proofing if you like.
Approving.
Summary
bitmovin config showonly inspected the config file, so it reportedAPI Key: (not set)even when the user was authenticated via the--api-keyflag orBITMOVIN_API_KEYenvironment variable. The CLI'sgetClient()honors those sources, so this disagreement was misleading: users and tooling couldn't tell fromconfig showwhich API key would actually be used.Changes
getClient()precedence:--api-keyflag first,BITMOVIN_API_KEYenv var second, config file third.--api-key flag,BITMOVIN_API_KEY env var,config file, ornone) so the user can tell at a glance where the key came from.apiKeySource(flag/env/config-file/none) in--jsonoutput for scripting.maskSecret()helper.config showdoes not import the Bitmovin SDK.Tests
apiKeySourcefor config-file, env, and none, includingnullfor unsetapiKey.getClient()authentication behavior.Test plan
npm run buildnpm run lintnpm testconfig showcorrectly identifies the API key source