- Notifications
You must be signed in to change notification settings - Fork2
Description
Description
When both environment variables (CF_API_KEY andCF_URL)and a local~/.cfconfig file are present,getCredentials() appears to prefer the file-basedcurrentContext and overwrites the env-derived credentials. This makes it impossible to force credentials via environment variables (e.g., in CI) if a machine has a~/.cfconfig lying around.
Affected code:src/logic/codefresh.ts – the logic first reads env vars, then loads~/.cfconfig and, ifcurrentContext exists, replaces the credentials with values from the file. See the lines around thegetCredentials() implementation. (GitHub)
Steps to Reproduce
Export valid env vars:
export CF_API_KEY=env-tokenexport CF_URL=https://g.codefresh.io
Ensure
~/.cfconfigexists with adifferentcurrentContext(e.g., stale token or different URL).Run any command/path that calls
getCredentials()(e.g., invoking the support package logic).Observe that the credentials used match the
~/.cfconfigcontext, not the env vars.
Expected Behavior
- If
CF_API_KEYandCF_URLare both set, they shouldtake precedence over file-based context (common pattern for CLI tools).
Actual Behavior
- File-based
currentContextoverrides env-provided credentials when present. - Possible exception when
~/.cfconfigis missing/unreadable (no graceful fallback).
Impact
- Hard to run reliably or when users want to temporarily override local config with env vars.
- Confusing experience: env vars appear to be ignored.
Proposed Fixes
- Precedence change: If both
CF_API_KEYandCF_URLare set,use them and skip reading~/.cfconfig, or at least do not overwrite. - Resilience: Wrap config-file read with try/catch andfallback to env vars on error.
- Observability: Log which credential source was selected (env vs file) to aid troubleshooting.
- Docs: Clarify intended precedence in README/usage notes.
Environment
- Package version / commit:
c7c823f4e2f7c3857eca1aa3c58e0479eb7f332d(linked above). (GitHub)
Additional Notes
If the current behavior is intentional, please document the precedence rules.