assert RoundTripperWrapper interface

This commit is contained in:
Antonio Ojea 2021-11-05 14:53:22 +01:00
parent ef190f860a
commit 938cc5445d
2 changed files with 15 additions and 0 deletions

View File

@ -92,6 +92,8 @@ type authProxyRoundTripper struct {
rt http.RoundTripper
}
var _ utilnet.RoundTripperWrapper = &authProxyRoundTripper{}
// NewAuthProxyRoundTripper provides a roundtripper which will add auth proxy fields to requests for
// authentication terminating proxy cases
// assuming you pull the user from the context:
@ -150,6 +152,8 @@ type userAgentRoundTripper struct {
rt http.RoundTripper
}
var _ utilnet.RoundTripperWrapper = &userAgentRoundTripper{}
// NewUserAgentRoundTripper will add User-Agent header to a request unless it has already been set.
func NewUserAgentRoundTripper(agent string, rt http.RoundTripper) http.RoundTripper {
return &userAgentRoundTripper{agent, rt}
@ -176,6 +180,8 @@ type basicAuthRoundTripper struct {
rt http.RoundTripper
}
var _ utilnet.RoundTripperWrapper = &basicAuthRoundTripper{}
// NewBasicAuthRoundTripper will apply a BASIC auth authorization header to a
// request unless it has already been set.
func NewBasicAuthRoundTripper(username, password string, rt http.RoundTripper) http.RoundTripper {
@ -225,6 +231,8 @@ type impersonatingRoundTripper struct {
delegate http.RoundTripper
}
var _ utilnet.RoundTripperWrapper = &impersonatingRoundTripper{}
// NewImpersonatingRoundTripper will add an Act-As header to a request unless it has already been set.
func NewImpersonatingRoundTripper(impersonate ImpersonationConfig, delegate http.RoundTripper) http.RoundTripper {
return &impersonatingRoundTripper{impersonate, delegate}
@ -264,6 +272,8 @@ type bearerAuthRoundTripper struct {
rt http.RoundTripper
}
var _ utilnet.RoundTripperWrapper = &bearerAuthRoundTripper{}
// NewBearerAuthRoundTripper adds the provided bearer token to a request
// unless the authorization header has already been set.
func NewBearerAuthRoundTripper(bearer string, rt http.RoundTripper) http.RoundTripper {
@ -373,6 +383,8 @@ type debuggingRoundTripper struct {
levels map[DebugLevel]bool
}
var _ utilnet.RoundTripperWrapper = &debuggingRoundTripper{}
// DebugLevel is used to enable debugging of certain
// HTTP requests and responses fields via the debuggingRoundTripper.
type DebugLevel int

View File

@ -26,6 +26,7 @@ import (
"golang.org/x/oauth2"
utilnet "k8s.io/apimachinery/pkg/util/net"
"k8s.io/klog/v2"
)
@ -95,6 +96,8 @@ type tokenSourceTransport struct {
src ResettableTokenSource
}
var _ utilnet.RoundTripperWrapper = &tokenSourceTransport{}
func (tst *tokenSourceTransport) RoundTrip(req *http.Request) (*http.Response, error) {
// This is to allow --token to override other bearer token providers.
if req.Header.Get("Authorization") != "" {