#pragma once // The ONE table of REST calls the ops package makes (calls.cpp, generated from // Google's Discovery documents by tools/gen_calls.py and re-checked by // tools/check_discovery.py). Code builds every URL from this table, never from // a literal. The rpc id is Discovery's method id (`run.projects.locations.services.get`). #include #include #include #include "clients/request.h" #include "google/endpoints.h" namespace molo::google::ops { struct Product { const char* name; // discovery name, also the rpc id prefix const char* version; // v1, v2, v3 const char* root_url; // https://run.googleapis.com (no trailing slash) const char* service_path; // "compute/v1" or "" when the path carries the version const char* revision; // discovery revision the table was generated from }; // Read never changes state. Write changes or creates state. Destructive // deletes or irreversibly stops something: callers have no default. enum class Safety { kRead, kWrite, kDestructive }; struct CallSpec { const char* rpc; const char* http; // GET POST PATCH PUT DELETE const char* path; // discovery path, e.g. "v2/{+parent}/services" const char* safety; // "R" "W" "D" const char* kind; // "" | "lro" (google.longrunning) | "compute" (compute Operation) const char* items_key; // list response array, "" when not a list call const char* body_fields; // comma list: request body top level fields const char* query_params; // comma list const char* path_shapes; // "name=projects/*/locations/*" per path parameter, space separated Safety safe() const; clients::Method method() const; std::string product() const; // rpc prefix bool has_body_field(std::string_view f) const; bool has_query(std::string_view q) const; bool is_list() const { return items_key[0] != '\0'; } bool is_lro() const { return std::string_view(kind) == "lro"; } bool is_compute_operation() const { return std::string_view(kind) == "compute"; } // Empty when the parameter has no declared shape. std::string shape_of(std::string_view param) const; }; const Product* products(); std::size_t product_count(); const CallSpec* call_table(); std::size_t call_count(); // Throws GoogleError::invalid for an unknown name. const Product& product_named(const std::string& name); const CallSpec& call_named(const std::string& rpc); const CallSpec* find_call(const std::string& rpc); // Where requests go: root_url + service_path. The table path is appended. ServiceEndpoint endpoint_of(const Product& p); // Where google.longrunning operation names are polled: root_url + "/" + version. ServiceEndpoint operation_endpoint_of(const Product& p); } // namespace molo::google::ops