Use global HTTP client whenever applicable (#2682)
This commit is contained in:
@@ -124,11 +124,6 @@ func getListConfigResponse(session *models.Principal, params cfgApi.ListConfigPa
|
||||
}
|
||||
|
||||
// getConfig gets the key values for a defined configuration.
|
||||
//
|
||||
// FIXME: This currently only returns config parameters in the default target
|
||||
// `madmin.Default`. Some configuration sub-systems are multi-target and since
|
||||
// this function does not accept a target argument, it ignores all non-default
|
||||
// targets.
|
||||
func getConfig(ctx context.Context, client MinioAdmin, name string) ([]*models.Configuration, error) {
|
||||
configBytes, err := client.getConfigKV(ctx, name)
|
||||
if err != nil {
|
||||
|
||||
@@ -21,6 +21,7 @@ import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"time"
|
||||
|
||||
"github.com/go-openapi/runtime/middleware"
|
||||
@@ -78,20 +79,23 @@ func getReleaseServiceURL() string {
|
||||
return fmt.Sprintf("%s/releases", host)
|
||||
}
|
||||
|
||||
func getReleases(url, repo, currentRelease, search, filter string) (*models.ReleaseListResponse, error) {
|
||||
func getReleases(endpoint, repo, currentRelease, search, filter string) (*models.ReleaseListResponse, error) {
|
||||
rl := &models.ReleaseListResponse{}
|
||||
client := &http.Client{Timeout: time.Second * 5}
|
||||
req, err := http.NewRequest("GET", url, nil)
|
||||
q := req.URL.Query()
|
||||
q.Add("repo", repo)
|
||||
q.Add("current", currentRelease)
|
||||
q.Add("search", search)
|
||||
q.Add("filter", filter)
|
||||
req.URL.RawQuery = q.Encode()
|
||||
req, err := http.NewRequest(http.MethodGet, endpoint, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
q := &url.Values{}
|
||||
q.Add("repo", repo)
|
||||
q.Add("search", search)
|
||||
q.Add("filter", filter)
|
||||
q.Add("current", currentRelease)
|
||||
req.URL.RawQuery = q.Encode()
|
||||
req.Header.Set("Content-Type", "application/json")
|
||||
|
||||
client := GetConsoleHTTPClient("")
|
||||
client.Timeout = time.Second * 5
|
||||
|
||||
resp, err := client.Do(req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
@@ -195,23 +195,17 @@ func SubnetLoginWithMFA(client xhttp.ClientI, username, mfaToken, otp string) (*
|
||||
|
||||
// GetSubnetHTTPClient will return a client with proxy if configured, otherwise will return the default console http client
|
||||
func GetSubnetHTTPClient(ctx context.Context, minioClient MinioAdmin) (*xhttp.Client, error) {
|
||||
var subnetHTTPClient *http.Client
|
||||
var proxy string
|
||||
envProxy := getSubnetProxy()
|
||||
subnetHTTPClient := GetConsoleHTTPClient("")
|
||||
subnetKey, err := GetSubnetKeyFromMinIOConfig(ctx, minioClient)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
proxy := getSubnetProxy()
|
||||
if subnetKey.Proxy != "" {
|
||||
proxy = subnetKey.Proxy
|
||||
} else if envProxy != "" {
|
||||
proxy = envProxy
|
||||
}
|
||||
if proxy != "" {
|
||||
transport := PrepareSTSClientTransport(false)
|
||||
subnetHTTPClient = &http.Client{
|
||||
Transport: transport,
|
||||
}
|
||||
subnetProxyURL, err := url.Parse(proxy)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
@@ -19,7 +19,6 @@ package restapi
|
||||
import (
|
||||
"os"
|
||||
|
||||
"github.com/minio/console/pkg/http"
|
||||
"github.com/minio/console/pkg/subnet"
|
||||
)
|
||||
|
||||
@@ -45,10 +44,7 @@ func (sp SubnetPlan) String() string {
|
||||
var InstanceLicensePlan = PlanAGPL
|
||||
|
||||
func fetchLicensePlan() {
|
||||
client := &http.Client{
|
||||
Client: GetConsoleHTTPClient(""),
|
||||
}
|
||||
licenseInfo, err := subnet.ParseLicense(client, os.Getenv(EnvSubnetLicense))
|
||||
licenseInfo, err := subnet.ParseLicense(GetConsoleHTTPClient(""), os.Getenv(EnvSubnetLicense))
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
@@ -18,7 +18,6 @@ package restapi
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
xhttp "github.com/minio/console/pkg/http"
|
||||
@@ -44,10 +43,12 @@ func registerVersionHandlers(api *operations.ConsoleAPI) {
|
||||
func getVersionResponse(params systemApi.CheckMinIOVersionParams) (*models.CheckVersionResponse, *models.Error) {
|
||||
ctx, cancel := context.WithCancel(params.HTTPRequest.Context())
|
||||
defer cancel()
|
||||
|
||||
client := GetConsoleHTTPClient("")
|
||||
client.Timeout = 15 * time.Second
|
||||
|
||||
ver, err := utils.GetLatestMinIOImage(&xhttp.Client{
|
||||
Client: &http.Client{
|
||||
Timeout: 15 * time.Second,
|
||||
},
|
||||
Client: client,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, ErrorWithContext(ctx, err)
|
||||
|
||||
Reference in New Issue
Block a user