From d76070aeda5fb0b0f018fce450ead42594ad0796 Mon Sep 17 00:00:00 2001 From: Harshavardhana Date: Sat, 8 Aug 2015 23:43:35 -0700 Subject: [PATCH] Move to new changes in minio-go --- Godeps/Godeps.json | 8 +- .../github.com/dustin/go-humanize/bigbytes.go | 2 +- .../dustin/go-humanize/bigbytes_test.go | 4 +- .../github.com/dustin/go-humanize/bytes.go | 2 +- .../dustin/go-humanize/bytes_test.go | 6 +- .../github.com/dustin/go-humanize/comma.go | 2 +- .../minio/minio-go/api-multipart-v1.go | 10 +- .../src/github.com/minio/minio-go/api-v1.go | 18 +-- .../src/github.com/minio/minio-go/api-v2.go | 14 +- .../minio/minio-go/api_handlers_test.go | 2 +- .../minio/minio-go/api_private_test.go | 116 ++++++++++++++ .../{api_test.go => api_public_test.go} | 149 +++++++----------- .../src/github.com/minio/minio-go/chopper.go | 10 +- .../src/github.com/minio/minio-go/errors.go | 16 +- .../src/github.com/minio/minio-go/request.go | 8 +- .../_workspace/src/gopkg.in/check.v1/check.go | 2 +- 16 files changed, 226 insertions(+), 143 deletions(-) create mode 100644 Godeps/_workspace/src/github.com/minio/minio-go/api_private_test.go rename Godeps/_workspace/src/github.com/minio/minio-go/{api_test.go => api_public_test.go} (71%) diff --git a/Godeps/Godeps.json b/Godeps/Godeps.json index fd639a35..85a7885a 100644 --- a/Godeps/Godeps.json +++ b/Godeps/Godeps.json @@ -7,7 +7,7 @@ "Deps": [ { "ImportPath": "github.com/dustin/go-humanize", - "Rev": "c128122e0b9b93799aef8181a537e5d8fd7081d6" + "Rev": "00897f070f09f194c26d65afae734ba4c32404e8" }, { "ImportPath": "github.com/fatih/color", @@ -29,8 +29,8 @@ }, { "ImportPath": "github.com/minio/minio-go", - "Comment": "v0.2.0-21-gd9184e5", - "Rev": "d9184e5834efb7cd4a24df4d6ebab9b51dad4d9c" + "Comment": "v0.2.0-27-gd053903", + "Rev": "d053903f65055551c9327c3acf3b64b5f013cf9b" }, { "ImportPath": "github.com/minio/pb", @@ -51,7 +51,7 @@ }, { "ImportPath": "gopkg.in/check.v1", - "Rev": "b3d3430320d4260e5fea99841af984b3badcea63" + "Rev": "11d3bc7aa68e238947792f30573146a3231fc0f1" } ] } diff --git a/Godeps/_workspace/src/github.com/dustin/go-humanize/bigbytes.go b/Godeps/_workspace/src/github.com/dustin/go-humanize/bigbytes.go index e4a814a9..6876e92e 100644 --- a/Godeps/_workspace/src/github.com/dustin/go-humanize/bigbytes.go +++ b/Godeps/_workspace/src/github.com/dustin/go-humanize/bigbytes.go @@ -115,7 +115,7 @@ func humanateBigBytes(s, base *big.Int, sizes []string) string { // // BigBytes(82854982) -> 83MB func BigBytes(s *big.Int) string { - sizes := []string{"B", "kB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"} + sizes := []string{"B", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"} return humanateBigBytes(s, bigSIExp, sizes) } diff --git a/Godeps/_workspace/src/github.com/dustin/go-humanize/bigbytes_test.go b/Godeps/_workspace/src/github.com/dustin/go-humanize/bigbytes_test.go index da367d41..a0f977a6 100644 --- a/Godeps/_workspace/src/github.com/dustin/go-humanize/bigbytes_test.go +++ b/Godeps/_workspace/src/github.com/dustin/go-humanize/bigbytes_test.go @@ -86,8 +86,8 @@ func TestBigBytes(t *testing.T) { {"bytes(803)", bbyte(803), "803B"}, {"bytes(999)", bbyte(999), "999B"}, - {"bytes(1024)", bbyte(1024), "1.0kB"}, - {"bytes(1MB - 1)", bbyte(MByte - Byte), "1000kB"}, + {"bytes(1024)", bbyte(1024), "1.0KB"}, + {"bytes(1MB - 1)", bbyte(MByte - Byte), "1000KB"}, {"bytes(1MB)", bbyte(1024 * 1024), "1.0MB"}, {"bytes(1GB - 1K)", bbyte(GByte - KByte), "1000MB"}, diff --git a/Godeps/_workspace/src/github.com/dustin/go-humanize/bytes.go b/Godeps/_workspace/src/github.com/dustin/go-humanize/bytes.go index b7a77b52..4c4b5af1 100644 --- a/Godeps/_workspace/src/github.com/dustin/go-humanize/bytes.go +++ b/Godeps/_workspace/src/github.com/dustin/go-humanize/bytes.go @@ -86,7 +86,7 @@ func humanateBytes(s uint64, base float64, sizes []string) string { // // Bytes(82854982) -> 83MB func Bytes(s uint64) string { - sizes := []string{"B", "kB", "MB", "GB", "TB", "PB", "EB"} + sizes := []string{"B", "KB", "MB", "GB", "TB", "PB", "EB"} return humanateBytes(s, 1000, sizes) } diff --git a/Godeps/_workspace/src/github.com/dustin/go-humanize/bytes_test.go b/Godeps/_workspace/src/github.com/dustin/go-humanize/bytes_test.go index 7497fa00..76a594c1 100644 --- a/Godeps/_workspace/src/github.com/dustin/go-humanize/bytes_test.go +++ b/Godeps/_workspace/src/github.com/dustin/go-humanize/bytes_test.go @@ -80,9 +80,9 @@ func TestBytes(t *testing.T) { {"bytes(803)", Bytes(803), "803B"}, {"bytes(999)", Bytes(999), "999B"}, - {"bytes(1024)", Bytes(1024), "1.0kB"}, - {"bytes(9999)", Bytes(9999), "10kB"}, - {"bytes(1MB - 1)", Bytes(MByte - Byte), "1000kB"}, + {"bytes(1024)", Bytes(1024), "1.0KB"}, + {"bytes(9999)", Bytes(9999), "10KB"}, + {"bytes(1MB - 1)", Bytes(MByte - Byte), "1000KB"}, {"bytes(1MB)", Bytes(1024 * 1024), "1.0MB"}, {"bytes(1GB - 1K)", Bytes(GByte - KByte), "1000MB"}, diff --git a/Godeps/_workspace/src/github.com/dustin/go-humanize/comma.go b/Godeps/_workspace/src/github.com/dustin/go-humanize/comma.go index 20711c15..9d0d2ed1 100644 --- a/Godeps/_workspace/src/github.com/dustin/go-humanize/comma.go +++ b/Godeps/_workspace/src/github.com/dustin/go-humanize/comma.go @@ -18,7 +18,7 @@ func Comma(v int64) string { v = 0 - v } - parts := []string{"", "", "", "", "", "", ""} + parts := []string{"", "", "", "", "", "", "", ""} j := len(parts) - 1 for v > 999 { diff --git a/Godeps/_workspace/src/github.com/minio/minio-go/api-multipart-v1.go b/Godeps/_workspace/src/github.com/minio/minio-go/api-multipart-v1.go index 93454235..72a7ea71 100644 --- a/Godeps/_workspace/src/github.com/minio/minio-go/api-multipart-v1.go +++ b/Godeps/_workspace/src/github.com/minio/minio-go/api-multipart-v1.go @@ -103,7 +103,7 @@ func (a apiV1) listMultipartUploads(bucket, keymarker, uploadIDMarker, prefix, d } if resp != nil { if resp.StatusCode != http.StatusOK { - return listMultipartUploadsResult{}, a.ToErrorResponseBody(resp.Body) + return listMultipartUploadsResult{}, BodyToErrorResponse(resp.Body, a.config.AcceptType) } } listMultipartUploadsResult := listMultipartUploadsResult{} @@ -142,7 +142,7 @@ func (a apiV1) initiateMultipartUpload(bucket, object string) (initiateMultipart } if resp != nil { if resp.StatusCode != http.StatusOK { - return initiateMultipartUploadResult{}, a.ToErrorResponseBody(resp.Body) + return initiateMultipartUploadResult{}, BodyToErrorResponse(resp.Body, a.config.AcceptType) } } initiateMultipartUploadResult := initiateMultipartUploadResult{} @@ -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.ToErrorResponseBody(resp.Body) + return completeMultipartUploadResult{}, BodyToErrorResponse(resp.Body, a.config.AcceptType) } } completeMultipartUploadResult := completeMultipartUploadResult{} @@ -308,7 +308,7 @@ func (a apiV1) listObjectParts(bucket, object, uploadID string, partNumberMarker } if resp != nil { if resp.StatusCode != http.StatusOK { - return listObjectPartsResult{}, a.ToErrorResponseBody(resp.Body) + return listObjectPartsResult{}, BodyToErrorResponse(resp.Body, a.config.AcceptType) } } listObjectPartsResult := listObjectPartsResult{} @@ -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.ToErrorResponseBody(resp.Body) + return completePart{}, BodyToErrorResponse(resp.Body, a.config.AcceptType) } } return cPart, nil diff --git a/Godeps/_workspace/src/github.com/minio/minio-go/api-v1.go b/Godeps/_workspace/src/github.com/minio/minio-go/api-v1.go index d250a7fe..5b5f6324 100644 --- a/Godeps/_workspace/src/github.com/minio/minio-go/api-v1.go +++ b/Godeps/_workspace/src/github.com/minio/minio-go/api-v1.go @@ -134,7 +134,7 @@ func (a apiV1) putBucket(bucket, acl, location string) error { } if resp != nil { if resp.StatusCode != http.StatusOK { - return a.ToErrorResponseBody(resp.Body) + return BodyToErrorResponse(resp.Body, a.config.AcceptType) } } return nil @@ -168,7 +168,7 @@ func (a apiV1) putBucketACL(bucket, acl string) error { } if resp != nil { if resp.StatusCode != http.StatusOK { - return a.ToErrorResponseBody(resp.Body) + return BodyToErrorResponse(resp.Body, a.config.AcceptType) } } return nil @@ -201,7 +201,7 @@ func (a apiV1) getBucketACL(bucket string) (accessControlPolicy, error) { } if resp != nil { if resp.StatusCode != http.StatusOK { - return accessControlPolicy{}, a.ToErrorResponseBody(resp.Body) + return accessControlPolicy{}, BodyToErrorResponse(resp.Body, a.config.AcceptType) } } policy := accessControlPolicy{} @@ -249,7 +249,7 @@ func (a apiV1) getBucketLocation(bucket string) (string, error) { } if resp != nil { if resp.StatusCode != http.StatusOK { - return "", a.ToErrorResponseBody(resp.Body) + return "", BodyToErrorResponse(resp.Body, a.config.AcceptType) } } var locationConstraint string @@ -332,7 +332,7 @@ func (a apiV1) listObjects(bucket, marker, prefix, delimiter string, maxkeys int } if resp != nil { if resp.StatusCode != http.StatusOK { - return listBucketResult{}, a.ToErrorResponseBody(resp.Body) + return listBucketResult{}, BodyToErrorResponse(resp.Body, a.config.AcceptType) } } listBucketResult := listBucketResult{} @@ -508,7 +508,7 @@ func (a apiV1) putObject(bucket, object, contentType string, md5SumBytes []byte, } if resp != nil { if resp.StatusCode != http.StatusOK { - return ObjectStat{}, a.ToErrorResponseBody(resp.Body) + return ObjectStat{}, BodyToErrorResponse(resp.Body, a.config.AcceptType) } } var metadata ObjectStat @@ -557,7 +557,7 @@ func (a apiV1) presignedGetObject(bucket, object string, expires, offset, length if err != nil { return "", err } - return req.PreSignV4(), nil + return req.PreSignV4() } // getObjectRequest wrapper creates a new getObject request @@ -609,7 +609,7 @@ func (a apiV1) getObject(bucket, object string, offset, length int64) (io.ReadCl case http.StatusOK: case http.StatusPartialContent: default: - return nil, ObjectStat{}, a.ToErrorResponseBody(resp.Body) + return nil, ObjectStat{}, BodyToErrorResponse(resp.Body, a.config.AcceptType) } } md5sum := strings.Trim(resp.Header.Get("ETag"), "\"") // trim off the odd double quotes @@ -850,7 +850,7 @@ func (a apiV1) listBuckets() (listAllMyBucketsResult, error) { } } if resp.StatusCode != http.StatusOK { - return listAllMyBucketsResult{}, a.ToErrorResponseBody(resp.Body) + return listAllMyBucketsResult{}, BodyToErrorResponse(resp.Body, a.config.AcceptType) } } listAllMyBucketsResult := listAllMyBucketsResult{} diff --git a/Godeps/_workspace/src/github.com/minio/minio-go/api-v2.go b/Godeps/_workspace/src/github.com/minio/minio-go/api-v2.go index d37d3302..c5b765ac 100644 --- a/Godeps/_workspace/src/github.com/minio/minio-go/api-v2.go +++ b/Godeps/_workspace/src/github.com/minio/minio-go/api-v2.go @@ -336,7 +336,7 @@ func (a apiV2) newObjectUpload(bucket, object, contentType string, size int64, d } } } - completePart, err := a.uploadPart(bucket, object, uploadID, part.Md5Sum, part.Num, part.Len, part.ReadSeeker) + completePart, err := a.uploadPart(bucket, object, uploadID, part.MD5Sum, part.Num, part.Len, part.ReadSeeker) if err != nil { return err } @@ -357,7 +357,7 @@ type partCh struct { } func (a apiV2) listObjectPartsRecursive(bucket, object, uploadID string) <-chan partCh { - partCh := make(chan partCh) + partCh := make(chan partCh, 1000) go a.listObjectPartsRecursiveInRoutine(bucket, object, uploadID, partCh) return partCh } @@ -433,7 +433,7 @@ func (a apiV2) continueObjectUpload(bucket, object, uploadID string, size int64, } } } - completedPart, err := a.uploadPart(bucket, object, uploadID, part.Md5Sum, part.Num, part.Len, part.ReadSeeker) + completedPart, err := a.uploadPart(bucket, object, uploadID, part.MD5Sum, part.Num, part.Len, part.ReadSeeker) if err != nil { return err } @@ -453,7 +453,7 @@ type multiPartUploadCh struct { } func (a apiV2) listMultipartUploadsRecursive(bucket, object string) <-chan multiPartUploadCh { - ch := make(chan multiPartUploadCh) + ch := make(chan multiPartUploadCh, 1000) go a.listMultipartUploadsRecursiveInRoutine(bucket, object, ch) return ch } @@ -521,7 +521,7 @@ func (a apiV2) PutObject(bucket, object, contentType string, size int64, data io Message: "IncompleteBody", } } - _, err := a.putObject(bucket, object, contentType, part.Md5Sum, part.Len, part.ReadSeeker) + _, err := a.putObject(bucket, object, contentType, part.MD5Sum, part.Len, part.ReadSeeker) if err != nil { return err } @@ -775,7 +775,7 @@ func (a apiV2) listObjectsInRoutine(bucket, prefix string, recursive bool, ch ch // } // func (a apiV2) ListObjects(bucket string, prefix string, recursive bool) <-chan ObjectStatCh { - ch := make(chan ObjectStatCh) + ch := make(chan ObjectStatCh, 1000) go a.listObjectsInRoutine(bucket, prefix, recursive, ch) return ch } @@ -814,7 +814,7 @@ func (a apiV2) listBucketsInRoutine(ch chan BucketStatCh) { // } // func (a apiV2) ListBuckets() <-chan BucketStatCh { - ch := make(chan BucketStatCh) + ch := make(chan BucketStatCh, 100) go a.listBucketsInRoutine(ch) return ch } diff --git a/Godeps/_workspace/src/github.com/minio/minio-go/api_handlers_test.go b/Godeps/_workspace/src/github.com/minio/minio-go/api_handlers_test.go index 45977f19..45b432ce 100644 --- a/Godeps/_workspace/src/github.com/minio/minio-go/api_handlers_test.go +++ b/Godeps/_workspace/src/github.com/minio/minio-go/api_handlers_test.go @@ -14,7 +14,7 @@ * limitations under the License. */ -package minio +package minio_test // bucketHandler is an http.Handler that verifies bucket responses and validates incoming requests import ( diff --git a/Godeps/_workspace/src/github.com/minio/minio-go/api_private_test.go b/Godeps/_workspace/src/github.com/minio/minio-go/api_private_test.go new file mode 100644 index 00000000..b79a48cf --- /dev/null +++ b/Godeps/_workspace/src/github.com/minio/minio-go/api_private_test.go @@ -0,0 +1,116 @@ +/* + * Minio Go Library for Amazon S3 compatible cloud storage (C) 2015 Minio, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package minio + +import ( + "strings" + "testing" +) + +func TestACLTypes(t *testing.T) { + want := map[string]bool{ + "private": true, + "public-read": true, + "public-read-write": true, + "authenticated-read": true, + "invalid": false, + } + for acl, ok := range want { + if BucketACL(acl).isValidBucketACL() != ok { + t.Fatal("Error") + } + } +} + +func TestUserAgent(t *testing.T) { + conf := new(Config) + conf.SetUserAgent("minio", "1.0", "amd64") + if !strings.Contains(conf.userAgent, "minio") { + t.Fatalf("Error") + } +} + +func TestGetRegion(t *testing.T) { + region, err := getRegion("s3.amazonaws.com") + if err != nil { + t.Fatalf("Error") + } + if region != "us-east-1" { + t.Fatalf("Error") + } + region, err = getRegion("localhost:9000") + if err != nil { + t.Fatalf("Error") + } + if region != "milkyway" { + t.Fatalf("Error") + } +} + +func TestPartSize(t *testing.T) { + var maxPartSize int64 = 1024 * 1024 * 1024 * 5 + partSize := getPartSize(5000000000000000000) + if partSize > minimumPartSize { + if partSize > maxPartSize { + t.Fatal("invalid result, cannot be bigger than maxPartSize 5GB") + } + } + partSize = getPartSize(50000000000) + if partSize > minimumPartSize { + t.Fatal("invalid result, cannot be bigger than minimumPartSize 5MB") + } +} + +func TestURLEncoding(t *testing.T) { + type urlStrings struct { + name string + encodedName string + } + + want := []urlStrings{ + { + name: "bigfile-1._%", + encodedName: "bigfile-1._%25", + }, + { + name: "本語", + encodedName: "%E6%9C%AC%E8%AA%9E", + }, + { + name: "本語.1", + encodedName: "%E6%9C%AC%E8%AA%9E.1", + }, + { + name: ">123>3123123", + encodedName: "%3E123%3E3123123", + }, + { + name: "test 1 2.txt", + encodedName: "test%201%202.txt", + }, + } + + for _, u := range want { + encodedName, err := urlEncodeName(u.name) + if err != nil { + t.Fatalf("Error") + } + if u.encodedName != encodedName { + t.Errorf("Error") + } + } +} diff --git a/Godeps/_workspace/src/github.com/minio/minio-go/api_test.go b/Godeps/_workspace/src/github.com/minio/minio-go/api_public_test.go similarity index 71% rename from Godeps/_workspace/src/github.com/minio/minio-go/api_test.go rename to Godeps/_workspace/src/github.com/minio/minio-go/api_public_test.go index 22e4a54b..cc12eff5 100644 --- a/Godeps/_workspace/src/github.com/minio/minio-go/api_test.go +++ b/Godeps/_workspace/src/github.com/minio/minio-go/api_public_test.go @@ -14,56 +14,18 @@ * limitations under the License. */ -package minio +package minio_test import ( "bytes" "io" "net/http/httptest" - "strings" "testing" + "time" + + "github.com/minio/minio-go" ) -func TestACLTypes(t *testing.T) { - want := map[string]bool{ - "private": true, - "public-read": true, - "public-read-write": true, - "authenticated-read": true, - "invalid": false, - } - for acl, ok := range want { - if BucketACL(acl).isValidBucketACL() != ok { - t.Fatal("Error") - } - } -} - -func TestGetRegion(t *testing.T) { - region, err := getRegion("s3.amazonaws.com") - if err != nil { - t.Fatalf("Error") - } - if region != "us-east-1" { - t.Fatalf("Error") - } - region, err = getRegion("localhost:9000") - if err != nil { - t.Fatalf("Error") - } - if region != "milkyway" { - t.Fatalf("Error") - } -} - -func TestUserAgent(t *testing.T) { - conf := new(Config) - conf.SetUserAgent("minio", "1.0", "amd64") - if !strings.Contains(conf.userAgent, "minio") { - t.Fatalf("Error") - } -} - func TestBucketOperations(t *testing.T) { bucket := bucketHandler(bucketHandler{ resource: "/bucket", @@ -71,7 +33,7 @@ func TestBucketOperations(t *testing.T) { server := httptest.NewServer(bucket) defer server.Close() - a, err := New(Config{Endpoint: server.URL}) + a, err := minio.New(minio.Config{Endpoint: server.URL}) if err != nil { t.Errorf("Error") } @@ -102,7 +64,7 @@ func TestBucketOperations(t *testing.T) { if err != nil { t.Errorf("Error") } - if !acl.isPrivate() { + if acl != minio.BucketACL("private") { t.Fatalf("Error") } @@ -145,7 +107,7 @@ func TestBucketOperationsFail(t *testing.T) { server := httptest.NewServer(bucket) defer server.Close() - a, err := New(Config{Endpoint: server.URL}) + a, err := minio.New(minio.Config{Endpoint: server.URL}) if err != nil { t.Errorf("Error") } @@ -193,7 +155,7 @@ func TestObjectOperations(t *testing.T) { server := httptest.NewServer(object) defer server.Close() - a, err := New(Config{Endpoint: server.URL}) + a, err := minio.New(minio.Config{Endpoint: server.URL}) if err != nil { t.Fatalf("Error") } @@ -243,72 +205,67 @@ func TestObjectOperations(t *testing.T) { } } -func TestPartSize(t *testing.T) { - var maxPartSize int64 = 1024 * 1024 * 1024 * 5 - partSize := getPartSize(5000000000000000000) - if partSize > minimumPartSize { - if partSize > maxPartSize { - t.Fatal("invalid result, cannot be bigger than maxPartSize 5GB") - } - } - partSize = getPartSize(50000000000) - if partSize > minimumPartSize { - t.Fatal("invalid result, cannot be bigger than minimumPartSize 5MB") - } -} +func TestPresignedURL(t *testing.T) { + object := objectHandler(objectHandler{ + resource: "/bucket/object", + data: []byte("Hello, World"), + }) + server := httptest.NewServer(object) + defer server.Close() -func TestURLEncoding(t *testing.T) { - type urlStrings struct { - name string - encodedName string + a, err := minio.New(minio.Config{Endpoint: server.URL}) + if err != nil { + t.Fatalf("Error") + } + // should error out for invalid access keys + _, err = a.PresignedGetObject("bucket", "object", time.Duration(1000)*time.Second) + if err == nil { + t.Fatalf("Error") } - want := []urlStrings{ - { - name: "bigfile-1._%", - encodedName: "bigfile-1._%25", - }, - { - name: "本語", - encodedName: "%E6%9C%AC%E8%AA%9E", - }, - { - name: "本b語.1", - encodedName: "%E6%9C%ACb%E8%AA%9E.1", - }, - { - name: ">123>3123123", - encodedName: "%3E123%3E3123123", - }, - { - name: "test 1 2.txt", - encodedName: "test%201%202.txt", - }, + a, err = minio.New(minio.Config{ + Endpoint: server.URL, + AccessKeyID: "accessKey", + SecretAccessKey: "secretKey", + }) + if err != nil { + t.Fatalf("Error") } - - for _, u := range want { - encodedName, err := urlEncodeName(u.name) - if err != nil { - t.Fatalf("Error") - } - if u.encodedName != encodedName { - t.Errorf("Error") - } + url, err := a.PresignedGetObject("bucket", "object", time.Duration(1000)*time.Second) + if err != nil { + t.Fatalf("Error") + } + if url == "" { + t.Fatalf("Error") + } + url, err = a.PresignedGetPartialObject("bucket", "object", time.Duration(1000)*time.Second, 5, 11) + if err != nil { + t.Fatalf("Error") + } + if url == "" { + t.Fatalf("Error") + } + _, err = a.PresignedGetObject("bucket", "object", time.Duration(0)*time.Second) + if err == nil { + t.Fatalf("Error") + } + _, err = a.PresignedGetObject("bucket", "object", time.Duration(604801)*time.Second) + if err == nil { + t.Fatalf("Error") } } func TestErrorResponse(t *testing.T) { - a := apiV1{&Config{}} errorResponse := []byte("AccessDeniedAccess Denied/mybucket/myphoto.jpgF19772218238A85AGuWkjyviSiGHizehqpmsD1ndz5NClSP19DOT+s2mv7gXGQ8/X1lhbDGiIJEXpGFD") errorReader := bytes.NewReader(errorResponse) - err := a.ToErrorResponseBody(errorReader) + err := minio.BodyToErrorResponse(errorReader, "application/xml") if err == nil { t.Fatal("Error") } if err.Error() != "Access Denied" { t.Fatal("Error") } - resp := ToErrorResponse(err) + resp := minio.ToErrorResponse(err) // valid all fields if resp == nil { t.Fatal("Error") diff --git a/Godeps/_workspace/src/github.com/minio/minio-go/chopper.go b/Godeps/_workspace/src/github.com/minio/minio-go/chopper.go index bf4317d0..02b0792d 100644 --- a/Godeps/_workspace/src/github.com/minio/minio-go/chopper.go +++ b/Godeps/_workspace/src/github.com/minio/minio-go/chopper.go @@ -24,7 +24,7 @@ import ( // part - message structure for results from the MultiPart type part struct { - Md5Sum []byte + MD5Sum []byte ReadSeeker io.ReadSeeker Err error Len int64 @@ -46,7 +46,7 @@ type skipPart struct { // // additionally this function also skips list of parts if provided func chopper(reader io.Reader, chunkSize int64, skipParts []skipPart) <-chan part { - ch := make(chan part) + ch := make(chan part, 3) go chopperInRoutine(reader, chunkSize, skipParts, ch) return ch } @@ -58,7 +58,7 @@ func chopperInRoutine(reader io.Reader, chunkSize int64, skipParts []skipPart, c if err == io.EOF || err == io.ErrUnexpectedEOF { // short read, only single part return m := md5.Sum(p[0:n]) ch <- part{ - Md5Sum: m[:], + MD5Sum: m[:], ReadSeeker: bytes.NewReader(p[0:n]), Err: nil, Len: int64(n), @@ -84,7 +84,7 @@ func chopperInRoutine(reader io.Reader, chunkSize int64, skipParts []skipPart, c } if !isPartNumberUploaded(sp, skipParts) { ch <- part{ - Md5Sum: md5SumBytes[:], + MD5Sum: md5SumBytes[:], ReadSeeker: bytes.NewReader(p), Err: nil, Len: int64(n), @@ -115,7 +115,7 @@ func chopperInRoutine(reader io.Reader, chunkSize int64, skipParts []skipPart, c continue } ch <- part{ - Md5Sum: md5SumBytes[:], + MD5Sum: md5SumBytes[:], ReadSeeker: bytes.NewReader(p[0:n]), Err: nil, Len: int64(n), diff --git a/Godeps/_workspace/src/github.com/minio/minio-go/errors.go b/Godeps/_workspace/src/github.com/minio/minio-go/errors.go index 6142b436..ead4e252 100644 --- a/Godeps/_workspace/src/github.com/minio/minio-go/errors.go +++ b/Godeps/_workspace/src/github.com/minio/minio-go/errors.go @@ -72,13 +72,19 @@ func ToErrorResponse(err error) *ErrorResponse { // ToXML send raw xml marshalled as string func (e ErrorResponse) ToXML() string { - b, _ := xml.Marshal(&e) + b, err := xml.Marshal(&e) + if err != nil { + panic(err) + } return string(b) } // ToJSON send raw json marshalled as string func (e ErrorResponse) ToJSON() string { - b, _ := json.Marshal(&e) + b, err := json.Marshal(&e) + if err != nil { + panic(err) + } return string(b) } @@ -87,10 +93,10 @@ func (e ErrorResponse) Error() string { return e.Message } -// ToErrorResponseBody returns a new encoded ErrorResponse structure -func (a apiV1) ToErrorResponseBody(errBody io.Reader) error { +// BodyToErrorResponse returns a new encoded ErrorResponse structure +func BodyToErrorResponse(errBody io.Reader, acceptType string) error { var errorResponse ErrorResponse - err := acceptTypeDecoder(errBody, a.config.AcceptType, &errorResponse) + err := acceptTypeDecoder(errBody, acceptType, &errorResponse) if err != nil { return err } diff --git a/Godeps/_workspace/src/github.com/minio/minio-go/request.go b/Godeps/_workspace/src/github.com/minio/minio-go/request.go index ef6dfd74..0e8ea21d 100644 --- a/Godeps/_workspace/src/github.com/minio/minio-go/request.go +++ b/Godeps/_workspace/src/github.com/minio/minio-go/request.go @@ -19,6 +19,7 @@ package minio import ( "bytes" "encoding/hex" + "errors" "io" "io/ioutil" "net/http" @@ -433,9 +434,12 @@ func (r *request) getSignature(signingKey []byte, stringToSign string) string { } // Presign the request, in accordance with - http://docs.aws.amazon.com/AmazonS3/latest/API/sigv4-query-string-auth.html -func (r *request) PreSignV4() string { +func (r *request) PreSignV4() (string, error) { + if r.config.AccessKeyID == "" && r.config.SecretAccessKey == "" { + return "", errors.New("presign requires accesskey and secretkey") + } r.SignV4() - return r.req.URL.String() + return r.req.URL.String(), nil } // SignV4 the request before Do(), in accordance with - http://docs.aws.amazon.com/AmazonS3/latest/API/sig-v4-authenticating-requests.html diff --git a/Godeps/_workspace/src/gopkg.in/check.v1/check.go b/Godeps/_workspace/src/gopkg.in/check.v1/check.go index f302a053..c99392a2 100644 --- a/Godeps/_workspace/src/gopkg.in/check.v1/check.go +++ b/Godeps/_workspace/src/gopkg.in/check.v1/check.go @@ -335,7 +335,7 @@ func (c *C) logPanic(skip int, value interface{}) { if name == "Value.call" && strings.HasSuffix(path, valueGo) { continue } - if name == "call16" && strings.Contains(path, asmGo) { + if (name == "call16" || name == "call32") && strings.Contains(path, asmGo) { continue } c.logf("%s:%d\n in %s", nicePath(file), line, name)