Load Subnet proxy and API key from the env if found (#4557)

This commit is contained in:
Anis Eleuch
2023-05-09 10:11:27 -07:00
committed by GitHub
parent ada4096d0b
commit aefb1db4db
2 changed files with 18 additions and 6 deletions
+16 -4
View File
@@ -66,8 +66,9 @@ mr/cKCUyBL7rcAvg0zNq1vcSrUSGlAmY3SEDCu3GOKnjG/U4E7+p957ocWSV+mQU
Usage: "use in environments without network access to SUBNET (e.g. airgapped, firewalled, etc.)",
},
cli.StringFlag{
Name: "api-key",
Usage: "API Key of the account on SUBNET",
Name: "api-key",
Usage: "API Key of the account on SUBNET",
EnvVar: "_MC_SUBNET_API_KEY",
},
}
)
@@ -215,7 +216,7 @@ func subnetReqDo(r *http.Request, headers map[string]string) (string, error) {
if resp.StatusCode == http.StatusOK {
return respStr, nil
}
return respStr, fmt.Errorf("Request failed with code %d and error: %s", resp.StatusCode, respStr)
return respStr, fmt.Errorf("Request failed with code %d with error: %s", resp.StatusCode, respStr)
}
func subnetGetReq(reqURL string, headers map[string]string) (string, error) {
@@ -293,8 +294,19 @@ func setGlobalSubnetProxyFromConfig(alias string) error {
return nil
}
var (
proxy string
supported bool
)
if env, ok := os.LookupEnv("_MC_SUBNET_PROXY_URL"); ok {
proxy = env
supported = env != ""
} else {
proxy, supported = getKeyFromSubnetConfig(alias, "proxy")
}
// get the subnet proxy config from MinIO if available
proxy, supported := getKeyFromSubnetConfig(alias, "proxy")
if supported && len(proxy) > 0 {
proxyURL, e := url.Parse(proxy)
if e != nil {
+2 -2
View File
@@ -208,8 +208,8 @@ func execSupportProfile(ctx *cli.Context, client *madmin.AdminClient, alias stri
if !globalAirgapped {
_, e := uploadFileToSubnet(alias, profileFile, reqURL, headers)
if e != nil {
failureClr.Println("\nUnable to upload profile file to SUBNET.", e.Error())
successClr.Printf("It has been saved locally at '%s'\n", profileFile)
failureClr.Println("\nUnable to upload profile file to SUBNET:", e.Error())
successClr.Printf("Profiling data are saved locally at '%s'\n", profileFile)
return
}
successClr.Println("uploaded successfully to SUBNET.")