diff --git a/cmd/subnet-utils.go b/cmd/subnet-utils.go index 4c916342..411be805 100644 --- a/cmd/subnet-utils.go +++ b/cmd/subnet-utils.go @@ -459,6 +459,11 @@ func registerClusterOnSubnet(alias string, clusterRegInfo ClusterRegistrationInf return "", e } + return registerClusterWithSubnetCreds(clusterRegInfo, apiKey, lic) +} + +// registerClusterOnSubnet - Registers the given cluster on SUBNET +func registerClusterWithSubnetCreds(clusterRegInfo ClusterRegistrationInfo, apiKey string, lic string) (string, error) { regURL, headers, e := subnetURLWithAuth(subnetRegisterURL(), apiKey, lic) if e != nil { return "", e diff --git a/cmd/support-register.go b/cmd/support-register.go index dc6a3ca6..09581844 100644 --- a/cmd/support-register.go +++ b/cmd/support-register.go @@ -19,6 +19,7 @@ package cmd import ( "bufio" + "errors" "fmt" "os" "strings" @@ -32,6 +33,10 @@ import ( ) var supportRegisterFlags = append([]cli.Flag{ + cli.StringFlag{ + Name: "api-key", + Usage: "SUBNET API key", + }, cli.StringFlag{ Name: "name", Usage: "Specify the name to associate to this MinIO cluster in SUBNET", @@ -110,19 +115,37 @@ type SubnetMFAReq struct { Token string `json:"token"` } +func validateAPIKey(apiKey string, offline bool) error { + if offline { + return errors.New("--api-key is not applicable in airgap mode") + } + + _, e := uuid.Parse(apiKey) + if e != nil { + return e + } + + return nil +} + func mainSupportRegister(ctx *cli.Context) error { console.SetColor("RegisterSuccessMessage", color.New(color.FgGreen, color.Bold)) checkSupportRegisterSyntax(ctx) // Get the alias parameter from cli aliasedURL := ctx.Args().Get(0) - alias, _ := url2Alias(aliasedURL) offline := ctx.Bool("airgap") || ctx.Bool("offline") if !offline { fatalIf(checkURLReachable(subnetBaseURL()).Trace(aliasedURL), "Unable to reach %s register", subnetBaseURL()) } + accAPIKey := ctx.String("api-key") + if len(accAPIKey) > 0 { + e := validateAPIKey(accAPIKey, offline) + fatalIf(probe.NewError(e), "unable to parse input values") + } + // Create a new MinIO Admin Client client := getClient(aliasedURL) @@ -130,6 +153,7 @@ func mainSupportRegister(ctx *cli.Context) error { admInfo, e := client.ServerInfo(globalContext) fatalIf(probe.NewError(e), "Unable to fetch cluster info") + alias, _ := url2Alias(aliasedURL) clusterName := ctx.String("name") if len(clusterName) == 0 { clusterName = alias @@ -151,7 +175,7 @@ func mainSupportRegister(ctx *cli.Context) error { if offline { registerOffline(regInfo, alias) } else { - registerOnline(regInfo, alias, clusterName) + registerOnline(regInfo, alias, accAPIKey) } action := "registered" @@ -200,8 +224,16 @@ Step 2: Enter the key generated by SUBNET: `) } } -func registerOnline(clusterRegInfo ClusterRegistrationInfo, alias string, clusterName string) { - resp, e := registerClusterOnSubnet(alias, clusterRegInfo) +func registerOnline(clusterRegInfo ClusterRegistrationInfo, alias string, accAPIKey string) { + var resp string + var e error + + if len(accAPIKey) > 0 { + resp, e = registerClusterWithSubnetCreds(clusterRegInfo, accAPIKey, "") + } else { + resp, e = registerClusterOnSubnet(alias, clusterRegInfo) + } + fatalIf(probe.NewError(e), "Could not register cluster with SUBNET:") extractAndSaveSubnetCreds(alias, resp)