Merge pull request #1583 from harshavardhana/make-bucket
re-vendorize minio-go with new URL handling changes
This commit is contained in:
+7
-12
@@ -91,19 +91,14 @@ func (c Client) makeBucketRequest(bucketName string, acl BucketACL, location str
|
||||
return nil, ErrInvalidArgument("Unrecognized ACL " + acl.String())
|
||||
}
|
||||
|
||||
// Set get bucket location always as path style.
|
||||
// In case of Amazon S3. The make bucket issued on already
|
||||
// existing bucket would fail with 'AuthorizationMalformed' error
|
||||
// if virtual style is used. So we default to 'path style' as that
|
||||
// is the preferred method here. The final location of the
|
||||
// 'bucket' is provided through XML LocationConstraint data with
|
||||
// the request.
|
||||
targetURL := *c.endpointURL
|
||||
if bucketName != "" {
|
||||
// If endpoint supports virtual host style use that always.
|
||||
// Currently only S3 and Google Cloud Storage would support this.
|
||||
if isVirtualHostSupported(c.endpointURL, bucketName) {
|
||||
targetURL.Host = bucketName + "." + c.endpointURL.Host
|
||||
targetURL.Path = "/"
|
||||
} else {
|
||||
// If not fall back to using path style.
|
||||
targetURL.Path = "/" + bucketName + "/"
|
||||
}
|
||||
}
|
||||
targetURL.Path = "/" + bucketName + "/"
|
||||
|
||||
// get a new HTTP request for the method.
|
||||
req, err := http.NewRequest("PUT", targetURL.String(), nil)
|
||||
|
||||
+64
-17
@@ -31,6 +31,53 @@ import (
|
||||
"github.com/minio/minio-go"
|
||||
)
|
||||
|
||||
// Tests bucket re-create errors.
|
||||
func TestMakeBucketErrorV2(t *testing.T) {
|
||||
if testing.Short() {
|
||||
t.Skip("skipping functional tests for short runs")
|
||||
}
|
||||
|
||||
// Seed random based on current time.
|
||||
rand.Seed(time.Now().Unix())
|
||||
|
||||
// Instantiate new minio client object.
|
||||
c, err := minio.NewV2(
|
||||
"s3.amazonaws.com",
|
||||
os.Getenv("ACCESS_KEY"),
|
||||
os.Getenv("SECRET_KEY"),
|
||||
false,
|
||||
)
|
||||
if err != nil {
|
||||
t.Fatal("Error:", err)
|
||||
}
|
||||
|
||||
// Enable tracing, write to stderr.
|
||||
// c.TraceOn(os.Stderr)
|
||||
|
||||
// Set user agent.
|
||||
c.SetAppInfo("Minio-go-FunctionalTest", "0.1.0")
|
||||
|
||||
// Generate a new random bucket name.
|
||||
bucketName := randString(60, rand.NewSource(time.Now().UnixNano()))
|
||||
|
||||
// Make a new bucket in 'eu-west-1'.
|
||||
if err = c.MakeBucket(bucketName, "private", "eu-west-1"); err != nil {
|
||||
t.Fatal("Error:", err, bucketName)
|
||||
}
|
||||
if err = c.MakeBucket(bucketName, "private", "eu-west-1"); err == nil {
|
||||
t.Fatal("Error: make bucket should should fail for", bucketName)
|
||||
}
|
||||
// Verify valid error response from server.
|
||||
if minio.ToErrorResponse(err).Code != "BucketAlreadyExists" &&
|
||||
minio.ToErrorResponse(err).Code != "BucketAlreadyOwnedByYou" {
|
||||
t.Fatal("Error: Invalid error returned by server", err)
|
||||
}
|
||||
if err = c.RemoveBucket(bucketName); err != nil {
|
||||
t.Fatal("Error:", err, bucketName)
|
||||
}
|
||||
}
|
||||
|
||||
// Test get object reader to not throw error on being closed twice.
|
||||
func TestGetObjectClosedTwiceV2(t *testing.T) {
|
||||
if testing.Short() {
|
||||
t.Skip("skipping functional tests for short runs")
|
||||
@@ -39,8 +86,8 @@ func TestGetObjectClosedTwiceV2(t *testing.T) {
|
||||
// Seed random based on current time.
|
||||
rand.Seed(time.Now().Unix())
|
||||
|
||||
// Connect and make sure bucket exists.
|
||||
c, err := minio.New(
|
||||
// Instantiate new minio client object.
|
||||
c, err := minio.NewV2(
|
||||
"s3.amazonaws.com",
|
||||
os.Getenv("ACCESS_KEY"),
|
||||
os.Getenv("SECRET_KEY"),
|
||||
@@ -124,7 +171,7 @@ func TestRemovePartiallyUploadedV2(t *testing.T) {
|
||||
// Seed random based on current time.
|
||||
rand.Seed(time.Now().Unix())
|
||||
|
||||
// Connect and make sure bucket exists.
|
||||
// Instantiate new minio client object.
|
||||
c, err := minio.NewV2(
|
||||
"s3.amazonaws.com",
|
||||
os.Getenv("ACCESS_KEY"),
|
||||
@@ -191,8 +238,8 @@ func TestResumbalePutObjectV2(t *testing.T) {
|
||||
// Seed random based on current time.
|
||||
rand.Seed(time.Now().Unix())
|
||||
|
||||
// Connect and make sure bucket exists.
|
||||
c, err := minio.New(
|
||||
// Instantiate new minio client object.
|
||||
c, err := minio.NewV2(
|
||||
"s3.amazonaws.com",
|
||||
os.Getenv("ACCESS_KEY"),
|
||||
os.Getenv("SECRET_KEY"),
|
||||
@@ -302,8 +349,8 @@ func TestResumableFPutObjectV2(t *testing.T) {
|
||||
// Seed random based on current time.
|
||||
rand.Seed(time.Now().Unix())
|
||||
|
||||
// Connect and make sure bucket exists.
|
||||
c, err := minio.New(
|
||||
// Instantiate new minio client object.
|
||||
c, err := minio.NewV2(
|
||||
"s3.amazonaws.com",
|
||||
os.Getenv("ACCESS_KEY"),
|
||||
os.Getenv("SECRET_KEY"),
|
||||
@@ -379,8 +426,8 @@ func TestMakeBucketRegionsV2(t *testing.T) {
|
||||
// Seed random based on current time.
|
||||
rand.Seed(time.Now().Unix())
|
||||
|
||||
// Connect and make sure bucket exists.
|
||||
c, err := minio.New(
|
||||
// Instantiate new minio client object.
|
||||
c, err := minio.NewV2(
|
||||
"s3.amazonaws.com",
|
||||
os.Getenv("ACCESS_KEY"),
|
||||
os.Getenv("SECRET_KEY"),
|
||||
@@ -400,7 +447,7 @@ func TestMakeBucketRegionsV2(t *testing.T) {
|
||||
bucketName := randString(60, rand.NewSource(time.Now().UnixNano()))
|
||||
|
||||
// Make a new bucket in 'eu-central-1'.
|
||||
if err = c.MakeBucket(bucketName, "private", "eu-central-1"); err != nil {
|
||||
if err = c.MakeBucket(bucketName, "private", "eu-west-1"); err != nil {
|
||||
t.Fatal("Error:", err, bucketName)
|
||||
}
|
||||
|
||||
@@ -430,8 +477,8 @@ func TestResumablePutObjectV2(t *testing.T) {
|
||||
// Seed random based on current time.
|
||||
rand.Seed(time.Now().Unix())
|
||||
|
||||
// Connect and make sure bucket exists.
|
||||
c, err := minio.New(
|
||||
// Instantiate new minio client object.
|
||||
c, err := minio.NewV2(
|
||||
"s3.amazonaws.com",
|
||||
os.Getenv("ACCESS_KEY"),
|
||||
os.Getenv("SECRET_KEY"),
|
||||
@@ -494,8 +541,8 @@ func TestGetObjectReadSeekFunctionalV2(t *testing.T) {
|
||||
// Seed random based on current time.
|
||||
rand.Seed(time.Now().Unix())
|
||||
|
||||
// Connect and make sure bucket exists.
|
||||
c, err := minio.New(
|
||||
// Instantiate new minio client object.
|
||||
c, err := minio.NewV2(
|
||||
"s3.amazonaws.com",
|
||||
os.Getenv("ACCESS_KEY"),
|
||||
os.Getenv("SECRET_KEY"),
|
||||
@@ -608,8 +655,8 @@ func TestGetObjectReadAtFunctionalV2(t *testing.T) {
|
||||
// Seed random based on current time.
|
||||
rand.Seed(time.Now().Unix())
|
||||
|
||||
// Connect and make sure bucket exists.
|
||||
c, err := minio.New(
|
||||
// Instantiate new minio client object.
|
||||
c, err := minio.NewV2(
|
||||
"s3.amazonaws.com",
|
||||
os.Getenv("ACCESS_KEY"),
|
||||
os.Getenv("SECRET_KEY"),
|
||||
@@ -750,7 +797,7 @@ func TestFunctionalV2(t *testing.T) {
|
||||
// Seed random based on current time.
|
||||
rand.Seed(time.Now().Unix())
|
||||
|
||||
c, err := minio.New(
|
||||
c, err := minio.NewV2(
|
||||
"s3.amazonaws.com",
|
||||
os.Getenv("ACCESS_KEY"),
|
||||
os.Getenv("SECRET_KEY"),
|
||||
|
||||
+55
-9
@@ -55,6 +55,52 @@ func randString(n int, src rand.Source) string {
|
||||
return string(b[0:30])
|
||||
}
|
||||
|
||||
// Tests bucket re-create errors.
|
||||
func TestMakeBucketError(t *testing.T) {
|
||||
if testing.Short() {
|
||||
t.Skip("skipping functional tests for short runs")
|
||||
}
|
||||
|
||||
// Seed random based on current time.
|
||||
rand.Seed(time.Now().Unix())
|
||||
|
||||
// Instantiate new minio client object.
|
||||
c, err := minio.New(
|
||||
"s3.amazonaws.com",
|
||||
os.Getenv("ACCESS_KEY"),
|
||||
os.Getenv("SECRET_KEY"),
|
||||
false,
|
||||
)
|
||||
if err != nil {
|
||||
t.Fatal("Error:", err)
|
||||
}
|
||||
|
||||
// Enable tracing, write to stderr.
|
||||
// c.TraceOn(os.Stderr)
|
||||
|
||||
// Set user agent.
|
||||
c.SetAppInfo("Minio-go-FunctionalTest", "0.1.0")
|
||||
|
||||
// Generate a new random bucket name.
|
||||
bucketName := randString(60, rand.NewSource(time.Now().UnixNano()))
|
||||
|
||||
// Make a new bucket in 'eu-central-1'.
|
||||
if err = c.MakeBucket(bucketName, "private", "eu-central-1"); err != nil {
|
||||
t.Fatal("Error:", err, bucketName)
|
||||
}
|
||||
if err = c.MakeBucket(bucketName, "private", "eu-central-1"); err == nil {
|
||||
t.Fatal("Error: make bucket should should fail for", bucketName)
|
||||
}
|
||||
// Verify valid error response from server.
|
||||
if minio.ToErrorResponse(err).Code != "BucketAlreadyExists" &&
|
||||
minio.ToErrorResponse(err).Code != "BucketAlreadyOwnedByYou" {
|
||||
t.Fatal("Error: Invalid error returned by server", err)
|
||||
}
|
||||
if err = c.RemoveBucket(bucketName); err != nil {
|
||||
t.Fatal("Error:", err, bucketName)
|
||||
}
|
||||
}
|
||||
|
||||
// Tests various bucket supported formats.
|
||||
func TestMakeBucketRegions(t *testing.T) {
|
||||
if testing.Short() {
|
||||
@@ -64,7 +110,7 @@ func TestMakeBucketRegions(t *testing.T) {
|
||||
// Seed random based on current time.
|
||||
rand.Seed(time.Now().Unix())
|
||||
|
||||
// Connect and make sure bucket exists.
|
||||
// Instantiate new minio client object.
|
||||
c, err := minio.New(
|
||||
"s3.amazonaws.com",
|
||||
os.Getenv("ACCESS_KEY"),
|
||||
@@ -115,7 +161,7 @@ func TestGetObjectClosedTwice(t *testing.T) {
|
||||
// Seed random based on current time.
|
||||
rand.Seed(time.Now().Unix())
|
||||
|
||||
// Connect and make sure bucket exists.
|
||||
// Instantiate new minio client object.
|
||||
c, err := minio.New(
|
||||
"s3.amazonaws.com",
|
||||
os.Getenv("ACCESS_KEY"),
|
||||
@@ -200,7 +246,7 @@ func TestRemovePartiallyUploaded(t *testing.T) {
|
||||
// Seed random based on current time.
|
||||
rand.Seed(time.Now().Unix())
|
||||
|
||||
// Connect and make sure bucket exists.
|
||||
// Instantiate new minio client object.
|
||||
c, err := minio.New(
|
||||
"s3.amazonaws.com",
|
||||
os.Getenv("ACCESS_KEY"),
|
||||
@@ -236,7 +282,7 @@ func TestRemovePartiallyUploaded(t *testing.T) {
|
||||
}
|
||||
i++
|
||||
}
|
||||
err = writer.CloseWithError(errors.New("Proactively closed to be verified later."))
|
||||
err := writer.CloseWithError(errors.New("Proactively closed to be verified later."))
|
||||
if err != nil {
|
||||
t.Fatal("Error:", err)
|
||||
}
|
||||
@@ -270,7 +316,7 @@ func TestResumbalePutObject(t *testing.T) {
|
||||
// Seed random based on current time.
|
||||
rand.Seed(time.Now().Unix())
|
||||
|
||||
// Connect and make sure bucket exists.
|
||||
// Instantiate new minio client object.
|
||||
c, err := minio.New(
|
||||
"s3.amazonaws.com",
|
||||
os.Getenv("ACCESS_KEY"),
|
||||
@@ -380,7 +426,7 @@ func TestResumableFPutObject(t *testing.T) {
|
||||
// Seed random based on current time.
|
||||
rand.Seed(time.Now().Unix())
|
||||
|
||||
// Connect and make sure bucket exists.
|
||||
// Instantiate new minio client object.
|
||||
c, err := minio.New(
|
||||
"s3.amazonaws.com",
|
||||
os.Getenv("ACCESS_KEY"),
|
||||
@@ -460,7 +506,7 @@ func TestResumablePutObject(t *testing.T) {
|
||||
// Seed random based on current time.
|
||||
rand.Seed(time.Now().Unix())
|
||||
|
||||
// Connect and make sure bucket exists.
|
||||
// Instantiate new minio client object.
|
||||
c, err := minio.New(
|
||||
"s3.amazonaws.com",
|
||||
os.Getenv("ACCESS_KEY"),
|
||||
@@ -524,7 +570,7 @@ func TestGetObjectReadSeekFunctional(t *testing.T) {
|
||||
// Seed random based on current time.
|
||||
rand.Seed(time.Now().Unix())
|
||||
|
||||
// Connect and make sure bucket exists.
|
||||
// Instantiate new minio client object.
|
||||
c, err := minio.New(
|
||||
"s3.amazonaws.com",
|
||||
os.Getenv("ACCESS_KEY"),
|
||||
@@ -638,7 +684,7 @@ func TestGetObjectReadAtFunctional(t *testing.T) {
|
||||
// Seed random based on current time.
|
||||
rand.Seed(time.Now().Unix())
|
||||
|
||||
// Connect and make sure bucket exists.
|
||||
// Instantiate new minio client object.
|
||||
c, err := minio.New(
|
||||
"s3.amazonaws.com",
|
||||
os.Getenv("ACCESS_KEY"),
|
||||
|
||||
+6
-2
@@ -24,6 +24,7 @@ import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"path/filepath"
|
||||
"sort"
|
||||
"strconv"
|
||||
"strings"
|
||||
@@ -38,8 +39,11 @@ const (
|
||||
// Encode input URL path to URL encoded path.
|
||||
func encodeURL2Path(u *url.URL) (path string) {
|
||||
// Encode URL path.
|
||||
if strings.HasSuffix(u.Host, ".s3.amazonaws.com") {
|
||||
path = "/" + strings.TrimSuffix(u.Host, ".s3.amazonaws.com")
|
||||
if isS3, _ := filepath.Match("*.s3*.amazonaws.com", u.Host); isS3 {
|
||||
hostSplits := strings.SplitN(u.Host, ".", 4)
|
||||
// First element is the bucket name.
|
||||
bucketName := hostSplits[0]
|
||||
path = "/" + bucketName
|
||||
path += u.Path
|
||||
path = urlEncodePath(path)
|
||||
return
|
||||
|
||||
Vendored
+2
-2
@@ -29,8 +29,8 @@
|
||||
},
|
||||
{
|
||||
"path": "github.com/minio/minio-go",
|
||||
"revision": "65e5154d5edc3c1c1279d71ab595cc4a6bb94b1a",
|
||||
"revisionTime": "2016-01-25T00:19:13-08:00"
|
||||
"revision": "da044a0509a9a9e667e8cc838a7313b0a8ba2710",
|
||||
"revisionTime": "2016-01-25T16:31:01-08:00"
|
||||
},
|
||||
{
|
||||
"path": "github.com/minio/minio-xl/pkg/atomic",
|
||||
|
||||
Reference in New Issue
Block a user