Skip to content

Commit

Permalink
fix: Fixed couple of bugs regarding to GetObject range errors, blob m…
Browse files Browse the repository at this point in the history
…etadata reference losing
  • Loading branch information
0x180 authored and benmcclelland committed Jan 17, 2024
1 parent 240db54 commit 03e4a28
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 27 deletions.
28 changes: 7 additions & 21 deletions backend/azure/azure.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import (
"fmt"
"io"
"math"
"net/url"
"os"
"strconv"
"strings"
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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
Expand All @@ -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
}
Expand Down
2 changes: 2 additions & 0 deletions backend/azure/err.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
8 changes: 2 additions & 6 deletions integration/tests.go
Original file line number Diff line number Diff line change
Expand Up @@ -1426,15 +1426,15 @@ 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 {
return fmt.Errorf("expected max-keys to be %v, instead got %v", maxKeys, out1.MaxKeys)
}

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) {
Expand Down Expand Up @@ -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)
}
Expand Down

0 comments on commit 03e4a28

Please sign in to comment.