#pragma once // Executes a call from the table. All validation happens before any network // traffic: the call id, path variables, query parameters (only those the // discovery document lists for the call), and the top-level request fields // (only those declared in the table). Lists follow pages under the caps; // mutations wait for their long-running operation (capped). #include #include #include #include #include "google/operation.h" #include "google/registry/calls.h" namespace molo::google::registry { struct CallArgs { std::map vars; // {+parent}, {+name}, ... std::map query; // updateMask, filter, ... clients::body::Json body; // Null: no body. }; class CallRunner { public: CallRunner(std::shared_ptr client, std::string location); // One request, one reply. clients::body::Json invoke(const std::string& call_id, const CallArgs& args) const; // Follows nextPageToken (RegistryCaps::kMaxPages pages of kPageSize) and // returns the concatenated `items_key` array. clients::body::Json list(const std::string& call_id, const std::string& items_key, const CallArgs& args) const; // invoke + wait for the operation the reply describes; returns // {"operation": name}. clients::body::Json mutate(const std::string& call_id, const CallArgs& args) const; // The exact request that invoke() would send: "METHOD path?query". Pure, // no network. Used by tests to compare against the discovery paths. std::string describe(const std::string& call_id, const CallArgs& args) const; // Validated updateMask value: non-empty, every root segment is a request // field declared for `call_id`. Throws GoogleError (invalid). static std::string update_mask(const std::string& call_id, const std::vector& fields); void set_sleeper(Sleeper sleeper) { sleeper_ = std::move(sleeper); } bool configured() const { return client_->configured(); } const std::shared_ptr& client() const { return client_; } const std::string& location() const { return location_; } private: std::string build_path(const CallSpec& call, const CallArgs& args, bool default_page) const; void check_body(const CallSpec& call, const CallArgs& args) const; std::shared_ptr client_; std::string location_; Sleeper sleeper_; }; } // namespace molo::google::registry