Skip to content

Commit 6a83bd3

Browse files
committed
Remove custom code and use available utility code
1 parent 8c2dbe2 commit 6a83bd3

File tree

1 file changed

+2
-15
lines changed

1 file changed

+2
-15
lines changed

pkg/auth/client/impersonate.go

+2-15
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
authenticationapi "github.com/openshift/origin/pkg/auth/api"
1111
authorizationapi "github.com/openshift/origin/pkg/authorization/apis/authorization"
1212
"github.com/openshift/origin/pkg/client"
13+
utilnet "k8s.io/apimachinery/pkg/util/net"
1314
)
1415

1516
type impersonatingRoundTripper struct {
@@ -23,7 +24,7 @@ func NewImpersonatingRoundTripper(user user.Info, delegate http.RoundTripper) ht
2324
}
2425

2526
func (rt *impersonatingRoundTripper) RoundTrip(req *http.Request) (*http.Response, error) {
26-
req = cloneRequest(req)
27+
req = utilnet.CloneRequest(req)
2728
req.Header.Del(authenticationapi.ImpersonateUserHeader)
2829
req.Header.Del(authenticationapi.ImpersonateGroupHeader)
2930
req.Header.Del(authenticationapi.ImpersonateUserScopeHeader)
@@ -38,20 +39,6 @@ func (rt *impersonatingRoundTripper) RoundTrip(req *http.Request) (*http.Respons
3839
return rt.delegate.RoundTrip(req)
3940
}
4041

41-
// cloneRequest returns a clone of the provided *http.Request.
42-
// The clone is a shallow copy of the struct and its Header map.
43-
func cloneRequest(r *http.Request) *http.Request {
44-
// shallow copy of the struct
45-
r2 := new(http.Request)
46-
*r2 = *r
47-
// deep copy of the Header
48-
r2.Header = make(http.Header)
49-
for k, s := range r.Header {
50-
r2.Header[k] = s
51-
}
52-
return r2
53-
}
54-
5542
// NewImpersonatingConfig wraps the config's transport to impersonate a user, including user, groups, and scopes
5643
func NewImpersonatingConfig(user user.Info, config restclient.Config) restclient.Config {
5744
oldWrapTransport := config.WrapTransport

0 commit comments

Comments
 (0)