Add --api-key flag to mc support register (#4144)

This commit is contained in:
Shireesh Anjal
2022-07-06 07:54:36 -07:00
committed by GitHub
parent 811d7e5edb
commit f9e4ca8ece
2 changed files with 41 additions and 4 deletions
+5
View File
@@ -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
+36 -4
View File
@@ -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)