Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New way to update ObjectACL or Header or Meta data #1010

Merged
merged 4 commits into from Jul 19, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 5 additions & 1 deletion api-compose-object.go
Expand Up @@ -101,7 +101,11 @@ func (d *DestinationInfo) getUserMetaHeadersMap(withCopyDirectiveHeader bool) ma
r["x-amz-metadata-directive"] = "REPLACE"
}
for k, v := range d.userMetadata {
r["x-amz-meta-"+k] = v
if isAmzHeader(k) || isStandardHeader(k) || isStorageClassHeader(k) {
r[k] = v
} else {
r["x-amz-meta-"+k] = v
}
}
return r
}
Expand Down
35 changes: 35 additions & 0 deletions api-compose-object_test.go
Expand Up @@ -18,6 +18,7 @@ package minio

import (
"reflect"
"strings"
"testing"
)

Expand Down Expand Up @@ -118,3 +119,37 @@ func TestCalculateEvenSplits(t *testing.T) {
}
}
}

func TestGetUserMetaHeadersMap(t *testing.T) {

userMetadata := map[string]string{
"test": "test",
"x-amz-acl": "public-read-write",
"content-type": "application/binary",
"X-Amz-Storage-Class": "rrs",
"x-amz-grant-write": "test@exo.ch",
}

destInfo := &DestinationInfo{"bucket", "object", nil, userMetadata}

r := destInfo.getUserMetaHeadersMap(true)

i := 0

if _, ok := r["x-amz-metadata-directive"]; !ok {
t.Errorf("Test %d - metadata directive was expected but is missing", i)
i++
}

for k := range r {
if strings.HasSuffix(k, "test") && !strings.HasPrefix(k, "x-amz-meta-") {
t.Errorf("Test %d - meta %q was expected as an x amz meta", i, k)
i++
}

if !strings.HasSuffix(k, "test") && strings.HasPrefix(k, "x-amz-meta-") {
t.Errorf("Test %d - an amz/standard/storageClass Header was expected but got an x amz meta data", i)
i++
}
}
}
2 changes: 1 addition & 1 deletion utils.go
Expand Up @@ -267,5 +267,5 @@ func isSSEHeader(headerKey string) bool {
func isAmzHeader(headerKey string) bool {
key := strings.ToLower(headerKey)

return strings.HasPrefix(key, "x-amz-meta-") || key == "x-amz-acl"
return strings.HasPrefix(key, "x-amz-meta-") || strings.HasPrefix(key, "x-amz-grant-") || key == "x-amz-acl"
}