From 9760dd9943f99c0ab850ac350b818406eead30cd Mon Sep 17 00:00:00 2001 From: Haoran Wang Date: Wed, 10 May 2017 13:54:45 +0800 Subject: [PATCH] gcp auth provider not to override the Auth header if it's already exits --- .../client-go/plugin/pkg/client/auth/gcp/gcp.go | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/staging/src/k8s.io/client-go/plugin/pkg/client/auth/gcp/gcp.go b/staging/src/k8s.io/client-go/plugin/pkg/client/auth/gcp/gcp.go index 142ffdd50eb..f5d2899d91f 100644 --- a/staging/src/k8s.io/client-go/plugin/pkg/client/auth/gcp/gcp.go +++ b/staging/src/k8s.io/client-go/plugin/pkg/client/auth/gcp/gcp.go @@ -124,10 +124,7 @@ func newGCPAuthProvider(_ string, gcpConfig map[string]string, persister restcli } func (g *gcpAuthProvider) WrapTransport(rt http.RoundTripper) http.RoundTripper { - return &oauth2.Transport{ - Source: g.tokenSource, - Base: rt, - } + return &conditionalTransport{&oauth2.Transport{Source: g.tokenSource, Base: rt}} } func (g *gcpAuthProvider) Login() error { return nil } @@ -284,3 +281,14 @@ func parseJSONPath(input interface{}, name, template string) (string, error) { } return buf.String(), nil } + +type conditionalTransport struct { + oauthTransport *oauth2.Transport +} + +func (t *conditionalTransport) RoundTrip(req *http.Request) (*http.Response, error) { + if len(req.Header.Get("Authorization")) != 0 { + return t.oauthTransport.Base.RoundTrip(req) + } + return t.oauthTransport.RoundTrip(req) +}