Skip to content

Skip keyring for auth check - #7169

Merged
samcoe merged 11 commits into
cli:trunkfrom
benjlevesque:fix/skip-keyring-auth-check
Mar 17, 2023
Merged

samcoe merged 11 commits into
cli:trunkfrom
benjlevesque:fix/skip-keyring-auth-check

Conversation

@benjlevesque

Copy link
Copy Markdown
Contributor

Fixes #7145

Comment thread internal/config/config.go 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
Comment thread pkg/cmdutil/auth_check.go Outdated
// Any non-github.com hostname is fine here
dummyHostname := "example.com"
token, _ := cfg.Authentication().Token(dummyHostname)
token, _ := cfg.Authentication().TokenFromEnvOrConfig(dummyHostname)

Copy link
Copy Markdown
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
Copy Markdown
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

@mislav mislav Mar 15, 2023 •

Copy link
Copy Markdown
Contributor

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

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

see 70a6acc

@mislav mislav left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thank you!

Comment thread internal/config/config.go Outdated
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
Copy Markdown
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
Copy Markdown
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?

Comment thread internal/config/config.go Resolved
Comment thread internal/config/config.go Resolved
@benjlevesque
benjlevesque force-pushed the fix/skip-keyring-auth-check branch from bea6e78 to f91f1db Compare March 17, 2023 09:32
@benjlevesque
benjlevesque requested a review from samcoe March 17, 2023 09:33
@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
@benjlevesque
benjlevesque deleted the fix/skip-keyring-auth-check branch March 18, 2023 01:27
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

None yet

Development

Successfully merging this pull request may close these issues.

New keyring auth slowing down gh

4 participants