From 03e4a28d574299b4121f02f2957c94079df35bea Mon Sep 17 00:00:00 2001 From: jonaustin09 Date: Wed, 17 Jan 2024 11:01:16 -0500 Subject: [PATCH] fix: Fixed couple of bugs regarding to GetObject range errors, blob metadata reference losing --- backend/azure/azure.go | 28 +++++++--------------------- backend/azure/err.go | 2 ++ integration/tests.go | 8 ++------ 3 files changed, 11 insertions(+), 27 deletions(-) diff --git a/backend/azure/azure.go b/backend/azure/azure.go index d1d41fc4..218939ff 100644 --- a/backend/azure/azure.go +++ b/backend/azure/azure.go @@ -23,7 +23,6 @@ import ( "fmt" "io" "math" - "net/url" "os" "strconv" "strings" @@ -144,9 +143,7 @@ func (az *Azure) ListBuckets(ctx context.Context, owner string, isAdmin bool) (s } result.Buckets.Bucket = buckets - // If the gateway is initialized with shared key credentials - // provide user account name as the owner of the buckets - result.Owner.ID = az.getAccountNameFromURL() + result.Owner.ID = owner return result, nil } @@ -189,7 +186,7 @@ func (az *Azure) PutObject(ctx context.Context, po *s3.PutObjectInput) (string, func (az *Azure) GetObject(ctx context.Context, input *s3.GetObjectInput, writer io.Writer) (*s3.GetObjectOutput, error) { var opts *azblob.DownloadStreamOptions - if input.Range != nil { + if *input.Range != "" { offset, count, err := parseRange(*input.Range) if err != nil { return nil, err @@ -218,7 +215,7 @@ func (az *Azure) GetObject(ctx context.Context, input *s3.GetObjectInput, writer } return &s3.GetObjectOutput{ - AcceptRanges: blobDownloadResponse.AcceptRanges, + AcceptRanges: input.Range, ContentLength: blobDownloadResponse.ContentLength, ContentEncoding: blobDownloadResponse.ContentEncoding, ContentType: blobDownloadResponse.ContentType, @@ -715,6 +712,8 @@ func (az *Azure) ChangeBucketOwner(ctx context.Context, bucket, newOwner string) return nil } +// The action actually returns the containers owned by the user, who initialized the gateway +// TODO: Not sure if there's a way to list all the containers and owners? func (az *Azure) ListBucketsAndOwners(ctx context.Context) (buckets []s3response.Bucket, err error) { pager := az.client.NewListContainersPager(nil) @@ -779,20 +778,6 @@ func (az *Azure) getBlockBlobClient(cntr, blb string) (*blockblob.Client, error) return blockblob.NewClientWithSharedKeyCredential(blobURL, az.sharedkeyCreds, nil) } -func (az *Azure) getAccountNameFromURL() string { - urlParts, err := url.Parse(az.serviceURL) - if err != nil { - return "" - } - - acc := urlParts.Path - - if strings.HasSuffix(acc, ".blob.core.windows.net/") { - return strings.TrimSuffix(acc, ".blob.core.windows.net") - } - return acc[1:] -} - func parseMetadata(m map[string]string) map[string]*string { if m == nil { return nil @@ -801,7 +786,8 @@ func parseMetadata(m map[string]string) map[string]*string { meta := make(map[string]*string) for k, v := range m { - meta[k] = &v + val := v + meta[k] = &val } return meta } diff --git a/backend/azure/err.go b/backend/azure/err.go index 2a33012f..8eb239bc 100644 --- a/backend/azure/err.go +++ b/backend/azure/err.go @@ -41,6 +41,8 @@ func azErrToS3err(azErr *azcore.ResponseError) s3err.APIError { return s3err.GetAPIError(s3err.ErrNoSuchKey) case "TagsTooLarge": return s3err.GetAPIError(s3err.ErrInvalidTag) + case "Requested Range Not Satisfiable": + return s3err.GetAPIError(s3err.ErrInvalidRange) } return s3err.APIError{ Code: azErr.ErrorCode, diff --git a/integration/tests.go b/integration/tests.go index 847e37f9..9aa54028 100644 --- a/integration/tests.go +++ b/integration/tests.go @@ -1426,7 +1426,7 @@ func ListObject_truncated(s *S3Conf) error { } if out1.IsTruncated == nil || !*out1.IsTruncated { - return fmt.Errorf("expected out1put to be truncated") + return fmt.Errorf("expected output to be truncated") } if *out1.MaxKeys != maxKeys { @@ -1434,7 +1434,7 @@ func ListObject_truncated(s *S3Conf) error { } if *out1.NextMarker != "baz" { - return fmt.Errorf("expected nex-marker to be baz, instead got %v", *out1.NextMarker) + return fmt.Errorf("expected next-marker to be baz, instead got %v", *out1.NextMarker) } if !compareObjects([]string{"bar", "baz"}, out1.Contents) { @@ -1590,10 +1590,6 @@ func ListObjects_marker_not_from_obj_list(s *S3Conf) error { return err } - for _, el := range out.Contents { - fmt.Println(*el.Key) - } - if !compareObjects([]string{"foo", "qux", "hello", "xyz"}, out.Contents) { return fmt.Errorf("expected output to be %v, instead got %v", []string{"foo", "qux", "hello", "xyz"}, out.Contents) }