diff --git a/Godeps/Godeps.json b/Godeps/Godeps.json index 9ae80006..245d2d0c 100644 --- a/Godeps/Godeps.json +++ b/Godeps/Godeps.json @@ -36,7 +36,7 @@ }, { "ImportPath": "github.com/minio/objectstorage-go", - "Rev": "191883582ed0260d7be8f091971d5a7a840621d0" + "Rev": "3a8c0c3b348ad327f1e9ec69c3ab07ce327ff796" }, { "ImportPath": "github.com/shiena/ansicolor", diff --git a/Godeps/_workspace/src/github.com/minio/objectstorage-go/api.go b/Godeps/_workspace/src/github.com/minio/objectstorage-go/api.go index 505f2cf5..52457a59 100644 --- a/Godeps/_workspace/src/github.com/minio/objectstorage-go/api.go +++ b/Godeps/_workspace/src/github.com/minio/objectstorage-go/api.go @@ -131,7 +131,7 @@ type Config struct { // MustGetEndpoint makes sure that a valid endpoint is provided all the time, even with false regions it will fall // back to default, for no regions specified it chooses to default to "milkyway" and use endpoint as is func (c *Config) MustGetEndpoint() string { - if strings.TrimSpace(c.Endpoint) != "" { + if strings.TrimSpace(c.Endpoint) != "" && strings.TrimSpace(c.Region) == "" { if strings.Contains(strings.TrimSpace(c.Endpoint), "s3.amazonaws.com") { c.Region = "us-east-1" return getEndpoint(c.Region) @@ -262,6 +262,9 @@ func (a *api) continueObjectUpload(bucket, object, uploadID string, data io.Read // // This version of CreateObject automatically does multipart for more than 5MB worth of data func (a *api) CreateObject(bucket, object string, size uint64, data io.Reader) (string, error) { + if strings.TrimSpace(object) == "" { + return "", errors.New("object name cannot be empty") + } switch { case size < DefaultPartSize: // Single Part use case, use PutObject directly diff --git a/config.go b/config.go index 1e65183c..83c99410 100644 --- a/config.go +++ b/config.go @@ -155,9 +155,9 @@ func newConfig() (config quick.Config) { exampleHostConf.SecretAccessKey = globalSecretAccessKey conf.Hosts[exampleHostURL] = exampleHostConf - conf.Hosts["http*://s3*.amazonaws.com"] = s3HostConf - conf.Hosts["http://play.minio.io:9000"] = playHostConfig - conf.Hosts["http://dl.minio.io:9000"] = dlHostConfig + conf.Hosts["s3*.amazonaws.com"] = s3HostConf + conf.Hosts["play.minio.io:9000"] = playHostConfig + conf.Hosts["dl.minio.io:9000"] = dlHostConfig aliases := make(map[string]string) aliases["s3"] = "https://s3.amazonaws.com" diff --git a/pkg/client/s3/s3.go b/pkg/client/s3/s3.go index db82acab..0df1bb52 100644 --- a/pkg/client/s3/s3.go +++ b/pkg/client/s3/s3.go @@ -53,6 +53,25 @@ type s3Client struct { hostURL *url.URL } +// url2Regions s3 region map used by bucket location constraint +var url2Regions = map[string]string{ + "s3-fips-us-gov-west-1.amazonaws.com": "us-gov-west-1", + "s3.amazonaws.com": "us-east-1", + "s3-us-west-1.amazonaws.com": "us-west-1", + "s3-us-west-2.amazonaws.com": "us-west-2", + "s3-eu-west-1.amazonaws.com": "eu-west-1", + "s3-eu-central-1.amazonaws.com": "eu-central-1", + "s3-ap-southeast-1.amazonaws.com": "ap-southeast-1", + "s3-ap-southeast-2.amazonaws.com": "ap-southeast-2", + "s3-ap-northeast-1.amazonaws.com": "ap-northeast-1", + "s3-sa-east-1.amazonaws.com": "sa-east-1", + "s3.cn-north-1.amazonaws.com.cn": "cn-north-1", +} + +func getRegion(host string) string { + return url2Regions[host] +} + // New returns an initialized s3Client structure. if debug use a internal trace transport func New(config *Config) client.Client { u, err := url.Parse(config.HostURL) @@ -71,6 +90,7 @@ func New(config *Config) client.Client { objectstorageConf.SecretAccessKey = config.SecretAccessKey objectstorageConf.UserAgent = config.UserAgent objectstorageConf.Transport = transport + objectstorageConf.Region = getRegion(u.Host) objectstorageConf.Endpoint = u.Scheme + "://" + u.Host api := objectstorage.New(objectstorageConf) return &s3Client{api: api, hostURL: u}