cleanup legacy metadata handling (#3118)
This commit is contained in:
+10
-37
@@ -55,7 +55,6 @@ type s3Client struct {
|
||||
|
||||
const (
|
||||
amazonHostNameAccelerated = "s3-accelerate.amazonaws.com"
|
||||
|
||||
googleHostName = "storage.googleapis.com"
|
||||
serverEncryptionKeyPrefix = "x-amz-server-side-encryption"
|
||||
|
||||
@@ -78,13 +77,6 @@ const (
|
||||
AmzObjectLockRetainUntilDate = "X-Amz-Object-Lock-Retain-Until-Date"
|
||||
)
|
||||
|
||||
// cseHeaders is list of client side encryption headers
|
||||
var cseHeaders = []string{
|
||||
"X-Amz-Meta-X-Amz-Iv",
|
||||
"X-Amz-Meta-X-Amz-Key",
|
||||
"X-Amz-Meta-X-Amz-Matdesc",
|
||||
}
|
||||
|
||||
var timeSentinel = time.Unix(0, 0).UTC()
|
||||
|
||||
// newFactory encloses New function with client cache.
|
||||
@@ -825,6 +817,10 @@ func (c *s3Client) Copy(source string, size int64, progress io.Reader, srcSSE, t
|
||||
// Put - upload an object with custom metadata.
|
||||
func (c *s3Client) Put(ctx context.Context, reader io.Reader, size int64, metadata map[string]string, progress io.Reader, sse encrypt.ServerSide) (int64, *probe.Error) {
|
||||
bucket, object := c.url2BucketAndObject()
|
||||
if bucket == "" {
|
||||
return 0, probe.NewError(BucketNameEmpty{})
|
||||
}
|
||||
|
||||
contentType, ok := metadata["Content-Type"]
|
||||
if ok {
|
||||
delete(metadata, "Content-Type")
|
||||
@@ -873,10 +869,6 @@ func (c *s3Client) Put(ctx context.Context, reader io.Reader, size int64, metada
|
||||
retainUntilDate = t.UTC()
|
||||
}
|
||||
}
|
||||
|
||||
if bucket == "" {
|
||||
return 0, probe.NewError(BucketNameEmpty{})
|
||||
}
|
||||
opts := minio.PutObjectOptions{
|
||||
UserMetadata: metadata,
|
||||
Progress: progress,
|
||||
@@ -1269,7 +1261,6 @@ func (c *s3Client) Stat(isIncomplete, isFetchMeta, isPreserve bool, sse encrypt.
|
||||
objectMetadata.Size = objectMultipartInfo.Size
|
||||
objectMetadata.Type = os.FileMode(0664)
|
||||
objectMetadata.Metadata = map[string]string{}
|
||||
objectMetadata.EncryptionHeaders = map[string]string{}
|
||||
return objectMetadata, nil
|
||||
}
|
||||
|
||||
@@ -1277,8 +1268,6 @@ func (c *s3Client) Stat(isIncomplete, isFetchMeta, isPreserve bool, sse encrypt.
|
||||
objectMetadata.URL = *c.targetURL
|
||||
objectMetadata.Type = os.ModeDir
|
||||
objectMetadata.Metadata = map[string]string{}
|
||||
objectMetadata.EncryptionHeaders = map[string]string{}
|
||||
|
||||
return objectMetadata, nil
|
||||
}
|
||||
}
|
||||
@@ -1302,7 +1291,6 @@ func (c *s3Client) Stat(isIncomplete, isFetchMeta, isPreserve bool, sse encrypt.
|
||||
}
|
||||
objectMetadata.ETag = stat.ETag
|
||||
objectMetadata.Metadata = stat.Metadata
|
||||
objectMetadata.EncryptionHeaders = stat.EncryptionHeaders
|
||||
objectMetadata.Expires = stat.Expires
|
||||
}
|
||||
return objectMetadata, nil
|
||||
@@ -1315,14 +1303,12 @@ func (c *s3Client) Stat(isIncomplete, isFetchMeta, isPreserve bool, sse encrypt.
|
||||
objectMetadata.Type = os.FileMode(0664)
|
||||
objectMetadata.Metadata = map[string]string{}
|
||||
objectMetadata.Expires = objectStat.Expires
|
||||
objectMetadata.EncryptionHeaders = map[string]string{}
|
||||
if isFetchMeta {
|
||||
stat, err := c.getObjectStat(bucket, object, opts)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
objectMetadata.Metadata = stat.Metadata
|
||||
objectMetadata.EncryptionHeaders = stat.EncryptionHeaders
|
||||
objectMetadata.Expires = stat.Expires
|
||||
}
|
||||
return objectMetadata, nil
|
||||
@@ -1362,25 +1348,8 @@ func (c *s3Client) getObjectStat(bucket, object string, opts minio.StatObjectOpt
|
||||
objectMetadata.Expires = objectStat.Expires
|
||||
objectMetadata.Type = os.FileMode(0664)
|
||||
objectMetadata.Metadata = map[string]string{}
|
||||
objectMetadata.EncryptionHeaders = map[string]string{}
|
||||
objectMetadata.Metadata["Content-Type"] = objectStat.ContentType
|
||||
for k, v := range objectStat.Metadata {
|
||||
isCSEHeader := false
|
||||
for _, header := range cseHeaders {
|
||||
if (strings.Compare(strings.ToLower(header), strings.ToLower(k)) == 0) ||
|
||||
strings.HasPrefix(strings.ToLower(serverEncryptionKeyPrefix), strings.ToLower(k)) {
|
||||
if len(v) > 0 {
|
||||
objectMetadata.EncryptionHeaders[k] = v[0]
|
||||
}
|
||||
isCSEHeader = true
|
||||
break
|
||||
}
|
||||
}
|
||||
if !isCSEHeader {
|
||||
if len(v) > 0 {
|
||||
objectMetadata.Metadata[k] = v[0]
|
||||
}
|
||||
}
|
||||
for k := range objectStat.Metadata {
|
||||
objectMetadata.Metadata[k] = objectStat.Metadata.Get(k)
|
||||
}
|
||||
objectMetadata.ETag = objectStat.ETag
|
||||
return objectMetadata, nil
|
||||
@@ -1765,10 +1734,14 @@ func (c *s3Client) objectInfo2ClientContent(bucket string, entry minio.ObjectInf
|
||||
content.ETag = entry.ETag
|
||||
content.Time = entry.LastModified
|
||||
content.Expires = entry.Expires
|
||||
content.Metadata = map[string]string{}
|
||||
content.UserMetadata = map[string]string{}
|
||||
for k, v := range entry.UserMetadata {
|
||||
content.UserMetadata[k] = v
|
||||
}
|
||||
for k := range entry.Metadata {
|
||||
content.Metadata[k] = entry.Metadata.Get(k)
|
||||
}
|
||||
if strings.HasSuffix(entry.Key, string(c.targetURL.Separator)) && entry.Size == 0 && entry.LastModified.IsZero() {
|
||||
content.Type = os.ModeDir
|
||||
content.Time = time.Now()
|
||||
|
||||
+11
-12
@@ -88,18 +88,17 @@ type Client interface {
|
||||
|
||||
// Content container for content metadata
|
||||
type clientContent struct {
|
||||
URL clientURL
|
||||
Time time.Time
|
||||
Size int64
|
||||
Type os.FileMode
|
||||
StorageClass string
|
||||
Metadata map[string]string
|
||||
UserMetadata map[string]string
|
||||
ETag string
|
||||
Expires time.Time
|
||||
EncryptionHeaders map[string]string
|
||||
Retention bool
|
||||
Err *probe.Error
|
||||
URL clientURL
|
||||
Time time.Time
|
||||
Size int64
|
||||
Type os.FileMode
|
||||
StorageClass string
|
||||
Metadata map[string]string
|
||||
UserMetadata map[string]string
|
||||
ETag string
|
||||
Expires time.Time
|
||||
Retention bool
|
||||
Err *probe.Error
|
||||
}
|
||||
|
||||
// Config - see http://docs.amazonwebservices.com/AmazonS3/latest/dev/index.html?RESTAuthentication.html
|
||||
|
||||
@@ -287,7 +287,7 @@ func filterMetadata(metadata map[string]string) map[string]string {
|
||||
}
|
||||
}
|
||||
for k := range metadata {
|
||||
if strings.HasPrefix(http.CanonicalHeaderKey(k), "X-Amz-Server-Side-Encryption-") {
|
||||
if strings.HasPrefix(http.CanonicalHeaderKey(k), http.CanonicalHeaderKey(serverEncryptionKeyPrefix)) {
|
||||
delete(newMetadata, k)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -103,8 +103,6 @@ func mainStat(ctx *cli.Context) error {
|
||||
console.SetColor("Date", color.New(color.FgWhite))
|
||||
console.SetColor("Size", color.New(color.FgWhite))
|
||||
console.SetColor("ETag", color.New(color.FgWhite))
|
||||
|
||||
console.SetColor("EncryptionHeaders", color.New(color.FgWhite))
|
||||
console.SetColor("Metadata", color.New(color.FgWhite))
|
||||
|
||||
// Parse encryption keys per command.
|
||||
|
||||
+29
-20
@@ -30,15 +30,14 @@ import (
|
||||
|
||||
// contentMessage container for content message structure.
|
||||
type statMessage struct {
|
||||
Status string `json:"status"`
|
||||
Key string `json:"name"`
|
||||
Date time.Time `json:"lastModified"`
|
||||
Size int64 `json:"size"`
|
||||
ETag string `json:"etag"`
|
||||
Type string `json:"type"`
|
||||
Expires time.Time `json:"expires"`
|
||||
EncryptionHeaders map[string]string `json:"encryption,omitempty"`
|
||||
Metadata map[string]string `json:"metadata"`
|
||||
Status string `json:"status"`
|
||||
Key string `json:"name"`
|
||||
Date time.Time `json:"lastModified"`
|
||||
Size int64 `json:"size"`
|
||||
ETag string `json:"etag"`
|
||||
Type string `json:"type"`
|
||||
Expires time.Time `json:"expires"`
|
||||
Metadata map[string]string `json:"metadata"`
|
||||
}
|
||||
|
||||
// String colorized string message.
|
||||
@@ -57,26 +56,37 @@ func printStat(stat statMessage) {
|
||||
}
|
||||
var maxKey = 0
|
||||
for k := range stat.Metadata {
|
||||
if len(k) > maxKey {
|
||||
maxKey = len(k)
|
||||
// Skip encryption headers, we print them later.
|
||||
if !strings.HasPrefix(strings.ToLower(k), serverEncryptionKeyPrefix) {
|
||||
if len(k) > maxKey {
|
||||
maxKey = len(k)
|
||||
}
|
||||
}
|
||||
}
|
||||
if len(stat.Metadata) > 0 {
|
||||
if maxKey > 0 {
|
||||
console.Println(fmt.Sprintf("%-10s:", "Metadata"))
|
||||
for k, v := range stat.Metadata {
|
||||
console.Println(fmt.Sprintf(" %-*.*s: %s ", maxKey, maxKey, k, v))
|
||||
// Skip encryption headers, we print them later.
|
||||
if !strings.HasPrefix(strings.ToLower(k), serverEncryptionKeyPrefix) {
|
||||
console.Println(fmt.Sprintf(" %-*.*s: %s ", maxKey, maxKey, k, v))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
maxKey = 0
|
||||
for k := range stat.EncryptionHeaders {
|
||||
if len(k) > maxKey {
|
||||
maxKey = len(k)
|
||||
for k := range stat.Metadata {
|
||||
if strings.HasPrefix(strings.ToLower(k), serverEncryptionKeyPrefix) {
|
||||
if len(k) > maxKey {
|
||||
maxKey = len(k)
|
||||
}
|
||||
}
|
||||
}
|
||||
if len(stat.EncryptionHeaders) > 0 {
|
||||
if maxKey > 0 {
|
||||
console.Println(fmt.Sprintf("%-10s:", "Encrypted"))
|
||||
for k, v := range stat.EncryptionHeaders {
|
||||
console.Println(fmt.Sprintf(" %-*.*s: %s ", maxKey, maxKey, k, v))
|
||||
for k, v := range stat.Metadata {
|
||||
if strings.HasPrefix(strings.ToLower(k), serverEncryptionKeyPrefix) {
|
||||
console.Println(fmt.Sprintf(" %-*.*s: %s ", maxKey, maxKey, k, v))
|
||||
}
|
||||
}
|
||||
}
|
||||
console.Println()
|
||||
@@ -108,7 +118,6 @@ func parseStat(c *clientContent) statMessage {
|
||||
content.ETag = strings.TrimPrefix(c.ETag, "\"")
|
||||
content.ETag = strings.TrimSuffix(content.ETag, "\"")
|
||||
content.Expires = c.Expires
|
||||
content.EncryptionHeaders = c.EncryptionHeaders
|
||||
return content
|
||||
}
|
||||
|
||||
|
||||
+34
-25
@@ -18,41 +18,50 @@ package cmd
|
||||
|
||||
import (
|
||||
"os"
|
||||
"reflect"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
. "gopkg.in/check.v1"
|
||||
)
|
||||
|
||||
func (s *TestSuite) TestParseStat(c *C) {
|
||||
func TestParseStat(t *testing.T) {
|
||||
localTime := time.Unix(12001, 0).UTC()
|
||||
testCases := []struct {
|
||||
content clientContent
|
||||
targetAlias string
|
||||
}{
|
||||
{clientContent{URL: *newClientURL("https://play.min.io/abc"), Size: 0, Time: localTime, Type: os.ModeDir, ETag: "blahblah", Metadata: map[string]string{"cusom-key": "custom-value"}, EncryptionHeaders: map[string]string{}, Expires: time.Now()},
|
||||
"play"},
|
||||
{clientContent{URL: *newClientURL("https://play.min.io/testbucket"), Size: 500, Time: localTime, Type: os.ModeDir, ETag: "blahblah", Metadata: map[string]string{"cusom-key": "custom-value"}, EncryptionHeaders: map[string]string{}, Expires: time.Unix(0, 0).UTC()},
|
||||
"play"},
|
||||
{clientContent{URL: *newClientURL("https://s3.amazonaws.com/yrdy"), Size: 0, Time: localTime, Type: 0644, ETag: "abcdefasaas", Metadata: map[string]string{}, EncryptionHeaders: map[string]string{}},
|
||||
"s3"},
|
||||
{clientContent{URL: *newClientURL("https://play.min.io/yrdy"), Size: 10000, Time: localTime, Type: 0644, ETag: "blahblah", Metadata: map[string]string{"cusom-key": "custom-value"}, EncryptionHeaders: map[string]string{"X-Amz-Iv": "test", "X-Amz-Matdesc": "abcd"}},
|
||||
"play"},
|
||||
{clientContent{URL: *newClientURL("https://play.min.io/abc"), Size: 0, Time: localTime, Type: os.ModeDir, ETag: "blahblah", Metadata: map[string]string{"cusom-key": "custom-value"}, Expires: time.Now()}, "play"},
|
||||
{clientContent{URL: *newClientURL("https://play.min.io/testbucket"), Size: 500, Time: localTime, Type: os.ModeDir, ETag: "blahblah", Metadata: map[string]string{"cusom-key": "custom-value"}, Expires: time.Unix(0, 0).UTC()}, "play"},
|
||||
{clientContent{URL: *newClientURL("https://s3.amazonaws.com/yrdy"), Size: 0, Time: localTime, Type: 0644, ETag: "abcdefasaas", Metadata: map[string]string{}}, "s3"},
|
||||
{clientContent{URL: *newClientURL("https://play.min.io/yrdy"), Size: 10000, Time: localTime, Type: 0644, ETag: "blahblah", Metadata: map[string]string{"cusom-key": "custom-value"}}, "play"},
|
||||
}
|
||||
for _, testCase := range testCases {
|
||||
statMsg := parseStat(&testCase.content)
|
||||
c.Assert(testCase.content.Metadata, DeepEquals, statMsg.Metadata)
|
||||
c.Assert(testCase.content.EncryptionHeaders, DeepEquals, statMsg.EncryptionHeaders)
|
||||
c.Assert(testCase.content.Size, Equals, statMsg.Size)
|
||||
c.Assert(testCase.content.Expires, Equals, statMsg.Expires)
|
||||
c.Log(statMsg.Type)
|
||||
if testCase.content.Type.IsRegular() {
|
||||
c.Assert(statMsg.Type, Equals, "file")
|
||||
} else {
|
||||
c.Assert(statMsg.Type, Equals, "folder")
|
||||
}
|
||||
etag := strings.TrimPrefix(testCase.content.ETag, "\"")
|
||||
etag = strings.TrimSuffix(etag, "\"")
|
||||
c.Assert(etag, Equals, statMsg.ETag)
|
||||
testCase := testCase
|
||||
t.Run("", func(t *testing.T) {
|
||||
statMsg := parseStat(&testCase.content)
|
||||
if !reflect.DeepEqual(testCase.content.Metadata, statMsg.Metadata) {
|
||||
t.Errorf("Expecting %s, got %s", testCase.content.Metadata, statMsg.Metadata)
|
||||
}
|
||||
if testCase.content.Size != statMsg.Size {
|
||||
t.Errorf("Expecting %d, got %d", testCase.content.Size, statMsg.Size)
|
||||
}
|
||||
if testCase.content.Expires != statMsg.Expires {
|
||||
t.Errorf("Expecting %s, got %s", testCase.content.Expires, statMsg.Expires)
|
||||
}
|
||||
if testCase.content.Type.IsRegular() {
|
||||
if statMsg.Type != "file" {
|
||||
t.Errorf("Expecting file, got %s", statMsg.Type)
|
||||
}
|
||||
} else {
|
||||
if statMsg.Type != "folder" {
|
||||
t.Errorf("Expecting folder, got %s", statMsg.Type)
|
||||
}
|
||||
}
|
||||
etag := strings.TrimPrefix(testCase.content.ETag, "\"")
|
||||
etag = strings.TrimSuffix(etag, "\"")
|
||||
if etag != statMsg.ETag {
|
||||
t.Errorf("Expecting %s, got %s", etag, statMsg.ETag)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@ require (
|
||||
github.com/mattn/go-runewidth v0.0.5 // indirect
|
||||
github.com/minio/cli v1.22.0
|
||||
github.com/minio/minio v0.0.0-20200312144740-ed4bd20a7cfc
|
||||
github.com/minio/minio-go/v6 v6.0.50-0.20200306231101-b882ba63d570
|
||||
github.com/minio/minio-go/v6 v6.0.51-0.20200319192131-097caa7760c7
|
||||
github.com/minio/sha256-simd v0.1.1
|
||||
github.com/mitchellh/go-homedir v1.1.0
|
||||
github.com/pkg/profile v1.3.0
|
||||
|
||||
@@ -256,6 +256,8 @@ github.com/minio/minio v0.0.0-20200312144740-ed4bd20a7cfc/go.mod h1:QbCnTGb/blyN
|
||||
github.com/minio/minio-go/v6 v6.0.45/go.mod h1:qD0lajrGW49lKZLtXKtCB4X/qkMf0a5tBvN2PaZg7Gg=
|
||||
github.com/minio/minio-go/v6 v6.0.50-0.20200306231101-b882ba63d570 h1:GLTZoRC6rhCTucnkJAQ63LhMU2S4CM71MRc9gfX7ohE=
|
||||
github.com/minio/minio-go/v6 v6.0.50-0.20200306231101-b882ba63d570/go.mod h1:qD0lajrGW49lKZLtXKtCB4X/qkMf0a5tBvN2PaZg7Gg=
|
||||
github.com/minio/minio-go/v6 v6.0.51-0.20200319192131-097caa7760c7 h1:WQmYVUDRGdcEWhJeb42/Fn1IO7SBLem173DTE4+jp/E=
|
||||
github.com/minio/minio-go/v6 v6.0.51-0.20200319192131-097caa7760c7/go.mod h1:qD0lajrGW49lKZLtXKtCB4X/qkMf0a5tBvN2PaZg7Gg=
|
||||
github.com/minio/parquet-go v0.0.0-20200125064549-a1e49702e174 h1:WYFHZIJ5LTWd4C3CW26jguaBLLDdX7l1/Xa3QSKGkIc=
|
||||
github.com/minio/parquet-go v0.0.0-20200125064549-a1e49702e174/go.mod h1:PXYM9yI2l0YPmxHUXe6mFTmkQcyaVasDshAPTbGpDoo=
|
||||
github.com/minio/sha256-simd v0.1.1 h1:5QHSlgo3nt5yKOJrC7W8w7X+NFl8cMPZm96iu8kKUJU=
|
||||
|
||||
Reference in New Issue
Block a user