2018-02-21 17:22:49 +02:00
|
|
|
#include "command.hh"
|
|
|
|
#include "shared.hh"
|
|
|
|
#include "store-api.hh"
|
2023-01-31 16:10:39 +02:00
|
|
|
#include "finally.hh"
|
2018-02-21 17:22:49 +02:00
|
|
|
|
2023-01-31 14:24:23 +02:00
|
|
|
#include <nlohmann/json.hpp>
|
|
|
|
|
2018-02-21 17:22:49 +02:00
|
|
|
using namespace nix;
|
|
|
|
|
2023-01-31 14:24:23 +02:00
|
|
|
struct CmdPingStore : StoreCommand, MixJSON
|
2018-02-21 17:22:49 +02:00
|
|
|
{
|
|
|
|
std::string description() override
|
|
|
|
{
|
2020-12-09 18:55:59 +02:00
|
|
|
return "test whether a store can be accessed";
|
2018-02-21 17:22:49 +02:00
|
|
|
}
|
|
|
|
|
2020-12-09 18:55:59 +02:00
|
|
|
std::string doc() override
|
2018-02-21 17:22:49 +02:00
|
|
|
{
|
2020-12-09 18:55:59 +02:00
|
|
|
return
|
|
|
|
#include "ping-store.md"
|
|
|
|
;
|
2018-02-21 17:22:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void run(ref<Store> store) override
|
|
|
|
{
|
2023-01-31 14:24:23 +02:00
|
|
|
if (!json) {
|
|
|
|
notice("Store URL: %s", store->getUri());
|
|
|
|
store->connect();
|
|
|
|
if (auto version = store->getVersion())
|
|
|
|
notice("Version: %s", *version);
|
2022-12-26 22:21:08 +02:00
|
|
|
if (auto trusted = store->isTrustedClient())
|
|
|
|
notice("Trusted: %s", *trusted);
|
2023-01-31 14:24:23 +02:00
|
|
|
} else {
|
|
|
|
nlohmann::json res;
|
2023-01-31 16:10:39 +02:00
|
|
|
Finally printRes([&]() {
|
|
|
|
logger->cout("%s", res);
|
|
|
|
});
|
2022-12-26 22:21:08 +02:00
|
|
|
|
2023-01-31 14:24:23 +02:00
|
|
|
res["url"] = store->getUri();
|
|
|
|
store->connect();
|
|
|
|
if (auto version = store->getVersion())
|
|
|
|
res["version"] = *version;
|
2022-12-26 22:21:08 +02:00
|
|
|
if (auto trusted = store->isTrustedClient())
|
|
|
|
res["trusted"] = *trusted;
|
2023-01-31 14:24:23 +02:00
|
|
|
}
|
2018-02-21 17:22:49 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2023-10-13 04:46:05 +03:00
|
|
|
struct CmdInfoStore : CmdPingStore
|
|
|
|
{
|
|
|
|
void run(nix::ref<nix::Store> store) override
|
|
|
|
{
|
|
|
|
warn("'nix store info' is a deprecated alias for 'nix store ping'");
|
|
|
|
CmdPingStore::run(store);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2020-07-24 21:38:56 +03:00
|
|
|
static auto rCmdPingStore = registerCommand2<CmdPingStore>({"store", "ping"});
|
2023-10-13 04:46:05 +03:00
|
|
|
static auto rCmdInfoStore = registerCommand2<CmdInfoStore>({"store", "info"});
|