about summary refs log tree commit diff
path: root/src/libstore/s3-binary-cache-store.cc
diff options
context:
space:
mode:
authorEelco Dolstra <edolstra@gmail.com>2017-06-19T16·39+0200
committerEelco Dolstra <edolstra@gmail.com>2017-06-19T16·51+0200
commit82a0d614cf17b2997ba5f895c1db4c2cde41e88d (patch)
tree4fc1f632a6b3c323093dfd61bfc5f3afc07b3294 /src/libstore/s3-binary-cache-store.cc
parentb33621d4253addc4a0cdf1fb7a4082109aaafa78 (diff)
Support creating S3 caches in other regions than us-east-1
Diffstat (limited to 'src/libstore/s3-binary-cache-store.cc')
-rw-r--r--src/libstore/s3-binary-cache-store.cc14
1 files changed, 10 insertions, 4 deletions
diff --git a/src/libstore/s3-binary-cache-store.cc b/src/libstore/s3-binary-cache-store.cc
index 8029cd8cca0c..06622210cbf4 100644
--- a/src/libstore/s3-binary-cache-store.cc
+++ b/src/libstore/s3-binary-cache-store.cc
@@ -187,14 +187,20 @@ struct S3BinaryCacheStoreImpl : public S3BinaryCacheStore
                 if (res.GetError().GetErrorType() != Aws::S3::S3Errors::NO_SUCH_BUCKET)
                     throw Error(format("AWS error checking bucket ‘%s’: %s") % bucketName % res.GetError().GetMessage());
 
+                printInfo("creating S3 bucket ‘%s’...", bucketName);
+
+                // Stupid S3 bucket locations.
+                auto bucketConfig = Aws::S3::Model::CreateBucketConfiguration();
+                if (s3Helper.config->region != "us-east-1")
+                    bucketConfig.SetLocationConstraint(
+                        Aws::S3::Model::BucketLocationConstraintMapper::GetBucketLocationConstraintForName(
+                            s3Helper.config->region));
+
                 checkAws(format("AWS error creating bucket ‘%s’") % bucketName,
                     s3Helper.client->CreateBucket(
                         Aws::S3::Model::CreateBucketRequest()
                         .WithBucket(bucketName)
-                        .WithCreateBucketConfiguration(
-                            Aws::S3::Model::CreateBucketConfiguration()
-                            /* .WithLocationConstraint(
-                               Aws::S3::Model::BucketLocationConstraint::US) */ )));
+                        .WithCreateBucketConfiguration(bucketConfig)));
             }
 
             BinaryCacheStore::init();