From fc47db2e7edcc54596e0ee00ad240bfe4ef7ed3d Mon Sep 17 00:00:00 2001 From: Antoine Pelisse Date: Wed, 16 Aug 2017 08:39:57 -0700 Subject: [PATCH] client-go: Update RoundTrippers to be Unwrappable Kubernetes-commit: fd5775c192fb4d47250a2d99f3e022acb1c7c0f0 --- plugin/pkg/client/auth/azure/BUILD | 1 + plugin/pkg/client/auth/azure/azure.go | 5 +++++ plugin/pkg/client/auth/gcp/BUILD | 1 + plugin/pkg/client/auth/gcp/gcp.go | 5 +++++ plugin/pkg/client/auth/oidc/BUILD | 1 + plugin/pkg/client/auth/oidc/oidc.go | 5 +++++ plugin/pkg/client/auth/openstack/BUILD | 1 + plugin/pkg/client/auth/openstack/openstack.go | 5 +++++ 8 files changed, 24 insertions(+) diff --git a/plugin/pkg/client/auth/azure/BUILD b/plugin/pkg/client/auth/azure/BUILD index 2c928c71..78f22c98 100644 --- a/plugin/pkg/client/auth/azure/BUILD +++ b/plugin/pkg/client/auth/azure/BUILD @@ -21,6 +21,7 @@ go_library( "//vendor/github.com/Azure/go-autorest/autorest/adal:go_default_library", "//vendor/github.com/Azure/go-autorest/autorest/azure:go_default_library", "//vendor/github.com/golang/glog:go_default_library", + "//vendor/k8s.io/apimachinery/pkg/util/net:go_default_library", "//vendor/k8s.io/client-go/rest:go_default_library", ], ) diff --git a/plugin/pkg/client/auth/azure/azure.go b/plugin/pkg/client/auth/azure/azure.go index 06744e74..e14dc8d9 100644 --- a/plugin/pkg/client/auth/azure/azure.go +++ b/plugin/pkg/client/auth/azure/azure.go @@ -28,6 +28,7 @@ import ( "github.com/Azure/go-autorest/autorest/azure" "github.com/golang/glog" + "k8s.io/apimachinery/pkg/util/net" restclient "k8s.io/client-go/rest" ) @@ -113,6 +114,8 @@ type azureRoundTripper struct { roundTripper http.RoundTripper } +var _ net.RoundTripperWrapper = &azureRoundTripper{} + func (r *azureRoundTripper) RoundTrip(req *http.Request) (*http.Response, error) { if len(req.Header.Get(authHeader)) != 0 { return r.roundTripper.RoundTrip(req) @@ -137,6 +140,8 @@ func (r *azureRoundTripper) RoundTrip(req *http.Request) (*http.Response, error) return r.roundTripper.RoundTrip(req2) } +func (r *azureRoundTripper) WrappedRoundTripper() http.RoundTripper { return r.roundTripper } + type azureToken struct { token adal.Token clientID string diff --git a/plugin/pkg/client/auth/gcp/BUILD b/plugin/pkg/client/auth/gcp/BUILD index adba877c..e5ed0ffd 100644 --- a/plugin/pkg/client/auth/gcp/BUILD +++ b/plugin/pkg/client/auth/gcp/BUILD @@ -21,6 +21,7 @@ go_library( "//vendor/golang.org/x/net/context:go_default_library", "//vendor/golang.org/x/oauth2:go_default_library", "//vendor/golang.org/x/oauth2/google:go_default_library", + "//vendor/k8s.io/apimachinery/pkg/util/net:go_default_library", "//vendor/k8s.io/apimachinery/pkg/util/yaml:go_default_library", "//vendor/k8s.io/client-go/rest:go_default_library", "//vendor/k8s.io/client-go/util/jsonpath:go_default_library", diff --git a/plugin/pkg/client/auth/gcp/gcp.go b/plugin/pkg/client/auth/gcp/gcp.go index 59a27bea..d2e622ba 100644 --- a/plugin/pkg/client/auth/gcp/gcp.go +++ b/plugin/pkg/client/auth/gcp/gcp.go @@ -30,6 +30,7 @@ import ( "golang.org/x/net/context" "golang.org/x/oauth2" "golang.org/x/oauth2/google" + "k8s.io/apimachinery/pkg/util/net" "k8s.io/apimachinery/pkg/util/yaml" restclient "k8s.io/client-go/rest" "k8s.io/client-go/util/jsonpath" @@ -287,6 +288,8 @@ type conditionalTransport struct { persister restclient.AuthProviderConfigPersister } +var _ net.RoundTripperWrapper = &conditionalTransport{} + func (t *conditionalTransport) RoundTrip(req *http.Request) (*http.Response, error) { if len(req.Header.Get("Authorization")) != 0 { return t.oauthTransport.Base.RoundTrip(req) @@ -306,3 +309,5 @@ func (t *conditionalTransport) RoundTrip(req *http.Request) (*http.Response, err return res, nil } + +func (t *conditionalTransport) WrappedRoundTripper() http.RoundTripper { return t.oauthTransport.Base } diff --git a/plugin/pkg/client/auth/oidc/BUILD b/plugin/pkg/client/auth/oidc/BUILD index c65bfe9d..8f855cd0 100644 --- a/plugin/pkg/client/auth/oidc/BUILD +++ b/plugin/pkg/client/auth/oidc/BUILD @@ -18,6 +18,7 @@ go_library( deps = [ "//vendor/github.com/golang/glog:go_default_library", "//vendor/golang.org/x/oauth2:go_default_library", + "//vendor/k8s.io/apimachinery/pkg/util/net:go_default_library", "//vendor/k8s.io/client-go/rest:go_default_library", ], ) diff --git a/plugin/pkg/client/auth/oidc/oidc.go b/plugin/pkg/client/auth/oidc/oidc.go index ecfd13eb..27ba722a 100644 --- a/plugin/pkg/client/auth/oidc/oidc.go +++ b/plugin/pkg/client/auth/oidc/oidc.go @@ -30,6 +30,7 @@ import ( "github.com/golang/glog" "golang.org/x/oauth2" + "k8s.io/apimachinery/pkg/util/net" restclient "k8s.io/client-go/rest" ) @@ -189,6 +190,8 @@ type roundTripper struct { wrapped http.RoundTripper } +var _ net.RoundTripperWrapper = &roundTripper{} + func (r *roundTripper) RoundTrip(req *http.Request) (*http.Response, error) { if len(req.Header.Get("Authorization")) != 0 { return r.wrapped.RoundTrip(req) @@ -212,6 +215,8 @@ func (r *roundTripper) RoundTrip(req *http.Request) (*http.Response, error) { return r.wrapped.RoundTrip(r2) } +func (t *roundTripper) WrappedRoundTripper() http.RoundTripper { return t.wrapped } + func (p *oidcAuthProvider) idToken() (string, error) { p.mu.Lock() defer p.mu.Unlock() diff --git a/plugin/pkg/client/auth/openstack/BUILD b/plugin/pkg/client/auth/openstack/BUILD index 211e390e..e6912829 100644 --- a/plugin/pkg/client/auth/openstack/BUILD +++ b/plugin/pkg/client/auth/openstack/BUILD @@ -18,6 +18,7 @@ go_library( deps = [ "//vendor/github.com/golang/glog:go_default_library", "//vendor/github.com/gophercloud/gophercloud/openstack:go_default_library", + "//vendor/k8s.io/apimachinery/pkg/util/net:go_default_library", "//vendor/k8s.io/client-go/rest:go_default_library", ], ) diff --git a/plugin/pkg/client/auth/openstack/openstack.go b/plugin/pkg/client/auth/openstack/openstack.go index 9df94913..490eff12 100644 --- a/plugin/pkg/client/auth/openstack/openstack.go +++ b/plugin/pkg/client/auth/openstack/openstack.go @@ -25,6 +25,7 @@ import ( "github.com/golang/glog" "github.com/gophercloud/gophercloud/openstack" + "k8s.io/apimachinery/pkg/util/net" restclient "k8s.io/client-go/rest" ) @@ -102,6 +103,8 @@ type tokenRoundTripper struct { tokenGetter TokenGetter } +var _ net.RoundTripperWrapper = &tokenRoundTripper{} + // RoundTrip adds the bearer token into the request. func (t *tokenRoundTripper) RoundTrip(req *http.Request) (*http.Response, error) { // if the authorization header already present, use it. @@ -119,6 +122,8 @@ func (t *tokenRoundTripper) RoundTrip(req *http.Request) (*http.Response, error) return t.RoundTripper.RoundTrip(req) } +func (t *tokenRoundTripper) WrappedRoundTripper() http.RoundTripper { return t.RoundTripper } + // newOpenstackAuthProvider creates an auth provider which works with openstack // environment. func newOpenstackAuthProvider(clusterAddress string, config map[string]string, persister restclient.AuthProviderConfigPersister) (restclient.AuthProvider, error) {