From 0da22db3af01a96b0e771b7896b5f31d7eec7507 Mon Sep 17 00:00:00 2001 From: Harshavardhana Date: Fri, 21 Apr 2023 11:30:52 -0700 Subject: [PATCH] allow aliases to be `/` at the end and handle such cases (#4554) --- cmd/admin-cluster-bucket-export.go | 6 +++--- cmd/admin-cluster-bucket-import.go | 2 +- cmd/admin-cluster-iam-export.go | 5 ++++- cmd/admin-cluster-iam-import.go | 5 ++++- 4 files changed, 12 insertions(+), 6 deletions(-) diff --git a/cmd/admin-cluster-bucket-export.go b/cmd/admin-cluster-bucket-export.go index 5b7bb8df..d46b0cde 100644 --- a/cmd/admin-cluster-bucket-export.go +++ b/cmd/admin-cluster-bucket-export.go @@ -87,11 +87,11 @@ func mainClusterBucketExport(ctx *cli.Context) error { fatalIf(probe.NewError(e).Trace(aliasedURL), "Unable to export bucket metadata.") if bucket == "" { - bucket = "cluster" + bucket = "bucket" } // Create bucket metadata zip file - tmpFile, e := os.CreateTemp("", fmt.Sprintf("%s-metadata-", bucket)) + tmpFile, e := os.CreateTemp("", fmt.Sprintf("%s-%s-metadata-", aliasedURL, bucket)) fatalIf(probe.NewError(e), "Unable to download file data.") ext := "zip" @@ -104,7 +104,7 @@ func mainClusterBucketExport(ctx *cli.Context) error { tmpFile.Close() // We use 4 bytes of the 32 bytes to identify the file. - downloadPath := fmt.Sprintf("%s-metadata.%s", bucket, ext) + downloadPath := fmt.Sprintf("%s-%s-metadata.%s", aliasedURL, bucket, ext) fi, e := os.Stat(downloadPath) if e == nil && !fi.IsDir() { e = moveFile(downloadPath, downloadPath+"."+time.Now().Format(dateTimeFormatFilename)) diff --git a/cmd/admin-cluster-bucket-import.go b/cmd/admin-cluster-bucket-import.go index e2c05c90..f4234619 100644 --- a/cmd/admin-cluster-bucket-import.go +++ b/cmd/admin-cluster-bucket-import.go @@ -54,7 +54,7 @@ FLAGS: {{end}} EXAMPLES: 1. Recover bucket metadata for all buckets from previously saved bucket metadata backup. - {{.Prompt}} {{.HelpName}} myminio /backups/cluster-metadata.zip + {{.Prompt}} {{.HelpName}} myminio /backups/myminio-bucket-metadata.zip `, } diff --git a/cmd/admin-cluster-iam-export.go b/cmd/admin-cluster-iam-export.go index 71ad0d50..3f104c5a 100644 --- a/cmd/admin-cluster-iam-export.go +++ b/cmd/admin-cluster-iam-export.go @@ -22,6 +22,7 @@ import ( "fmt" "io" "os" + "path/filepath" "time" "github.com/fatih/color" @@ -67,7 +68,9 @@ func mainClusterIAMExport(ctx *cli.Context) error { // Get the alias parameter from cli args := ctx.Args() - aliasedURL := args.Get(0) + aliasedURL := filepath.ToSlash(args.Get(0)) + aliasedURL = filepath.Clean(aliasedURL) + console.SetColor("File", color.New(color.FgWhite, color.Bold)) // Create a new MinIO Admin Client diff --git a/cmd/admin-cluster-iam-import.go b/cmd/admin-cluster-iam-import.go index 7ad50c0f..6ac68bda 100644 --- a/cmd/admin-cluster-iam-import.go +++ b/cmd/admin-cluster-iam-import.go @@ -22,6 +22,7 @@ import ( "fmt" "io" "os" + "path/filepath" "github.com/klauspost/compress/zip" "github.com/minio/cli" @@ -66,7 +67,9 @@ func mainClusterIAMImport(ctx *cli.Context) error { // Get the alias parameter from cli args := ctx.Args() - aliasedURL := args.Get(0) + aliasedURL := filepath.ToSlash(args.Get(0)) + aliasedURL = filepath.Clean(aliasedURL) + var r io.Reader var sz int64 f, e := os.Open(args.Get(1))