Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit1993093

Browse files
committed
Add comments
1 parent6745875 commit1993093

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

‎coderd/externalauth/externalauth.go‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,16 @@ func (c *DeviceAuth) AuthorizeDevice(ctx context.Context) (*codersdk.ExternalAut
300300
iferr!=nil {
301301
returnnil,err
302302
}
303-
resp,err:=c.Cfg.Do(ctx,"AuthorizeDevice",req)
303+
304+
do:=http.DefaultClient.Do
305+
ifc.Cfg!=nil {
306+
// The cfg can be nil in unit tests.
307+
do=func(req*http.Request) (*http.Response,error) {
308+
returnc.Cfg.Do(ctx,"AuthorizeDevice",req)
309+
}
310+
}
311+
312+
resp,err:=do(req)
304313
req.Header.Set("Accept","application/json")
305314
iferr!=nil {
306315
returnnil,err

‎coderd/promoauth/oauth2.go‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,19 @@ type OAuth2Config interface {
2121
// InstrumentedOAuth2Config extends OAuth2Config with a `Do` method that allows
2222
// external oauth related calls to be instrumented. This is to support
2323
// "ValidateToken" which is not an oauth2 specified method.
24+
// These calls still count against the api rate limit, and should be instrumented.
2425
typeInstrumentedOAuth2Configinterface {
2526
OAuth2Config
2627

2728
// Do is provided as a convenience method to make a request with the oauth2 client.
2829
// It mirrors `http.Client.Do`.
29-
// We need this because Coder adds some extra functionality to
30-
// oauth clients such as the `ValidateToken()` method.
3130
Do(ctx context.Context,sourcestring,req*http.Request) (*http.Response,error)
3231
}
3332

3433
var_OAuth2Config= (*Config)(nil)
3534

35+
// Factory allows us to have 1 set of metrics for all oauth2 providers.
36+
// Primarily to avoid any prometheus errors registering duplicate metrics.
3637
typeFactorystruct {
3738
metrics*metrics
3839
}
@@ -107,10 +108,11 @@ func (c *Config) wrapClient(ctx context.Context, source string) context.Context
107108
returncontext.WithValue(ctx,oauth2.HTTPClient,c.oauthHTTPClient(ctx,source))
108109
}
109110

111+
// oauthHTTPClient returns an http client that will instrument every request made.
110112
func (c*Config)oauthHTTPClient(ctx context.Context,sourcestring)*http.Client {
111113
cli:=&http.Client{}
112114

113-
// Check if the context hasan http client already.
115+
// Check if the context hasa http client already.
114116
ifhc,ok:=ctx.Value(oauth2.HTTPClient).(*http.Client);ok {
115117
cli=hc
116118
}
@@ -126,6 +128,8 @@ type instrumentedTripper struct {
126128
underlying http.RoundTripper
127129
}
128130

131+
// newInstrumentedTripper intercepts a http request, and increments the
132+
// externalRequestCount metric.
129133
funcnewInstrumentedTripper(c*Config,sourcestring,under http.RoundTripper)*instrumentedTripper {
130134
ifunder==nil {
131135
under=http.DefaultTransport

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp