Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleanup simple_test.go and other functional naming changes #133

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions api-multipart-v1.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ func (a apiV1) listMultipartUploads(bucket, keymarker, uploadIDMarker, prefix, d
}
if resp != nil {
if resp.StatusCode != http.StatusOK {
return listMultipartUploadsResult{}, a.responseToError(resp.Body)
return listMultipartUploadsResult{}, a.ToErrorResponseBody(resp.Body)
}
}
listMultipartUploadsResult := listMultipartUploadsResult{}
Expand Down Expand Up @@ -142,7 +142,7 @@ func (a apiV1) initiateMultipartUpload(bucket, object string) (initiateMultipart
}
if resp != nil {
if resp.StatusCode != http.StatusOK {
return initiateMultipartUploadResult{}, a.responseToError(resp.Body)
return initiateMultipartUploadResult{}, a.ToErrorResponseBody(resp.Body)
}
}
initiateMultipartUploadResult := initiateMultipartUploadResult{}
Expand Down Expand Up @@ -198,7 +198,7 @@ func (a apiV1) completeMultipartUpload(bucket, object, uploadID string, c comple
}
if resp != nil {
if resp.StatusCode != http.StatusOK {
return completeMultipartUploadResult{}, a.responseToError(resp.Body)
return completeMultipartUploadResult{}, a.ToErrorResponseBody(resp.Body)
}
}
completeMultipartUploadResult := completeMultipartUploadResult{}
Expand Down Expand Up @@ -308,7 +308,7 @@ func (a apiV1) listObjectParts(bucket, object, uploadID string, partNumberMarker
}
if resp != nil {
if resp.StatusCode != http.StatusOK {
return listObjectPartsResult{}, a.responseToError(resp.Body)
return listObjectPartsResult{}, a.ToErrorResponseBody(resp.Body)
}
}
listObjectPartsResult := listObjectPartsResult{}
Expand Down Expand Up @@ -358,7 +358,7 @@ func (a apiV1) uploadPart(bucket, object, uploadID string, md5SumBytes []byte, p
}
if resp != nil {
if resp.StatusCode != http.StatusOK {
return completePart{}, a.responseToError(resp.Body)
return completePart{}, a.ToErrorResponseBody(resp.Body)
}
}
return cPart, nil
Expand Down
32 changes: 16 additions & 16 deletions api-v1.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ func (a apiV1) putBucket(bucket, acl, location string) error {
}
if resp != nil {
if resp.StatusCode != http.StatusOK {
return a.responseToError(resp.Body)
return a.ToErrorResponseBody(resp.Body)
}
}
return nil
Expand Down Expand Up @@ -164,7 +164,7 @@ func (a apiV1) putBucketACL(bucket, acl string) error {
}
if resp != nil {
if resp.StatusCode != http.StatusOK {
return a.responseToError(resp.Body)
return a.ToErrorResponseBody(resp.Body)
}
}
return nil
Expand Down Expand Up @@ -197,7 +197,7 @@ func (a apiV1) getBucketACL(bucket string) (accessControlPolicy, error) {
}
if resp != nil {
if resp.StatusCode != http.StatusOK {
return accessControlPolicy{}, a.responseToError(resp.Body)
return accessControlPolicy{}, a.ToErrorResponseBody(resp.Body)
}
}
policy := accessControlPolicy{}
Expand Down Expand Up @@ -244,7 +244,7 @@ func (a apiV1) getBucketLocation(bucket string) (string, error) {
}
if resp != nil {
if resp.StatusCode != http.StatusOK {
return "", a.responseToError(resp.Body)
return "", a.ToErrorResponseBody(resp.Body)
}
}
var locationConstraint string
Expand Down Expand Up @@ -313,7 +313,7 @@ func (a apiV1) listObjectsRequest(bucket, marker, prefix, delimiter string, maxk
// ?prefix - Limits the response to keys that begin with the specified prefix.
// ?max-keys - Sets the maximum number of keys returned in the response body.
func (a apiV1) listObjects(bucket, marker, prefix, delimiter string, maxkeys int) (listBucketResult, error) {
if err := invalidBucketToError(bucket); err != nil {
if err := invalidBucketError(bucket); err != nil {
return listBucketResult{}, err
}
req, err := a.listObjectsRequest(bucket, marker, prefix, delimiter, maxkeys)
Expand All @@ -327,7 +327,7 @@ func (a apiV1) listObjects(bucket, marker, prefix, delimiter string, maxkeys int
}
if resp != nil {
if resp.StatusCode != http.StatusOK {
return listBucketResult{}, a.responseToError(resp.Body)
return listBucketResult{}, a.ToErrorResponseBody(resp.Body)
}
}
listBucketResult := listBucketResult{}
Expand All @@ -351,7 +351,7 @@ func (a apiV1) headBucketRequest(bucket string) (*request, error) {

// headBucket useful to determine if a bucket exists and you have permission to access it.
func (a apiV1) headBucket(bucket string) error {
if err := invalidBucketToError(bucket); err != nil {
if err := invalidBucketError(bucket); err != nil {
return err
}
req, err := a.headBucketRequest(bucket)
Expand Down Expand Up @@ -412,7 +412,7 @@ func (a apiV1) deleteBucketRequest(bucket string) (*request, error) {
// All objects (including all object versions and delete markers)
// in the bucket must be deleted before successfully attempting this request
func (a apiV1) deleteBucket(bucket string) error {
if err := invalidBucketToError(bucket); err != nil {
if err := invalidBucketError(bucket); err != nil {
return err
}
req, err := a.deleteBucketRequest(bucket)
Expand Down Expand Up @@ -497,7 +497,7 @@ func (a apiV1) putObject(bucket, object, contentType string, md5SumBytes []byte,
}
if resp != nil {
if resp.StatusCode != http.StatusOK {
return ObjectStat{}, a.responseToError(resp.Body)
return ObjectStat{}, a.ToErrorResponseBody(resp.Body)
}
}
var metadata ObjectStat
Expand Down Expand Up @@ -545,7 +545,7 @@ func (a apiV1) getObjectRequest(bucket, object string, offset, length int64) (*r
//
// For more information about the HTTP Range header, go to http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.35.
func (a apiV1) getObject(bucket, object string, offset, length int64) (io.ReadCloser, ObjectStat, error) {
if err := invalidArgumentToError(object); err != nil {
if err := invalidArgumentError(object); err != nil {
return nil, ObjectStat{}, err
}
req, err := a.getObjectRequest(bucket, object, offset, length)
Expand All @@ -561,7 +561,7 @@ func (a apiV1) getObject(bucket, object string, offset, length int64) (io.ReadCl
case http.StatusOK:
case http.StatusPartialContent:
default:
return nil, ObjectStat{}, a.responseToError(resp.Body)
return nil, ObjectStat{}, a.ToErrorResponseBody(resp.Body)
}
}
md5sum := strings.Trim(resp.Header.Get("ETag"), "\"") // trim off the odd double quotes
Expand Down Expand Up @@ -611,10 +611,10 @@ func (a apiV1) deleteObjectRequest(bucket, object string) (*request, error) {

// deleteObject deletes a given object from a bucket
func (a apiV1) deleteObject(bucket, object string) error {
if err := invalidBucketToError(bucket); err != nil {
if err := invalidBucketError(bucket); err != nil {
return err
}
if err := invalidArgumentToError(object); err != nil {
if err := invalidArgumentError(object); err != nil {
return err
}
req, err := a.deleteObjectRequest(bucket, object)
Expand Down Expand Up @@ -674,10 +674,10 @@ func (a apiV1) headObjectRequest(bucket, object string) (*request, error) {

// headObject retrieves metadata from an object without returning the object itself
func (a apiV1) headObject(bucket, object string) (ObjectStat, error) {
if err := invalidBucketToError(bucket); err != nil {
if err := invalidBucketError(bucket); err != nil {
return ObjectStat{}, err
}
if err := invalidArgumentToError(object); err != nil {
if err := invalidArgumentError(object); err != nil {
return ObjectStat{}, err
}
req, err := a.headObjectRequest(bucket, object)
Expand Down Expand Up @@ -790,7 +790,7 @@ func (a apiV1) listBuckets() (listAllMyBucketsResult, error) {
}
}
if resp.StatusCode != http.StatusOK {
return listAllMyBucketsResult{}, a.responseToError(resp.Body)
return listAllMyBucketsResult{}, a.ToErrorResponseBody(resp.Body)
}
}
listAllMyBucketsResult := listAllMyBucketsResult{}
Expand Down
44 changes: 22 additions & 22 deletions api-v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ type Config struct {
// Global constants
const (
LibraryName = "minio-go"
LibraryVersion = "0.1.0"
LibraryVersion = "0.2.0"
)

// SetUserAgent - append to a default user agent
Expand Down Expand Up @@ -212,10 +212,10 @@ func New(config Config) (API, error) {

// Downloads full object with no ranges, if you need ranges use GetPartialObject
func (a apiV2) GetObject(bucket, object string) (io.ReadCloser, ObjectStat, error) {
if err := invalidBucketToError(bucket); err != nil {
if err := invalidBucketError(bucket); err != nil {
return nil, ObjectStat{}, err
}
if err := invalidObjectToError(object); err != nil {
if err := invalidObjectError(object); err != nil {
return nil, ObjectStat{}, err
}
// get object
Expand All @@ -228,10 +228,10 @@ func (a apiV2) GetObject(bucket, object string) (io.ReadCloser, ObjectStat, erro
// Setting offset and length = 0 will download the full object.
// For more information about the HTTP Range header, go to http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.35.
func (a apiV2) GetPartialObject(bucket, object string, offset, length int64) (io.ReadCloser, ObjectStat, error) {
if err := invalidBucketToError(bucket); err != nil {
if err := invalidBucketError(bucket); err != nil {
return nil, ObjectStat{}, err
}
if err := invalidObjectToError(object); err != nil {
if err := invalidObjectError(object); err != nil {
return nil, ObjectStat{}, err
}
// get partial object
Expand Down Expand Up @@ -468,10 +468,10 @@ func (a apiV2) listMultipartUploadsRecursiveInRoutine(bucket, object string, ch
//
// This version of PutObject automatically does multipart for more than 5MB worth of data
func (a apiV2) PutObject(bucket, object, contentType string, size int64, data io.Reader) error {
if err := invalidBucketToError(bucket); err != nil {
if err := invalidBucketError(bucket); err != nil {
return err
}
if err := invalidArgumentToError(object); err != nil {
if err := invalidArgumentError(object); err != nil {
return err
}
switch {
Expand Down Expand Up @@ -516,21 +516,21 @@ func (a apiV2) PutObject(bucket, object, contentType string, size int64, data io

// StatObject verify if object exists and you have permission to access it
func (a apiV2) StatObject(bucket, object string) (ObjectStat, error) {
if err := invalidBucketToError(bucket); err != nil {
if err := invalidBucketError(bucket); err != nil {
return ObjectStat{}, err
}
if err := invalidObjectToError(object); err != nil {
if err := invalidObjectError(object); err != nil {
return ObjectStat{}, err
}
return a.headObject(bucket, object)
}

// RemoveObject remove the object from a bucket
func (a apiV2) RemoveObject(bucket, object string) error {
if err := invalidBucketToError(bucket); err != nil {
if err := invalidBucketError(bucket); err != nil {
return err
}
if err := invalidObjectToError(object); err != nil {
if err := invalidObjectError(object); err != nil {
return err
}
return a.deleteObject(bucket, object)
Expand All @@ -556,11 +556,11 @@ func (a apiV2) RemoveObject(bucket, object string) error {
// [ us-west-1 | us-west-2 | eu-west-1 | eu-central-1 | ap-southeast-1 | ap-northeast-1 | ap-southeast-2 | sa-east-1 ]
// Default - US standard
func (a apiV2) MakeBucket(bucket string, acl BucketACL) error {
if err := invalidBucketToError(bucket); err != nil {
if err := invalidBucketError(bucket); err != nil {
return err
}
if !acl.isValidBucketACL() {
return invalidArgumentToError("")
return invalidArgumentError("")
}
location, _ := getRegion(a.config.Endpoint)
if location == "milkyway" {
Expand All @@ -582,11 +582,11 @@ func (a apiV2) MakeBucket(bucket string, acl BucketACL) error {
// authenticated-read - owner gets full access, authenticated users get read access
//
func (a apiV2) SetBucketACL(bucket string, acl BucketACL) error {
if err := invalidBucketToError(bucket); err != nil {
if err := invalidBucketError(bucket); err != nil {
return err
}
if !acl.isValidBucketACL() {
return invalidArgumentToError("")
return invalidArgumentError("")
}
return a.putBucketACL(bucket, string(acl))
}
Expand All @@ -601,7 +601,7 @@ func (a apiV2) SetBucketACL(bucket string, acl BucketACL) error {
// authenticated-read - owner gets full access, authenticated users get read access
//
func (a apiV2) GetBucketACL(bucket string) (BucketACL, error) {
if err := invalidBucketToError(bucket); err != nil {
if err := invalidBucketError(bucket); err != nil {
return "", err
}
policy, err := a.getBucketACL(bucket)
Expand Down Expand Up @@ -640,7 +640,7 @@ func (a apiV2) GetBucketACL(bucket string) (BucketACL, error) {

// BucketExists verify if bucket exists and you have permission to access it
func (a apiV2) BucketExists(bucket string) error {
if err := invalidBucketToError(bucket); err != nil {
if err := invalidBucketError(bucket); err != nil {
return err
}
return a.headBucket(bucket)
Expand All @@ -651,7 +651,7 @@ func (a apiV2) BucketExists(bucket string) error {
// All objects (including all object versions and delete markers)
// in the bucket must be deleted before successfully attempting this request
func (a apiV2) RemoveBucket(bucket string) error {
if err := invalidBucketToError(bucket); err != nil {
if err := invalidBucketError(bucket); err != nil {
return err
}
return a.deleteBucket(bucket)
Expand All @@ -661,7 +661,7 @@ func (a apiV2) RemoveBucket(bucket string) error {
// This function feeds data into channel
func (a apiV2) listObjectsInRoutine(bucket, prefix string, recursive bool, ch chan ObjectStatCh) {
defer close(ch)
if err := invalidBucketToError(bucket); err != nil {
if err := invalidBucketError(bucket); err != nil {
ch <- ObjectStatCh{
Stat: ObjectStat{},
Err: err,
Expand Down Expand Up @@ -787,11 +787,11 @@ func (a apiV2) ListBuckets() <-chan BucketStatCh {

func (a apiV2) dropIncompleteUploadsInRoutine(bucket, object string, errorCh chan error) {
defer close(errorCh)
if err := invalidBucketToError(bucket); err != nil {
if err := invalidBucketError(bucket); err != nil {
errorCh <- err
return
}
if err := invalidObjectToError(object); err != nil {
if err := invalidObjectError(object); err != nil {
errorCh <- err
return
}
Expand Down Expand Up @@ -843,7 +843,7 @@ func (a apiV2) DropIncompleteUploads(bucket, object string) <-chan error {

func (a apiV2) dropAllIncompleteUploadsInRoutine(bucket string, errorCh chan error) {
defer close(errorCh)
if err := invalidBucketToError(bucket); err != nil {
if err := invalidBucketError(bucket); err != nil {
errorCh <- err
return
}
Expand Down
2 changes: 1 addition & 1 deletion api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ func TestErrorResponse(t *testing.T) {
a := apiV1{&Config{}}
errorResponse := []byte("<?xml version=\"1.0\" encoding=\"UTF-8\"?><Error><Code>AccessDenied</Code><Message>Access Denied</Message><Resource>/mybucket/myphoto.jpg</Resource><RequestId>F19772218238A85A</RequestId><HostId>GuWkjyviSiGHizehqpmsD1ndz5NClSP19DOT+s2mv7gXGQ8/X1lhbDGiIJEXpGFD</HostId></Error>")
errorReader := bytes.NewReader(errorResponse)
err := a.responseToError(errorReader)
err := a.ToErrorResponseBody(errorReader)
if err == nil {
t.Fatal("Error")
}
Expand Down
21 changes: 11 additions & 10 deletions errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,19 +87,18 @@ func (e ErrorResponse) Error() string {
return e.Message
}

/// Internal function not exposed

// responseToError returns a new encoded ErrorResponse structure
func (a apiV1) responseToError(errBody io.Reader) error {
var respError ErrorResponse
err := acceptTypeDecoder(errBody, a.config.AcceptType, &respError)
// ToErrorResponseBody returns a new encoded ErrorResponse structure
func (a apiV1) ToErrorResponseBody(errBody io.Reader) error {
var errorResponse ErrorResponse
err := acceptTypeDecoder(errBody, a.config.AcceptType, &errorResponse)
if err != nil {
return err
}
return respError
return errorResponse
}

func invalidBucketToError(bucket string) error {
// invalidBucketToError - invalid bucket to errorResponse
func invalidBucketError(bucket string) error {
// verify bucket name in accordance with
// - http://docs.aws.amazon.com/AmazonS3/latest/dev/UsingBucket.html
isValidBucket := func(bucket string) bool {
Expand Down Expand Up @@ -129,7 +128,8 @@ func invalidBucketToError(bucket string) error {
return nil
}

func invalidObjectToError(object string) error {
// invalidObjectError invalid object name to errorResponse
func invalidObjectError(object string) error {
if strings.TrimSpace(object) == "" || object == "" {
// no resource since object name is empty
errorResponse := ErrorResponse{
Expand All @@ -142,7 +142,8 @@ func invalidObjectToError(object string) error {
return nil
}

func invalidArgumentToError(arg string) error {
// invalidArgumentError invalid argument to errorResponse
func invalidArgumentError(arg string) error {
errorResponse := ErrorResponse{
Code: "InvalidArgument",
Message: "Invalid Argument",
Expand Down
Loading