Skip to content

Commit

Permalink
fix: gcp path escape for object
Browse files Browse the repository at this point in the history
  • Loading branch information
Qu Xuan committed Jun 1, 2020
1 parent 9307660 commit 23df223
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
8 changes: 4 additions & 4 deletions pkg/multicloud/google/bucket.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ func (b *SBucket) AbortMultipartUpload(ctx context.Context, key string, uploadId
}

func (b *SBucket) CompleteMultipartUpload(ctx context.Context, key string, uploadId string, partEtags []string) error {
resource := fmt.Sprintf("b/%s/o/%s", b.Name, key)
resource := fmt.Sprintf("b/%s/o/%s", b.Name, url.PathEscape(key))
err := b.region.StorageGet(resource, nil)
if err != nil {
return errors.Wrapf(err, "failed to get object %s", key)
Expand All @@ -236,8 +236,8 @@ func (b *SBucket) CompleteMultipartUpload(ctx context.Context, key string, uploa
}

func (b *SBucket) CopyObject(ctx context.Context, destKey string, srcBucket, srcKey string, cannedAcl cloudprovider.TBucketACLType, storageClassStr string, meta http.Header) error {
resource := fmt.Sprintf("b/%s/o/%s", srcBucket, srcKey)
action := fmt.Sprintf("copyTo/b/%s/o/%s", b.Name, destKey)
resource := fmt.Sprintf("b/%s/o/%s", srcBucket, url.PathEscape(srcKey))
action := fmt.Sprintf("copyTo/b/%s/o/%s", b.Name, url.PathEscape(destKey))
err := b.region.StorageDo(resource, action, nil, nil)
if err != nil {
return errors.Wrap(err, "CopyObject")
Expand Down Expand Up @@ -267,7 +267,7 @@ func (b *SBucket) DeleteObject(ctx context.Context, key string) error {
}

func (region *SRegion) DownloadObjectRange(bucket, object string, start, end int64) (io.ReadCloser, error) {
resource := fmt.Sprintf("b/%s/o/%s?alt=media", bucket, object)
resource := fmt.Sprintf("b/%s/o/%s?alt=media", bucket, url.PathEscape(object))
header := http.Header{}
if start <= 0 {
if end > 0 {
Expand Down
7 changes: 4 additions & 3 deletions pkg/multicloud/google/bucketacl.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package google

import (
"fmt"
"net/url"

"cloud.google.com/go/storage"

Expand Down Expand Up @@ -47,7 +48,7 @@ func (region *SRegion) GetBucketAcl(bucket string) ([]GCSAcl, error) {
}

func (region *SRegion) SetObjectAcl(bucket, object string, cannedAcl cloudprovider.TBucketACLType) error {
resource := fmt.Sprintf("b/%s/o/%s", bucket, object)
resource := fmt.Sprintf("b/%s/o/%s", bucket, url.PathEscape(object))
acl := map[string]string{}
switch cannedAcl {
case cloudprovider.ACLPrivate:
Expand All @@ -57,7 +58,7 @@ func (region *SRegion) SetObjectAcl(bucket, object string, cannedAcl cloudprovid
}
for _, _acl := range acls {
if _acl.Entity == string(storage.AllUsers) || _acl.Entity == string(storage.AllAuthenticatedUsers) {
resource := fmt.Sprintf("b/%s/o/%s/acl/%s", bucket, object, _acl.Entity)
resource := fmt.Sprintf("b/%s/o/%s/acl/%s", bucket, url.PathEscape(object), _acl.Entity)
err = region.StorageDelete(resource)
if err != nil {
return errors.Wrapf(err, "StorageDelete(%s)", resource)
Expand Down Expand Up @@ -120,7 +121,7 @@ func (region *SRegion) SetBucketIam(bucket string, iam *SBucketIam) (*SBucketIam
}

func (region *SRegion) GetObjectAcl(bucket string, object string) ([]GCSAcl, error) {
resource := fmt.Sprintf("b/%s/o/%s/acl", bucket, object)
resource := fmt.Sprintf("b/%s/o/%s/acl", bucket, url.PathEscape(object))
acls := []GCSAcl{}
err := region.StorageListAll(resource, map[string]string{}, &acls)
if err != nil {
Expand Down
3 changes: 2 additions & 1 deletion pkg/multicloud/google/s3object.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import (
"context"
"fmt"
"net/http"
"net/url"
"strings"
"time"

Expand Down Expand Up @@ -197,7 +198,7 @@ func (region *SRegion) SetObjectMeta(bucket, object string, meta http.Header) er
body[fmt.Sprintf("metadata.%s", k)] = meta.Get(k)
}
}
resource := fmt.Sprintf("b/%s/o/%s", bucket, object)
resource := fmt.Sprintf("b/%s/o/%s", bucket, url.PathEscape(object))
return region.StoragePut(resource, jsonutils.Marshal(body), nil)
}

Expand Down

0 comments on commit 23df223

Please sign in to comment.