mc support commands: allow --json in online mode (#4859)
There was a validation that said `--json` is supported only when `--airgap` is also passed for SUBNET related `mc support` commands. Remove this validation to allow `--json` to be passed even in online mode. In this scenario, print a status JSON after upload to SUBNET.
This commit is contained in:
+1
-1
@@ -179,7 +179,7 @@ func mainLicenseInfo(ctx *cli.Context) error {
|
||||
initLicInfoColors()
|
||||
|
||||
aliasedURL := ctx.Args().Get(0)
|
||||
alias, _ := initSubnetConnectivity(ctx, aliasedURL, false, true)
|
||||
alias, _ := initSubnetConnectivity(ctx, aliasedURL, true)
|
||||
|
||||
apiKey, lic, e := getSubnetCreds(alias)
|
||||
fatalIf(probe.NewError(e), "Error in checking cluster registration status")
|
||||
|
||||
@@ -220,7 +220,7 @@ func mainLicenseRegister(ctx *cli.Context) error {
|
||||
alias, _ = url2Alias(aliasedURL)
|
||||
accAPIKey = validateAndSaveLic(string(licBytes), alias, true)
|
||||
} else {
|
||||
alias, accAPIKey = initSubnetConnectivity(ctx, aliasedURL, true, false)
|
||||
alias, accAPIKey = initSubnetConnectivity(ctx, aliasedURL, false)
|
||||
}
|
||||
|
||||
clusterName := ctx.String("name")
|
||||
|
||||
@@ -83,7 +83,7 @@ func mainLicenseUnregister(ctx *cli.Context) error {
|
||||
checkLicenseUnregisterSyntax(ctx)
|
||||
|
||||
aliasedURL := ctx.Args().Get(0)
|
||||
alias, apiKey := initSubnetConnectivity(ctx, aliasedURL, false, true)
|
||||
alias, apiKey := initSubnetConnectivity(ctx, aliasedURL, true)
|
||||
if len(apiKey) == 0 {
|
||||
// api key not passed as flag. Check that the cluster is registered.
|
||||
apiKey = validateClusterRegistered(alias, true)
|
||||
|
||||
+4
-17
@@ -782,9 +782,10 @@ func getAPIKeyFlag(ctx *cli.Context) (string, error) {
|
||||
return apiKey, nil
|
||||
}
|
||||
|
||||
func initSubnetConnectivity(ctx *cli.Context, aliasedURL string, forUpload bool, failOnConnErr bool) (string, string) {
|
||||
e := validateSubnetFlags(ctx, forUpload)
|
||||
fatalIf(probe.NewError(e), "Invalid flags:")
|
||||
func initSubnetConnectivity(ctx *cli.Context, aliasedURL string, failOnConnErr bool) (string, string) {
|
||||
if ctx.Bool("airgap") && len(ctx.String("api-key")) > 0 {
|
||||
fatal(errDummy().Trace(), "--api-key is not applicable in airgap mode")
|
||||
}
|
||||
|
||||
alias, _ := url2Alias(aliasedURL)
|
||||
|
||||
@@ -805,17 +806,3 @@ func initSubnetConnectivity(ctx *cli.Context, aliasedURL string, forUpload bool,
|
||||
|
||||
return alias, apiKey
|
||||
}
|
||||
|
||||
func validateSubnetFlags(ctx *cli.Context, forUpload bool) error {
|
||||
if !globalAirgapped {
|
||||
if globalJSON && forUpload {
|
||||
return errors.New("--json is applicable only when --airgap is also passed")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
if len(ctx.String("api-key")) > 0 {
|
||||
return errors.New("--api-key is not applicable in airgap mode")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
+20
-11
@@ -24,7 +24,6 @@ import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"io"
|
||||
"net/url"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
@@ -38,7 +37,6 @@ import (
|
||||
"github.com/minio/madmin-go/v3"
|
||||
"github.com/minio/mc/pkg/probe"
|
||||
"github.com/minio/pkg/v2/console"
|
||||
"github.com/tidwall/gjson"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -96,6 +94,21 @@ EXAMPLES:
|
||||
`,
|
||||
}
|
||||
|
||||
type supportDiagMessage struct {
|
||||
Status string `json:"status"`
|
||||
}
|
||||
|
||||
// String colorized status message
|
||||
func (s supportDiagMessage) String() string {
|
||||
return console.Colorize(supportSuccessMsgTag, "MinIO diagnostics report was successfully uploaded to SUBNET.")
|
||||
}
|
||||
|
||||
// JSON jsonified status message
|
||||
func (s supportDiagMessage) JSON() string {
|
||||
s.Status = "success"
|
||||
return toJSON(s)
|
||||
}
|
||||
|
||||
// checkSupportDiagSyntax - validate arguments passed by a user
|
||||
func checkSupportDiagSyntax(ctx *cli.Context) {
|
||||
if len(ctx.Args()) == 0 || len(ctx.Args()) > 1 {
|
||||
@@ -168,7 +181,7 @@ func mainSupportDiag(ctx *cli.Context) error {
|
||||
|
||||
// Get the alias parameter from cli
|
||||
aliasedURL := ctx.Args().Get(0)
|
||||
alias, apiKey := initSubnetConnectivity(ctx, aliasedURL, true, true)
|
||||
alias, apiKey := initSubnetConnectivity(ctx, aliasedURL, true)
|
||||
if len(apiKey) == 0 {
|
||||
// api key not passed as flag. Check that the cluster is registered.
|
||||
apiKey = validateClusterRegistered(alias, true)
|
||||
@@ -186,6 +199,7 @@ func mainSupportDiag(ctx *cli.Context) error {
|
||||
func execSupportDiag(ctx *cli.Context, client *madmin.AdminClient, alias, apiKey string) {
|
||||
var reqURL string
|
||||
var headers map[string]string
|
||||
setSuccessMessageColor()
|
||||
|
||||
filename := fmt.Sprintf("%s-health_%s.json.gz", filepath.Clean(alias), UTCNow().Format("20060102150405"))
|
||||
if !globalAirgapped {
|
||||
@@ -198,7 +212,7 @@ func execSupportDiag(ctx *cli.Context, client *madmin.AdminClient, alias, apiKey
|
||||
healthInfo, version, e := fetchServerDiagInfo(ctx, client)
|
||||
fatalIf(probe.NewError(e), "Unable to fetch health information.")
|
||||
|
||||
if globalJSON {
|
||||
if globalJSON && globalAirgapped {
|
||||
switch version {
|
||||
case madmin.HealthInfoVersion0:
|
||||
printMsg(healthInfo.(madmin.HealthInfoV0))
|
||||
@@ -214,15 +228,10 @@ func execSupportDiag(ctx *cli.Context, client *madmin.AdminClient, alias, apiKey
|
||||
fatalIf(probe.NewError(e), "Unable to save MinIO diagnostics report")
|
||||
|
||||
if !globalAirgapped {
|
||||
resp, e := uploadFileToSubnet(alias, filename, reqURL, headers)
|
||||
_, e := uploadFileToSubnet(alias, filename, reqURL, headers)
|
||||
fatalIf(probe.NewError(e), "Unable to upload MinIO diagnostics report to SUBNET portal")
|
||||
|
||||
msg := "MinIO diagnostics report was successfully uploaded to SUBNET."
|
||||
clusterURL, _ := url.PathUnescape(gjson.Get(resp, "cluster_url").String())
|
||||
if len(clusterURL) > 0 {
|
||||
msg += fmt.Sprintf(" Please click here to view our analysis: %s", clusterURL)
|
||||
}
|
||||
console.Infoln(msg)
|
||||
printMsg(supportDiagMessage{})
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+23
-14
@@ -81,27 +81,34 @@ EXAMPLES:
|
||||
}
|
||||
|
||||
type inspectMessage struct {
|
||||
File string `json:"file"`
|
||||
Key string `json:"key,omitempty"`
|
||||
Status string `json:"status"`
|
||||
AliasedURL string `json:"aliasedURL,omitempty"`
|
||||
File string `json:"file,omitempty"`
|
||||
Key string `json:"key,omitempty"`
|
||||
}
|
||||
|
||||
// Colorized message for console printing.
|
||||
func (t inspectMessage) String() string {
|
||||
msg := ""
|
||||
if t.Key == "" {
|
||||
msg += fmt.Sprintf("File data successfully downloaded as %s\n", console.Colorize("File", t.File))
|
||||
} else {
|
||||
msg += fmt.Sprintf("Encrypted file data successfully downloaded as %s\n", console.Colorize("File", t.File))
|
||||
msg += fmt.Sprintf("Decryption key: %s\n\n", console.Colorize("Key", t.Key))
|
||||
var msg string
|
||||
if globalAirgapped {
|
||||
if t.Key == "" {
|
||||
msg = fmt.Sprintf("File data successfully downloaded as %s", console.Colorize("File", t.File))
|
||||
} else {
|
||||
msg = fmt.Sprintf("Encrypted file data successfully downloaded as %s\n", console.Colorize("File", t.File))
|
||||
msg += fmt.Sprintf("Decryption key: %s\n\n", console.Colorize("Key", t.Key))
|
||||
|
||||
msg += "The decryption key will ONLY be shown here. It cannot be recovered.\n"
|
||||
msg += "The encrypted file can safely be shared without the decryption key.\n"
|
||||
msg += "Even with the decryption key, data stored with encryption cannot be accessed.\n"
|
||||
msg += "The decryption key will ONLY be shown here. It cannot be recovered.\n"
|
||||
msg += "The encrypted file can safely be shared without the decryption key.\n"
|
||||
msg += "Even with the decryption key, data stored with encryption cannot be accessed."
|
||||
}
|
||||
} else {
|
||||
msg = fmt.Sprintf("Object inspection data for '%s' uploaded to SUBNET successfully", t.AliasedURL)
|
||||
}
|
||||
return msg
|
||||
return console.Colorize(supportSuccessMsgTag, msg)
|
||||
}
|
||||
|
||||
func (t inspectMessage) JSON() string {
|
||||
t.Status = "success"
|
||||
jsonMessageBytes, e := json.MarshalIndent(t, "", " ")
|
||||
fatalIf(probe.NewError(e), "Unable to marshal into JSON.")
|
||||
return string(jsonMessageBytes)
|
||||
@@ -118,11 +125,13 @@ func mainSupportInspect(ctx *cli.Context) error {
|
||||
// Check for command syntax
|
||||
checkSupportInspectSyntax(ctx)
|
||||
|
||||
setSuccessMessageColor()
|
||||
|
||||
// Get the alias parameter from cli
|
||||
args := ctx.Args()
|
||||
aliasedURL := args.Get(0)
|
||||
|
||||
alias, apiKey := initSubnetConnectivity(ctx, aliasedURL, true, true)
|
||||
alias, apiKey := initSubnetConnectivity(ctx, aliasedURL, true)
|
||||
if len(apiKey) == 0 {
|
||||
// api key not passed as flag. Check that the cluster is registered.
|
||||
apiKey = validateClusterRegistered(alias, true)
|
||||
@@ -197,7 +206,7 @@ func mainSupportInspect(ctx *cli.Context) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
console.Infof("Object inspection data for '%s' uploaded to SUBNET successfully\n", aliasedURL)
|
||||
printMsg(inspectMessage{AliasedURL: aliasedURL})
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -461,7 +461,7 @@ func convertPerfResults(results []PerfTestResult) PerfTestOutput {
|
||||
}
|
||||
|
||||
func execSupportPerf(ctx *cli.Context, aliasedURL, perfType string) {
|
||||
alias, apiKey := initSubnetConnectivity(ctx, aliasedURL, true, true)
|
||||
alias, apiKey := initSubnetConnectivity(ctx, aliasedURL, true)
|
||||
if len(apiKey) == 0 {
|
||||
// api key not passed as flag. Check that the cluster is registered.
|
||||
apiKey = validateClusterRegistered(alias, true)
|
||||
|
||||
+50
-6
@@ -18,6 +18,7 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
"strings"
|
||||
@@ -48,6 +49,36 @@ var (
|
||||
|
||||
const profileFile = "profile.zip"
|
||||
|
||||
type supportProfileMessage struct {
|
||||
Status string `json:"status"`
|
||||
File string `json:"file,omitempty"`
|
||||
Error string `json:"error,omitempty"`
|
||||
}
|
||||
|
||||
// Colorized message for console printing.
|
||||
func (s supportProfileMessage) String() string {
|
||||
var msg string
|
||||
if s.Error != "" {
|
||||
errMsg := fmt.Sprintln("Unable to upload profile file to SUBNET: ", s.Error)
|
||||
msg := console.Colorize(supportErrorMsgTag, errMsg)
|
||||
infoMsg := fmt.Sprintf("Profiling data saved locally at '%s'", profileFile)
|
||||
msg += console.Colorize(supportSuccessMsgTag, infoMsg)
|
||||
return msg
|
||||
}
|
||||
|
||||
if globalAirgapped {
|
||||
msg = fmt.Sprintf("Profiling data saved successfully at %s", s.File)
|
||||
} else {
|
||||
msg = "Profiling data uploaded to SUBNET successfully"
|
||||
}
|
||||
return console.Colorize(supportSuccessMsgTag, msg)
|
||||
}
|
||||
|
||||
// JSON jsonified proxy remove message
|
||||
func (s supportProfileMessage) JSON() string {
|
||||
return toJSON(s)
|
||||
}
|
||||
|
||||
var supportProfileCmd = cli.Command{
|
||||
Name: "profile",
|
||||
Usage: "upload profile data for debugging",
|
||||
@@ -167,9 +198,12 @@ func mainSupportProfile(ctx *cli.Context) error {
|
||||
// Check for command syntax
|
||||
checkAdminProfileSyntax(ctx)
|
||||
|
||||
setSuccessMessageColor()
|
||||
setErrorMessageColor()
|
||||
|
||||
// Get the alias parameter from cli
|
||||
aliasedURL := ctx.Args().Get(0)
|
||||
alias, apiKey := initSubnetConnectivity(ctx, aliasedURL, true, true)
|
||||
alias, apiKey := initSubnetConnectivity(ctx, aliasedURL, true)
|
||||
if len(apiKey) == 0 {
|
||||
// api key not passed as flag. Check that the cluster is registered.
|
||||
apiKey = validateClusterRegistered(alias, true)
|
||||
@@ -196,7 +230,9 @@ func execSupportProfile(ctx *cli.Context, client *madmin.AdminClient, alias, api
|
||||
reqURL, headers = prepareSubnetUploadURL(uploadURL, alias, apiKey)
|
||||
}
|
||||
|
||||
console.Infof("Profiling '%s' for %d seconds... \n", alias, duration)
|
||||
if !globalJSON {
|
||||
console.Infof("Profiling '%s' for %d seconds... \n", alias, duration)
|
||||
}
|
||||
data, e := client.Profile(globalContext, madmin.ProfilerType(profilers), time.Second*time.Duration(duration))
|
||||
fatalIf(probe.NewError(e), "Unable to save profile data")
|
||||
|
||||
@@ -205,12 +241,20 @@ func execSupportProfile(ctx *cli.Context, client *madmin.AdminClient, alias, api
|
||||
if !globalAirgapped {
|
||||
_, e = uploadFileToSubnet(alias, profileFile, reqURL, headers)
|
||||
if e != nil {
|
||||
errorIf(probe.NewError(e), "Unable to upload profile file to SUBNET")
|
||||
console.Infof("Profiling data saved locally at '%s'\n", profileFile)
|
||||
printMsg(supportProfileMessage{
|
||||
Status: "error",
|
||||
Error: e.Error(),
|
||||
File: profileFile,
|
||||
})
|
||||
return
|
||||
}
|
||||
console.Infoln("Profiling data uploaded to SUBNET successfully")
|
||||
printMsg(supportProfileMessage{
|
||||
Status: "success",
|
||||
})
|
||||
} else {
|
||||
console.Infoln("Profiling data saved successfully at ", profileFile)
|
||||
printMsg(supportProfileMessage{
|
||||
Status: "success",
|
||||
File: profileFile,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -44,7 +44,7 @@ var supportProxyRemoveCmd = cli.Command{
|
||||
Action: mainSupportProxyRemove,
|
||||
OnUsageError: onUsageError,
|
||||
Before: setGlobalsFromContext,
|
||||
Flags: supportGlobalFlags,
|
||||
Flags: globalFlags,
|
||||
HideHelpCommand: true,
|
||||
CustomHelpTemplate: `NAME:
|
||||
{{.HelpName}} - {{.Usage}}
|
||||
|
||||
@@ -47,7 +47,7 @@ var supportProxySetCmd = cli.Command{
|
||||
Action: mainSupportProxySet,
|
||||
OnUsageError: onUsageError,
|
||||
Before: setGlobalsFromContext,
|
||||
Flags: supportGlobalFlags,
|
||||
Flags: globalFlags,
|
||||
HideHelpCommand: true,
|
||||
CustomHelpTemplate: `NAME:
|
||||
{{.HelpName}} - {{.Usage}}
|
||||
|
||||
@@ -28,7 +28,7 @@ var supportProxyShowCmd = cli.Command{
|
||||
Action: mainSupportProxyShow,
|
||||
OnUsageError: onUsageError,
|
||||
Before: setGlobalsFromContext,
|
||||
Flags: supportGlobalFlags,
|
||||
Flags: globalFlags,
|
||||
HideHelpCommand: true,
|
||||
CustomHelpTemplate: `NAME:
|
||||
{{.HelpName}} - {{.Usage}}
|
||||
|
||||
+8
-1
@@ -29,7 +29,10 @@ import (
|
||||
"github.com/minio/pkg/v2/console"
|
||||
)
|
||||
|
||||
const supportSuccessMsgTag = "SupportSuccessMessage"
|
||||
const (
|
||||
supportSuccessMsgTag = "SupportSuccessMessage"
|
||||
supportErrorMsgTag = "SupportErrorMessage"
|
||||
)
|
||||
|
||||
var supportGlobalFlags = append(globalFlags,
|
||||
cli.BoolFlag{
|
||||
@@ -94,6 +97,10 @@ func setSuccessMessageColor() {
|
||||
console.SetColor(supportSuccessMsgTag, color.New(color.FgGreen, color.Bold))
|
||||
}
|
||||
|
||||
func setErrorMessageColor() {
|
||||
console.SetColor(supportErrorMsgTag, color.New(color.FgYellow, color.Italic))
|
||||
}
|
||||
|
||||
func featureStatusStr(enabled bool) string {
|
||||
if enabled {
|
||||
return "enabled"
|
||||
|
||||
Reference in New Issue
Block a user