From 2320487dcbf372a0964c924667710cbdf17a687f Mon Sep 17 00:00:00 2001 From: Harshavardhana Date: Mon, 16 Nov 2015 12:29:16 -0800 Subject: [PATCH] minio-go/vendor: Add proper return on 301 for all apis. --- vendor/github.com/minio/minio-go/errors.go | 2 +- vendor/github.com/minio/minio-go/s3-api.go | 103 +++++++++++++++++++++ vendor/vendor.json | 4 +- 3 files changed, 106 insertions(+), 3 deletions(-) diff --git a/vendor/github.com/minio/minio-go/errors.go b/vendor/github.com/minio/minio-go/errors.go index 9ccaefa4..a490d5bf 100644 --- a/vendor/github.com/minio/minio-go/errors.go +++ b/vendor/github.com/minio/minio-go/errors.go @@ -45,7 +45,7 @@ type ErrorResponse struct { RequestID string `xml:"RequestId"` HostID string `xml:"HostId"` - // This is a new undocumented field + // This is a new undocumented field, set only if available. AmzBucketRegion string } diff --git a/vendor/github.com/minio/minio-go/s3-api.go b/vendor/github.com/minio/minio-go/s3-api.go index d3fe3077..329b7180 100644 --- a/vendor/github.com/minio/minio-go/s3-api.go +++ b/vendor/github.com/minio/minio-go/s3-api.go @@ -177,6 +177,19 @@ func (a s3API) putBucketACL(bucket, acl string) error { } if resp != nil { if resp.StatusCode != http.StatusOK { + if resp.StatusCode == http.StatusMovedPermanently { + region, _ := a.getBucketLocation(bucket) + endPoint := getEndpoint(region) + errorResponse := ErrorResponse{ + Code: "PermanentRedirect", + Message: "The bucket you are attempting to access must be addressed using the specified endpoint https://" + endPoint + ". Send all future requests to this endpoint.", + Resource: separator + bucket, + RequestID: resp.Header.Get("x-amz-request-id"), + HostID: resp.Header.Get("x-amz-id-2"), + AmzBucketRegion: resp.Header.Get("x-amz-bucket-region"), + } + return errorResponse + } return BodyToErrorResponse(resp.Body, a.config.AcceptType) } } @@ -210,6 +223,19 @@ func (a s3API) getBucketACL(bucket string) (accessControlPolicy, error) { } if resp != nil { if resp.StatusCode != http.StatusOK { + if resp.StatusCode == http.StatusMovedPermanently { + region, _ := a.getBucketLocation(bucket) + endPoint := getEndpoint(region) + errorResponse := ErrorResponse{ + Code: "PermanentRedirect", + Message: "The bucket you are attempting to access must be addressed using the specified endpoint https://" + endPoint + ". Send all future requests to this endpoint.", + Resource: separator + bucket, + RequestID: resp.Header.Get("x-amz-request-id"), + HostID: resp.Header.Get("x-amz-id-2"), + AmzBucketRegion: resp.Header.Get("x-amz-bucket-region"), + } + return accessControlPolicy{}, errorResponse + } return accessControlPolicy{}, BodyToErrorResponse(resp.Body, a.config.AcceptType) } } @@ -333,6 +359,19 @@ func (a s3API) listObjects(bucket, marker, prefix, delimiter string, maxkeys int } if resp != nil { if resp.StatusCode != http.StatusOK { + if resp.StatusCode == http.StatusMovedPermanently { + region, _ := a.getBucketLocation(bucket) + endPoint := getEndpoint(region) + errorResponse := ErrorResponse{ + Code: "PermanentRedirect", + Message: "The bucket you are attempting to access must be addressed using the specified endpoint https://" + endPoint + ". Send all future requests to this endpoint.", + Resource: separator + bucket, + RequestID: resp.Header.Get("x-amz-request-id"), + HostID: resp.Header.Get("x-amz-id-2"), + AmzBucketRegion: resp.Header.Get("x-amz-bucket-region"), + } + return listBucketResult{}, errorResponse + } return listBucketResult{}, BodyToErrorResponse(resp.Body, a.config.AcceptType) } } @@ -449,6 +488,17 @@ func (a s3API) deleteBucket(bucket string) error { if resp.StatusCode != http.StatusNoContent { var errorResponse ErrorResponse switch resp.StatusCode { + case http.StatusMovedPermanently: + region, _ := a.getBucketLocation(bucket) + endPoint := getEndpoint(region) + errorResponse = ErrorResponse{ + Code: "PermanentRedirect", + Message: "The bucket you are attempting to access must be addressed using the specified endpoint https://" + endPoint + ". Send all future requests to this endpoint.", + Resource: separator + bucket, + RequestID: resp.Header.Get("x-amz-request-id"), + HostID: resp.Header.Get("x-amz-id-2"), + AmzBucketRegion: resp.Header.Get("x-amz-bucket-region"), + } case http.StatusNotFound: errorResponse = ErrorResponse{ Code: "NoSuchBucket", @@ -530,6 +580,20 @@ func (a s3API) putObjectUnAuthenticated(bucket, object, contentType string, } if resp != nil { if resp.StatusCode != http.StatusOK { + // handle 301 sepcifically in case of wrong regions during path style. + if resp.StatusCode == http.StatusMovedPermanently { + region, _ := a.getBucketLocation(bucket) + endPoint := getEndpoint(region) + errorResponse := ErrorResponse{ + Code: "PermanentRedirect", + Message: "The bucket you are attempting to access must be addressed using the specified endpoint https://" + endPoint + ". Send all future requests to this endpoint.", + Resource: separator + bucket, + RequestID: resp.Header.Get("x-amz-request-id"), + HostID: resp.Header.Get("x-amz-id-2"), + AmzBucketRegion: resp.Header.Get("x-amz-bucket-region"), + } + return ObjectStat{}, errorResponse + } return ObjectStat{}, BodyToErrorResponse(resp.Body, a.config.AcceptType) } } @@ -577,6 +641,20 @@ func (a s3API) putObject(bucket, object, contentType string, } if resp != nil { if resp.StatusCode != http.StatusOK { + // handle 301 sepcifically in case of wrong regions during path style. + if resp.StatusCode == http.StatusMovedPermanently { + region, _ := a.getBucketLocation(bucket) + endPoint := getEndpoint(region) + errorResponse := ErrorResponse{ + Code: "PermanentRedirect", + Message: "The bucket you are attempting to access must be addressed using the specified endpoint https://" + endPoint + ". Send all future requests to this endpoint.", + Resource: separator + bucket, + RequestID: resp.Header.Get("x-amz-request-id"), + HostID: resp.Header.Get("x-amz-id-2"), + AmzBucketRegion: resp.Header.Get("x-amz-bucket-region"), + } + return ObjectStat{}, errorResponse + } return ObjectStat{}, BodyToErrorResponse(resp.Body, a.config.AcceptType) } } @@ -725,8 +803,22 @@ func (a s3API) getObject(bucket, object string, offset, length int64) (io.ReadCl } if resp != nil { switch resp.StatusCode { + // for HTTP status 200 and 204 are valid cases. case http.StatusOK: case http.StatusPartialContent: + // handle 301 sepcifically in case of wrong regions during path style. + case http.StatusMovedPermanently: + region, _ := a.getBucketLocation(bucket) + endPoint := getEndpoint(region) + errorResponse := ErrorResponse{ + Code: "PermanentRedirect", + Message: "The bucket you are attempting to access must be addressed using the specified endpoint https://" + endPoint + ". Send all future requests to this endpoint.", + Resource: separator + bucket, + RequestID: resp.Header.Get("x-amz-request-id"), + HostID: resp.Header.Get("x-amz-id-2"), + AmzBucketRegion: resp.Header.Get("x-amz-bucket-region"), + } + return nil, ObjectStat{}, errorResponse default: return nil, ObjectStat{}, BodyToErrorResponse(resp.Body, a.config.AcceptType) } @@ -821,6 +913,17 @@ func (a s3API) headObject(bucket, object string) (ObjectStat, error) { if resp.StatusCode != http.StatusOK { var errorResponse ErrorResponse switch resp.StatusCode { + case http.StatusMovedPermanently: + region, _ := a.getBucketLocation(bucket) + endPoint := getEndpoint(region) + errorResponse = ErrorResponse{ + Code: "PermanentRedirect", + Message: "The bucket you are attempting to access must be addressed using the specified endpoint https://" + endPoint + ". Send all future requests to this endpoint.", + Resource: separator + bucket, + RequestID: resp.Header.Get("x-amz-request-id"), + HostID: resp.Header.Get("x-amz-id-2"), + AmzBucketRegion: resp.Header.Get("x-amz-bucket-region"), + } case http.StatusNotFound: errorResponse = ErrorResponse{ Code: "NoSuchKey", diff --git a/vendor/vendor.json b/vendor/vendor.json index 7f583e2a..5774a62a 100644 --- a/vendor/vendor.json +++ b/vendor/vendor.json @@ -29,8 +29,8 @@ }, { "path": "github.com/minio/minio-go", - "revision": "e118c27ff5ddde1175ee1bdfd6486871442fbbb0", - "revisionTime": "2015-11-16T11:08:12-08:00" + "revision": "8264db82e69176b2a0f5b37fd8ffd232bdea6ad1", + "revisionTime": "2015-11-16T12:27:52-08:00" }, { "path": "github.com/minio/minio-xl/pkg/probe",