Skip to content

Commit

Permalink
fix: Prevent nil panic. Fixes #7175
Browse files Browse the repository at this point in the history
Signed-off-by: Alex Collins <alex_collins@intuit.com>
  • Loading branch information
alexec committed Nov 9, 2021
1 parent 1c9ec22 commit 494f811
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 23 deletions.
14 changes: 8 additions & 6 deletions util/kubeconfig/kubeconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,15 +169,17 @@ func GetBearerToken(in *restclient.Config, explicitKubeConfigPath string) (strin
if err != nil {
return "", err
}
req := http.Request{Header: map[string][]string{}}

newT := NewUserAgentRoundTripper("dummy", rt)
resp, err := newT.RoundTrip(&req)
req, err := http.NewRequest("GET", in.Host, nil)
if err != nil {
return "", err
}
resp.Body.Close()

resp, err := rt.RoundTrip(req)
if err != nil {
return "", err
}
if err := resp.Body.Close(); err != nil {
return "", err
}
token := req.Header.Get("Authorization")
return strings.TrimPrefix(token, "Bearer "), nil
}
Expand Down
17 changes: 0 additions & 17 deletions util/kubeconfig/roundtripper.go

This file was deleted.

0 comments on commit 494f811

Please sign in to comment.