From 44300859819c859f2be63555c9573fd46dd1a631 Mon Sep 17 00:00:00 2001 From: Remco Verhoef Date: Wed, 10 May 2017 16:53:44 -0700 Subject: [PATCH] Add region to gcs gateway example --- cmd/gateway-gcs.go | 22 +++++++++++++++++++++- cmd/gateway-handlers.go | 5 ++++- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/cmd/gateway-gcs.go b/cmd/gateway-gcs.go index 8d1010191..9fe3035eb 100644 --- a/cmd/gateway-gcs.go +++ b/cmd/gateway-gcs.go @@ -222,8 +222,28 @@ func (l *gcsGateway) MakeBucket(bucket string) error { func (l *gcsGateway) MakeBucketWithLocation(bucket, location string) error { bkt := l.client.Bucket(bucket) + // this will map s3 regions to google multi regions + if v, ok := map[string]string{ + "ap-northeast-1": "asia", + "ap-northeast-2": "asia", + "ap-south-1": "asia", + "ap-southeast-1": "asia", + "ap-southeast-2": "asia", + "eu-central-1": "eu", + "eu-west-1": "eu", + "eu-west-2": "eu", + "ca-central-1": "us", + "sa-east-1": "us", + "us-east-1": "us", + "us-east-2": "us", + "us-west-1": "us", + "us-west-2": "us", + }[location]; ok { + location = v + } + if err := bkt.Create(l.ctx, l.projectID, &storage.BucketAttrs{ - Location: serverConfig.Region, + Location: location, }); err != nil { return gcsToObjectError(traceError(err), bucket) } diff --git a/cmd/gateway-handlers.go b/cmd/gateway-handlers.go index fa6af325c..e7a8cffff 100644 --- a/cmd/gateway-handlers.go +++ b/cmd/gateway-handlers.go @@ -658,7 +658,10 @@ func (api gatewayAPIHandlers) PutBucketHandler(w http.ResponseWriter, r *http.Re // reads body which has been read already. So only validating // region here. serverRegion := serverConfig.GetRegion() - if serverRegion != location { + if serverRegion == "" { + // we will only validate the region + // when the region has been explicitely set + } else if serverRegion != location { writeErrorResponse(w, ErrInvalidRegion, r.URL) return }