client-go: Update RoundTrippers to be Unwrappable

Kubernetes-commit: fd5775c192fb4d47250a2d99f3e022acb1c7c0f0
This commit is contained in:
Antoine Pelisse
2017-08-16 08:39:57 -07:00
committed by Kubernetes Publisher
parent db8228460e
commit fc47db2e7e
8 changed files with 24 additions and 0 deletions

View File

@@ -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",

View File

@@ -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 }