Skip to content

Commit

Permalink
Merge pull request #4 from daphnenhuch-at/daphnenhuch-addTaggingToCre…
Browse files Browse the repository at this point in the history
…ateMultipart

Added tagging to createMultipartUpload
  • Loading branch information
DavidZbarsky-at authored Feb 9, 2024
2 parents d3d786a + c82b856 commit acfe465
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
19 changes: 19 additions & 0 deletions services/s3/itest/s3_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ func TestMultipartUpload(t *testing.T) {
ServerSideEncryption: types.ServerSideEncryptionAwsKms,
SSEKMSKeyId: &kmsKey,
SSEKMSEncryptionContext: &kmsContext,
Tagging: aws.String("foo=bar"),
})
if err != nil {
t.Fatal(err)
Expand Down Expand Up @@ -173,6 +174,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 != "foo" {
t.Fatal("bad tag")
}
if *tags[0].Value != "bar" {
t.Fatal("bad value")
}
}

type RangeTestCase struct {
Expand Down
5 changes: 4 additions & 1 deletion services/s3/s3.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ type multipartUpload struct {
Status UploadStatus
Bucket string
Key string
Tagging string
Parts map[int]Part
// For metadata
Object Object
Expand Down Expand Up @@ -546,6 +547,7 @@ func (s *S3) GetObjectTagging(input GetObjectTaggingInput) (*GetObjectTaggingOut
})
}
}

return tagging, nil
}

Expand Down Expand Up @@ -608,11 +610,11 @@ func (s *S3) CreateMultipartUpload(input CreateMultipartUploadInput) (*CreateMul
}

uploadId := base64.RawURLEncoding.EncodeToString(uuid.Must(uuid.NewV4()).Bytes())

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{
Expand Down Expand Up @@ -762,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
Expand Down
1 change: 1 addition & 0 deletions services/s3/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down

0 comments on commit acfe465

Please sign in to comment.