diff options
author | Shea Levy <shea@shealevy.com> | 2017-03-03 16:12:17 -0500 |
---|---|---|
committer | Shea Levy <shea@shealevy.com> | 2017-03-03 16:12:17 -0500 |
commit | 5789eaa3f45cadec719b4f642de2169b8b0a56c4 (patch) | |
tree | c46c122af0ff474267882643ddcf6c1ea3bf6ede /src | |
parent | d1158bb8168804b27508972988d4b85ba9d5e49d (diff) |
Add aws-region param to S3 store URLs
Diffstat (limited to 'src')
-rw-r--r-- | src/libstore/download.cc | 5 | ||||
-rw-r--r-- | src/libstore/s3-binary-cache-store.cc | 9 | ||||
-rw-r--r-- | src/libstore/s3.hh | 4 |
3 files changed, 11 insertions, 7 deletions
diff --git a/src/libstore/download.cc b/src/libstore/download.cc index 75c00d85d..11374b1da 100644 --- a/src/libstore/download.cc +++ b/src/libstore/download.cc @@ -5,6 +5,9 @@ #include "store-api.hh" #include "archive.hh" #include "s3.hh" +#ifdef ENABLE_S3 +#include <aws/core/client/ClientConfiguration.h> +#endif #include <unistd.h> #include <fcntl.h> @@ -496,7 +499,7 @@ struct CurlDownloader : public Downloader // FIXME: do this on a worker thread sync2async<DownloadResult>(success, failure, [&]() -> DownloadResult { #ifdef ENABLE_S3 - S3Helper s3Helper; + S3Helper s3Helper(Aws::Region::US_EAST_1); // FIXME: make configurable auto slash = request.uri.find('/', 5); if (slash == std::string::npos) throw nix::Error("bad S3 URI ā%sā", request.uri); diff --git a/src/libstore/s3-binary-cache-store.cc b/src/libstore/s3-binary-cache-store.cc index 041c68c68..a110f5ade 100644 --- a/src/libstore/s3-binary-cache-store.cc +++ b/src/libstore/s3-binary-cache-store.cc @@ -52,8 +52,8 @@ static void initAWS() }); } -S3Helper::S3Helper() - : config(makeConfig()) +S3Helper::S3Helper(const string & region) + : config(makeConfig(region)) , client(make_ref<Aws::S3::S3Client>(*config)) { } @@ -70,11 +70,11 @@ class RetryStrategy : public Aws::Client::DefaultRetryStrategy } }; -ref<Aws::Client::ClientConfiguration> S3Helper::makeConfig() +ref<Aws::Client::ClientConfiguration> S3Helper::makeConfig(const string & region) { initAWS(); auto res = make_ref<Aws::Client::ClientConfiguration>(); - res->region = Aws::Region::US_EAST_1; // FIXME: make configurable + res->region = region; res->requestTimeoutMs = 600 * 1000; res->retryStrategy = std::make_shared<RetryStrategy>(); return res; @@ -140,6 +140,7 @@ struct S3BinaryCacheStoreImpl : public S3BinaryCacheStore const Params & params, const std::string & bucketName) : S3BinaryCacheStore(params) , bucketName(bucketName) + , s3Helper(get(params, "aws-region", Aws::Region::US_EAST_1)) { diskCache = getNarInfoDiskCache(); } diff --git a/src/libstore/s3.hh b/src/libstore/s3.hh index 5d5d3475c..08a7fbf96 100644 --- a/src/libstore/s3.hh +++ b/src/libstore/s3.hh @@ -14,9 +14,9 @@ struct S3Helper ref<Aws::Client::ClientConfiguration> config; ref<Aws::S3::S3Client> client; - S3Helper(); + S3Helper(const std::string & region); - ref<Aws::Client::ClientConfiguration> makeConfig(); + ref<Aws::Client::ClientConfiguration> makeConfig(const std::string & region); struct DownloadResult { |