Skip to content

fix: Prefer config file api_token over JIRA_API_TOKEN env var#962

Open
RameezShuhaib wants to merge 1 commit intoankitpokhrel:mainfrom
RameezShuhaib:fix/config-file-token-priority
Open

fix: Prefer config file api_token over JIRA_API_TOKEN env var#962
RameezShuhaib wants to merge 1 commit intoankitpokhrel:mainfrom
RameezShuhaib:fix/config-file-token-priority

Conversation

@RameezShuhaib
Copy link
Copy Markdown

Problem

When using --config or JIRA_CONFIG_FILE to specify a different Jira account, the JIRA_API_TOKEN environment variable overrides the api_token from the config file. This causes issue list to return empty results when the env var token does not have access to the project.

Root Cause

viper.AutomaticEnv() was called after ReadInConfig(), but since viper treats env vars with higher priority by default, the config file value was being overwritten.

Solution

After reading the config file, explicitly preserve the api_token value using viper.Set() before calling AutomaticEnv(). This ensures the config file token takes precedence when explicitly set.

Testing

Tested with multiple Jira accounts where:

  • JIRA_API_TOKEN is set to account A
  • --config specifies account B with a different api_token

Before: Returns empty results (uses account A token)
After: Returns correct results (uses account B token from config file)

When a config file explicitly sets api_token, preserve it before
AutomaticEnv binds JIRA_API_TOKEN so the env var does not override it.

Fixes issue list returning empty results when using --config or
JIRA_CONFIG_FILE with a different account than JIRA_API_TOKEN.
Copy link
Copy Markdown

@ccoVeille ccoVeille left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This sounds like an unexpected changes to me.

The classic variable resolution order is

argument > env > config file

So here you would break the expectations of many users

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.

2 participants