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

Skip keyring for auth check #7169

Merged
merged 11 commits into from Mar 17, 2023
Merged

Conversation

benjlevesque
Copy link
Contributor

Fixes #7145

internal/config/config.go Outdated Show resolved Hide resolved
@samcoe samcoe self-assigned this Mar 15, 2023
@benjlevesque benjlevesque marked this pull request as ready for review March 15, 2023 07:38
@benjlevesque benjlevesque requested a review from a team as a code owner March 15, 2023 07:38
@benjlevesque benjlevesque requested review from mislav and removed request for a team March 15, 2023 07:38
@cliAutomation cliAutomation added the external pull request originating outside of the CLI core team label Mar 15, 2023
@cliAutomation cliAutomation added this to Needs review 🤔 in The GitHub CLI Mar 15, 2023
@@ -18,7 +18,7 @@ func CheckAuth(cfg config.Config) bool {
// authentication tokens set for enterprise hosts.
// Any non-github.com hostname is fine here
dummyHostname := "example.com"
token, _ := cfg.Authentication().Token(dummyHostname)
token, _ := cfg.Authentication().TokenFromEnvOrConfig(dummyHostname)
Copy link
Contributor

Choose a reason for hiding this comment

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

Since we don't need an actual token, could we come up with an approach to just test whether an environment variable was set? We used to go the token route in the past because it was cheap, but now with keyring it's not so cheap anymore, so instead of coming up with workarounds I would prefer to just see an approach that specifically asks for the information we're interested in (and nothing more).

I'm imagining a method called something like IsEnterpriseTokenEnv() bool

Copy link
Contributor Author

Choose a reason for hiding this comment

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

😅 that was my initial approach but changed following @samcoe's comment. He pointed out this could be used also here. Both are fine with me, let me know what is prefered

Copy link
Contributor

@mislav mislav Mar 15, 2023

Choose a reason for hiding this comment

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

Both call points are only interested in whether GITHUB_ENTERPRISE_TOKEN or GH_ENTERPRISE_TOKEN was set, but not interested in the value itself. I'd vote for a new method that is precisely tuned to what is being asked for.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

maybe something to export from https://github.com/cli/go-gh?

Copy link
Contributor

Choose a reason for hiding this comment

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

I am okay with a method HasEnterpriseEnvToken() bool. Sorry for the back and forth on this. I don't think we need to expose any additional functionality in go-gh to achieve this. The ghAuth.TokenFromEnvOrConfig function returns the source of the token as its second return value. We just need to verify that the source is either GITHUB_ENTERPRISE_TOKEN or GH_ENTERPRISE_TOKEN.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@mislav I didn't notice at first, but this is not actually specific to Enterprise. If there is an Enterprise token, it will be returned, true. But if there is no enterprise token, it will fallback to GH_TOKEN, GITHUB_TOKEN.

My proposal is to have the original behaviour (TokenFromEnvOrConfig() != ""), wrapped in a function HasEnvOrConfigToken to encapsulate this logic

Copy link
Contributor Author

Choose a reason for hiding this comment

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

see 70a6acc

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.

Thank you!

return ghAuth.TokenFromEnvOrConfig(hostname)
// HasEnterpriseEnvToken checks whether the current env or config contains an enterprise token
func (c *AuthConfig) HasEnterpriseEnvToken() bool {
token, source := ghAuth.TokenFromEnvOrConfig("")
Copy link
Contributor

Choose a reason for hiding this comment

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

This works right now, but only because of an accident. We just so happen to interpret an empty string passed to TokenFromEnvOrConfig as an "enterprise" hostname because it technically doesn't match github.com. We should add a test to go-gh to make note that we shouldn't accidentally break this behavior. But this shouldn't prevent this PR from shipping 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

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

would you prefer I use example.com as before?

The GitHub CLI automation moved this from Needs review 🤔 to Needs to be merged 🎉 Mar 16, 2023
internal/config/config.go Outdated Show resolved Hide resolved
internal/config/config.go Outdated Show resolved Hide resolved
benjlevesque and others added 2 commits March 17, 2023 10:18
Co-authored-by: Sam Coe <samcoe@users.noreply.github.com>
@benjlevesque benjlevesque changed the title fix: skip keyring for auth check Skip keyring for auth check Mar 17, 2023
@samcoe samcoe merged commit 9596fd5 into cli:trunk Mar 17, 2023
6 checks passed
The GitHub CLI automation moved this from Needs to be merged 🎉 to Pending Release 🥚 Mar 17, 2023
@benjlevesque benjlevesque deleted the fix/skip-keyring-auth-check branch March 18, 2023 01:27
@github-actions github-actions bot moved this from Pending Release 🥚 to Done 💤 in The GitHub CLI Mar 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
external pull request originating outside of the CLI core team
Projects
No open projects
The GitHub CLI
  
Done 💤
Development

Successfully merging this pull request may close these issues.

New keyring auth slowing down gh
4 participants