Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add GH_HOST to hosts list if it has corresponding auth token #5087

Merged
merged 3 commits into from Jan 29, 2022
Merged

Conversation

Copy link
Member

@samcoe samcoe commented Jan 24, 2022

This PR changes the behavior of envConfig.Hosts() to now include in the return set GH_HOST if it has a corresponding authentication token from one of the numerous environment variable token locations. This solves the case where auth commands were displaying that a user was not authenticated despite having both GH_HOST and a corresponding authentication token environment variable set.

Closes #4576

@samcoe samcoe requested a review from as a code owner Jan 24, 2022
@samcoe samcoe self-assigned this Jan 24, 2022
@samcoe samcoe requested review from mislav (assigned from cli/code-reviewers) and removed request for Jan 24, 2022
@cliAutomation cliAutomation added this to Needs review 🤔 in The GitHub CLI Jan 24, 2022
internal/config/from_env_test.go Outdated Show resolved Hide resolved
Copy link
Member

@mislav mislav left a comment

Thanks for working on this! Looking good, but I would just like to try and keep backwards compatibility.

// If GH_HOST is set and there is a valid environment variable
// token for the host then add it to list.
if host := os.Getenv(GH_HOST); host != "" {
if token, _ := AuthTokenFromEnv(host); token != "" {
Copy link
Member

@mislav mislav Jan 24, 2022

Choose a reason for hiding this comment

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

If GH_HOST is set in the environment, would it be a good idea to make it the default host even if GH_ENTERPRISE_TOKEN wasn't set?

Copy link
Member Author

@samcoe samcoe Jan 24, 2022

Choose a reason for hiding this comment

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

Can you elaborate on what you mean by default host? Are you suggesting that if GH_HOST is set then it should always be returned or are you suggesting that if GH_HOST is set then it should be the only value returned?

Copy link
Member

@mislav mislav Jan 28, 2022

Choose a reason for hiding this comment

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

So, what I meant was, I see two conditions here for hostSet.Add(<GH_HOST>) to happen: that GH_HOST is set and that GH_ENTERPRISE_TOKEN is also set. Could we remove the second condition and just do:

if GH_HOST is set
  hostSet.Add(<GH_HOST>)

Copy link
Member Author

@samcoe samcoe Jan 29, 2022

Choose a reason for hiding this comment

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

Yeah that makes sense to me. Updated.

internal/config/from_env.go Show resolved Hide resolved
internal/config/from_env_test.go Outdated Show resolved Hide resolved
@samcoe samcoe requested a review from mislav Jan 25, 2022
// If GH_HOST is set and there is a valid environment variable
// token for the host then add it to list.
if host := os.Getenv(GH_HOST); host != "" {
if token, _ := AuthTokenFromEnv(host); token != "" {
Copy link
Member

@mislav mislav Jan 28, 2022

Choose a reason for hiding this comment

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

So, what I meant was, I see two conditions here for hostSet.Add(<GH_HOST>) to happen: that GH_HOST is set and that GH_ENTERPRISE_TOKEN is also set. Could we remove the second condition and just do:

if GH_HOST is set
  hostSet.Add(<GH_HOST>)

The GitHub CLI automation moved this from Needs review 🤔 to Needs to be merged 🎉 Jan 28, 2022
@samcoe samcoe enabled auto-merge (squash) Jan 29, 2022
@samcoe samcoe merged commit ba8c41a into trunk Jan 29, 2022
10 checks passed
The GitHub CLI automation moved this from Needs to be merged 🎉 to Pending Release 🥚 Jan 29, 2022
@samcoe samcoe deleted the fix-hosts branch Jan 29, 2022
@github-actions github-actions bot moved this from Pending Release 🥚 to Done 💤 in The GitHub CLI Feb 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
The GitHub CLI
  
Done 💤
Development

Successfully merging this pull request may close these issues.

2 participants