bucket_location.go 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. package s3
  2. import (
  3. "io/ioutil"
  4. "regexp"
  5. "github.com/aws/aws-sdk-go/aws"
  6. "github.com/aws/aws-sdk-go/aws/awserr"
  7. "github.com/aws/aws-sdk-go/aws/awsutil"
  8. "github.com/aws/aws-sdk-go/aws/request"
  9. )
  10. var reBucketLocation = regexp.MustCompile(`>([^<>]+)<\/Location`)
  11. func buildGetBucketLocation(r *request.Request) {
  12. if r.DataFilled() {
  13. out := r.Data.(*GetBucketLocationOutput)
  14. b, err := ioutil.ReadAll(r.HTTPResponse.Body)
  15. if err != nil {
  16. r.Error = awserr.New("SerializationError", "failed reading response body", err)
  17. return
  18. }
  19. match := reBucketLocation.FindSubmatch(b)
  20. if len(match) > 1 {
  21. loc := string(match[1])
  22. out.LocationConstraint = &loc
  23. }
  24. }
  25. }
  26. func populateLocationConstraint(r *request.Request) {
  27. if r.ParamsFilled() && aws.StringValue(r.Service.Config.Region) != "us-east-1" {
  28. in := r.Params.(*CreateBucketInput)
  29. if in.CreateBucketConfiguration == nil {
  30. r.Params = awsutil.CopyOf(r.Params)
  31. in = r.Params.(*CreateBucketInput)
  32. in.CreateBucketConfiguration = &CreateBucketConfiguration{
  33. LocationConstraint: r.Service.Config.Region,
  34. }
  35. }
  36. }
  37. }