Merge branch 'configurable-aws-region'
This commit is contained in:
commit
96443e94a1
|
@ -5,6 +5,9 @@
|
||||||
#include "store-api.hh"
|
#include "store-api.hh"
|
||||||
#include "archive.hh"
|
#include "archive.hh"
|
||||||
#include "s3.hh"
|
#include "s3.hh"
|
||||||
|
#ifdef ENABLE_S3
|
||||||
|
#include <aws/core/client/ClientConfiguration.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
|
@ -495,7 +498,7 @@ struct CurlDownloader : public Downloader
|
||||||
// FIXME: do this on a worker thread
|
// FIXME: do this on a worker thread
|
||||||
sync2async<DownloadResult>(success, failure, [&]() -> DownloadResult {
|
sync2async<DownloadResult>(success, failure, [&]() -> DownloadResult {
|
||||||
#ifdef ENABLE_S3
|
#ifdef ENABLE_S3
|
||||||
S3Helper s3Helper;
|
S3Helper s3Helper(Aws::Region::US_EAST_1); // FIXME: make configurable
|
||||||
auto slash = request.uri.find('/', 5);
|
auto slash = request.uri.find('/', 5);
|
||||||
if (slash == std::string::npos)
|
if (slash == std::string::npos)
|
||||||
throw nix::Error("bad S3 URI ‘%s’", request.uri);
|
throw nix::Error("bad S3 URI ‘%s’", request.uri);
|
||||||
|
|
|
@ -52,8 +52,8 @@ static void initAWS()
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
S3Helper::S3Helper()
|
S3Helper::S3Helper(const string & region)
|
||||||
: config(makeConfig())
|
: config(makeConfig(region))
|
||||||
, client(make_ref<Aws::S3::S3Client>(*config))
|
, 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();
|
initAWS();
|
||||||
auto res = make_ref<Aws::Client::ClientConfiguration>();
|
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->requestTimeoutMs = 600 * 1000;
|
||||||
res->retryStrategy = std::make_shared<RetryStrategy>();
|
res->retryStrategy = std::make_shared<RetryStrategy>();
|
||||||
res->caFile = settings.caFile;
|
res->caFile = settings.caFile;
|
||||||
|
@ -141,6 +141,7 @@ struct S3BinaryCacheStoreImpl : public S3BinaryCacheStore
|
||||||
const Params & params, const std::string & bucketName)
|
const Params & params, const std::string & bucketName)
|
||||||
: S3BinaryCacheStore(params)
|
: S3BinaryCacheStore(params)
|
||||||
, bucketName(bucketName)
|
, bucketName(bucketName)
|
||||||
|
, s3Helper(get(params, "aws-region", Aws::Region::US_EAST_1))
|
||||||
{
|
{
|
||||||
diskCache = getNarInfoDiskCache();
|
diskCache = getNarInfoDiskCache();
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,9 +14,9 @@ struct S3Helper
|
||||||
ref<Aws::Client::ClientConfiguration> config;
|
ref<Aws::Client::ClientConfiguration> config;
|
||||||
ref<Aws::S3::S3Client> client;
|
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
|
struct DownloadResult
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue