mirror of https://github.com/k3s-io/k3s
Export transport constructors
parent
a9050679a5
commit
605979673b
|
@ -41,12 +41,12 @@ func HTTPWrappersForConfig(config *Config, rt http.RoundTripper) (http.RoundTrip
|
|||
case config.HasBasicAuth() && config.HasTokenAuth():
|
||||
return nil, fmt.Errorf("username/password or bearer token may be set, but not both")
|
||||
case config.HasTokenAuth():
|
||||
rt = newBearerAuthRoundTripper(config.BearerToken, rt)
|
||||
rt = NewBearerAuthRoundTripper(config.BearerToken, rt)
|
||||
case config.HasBasicAuth():
|
||||
rt = newBasicAuthRoundTripper(config.Username, config.Password, rt)
|
||||
rt = NewBasicAuthRoundTripper(config.Username, config.Password, rt)
|
||||
}
|
||||
if len(config.UserAgent) > 0 {
|
||||
rt = newUserAgentRoundTripper(config.UserAgent, rt)
|
||||
rt = NewUserAgentRoundTripper(config.UserAgent, rt)
|
||||
}
|
||||
return rt, nil
|
||||
}
|
||||
|
@ -76,7 +76,7 @@ type userAgentRoundTripper struct {
|
|||
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}
|
||||
}
|
||||
|
||||
|
@ -105,7 +105,7 @@ type basicAuthRoundTripper struct {
|
|||
|
||||
// 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 {
|
||||
func NewBasicAuthRoundTripper(username, password string, rt http.RoundTripper) http.RoundTripper {
|
||||
return &basicAuthRoundTripper{username, password, rt}
|
||||
}
|
||||
|
||||
|
@ -133,7 +133,7 @@ type bearerAuthRoundTripper struct {
|
|||
|
||||
// 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 {
|
||||
func NewBearerAuthRoundTripper(bearer string, rt http.RoundTripper) http.RoundTripper {
|
||||
return &bearerAuthRoundTripper{bearer, rt}
|
||||
}
|
||||
|
||||
|
|
|
@ -35,7 +35,7 @@ func (rt *testRoundTripper) RoundTrip(req *http.Request) (*http.Response, error)
|
|||
func TestBearerAuthRoundTripper(t *testing.T) {
|
||||
rt := &testRoundTripper{}
|
||||
req := &http.Request{}
|
||||
newBearerAuthRoundTripper("test", rt).RoundTrip(req)
|
||||
NewBearerAuthRoundTripper("test", rt).RoundTrip(req)
|
||||
if rt.Request == nil {
|
||||
t.Fatalf("unexpected nil request: %v", rt)
|
||||
}
|
||||
|
@ -57,7 +57,7 @@ func TestBasicAuthRoundTripper(t *testing.T) {
|
|||
} {
|
||||
rt := &testRoundTripper{}
|
||||
req := &http.Request{}
|
||||
newBasicAuthRoundTripper(tc.user, tc.pass, rt).RoundTrip(req)
|
||||
NewBasicAuthRoundTripper(tc.user, tc.pass, rt).RoundTrip(req)
|
||||
if rt.Request == nil {
|
||||
t.Fatalf("%s: unexpected nil request: %v", n, rt)
|
||||
}
|
||||
|
@ -76,7 +76,7 @@ func TestUserAgentRoundTripper(t *testing.T) {
|
|||
Header: make(http.Header),
|
||||
}
|
||||
req.Header.Set("User-Agent", "other")
|
||||
newUserAgentRoundTripper("test", rt).RoundTrip(req)
|
||||
NewUserAgentRoundTripper("test", rt).RoundTrip(req)
|
||||
if rt.Request == nil {
|
||||
t.Fatalf("unexpected nil request: %v", rt)
|
||||
}
|
||||
|
@ -88,7 +88,7 @@ func TestUserAgentRoundTripper(t *testing.T) {
|
|||
}
|
||||
|
||||
req = &http.Request{}
|
||||
newUserAgentRoundTripper("test", rt).RoundTrip(req)
|
||||
NewUserAgentRoundTripper("test", rt).RoundTrip(req)
|
||||
if rt.Request == nil {
|
||||
t.Fatalf("unexpected nil request: %v", rt)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue