From 834a25f0840c0dfbf3b27006f419d7e2d5f25b90 Mon Sep 17 00:00:00 2001 From: Chris Lu Date: Wed, 18 Jul 2018 02:37:09 -0700 Subject: add list all my buckets --- weed/s3api/s3api_errors.go | 76 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 weed/s3api/s3api_errors.go (limited to 'weed/s3api/s3api_errors.go') diff --git a/weed/s3api/s3api_errors.go b/weed/s3api/s3api_errors.go new file mode 100644 index 000000000..f6988f5e1 --- /dev/null +++ b/weed/s3api/s3api_errors.go @@ -0,0 +1,76 @@ +package s3api + +import ( + "encoding/xml" + "net/http" +) + +// APIError structure +type APIError struct { + Code string + Description string + HTTPStatusCode int +} + +// RESTErrorResponse - error response format +type RESTErrorResponse struct { + XMLName xml.Name `xml:"Error" json:"-"` + Code string `xml:"Code" json:"Code"` + Message string `xml:"Message" json:"Message"` + Resource string `xml:"Resource" json:"Resource"` + RequestID string `xml:"RequestId" json:"RequestId"` +} + +// ErrorCode type of error status. +type ErrorCode int + +// Error codes, see full list at http://docs.aws.amazon.com/AmazonS3/latest/API/ErrorResponses.html +const ( + ErrNone ErrorCode = iota + ErrMethodNotAllowed + ErrBucketNotEmpty + ErrBucketAlreadyExists + ErrBucketAlreadyOwnedByYou + ErrInvalidBucketName + ErrInternalError +) + +// error code to APIError structure, these fields carry respective +// descriptions for all the error responses. +var errorCodeResponse = map[ErrorCode]APIError{ + ErrMethodNotAllowed: { + Code: "MethodNotAllowed", + Description: "The specified method is not allowed against this resource.", + HTTPStatusCode: http.StatusMethodNotAllowed, + }, + ErrBucketNotEmpty: { + Code: "BucketNotEmpty", + Description: "The bucket you tried to delete is not empty", + HTTPStatusCode: http.StatusConflict, + }, + ErrBucketAlreadyExists: { + Code: "BucketAlreadyExists", + Description: "The requested bucket name is not available. The bucket namespace is shared by all users of the system. Please select a different name and try again.", + HTTPStatusCode: http.StatusConflict, + }, + ErrBucketAlreadyOwnedByYou: { + Code: "BucketAlreadyOwnedByYou", + Description: "Your previous request to create the named bucket succeeded and you already own it.", + HTTPStatusCode: http.StatusConflict, + }, + ErrInvalidBucketName: { + Code: "InvalidBucketName", + Description: "The specified bucket is not valid.", + HTTPStatusCode: http.StatusBadRequest, + }, + ErrInternalError: { + Code: "InternalError", + Description: "We encountered an internal error, please try again.", + HTTPStatusCode: http.StatusInternalServerError, + }, +} + +// getAPIError provides API Error for input API error code. +func getAPIError(code ErrorCode) APIError { + return errorCodeResponse[code] +} -- cgit v1.2.3 From feea33d5e02944e5aeb43d138b8e3d91b2407f08 Mon Sep 17 00:00:00 2001 From: Chris Lu Date: Thu, 19 Jul 2018 01:43:27 -0700 Subject: add HeadBucket --- weed/s3api/s3api_errors.go | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'weed/s3api/s3api_errors.go') diff --git a/weed/s3api/s3api_errors.go b/weed/s3api/s3api_errors.go index f6988f5e1..8af024700 100644 --- a/weed/s3api/s3api_errors.go +++ b/weed/s3api/s3api_errors.go @@ -32,6 +32,7 @@ const ( ErrBucketAlreadyExists ErrBucketAlreadyOwnedByYou ErrInvalidBucketName + ErrNoSuchBucket ErrInternalError ) @@ -63,6 +64,11 @@ var errorCodeResponse = map[ErrorCode]APIError{ Description: "The specified bucket is not valid.", HTTPStatusCode: http.StatusBadRequest, }, + ErrNoSuchBucket: { + Code: "NoSuchBucket", + Description: "The specified bucket does not exist", + HTTPStatusCode: http.StatusNotFound, + }, ErrInternalError: { Code: "InternalError", Description: "We encountered an internal error, please try again.", -- cgit v1.2.3 From 8480008a9a64ed8b922c786c70bc38e1f0353478 Mon Sep 17 00:00:00 2001 From: Chris Lu Date: Sat, 21 Jul 2018 10:39:02 -0700 Subject: add s3 upload, and removing mono and multi part upload analyzer removing mono and multi part upload analyzer, which were used just to determine the file name --- weed/s3api/s3api_errors.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'weed/s3api/s3api_errors.go') diff --git a/weed/s3api/s3api_errors.go b/weed/s3api/s3api_errors.go index 8af024700..10b48c2c8 100644 --- a/weed/s3api/s3api_errors.go +++ b/weed/s3api/s3api_errors.go @@ -31,8 +31,9 @@ const ( ErrBucketNotEmpty ErrBucketAlreadyExists ErrBucketAlreadyOwnedByYou - ErrInvalidBucketName ErrNoSuchBucket + ErrInvalidBucketName + ErrInvalidDigest ErrInternalError ) @@ -64,6 +65,11 @@ var errorCodeResponse = map[ErrorCode]APIError{ Description: "The specified bucket is not valid.", HTTPStatusCode: http.StatusBadRequest, }, + ErrInvalidDigest: { + Code: "InvalidDigest", + Description: "The Content-Md5 you specified is not valid.", + HTTPStatusCode: http.StatusBadRequest, + }, ErrNoSuchBucket: { Code: "NoSuchBucket", Description: "The specified bucket does not exist", -- cgit v1.2.3 From 7e2031b18f3f78688ff596921b5a6b8ebb36986b Mon Sep 17 00:00:00 2001 From: Chris Lu Date: Sat, 21 Jul 2018 17:39:10 -0700 Subject: go fmt --- weed/s3api/s3api_errors.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'weed/s3api/s3api_errors.go') diff --git a/weed/s3api/s3api_errors.go b/weed/s3api/s3api_errors.go index 10b48c2c8..771b1dd82 100644 --- a/weed/s3api/s3api_errors.go +++ b/weed/s3api/s3api_errors.go @@ -26,7 +26,7 @@ type ErrorCode int // Error codes, see full list at http://docs.aws.amazon.com/AmazonS3/latest/API/ErrorResponses.html const ( - ErrNone ErrorCode = iota + ErrNone ErrorCode = iota ErrMethodNotAllowed ErrBucketNotEmpty ErrBucketAlreadyExists -- cgit v1.2.3