Skip to content

Commit b9af19c

Browse files
authored
Merge pull request #14295 from NixOS/s3-store-human-readable-uri
libstore: Implement getHumanReadableURI for S3BinaryCacheStoreConfig
2 parents 5d365cd + 3d147c0 commit b9af19c

File tree

2 files changed

+28
-10
lines changed

2 files changed

+28
-10
lines changed

src/libstore/include/nix/store/s3-binary-cache-store.hh

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@ struct S3BinaryCacheStoreConfig : HttpBinaryCacheStoreConfig
2121
Nix uses the `default` profile.
2222
)"};
2323

24-
public:
25-
2624
const Setting<std::string> region{
2725
this,
2826
"us-east-1",
@@ -63,6 +61,12 @@ public:
6361
> addressing instead of virtual host based addressing.
6462
)"};
6563

64+
/**
65+
* Set of settings that are part of the S3 URI itself.
66+
* These are needed for region specification and other S3-specific settings.
67+
*/
68+
const std::set<const AbstractSetting *> s3UriSettings = {&profile, &region, &scheme, &endpoint};
69+
6670
static const std::string name()
6771
{
6872
return "S3 Binary Cache Store";
@@ -71,6 +75,8 @@ public:
7175
static StringSet uriSchemes();
7276

7377
static std::string doc();
78+
79+
std::string getHumanReadableURI() const override;
7480
};
7581

7682
} // namespace nix

src/libstore/s3-binary-cache-store.cc

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
#include "nix/store/s3-binary-cache-store.hh"
2-
3-
#include <cassert>
4-
52
#include "nix/store/http-binary-cache-store.hh"
63
#include "nix/store/store-registration.hh"
74

5+
#include <cassert>
6+
#include <ranges>
7+
88
namespace nix {
99

1010
StringSet S3BinaryCacheStoreConfig::uriSchemes()
@@ -17,19 +17,31 @@ S3BinaryCacheStoreConfig::S3BinaryCacheStoreConfig(
1717
: StoreConfig(params)
1818
, HttpBinaryCacheStoreConfig(scheme, _cacheUri, params)
1919
{
20-
// For S3 stores, preserve S3-specific query parameters as part of the URL
21-
// These are needed for region specification and other S3-specific settings
2220
assert(cacheUri.query.empty());
21+
assert(cacheUri.scheme == "s3");
2322

24-
// Only copy S3-specific parameters to the URL query
25-
static const std::set<std::string> s3Params = {"region", "endpoint", "profile", "scheme"};
2623
for (const auto & [key, value] : params) {
27-
if (s3Params.contains(key)) {
24+
auto s3Params =
25+
std::views::transform(s3UriSettings, [](const AbstractSetting * setting) { return setting->name; });
26+
if (std::ranges::contains(s3Params, key)) {
2827
cacheUri.query[key] = value;
2928
}
3029
}
3130
}
3231

32+
std::string S3BinaryCacheStoreConfig::getHumanReadableURI() const
33+
{
34+
auto reference = getReference();
35+
reference.params = [&]() {
36+
Params relevantParams;
37+
for (auto & setting : s3UriSettings)
38+
if (setting->overridden)
39+
relevantParams.insert({setting->name, reference.params.at(setting->name)});
40+
return relevantParams;
41+
}();
42+
return reference.render();
43+
}
44+
3345
std::string S3BinaryCacheStoreConfig::doc()
3446
{
3547
return R"(

0 commit comments

Comments
 (0)