From 65efe40a822e31d0eae44daaf17e1b2475e0084e Mon Sep 17 00:00:00 2001 From: Shireesh Anjal <355479+anjalshireesh@users.noreply.github.com> Date: Mon, 14 Feb 2022 11:43:27 +0530 Subject: [PATCH] Use subnet proxy from minio config if available (#3969) minio now supports storing the proxy to be used for connecting to subnet in the `subnet proxy` config. So mc can use it if available when communicating with subnet during cluster registration or diagnostics upload. --- cmd/subnet-utils.go | 24 ++++++++++++++++++++++++ cmd/support-diag.go | 5 +++++ 2 files changed, 29 insertions(+) diff --git a/cmd/subnet-utils.go b/cmd/subnet-utils.go index 81c3c457..cd09c123 100644 --- a/cmd/subnet-utils.go +++ b/cmd/subnet-utils.go @@ -27,6 +27,7 @@ import ( "io" "io/ioutil" "net/http" + "net/url" "os" "strconv" "strings" @@ -240,6 +241,24 @@ func getSubnetAPIKeyFromConfig(alias string) string { return mcConfig().Aliases[alias].APIKey } +func setSubnetProxyFromConfig(alias string) error { + if globalSubnetProxyURL != nil { + // proxy already set via command line arg. + return nil + } + + // get the subnet proxy config from MinIO if available + supported, proxy := getSubnetKeyFromMinIOConfig(alias, "proxy") + if supported { + proxyURL, e := url.Parse(proxy) + if e != nil { + return e + } + globalSubnetProxyURL = proxyURL + } + return nil +} + func getSubnetLicenseFromConfig(alias string) string { // get the subnet license config from MinIO if available supported, lic := getSubnetKeyFromMinIOConfig(alias, "license") @@ -414,6 +433,11 @@ func getSubnetAccID(headers map[string]string) (string, error) { // registerClusterOnSubnet - Registers the given cluster on SUBNET func registerClusterOnSubnet(alias string, clusterRegInfo ClusterRegistrationInfo) (string, error) { + e := setSubnetProxyFromConfig(alias) + if e != nil { + return "", e + } + apiKey := getSubnetAPIKeyFromConfig(alias) lic := "" diff --git a/cmd/support-diag.go b/cmd/support-diag.go index f8d703d8..6e5f6e5c 100644 --- a/cmd/support-diag.go +++ b/cmd/support-diag.go @@ -316,6 +316,11 @@ func prepareDiagUploadURL(alias string, clusterName string, filename string, lic } func uploadDiagReport(alias string, filename string, reqURL string, headers map[string]string) error { + e := setSubnetProxyFromConfig(alias) + if e != nil { + return e + } + req, e := subnetUploadReq(reqURL, filename) if e != nil { return e