From 4067b0be18721972b2cb651f0c778b5892c0763b Mon Sep 17 00:00:00 2001 From: Harshavardhana Date: Thu, 19 Mar 2015 00:14:58 -0700 Subject: [PATCH] Move s3errors and make it part of standard s3 package. Also update 'resourceList' with additional resources from amazon api. --- pkg/s3/auth.go | 24 +++++++++++++++++++++++- pkg/s3/bucket.go | 8 +++----- pkg/{s3errors => s3}/errors.go | 7 +++---- pkg/s3/object.go | 10 ++++------ 4 files changed, 33 insertions(+), 16 deletions(-) rename pkg/{s3errors => s3}/errors.go (89%) diff --git a/pkg/s3/auth.go b/pkg/s3/auth.go index c56e08d6..7f031a04 100644 --- a/pkg/s3/auth.go +++ b/pkg/s3/auth.go @@ -215,7 +215,28 @@ func (a *Auth) writeCanonicalizedAmzHeaders(buf *bytes.Buffer, req *http.Request } // Must be sorted: -var subResList = []string{"acl", "lifecycle", "location", "logging", "notification", "partNumber", "policy", "requestPayment", "torrent", "uploadId", "uploads", "versionId", "versioning", "versions", "website"} +var subResList = []string{ + "acl", + "location", + "logging", + "notification", + "partNumber", + "policy", + "requestPayment", + "torrent", + "uploadId", + "uploads", + "versionId", + "versioning", + "versions", + "response-content-type", + "response-content-language", + "response-expires", + "response-cache-control", + "response-content-disposition", + "response-content-encoding", + "website", +} // From the Amazon docs: // @@ -229,6 +250,7 @@ func (a *Auth) writeCanonicalizedResource(buf *bytes.Buffer, req *http.Request, buf.WriteString(bucket) } buf.WriteString(req.URL.Path) + sort.Strings(subResList) if req.URL.RawQuery != "" { n := 0 vals, _ := url.ParseQuery(req.URL.RawQuery) diff --git a/pkg/s3/bucket.go b/pkg/s3/bucket.go index 63e3a1e2..8ff6d9c4 100644 --- a/pkg/s3/bucket.go +++ b/pkg/s3/bucket.go @@ -50,8 +50,6 @@ import ( "encoding/xml" "net/http" "net/url" - - "github.com/minio-io/mc/pkg/s3errors" ) // bySize implements sort.Interface for []Item based on the Size field. @@ -76,7 +74,7 @@ func (c *Client) ListBuckets() ([]*Bucket, error) { defer res.Body.Close() if res.StatusCode != http.StatusOK { - return nil, s3errors.New(res) + return nil, NewError(res) } return parseListAllMyBuckets(res.Body) @@ -98,7 +96,7 @@ func (c *Client) PutBucket(bucket string) error { defer res.Body.Close() if res.StatusCode != http.StatusOK { - return s3errors.New(res) + return NewError(res) } return nil @@ -154,7 +152,7 @@ func (c *Client) ListObjects(bucket string, startAt, prefix, delimiter string, m defer res.Body.Close() if res.StatusCode != http.StatusOK { - return nil, nil, s3errors.New(res) + return nil, nil, NewError(res) } bres = listBucketResults{} diff --git a/pkg/s3errors/errors.go b/pkg/s3/errors.go similarity index 89% rename from pkg/s3errors/errors.go rename to pkg/s3/errors.go index 89743d23..48aac2ba 100644 --- a/pkg/s3errors/errors.go +++ b/pkg/s3/errors.go @@ -14,8 +14,7 @@ * limitations under the License. */ -// Package s3errors implements client side error handling for S3 protocol -package s3errors +package s3 import ( "fmt" @@ -42,8 +41,8 @@ type Error struct { resMsg mxj.Map // Keys: Code, Message, Resource, RequestId, HostId } -// New returns a new initialized S3.Error structure -func New(res *http.Response) error { +// NewError returns a new initialized S3.Error structure +func NewError(res *http.Response) error { var err error var s3Err Error diff --git a/pkg/s3/object.go b/pkg/s3/object.go index 9a5c0f98..91bc0ca7 100644 --- a/pkg/s3/object.go +++ b/pkg/s3/object.go @@ -51,8 +51,6 @@ import ( "encoding/base64" "io/ioutil" "net/http" - - "github.com/minio-io/mc/pkg/s3errors" ) /// Object API operations @@ -86,7 +84,7 @@ func (c *Client) Put(bucket, key string, size int64, contents io.Reader) error { defer res.Body.Close() if res.StatusCode != http.StatusOK { - return s3errors.New(res) + return NewError(res) } return nil } @@ -119,7 +117,7 @@ func (c *Client) Stat(bucket, key string) (size int64, date time.Time, reterr er return size, date, nil } default: - return 0, date, s3errors.New(res) + return 0, date, NewError(res) } return } @@ -134,7 +132,7 @@ func (c *Client) Get(bucket, key string) (body io.ReadCloser, size int64, err er } if res.StatusCode != http.StatusOK { - return nil, 0, s3errors.New(res) + return nil, 0, NewError(res) } return res.Body, res.ContentLength, nil @@ -164,6 +162,6 @@ func (c *Client) GetPartial(bucket, key string, offset, length int64) (body io.R case http.StatusOK, http.StatusPartialContent: return res.Body, res.ContentLength, nil default: - return nil, 0, s3errors.New(res) + return nil, 0, NewError(res) } }