Add timeout to Tailscale WhoIs call
This commit is contained in:
parent
7a1a654b73
commit
972ff18012
1 changed files with 6 additions and 3 deletions
|
@ -7,6 +7,7 @@ import (
|
|||
"net/http"
|
||||
"strconv"
|
||||
"tailscale.com/client/tailscale"
|
||||
"time"
|
||||
)
|
||||
|
||||
func init() {
|
||||
|
@ -30,8 +31,10 @@ func (ta *TailscaleAuth) Provision(caddy.Context) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func (ta *TailscaleAuth) Authenticate(wr http.ResponseWriter, req *http.Request) (caddyauth.User, bool, error) {
|
||||
whois, err := ta.lc.WhoIs(context.Background(), req.RemoteAddr)
|
||||
func (ta *TailscaleAuth) Authenticate(_ http.ResponseWriter, req *http.Request) (caddyauth.User, bool, error) {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), time.Second*30)
|
||||
defer cancel()
|
||||
whois, err := ta.lc.WhoIs(ctx, req.RemoteAddr)
|
||||
if err != nil {
|
||||
return caddyauth.User{}, false, err
|
||||
}
|
||||
|
@ -43,7 +46,7 @@ func (ta *TailscaleAuth) Authenticate(wr http.ResponseWriter, req *http.Request)
|
|||
"login_name": whois.UserProfile.LoginName,
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
return user, true, nil
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue