mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-26 21:17:23 +00:00
Merge pull request #19887 from liggitt/export_transports
Export transport constructors
This commit is contained in:
commit
ba6c939b3e
@ -41,12 +41,12 @@ func HTTPWrappersForConfig(config *Config, rt http.RoundTripper) (http.RoundTrip
|
|||||||
case config.HasBasicAuth() && config.HasTokenAuth():
|
case config.HasBasicAuth() && config.HasTokenAuth():
|
||||||
return nil, fmt.Errorf("username/password or bearer token may be set, but not both")
|
return nil, fmt.Errorf("username/password or bearer token may be set, but not both")
|
||||||
case config.HasTokenAuth():
|
case config.HasTokenAuth():
|
||||||
rt = newBearerAuthRoundTripper(config.BearerToken, rt)
|
rt = NewBearerAuthRoundTripper(config.BearerToken, rt)
|
||||||
case config.HasBasicAuth():
|
case config.HasBasicAuth():
|
||||||
rt = newBasicAuthRoundTripper(config.Username, config.Password, rt)
|
rt = NewBasicAuthRoundTripper(config.Username, config.Password, rt)
|
||||||
}
|
}
|
||||||
if len(config.UserAgent) > 0 {
|
if len(config.UserAgent) > 0 {
|
||||||
rt = newUserAgentRoundTripper(config.UserAgent, rt)
|
rt = NewUserAgentRoundTripper(config.UserAgent, rt)
|
||||||
}
|
}
|
||||||
return rt, nil
|
return rt, nil
|
||||||
}
|
}
|
||||||
@ -76,7 +76,7 @@ type userAgentRoundTripper struct {
|
|||||||
rt http.RoundTripper
|
rt http.RoundTripper
|
||||||
}
|
}
|
||||||
|
|
||||||
func newUserAgentRoundTripper(agent string, rt http.RoundTripper) http.RoundTripper {
|
func NewUserAgentRoundTripper(agent string, rt http.RoundTripper) http.RoundTripper {
|
||||||
return &userAgentRoundTripper{agent, rt}
|
return &userAgentRoundTripper{agent, rt}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -105,7 +105,7 @@ type basicAuthRoundTripper struct {
|
|||||||
|
|
||||||
// NewBasicAuthRoundTripper will apply a BASIC auth authorization header to a
|
// NewBasicAuthRoundTripper will apply a BASIC auth authorization header to a
|
||||||
// request unless it has already been set.
|
// request unless it has already been set.
|
||||||
func newBasicAuthRoundTripper(username, password string, rt http.RoundTripper) http.RoundTripper {
|
func NewBasicAuthRoundTripper(username, password string, rt http.RoundTripper) http.RoundTripper {
|
||||||
return &basicAuthRoundTripper{username, password, rt}
|
return &basicAuthRoundTripper{username, password, rt}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -133,7 +133,7 @@ type bearerAuthRoundTripper struct {
|
|||||||
|
|
||||||
// NewBearerAuthRoundTripper adds the provided bearer token to a request
|
// NewBearerAuthRoundTripper adds the provided bearer token to a request
|
||||||
// unless the authorization header has already been set.
|
// unless the authorization header has already been set.
|
||||||
func newBearerAuthRoundTripper(bearer string, rt http.RoundTripper) http.RoundTripper {
|
func NewBearerAuthRoundTripper(bearer string, rt http.RoundTripper) http.RoundTripper {
|
||||||
return &bearerAuthRoundTripper{bearer, rt}
|
return &bearerAuthRoundTripper{bearer, rt}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -35,7 +35,7 @@ func (rt *testRoundTripper) RoundTrip(req *http.Request) (*http.Response, error)
|
|||||||
func TestBearerAuthRoundTripper(t *testing.T) {
|
func TestBearerAuthRoundTripper(t *testing.T) {
|
||||||
rt := &testRoundTripper{}
|
rt := &testRoundTripper{}
|
||||||
req := &http.Request{}
|
req := &http.Request{}
|
||||||
newBearerAuthRoundTripper("test", rt).RoundTrip(req)
|
NewBearerAuthRoundTripper("test", rt).RoundTrip(req)
|
||||||
if rt.Request == nil {
|
if rt.Request == nil {
|
||||||
t.Fatalf("unexpected nil request: %v", rt)
|
t.Fatalf("unexpected nil request: %v", rt)
|
||||||
}
|
}
|
||||||
@ -57,7 +57,7 @@ func TestBasicAuthRoundTripper(t *testing.T) {
|
|||||||
} {
|
} {
|
||||||
rt := &testRoundTripper{}
|
rt := &testRoundTripper{}
|
||||||
req := &http.Request{}
|
req := &http.Request{}
|
||||||
newBasicAuthRoundTripper(tc.user, tc.pass, rt).RoundTrip(req)
|
NewBasicAuthRoundTripper(tc.user, tc.pass, rt).RoundTrip(req)
|
||||||
if rt.Request == nil {
|
if rt.Request == nil {
|
||||||
t.Fatalf("%s: unexpected nil request: %v", n, rt)
|
t.Fatalf("%s: unexpected nil request: %v", n, rt)
|
||||||
}
|
}
|
||||||
@ -76,7 +76,7 @@ func TestUserAgentRoundTripper(t *testing.T) {
|
|||||||
Header: make(http.Header),
|
Header: make(http.Header),
|
||||||
}
|
}
|
||||||
req.Header.Set("User-Agent", "other")
|
req.Header.Set("User-Agent", "other")
|
||||||
newUserAgentRoundTripper("test", rt).RoundTrip(req)
|
NewUserAgentRoundTripper("test", rt).RoundTrip(req)
|
||||||
if rt.Request == nil {
|
if rt.Request == nil {
|
||||||
t.Fatalf("unexpected nil request: %v", rt)
|
t.Fatalf("unexpected nil request: %v", rt)
|
||||||
}
|
}
|
||||||
@ -88,7 +88,7 @@ func TestUserAgentRoundTripper(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
req = &http.Request{}
|
req = &http.Request{}
|
||||||
newUserAgentRoundTripper("test", rt).RoundTrip(req)
|
NewUserAgentRoundTripper("test", rt).RoundTrip(req)
|
||||||
if rt.Request == nil {
|
if rt.Request == nil {
|
||||||
t.Fatalf("unexpected nil request: %v", rt)
|
t.Fatalf("unexpected nil request: %v", rt)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user