From 603437e70f2e1cd1c0256a275a1681d0a2ad3c5c Mon Sep 17 00:00:00 2001 From: Sveinn Date: Mon, 2 Oct 2023 13:39:47 +0000 Subject: [PATCH] Fix startup formatting (#18156) Percentages in root user names are used for formatting. Before: ``` S3-API: http://192.168.50.21:9000 http://172.31.96.1:9000 http://127.0.0.1:9000 RootUser: "U4B6Zi!b75DXSPm%!!(MISSING)a(MISSING)vZb" RootPass: "Q4#Q6y8G%!P(MISSING)x#npP4dudUobU#NBcGB7RMKV4ajYb" Console: http://192.168.50.21:51915 http://172.31.96.1:51915 http://127.0.0.1:51915 RootUser: "U4B6Zi!b75DXSPm%!!(MISSING)a(MISSING)vZb" RootPass: "Q4#Q6y8G%!P(MISSING)x#npP4dudUobU#NBcGB7RMKV4ajYb" Command-line: https://min.io/docs/minio/linux/reference/minio-mc.html#quickstart FORMAT: %117s MESSAGE: $ mc alias set myminio http://192.168.50.21:9000 "U4B6Zi!b75DXSPm%avZb" "Q4#Q6y8G%%Px#npP4dudUobU#NBcGB7RMKV4ajYb" $ mc alias set myminio http://192.168.50.21:9000 "U4B6Zi!b75DXSPm%!a(MISSING)vZb" "Q4#Q6y8G%Px#npP4dudUobU#NBcGB7RMKV4ajYb" ``` After: ``` Status: 1 Online, 0 Offline. S3-API: http://192.168.50.21:9000 http://172.31.96.1:9000 http://127.0.0.1:9000 RootUser: "U4B6Zi!b75DXSPm%avZb" RootPass: "Q4#Q6y8G%%Px#npP4dudUobU#NBcGB7RMKV4ajYb" Console: http://192.168.50.21:52421 http://172.31.96.1:52421 http://127.0.0.1:52421 RootUser: "U4B6Zi!b75DXSPm%avZb" RootPass: "Q4#Q6y8G%%Px#npP4dudUobU#NBcGB7RMKV4ajYb" Command-line: https://min.io/docs/minio/linux/reference/minio-mc.html#quickstart $ mc alias set myminio http://192.168.50.21:9000 "U4B6Zi!b75DXSPm%avZb" "Q4#Q6y8G%%Px#npP4dudUobU#NBcGB7RMKV4ajYb" ``` No need for special Windows case. `mc` works just fine. --- cmd/server-startup-msg.go | 27 ++++++++++----------------- internal/logger/console.go | 8 ++++++++ 2 files changed, 18 insertions(+), 17 deletions(-) diff --git a/cmd/server-startup-msg.go b/cmd/server-startup-msg.go index 7ac43a94f..1122087dd 100644 --- a/cmd/server-startup-msg.go +++ b/cmd/server-startup-msg.go @@ -21,12 +21,11 @@ import ( "fmt" "net" "net/url" - "runtime" "strings" - humanize "github.com/dustin/go-humanize" + "github.com/dustin/go-humanize" "github.com/minio/madmin-go/v3" - color "github.com/minio/minio/internal/color" + "github.com/minio/minio/internal/color" "github.com/minio/minio/internal/logger" xnet "github.com/minio/pkg/v2/net" ) @@ -129,10 +128,10 @@ func printServerCommonMsg(apiEndpoints []string) { // Colorize the message and print. logger.Info(color.Blue("S3-API: ") + color.Bold(fmt.Sprintf("%s ", apiEndpointStr))) if color.IsTerminal() && (!globalCLIContext.Anonymous && !globalCLIContext.JSON) { - logger.Info(color.Blue("RootUser: ") + color.Bold(fmt.Sprintf("%s ", cred.AccessKey))) - logger.Info(color.Blue("RootPass: ") + color.Bold(fmt.Sprintf("%s \n", cred.SecretKey))) + logger.Info(color.Blue("RootUser: ") + color.Bold("%s ", cred.AccessKey)) + logger.Info(color.Blue("RootPass: ") + color.Bold("%s \n", cred.SecretKey)) if region != "" { - logger.Info(color.Blue("Region: ") + color.Bold(fmt.Sprintf(getFormatStr(len(region), 2), region))) + logger.Info(color.Blue("Region: ") + color.Bold("%s", fmt.Sprintf(getFormatStr(len(region), 2), region))) } } @@ -140,8 +139,8 @@ func printServerCommonMsg(apiEndpoints []string) { consoleEndpointStr := strings.Join(stripStandardPorts(getConsoleEndpoints(), globalMinioConsoleHost), " ") logger.Info(color.Blue("Console: ") + color.Bold(fmt.Sprintf("%s ", consoleEndpointStr))) if color.IsTerminal() && (!globalCLIContext.Anonymous && !globalCLIContext.JSON) { - logger.Info(color.Blue("RootUser: ") + color.Bold(fmt.Sprintf("%s ", cred.AccessKey))) - logger.Info(color.Blue("RootPass: ") + color.Bold(fmt.Sprintf("%s ", cred.SecretKey))) + logger.Info(color.Blue("RootUser: ") + color.Bold("%s ", cred.AccessKey)) + logger.Info(color.Blue("RootPass: ") + color.Bold("%s ", cred.SecretKey)) } } @@ -196,15 +195,9 @@ func printCLIAccessMsg(endPoint string, alias string) { // Configure 'mc', following block prints platform specific information for minio client. if color.IsTerminal() && !globalCLIContext.Anonymous { logger.Info(color.Blue("\nCommand-line: ") + mcQuickStartGuide) - if runtime.GOOS == globalWindowsOSName { - mcMessage := fmt.Sprintf("$ mc.exe alias set %s %s %s %s", alias, - endPoint, cred.AccessKey, cred.SecretKey) - logger.Info(fmt.Sprintf(getFormatStr(len(mcMessage), 3), mcMessage)) - } else { - mcMessage := fmt.Sprintf("$ mc alias set %s %s %s %s", alias, - endPoint, cred.AccessKey, cred.SecretKey) - logger.Info(fmt.Sprintf(getFormatStr(len(mcMessage), 3), mcMessage)) - } + mcMessage := fmt.Sprintf("$ mc alias set '%s' '%s' '%s' '%s'", alias, + endPoint, cred.AccessKey, cred.SecretKey) + logger.Info(fmt.Sprintf(getFormatStr(len(mcMessage), 3), mcMessage)) } } diff --git a/internal/logger/console.go b/internal/logger/console.go index d102454d8..96f751bc0 100644 --- a/internal/logger/console.go +++ b/internal/logger/console.go @@ -49,8 +49,16 @@ func consoleLog(console Logger, msg string, args ...interface{}) { msg = ansiRE.ReplaceAllLiteralString(msg, "") console.json(msg, args...) case quietFlag: + if len(msg) != 0 && len(args) == 0 { + args = append(args, msg) + msg = "%s" + } console.quiet(msg+"\n", args...) default: + if len(msg) != 0 && len(args) == 0 { + args = append(args, msg) + msg = "%s" + } console.pretty(msg+"\n", args...) } }