From 8956ae19879e0367250002b94e399d8c771f37a1 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Wed, 15 Nov 2017 14:16:04 +0100 Subject: 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-... --- src/libstore/download.cc | 2 +- src/libstore/s3-binary-cache-store.cc | 15 ++++++++++++--- src/libstore/s3.hh | 2 +- 3 files changed, 14 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/libstore/download.cc b/src/libstore/download.cc index 70f9b1f5eacb..da31029b4f87 100644 --- a/src/libstore/download.cc +++ b/src/libstore/download.cc @@ -533,7 +533,7 @@ struct CurlDownloader : public Downloader // FIXME: do this on a worker thread sync2async(success, failure, [&]() -> DownloadResult { #ifdef ENABLE_S3 - S3Helper s3Helper(Aws::Region::US_EAST_1); // FIXME: make configurable + 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 6a0f19238add..0079da1becfb 100644 --- a/src/libstore/s3-binary-cache-store.cc +++ b/src/libstore/s3-binary-cache-store.cc @@ -10,6 +10,8 @@ #include "istringstream_nocopy.hh" #include +#include +#include #include #include #include @@ -77,9 +79,15 @@ static void initAWS() }); } -S3Helper::S3Helper(const string & region) +S3Helper::S3Helper(const std::string & profile, const std::string & region) : config(makeConfig(region)) - , client(make_ref(*config, true, false)) + , client(make_ref( + profile == "" + ? std::dynamic_pointer_cast( + std::make_shared()) + : std::dynamic_pointer_cast( + std::make_shared(profile.c_str())), + *config, true, false)) { } @@ -148,6 +156,7 @@ S3Helper::DownloadResult S3Helper::getObject( struct S3BinaryCacheStoreImpl : public S3BinaryCacheStore { + const Setting profile{this, "", "profile", "The name of the AWS configuration profile to use."}; const Setting region{this, Aws::Region::US_EAST_1, "region", {"aws-region"}}; const Setting narinfoCompression{this, "", "narinfo-compression", "compression method for .narinfo files"}; const Setting lsCompression{this, "", "ls-compression", "compression method for .ls files"}; @@ -163,7 +172,7 @@ struct S3BinaryCacheStoreImpl : public S3BinaryCacheStore const Params & params, const std::string & bucketName) : S3BinaryCacheStore(params) , bucketName(bucketName) - , s3Helper(region) + , s3Helper(profile, region) { diskCache = getNarInfoDiskCache(); } diff --git a/src/libstore/s3.hh b/src/libstore/s3.hh index 08a7fbf96e98..4f996400343c 100644 --- a/src/libstore/s3.hh +++ b/src/libstore/s3.hh @@ -14,7 +14,7 @@ struct S3Helper ref config; ref client; - S3Helper(const std::string & region); + S3Helper(const std::string & profile, const std::string & region); ref makeConfig(const std::string & region); -- cgit 1.4.1