From 374100da7ea50056a795e72852312d5129c44bca Mon Sep 17 00:00:00 2001 From: Harshavardhana Date: Fri, 10 Jan 2020 05:48:42 -0800 Subject: [PATCH] fix: update docs for --attr command (#3040) Also canonicalize metadata headers automatically before, minio-go consumes it. --- cmd/cp-main.go | 17 ++++++++++------- cmd/cp-main_test.go | 6 +++--- cmd/mirror-main.go | 4 ++-- 3 files changed, 15 insertions(+), 12 deletions(-) diff --git a/cmd/cp-main.go b/cmd/cp-main.go index 18ce3e2e..ab223b30 100644 --- a/cmd/cp-main.go +++ b/cmd/cp-main.go @@ -22,6 +22,7 @@ import ( "errors" "fmt" "io" + "net/http" "os" "path/filepath" "strings" @@ -127,11 +128,11 @@ EXAMPLES: base64 encoded string as key. {{.Prompt}} {{.HelpName}} --recursive --encrypt-key "s3/documents/=MzJieXRlc2xvbmdzZWNyZWFiY2RlZmcJZ2l2ZW5uMjE=,myminio/documents/=MzJieXRlc2xvbmdzZWNyZWFiY2RlZmcJZ2l2ZW5uMjE=" s3/documents/ myminio/documents/ - 11. Copy a list of objects from local file system to MinIO cloud storage with specified metadata. - {{.Prompt}} {{.HelpName}} --attr key1=value1,key2=value2 Music/*.mp4 play/mybucket/ + 11. Copy a list of objects from local file system to MinIO cloud storage with specified metadata, separated by ";" + {{.Prompt}} {{.HelpName}} --attr "key1=value1;key2=value2" Music/*.mp4 play/mybucket/ - 12. Copy a folder recursively from MinIO cloud storage to Amazon S3 cloud storage with specified metadata. - {{.Prompt}} {{.HelpName}} --attr Cache-Control=max-age=90000,min-fresh=9000\;key1=value1\;key2=value2 --recursive play/mybucket/burningman2011/ s3/mybucket/ + 12. Copy a folder recursively from MinIO cloud storage to Amazon S3 cloud storage with Cache-Control and custom metadata, separated by ";". + {{.Prompt}} {{.HelpName}} --attr "Cache-Control=max-age=90000,min-fresh=9000;key1=value1;key2=value2" --recursive play/mybucket/burningman2011/ s3/mybucket/ 13. Copy a text file to an object storage and assign REDUCED_REDUNDANCY storage-class to the uploaded object. {{.Prompt}} {{.HelpName}} --storage-class REDUCED_REDUNDANCY myobject.txt play/mybucket @@ -141,6 +142,9 @@ EXAMPLES: 15. Copy a text file to an object storage and preserve the file system attribute as metadata. {{.Prompt}} {{.HelpName}} -a myobject.txt play/mybucket + + 16. Copy a text file to an object storage with object lock mode set to 'GOVERNANCE' with retention date. + {{.Prompt}} {{.HelpName} --attr "x-amz-object-lock-mode=GOVERNANCE;x-amz-object-lock-retain-until-date=2020-01-11T01:57:02Z" locked.txt play/locked-bucket/ `, } @@ -529,11 +533,10 @@ func getMetaDataEntry(metadataString string) (map[string]string, *probe.Error) { metaDataMap := make(map[string]string) for _, metaData := range strings.Split(metadataString, ";") { metaDataEntry := strings.SplitN(metaData, "=", 2) - if len(metaDataEntry) == 2 { - metaDataMap[metaDataEntry[0]] = metaDataEntry[1] - } else { + if len(metaDataEntry) != 2 { return nil, probe.NewError(ErrInvalidMetadata) } + metaDataMap[http.CanonicalHeaderKey(metaDataEntry[0])] = metaDataEntry[1] } return metaDataMap, nil } diff --git a/cmd/cp-main_test.go b/cmd/cp-main_test.go index 24fc11d8..07a180aa 100644 --- a/cmd/cp-main_test.go +++ b/cmd/cp-main_test.go @@ -29,11 +29,11 @@ func TestParseMetaData(t *testing.T) { status bool }{ // success scenario using ; as delimiter - {"key1=value1;key2=value2", map[string]string{"key1": "value1", "key2": "value2"}, nil, true}, + {"key1=value1;key2=value2", map[string]string{"Key1": "value1", "Key2": "value2"}, nil, true}, // success scenario using ; as delimiter - {"key1=m1=m2,m3=m4;key2=value2", map[string]string{"key1": "m1=m2,m3=m4", "key2": "value2"}, nil, true}, + {"key1=m1=m2,m3=m4;key2=value2", map[string]string{"Key1": "m1=m2,m3=m4", "Key2": "value2"}, nil, true}, // success scenario using = more than once - {"Cache-Control=max-age=90000,min-fresh=9000;key1=value1;key2=value2", map[string]string{"Cache-Control": "max-age=90000,min-fresh=9000", "key1": "value1", "key2": "value2"}, nil, true}, + {"Cache-Control=max-age=90000,min-fresh=9000;key1=value1;key2=value2", map[string]string{"Cache-Control": "max-age=90000,min-fresh=9000", "Key1": "value1", "Key2": "value2"}, nil, true}, // using different delimiter, other than '=' between key value {"key1:value1;key2:value2", nil, ErrInvalidMetadata, false}, // using no delimiter diff --git a/cmd/mirror-main.go b/cmd/mirror-main.go index c7b5d08e..1cf31765 100644 --- a/cmd/mirror-main.go +++ b/cmd/mirror-main.go @@ -160,8 +160,8 @@ EXAMPLES: non-printable character like tab, pass the base64 encoded string as key. {{.Prompt}} {{.HelpName}} --encrypt-key "s3/photos/=32byteslongsecretkeymustbegiven1,play/archive/=MzJieXRlc2xvbmdzZWNyZXRrZQltdXN0YmVnaXZlbjE=" s3/photos/ play/archive/ - 13. Update 'Cache-Control' header on existing objects. - {{.Prompt}} {{.HelpName}} --attr Cache-Control=max-age=90000,min-fresh=9000 myminio/video-files myminio/video-files + 13. Update 'Cache-Control' header on all existing objects recursively. + {{.Prompt}} {{.HelpName}} --attr "Cache-Control=max-age=90000,min-fresh=9000" myminio/video-files myminio/video-files 14. Mirror a local folder recursively to Amazon S3 cloud storage and preserve all local file attributes. {{.Prompt}} {{.HelpName}} -a backup/ s3/archive