Merge pull request #625 from harshavardhana/pr_out_fix_region_handling_inside_client_s3
This commit is contained in:
Generated
+1
-1
@@ -36,7 +36,7 @@
|
||||
},
|
||||
{
|
||||
"ImportPath": "github.com/minio/objectstorage-go",
|
||||
"Rev": "191883582ed0260d7be8f091971d5a7a840621d0"
|
||||
"Rev": "3a8c0c3b348ad327f1e9ec69c3ab07ce327ff796"
|
||||
},
|
||||
{
|
||||
"ImportPath": "github.com/shiena/ansicolor",
|
||||
|
||||
+4
-1
@@ -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
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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}
|
||||
|
||||
Reference in New Issue
Block a user