From e9eb6ae7675a1c21a3b21ec4afed1d0992a917db Mon Sep 17 00:00:00 2001 From: Daphne Nhuch Date: Thu, 8 Feb 2024 17:07:37 -0500 Subject: [PATCH 1/2] Added tagging to createMultipartUpload --- services/s3/itest/s3_test.go | 20 ++++++++++++++++++++ services/s3/s3.go | 4 +++- services/s3/types.go | 1 + 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/services/s3/itest/s3_test.go b/services/s3/itest/s3_test.go index cf2d342..96524a6 100644 --- a/services/s3/itest/s3_test.go +++ b/services/s3/itest/s3_test.go @@ -59,12 +59,14 @@ func TestMultipartUpload(t *testing.T) { kmsKey := "custom-kms-key" key := "test-key" kmsContext := "foo=bar" + tagging := "hello=world" upload, err := client.CreateMultipartUpload(ctx, &s3.CreateMultipartUploadInput{ Bucket: &bucket, Key: &key, ServerSideEncryption: types.ServerSideEncryptionAwsKms, SSEKMSKeyId: &kmsKey, SSEKMSEncryptionContext: &kmsContext, + Tagging: &tagging, }) if err != nil { t.Fatal(err) @@ -173,6 +175,24 @@ func TestMultipartUpload(t *testing.T) { }}) { t.Fatal("wrong parts", partsOutput.Parts) } + + objectTagging, err := client.GetObjectTagging(ctx, &s3.GetObjectTaggingInput{ + Bucket: &bucket, + Key: &key, + }) + if err != nil { + t.Fatal(err) + } + tags := objectTagging.TagSet + if len(tags) != 1 { + t.Fatal("bad tags", objectTagging.TagSet) + } + if *tags[0].Key != "key" { + t.Fatal("bad tag") + } + if *tags[0].Value != "value" { + t.Fatal("bad value") + } } type RangeTestCase struct { diff --git a/services/s3/s3.go b/services/s3/s3.go index bebc2c2..ff43b58 100644 --- a/services/s3/s3.go +++ b/services/s3/s3.go @@ -57,6 +57,7 @@ type multipartUpload struct { Status UploadStatus Bucket string Key string + Tagging string Parts map[int]Part // For metadata Object Object @@ -608,11 +609,12 @@ func (s *S3) CreateMultipartUpload(input CreateMultipartUploadInput) (*CreateMul } uploadId := base64.RawURLEncoding.EncodeToString(uuid.Must(uuid.NewV4()).Bytes()) - + fmt.Sprintf("Daphne Tagging " + input.Tagging) s.multipartUploads[uploadId] = &multipartUpload{ Status: UploadStatusInProgress, Bucket: input.Bucket, Key: input.Key, + Tagging: input.Tagging, Parts: make(map[int]Part), // Just for metadata Object: Object{ diff --git a/services/s3/types.go b/services/s3/types.go index d0b71c4..069872b 100644 --- a/services/s3/types.go +++ b/services/s3/types.go @@ -156,6 +156,7 @@ type CreateMultipartUploadInput struct { Bucket string `s3:"bucket"` Key string `s3:"key"` ContentType string `s3:"header:content-type"` + Tagging string `s3:"header:x-amz-tagging"` ServerSideEncryption string `s3:"header:x-amz-server-side-encryption"` SSEKMSKeyId string `s3:"header:x-amz-server-side-encryption-aws-kms-key-id"` SSEKMSEncryptionContext string `s3:"header:x-amz-server-side-encryption-context"` From c82b856c4427d09a43102ee4c9a5a101d9875c9e Mon Sep 17 00:00:00 2001 From: Daphne Nhuch Date: Thu, 8 Feb 2024 18:18:21 -0500 Subject: [PATCH 2/2] cleanup --- services/s3/itest/s3_test.go | 7 +++---- services/s3/s3.go | 3 ++- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/services/s3/itest/s3_test.go b/services/s3/itest/s3_test.go index 96524a6..dd24122 100644 --- a/services/s3/itest/s3_test.go +++ b/services/s3/itest/s3_test.go @@ -59,14 +59,13 @@ func TestMultipartUpload(t *testing.T) { kmsKey := "custom-kms-key" key := "test-key" kmsContext := "foo=bar" - tagging := "hello=world" upload, err := client.CreateMultipartUpload(ctx, &s3.CreateMultipartUploadInput{ Bucket: &bucket, Key: &key, ServerSideEncryption: types.ServerSideEncryptionAwsKms, SSEKMSKeyId: &kmsKey, SSEKMSEncryptionContext: &kmsContext, - Tagging: &tagging, + Tagging: aws.String("foo=bar"), }) if err != nil { t.Fatal(err) @@ -187,10 +186,10 @@ func TestMultipartUpload(t *testing.T) { if len(tags) != 1 { t.Fatal("bad tags", objectTagging.TagSet) } - if *tags[0].Key != "key" { + if *tags[0].Key != "foo" { t.Fatal("bad tag") } - if *tags[0].Value != "value" { + if *tags[0].Value != "bar" { t.Fatal("bad value") } } diff --git a/services/s3/s3.go b/services/s3/s3.go index ff43b58..486d2cc 100644 --- a/services/s3/s3.go +++ b/services/s3/s3.go @@ -547,6 +547,7 @@ func (s *S3) GetObjectTagging(input GetObjectTaggingInput) (*GetObjectTaggingOut }) } } + return tagging, nil } @@ -609,7 +610,6 @@ func (s *S3) CreateMultipartUpload(input CreateMultipartUploadInput) (*CreateMul } uploadId := base64.RawURLEncoding.EncodeToString(uuid.Must(uuid.NewV4()).Bytes()) - fmt.Sprintf("Daphne Tagging " + input.Tagging) s.multipartUploads[uploadId] = &multipartUpload{ Status: UploadStatusInProgress, Bucket: input.Bucket, @@ -764,6 +764,7 @@ func (s *S3) CompleteMultipartUpload(input CompleteMultipartUploadInput) (*Compl } object.ContentLength = totalContentLength object.ETag = etag(combinedMD5s) + "-" + strconv.Itoa(len(input.Part)) + object.Tagging = upload.Tagging s.buckets[input.Bucket].objects[input.Key] = &object upload.Status = UploadStatusCompleted