rgw/admin: add an interface around the HTTP Client

We now have a new interface `HTTPClient` which helps us doing various
operations such as mutating and mocking the HTTP Client.

Signed-off-by: Sébastien Han <seb@redhat.com>
This commit is contained in:
Sébastien Han 2021-07-13 17:16:13 +02:00 committed by mergify[bot]
parent 5da5db0b9c
commit 53b3842e29
1 changed files with 8 additions and 3 deletions

View File

@ -28,6 +28,11 @@ var (
errNoSecretKey = errors.New("secret key not set")
)
// HTTPClient interface that conforms to that of the http package's Client.
type HTTPClient interface {
Do(req *http.Request) (*http.Response, error)
}
type verbHTTP string
// API struct for New Client
@ -35,12 +40,12 @@ type API struct {
AccessKey string
SecretKey string
Endpoint string
HTTPClient *http.Client
HTTPClient HTTPClient
Debug bool
}
// New returns client for Ceph RGW
func New(endpoint, accessKey, secretKey string, httpClient *http.Client) (*API, error) {
func New(endpoint, accessKey, secretKey string, httpClient HTTPClient) (*API, error) {
// validate endpoint
if endpoint == "" {
return nil, errNoEndpoint
@ -56,7 +61,7 @@ func New(endpoint, accessKey, secretKey string, httpClient *http.Client) (*API,
return nil, errNoSecretKey
}
// set http client, if TLS is desired it will have to be passed with an http client
// If no client is passed initialize it
if httpClient == nil {
httpClient = &http.Client{Timeout: connectionTimeout}
}