Skip to content

Commit 8956ae1

Browse files
committedNov 15, 2017
Add a "profile" option to S3BinaryCacheStore
This allows specifying the AWS configuration profile to use. E.g. nix copy --from s3://my-cache?profile=aws-dev-account /nix/store/cf3isrlqavvd5w7rpky1fa8j9lcnlggm-...
1 parent 897ca33 commit 8956ae1

File tree

3 files changed

+14
-5
lines changed

3 files changed

+14
-5
lines changed
 

Diff for: ‎src/libstore/download.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -533,7 +533,7 @@ struct CurlDownloader : public Downloader
533533
// FIXME: do this on a worker thread
534534
sync2async<DownloadResult>(success, failure, [&]() -> DownloadResult {
535535
#ifdef ENABLE_S3
536-
S3Helper s3Helper(Aws::Region::US_EAST_1); // FIXME: make configurable
536+
S3Helper s3Helper("", Aws::Region::US_EAST_1); // FIXME: make configurable
537537
auto slash = request.uri.find('/', 5);
538538
if (slash == std::string::npos)
539539
throw nix::Error("bad S3 URI '%s'", request.uri);

Diff for: ‎src/libstore/s3-binary-cache-store.cc

+12-3
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
#include "istringstream_nocopy.hh"
1111

1212
#include <aws/core/Aws.h>
13+
#include <aws/core/auth/AWSCredentialsProvider.h>
14+
#include <aws/core/auth/AWSCredentialsProviderChain.h>
1315
#include <aws/core/client/ClientConfiguration.h>
1416
#include <aws/core/client/DefaultRetryStrategy.h>
1517
#include <aws/core/utils/logging/FormattedLogSystem.h>
@@ -77,9 +79,15 @@ static void initAWS()
7779
});
7880
}
7981

80-
S3Helper::S3Helper(const string & region)
82+
S3Helper::S3Helper(const std::string & profile, const std::string & region)
8183
: config(makeConfig(region))
82-
, client(make_ref<Aws::S3::S3Client>(*config, true, false))
84+
, client(make_ref<Aws::S3::S3Client>(
85+
profile == ""
86+
? std::dynamic_pointer_cast<Aws::Auth::AWSCredentialsProvider>(
87+
std::make_shared<Aws::Auth::DefaultAWSCredentialsProviderChain>())
88+
: std::dynamic_pointer_cast<Aws::Auth::AWSCredentialsProvider>(
89+
std::make_shared<Aws::Auth::ProfileConfigFileAWSCredentialsProvider>(profile.c_str())),
90+
*config, true, false))
8391
{
8492
}
8593

@@ -148,6 +156,7 @@ S3Helper::DownloadResult S3Helper::getObject(
148156

149157
struct S3BinaryCacheStoreImpl : public S3BinaryCacheStore
150158
{
159+
const Setting<std::string> profile{this, "", "profile", "The name of the AWS configuration profile to use."};
151160
const Setting<std::string> region{this, Aws::Region::US_EAST_1, "region", {"aws-region"}};
152161
const Setting<std::string> narinfoCompression{this, "", "narinfo-compression", "compression method for .narinfo files"};
153162
const Setting<std::string> lsCompression{this, "", "ls-compression", "compression method for .ls files"};
@@ -163,7 +172,7 @@ struct S3BinaryCacheStoreImpl : public S3BinaryCacheStore
163172
const Params & params, const std::string & bucketName)
164173
: S3BinaryCacheStore(params)
165174
, bucketName(bucketName)
166-
, s3Helper(region)
175+
, s3Helper(profile, region)
167176
{
168177
diskCache = getNarInfoDiskCache();
169178
}

Diff for: ‎src/libstore/s3.hh

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ struct S3Helper
1414
ref<Aws::Client::ClientConfiguration> config;
1515
ref<Aws::S3::S3Client> client;
1616

17-
S3Helper(const std::string & region);
17+
S3Helper(const std::string & profile, const std::string & region);
1818

1919
ref<Aws::Client::ClientConfiguration> makeConfig(const std::string & region);
2020

0 commit comments

Comments
 (0)
Please sign in to comment.