mirror of
https://github.com/versity/versitygw.git
synced 2026-06-06 02:52:36 +00:00
fix: Fixed couple of bugs regarding to GetObject range errors, blob metadata reference losing
This commit is contained in:
committed by
Ben McClelland
parent
240db54feb
commit
03e4a28d57
@@ -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
|
||||
}
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user