mirror of
https://github.com/NixOS/nix.git
synced 2025-11-08 19:46:02 +01:00
libstore: Simplify check for S3-specific URI query parameters
Instead of hardcoding strings we should instead use the setting objects to determine the query names that should be preserved.
This commit is contained in:
parent
64c55961eb
commit
61fbef42a6
2 changed files with 13 additions and 10 deletions
|
|
@ -21,8 +21,6 @@ struct S3BinaryCacheStoreConfig : HttpBinaryCacheStoreConfig
|
||||||
Nix uses the `default` profile.
|
Nix uses the `default` profile.
|
||||||
)"};
|
)"};
|
||||||
|
|
||||||
public:
|
|
||||||
|
|
||||||
const Setting<std::string> region{
|
const Setting<std::string> region{
|
||||||
this,
|
this,
|
||||||
"us-east-1",
|
"us-east-1",
|
||||||
|
|
@ -63,6 +61,12 @@ public:
|
||||||
> addressing instead of virtual host based addressing.
|
> addressing instead of virtual host based addressing.
|
||||||
)"};
|
)"};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set of settings that are part of the S3 URI itself.
|
||||||
|
* These are needed for region specification and other S3-specific settings.
|
||||||
|
*/
|
||||||
|
const std::set<const AbstractSetting *> s3UriSettings = {&profile, ®ion, &scheme, &endpoint};
|
||||||
|
|
||||||
static const std::string name()
|
static const std::string name()
|
||||||
{
|
{
|
||||||
return "S3 Binary Cache Store";
|
return "S3 Binary Cache Store";
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,10 @@
|
||||||
#include "nix/store/s3-binary-cache-store.hh"
|
#include "nix/store/s3-binary-cache-store.hh"
|
||||||
|
|
||||||
#include <cassert>
|
|
||||||
|
|
||||||
#include "nix/store/http-binary-cache-store.hh"
|
#include "nix/store/http-binary-cache-store.hh"
|
||||||
#include "nix/store/store-registration.hh"
|
#include "nix/store/store-registration.hh"
|
||||||
|
|
||||||
|
#include <cassert>
|
||||||
|
#include <ranges>
|
||||||
|
|
||||||
namespace nix {
|
namespace nix {
|
||||||
|
|
||||||
StringSet S3BinaryCacheStoreConfig::uriSchemes()
|
StringSet S3BinaryCacheStoreConfig::uriSchemes()
|
||||||
|
|
@ -17,14 +17,13 @@ S3BinaryCacheStoreConfig::S3BinaryCacheStoreConfig(
|
||||||
: StoreConfig(params)
|
: StoreConfig(params)
|
||||||
, HttpBinaryCacheStoreConfig(scheme, _cacheUri, params)
|
, HttpBinaryCacheStoreConfig(scheme, _cacheUri, params)
|
||||||
{
|
{
|
||||||
// For S3 stores, preserve S3-specific query parameters as part of the URL
|
|
||||||
// These are needed for region specification and other S3-specific settings
|
|
||||||
assert(cacheUri.query.empty());
|
assert(cacheUri.query.empty());
|
||||||
|
assert(cacheUri.scheme == "s3");
|
||||||
|
|
||||||
// Only copy S3-specific parameters to the URL query
|
|
||||||
static const std::set<std::string> s3Params = {"region", "endpoint", "profile", "scheme"};
|
|
||||||
for (const auto & [key, value] : params) {
|
for (const auto & [key, value] : params) {
|
||||||
if (s3Params.contains(key)) {
|
auto s3Params =
|
||||||
|
std::views::transform(s3UriSettings, [](const AbstractSetting * setting) { return setting->name; });
|
||||||
|
if (std::ranges::contains(s3Params, key)) {
|
||||||
cacheUri.query[key] = value;
|
cacheUri.query[key] = value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue