Skip to content

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

Merged
samcoe merged 3 commits intotrunkfrom
fix-hosts
Jan 29, 2022
Merged

Add GH_HOST to hosts list if it has corresponding auth token#5087
samcoe merged 3 commits intotrunkfrom
fix-hosts

Conversation

@samcoe
Copy link
Contributor

@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 a team as a code owner January 24, 2022 12:24
@samcoe samcoe self-assigned this Jan 24, 2022
@samcoe samcoe requested review from mislav and removed request for a team January 24, 2022 12:24
Copy link
Contributor

@mislav mislav left a comment

Choose a reason for hiding this comment

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

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
Contributor

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
Contributor Author

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
Contributor

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
Contributor Author

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.

@samcoe samcoe requested a review from mislav January 25, 2022 07:51
// 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
Contributor

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>)

@samcoe samcoe enabled auto-merge (squash) January 29, 2022 07:28
@samcoe samcoe merged commit ba8c41a into trunk Jan 29, 2022
@samcoe samcoe deleted the fix-hosts branch January 29, 2022 07:37
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.

auth status shows "not logged into any GitHub hosts" even with GH_ENTERPRISE_TOKEN and GH_HOST

2 participants