lix/src/nix/ping-store.cc

50 lines
1.2 KiB
C++
Raw Normal View History

#include "command.hh"
#include "shared.hh"
#include "store-api.hh"
#include "finally.hh"
2023-01-31 12:24:23 +00:00
#include <nlohmann/json.hpp>
using namespace nix;
2023-01-31 12:24:23 +00:00
struct CmdPingStore : StoreCommand, MixJSON
{
std::string description() override
{
2020-12-09 16:55:59 +00:00
return "test whether a store can be accessed";
}
2020-12-09 16:55:59 +00:00
std::string doc() override
{
2020-12-09 16:55:59 +00:00
return
#include "ping-store.md"
;
}
void run(ref<Store> store) override
{
2023-01-31 12:24:23 +00:00
if (!json) {
notice("Store URL: %s", store->getUri());
store->connect();
if (auto version = store->getVersion())
notice("Version: %s", *version);
if (auto trusted = store->isTrustedClient())
notice("Trusted: %s", *trusted);
2023-01-31 12:24:23 +00:00
} else {
nlohmann::json res;
Finally printRes([&]() {
logger->cout("%s", res);
});
2023-01-31 12:24:23 +00:00
res["url"] = store->getUri();
store->connect();
if (auto version = store->getVersion())
res["version"] = *version;
if (auto trusted = store->isTrustedClient())
res["trusted"] = *trusted;
2023-01-31 12:24:23 +00:00
}
}
};
static auto rCmdPingStore = registerCommand2<CmdPingStore>({"store", "ping"});