diff --git a/cmd/subnet-utils.go b/cmd/subnet-utils.go index 698dbcb9..d3c029b9 100644 --- a/cmd/subnet-utils.go +++ b/cmd/subnet-utils.go @@ -434,18 +434,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) + apiKey, lic, e := getSubnetCreds(alias) if e != nil { return "", e } - apiKey := getSubnetAPIKeyFromConfig(alias) - - lic := "" - if len(apiKey) == 0 { - lic = getSubnetLicenseFromConfig(alias) - } - regURL, headers, e := subnetURLWithAuth(subnetRegisterURL(), apiKey, lic) if e != nil { return "", e @@ -460,6 +453,22 @@ func registerClusterOnSubnet(alias string, clusterRegInfo ClusterRegistrationInf return subnetPostReq(regURL, reqPayload, headers) } +func getSubnetCreds(alias string) (string, string, error) { + e := setSubnetProxyFromConfig(alias) + if e != nil { + return "", "", e + } + + apiKey := getSubnetAPIKeyFromConfig(alias) + + lic := "" + if len(apiKey) == 0 { + lic = getSubnetLicenseFromConfig(alias) + } + + return apiKey, lic, nil +} + // extractAndSaveAPIKey - extract api key from response and set it in minio config func extractAndSaveAPIKey(alias string, resp string) { subnetAPIKey := gjson.Parse(resp).Get("api_key").String() diff --git a/cmd/support-register.go b/cmd/support-register.go index e7d44046..dbf98127 100644 --- a/cmd/support-register.go +++ b/cmd/support-register.go @@ -23,6 +23,7 @@ import ( "os" "strings" + "github.com/fatih/color" "github.com/google/uuid" "github.com/minio/cli" "github.com/minio/mc/pkg/probe" @@ -109,6 +110,7 @@ type SubnetMFAReq struct { } func mainSupportRegister(ctx *cli.Context) error { + console.SetColor("RegisterSuccessMessage", color.New(color.FgGreen, color.Bold)) checkSupportRegisterSyntax(ctx) // Get the alias parameter from cli @@ -138,12 +140,26 @@ func mainSupportRegister(ctx *cli.Context) error { regInfo := getClusterRegInfo(admInfo, clusterName) + alreadyRegistered := false + apiKey, lic, e := getSubnetCreds(alias) + fatalIf(probe.NewError(e), "Error in fetching subnet credentials") + if len(apiKey) > 0 || len(lic) > 0 { + alreadyRegistered = true + } + if offline { registerOffline(regInfo, alias) } else { registerOnline(regInfo, alias, clusterName) } - console.Infoln(fmt.Sprintln("Cluster", clusterName, "successfully registered on SUBNET.")) + + action := "registered" + if alreadyRegistered { + action = "updated" + } + + msg := console.Colorize("RegisterSuccessMessage", fmt.Sprintf("%s %s successfully.", clusterName, action)) + fmt.Println(msg) return nil }