mirror of
https://github.com/goharbor/harbor.git
synced 2024-12-24 09:38:09 +01:00
provide NewClient() func
This commit is contained in:
parent
0cd7175a6b
commit
92d58f6287
@ -22,6 +22,15 @@ import (
|
|||||||
"github.com/vmware/harbor/utils/registry/auth"
|
"github.com/vmware/harbor/utils/registry/auth"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// NewClient returns a http.Client according to the handlers provided
|
||||||
|
func NewClient(handlers []auth.Handler) *http.Client {
|
||||||
|
transport := NewAuthTransport(http.DefaultTransport, handlers)
|
||||||
|
|
||||||
|
return &http.Client{
|
||||||
|
Transport: transport,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// NewClientStandardAuthHandlerEmbeded return a http.Client which will authorize the request
|
// NewClientStandardAuthHandlerEmbeded return a http.Client which will authorize the request
|
||||||
// according to the credential provided and send it again when encounters a 401 error
|
// according to the credential provided and send it again when encounters a 401 error
|
||||||
func NewClientStandardAuthHandlerEmbeded(credential *auth.Credential) *http.Client {
|
func NewClientStandardAuthHandlerEmbeded(credential *auth.Credential) *http.Client {
|
||||||
@ -31,11 +40,7 @@ func NewClientStandardAuthHandlerEmbeded(credential *auth.Credential) *http.Clie
|
|||||||
|
|
||||||
handlers = append(handlers, tokenHandler)
|
handlers = append(handlers, tokenHandler)
|
||||||
|
|
||||||
transport := NewAuthTransport(http.DefaultTransport, handlers)
|
return NewClient(handlers)
|
||||||
|
|
||||||
return &http.Client{
|
|
||||||
Transport: transport,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewClientUsernameAuthHandlerEmbeded return a http.Client which will authorize the request
|
// NewClientUsernameAuthHandlerEmbeded return a http.Client which will authorize the request
|
||||||
@ -47,11 +52,7 @@ func NewClientUsernameAuthHandlerEmbeded(username string) *http.Client {
|
|||||||
|
|
||||||
handlers = append(handlers, tokenHandler)
|
handlers = append(handlers, tokenHandler)
|
||||||
|
|
||||||
transport := NewAuthTransport(http.DefaultTransport, handlers)
|
return NewClient(handlers)
|
||||||
|
|
||||||
return &http.Client{
|
|
||||||
Transport: transport,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type authTransport struct {
|
type authTransport struct {
|
||||||
|
Loading…
Reference in New Issue
Block a user