From 4cd14a30bc1b52e77904f5831cea5868ef4c9659 Mon Sep 17 00:00:00 2001 From: eldritch horrors Date: Wed, 5 Mar 2025 16:42:11 +0100 Subject: [PATCH] libstore: asyncify Store::isTrustedClient Change-Id: Iabf4aa6bf04e23179f03f5d0055560970809773e --- lix/legacy/build-remote.cc | 2 +- lix/libstore/build/local-derivation-goal.cc | 4 ++-- lix/libstore/daemon.cc | 2 +- lix/libstore/dummy-store.cc | 4 ++-- lix/libstore/http-binary-cache-store.cc | 4 ++-- lix/libstore/legacy-ssh-store.cc | 4 ++-- lix/libstore/local-binary-cache-store.cc | 4 ++-- lix/libstore/local-store.cc | 4 ++-- lix/libstore/local-store.hh | 2 +- lix/libstore/remote-store.cc | 10 ++++++---- lix/libstore/remote-store.hh | 2 +- lix/libstore/s3-binary-cache-store.cc | 4 ++-- lix/libstore/store-api.hh | 2 +- lix/nix/doctor.cc | 2 +- lix/nix/ping-store.cc | 4 ++-- 15 files changed, 28 insertions(+), 26 deletions(-) diff --git a/lix/legacy/build-remote.cc b/lix/legacy/build-remote.cc index ced54fd88..a022776a1 100644 --- a/lix/legacy/build-remote.cc +++ b/lix/legacy/build-remote.cc @@ -305,7 +305,7 @@ connected: // stores), we assume we are. This is necessary for backwards // compat. bool trustedOrLegacy = ({ - std::optional trusted = sshStore->isTrustedClient(); + std::optional trusted = aio.blockOn(sshStore->isTrustedClient()); !trusted || *trusted; }); diff --git a/lix/libstore/build/local-derivation-goal.cc b/lix/libstore/build/local-derivation-goal.cc index 6ba108caa..d4f415bea 100644 --- a/lix/libstore/build/local-derivation-goal.cc +++ b/lix/libstore/build/local-derivation-goal.cc @@ -1276,8 +1276,8 @@ struct RestrictedStore : public virtual IndirectRootStore, public virtual GcStor return {result::current_exception()}; } - std::optional isTrustedClient() override - { return NotTrusted; } + kj::Promise>> isTrustedClient() override + { return {result::success(NotTrusted)}; } }; diff --git a/lix/libstore/daemon.cc b/lix/libstore/daemon.cc index 3c02c6bd1..4c449c6b9 100644 --- a/lix/libstore/daemon.cc +++ b/lix/libstore/daemon.cc @@ -1057,7 +1057,7 @@ void processConnection( // We and the underlying store both need to trust the client for // it to be trusted. auto temp = trusted - ? store->isTrustedClient() + ? aio.blockOn(store->isTrustedClient()) : std::optional { NotTrusted }; WorkerProto::WriteConn wconn {clientVersion}; to << WorkerProto::write(*store, wconn, temp); diff --git a/lix/libstore/dummy-store.cc b/lix/libstore/dummy-store.cc index 3503dee2b..794759112 100644 --- a/lix/libstore/dummy-store.cc +++ b/lix/libstore/dummy-store.cc @@ -42,9 +42,9 @@ struct DummyStore final : public Store /** * The dummy store is incapable of *not* trusting! :) */ - virtual std::optional isTrustedClient() override + virtual kj::Promise>> isTrustedClient() override { - return Trusted; + return {result::success(Trusted)}; } static std::set uriSchemes() { diff --git a/lix/libstore/http-binary-cache-store.cc b/lix/libstore/http-binary-cache-store.cc index cc4d0aadb..39576d740 100644 --- a/lix/libstore/http-binary-cache-store.cc +++ b/lix/libstore/http-binary-cache-store.cc @@ -172,9 +172,9 @@ protected: * * \todo try to expose our HTTP authentication status. */ - std::optional isTrustedClient() override + kj::Promise>> isTrustedClient() override { - return std::nullopt; + return {result::success(std::nullopt)}; } }; diff --git a/lix/libstore/legacy-ssh-store.cc b/lix/libstore/legacy-ssh-store.cc index 4bb67595f..303a13d1f 100644 --- a/lix/libstore/legacy-ssh-store.cc +++ b/lix/libstore/legacy-ssh-store.cc @@ -451,9 +451,9 @@ public: * The legacy ssh protocol doesn't support checking for trusted-user. * Try using ssh-ng:// instead if you want to know. */ - std::optional isTrustedClient() override + kj::Promise>> isTrustedClient() override { - return std::nullopt; + return {result::success(std::nullopt)}; } std::shared_ptr queryRealisationUncached(const DrvOutput &) override diff --git a/lix/libstore/local-binary-cache-store.cc b/lix/libstore/local-binary-cache-store.cc index 1fb0d495a..3df9e7c04 100644 --- a/lix/libstore/local-binary-cache-store.cc +++ b/lix/libstore/local-binary-cache-store.cc @@ -99,9 +99,9 @@ protected: return paths; } - std::optional isTrustedClient() override + kj::Promise>> isTrustedClient() override { - return Trusted; + return {result::success(Trusted)}; } }; diff --git a/lix/libstore/local-store.cc b/lix/libstore/local-store.cc index c51677a23..067b9647b 100644 --- a/lix/libstore/local-store.cc +++ b/lix/libstore/local-store.cc @@ -1745,9 +1745,9 @@ kj::Promise> LocalStore::getProtocol() return {result::success(PROTOCOL_VERSION)}; } -std::optional LocalStore::isTrustedClient() +kj::Promise>> LocalStore::isTrustedClient() { - return Trusted; + return {result::success(Trusted)}; } diff --git a/lix/libstore/local-store.hh b/lix/libstore/local-store.hh index 8b0963c70..84ef9db7f 100644 --- a/lix/libstore/local-store.hh +++ b/lix/libstore/local-store.hh @@ -300,7 +300,7 @@ public: kj::Promise> getProtocol() override; - std::optional isTrustedClient() override; + kj::Promise>> isTrustedClient() override; void addSignatures(const StorePath & storePath, const StringSet & sigs) override; diff --git a/lix/libstore/remote-store.cc b/lix/libstore/remote-store.cc index 4e7c626e1..c313969b2 100644 --- a/lix/libstore/remote-store.cc +++ b/lix/libstore/remote-store.cc @@ -952,11 +952,13 @@ try { co_return result::current_exception(); } -std::optional RemoteStore::isTrustedClient() -{ +kj::Promise>> RemoteStore::isTrustedClient() +try { auto conn(getConnection()); - return conn->remoteTrustsUs; -} + co_return conn->remoteTrustsUs; +} catch (...) { + co_return result::current_exception();} + RemoteStore::Connection::~Connection() diff --git a/lix/libstore/remote-store.hh b/lix/libstore/remote-store.hh index d73c9a280..3a8888118 100644 --- a/lix/libstore/remote-store.hh +++ b/lix/libstore/remote-store.hh @@ -169,7 +169,7 @@ public: kj::Promise> getProtocol() override; - std::optional isTrustedClient() override; + kj::Promise>> isTrustedClient() override; struct Connection; diff --git a/lix/libstore/s3-binary-cache-store.cc b/lix/libstore/s3-binary-cache-store.cc index c71d2b491..51c311556 100644 --- a/lix/libstore/s3-binary-cache-store.cc +++ b/lix/libstore/s3-binary-cache-store.cc @@ -526,9 +526,9 @@ struct S3BinaryCacheStoreImpl : public S3BinaryCacheStore * * \todo try to expose our S3 authentication status. */ - std::optional isTrustedClient() override + kj::Promise>> isTrustedClient() override { - return std::nullopt; + return {result::success(std::nullopt)}; } static std::set uriSchemes() { return {"s3"}; } diff --git a/lix/libstore/store-api.hh b/lix/libstore/store-api.hh index 650c812d2..a4fa04a7d 100644 --- a/lix/libstore/store-api.hh +++ b/lix/libstore/store-api.hh @@ -880,7 +880,7 @@ public: * @note This is the opposite of the StoreConfig::isTrusted * store setting. That is about whether *we* trust the store. */ - virtual std::optional isTrustedClient() = 0; + virtual kj::Promise>> isTrustedClient() = 0; virtual Path toRealPath(const Path & storePath) diff --git a/lix/nix/doctor.cc b/lix/nix/doctor.cc index c7f9d0715..55104828d 100644 --- a/lix/nix/doctor.cc +++ b/lix/nix/doctor.cc @@ -146,7 +146,7 @@ struct CmdDoctor : StoreCommand void checkTrustedUser(ref store) { - auto trustedMay = store->isTrustedClient(); + auto trustedMay = aio().blockOn(store->isTrustedClient()); std::string_view trustedness = trustedMay ? (*trustedMay ? "trusted" : "not trusted") : "unknown trust"; checkInfo(fmt("You are %s by store uri: %s", trustedness, store->getUri())); } diff --git a/lix/nix/ping-store.cc b/lix/nix/ping-store.cc index e0a029327..8f021cfd8 100644 --- a/lix/nix/ping-store.cc +++ b/lix/nix/ping-store.cc @@ -28,7 +28,7 @@ struct CmdPingStore : StoreCommand, MixJSON aio().blockOn(store->connect()); if (auto version = store->getVersion()) notice("Version: %s", *version); - if (auto trusted = store->isTrustedClient()) + if (auto trusted = aio().blockOn(store->isTrustedClient())) notice("Trusted: %s", *trusted); } else { nlohmann::json res; @@ -40,7 +40,7 @@ struct CmdPingStore : StoreCommand, MixJSON aio().blockOn(store->connect()); if (auto version = store->getVersion()) res["version"] = *version; - if (auto trusted = store->isTrustedClient()) + if (auto trusted = aio().blockOn(store->isTrustedClient())) res["trusted"] = *trusted; } }