mirror of
https://github.com/NixOS/nix.git
synced 2025-11-08 19:46:02 +01:00
libstore: Correct getUri methods for all stores
Previously `getUri` didn't include store query parameters, `ssh-ng` didn't include any information at all and the local store didn't have the path: ``` $ nix store info --store "local?root=/tmp/aaa&require-sigs=false" Store URL: local Version: 2.31.0 Trusted: 1 $ nix store info --store "ssh-ng://localhost?remote-program=nix-daemon" Store URL: ssh-ng:// Version: 2.31.0 Trusted: 1 $ nix store info --store "ssh://localhost?remote-program=nix-store" Store URL: ssh://localhost ``` This commit changes this to: ``` $ nix store info --store "local?root=/tmp/aaa&require-sigs=false" Store URL: local?require-sigs=false&root=/tmp/aaa Version: 2.31.0 Trusted: 1 $ nix store info --store "ssh-ng://localhost?remote-program=nix-daemon" Store URL: ssh-ng://localhost?remote-program=nix-daemon Version: 2.31.0 Trusted: 1 $ nix store info --store "ssh://localhost?remote-program=nix-store" Store URL: ssh://localhost?remote-program=nix-store ```
This commit is contained in:
parent
73ebdf2497
commit
41af531392
7 changed files with 58 additions and 16 deletions
|
|
@ -6,21 +6,27 @@ namespace nix {
|
|||
|
||||
TEST(LegacySSHStore, constructConfig)
|
||||
{
|
||||
LegacySSHStoreConfig config{
|
||||
initLibStore(/*loadConfig=*/false);
|
||||
|
||||
auto config = make_ref<LegacySSHStoreConfig>(
|
||||
"ssh",
|
||||
"localhost",
|
||||
"me@localhost:2222",
|
||||
StoreConfig::Params{
|
||||
{
|
||||
"remote-program",
|
||||
// TODO #11106, no more split on space
|
||||
"foo bar",
|
||||
},
|
||||
}};
|
||||
});
|
||||
|
||||
EXPECT_EQ(
|
||||
config.remoteProgram.get(),
|
||||
config->remoteProgram.get(),
|
||||
(Strings{
|
||||
"foo",
|
||||
"bar",
|
||||
}));
|
||||
|
||||
auto store = config->openStore();
|
||||
EXPECT_EQ(store->getUri(), "ssh://me@localhost:2222?remote-program=foo%20bar");
|
||||
}
|
||||
} // namespace nix
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@
|
|||
|
||||
#include "nix/store/tests/nix_api_store.hh"
|
||||
#include "nix/util/tests/string_callback.hh"
|
||||
#include "nix/util/url.hh"
|
||||
|
||||
#include "store-tests-config.hh"
|
||||
|
||||
|
|
@ -23,7 +24,13 @@ TEST_F(nix_api_store_test, nix_store_get_uri)
|
|||
std::string str;
|
||||
auto ret = nix_store_get_uri(ctx, store, OBSERVE_STRING(str));
|
||||
ASSERT_EQ(NIX_OK, ret);
|
||||
ASSERT_STREQ("local", str.c_str());
|
||||
auto expectedStoreURI = "local?"
|
||||
+ nix::encodeQuery({
|
||||
{"log", nixLogDir},
|
||||
{"state", nixStateDir},
|
||||
{"store", nixStoreDir},
|
||||
});
|
||||
ASSERT_EQ(expectedStoreURI, str);
|
||||
}
|
||||
|
||||
TEST_F(nix_api_util_context, nix_store_get_storedir_default)
|
||||
|
|
|
|||
|
|
@ -8,24 +8,31 @@ namespace nix {
|
|||
|
||||
TEST(SSHStore, constructConfig)
|
||||
{
|
||||
SSHStoreConfig config{
|
||||
"ssh",
|
||||
"localhost",
|
||||
initLibStore(/*loadConfig=*/false);
|
||||
|
||||
auto config = make_ref<SSHStoreConfig>(
|
||||
"ssh-ng",
|
||||
"me@localhost:2222",
|
||||
StoreConfig::Params{
|
||||
{
|
||||
"remote-program",
|
||||
// TODO #11106, no more split on space
|
||||
"foo bar",
|
||||
},
|
||||
},
|
||||
};
|
||||
});
|
||||
|
||||
EXPECT_EQ(
|
||||
config.remoteProgram.get(),
|
||||
config->remoteProgram.get(),
|
||||
(Strings{
|
||||
"foo",
|
||||
"bar",
|
||||
}));
|
||||
|
||||
auto store = config->openStore();
|
||||
EXPECT_EQ(store->getUri(), "ssh-ng://me@localhost:2222?remote-program=foo%20bar");
|
||||
config->resetOverridden();
|
||||
store = config->openStore();
|
||||
EXPECT_EQ(store->getUri(), "ssh-ng://me@localhost:2222");
|
||||
}
|
||||
|
||||
TEST(MountedSSHStore, constructConfig)
|
||||
|
|
|
|||
|
|
@ -126,6 +126,19 @@ struct StoreConfig : public StoreDirConfig
|
|||
return "";
|
||||
}
|
||||
|
||||
/**
|
||||
* Get overridden store reference query parameters.
|
||||
*/
|
||||
StringMap getQueryParams() const
|
||||
{
|
||||
auto queryParams = std::map<std::string, AbstractConfig::SettingInfo>{};
|
||||
getSettings(queryParams, /*overriddenOnly=*/true);
|
||||
StringMap res;
|
||||
for (const auto & [name, info] : queryParams)
|
||||
res.insert({name, info.value});
|
||||
return res;
|
||||
}
|
||||
|
||||
/**
|
||||
* An experimental feature this type store is gated, if it is to be
|
||||
* experimental.
|
||||
|
|
|
|||
|
|
@ -90,7 +90,9 @@ ref<LegacySSHStore::Connection> LegacySSHStore::openConnection()
|
|||
|
||||
std::string LegacySSHStore::getUri()
|
||||
{
|
||||
return *Config::uriSchemes().begin() + "://" + config->authority.to_string();
|
||||
return ParsedURL{
|
||||
.scheme = *Config::uriSchemes().begin(), .authority = config->authority, .query = config->getQueryParams()}
|
||||
.to_string();
|
||||
}
|
||||
|
||||
std::map<StorePath, UnkeyedValidPathInfo> LegacySSHStore::queryPathInfosUncached(const StorePathSet & paths)
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@
|
|||
#include "nix/store/posix-fs-canonicalise.hh"
|
||||
#include "nix/util/posix-source-accessor.hh"
|
||||
#include "nix/store/keys.hh"
|
||||
#include "nix/util/url.hh"
|
||||
#include "nix/util/users.hh"
|
||||
#include "nix/store/store-open.hh"
|
||||
#include "nix/store/store-registration.hh"
|
||||
|
|
@ -440,7 +441,13 @@ LocalStore::~LocalStore()
|
|||
|
||||
std::string LocalStore::getUri()
|
||||
{
|
||||
return "local";
|
||||
std::ostringstream oss;
|
||||
oss << *config->uriSchemes().begin();
|
||||
auto queryParams = config->getQueryParams();
|
||||
if (!queryParams.empty())
|
||||
oss << "?";
|
||||
oss << encodeQuery(queryParams);
|
||||
return std::move(oss).str();
|
||||
}
|
||||
|
||||
int LocalStore::getSchema()
|
||||
|
|
|
|||
|
|
@ -43,7 +43,9 @@ struct SSHStore : virtual RemoteStore
|
|||
|
||||
std::string getUri() override
|
||||
{
|
||||
return *Config::uriSchemes().begin() + "://" + host;
|
||||
return ParsedURL{
|
||||
.scheme = *Config::uriSchemes().begin(), .authority = config->authority, .query = config->getQueryParams()}
|
||||
.to_string();
|
||||
}
|
||||
|
||||
// FIXME extend daemon protocol, move implementation to RemoteStore
|
||||
|
|
@ -66,8 +68,6 @@ protected:
|
|||
|
||||
ref<RemoteStore::Connection> openConnection() override;
|
||||
|
||||
std::string host;
|
||||
|
||||
std::vector<std::string> extraRemoteProgramArgs;
|
||||
|
||||
SSHMaster master;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue