open-vault/vendor/github.com/aws/aws-sdk-go/service/s3/bucket_location.go

44 lines
1.1 KiB
Go
Raw Normal View History

2015-05-20 15:46:21 +00:00
package s3
import (
"io/ioutil"
"regexp"
2015-06-03 19:07:39 +00:00
"github.com/aws/aws-sdk-go/aws"
2015-06-29 22:05:44 +00:00
"github.com/aws/aws-sdk-go/aws/awserr"
2015-06-03 19:07:39 +00:00
"github.com/aws/aws-sdk-go/aws/awsutil"
2015-09-22 15:44:21 +00:00
"github.com/aws/aws-sdk-go/aws/request"
2015-05-20 15:46:21 +00:00
)
var reBucketLocation = regexp.MustCompile(`>([^<>]+)<\/Location`)
2015-09-22 15:44:21 +00:00
func buildGetBucketLocation(r *request.Request) {
2015-05-20 15:46:21 +00:00
if r.DataFilled() {
out := r.Data.(*GetBucketLocationOutput)
b, err := ioutil.ReadAll(r.HTTPResponse.Body)
if err != nil {
2015-06-29 22:05:44 +00:00
r.Error = awserr.New("SerializationError", "failed reading response body", err)
2015-05-20 15:46:21 +00:00
return
}
match := reBucketLocation.FindSubmatch(b)
if len(match) > 1 {
loc := string(match[1])
out.LocationConstraint = &loc
}
}
}
2015-09-22 15:44:21 +00:00
func populateLocationConstraint(r *request.Request) {
2015-10-30 22:07:00 +00:00
if r.ParamsFilled() && aws.StringValue(r.Config.Region) != "us-east-1" {
2015-05-20 15:46:21 +00:00
in := r.Params.(*CreateBucketInput)
if in.CreateBucketConfiguration == nil {
r.Params = awsutil.CopyOf(r.Params)
in = r.Params.(*CreateBucketInput)
in.CreateBucketConfiguration = &CreateBucketConfiguration{
2015-10-30 22:07:00 +00:00
LocationConstraint: r.Config.Region,
2015-05-20 15:46:21 +00:00
}
}
}
}