about summary refs log tree commit diff
path: root/src/libstore
diff options
context:
space:
mode:
authorDzmitry Zaitsau <pradd.me@gmail.com>2019-02-25T16·56+0100
committerDzmitry Zaitsau <pradd.me@gmail.com>2019-02-25T17·00+0100
commit56c18c67d98078dbed1d05ac68663cc52d2cb543 (patch)
tree9e55c98ce24b3a67ef25b5b5ccb96fc5071025f0 /src/libstore
parent07f992a74b64f4376d5b415d0042babc924772f3 (diff)
Extend S3 URL parsing with parameters extraction
Diffstat (limited to 'src/libstore')
-rw-r--r--src/libstore/download.cc22
1 files changed, 17 insertions, 5 deletions
diff --git a/src/libstore/download.cc b/src/libstore/download.cc
index 467f570bbf05..8bc496515f78 100644
--- a/src/libstore/download.cc
+++ b/src/libstore/download.cc
@@ -614,6 +614,22 @@ struct CurlDownloader : public Downloader
         writeFull(wakeupPipe.writeSide.get(), " ");
     }
 
+#ifdef ENABLE_S3
+    std::tuple<std::string, std::string, Store::Params> parseS3Uri(std::string uri)
+    {
+        auto [path, params] = splitUriAndParams(uri);
+
+        auto slash = path.find('/', 5); // 5 is the length of "s3://" prefix
+           if (slash == std::string::npos)
+               throw nix::Error("bad S3 URI '%s'", path);
+
+        std::string bucketName(path, 5, slash - 5);
+        std::string key(path, slash + 1);
+
+        return {bucketName, key, params};
+    }
+#endif
+
     void enqueueDownload(const DownloadRequest & request,
         Callback<DownloadResult> callback) override
     {
@@ -622,12 +638,8 @@ struct CurlDownloader : public Downloader
             // FIXME: do this on a worker thread
             try {
 #ifdef ENABLE_S3
+                auto [bucketName, key, params] = parseS3Uri(request.uri);
                 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);
-                std::string bucketName(request.uri, 5, slash - 5);
-                std::string key(request.uri, slash + 1);
                 // FIXME: implement ETag
                 auto s3Res = s3Helper.getObject(bucketName, key);
                 DownloadResult res;