mirror of
https://github.com/coder/coder.git
synced 2025-07-03 16:13:58 +00:00
chore: instrument additional github api calls (#11824)
* chore: instrument additional githubapi calls This only affects github as a login source, not external auth.
This commit is contained in:
@ -19,6 +19,11 @@ const (
|
||||
SourceTokenSource Oauth2Source = "TokenSource"
|
||||
SourceAppInstallations Oauth2Source = "AppInstallations"
|
||||
SourceAuthorizeDevice Oauth2Source = "AuthorizeDevice"
|
||||
|
||||
SourceGitAPIAuthUser Oauth2Source = "GitAPIAuthUser"
|
||||
SourceGitAPIListEmails Oauth2Source = "GitAPIListEmails"
|
||||
SourceGitAPIOrgMemberships Oauth2Source = "GitAPIOrgMemberships"
|
||||
SourceGitAPITeamMemberships Oauth2Source = "GitAPITeamMemberships"
|
||||
)
|
||||
|
||||
// OAuth2Config exposes a subset of *oauth2.Config functions for easier testing.
|
||||
@ -209,6 +214,12 @@ func (c *Config) TokenSource(ctx context.Context, token *oauth2.Token) oauth2.To
|
||||
return c.underlying.TokenSource(c.wrapClient(ctx, SourceTokenSource), token)
|
||||
}
|
||||
|
||||
func (c *Config) InstrumentHTTPClient(hc *http.Client, source Oauth2Source) *http.Client {
|
||||
// The new tripper will instrument every request made by the oauth2 client.
|
||||
hc.Transport = newInstrumentedTripper(c, source, hc.Transport)
|
||||
return hc
|
||||
}
|
||||
|
||||
// wrapClient is the only way we can accurately instrument the oauth2 client.
|
||||
// This is because method calls to the 'OAuth2Config' interface are not 1:1 with
|
||||
// network requests.
|
||||
@ -229,8 +240,7 @@ func (c *Config) oauthHTTPClient(ctx context.Context, source Oauth2Source) *http
|
||||
cli = hc
|
||||
}
|
||||
|
||||
// The new tripper will instrument every request made by the oauth2 client.
|
||||
cli.Transport = newInstrumentedTripper(c, source, cli.Transport)
|
||||
cli = c.InstrumentHTTPClient(cli, source)
|
||||
return cli
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user