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

Commite6f157c

Browse files
committed
improvements from code review
1 parentd3c2c68 commite6f157c

File tree

1 file changed

+6
-9
lines changed

1 file changed

+6
-9
lines changed

‎coderd/httpmw/apikey.go

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -232,13 +232,7 @@ func ExtractAPIKey(rw http.ResponseWriter, r *http.Request, cfg ExtractAPIKeyCon
232232
returnoptionalWrite(http.StatusUnauthorized,resp)
233233
}
234234

235-
var (
236-
link database.UserLink
237-
now=dbtime.Now()
238-
// Tracks if the API key has properties updated
239-
changed=false
240-
)
241-
235+
now:=dbtime.Now()
242236
ifkey.ExpiresAt.Before(now) {
243237
returnoptionalWrite(http.StatusUnauthorized, codersdk.Response{
244238
Message:SignedOutErrorMessage,
@@ -252,7 +246,7 @@ func ExtractAPIKey(rw http.ResponseWriter, r *http.Request, cfg ExtractAPIKeyCon
252246
ifkey.LoginType==database.LoginTypeGithub||key.LoginType==database.LoginTypeOIDC {
253247
varerrerror
254248
//nolint:gocritic // System needs to fetch UserLink to check if it's valid.
255-
link,err=cfg.DB.GetUserLinkByUserIDLoginType(dbauthz.AsSystemRestricted(ctx), database.GetUserLinkByUserIDLoginTypeParams{
249+
link,err:=cfg.DB.GetUserLinkByUserIDLoginType(dbauthz.AsSystemRestricted(ctx), database.GetUserLinkByUserIDLoginTypeParams{
256250
UserID:key.UserID,
257251
LoginType:key.LoginType,
258252
})
@@ -309,7 +303,7 @@ func ExtractAPIKey(rw http.ResponseWriter, r *http.Request, cfg ExtractAPIKeyCon
309303
iflink.OAuthRefreshToken=="" {
310304
returnoptionalWrite(http.StatusUnauthorized, codersdk.Response{
311305
Message:SignedOutErrorMessage,
312-
Detail:fmt.Sprintf("%s session expired at %q.",friendlyName,link.OAuthExpiry.String()),
306+
Detail:fmt.Sprintf("%s session expired at %q. Try signing in again.",friendlyName,link.OAuthExpiry.String()),
313307
})
314308
}
315309
// We have a refresh token, so let's try it
@@ -351,6 +345,9 @@ func ExtractAPIKey(rw http.ResponseWriter, r *http.Request, cfg ExtractAPIKeyCon
351345
}
352346
}
353347

348+
// Tracks if the API key has properties updated
349+
changed:=false
350+
354351
// Only update LastUsed once an hour to prevent database spam.
355352
ifnow.Sub(key.LastUsed)>time.Hour {
356353
key.LastUsed=now

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp