diff --git a/example/app/google/OpsDemo.cpp b/example/app/google/OpsDemo.cpp index c11eaa0..ddfa544 100644 --- a/example/app/google/OpsDemo.cpp +++ b/example/app/google/OpsDemo.cpp @@ -1,13 +1,433 @@ #include "../GoogleDemos.hpp" +#include +#include + #include "../../fw/Router.hpp" +#include "../../fw/Templates.hpp" +#include "google/credentials.h" +#include "google/ops/api_state.h" +#include "google/ops/call_plan.h" +#include "google/ops/calls.h" +#include "google/ops/caps.h" +#include "google/ops/ops.h" +#include "google/resource.h" namespace molo::example::app { -// Compute, Cloud Run, Functions, GKE, IAM, Resource Manager, Service Usage, Logging, Monitoring, Build, Artifact Registry. Stub: the package agent fills this in. +// Google Cloud operations (Compute, Cloud Run, Functions, GKE, Build, Artifact +// Registry, IAM, Resource Manager, Service Usage, Logging, Monitoring, +// Scheduler, Tasks, Workflows, Eventarc, Billing, Asset, Org Policy) over the +// real src/google/ops package. GET routes need no credential. Every route that +// calls Google is a POST: 422 on bad input (checked first, against the +// Discovery-derived call table), 503 google_not_configured without a +// credential. Writes and destructive calls are dry runs unless the body says +// "confirm":true; enabling or disabling an API is never done by the page on its +// own and stays a dry run until a human confirms. + +namespace { + +namespace ops = google::ops; +using Json = clients::body::Json; + +constexpr std::size_t kMaxBody = 256 * 1024; +constexpr std::size_t kMaxCallsShown = 500; +constexpr int kDemoPages = 5; + +const char kPage[] = R"GOOGLEOPS({% extends "base.html" %} +{% block content %} +

Google Cloud operations

+

Compute, Cloud Run, Functions, GKE, Build, Artifact Registry, IAM, +Resource Manager, Service Usage, Logging, Monitoring, Scheduler, Tasks, Workflows, +Eventarc, Billing, Asset, Org Policy. Reads run; every change is a dry run until +you tick confirm. Enabling an API is a human decision: the page only shows the plan.

+

Checking Google credentials...

+
+

API state

+ +
+ + +
+

Any call

+ + +

+ + + + +
+ +

+
+ + +{% endblock %} +)GOOGLEOPS"; + +fw::Response json_out(const Json& j, int status = 200) { + fw::Response res = fw::JsonResponse(j.dump(), status); + res.headers.set("Cache-Control", "no-store"); + return res; +} + +[[noreturn]] void bad(const std::string& why) { + throw fw::HttpError(422, "validation_error", why); +} + +std::string project_hint() { return google::Credentials::env("GOOGLE_CLOUD_PROJECT"); } + +[[noreturn]] void rethrow(const google::GoogleError& e) { + if (e.http_status() == 503 && e.status() == "NOT_CONFIGURED") + throw fw::HttpError(503, "google_not_configured", e.message()); + if (e.service().empty() && e.status() == "INVALID_ARGUMENT") + throw fw::HttpError(422, "validation_error", e.message()); + if (auto off = ops::ApiState::disabled(e, project_hint())) + throw fw::HttpError(502, "api_not_enabled", off->loud()); + throw fw::HttpError(502, "google_error", e.status() + ": " + e.message()); +} + +template +auto guarded(F&& f) -> decltype(f()) { + try { + return f(); + } catch (const google::GoogleError& e) { + rethrow(e); + } +} + +Json parse_body(const fw::Request& req) { + if (req.body.size() > kMaxBody) throw fw::HttpError(413, "payload_too_large", "body too large"); + if (req.body.empty()) return Json::object(); + try { + Json j = Json::parse(req.body); + if (!j.is_object()) bad("body must be a JSON object"); + return j; + } catch (const clients::body::JsonError&) { + bad("body is not valid JSON"); + } +} + +std::string text(const Json& body, const char* key, bool required = false) { + const Json* v = body.find(key); + if (!v || v->is_null()) { + if (required) bad(std::string(key) + " is required"); + return ""; + } + if (!v->is_string()) bad(std::string(key) + " must be a string"); + return v->as_string(); +} + +bool flag(const Json& body, const char* key) { + const Json* v = body.find(key); + if (!v || v->is_null()) return false; + if (!v->is_bool()) bad(std::string(key) + " must be true or false"); + return v->as_bool(); +} + +std::string project_of(const Json& body) { + std::string p = text(body, "project"); + if (p.empty()) p = project_hint(); + if (p.empty()) bad("project is required (body.project or GOOGLE_CLOUD_PROJECT)"); + if (!ops::valid_name_segment(p)) bad("project is not a valid project id"); + return p; +} + +// Local checks failing as 422 (library "invalid" = bad input). +template +auto local(F&& f) -> decltype(f()) { + return guarded(std::forward(f)); +} + +class OpsRoutes { + public: + explicit OpsRoutes(std::shared_ptr client) : client_(std::move(client)) {} + + fw::Response status(const fw::Request&) const { + Json o = Json::object(); + o.set("configured", Json(client_->configured())); + o.set("project_set", Json(!project_hint().empty())); + o.set("products", Json(static_cast(ops::product_count()))); + o.set("calls", Json(static_cast(ops::call_count()))); + o.set("max_pages", Json(kDemoPages)); + return json_out(o); + } + + // The discovery-derived table, optionally one product: ?product=run + fw::Response calls(const fw::Request& req) const { + std::string only = req.query_or("product", ""); + Json arr = Json::array(); + Json prods = Json::array(); + for (std::size_t i = 0; i < ops::product_count(); ++i) { + Json p = Json::object(); + p.set("name", Json(ops::products()[i].name)); + p.set("version", Json(ops::products()[i].version)); + p.set("revision", Json(ops::products()[i].revision)); + prods.push(p); + } + std::size_t shown = 0; + for (std::size_t i = 0; i < ops::call_count() && shown < kMaxCallsShown; ++i) { + const ops::CallSpec& c = ops::call_table()[i]; + if (!only.empty() && c.product() != only) continue; + Json row = Json::object(); + row.set("rpc", Json(c.rpc)); + row.set("http", Json(c.http)); + row.set("path", Json(c.path)); + row.set("safety", Json(c.safe() == ops::Safety::kRead + ? "read" + : c.safe() == ops::Safety::kWrite ? "write" : "destructive")); + row.set("list", Json(c.is_list())); + row.set("body_fields", Json(c.body_fields)); + row.set("query", Json(c.query_params)); + arr.push(row); + ++shown; + } + Json o = Json::object(); + o.set("products", prods); + o.set("calls", arr); + return json_out(o); + } + + // Any table row. Body: {"rpc","path":{},"query":{},"body":{},"confirm":bool}. + fw::Response call(const fw::Request& req) const { + Json b = parse_body(req); + std::string rpc = text(b, "rpc", true); + bool confirm = flag(b, "confirm"); + ops::Args args = local([&] { return ops::Args::from_json(b); }); + const ops::CallSpec* spec = ops::find_call(rpc); + if (!spec) bad("unknown call: " + rpc); + ops::CallPlan plan = local([&] { return ops::CallPlan::build(*spec, args); }); + if (spec->safe() != ops::Safety::kRead) { + ops::Outcome out; + out.plan = plan; + if (!confirm) return json_out(out.to_json()); // dry run: no credential needed + need_credential(spec->product()); + return guarded([&] { + return json_out(ops::OpsClient(client_).execute(rpc, args, true).to_json()); + }); + } + need_credential(spec->product()); + return guarded([&] { + ops::OpsClient c(client_); + Json o = Json::object(); + o.set("rpc", Json(rpc)); + if (spec->is_list()) o.set("items", c.list(rpc, args, kDemoPages)); + else o.set("response", c.read(rpc, args)); + return json_out(o); + }); + } + + // Service Usage: list, get, batch_get, enable, disable. enable and disable + // are dry runs unless confirm is true. + fw::Response services(const fw::Request& req) const { + Json b = parse_body(req); + std::string action = text(b, "action", true); + std::string project = project_of(b); + std::string parent = local([&] { return ops::Names::project(project); }); + if (action == "list") { + std::string state = text(b, "state"); + if (!state.empty() && state != "ENABLED" && state != "DISABLED") + bad("state must be ENABLED or DISABLED"); + std::string filter = state.empty() ? "" : "state:" + state; + need_credential("serviceusage"); + return guarded([&] { + ops::ServiceUsage su(client_); + Json items = su.list_services(parent, filter); + Json arr = Json::array(); + for (const Json& item : items.as_array()) { + ops::ServiceState s = ops::ServiceState::from_json(item); + Json row = Json::object(); + row.set("api", Json(s.api)); + row.set("state", Json(s.state)); + row.set("title", Json(s.title)); + arr.push(row); + } + Json o = Json::object(); + o.set("services", arr); + return json_out(o); + }); + } + if (action == "get" || action == "enable" || action == "disable") { + std::string name = local([&] { + return ops::ServiceUsage::service_name(project, text(b, "api", true)); + }); + if (action == "get") { + need_credential("serviceusage"); + return guarded([&] { return json_out(ops::ServiceUsage(client_).service(name)); }); + } + bool confirm = flag(b, "confirm"); + ops::ServiceUsage su(client_); + ops::Outcome out = local([&] { + return action == "enable" ? su.enable(name, false) : su.disable(name, false, false); + }); + if (!confirm) return json_out(out.to_json()); + need_credential("serviceusage"); + return guarded([&] { + return json_out((action == "enable" ? su.enable(name, true) : su.disable(name, false, true)) + .to_json()); + }); + } + if (action == "batch_get") { + const Json* apis = b.find("apis"); + if (!apis || !apis->is_array()) bad("apis must be an array of API names"); + std::vector names; + for (const Json& a : apis->as_array()) { + if (!a.is_string()) bad("apis must be strings"); + names.push_back(local([&] { return ops::ServiceUsage::service_name(project, a.as_string()); })); + } + if (names.empty() || names.size() > ops::OpsCaps::kMaxBatchNames) bad("apis must hold 1..20 names"); + need_credential("serviceusage"); + return guarded([&] { return json_out(ops::ServiceUsage(client_).batch_get(parent, names)); }); + } + bad("action must be list, get, batch_get, enable or disable"); + } + + // Resource Manager: get, search. + fw::Response projects(const fw::Request& req) const { + Json b = parse_body(req); + std::string action = text(b, "action", true); + if (action == "get") { + std::string name = local([&] { return ops::Names::project(project_of(b)); }); + need_credential("cloudresourcemanager"); + return guarded([&] { return json_out(ops::ResourceManager(client_).project(name)); }); + } + if (action == "search") { + std::string query = text(b, "query"); + if (query.size() > 256) bad("query too long"); + need_credential("cloudresourcemanager"); + return guarded([&] { + Json o = Json::object(); + o.set("projects", ops::ResourceManager(client_).search_projects(query)); + return json_out(o); + }); + } + bad("action must be get or search"); + } + + // IAM: service accounts, roles, permission test; signing via IAM Credentials. + fw::Response iam(const fw::Request& req) const { + Json b = parse_body(req); + std::string action = text(b, "action", true); + std::string project = project_of(b); + std::string parent = local([&] { return ops::Names::project(project); }); + if (action == "service_accounts") { + need_credential("iam"); + return guarded([&] { + Json o = Json::object(); + o.set("accounts", ops::Iam(client_).service_accounts(parent)); + return json_out(o); + }); + } + if (action == "roles") { + need_credential("iam"); + return guarded([&] { + Json o = Json::object(); + o.set("roles", ops::Iam(client_).project_roles(parent)); + return json_out(o); + }); + } + if (action == "test_permissions" || action == "sign_jwt" || action == "sign_blob") { + std::string account = text(b, "account", true); + std::string name = local([&] { + std::string n = "projects/" + project + "/serviceAccounts/" + account; + ops::check_resource_name("account", n, "projects/*/serviceAccounts/*"); + return n; + }); + if (action == "test_permissions") { + const Json* perms = b.find("permissions"); + if (!perms || !perms->is_array() || perms->as_array().empty() || perms->as_array().size() > 100) + bad("permissions must be an array of 1..100 strings"); + std::vector list; + for (const Json& p : perms->as_array()) { + if (!p.is_string()) bad("permissions must be strings"); + list.push_back(p.as_string()); + } + need_credential("iam"); + return guarded([&] { return json_out(ops::Iam(client_).test_permissions(name, list)); }); + } + std::string payload = text(b, "payload", true); + if (payload.size() > ops::OpsCaps::kMaxSignPayloadBytes) bad("payload too large"); + need_credential("iamcredentials"); + return guarded([&] { + ops::IamCredentials cr(client_); + return json_out(action == "sign_jwt" ? cr.sign_jwt(name, payload) : cr.sign_blob(name, payload)); + }); + } + bad("action must be service_accounts, roles, test_permissions, sign_jwt or sign_blob"); + } + + // Logging: recent entries of a project. + fw::Response logs(const fw::Request& req) const { + Json b = parse_body(req); + std::string parent = local([&] { return ops::Names::project(project_of(b)); }); + std::string filter = text(b, "filter"); + int limit = 20; + if (const Json* l = b.find("limit"); l && !l->is_null()) { + if (!l->is_number()) bad("limit must be a number"); + limit = static_cast(l->as_int()); + } + if (limit < 1 || limit > 100) bad("limit must be 1..100"); + if (filter.size() > 2048) bad("filter too long"); + need_credential("logging"); + return guarded([&] { + Json o = Json::object(); + o.set("entries", ops::CloudLogging(client_).entries({parent}, filter, "timestamp desc", limit)); + return json_out(o); + }); + } + + private: + void need_credential(const std::string& product) const { + if (!client_->configured()) { + google::NotConfiguredError e(product); + rethrow(e); + } + } + + std::shared_ptr client_; +}; + +} // namespace + void register_google_ops_demo(fw::Router& router, Services& services) { - (void)router; - (void)services; + if (!services.google) services.google = google::GoogleClient::from_env(); + auto client = services.google; + fw::Environment* env = services.templates.get(); + services.templates->add_template("google_ops.html", kPage); + services.add_feature("google-ops", "/google/ops"); + + auto routes = std::make_shared(client); + + router.get("/google/ops", "google-ops-page", [env](fw::Request req) { + (void)req; + fw::TemplateCtx ctx; + ctx["title"] = std::string("Google Cloud operations"); + return fw::Response(200, env->render("google_ops.html", ctx), "text/html; charset=utf-8"); + }); + + using Handler = fw::Response (OpsRoutes::*)(const fw::Request&) const; + auto get = [&](const char* path, const char* name, Handler h) { + router.get(path, name, [routes, h](fw::Request req) { return ((*routes).*h)(req); }); + }; + auto post = [&](const char* path, const char* name, Handler h) { + router.post(path, name, [routes, h](fw::Request req) { return ((*routes).*h)(req); }); + }; + get("/google/ops/status", "google-ops-status", &OpsRoutes::status); + get("/google/ops/calls", "google-ops-calls", &OpsRoutes::calls); + post("/google/ops/call", "google-ops-call", &OpsRoutes::call); + post("/google/ops/services", "google-ops-services", &OpsRoutes::services); + post("/google/ops/projects", "google-ops-projects", &OpsRoutes::projects); + post("/google/ops/iam", "google-ops-iam", &OpsRoutes::iam); + post("/google/ops/logs", "google-ops-logs", &OpsRoutes::logs); } } // namespace molo::example::app diff --git a/example/assets/google_ops.js b/example/assets/google_ops.js new file mode 100644 index 0000000..495031b --- /dev/null +++ b/example/assets/google_ops.js @@ -0,0 +1,81 @@ +// Google Cloud operations page: thin client over /google/ops/* (all limits server side). +(function () { + "use strict"; + var $ = function (id) { return document.getElementById(id); }; + var out = $("go-out"), err = $("go-error"); + var calls = []; + + function show(res) { + return res.text().then(function (t) { + var j; + try { j = JSON.parse(t); } catch (e) { j = { message: t }; } + if (!res.ok) { err.textContent = j.message || ("HTTP " + res.status); out.textContent = ""; } + else { out.textContent = JSON.stringify(j, null, 2); } + }); + } + function post(path, body) { + err.textContent = ""; + out.textContent = "..."; + return fetch(path, { + method: "POST", + headers: { "Content-Type": "application/json" }, + body: JSON.stringify(body) + }).then(show).catch(function (e) { err.textContent = String(e); out.textContent = ""; }); + } + function json(id) { + try { return JSON.parse($(id).value || "{}"); } + catch (e) { err.textContent = "Field " + id + " is not valid JSON"; return null; } + } + function project() { return $("go-project").value.trim(); } + + fetch("/google/ops/status").then(function (r) { return r.json(); }).then(function (s) { + $("go-config").textContent = s.configured + ? "Google credential found. " + s.calls + " calls in " + s.products + " products." + : "No Google credential: calls answer 503 until one is configured."; + }); + + function fillRpcs() { + var p = $("go-product").value, sel = $("go-rpc"); + sel.innerHTML = ""; + calls.filter(function (c) { return c.rpc.split(".")[0] === p; }).forEach(function (c) { + var o = document.createElement("option"); + o.value = c.rpc; + o.textContent = c.rpc.substring(p.length + 1) + " [" + c.safety + "]"; + sel.appendChild(o); + }); + describe(); + } + function describe() { + var c = calls.filter(function (x) { return x.rpc === $("go-rpc").value; })[0]; + $("go-info").textContent = c ? c.http + " " + c.path + (c.query ? " query: " + c.query : "") + + (c.body_fields ? " body: " + c.body_fields : "") : ""; + } + fetch("/google/ops/calls").then(function (r) { return r.json(); }).then(function (d) { + calls = d.calls; + var sel = $("go-product"); + d.products.forEach(function (p) { + var o = document.createElement("option"); + o.value = p.name; + o.textContent = p.name + " " + p.version; + sel.appendChild(o); + }); + fillRpcs(); + }); + $("go-product").onchange = fillRpcs; + $("go-rpc").onchange = describe; + + $("go-enabled").onclick = function () { + post("/google/ops/services", { action: "list", state: "ENABLED", project: project() }); + }; + $("go-iam").onclick = function () { + post("/google/ops/services", { action: "get", api: "iam.googleapis.com", project: project() }); + }; + $("go-send").onclick = function () { + var path = json("go-path"), query = json("go-query"), body = json("go-body"); + if (path === null || query === null || body === null) return; + post("/google/ops/call", { + rpc: $("go-rpc").value, path: path, query: query, body: body, + confirm: $("go-confirm").checked + }); + }; +})(); diff --git a/src/google/ops/SPEC.md b/src/google/ops/SPEC.md new file mode 100644 index 0000000..8553b20 --- /dev/null +++ b/src/google/ops/SPEC.md @@ -0,0 +1,183 @@ +# Google Cloud operations (ops) - Specification + +Owned directory: `src/google/ops/`. Namespace `molo::google::ops`. Depends on +the `src/google` foundation (`GoogleClient`, `Service`, `operation.h`, +`resource.h`). Plan: `plans/18-breadth.md` (method: plans 16 and 17). + +## 1. Scope + +Twenty Discovery APIs, 418 calls, one table: + +| Product object | Discovery API | Typed methods cover | +|---|---|---| +| `Compute` | compute v1 | instances (list, get, insert, start, stop, reset, delete), zones, regions, machine types, disks, networks, subnetworks, firewalls, images, project, zone operations (get, wait) | +| `CloudRun` | run v2 | services, revisions, jobs, executions, tasks, run / cancel / delete, IAM policy | +| `CloudFunctions` | cloudfunctions v2 | functions, runtimes, locations, upload / download URLs, create, delete | +| `Gke` | container v1 | clusters, node pools, operations, server config, create, resize, delete | +| `CloudBuild` | cloudbuild v1 | builds, triggers, worker pools, create / cancel / retry / run, delete | +| `ArtifactRegistry` | artifactregistry v1 | repositories, packages, versions, tags, files, docker images, delete | +| `Iam` | iam v1 | roles, grantable roles, testable permissions, service accounts, keys, policy, testIamPermissions, create / enable / disable / delete | +| `IamCredentials` | iamcredentials v1 | signJwt, signBlob, access token, id token | +| `ResourceManager` | cloudresourcemanager v3 | projects, folders, organizations, liens, tags, IAM policy, testIamPermissions, create / delete | +| `ServiceUsage` | serviceusage v1 | list, get, batchGet, enable, disable, batchEnable, operations | +| `CloudLogging` | logging v2 | entries.list, entries.write, log names, sinks, metrics, exclusions, buckets | +| `CloudMonitoring` | monitoring v3 | time series, metric and resource descriptors, alert policies, channels, groups, uptime checks, services | +| `CloudScheduler` | cloudscheduler v1 | jobs: list, get, create, pause, resume, run, delete | +| `CloudTasks` | cloudtasks v2 | queues, tasks, pause, resume, purge, delete | +| `Workflows`, `WorkflowExecutions` | workflows v1, workflowexecutions v1 | workflows, revisions, executions, step entries, start, cancel | +| `Eventarc` | eventarc v1 | triggers, channels, providers, pipelines, message buses, enrollments | +| `Billing` | cloudbilling v1 | accounts, account projects, project billing info, services, SKUs, link project | +| `CloudAsset` | cloudasset v1 | searchAllResources, searchAllIamPolicies, assets, feeds, saved queries, exportAssets | +| `OrgPolicy` | orgpolicy v2 | constraints, policies, effective policy, custom constraints, create, delete | + +Every one of the 418 rows is also reachable through the generic +`OpsProduct::read / list / call` of its product (a product refuses rows of +another product). Not covered: media upload and download, aggregated compute +lists (map-shaped responses), the legacy `zones` surface of GKE, Cloud Build +GitHub / Bitbucket configs, IAM workforce and workload identity pools, +Logging folder / organization / billing scopes, A2A rows that Cloud Billing's +Discovery document carries by mistake. + +## 2. Module map + +| File | Concern | +|---|---| +| `caps.h` | Static ceilings (`OpsCaps`) | +| `calls.cpp` | GENERATED table of products and calls from Discovery (`tools/gen_calls.py`); never hand edited | +| `calls.h`, `calls_lookup.cpp` | `Product`, `CallSpec`, `Safety`, lookup, endpoints | +| `call_plan.h/.cpp` | `Args`, `CallPlan` (all local validation), resource name checks | +| `ops_client.h/.cpp` | `OpsClient`: read, list (page walk), execute (dry run gate), wait; `Outcome` | +| `ops_product.h/.cpp` | `OpsProduct : Service` base, `Names` | +| `api_state.h/.cpp` | `ApiState`, `DisabledApi`: recognises "API not enabled" | +| one header per product | typed methods (see section 1), `service_usage.cpp` for `ServiceUsage` | +| `ops.h` | `Ops`: all products over one client | +| `tools/gen_calls.py` | Selection list plus generator: everything else is read from Discovery | +| `tools/check_discovery.py` | Fails on any drift between `calls.cpp` and Discovery | + +## 3. Static caps + +| Knob | Value | +|---|---| +| path segment / segments per resource name | 256 chars / 12 | +| rendered path plus query | 1024 chars | +| query value / values of a repeated parameter | 1024 chars / 100 | +| request body | 1 MiB | +| list page walk / items returned | 20 pages (demo 5) / 5000 | +| default page size | 100 | +| batchGet / batchEnable names | 20 | +| logging entries per read / resource names | 1000 (demo 100) / 10 | +| sign payload | 64 KiB | +| operation name | 512 chars, `projects/` or `organizations/` prefix | +| wait for an operation | `operation.h`: 600 s, 400 polls | + +## 4. Contracts + +- Every URL comes from the table. Path parameters are validated against the + shape Discovery declares (`projects/*/locations/*/services/*`), each segment + `[A-Za-z0-9._~@:-]` or `%XX` (never an encoded dot), no `..`. Query keys and + top level body keys must be declared by Discovery; GET and DELETE take no body. + Invalid input is `GoogleError` 400 `INVALID_ARGUMENT` before any traffic. +- No credential: a call that passes validation throws `NotConfiguredError`. +- Safety classes come from the table: read (runs), write, destructive. + `OpsClient::execute(rpc, args, confirm)` has no default for `confirm`; + a write or destructive call with `confirm=false` is a DRY RUN: it returns an + `Outcome` with `executed=false` and the full plan, sends nothing and needs no + credential. Typed write methods default `confirm=false`; typed destructive + methods (delete, purge) have no default. +- `ServiceUsage::enable / disable / batch_enable` are writes with the dry run + default. Enabling an API is the human's job; no code path of this package, + demo or test calls them with `confirm=true`. +- POST rows that only read or sign (getIamPolicy, testIamPermissions, + signJwt, signBlob, entries.list, query verbs, zone operation wait) are + classed read. +- List rows walk `nextPageToken` (query for GET, body for POST) up to the page + and item caps. Long-running rows are tagged `lro` (google.longrunning, poll + with `OpsProduct::wait`) or `compute` (Compute operation, poll with + `zone_operation`); GKE operations are polled by `operation(name)` status. +- A disabled API answers 403; `ApiState::disabled` turns it into + `API NOT ENABLED: , a human enables it at ` and the + demo answers 502 `api_not_enabled`. + +## 5. Example routes (`/google/ops`) + +GET `/google/ops` (page), `/status`, `/calls[?product=]`. POST `/call` (any +row: `{rpc,path,query,body,confirm}`), `/services` (list, get, batch_get, +enable, disable), `/projects` (get, search), `/iam` (service_accounts, roles, +test_permissions, sign_jwt, sign_blob), `/logs`. Validation first (422), then +the credential (503 `google_not_configured`); non-read calls are dry runs +unless `"confirm":true`; oversize body 413. + +## Required APIs + +Enable these on the project (placeholder project `example-214512124`). A +disabled API answers 403 `SERVICE_DISABLED`. + +- `compute.googleapis.com`: https://console.developers.google.com/apis/api/compute.googleapis.com/overview?project=example-214512124 +- `run.googleapis.com`: https://console.developers.google.com/apis/api/run.googleapis.com/overview?project=example-214512124 +- `cloudfunctions.googleapis.com`: https://console.developers.google.com/apis/api/cloudfunctions.googleapis.com/overview?project=example-214512124 +- `container.googleapis.com`: https://console.developers.google.com/apis/api/container.googleapis.com/overview?project=example-214512124 +- `cloudbuild.googleapis.com`: https://console.developers.google.com/apis/api/cloudbuild.googleapis.com/overview?project=example-214512124 +- `artifactregistry.googleapis.com`: https://console.developers.google.com/apis/api/artifactregistry.googleapis.com/overview?project=example-214512124 +- `iam.googleapis.com`: https://console.developers.google.com/apis/api/iam.googleapis.com/overview?project=example-214512124 +- `iamcredentials.googleapis.com`: https://console.developers.google.com/apis/api/iamcredentials.googleapis.com/overview?project=example-214512124 +- `cloudresourcemanager.googleapis.com`: https://console.developers.google.com/apis/api/cloudresourcemanager.googleapis.com/overview?project=example-214512124 +- `serviceusage.googleapis.com`: https://console.developers.google.com/apis/api/serviceusage.googleapis.com/overview?project=example-214512124 +- `logging.googleapis.com`: https://console.developers.google.com/apis/api/logging.googleapis.com/overview?project=example-214512124 +- `monitoring.googleapis.com`: https://console.developers.google.com/apis/api/monitoring.googleapis.com/overview?project=example-214512124 +- `cloudscheduler.googleapis.com`: https://console.developers.google.com/apis/api/cloudscheduler.googleapis.com/overview?project=example-214512124 +- `cloudtasks.googleapis.com`: https://console.developers.google.com/apis/api/cloudtasks.googleapis.com/overview?project=example-214512124 +- `workflows.googleapis.com`: https://console.developers.google.com/apis/api/workflows.googleapis.com/overview?project=example-214512124 +- `workflowexecutions.googleapis.com`: https://console.developers.google.com/apis/api/workflowexecutions.googleapis.com/overview?project=example-214512124 +- `eventarc.googleapis.com`: https://console.developers.google.com/apis/api/eventarc.googleapis.com/overview?project=example-214512124 +- `cloudbilling.googleapis.com`: https://console.developers.google.com/apis/api/cloudbilling.googleapis.com/overview?project=example-214512124 +- `cloudasset.googleapis.com`: https://console.developers.google.com/apis/api/cloudasset.googleapis.com/overview?project=example-214512124 +- `orgpolicy.googleapis.com`: https://console.developers.google.com/apis/api/orgpolicy.googleapis.com/overview?project=example-214512124 + +Scope: all calls use `cloud-platform`; no other scope is needed. + +## Sources + +- Discovery documents fetched 2026-10-25 (`https://.googleapis.com/$discovery/rest?version=`), + revisions recorded per product in `calls.cpp`. + +## Verified against discovery + +`python3 -I src/google/ops/tools/check_discovery.py`, 2026-10-25: +`ops discovery: 20 products, 418 calls` / `discovery ok`. Checks, per row: +HTTP method, path, query parameters (exact set), request body fields (exact +set of non read-only top level fields), path shapes, list item key is an array +of the response, long-running kind, safety consistency; per product: version, +root URL, service path. + +## Verified live + +Service account on project `lisa-448004`, read-only, 2026-10-25 +(`make google-live`, test `ops_live.read_only_probe_of_every_product`): +serviceusage list (49 enabled), get, batchGet; compute zones (130) and +instances (0); iam serviceAccounts (4), roles, testIamPermissions (1 of 1 +held); logging log names (3) and entries; monitoring alert policies (0); +billing project info; cloudasset search (155). `API NOT ENABLED` on the +project for: cloudresourcemanager, run, cloudfunctions, container, +cloudbuild, artifactregistry, cloudscheduler, cloudtasks, workflows, +eventarc, orgpolicy (enabling is the human's job; those product paths are +verified by Discovery only). + +## Unverified + +- Every write and destructive call: never sent to Google by design (dry run + plus Discovery check only), including enable / disable. +- signJwt, signBlob, generateAccessToken, generateIdToken (needs + iamcredentials enabled and impersonation rights); body field names come from + Discovery. +- All responses of the 11 products whose API is not enabled. +- Compute `wait`, long-running `wait()` polling against a real operation. +- `ServiceState` parsing is tested on the documented shape only (no scripted + Google reply); live use parsed real `services.list` output. + +## Gaps + +- Typed response classes exist only for `ServiceState`; other replies are Json. +- GKE and Compute operations have no wait helper (poll `operation` / + `zone_operation`). +- Folder and organization scopes of Logging, Org Policy writes outside + projects: reachable only through generic `call` rows that were selected. diff --git a/src/google/ops/api_state.cpp b/src/google/ops/api_state.cpp new file mode 100644 index 0000000..880215c --- /dev/null +++ b/src/google/ops/api_state.cpp @@ -0,0 +1,42 @@ +#include "google/ops/api_state.h" + +namespace molo::google::ops { + +std::string DisabledApi::loud() const { + return "API NOT ENABLED: " + (service.empty() ? std::string("(unnamed)") : service) + + (activation_url.empty() ? "" : ", a human enables it at " + activation_url); +} + +std::string ApiState::service_in(const std::string& text) { + const std::string suffix = ".googleapis.com"; + std::size_t at = 0; + while ((at = text.find(suffix, at)) != std::string::npos) { + std::size_t start = at; + while (start > 0) { + char c = text[start - 1]; + if ((c >= 'a' && c <= 'z') || (c >= '0' && c <= '9') || c == '-') --start; + else break; + } + if (start < at) return text.substr(start, at + suffix.size() - start); + at += suffix.size(); + } + return ""; +} + +std::optional ApiState::disabled(const GoogleError& e, const std::string& project) { + if (e.http_status() != 403) return std::nullopt; + const std::string& m = e.message(); + bool off = e.status() == "SERVICE_DISABLED" || + m.find("has not been used in project") != std::string::npos || + m.find("it is disabled") != std::string::npos || + m.find("SERVICE_DISABLED") != std::string::npos; + if (!off) return std::nullopt; + DisabledApi d; + d.service = service_in(m); + if (!d.service.empty() && !project.empty()) + d.activation_url = "https://console.developers.google.com/apis/api/" + d.service + + "/overview?project=" + project; + return d; +} + +} // namespace molo::google::ops diff --git a/src/google/ops/api_state.h b/src/google/ops/api_state.h new file mode 100644 index 0000000..7681346 --- /dev/null +++ b/src/google/ops/api_state.h @@ -0,0 +1,31 @@ +#pragma once + +// Recognises "the API is not enabled on this project" so callers can say so +// loudly instead of showing a bare 403. Enabling is a human decision: this +// class only reports. + +#include +#include + +#include "google/errors.h" + +namespace molo::google::ops { + +struct DisabledApi { + std::string service; // e.g. iam.googleapis.com ("" when Google named none) + std::string activation_url; // console page where a human enables it + // "API NOT ENABLED: iam.googleapis.com, enable it at https://..." + std::string loud() const; +}; + +class ApiState { + public: + // Set when the error is Google's "has not been used in project ... or it is + // disabled" / SERVICE_DISABLED answer (HTTP 403). + static std::optional disabled(const GoogleError& error, + const std::string& project); + // "services/serviceusage.googleapis.com" style segment of the API host in a text. + static std::string service_in(const std::string& text); +}; + +} // namespace molo::google::ops diff --git a/src/google/ops/artifact_registry.h b/src/google/ops/artifact_registry.h new file mode 100644 index 0000000..5f0a7c7 --- /dev/null +++ b/src/google/ops/artifact_registry.h @@ -0,0 +1,72 @@ +#pragma once + +// Artifact Registry v1. `parent` is projects/{p}/locations/{l}; deeper names +// are full resource names (.../repositories/{r}/packages/{pkg}). + +#include "google/ops/ops_product.h" + +namespace molo::google::ops { + +class ArtifactRegistry : public OpsProduct { + public: + using Json = clients::body::Json; + explicit ArtifactRegistry(std::shared_ptr c, Sleeper s = nullptr) + : OpsProduct(std::move(c), "artifactregistry", std::move(s)) {} + + Json locations(const std::string& project_name) const { + return list("artifactregistry.projects.locations.list", at("name", project_name)); + } + Json repositories(const std::string& parent) const { + return list("artifactregistry.projects.locations.repositories.list", at("parent", parent)); + } + Json repository(const std::string& name) const { + return read("artifactregistry.projects.locations.repositories.get", at("name", name)); + } + Json packages(const std::string& repository_name) const { + return list("artifactregistry.projects.locations.repositories.packages.list", + at("parent", repository_name)); + } + Json versions(const std::string& package_name) const { + return list("artifactregistry.projects.locations.repositories.packages.versions.list", + at("parent", package_name)); + } + Json tags(const std::string& package_name) const { + return list("artifactregistry.projects.locations.repositories.packages.tags.list", + at("parent", package_name)); + } + Json files(const std::string& repository_name) const { + return list("artifactregistry.projects.locations.repositories.files.list", + at("parent", repository_name)); + } + Json docker_images(const std::string& repository_name) const { + return list("artifactregistry.projects.locations.repositories.dockerImages.list", + at("parent", repository_name)); + } + Json project_settings(const std::string& name) const { + return read("artifactregistry.projects.getProjectSettings", at("name", name)); + } + Json operation(const std::string& name) const { + return read("artifactregistry.projects.locations.operations.get", at("name", name)); + } + + Outcome create_repository(const std::string& parent, const std::string& repository_id, + const Json& repository, bool confirm = false) const { + Args a = at("parent", parent); + a.query("repositoryId", Json(repository_id)).body(repository); + return call("artifactregistry.projects.locations.repositories.create", a, confirm); + } + Outcome delete_repository(const std::string& name, bool confirm) const { + return call("artifactregistry.projects.locations.repositories.delete", at("name", name), + confirm); + } + Outcome delete_package(const std::string& name, bool confirm) const { + return call("artifactregistry.projects.locations.repositories.packages.delete", + at("name", name), confirm); + } + Outcome delete_version(const std::string& name, bool confirm) const { + return call("artifactregistry.projects.locations.repositories.packages.versions.delete", + at("name", name), confirm); + } +}; + +} // namespace molo::google::ops diff --git a/src/google/ops/billing.h b/src/google/ops/billing.h new file mode 100644 index 0000000..1f996f0 --- /dev/null +++ b/src/google/ops/billing.h @@ -0,0 +1,45 @@ +#pragma once + +// Cloud Billing v1: accounts, the billing link of a project, the public +// catalog (services, SKUs). Re-linking a project to another account is a +// write (dry run unless confirm) and moves cost. + +#include "google/ops/ops_product.h" + +namespace molo::google::ops { + +class Billing : public OpsProduct { + public: + using Json = clients::body::Json; + explicit Billing(std::shared_ptr c, Sleeper s = nullptr) + : OpsProduct(std::move(c), "cloudbilling", std::move(s)) {} + + Json accounts() const { return list("cloudbilling.billingAccounts.list", Args()); } + Json account(const std::string& name) const { + return read("cloudbilling.billingAccounts.get", at("name", name)); + } + Json account_projects(const std::string& account_name) const { + return list("cloudbilling.billingAccounts.projects.list", at("name", account_name)); + } + Json account_policy(const std::string& account_name) const { + return read("cloudbilling.billingAccounts.getIamPolicy", at("resource", account_name)); + } + Json project_billing_info(const std::string& project_name) const { + return read("cloudbilling.projects.getBillingInfo", at("name", project_name)); + } + Json services() const { return list("cloudbilling.services.list", Args()); } + // service_name: services/{id} + Json skus(const std::string& service_name) const { + return list("cloudbilling.services.skus.list", at("parent", service_name), 5); + } + + // billing_account_name: billingAccounts/{id}, or "" to unlink the project. + Outcome link_project(const std::string& project_name, const std::string& billing_account_name, + bool confirm = false) const { + Args a = at("name", project_name); + a.field("billingAccountName", Json(billing_account_name)); + return call("cloudbilling.projects.updateBillingInfo", a, confirm); + } +}; + +} // namespace molo::google::ops diff --git a/src/google/ops/call_plan.cpp b/src/google/ops/call_plan.cpp new file mode 100644 index 0000000..85f63dc --- /dev/null +++ b/src/google/ops/call_plan.cpp @@ -0,0 +1,208 @@ +#include "google/ops/call_plan.h" + +#include + +#include "clients/url.h" +#include "google/errors.h" +#include "google/ops/caps.h" + +namespace molo::google::ops { + +using clients::body::Json; + +namespace { + +bool hex(char c) { + return (c >= '0' && c <= '9') || (c >= 'a' && c <= 'f') || (c >= 'A' && c <= 'F'); +} + +std::string lower(std::string s) { + for (char& c : s) + if (c >= 'A' && c <= 'Z') c = static_cast(c - 'A' + 'a'); + return s; +} + +[[noreturn]] void bad(const std::string& why) { throw GoogleError::invalid(why); } + +std::string query_value(const std::string& key, const Json& v) { + if (v.is_string()) { + if (v.as_string().size() > OpsCaps::kMaxQueryValueChars) bad(key + " too long"); + return clients::Url::encode_component(v.as_string()); + } + if (v.is_bool()) return v.as_bool() ? "true" : "false"; + if (v.is_number()) { + double d = v.as_number(); + if (d != std::floor(d) || std::fabs(d) > 1e15) bad(key + " must be an integer"); + return std::to_string(static_cast(d)); + } + bad(key + " must be a string, number or boolean"); +} + +} // namespace + +bool valid_name_segment(const std::string& s) { + if (s.empty() || s.size() > OpsCaps::kMaxSegmentChars || s == "." || s == "..") return false; + for (std::size_t i = 0; i < s.size(); ++i) { + char c = s[i]; + if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9') || + c == '-' || c == '_' || c == '.' || c == '~' || c == '@' || c == ':') + continue; + if (c == '%' && i + 2 < s.size() + 0 && hex(s[i + 1]) && hex(s[i + 2])) { + if (lower(s.substr(i, 3)) == "%2e") return false; // no encoded dots + i += 2; + continue; + } + return false; + } + return true; +} + +void check_resource_name(const std::string& what, const std::string& value, + const std::string& shape) { + std::vector parts, want; + auto split = [](const std::string& s, std::vector& out) { + std::size_t at = 0; + while (true) { + std::size_t end = s.find('/', at); + out.push_back(s.substr(at, end == std::string::npos ? end : end - at)); + if (end == std::string::npos) break; + at = end + 1; + } + }; + split(value, parts); + if (parts.size() > OpsCaps::kMaxSegments) bad(what + " has too many segments"); + for (const std::string& p : parts) + if (!valid_name_segment(p)) bad(what + " has an invalid segment"); + if (shape.empty()) return; + split(shape, want); + if (parts.size() != want.size()) bad(what + " must look like " + shape); + for (std::size_t i = 0; i < want.size(); ++i) + if (want[i] != "*" && want[i] != parts[i]) bad(what + " must look like " + shape); +} + +// --- Args --------------------------------------------------------------------- + +Args& Args::path(const std::string& name, const std::string& value) { + path_.set(name, Json(value)); + return *this; +} +Args& Args::query(const std::string& name, const Json& value) { + query_.set(name, value); + return *this; +} +Args& Args::body(Json value) { + body_ = std::move(value); + return *this; +} +Args& Args::field(const std::string& name, Json value) { + if (!body_.is_object()) body_ = Json::object(); + body_.set(name, std::move(value)); + return *this; +} + +Args Args::from_json(const Json& doc) { + Args a; + if (!doc.is_object()) bad("arguments must be a JSON object"); + for (const char* key : {"path", "query", "body"}) { + const Json* v = doc.find(key); + if (v && !v->is_null() && !v->is_object()) bad(std::string(key) + " must be a JSON object"); + } + if (const Json* p = doc.find("path"); p && p->is_object()) + for (const auto& [k, v] : p->as_object()) { + if (!v.is_string()) bad("path." + k + " must be a string"); + a.path(k, v.as_string()); + } + if (const Json* q = doc.find("query"); q && q->is_object()) + for (const auto& [k, v] : q->as_object()) a.query(k, v); + if (const Json* b = doc.find("body"); b && b->is_object()) a.body(*b); + return a; +} + +// --- CallPlan ----------------------------------------------------------------- + +CallPlan CallPlan::build(const CallSpec& spec, const Args& args) { + CallPlan plan; + plan.spec_ = &spec; + + // Path: every {x} / {+x} must be supplied; nothing else may be. + std::string tmpl = spec.path, rendered; + std::vector used; + for (std::size_t i = 0; i < tmpl.size();) { + if (tmpl[i] != '{') { + rendered += tmpl[i++]; + continue; + } + std::size_t close = tmpl.find('}', i); + if (close == std::string::npos) bad("bad path template"); + std::string name = tmpl.substr(i + 1, close - i - 1); + bool multi = !name.empty() && name[0] == '+'; + if (multi) name.erase(0, 1); + const Json* v = args.path_args().find(name); + if (!v || !v->is_string()) bad("path parameter " + name + " is required"); + const std::string& value = v->as_string(); + if (multi) check_resource_name(name, value, spec.shape_of(name)); + else if (!valid_name_segment(value)) bad("path parameter " + name + " is invalid"); + rendered += value; + used.push_back(name); + i = close + 1; + } + for (const auto& [k, v] : args.path_args().as_object()) { + (void)v; + bool known = false; + for (const std::string& u : used) known = known || u == k; + if (!known) bad("unknown path parameter " + k); + } + + // Query: only declared parameters; arrays repeat the key. + std::string query; + for (const auto& [k, v] : args.query_args().as_object()) { + if (!spec.has_query(k)) bad("unknown query parameter " + k + " for " + spec.rpc); + if (v.is_null()) continue; + if (v.is_array()) { + if (v.as_array().size() > OpsCaps::kMaxQueryValues) bad(k + " has too many values"); + for (const Json& item : v.as_array()) { + if (!item.is_string()) bad(k + " values must be strings"); + query += (query.empty() ? "" : "&") + k + "=" + query_value(k, item); + } + } else { + query += (query.empty() ? "" : "&") + k + "=" + query_value(k, v); + } + } + plan.path_ = "/" + rendered + (query.empty() ? "" : "?" + query); + if (plan.path_.size() > OpsCaps::kMaxPathChars) bad("request path too long"); + + // Body: only the declared top level fields; bodiless verbs take none. + bool bodiless = spec.method() == clients::Method::kGet || + spec.method() == clients::Method::kDelete; + if (args.has_body()) { + if (!args.body_arg().is_object()) bad("body must be a JSON object"); + if (bodiless && !args.body_arg().as_object().empty()) + bad(std::string(spec.rpc) + " takes no request body"); + for (const auto& [k, v] : args.body_arg().as_object()) { + (void)v; + if (!spec.has_body_field(k)) bad("unknown body field " + k + " for " + spec.rpc); + } + if (args.body_arg().dump().size() > OpsCaps::kMaxBodyBytes) bad("body too large"); + } + if (!bodiless) { + plan.has_body_ = true; + plan.body_ = args.has_body() ? args.body_arg() : Json::object(); + } + return plan; +} + +std::string CallPlan::url() const { return endpoint_of(product_named(spec_->product())).base_url + path_; } + +Json CallPlan::to_json() const { + Json o = Json::object(); + o.set("rpc", Json(spec_->rpc)); + o.set("http", Json(spec_->http)); + o.set("url", Json(url())); + o.set("safety", Json(spec_->safe() == Safety::kRead + ? "read" + : spec_->safe() == Safety::kWrite ? "write" : "destructive")); + if (has_body_) o.set("body", body_); + return o; +} + +} // namespace molo::google::ops diff --git a/src/google/ops/call_plan.h b/src/google/ops/call_plan.h new file mode 100644 index 0000000..242207a --- /dev/null +++ b/src/google/ops/call_plan.h @@ -0,0 +1,70 @@ +#pragma once + +// A validated, not yet sent request: the table row plus path, query and body +// arguments. Building a plan does all local validation (no network, no +// credential), so a plan can also be shown as a dry run. + +#include +#include +#include + +#include "clients/body/json.h" +#include "google/ops/calls.h" + +namespace molo::google::ops { + +// Arguments of one call. Path and query values are strings (query also +// numbers, bools and string arrays); the body is a JSON object. +class Args { + public: + Args& path(const std::string& name, const std::string& value); + Args& query(const std::string& name, const clients::body::Json& value); + Args& body(clients::body::Json value); + // One body field. + Args& field(const std::string& name, clients::body::Json value); + + const clients::body::Json& path_args() const { return path_; } + const clients::body::Json& query_args() const { return query_; } + const clients::body::Json& body_arg() const { return body_; } + bool has_body() const { return !body_.is_null(); } + + // From the JSON shape used by the demo: {"path":{},"query":{},"body":{}}. + static Args from_json(const clients::body::Json& doc); + + private: + clients::body::Json path_ = clients::body::Json::object(); + clients::body::Json query_ = clients::body::Json::object(); + clients::body::Json body_; +}; + +class CallPlan { + public: + // Throws GoogleError 400 INVALID_ARGUMENT on any violation. + static CallPlan build(const CallSpec& spec, const Args& args); + + const CallSpec& spec() const { return *spec_; } + clients::Method method() const { return spec_->method(); } + const std::string& path() const { return path_; } // "/v2/projects/p/...?x=y" + bool has_body() const { return has_body_; } + const clients::body::Json& body() const { return body_; } + // Full URL for display: endpoint base + path. + std::string url() const; + // {"rpc","http","url","safety","body"} for dry runs and logs (no credential). + clients::body::Json to_json() const; + + private: + const CallSpec* spec_ = nullptr; + std::string path_; + bool has_body_ = false; + clients::body::Json body_; +}; + +// Segment and resource-name validation shared by plan building and the typed +// helpers: each segment 1..256 of [A-Za-z0-9._~@:%-], not "." or "..". +bool valid_name_segment(const std::string& s); +// A resource name: segments split by '/', matching `shape` ("projects/*/x/*") +// segment for segment when the shape is not empty. +void check_resource_name(const std::string& what, const std::string& value, + const std::string& shape); + +} // namespace molo::google::ops diff --git a/src/google/ops/calls.cpp b/src/google/ops/calls.cpp new file mode 100644 index 0000000..302e1e9 --- /dev/null +++ b/src/google/ops/calls.cpp @@ -0,0 +1,460 @@ +// GENERATED by tools/gen_calls.py from Google's Discovery documents; do not edit. +// tools/check_discovery.py re-reads this file and fails on any drift. +#include "google/ops/calls.h" + +namespace molo::google::ops { + +// PRODUCTS-BEGIN (name, version, root url, service path, discovery revision) +static const Product kProducts[] = { + {"compute", "v1", "https://compute.googleapis.com", "compute/v1", "20261016"}, + {"run", "v2", "https://run.googleapis.com", "", "20261016"}, + {"cloudfunctions", "v2", "https://cloudfunctions.googleapis.com", "", "20261015"}, + {"container", "v1", "https://container.googleapis.com", "", "20260922"}, + {"cloudbuild", "v1", "https://cloudbuild.googleapis.com", "", "20261010"}, + {"artifactregistry", "v1", "https://artifactregistry.googleapis.com", "", "20261022"}, + {"iam", "v1", "https://iam.googleapis.com", "", "20261016"}, + {"iamcredentials", "v1", "https://iamcredentials.googleapis.com", "", "20261013"}, + {"cloudresourcemanager", "v3", "https://cloudresourcemanager.googleapis.com", "", "20261018"}, + {"serviceusage", "v1", "https://serviceusage.googleapis.com", "", "20261013"}, + {"logging", "v2", "https://logging.googleapis.com", "", "20261016"}, + {"monitoring", "v3", "https://monitoring.googleapis.com", "", "20261015"}, + {"cloudscheduler", "v1", "https://cloudscheduler.googleapis.com", "", "20261020"}, + {"cloudtasks", "v2", "https://cloudtasks.googleapis.com", "", "20261005"}, + {"workflows", "v1", "https://workflows.googleapis.com", "", "20261007"}, + {"workflowexecutions", "v1", "https://workflowexecutions.googleapis.com", "", "20261012"}, + {"eventarc", "v1", "https://eventarc.googleapis.com", "", "20261014"}, + {"cloudbilling", "v1", "https://cloudbilling.googleapis.com", "", "20261016"}, + {"cloudasset", "v1", "https://cloudasset.googleapis.com", "", "20261017"}, + {"orgpolicy", "v2", "https://orgpolicy.googleapis.com", "", "20261015"}, +}; +// PRODUCTS-END + +// CALLS-BEGIN (rpc, http, path, safety R/W/D, kind, items key, body fields, query params, path shapes) +static const CallSpec kCalls[] = { + {"compute.instances.list", "GET", "projects/{project}/zones/{zone}/instances", "R", "", "items", "", "pageToken,maxResults,returnPartialSuccess,filter,orderBy", "project= zone="}, + {"compute.instances.get", "GET", "projects/{project}/zones/{zone}/instances/{instance}", "R", "", "", "", "", "project= zone= instance="}, + {"compute.instances.insert", "POST", "projects/{project}/zones/{zone}/instances", "W", "compute", "", "instanceEncryptionKey,sourceMachineImage,labelFingerprint,sourceMachineImageEncryptionKey,workloadIdentityConfig,reservationAffinity,serviceAccounts,params,minCpuPlatform,localSsdEncryptionMode,description,scheduling,shieldedInstanceConfig,canIpForward,fingerprint,name,displayDevice,guestAccelerators,tags,shieldedInstanceIntegrityPolicy,privateIpv6GoogleAccess,metadata,advancedMachineFeatures,labels,keyRevocationActionType,resourcePolicies,confidentialInstanceConfig,deletionProtection,hostname,networkPerformanceConfig,disks,networkInterfaces,machineType", "sourceInstanceTemplate,sourceMachineImage,requestId", "project= zone="}, + {"compute.instances.delete", "DELETE", "projects/{project}/zones/{zone}/instances/{instance}", "D", "compute", "", "", "requestId,noGracefulShutdown", "project= zone= instance="}, + {"compute.instances.start", "POST", "projects/{project}/zones/{zone}/instances/{instance}/start", "W", "compute", "", "", "requestId", "project= zone= instance="}, + {"compute.instances.stop", "POST", "projects/{project}/zones/{zone}/instances/{instance}/stop", "W", "compute", "", "", "requestId,discardLocalSsd,noGracefulShutdown", "project= zone= instance="}, + {"compute.instances.reset", "POST", "projects/{project}/zones/{zone}/instances/{instance}/reset", "W", "compute", "", "", "requestId", "project= zone= instance="}, + {"compute.zones.list", "GET", "projects/{project}/zones", "R", "", "items", "", "pageToken,orderBy,maxResults,returnPartialSuccess,filter", "project="}, + {"compute.zones.get", "GET", "projects/{project}/zones/{zone}", "R", "", "", "", "", "project= zone="}, + {"compute.regions.list", "GET", "projects/{project}/regions", "R", "", "items", "", "maxResults,returnPartialSuccess,orderBy,pageToken,filter", "project="}, + {"compute.regions.get", "GET", "projects/{project}/regions/{region}", "R", "", "", "", "", "project= region="}, + {"compute.machineTypes.list", "GET", "projects/{project}/zones/{zone}/machineTypes", "R", "", "items", "", "returnPartialSuccess,maxResults,orderBy,pageToken,filter", "project= zone="}, + {"compute.machineTypes.get", "GET", "projects/{project}/zones/{zone}/machineTypes/{machineType}", "R", "", "", "", "", "project= zone= machineType="}, + {"compute.disks.list", "GET", "projects/{project}/zones/{zone}/disks", "R", "", "items", "", "returnPartialSuccess,filter,orderBy,maxResults,pageToken", "project= zone="}, + {"compute.disks.get", "GET", "projects/{project}/zones/{zone}/disks/{disk}", "R", "", "", "", "", "project= zone= disk="}, + {"compute.networks.list", "GET", "projects/{project}/global/networks", "R", "", "items", "", "maxResults,returnPartialSuccess,filter,orderBy,pageToken", "project="}, + {"compute.networks.get", "GET", "projects/{project}/global/networks/{network}", "R", "", "", "", "", "project= network="}, + {"compute.subnetworks.list", "GET", "projects/{project}/regions/{region}/subnetworks", "R", "", "items", "", "filter,maxResults,returnPartialSuccess,orderBy,views,pageToken", "project= region="}, + {"compute.subnetworks.get", "GET", "projects/{project}/regions/{region}/subnetworks/{subnetwork}", "R", "", "", "", "views", "project= region= subnetwork="}, + {"compute.firewalls.list", "GET", "projects/{project}/global/firewalls", "R", "", "items", "", "returnPartialSuccess,orderBy,pageToken,filter,maxResults", "project="}, + {"compute.firewalls.get", "GET", "projects/{project}/global/firewalls/{firewall}", "R", "", "", "", "", "project= firewall="}, + {"compute.images.list", "GET", "projects/{project}/global/images", "R", "", "items", "", "orderBy,maxResults,filter,returnPartialSuccess,pageToken", "project="}, + {"compute.images.get", "GET", "projects/{project}/global/images/{image}", "R", "", "", "", "", "project= image="}, + {"compute.addresses.list", "GET", "projects/{project}/regions/{region}/addresses", "R", "", "items", "", "returnPartialSuccess,filter,orderBy,maxResults,pageToken", "project= region="}, + {"compute.instanceTemplates.list", "GET", "projects/{project}/global/instanceTemplates", "R", "", "items", "", "pageToken,filter,orderBy,returnPartialSuccess,maxResults", "project="}, + {"compute.instanceTemplates.get", "GET", "projects/{project}/global/instanceTemplates/{instanceTemplate}", "R", "", "", "", "", "project= instanceTemplate="}, + {"compute.instanceGroups.list", "GET", "projects/{project}/zones/{zone}/instanceGroups", "R", "", "items", "", "pageToken,orderBy,maxResults,filter,returnPartialSuccess", "project= zone="}, + {"compute.snapshots.list", "GET", "projects/{project}/global/snapshots", "R", "", "items", "", "maxResults,pageToken,orderBy,returnPartialSuccess,filter", "project="}, + {"compute.snapshots.get", "GET", "projects/{project}/global/snapshots/{snapshot}", "R", "", "", "", "", "project= snapshot="}, + {"compute.backendServices.list", "GET", "projects/{project}/global/backendServices", "R", "", "items", "", "orderBy,filter,returnPartialSuccess,maxResults,pageToken", "project="}, + {"compute.forwardingRules.list", "GET", "projects/{project}/regions/{region}/forwardingRules", "R", "", "items", "", "pageToken,orderBy,maxResults,returnPartialSuccess,filter", "project= region="}, + {"compute.projects.get", "GET", "projects/{project}", "R", "", "", "", "", "project="}, + {"compute.zoneOperations.list", "GET", "projects/{project}/zones/{zone}/operations", "R", "", "items", "", "filter,maxResults,orderBy,pageToken,returnPartialSuccess", "project= zone="}, + {"compute.zoneOperations.get", "GET", "projects/{project}/zones/{zone}/operations/{operation}", "R", "compute", "", "", "", "project= zone= operation="}, + {"compute.zoneOperations.wait", "POST", "projects/{project}/zones/{zone}/operations/{operation}/wait", "R", "compute", "", "", "", "project= zone= operation="}, + {"compute.globalOperations.list", "GET", "projects/{project}/global/operations", "R", "", "items", "", "maxResults,returnPartialSuccess,pageToken,orderBy,filter", "project="}, + {"compute.globalOperations.get", "GET", "projects/{project}/global/operations/{operation}", "R", "compute", "", "", "", "project= operation="}, + {"compute.regionOperations.list", "GET", "projects/{project}/regions/{region}/operations", "R", "", "items", "", "orderBy,filter,returnPartialSuccess,pageToken,maxResults", "project= region="}, + {"compute.regionOperations.get", "GET", "projects/{project}/regions/{region}/operations/{operation}", "R", "compute", "", "", "", "project= region= operation="}, + {"run.projects.locations.services.list", "GET", "v2/{+parent}/services", "R", "", "services", "", "showDeleted,pageSize,pageToken", "parent=projects/*/locations/*"}, + {"run.projects.locations.services.get", "GET", "v2/{+name}", "R", "", "", "", "", "name=projects/*/locations/*/services/*"}, + {"run.projects.locations.services.create", "POST", "v2/{+parent}/services", "W", "lro", "", "annotations,name,multiRegionSettings,template,customAudiences,binaryAuthorization,labels,traffic,launchStage,invokerIamDisabled,description,ingress,scaling,clientVersion,etag,defaultUriDisabled,iapEnabled,buildConfig,sshEnabled,client,functionalType", "validateOnly,serviceId", "parent=projects/*/locations/*"}, + {"run.projects.locations.services.patch", "PATCH", "v2/{+name}", "W", "lro", "", "annotations,name,multiRegionSettings,template,customAudiences,binaryAuthorization,labels,traffic,launchStage,invokerIamDisabled,description,ingress,scaling,clientVersion,etag,defaultUriDisabled,iapEnabled,buildConfig,sshEnabled,client,functionalType", "allowMissing,forceNewRevision,updateMask,validateOnly", "name=projects/*/locations/*/services/*"}, + {"run.projects.locations.services.delete", "DELETE", "v2/{+name}", "D", "lro", "", "", "validateOnly,etag", "name=projects/*/locations/*/services/*"}, + {"run.projects.locations.services.getIamPolicy", "GET", "v2/{+resource}:getIamPolicy", "R", "", "", "", "options.requestedPolicyVersion", "resource=projects/*/locations/*/services/*"}, + {"run.projects.locations.services.setIamPolicy", "POST", "v2/{+resource}:setIamPolicy", "W", "", "", "policy,updateMask", "", "resource=projects/*/locations/*/services/*"}, + {"run.projects.locations.services.testIamPermissions", "POST", "v2/{+resource}:testIamPermissions", "R", "", "", "permissions", "", "resource=projects/*/locations/*/services/*"}, + {"run.projects.locations.services.revisions.list", "GET", "v2/{+parent}/revisions", "R", "", "revisions", "", "showDeleted,pageToken,pageSize", "parent=projects/*/locations/*/services/*"}, + {"run.projects.locations.services.revisions.get", "GET", "v2/{+name}", "R", "", "", "", "", "name=projects/*/locations/*/services/*/revisions/*"}, + {"run.projects.locations.services.revisions.delete", "DELETE", "v2/{+name}", "D", "lro", "", "", "validateOnly,etag", "name=projects/*/locations/*/services/*/revisions/*"}, + {"run.projects.locations.jobs.list", "GET", "v2/{+parent}/jobs", "R", "", "jobs", "", "showDeleted,pageToken,pageSize", "parent=projects/*/locations/*"}, + {"run.projects.locations.jobs.get", "GET", "v2/{+name}", "R", "", "", "", "", "name=projects/*/locations/*/jobs/*"}, + {"run.projects.locations.jobs.create", "POST", "v2/{+parent}/jobs", "W", "lro", "", "launchStage,etag,clientVersion,template,labels,functionalType,annotations,runExecutionToken,name,binaryAuthorization,startExecutionToken,client", "validateOnly,jobId", "parent=projects/*/locations/*"}, + {"run.projects.locations.jobs.patch", "PATCH", "v2/{+name}", "W", "lro", "", "launchStage,etag,clientVersion,template,labels,functionalType,annotations,runExecutionToken,name,binaryAuthorization,startExecutionToken,client", "allowMissing,validateOnly", "name=projects/*/locations/*/jobs/*"}, + {"run.projects.locations.jobs.delete", "DELETE", "v2/{+name}", "D", "lro", "", "", "etag,validateOnly", "name=projects/*/locations/*/jobs/*"}, + {"run.projects.locations.jobs.run", "POST", "v2/{+name}:run", "W", "lro", "", "etag,overrides,validateOnly", "", "name=projects/*/locations/*/jobs/*"}, + {"run.projects.locations.jobs.getIamPolicy", "GET", "v2/{+resource}:getIamPolicy", "R", "", "", "", "options.requestedPolicyVersion", "resource=projects/*/locations/*/jobs/*"}, + {"run.projects.locations.jobs.setIamPolicy", "POST", "v2/{+resource}:setIamPolicy", "W", "", "", "policy,updateMask", "", "resource=projects/*/locations/*/jobs/*"}, + {"run.projects.locations.jobs.testIamPermissions", "POST", "v2/{+resource}:testIamPermissions", "R", "", "", "permissions", "", "resource=projects/*/locations/*/jobs/*"}, + {"run.projects.locations.jobs.executions.list", "GET", "v2/{+parent}/executions", "R", "", "executions", "", "showDeleted,pageToken,pageSize", "parent=projects/*/locations/*/jobs/*"}, + {"run.projects.locations.jobs.executions.get", "GET", "v2/{+name}", "R", "", "", "", "", "name=projects/*/locations/*/jobs/*/executions/*"}, + {"run.projects.locations.jobs.executions.cancel", "POST", "v2/{+name}:cancel", "W", "lro", "", "etag,validateOnly", "", "name=projects/*/locations/*/jobs/*/executions/*"}, + {"run.projects.locations.jobs.executions.delete", "DELETE", "v2/{+name}", "D", "lro", "", "", "etag,validateOnly", "name=projects/*/locations/*/jobs/*/executions/*"}, + {"run.projects.locations.jobs.executions.tasks.list", "GET", "v2/{+parent}/tasks", "R", "", "tasks", "", "showDeleted,pageSize,pageToken", "parent=projects/*/locations/*/jobs/*/executions/*"}, + {"run.projects.locations.jobs.executions.tasks.get", "GET", "v2/{+name}", "R", "", "", "", "", "name=projects/*/locations/*/jobs/*/executions/*/tasks/*"}, + {"run.projects.locations.operations.list", "GET", "v2/{+name}/operations", "R", "", "operations", "", "pageSize,returnPartialSuccess,pageToken,filter", "name=projects/*/locations/*"}, + {"run.projects.locations.operations.get", "GET", "v2/{+name}", "R", "lro", "", "", "", "name=projects/*/locations/*/operations/*"}, + {"run.projects.locations.operations.wait", "POST", "v2/{+name}:wait", "R", "lro", "", "timeout", "", "name=projects/*/locations/*/operations/*"}, + {"cloudfunctions.projects.locations.functions.list", "GET", "v2/{+parent}/functions", "R", "", "functions", "", "pageSize,orderBy,filter,pageToken", "parent=projects/*/locations/*"}, + {"cloudfunctions.projects.locations.functions.get", "GET", "v2/{+name}", "R", "", "", "", "revision", "name=projects/*/locations/*/functions/*"}, + {"cloudfunctions.projects.locations.functions.create", "POST", "v2/{+parent}/functions", "W", "lro", "", "kmsKeyName,name,description,buildConfig,labels,eventTrigger,environment,serviceConfig", "functionId", "parent=projects/*/locations/*"}, + {"cloudfunctions.projects.locations.functions.patch", "PATCH", "v2/{+name}", "W", "lro", "", "kmsKeyName,name,description,buildConfig,labels,eventTrigger,environment,serviceConfig", "updateMask", "name=projects/*/locations/*/functions/*"}, + {"cloudfunctions.projects.locations.functions.delete", "DELETE", "v2/{+name}", "D", "lro", "", "", "", "name=projects/*/locations/*/functions/*"}, + {"cloudfunctions.projects.locations.functions.generateUploadUrl", "POST", "v2/{+parent}/functions:generateUploadUrl", "W", "", "", "environment,kmsKeyName", "", "parent=projects/*/locations/*"}, + {"cloudfunctions.projects.locations.functions.generateDownloadUrl", "POST", "v2/{+name}:generateDownloadUrl", "W", "", "", "", "", "name=projects/*/locations/*/functions/*"}, + {"cloudfunctions.projects.locations.functions.getIamPolicy", "GET", "v2/{+resource}:getIamPolicy", "R", "", "", "", "options.requestedPolicyVersion", "resource=projects/*/locations/*/functions/*"}, + {"cloudfunctions.projects.locations.functions.setIamPolicy", "POST", "v2/{+resource}:setIamPolicy", "W", "", "", "updateMask,policy", "", "resource=projects/*/locations/*/functions/*"}, + {"cloudfunctions.projects.locations.functions.testIamPermissions", "POST", "v2/{+resource}:testIamPermissions", "R", "", "", "permissions", "", "resource=projects/*/locations/*/functions/*"}, + {"cloudfunctions.projects.locations.list", "GET", "v2/{+name}/locations", "R", "", "locations", "", "pageToken,pageSize,extraLocationTypes,filter", "name=projects/*"}, + {"cloudfunctions.projects.locations.runtimes.list", "GET", "v2/{+parent}/runtimes", "R", "", "runtimes", "", "filter", "parent=projects/*/locations/*"}, + {"cloudfunctions.projects.locations.operations.list", "GET", "v2/{+name}/operations", "R", "", "operations", "", "pageToken,pageSize,filter,returnPartialSuccess", "name=projects/*/locations/*"}, + {"cloudfunctions.projects.locations.operations.get", "GET", "v2/{+name}", "R", "lro", "", "", "", "name=projects/*/locations/*/operations/*"}, + {"container.projects.locations.getServerConfig", "GET", "v1/{+name}/serverConfig", "R", "", "", "", "zone,projectId", "name=projects/*/locations/*"}, + {"container.projects.locations.clusters.list", "GET", "v1/{+parent}/clusters", "R", "", "clusters", "", "zone,projectId", "parent=projects/*/locations/*"}, + {"container.projects.locations.clusters.get", "GET", "v1/{+name}", "R", "", "", "", "zone,projectId,clusterId", "name=projects/*/locations/*/clusters/*"}, + {"container.projects.locations.clusters.create", "POST", "v1/{+parent}/clusters", "W", "", "", "zone,cluster,parent,projectId", "", "parent=projects/*/locations/*"}, + {"container.projects.locations.clusters.update", "PUT", "v1/{+name}", "W", "", "", "zone,projectId,clusterId,update,name", "", "name=projects/*/locations/*/clusters/*"}, + {"container.projects.locations.clusters.delete", "DELETE", "v1/{+name}", "D", "", "", "", "projectId,clusterId,zone", "name=projects/*/locations/*/clusters/*"}, + {"container.projects.locations.clusters.fetchClusterUpgradeInfo", "GET", "v1/{+name}:fetchClusterUpgradeInfo", "R", "", "", "", "version", "name=projects/*/locations/*/clusters/*"}, + {"container.projects.locations.clusters.checkAutopilotCompatibility", "GET", "v1/{+name}:checkAutopilotCompatibility", "R", "", "", "", "", "name=projects/*/locations/*/clusters/*"}, + {"container.projects.locations.clusters.getJwks", "GET", "v1/{+parent}/jwks", "R", "", "", "", "", "parent=projects/*/locations/*/clusters/*"}, + {"container.projects.locations.clusters.nodePools.list", "GET", "v1/{+parent}/nodePools", "R", "", "nodePools", "", "projectId,zone,clusterId", "parent=projects/*/locations/*/clusters/*"}, + {"container.projects.locations.clusters.nodePools.get", "GET", "v1/{+name}", "R", "", "", "", "nodePoolId,projectId,zone,clusterId", "name=projects/*/locations/*/clusters/*/nodePools/*"}, + {"container.projects.locations.clusters.nodePools.create", "POST", "v1/{+parent}/nodePools", "W", "", "", "projectId,zone,nodePool,clusterId,parent", "", "parent=projects/*/locations/*/clusters/*"}, + {"container.projects.locations.clusters.nodePools.update", "PUT", "v1/{+name}", "W", "", "", "queuedProvisioning,labels,kubeletConfig,tags,resourceManagerTags,linuxNodeConfig,windowsNodeConfig,storagePools,diskSizeGb,taintConfig,clusterId,gcfsConfig,loggingConfig,containerdConfig,image,nodeNetworkConfig,maintenancePolicy,workloadMetadataConfig,diskType,nodeDrainConfig,confidentialNodes,fastSocket,maxRunDuration,imageType,bootDisk,nodeVersion,resourceLabels,imageProject,name,taints,flexStart,nodePoolId,consolidationDelay,zone,etag,machineType,upgradeSettings,locations,accelerators,gvnic,projectId", "", "name=projects/*/locations/*/clusters/*/nodePools/*"}, + {"container.projects.locations.clusters.nodePools.delete", "DELETE", "v1/{+name}", "D", "", "", "", "clusterId,nodePoolId,zone,projectId", "name=projects/*/locations/*/clusters/*/nodePools/*"}, + {"container.projects.locations.clusters.nodePools.setSize", "POST", "v1/{+name}:setSize", "W", "", "", "projectId,nodeCount,zone,clusterId,nodePoolId,name", "", "name=projects/*/locations/*/clusters/*/nodePools/*"}, + {"container.projects.locations.clusters.nodePools.rollback", "POST", "v1/{+name}:rollback", "W", "", "", "zone,respectPdb,nodePoolId,clusterId,name,projectId", "", "name=projects/*/locations/*/clusters/*/nodePools/*"}, + {"container.projects.locations.operations.list", "GET", "v1/{+parent}/operations", "R", "", "operations", "", "projectId,zone", "parent=projects/*/locations/*"}, + {"container.projects.locations.operations.get", "GET", "v1/{+name}", "R", "", "", "", "projectId,operationId,zone", "name=projects/*/locations/*/operations/*"}, + {"container.projects.locations.operations.cancel", "POST", "v1/{+name}:cancel", "W", "", "", "operationId,zone,name,projectId", "", "name=projects/*/locations/*/operations/*"}, + {"container.projects.aggregated.usableSubnetworks.list", "GET", "v1/{+parent}/aggregated/usableSubnetworks", "R", "", "subnetworks", "", "pageSize,filter,pageToken", "parent=projects/*"}, + {"cloudbuild.projects.locations.builds.list", "GET", "v1/{+parent}/builds", "R", "", "builds", "", "filter,pageSize,projectId,pageToken", "parent=projects/*/locations/*"}, + {"cloudbuild.projects.locations.builds.get", "GET", "v1/{+name}", "R", "", "", "", "projectId,id", "name=projects/*/locations/*/builds/*"}, + {"cloudbuild.projects.locations.builds.create", "POST", "v1/{+parent}/builds", "W", "lro", "", "steps,serviceAccount,options,tags,gitConfig,logsBucket,images,queueTtl,source,availableSecrets,substitutions,artifacts,dependencies,timeout,secrets", "projectId", "parent=projects/*/locations/*"}, + {"cloudbuild.projects.locations.builds.cancel", "POST", "v1/{+name}:cancel", "W", "", "", "name,projectId,id", "", "name=projects/*/locations/*/builds/*"}, + {"cloudbuild.projects.locations.builds.retry", "POST", "v1/{+name}:retry", "W", "lro", "", "name,id,projectId", "", "name=projects/*/locations/*/builds/*"}, + {"cloudbuild.projects.locations.builds.approve", "POST", "v1/{+name}:approve", "W", "lro", "", "approvalResult", "", "name=projects/*/locations/*/builds/*"}, + {"cloudbuild.projects.builds.list", "GET", "v1/projects/{projectId}/builds", "R", "", "builds", "", "pageToken,filter,parent,pageSize", "projectId="}, + {"cloudbuild.projects.builds.get", "GET", "v1/projects/{projectId}/builds/{id}", "R", "", "", "", "name", "projectId= id="}, + {"cloudbuild.projects.builds.create", "POST", "v1/projects/{projectId}/builds", "W", "lro", "", "steps,serviceAccount,options,tags,gitConfig,logsBucket,images,queueTtl,source,availableSecrets,substitutions,artifacts,dependencies,timeout,secrets", "parent", "projectId="}, + {"cloudbuild.projects.builds.cancel", "POST", "v1/projects/{projectId}/builds/{id}:cancel", "W", "", "", "name,projectId,id", "", "projectId= id="}, + {"cloudbuild.projects.builds.retry", "POST", "v1/projects/{projectId}/builds/{id}:retry", "W", "lro", "", "name,id,projectId", "", "projectId= id="}, + {"cloudbuild.projects.locations.triggers.list", "GET", "v1/{+parent}/triggers", "R", "", "triggers", "", "pageToken,pageSize,projectId", "parent=projects/*/locations/*"}, + {"cloudbuild.projects.locations.triggers.get", "GET", "v1/{+name}", "R", "", "", "", "projectId,triggerId", "name=projects/*/locations/*/triggers/*"}, + {"cloudbuild.projects.locations.triggers.create", "POST", "v1/{+parent}/triggers", "W", "", "", "gitFileSource,resourceName,build,ignoredFiles,webhookConfig,developerConnectEventConfig,github,triggerTemplate,includeBuildLogs,tags,sourceToBuild,bitbucketServerTriggerConfig,pubsubConfig,disabled,autodetect,substitutions,description,eventType,approvalConfig,repositoryEventConfig,filter,serviceAccount,name,filename,includedFiles", "projectId", "parent=projects/*/locations/*"}, + {"cloudbuild.projects.locations.triggers.patch", "PATCH", "v1/{+resourceName}", "W", "", "", "gitFileSource,resourceName,build,ignoredFiles,webhookConfig,developerConnectEventConfig,github,triggerTemplate,includeBuildLogs,tags,sourceToBuild,bitbucketServerTriggerConfig,pubsubConfig,disabled,autodetect,substitutions,description,eventType,approvalConfig,repositoryEventConfig,filter,serviceAccount,name,filename,includedFiles", "updateMask,projectId,triggerId", "resourceName=projects/*/locations/*/triggers/*"}, + {"cloudbuild.projects.locations.triggers.delete", "DELETE", "v1/{+name}", "D", "", "", "", "projectId,triggerId", "name=projects/*/locations/*/triggers/*"}, + {"cloudbuild.projects.locations.triggers.run", "POST", "v1/{+name}:run", "W", "lro", "", "triggerId,projectId,source", "", "name=projects/*/locations/*/triggers/*"}, + {"cloudbuild.projects.locations.workerPools.list", "GET", "v1/{+parent}/workerPools", "R", "", "workerPools", "", "pageToken,pageSize", "parent=projects/*/locations/*"}, + {"cloudbuild.projects.locations.workerPools.get", "GET", "v1/{+name}", "R", "", "", "", "", "name=projects/*/locations/*/workerPools/*"}, + {"cloudbuild.projects.locations.workerPools.create", "POST", "v1/{+parent}/workerPools", "W", "lro", "", "displayName,annotations,privatePoolV1Config", "workerPoolId,validateOnly", "parent=projects/*/locations/*"}, + {"cloudbuild.projects.locations.workerPools.patch", "PATCH", "v1/{+name}", "W", "lro", "", "displayName,annotations,privatePoolV1Config", "updateMask,validateOnly", "name=projects/*/locations/*/workerPools/*"}, + {"cloudbuild.projects.locations.workerPools.delete", "DELETE", "v1/{+name}", "D", "lro", "", "", "allowMissing,validateOnly,etag", "name=projects/*/locations/*/workerPools/*"}, + {"cloudbuild.projects.locations.getDefaultServiceAccount", "GET", "v1/{+name}", "R", "", "", "", "", "name=projects/*/locations/*/defaultServiceAccount"}, + {"cloudbuild.projects.locations.operations.get", "GET", "v1/{+name}", "R", "lro", "", "", "", "name=projects/*/locations/*/operations/*"}, + {"cloudbuild.projects.locations.operations.cancel", "POST", "v1/{+name}:cancel", "W", "", "", "", "", "name=projects/*/locations/*/operations/*"}, + {"artifactregistry.projects.locations.list", "GET", "v1/{+name}/locations", "R", "", "locations", "", "pageSize,extraLocationTypes,pageToken,filter", "name=projects/*"}, + {"artifactregistry.projects.locations.get", "GET", "v1/{+name}", "R", "", "", "", "", "name=projects/*/locations/*"}, + {"artifactregistry.projects.locations.getProjectConfig", "GET", "v1/{+name}", "R", "", "", "", "", "name=projects/*/locations/*/projectConfig"}, + {"artifactregistry.projects.getProjectSettings", "GET", "v1/{+name}", "R", "", "", "", "", "name=projects/*/projectSettings"}, + {"artifactregistry.projects.locations.repositories.list", "GET", "v1/{+parent}/repositories", "R", "", "repositories", "", "pageToken,pageSize,filter,orderBy", "parent=projects/*/locations/*"}, + {"artifactregistry.projects.locations.repositories.get", "GET", "v1/{+name}", "R", "", "", "", "", "name=projects/*/locations/*/repositories/*"}, + {"artifactregistry.projects.locations.repositories.create", "POST", "v1/{+parent}/repositories", "W", "lro", "", "kmsKeyName,name,format,platformLogsConfig,labels,cleanupPolicies,dockerConfig,disallowUnspecifiedMode,remoteRepositoryConfig,cleanupPolicyDryRun,description,vulnerabilityScanningConfig,virtualRepositoryConfig,mode,mavenConfig", "repositoryId", "parent=projects/*/locations/*"}, + {"artifactregistry.projects.locations.repositories.patch", "PATCH", "v1/{+name}", "W", "", "", "kmsKeyName,name,format,platformLogsConfig,labels,cleanupPolicies,dockerConfig,disallowUnspecifiedMode,remoteRepositoryConfig,cleanupPolicyDryRun,description,vulnerabilityScanningConfig,virtualRepositoryConfig,mode,mavenConfig", "updateMask", "name=projects/*/locations/*/repositories/*"}, + {"artifactregistry.projects.locations.repositories.delete", "DELETE", "v1/{+name}", "D", "lro", "", "", "", "name=projects/*/locations/*/repositories/*"}, + {"artifactregistry.projects.locations.repositories.getIamPolicy", "GET", "v1/{+resource}:getIamPolicy", "R", "", "", "", "options.requestedPolicyVersion", "resource=projects/*/locations/*/repositories/*"}, + {"artifactregistry.projects.locations.repositories.setIamPolicy", "POST", "v1/{+resource}:setIamPolicy", "W", "", "", "policy", "", "resource=projects/*/locations/*/repositories/*"}, + {"artifactregistry.projects.locations.repositories.testIamPermissions", "POST", "v1/{+resource}:testIamPermissions", "R", "", "", "permissions", "", "resource=projects/*/locations/*/repositories/*"}, + {"artifactregistry.projects.locations.repositories.packages.list", "GET", "v1/{+parent}/packages", "R", "", "packages", "", "orderBy,pageToken,filter,pageSize", "parent=projects/*/locations/*/repositories/*"}, + {"artifactregistry.projects.locations.repositories.packages.get", "GET", "v1/{+name}", "R", "", "", "", "", "name=projects/*/locations/*/repositories/*/packages/*"}, + {"artifactregistry.projects.locations.repositories.packages.delete", "DELETE", "v1/{+name}", "D", "lro", "", "", "", "name=projects/*/locations/*/repositories/*/packages/*"}, + {"artifactregistry.projects.locations.repositories.packages.versions.list", "GET", "v1/{+parent}/versions", "R", "", "versions", "", "view,orderBy,filter,pageToken,pageSize", "parent=projects/*/locations/*/repositories/*/packages/*"}, + {"artifactregistry.projects.locations.repositories.packages.versions.get", "GET", "v1/{+name}", "R", "", "", "", "view", "name=projects/*/locations/*/repositories/*/packages/*/versions/*"}, + {"artifactregistry.projects.locations.repositories.packages.versions.delete", "DELETE", "v1/{+name}", "D", "lro", "", "", "force", "name=projects/*/locations/*/repositories/*/packages/*/versions/*"}, + {"artifactregistry.projects.locations.repositories.packages.versions.batchDelete", "POST", "v1/{+parent}/versions:batchDelete", "D", "lro", "", "validateOnly,names", "", "parent=projects/*/locations/*/repositories/*/packages/*"}, + {"artifactregistry.projects.locations.repositories.packages.tags.list", "GET", "v1/{+parent}/tags", "R", "", "tags", "", "pageSize,filter,pageToken", "parent=projects/*/locations/*/repositories/*/packages/*"}, + {"artifactregistry.projects.locations.repositories.packages.tags.get", "GET", "v1/{+name}", "R", "", "", "", "", "name=projects/*/locations/*/repositories/*/packages/*/tags/*"}, + {"artifactregistry.projects.locations.repositories.packages.tags.create", "POST", "v1/{+parent}/tags", "W", "", "", "name,version", "tagId", "parent=projects/*/locations/*/repositories/*/packages/*"}, + {"artifactregistry.projects.locations.repositories.packages.tags.patch", "PATCH", "v1/{+name}", "W", "", "", "name,version", "updateMask", "name=projects/*/locations/*/repositories/*/packages/*/tags/*"}, + {"artifactregistry.projects.locations.repositories.packages.tags.delete", "DELETE", "v1/{+name}", "D", "", "", "", "", "name=projects/*/locations/*/repositories/*/packages/*/tags/*"}, + {"artifactregistry.projects.locations.repositories.files.list", "GET", "v1/{+parent}/files", "R", "", "files", "", "pageSize,orderBy,filter,pageToken", "parent=projects/*/locations/*/repositories/*"}, + {"artifactregistry.projects.locations.repositories.files.get", "GET", "v1/{+name}", "R", "", "", "", "", "name="}, + {"artifactregistry.projects.locations.repositories.files.delete", "DELETE", "v1/{+name}", "D", "lro", "", "", "", "name=projects/*/locations/*/repositories/*/files/*"}, + {"artifactregistry.projects.locations.repositories.dockerImages.list", "GET", "v1/{+parent}/dockerImages", "R", "", "dockerImages", "", "pageSize,pageToken,orderBy", "parent=projects/*/locations/*/repositories/*"}, + {"artifactregistry.projects.locations.repositories.dockerImages.get", "GET", "v1/{+name}", "R", "", "", "", "", "name=projects/*/locations/*/repositories/*/dockerImages/*"}, + {"artifactregistry.projects.locations.repositories.mavenArtifacts.list", "GET", "v1/{+parent}/mavenArtifacts", "R", "", "mavenArtifacts", "", "pageToken,pageSize", "parent=projects/*/locations/*/repositories/*"}, + {"artifactregistry.projects.locations.repositories.mavenArtifacts.get", "GET", "v1/{+name}", "R", "", "", "", "", "name=projects/*/locations/*/repositories/*/mavenArtifacts/*"}, + {"artifactregistry.projects.locations.repositories.npmPackages.list", "GET", "v1/{+parent}/npmPackages", "R", "", "npmPackages", "", "pageToken,pageSize", "parent=projects/*/locations/*/repositories/*"}, + {"artifactregistry.projects.locations.repositories.npmPackages.get", "GET", "v1/{+name}", "R", "", "", "", "", "name=projects/*/locations/*/repositories/*/npmPackages/*"}, + {"artifactregistry.projects.locations.repositories.pythonPackages.list", "GET", "v1/{+parent}/pythonPackages", "R", "", "pythonPackages", "", "pageSize,pageToken", "parent=projects/*/locations/*/repositories/*"}, + {"artifactregistry.projects.locations.repositories.pythonPackages.get", "GET", "v1/{+name}", "R", "", "", "", "", "name=projects/*/locations/*/repositories/*/pythonPackages/*"}, + {"artifactregistry.projects.locations.repositories.rules.list", "GET", "v1/{+parent}/rules", "R", "", "rules", "", "pageSize,pageToken", "parent=projects/*/locations/*/repositories/*"}, + {"artifactregistry.projects.locations.repositories.rules.get", "GET", "v1/{+name}", "R", "", "", "", "", "name=projects/*/locations/*/repositories/*/rules/*"}, + {"artifactregistry.projects.locations.repositories.rules.create", "POST", "v1/{+parent}/rules", "W", "", "", "condition,action,name,operation,packageId", "ruleId", "parent=projects/*/locations/*/repositories/*"}, + {"artifactregistry.projects.locations.repositories.rules.patch", "PATCH", "v1/{+name}", "W", "", "", "condition,action,name,operation,packageId", "updateMask", "name=projects/*/locations/*/repositories/*/rules/*"}, + {"artifactregistry.projects.locations.repositories.rules.delete", "DELETE", "v1/{+name}", "D", "", "", "", "", "name=projects/*/locations/*/repositories/*/rules/*"}, + {"artifactregistry.projects.locations.repositories.attachments.list", "GET", "v1/{+parent}/attachments", "R", "", "attachments", "", "pageToken,filter,pageSize", "parent=projects/*/locations/*/repositories/*"}, + {"artifactregistry.projects.locations.repositories.attachments.get", "GET", "v1/{+name}", "R", "", "", "", "", "name=projects/*/locations/*/repositories/*/attachments/*"}, + {"artifactregistry.projects.locations.operations.get", "GET", "v1/{+name}", "R", "lro", "", "", "", "name=projects/*/locations/*/operations/*"}, + {"iam.roles.list", "GET", "v1/roles", "R", "", "roles", "", "pageSize,parent,showDeleted,view,pageToken", ""}, + {"iam.roles.get", "GET", "v1/{+name}", "R", "", "", "", "", "name=roles/*"}, + {"iam.roles.queryGrantableRoles", "POST", "v1/roles:queryGrantableRoles", "R", "", "roles", "view,pageSize,pageToken,fullResourceName", "", ""}, + {"iam.permissions.queryTestablePermissions", "POST", "v1/permissions:queryTestablePermissions", "R", "", "permissions", "pageToken,fullResourceName,pageSize", "", ""}, + {"iam.projects.roles.list", "GET", "v1/{+parent}/roles", "R", "", "roles", "", "view,pageSize,showDeleted,pageToken", "parent=projects/*"}, + {"iam.projects.roles.get", "GET", "v1/{+name}", "R", "", "", "", "", "name=projects/*/roles/*"}, + {"iam.projects.roles.create", "POST", "v1/{+parent}/roles", "W", "", "", "roleId,role", "", "parent=projects/*"}, + {"iam.projects.roles.patch", "PATCH", "v1/{+name}", "W", "", "", "includedPermissions,stage,description,name,etag,deleted,title", "updateMask", "name=projects/*/roles/*"}, + {"iam.projects.roles.delete", "DELETE", "v1/{+name}", "D", "", "", "", "etag", "name=projects/*/roles/*"}, + {"iam.projects.roles.undelete", "POST", "v1/{+name}:undelete", "W", "", "", "etag", "", "name=projects/*/roles/*"}, + {"iam.organizations.roles.list", "GET", "v1/{+parent}/roles", "R", "", "roles", "", "showDeleted,view,pageToken,pageSize", "parent=organizations/*"}, + {"iam.organizations.roles.get", "GET", "v1/{+name}", "R", "", "", "", "", "name=organizations/*/roles/*"}, + {"iam.projects.serviceAccounts.list", "GET", "v1/{+name}/serviceAccounts", "R", "", "accounts", "", "pageToken,pageSize", "name=projects/*"}, + {"iam.projects.serviceAccounts.get", "GET", "v1/{+name}", "R", "", "", "", "", "name=projects/*/serviceAccounts/*"}, + {"iam.projects.serviceAccounts.create", "POST", "v1/{+name}/serviceAccounts", "W", "", "", "accountId,serviceAccount", "", "name=projects/*"}, + {"iam.projects.serviceAccounts.patch", "PATCH", "v1/{+name}", "W", "", "", "updateMask,serviceAccount", "", "name=projects/*/serviceAccounts/*"}, + {"iam.projects.serviceAccounts.update", "PUT", "v1/{+name}", "W", "", "", "description,name,etag,displayName", "", "name=projects/*/serviceAccounts/*"}, + {"iam.projects.serviceAccounts.delete", "DELETE", "v1/{+name}", "D", "", "", "", "", "name=projects/*/serviceAccounts/*"}, + {"iam.projects.serviceAccounts.undelete", "POST", "v1/{+name}:undelete", "W", "", "", "", "", "name=projects/*/serviceAccounts/*"}, + {"iam.projects.serviceAccounts.enable", "POST", "v1/{+name}:enable", "W", "", "", "", "", "name=projects/*/serviceAccounts/*"}, + {"iam.projects.serviceAccounts.disable", "POST", "v1/{+name}:disable", "W", "", "", "", "", "name=projects/*/serviceAccounts/*"}, + {"iam.projects.serviceAccounts.signBlob", "POST", "v1/{+name}:signBlob", "R", "", "", "bytesToSign", "", "name=projects/*/serviceAccounts/*"}, + {"iam.projects.serviceAccounts.signJwt", "POST", "v1/{+name}:signJwt", "R", "", "", "payload", "", "name=projects/*/serviceAccounts/*"}, + {"iam.projects.serviceAccounts.getIamPolicy", "POST", "v1/{+resource}:getIamPolicy", "R", "", "", "", "options.requestedPolicyVersion", "resource=projects/*/serviceAccounts/*"}, + {"iam.projects.serviceAccounts.setIamPolicy", "POST", "v1/{+resource}:setIamPolicy", "W", "", "", "updateMask,policy", "", "resource=projects/*/serviceAccounts/*"}, + {"iam.projects.serviceAccounts.testIamPermissions", "POST", "v1/{+resource}:testIamPermissions", "R", "", "", "permissions", "", "resource=projects/*/serviceAccounts/*"}, + {"iam.projects.serviceAccounts.keys.list", "GET", "v1/{+name}/keys", "R", "", "keys", "", "keyTypes", "name=projects/*/serviceAccounts/*"}, + {"iam.projects.serviceAccounts.keys.get", "GET", "v1/{+name}", "R", "", "", "", "publicKeyType", "name=projects/*/serviceAccounts/*/keys/*"}, + {"iam.projects.serviceAccounts.keys.create", "POST", "v1/{+name}/keys", "W", "", "", "keyAlgorithm,privateKeyType", "", "name=projects/*/serviceAccounts/*"}, + {"iam.projects.serviceAccounts.keys.upload", "POST", "v1/{+name}/keys:upload", "W", "", "", "publicKeyData", "", "name=projects/*/serviceAccounts/*"}, + {"iam.projects.serviceAccounts.keys.delete", "DELETE", "v1/{+name}", "D", "", "", "", "", "name=projects/*/serviceAccounts/*/keys/*"}, + {"iam.projects.serviceAccounts.keys.enable", "POST", "v1/{+name}:enable", "W", "", "", "", "", "name=projects/*/serviceAccounts/*/keys/*"}, + {"iam.projects.serviceAccounts.keys.disable", "POST", "v1/{+name}:disable", "W", "", "", "", "", "name=projects/*/serviceAccounts/*/keys/*"}, + {"iamcredentials.projects.serviceAccounts.signJwt", "POST", "v1/{+name}:signJwt", "R", "", "", "delegates,payload", "", "name=projects/*/serviceAccounts/*"}, + {"iamcredentials.projects.serviceAccounts.signBlob", "POST", "v1/{+name}:signBlob", "R", "", "", "delegates,payload", "", "name=projects/*/serviceAccounts/*"}, + {"iamcredentials.projects.serviceAccounts.generateAccessToken", "POST", "v1/{+name}:generateAccessToken", "R", "", "", "scope,lifetime,delegates", "", "name=projects/*/serviceAccounts/*"}, + {"iamcredentials.projects.serviceAccounts.generateIdToken", "POST", "v1/{+name}:generateIdToken", "R", "", "", "audience,delegates,includeEmail,organizationNumberIncluded", "", "name=projects/*/serviceAccounts/*"}, + {"cloudresourcemanager.projects.get", "GET", "v3/{+name}", "R", "", "", "", "", "name=projects/*"}, + {"cloudresourcemanager.projects.list", "GET", "v3/projects", "R", "", "projects", "", "pageToken,parent,showDeleted,pageSize", ""}, + {"cloudresourcemanager.projects.search", "GET", "v3/projects:search", "R", "", "projects", "", "pageSize,pageToken,query", ""}, + {"cloudresourcemanager.projects.create", "POST", "v3/projects", "W", "lro", "", "projectId,parent,displayName,tags,labels", "", ""}, + {"cloudresourcemanager.projects.patch", "PATCH", "v3/{+name}", "W", "lro", "", "projectId,parent,displayName,tags,labels", "updateMask", "name=projects/*"}, + {"cloudresourcemanager.projects.delete", "DELETE", "v3/{+name}", "D", "lro", "", "", "", "name=projects/*"}, + {"cloudresourcemanager.projects.undelete", "POST", "v3/{+name}:undelete", "W", "lro", "", "", "", "name=projects/*"}, + {"cloudresourcemanager.projects.move", "POST", "v3/{+name}:move", "W", "lro", "", "destinationParent", "", "name=projects/*"}, + {"cloudresourcemanager.projects.getIamPolicy", "POST", "v3/{+resource}:getIamPolicy", "R", "", "", "options", "", "resource=projects/*"}, + {"cloudresourcemanager.projects.setIamPolicy", "POST", "v3/{+resource}:setIamPolicy", "W", "", "", "policy,updateMask", "", "resource=projects/*"}, + {"cloudresourcemanager.projects.testIamPermissions", "POST", "v3/{+resource}:testIamPermissions", "R", "", "", "permissions", "", "resource=projects/*"}, + {"cloudresourcemanager.folders.get", "GET", "v3/{+name}", "R", "", "", "", "", "name=folders/*"}, + {"cloudresourcemanager.folders.list", "GET", "v3/folders", "R", "", "folders", "", "parent,pageSize,showDeleted,pageToken", ""}, + {"cloudresourcemanager.folders.search", "GET", "v3/folders:search", "R", "", "folders", "", "pageToken,pageSize,query", ""}, + {"cloudresourcemanager.folders.create", "POST", "v3/folders", "W", "lro", "", "name,displayName,parent,tags", "", ""}, + {"cloudresourcemanager.folders.patch", "PATCH", "v3/{+name}", "W", "lro", "", "name,displayName,parent,tags", "updateMask", "name=folders/*"}, + {"cloudresourcemanager.folders.delete", "DELETE", "v3/{+name}", "D", "lro", "", "", "", "name=folders/*"}, + {"cloudresourcemanager.folders.undelete", "POST", "v3/{+name}:undelete", "W", "lro", "", "", "", "name=folders/*"}, + {"cloudresourcemanager.folders.move", "POST", "v3/{+name}:move", "W", "lro", "", "destinationParent", "", "name=folders/*"}, + {"cloudresourcemanager.folders.getIamPolicy", "POST", "v3/{+resource}:getIamPolicy", "R", "", "", "options", "", "resource=folders/*"}, + {"cloudresourcemanager.folders.setIamPolicy", "POST", "v3/{+resource}:setIamPolicy", "W", "", "", "policy,updateMask", "", "resource=folders/*"}, + {"cloudresourcemanager.folders.testIamPermissions", "POST", "v3/{+resource}:testIamPermissions", "R", "", "", "permissions", "", "resource=folders/*"}, + {"cloudresourcemanager.organizations.get", "GET", "v3/{+name}", "R", "", "", "", "", "name=organizations/*"}, + {"cloudresourcemanager.organizations.search", "GET", "v3/organizations:search", "R", "", "organizations", "", "pageSize,pageToken,query", ""}, + {"cloudresourcemanager.organizations.getIamPolicy", "POST", "v3/{+resource}:getIamPolicy", "R", "", "", "options", "", "resource=organizations/*"}, + {"cloudresourcemanager.organizations.setIamPolicy", "POST", "v3/{+resource}:setIamPolicy", "W", "", "", "policy,updateMask", "", "resource=organizations/*"}, + {"cloudresourcemanager.organizations.testIamPermissions", "POST", "v3/{+resource}:testIamPermissions", "R", "", "", "permissions", "", "resource=organizations/*"}, + {"cloudresourcemanager.operations.get", "GET", "v3/{+name}", "R", "lro", "", "", "", "name="}, + {"cloudresourcemanager.liens.list", "GET", "v3/liens", "R", "", "liens", "", "parent,pageSize,pageToken", ""}, + {"cloudresourcemanager.liens.get", "GET", "v3/{+name}", "R", "", "", "", "", "name="}, + {"cloudresourcemanager.liens.create", "POST", "v3/liens", "W", "", "", "reason,createTime,origin,parent,name,restrictions", "", ""}, + {"cloudresourcemanager.liens.delete", "DELETE", "v3/{+name}", "D", "", "", "", "", "name="}, + {"cloudresourcemanager.tagKeys.list", "GET", "v3/tagKeys", "R", "", "tagKeys", "", "pageSize,parent,pageToken", ""}, + {"cloudresourcemanager.tagKeys.get", "GET", "v3/{+name}", "R", "", "", "", "", "name=tagKeys/*"}, + {"cloudresourcemanager.tagValues.list", "GET", "v3/tagValues", "R", "", "tagValues", "", "pageToken,parent,pageSize", ""}, + {"cloudresourcemanager.tagValues.get", "GET", "v3/{+name}", "R", "", "", "", "", "name=tagValues/*"}, + {"cloudresourcemanager.tagBindings.list", "GET", "v3/tagBindings", "R", "", "tagBindings", "", "pageSize,pageToken,parent", ""}, + {"serviceusage.services.list", "GET", "v1/{+parent}/services", "R", "", "services", "", "filter,pageToken,pageSize", "parent=*/*"}, + {"serviceusage.services.get", "GET", "v1/{+name}", "R", "", "", "", "", "name=*/*/services/*"}, + {"serviceusage.services.batchGet", "GET", "v1/{+parent}/services:batchGet", "R", "", "", "", "names", "parent=*/*"}, + {"serviceusage.services.enable", "POST", "v1/{+name}:enable", "W", "lro", "", "", "", "name=*/*/services/*"}, + {"serviceusage.services.disable", "POST", "v1/{+name}:disable", "W", "lro", "", "disableDependentServices,checkIfServiceHasUsage", "", "name=*/*/services/*"}, + {"serviceusage.services.batchEnable", "POST", "v1/{+parent}/services:batchEnable", "W", "lro", "", "serviceIds", "", "parent=*/*"}, + {"serviceusage.operations.get", "GET", "v1/{+name}", "R", "lro", "", "", "", "name=operations/*"}, + {"serviceusage.operations.list", "GET", "v1/operations", "R", "", "operations", "", "pageToken,returnPartialSuccess,name,filter,pageSize", ""}, + {"logging.entries.list", "POST", "v2/entries:list", "R", "", "entries", "pageSize,resourceNames,filter,orderBy,projectIds,pageToken", "", ""}, + {"logging.entries.write", "POST", "v2/entries:write", "W", "", "", "partialSuccess,entries,resource,dryRun,labels,logName", "", ""}, + {"logging.projects.logs.list", "GET", "v2/{+parent}/logs", "R", "", "logNames", "", "pageToken,resourceNames,pageSize", "parent=projects/*"}, + {"logging.projects.logs.delete", "DELETE", "v2/{+logName}", "D", "", "", "", "", "logName=projects/*/logs/*"}, + {"logging.monitoredResourceDescriptors.list", "GET", "v2/monitoredResourceDescriptors", "R", "", "resourceDescriptors", "", "pageToken,pageSize", ""}, + {"logging.projects.sinks.list", "GET", "v2/{+parent}/sinks", "R", "", "sinks", "", "pageToken,filter,pageSize", "parent=projects/*"}, + {"logging.projects.sinks.get", "GET", "v2/{+sinkName}", "R", "", "", "", "", "sinkName=projects/*/sinks/*"}, + {"logging.projects.sinks.create", "POST", "v2/{+parent}/sinks", "W", "", "", "description,filter,includeChildren,name,bigqueryOptions,disabled,outputVersionFormat,destination,exclusions,interceptChildren", "customWriterIdentity,uniqueWriterIdentity", "parent=projects/*"}, + {"logging.projects.sinks.patch", "PATCH", "v2/{+sinkName}", "W", "", "", "description,filter,includeChildren,name,bigqueryOptions,disabled,outputVersionFormat,destination,exclusions,interceptChildren", "uniqueWriterIdentity,updateMask,customWriterIdentity", "sinkName=projects/*/sinks/*"}, + {"logging.projects.sinks.delete", "DELETE", "v2/{+sinkName}", "D", "", "", "", "", "sinkName=projects/*/sinks/*"}, + {"logging.projects.metrics.list", "GET", "v2/{+parent}/metrics", "R", "", "metrics", "", "pageSize,pageToken", "parent=projects/*"}, + {"logging.projects.metrics.get", "GET", "v2/{+metricName}", "R", "", "", "", "", "metricName=projects/*/metrics/*"}, + {"logging.projects.metrics.create", "POST", "v2/{+parent}/metrics", "W", "", "", "name,bucketOptions,bucketName,disabled,labelExtractors,description,metricDescriptor,filter,valueExtractor,version", "", "parent=projects/*"}, + {"logging.projects.metrics.update", "PUT", "v2/{+metricName}", "W", "", "", "name,bucketOptions,bucketName,disabled,labelExtractors,description,metricDescriptor,filter,valueExtractor,version", "", "metricName=projects/*/metrics/*"}, + {"logging.projects.metrics.delete", "DELETE", "v2/{+metricName}", "D", "", "", "", "", "metricName=projects/*/metrics/*"}, + {"logging.projects.exclusions.list", "GET", "v2/{+parent}/exclusions", "R", "", "exclusions", "", "pageSize,pageToken", "parent=projects/*"}, + {"logging.projects.exclusions.get", "GET", "v2/{+name}", "R", "", "", "", "", "name=projects/*/exclusions/*"}, + {"logging.projects.locations.buckets.list", "GET", "v2/{+parent}/buckets", "R", "", "buckets", "", "pageSize,pageToken", "parent=projects/*/locations/*"}, + {"logging.projects.locations.buckets.get", "GET", "v2/{+name}", "R", "", "", "", "", "name=projects/*/locations/*/buckets/*"}, + {"logging.projects.getSettings", "GET", "v2/{+name}/settings", "R", "", "", "", "", "name=projects/*"}, + {"logging.projects.locations.operations.get", "GET", "v2/{+name}", "R", "lro", "", "", "", "name=projects/*/locations/*/operations/*"}, + {"monitoring.projects.timeSeries.list", "GET", "v3/{+name}/timeSeries", "R", "", "timeSeries", "", "pageToken,secondaryAggregation.alignmentPeriod,view,secondaryAggregation.crossSeriesReducer,secondaryAggregation.perSeriesAligner,pageSize,aggregation.groupByFields,aggregation.perSeriesAligner,aggregation.alignmentPeriod,interval.endTime,filter,aggregation.crossSeriesReducer,orderBy,interval.startTime,secondaryAggregation.groupByFields", "name=projects/*"}, + {"monitoring.projects.timeSeries.create", "POST", "v3/{+name}/timeSeries", "W", "", "", "timeSeries", "", "name=projects/*"}, + {"monitoring.projects.metricDescriptors.list", "GET", "v3/{+name}/metricDescriptors", "R", "", "metricDescriptors", "", "pageSize,activeOnly,pageToken,filter", "name=projects/*"}, + {"monitoring.projects.metricDescriptors.get", "GET", "v3/{+name}", "R", "", "", "", "", "name="}, + {"monitoring.projects.monitoredResourceDescriptors.list", "GET", "v3/{+name}/monitoredResourceDescriptors", "R", "", "resourceDescriptors", "", "filter,pageSize,pageToken", "name=projects/*"}, + {"monitoring.projects.monitoredResourceDescriptors.get", "GET", "v3/{+name}", "R", "", "", "", "", "name="}, + {"monitoring.projects.alertPolicies.list", "GET", "v3/{+name}/alertPolicies", "R", "", "alertPolicies", "", "pageToken,filter,pageSize,orderBy", "name=projects/*"}, + {"monitoring.projects.alertPolicies.get", "GET", "v3/{+name}", "R", "", "", "", "", "name=projects/*/alertPolicies/*"}, + {"monitoring.projects.alertPolicies.create", "POST", "v3/{+name}/alertPolicies", "W", "", "", "validity,conditions,displayName,creationRecord,mutationRecord,severity,combiner,alertStrategy,enabled,name,userLabels,notificationChannels,documentation", "", "name=projects/*"}, + {"monitoring.projects.alertPolicies.patch", "PATCH", "v3/{+name}", "W", "", "", "validity,conditions,displayName,creationRecord,mutationRecord,severity,combiner,alertStrategy,enabled,name,userLabels,notificationChannels,documentation", "updateMask", "name=projects/*/alertPolicies/*"}, + {"monitoring.projects.alertPolicies.delete", "DELETE", "v3/{+name}", "D", "", "", "", "", "name=projects/*/alertPolicies/*"}, + {"monitoring.projects.notificationChannels.list", "GET", "v3/{+name}/notificationChannels", "R", "", "notificationChannels", "", "pageToken,orderBy,filter,pageSize", "name=projects/*"}, + {"monitoring.projects.notificationChannels.get", "GET", "v3/{+name}", "R", "", "", "", "", "name=projects/*/notificationChannels/*"}, + {"monitoring.projects.notificationChannelDescriptors.list", "GET", "v3/{+name}/notificationChannelDescriptors", "R", "", "channelDescriptors", "", "pageSize,pageToken", "name=projects/*"}, + {"monitoring.projects.notificationChannelDescriptors.get", "GET", "v3/{+name}", "R", "", "", "", "", "name=projects/*/notificationChannelDescriptors/*"}, + {"monitoring.projects.groups.list", "GET", "v3/{+name}/groups", "R", "", "group", "", "ancestorsOfGroup,descendantsOfGroup,childrenOfGroup,pageToken,pageSize", "name=projects/*"}, + {"monitoring.projects.groups.get", "GET", "v3/{+name}", "R", "", "", "", "", "name=projects/*/groups/*"}, + {"monitoring.projects.uptimeCheckConfigs.list", "GET", "v3/{+parent}/uptimeCheckConfigs", "R", "", "uptimeCheckConfigs", "", "pageToken,pageSize,filter", "parent=projects/*"}, + {"monitoring.projects.uptimeCheckConfigs.get", "GET", "v3/{+name}", "R", "", "", "", "", "name=projects/*/uptimeCheckConfigs/*"}, + {"monitoring.projects.snoozes.list", "GET", "v3/{+parent}/snoozes", "R", "", "snoozes", "", "pageSize,filter,pageToken", "parent=projects/*"}, + {"monitoring.projects.snoozes.get", "GET", "v3/{+name}", "R", "", "", "", "", "name=projects/*/snoozes/*"}, + {"monitoring.projects.alerts.list", "GET", "v3/{+parent}/alerts", "R", "", "alerts", "", "filter,pageToken,pageSize,orderBy", "parent=projects/*"}, + {"monitoring.projects.alerts.get", "GET", "v3/{+name}", "R", "", "", "", "", "name=projects/*/alerts/*"}, + {"monitoring.services.list", "GET", "v3/{+parent}/services", "R", "", "services", "", "filter,pageSize,pageToken", "parent=*/*"}, + {"monitoring.services.get", "GET", "v3/{+name}", "R", "", "", "", "", "name=*/*/services/*"}, + {"monitoring.services.serviceLevelObjectives.list", "GET", "v3/{+parent}/serviceLevelObjectives", "R", "", "serviceLevelObjectives", "", "pageSize,pageToken,view,filter", "parent=*/*/services/*"}, + {"monitoring.services.serviceLevelObjectives.get", "GET", "v3/{+name}", "R", "", "", "", "view", "name=*/*/services/*/serviceLevelObjectives/*"}, + {"cloudscheduler.projects.locations.list", "GET", "v1/{+name}/locations", "R", "", "locations", "", "pageSize,pageToken,filter,extraLocationTypes", "name=projects/*"}, + {"cloudscheduler.projects.locations.get", "GET", "v1/{+name}", "R", "", "", "", "", "name=projects/*/locations/*"}, + {"cloudscheduler.projects.locations.jobs.list", "GET", "v1/{+parent}/jobs", "R", "", "jobs", "", "pageToken,pageSize", "parent=projects/*/locations/*"}, + {"cloudscheduler.projects.locations.jobs.get", "GET", "v1/{+name}", "R", "", "", "", "", "name=projects/*/locations/*/jobs/*"}, + {"cloudscheduler.projects.locations.jobs.create", "POST", "v1/{+parent}/jobs", "W", "", "", "httpTarget,description,timeZone,pubsubTarget,schedule,retryConfig,name,appEngineHttpTarget,attemptDeadline", "", "parent=projects/*/locations/*"}, + {"cloudscheduler.projects.locations.jobs.patch", "PATCH", "v1/{+name}", "W", "", "", "httpTarget,description,timeZone,pubsubTarget,schedule,retryConfig,name,appEngineHttpTarget,attemptDeadline", "updateMask", "name=projects/*/locations/*/jobs/*"}, + {"cloudscheduler.projects.locations.jobs.delete", "DELETE", "v1/{+name}", "D", "", "", "", "", "name=projects/*/locations/*/jobs/*"}, + {"cloudscheduler.projects.locations.jobs.run", "POST", "v1/{+name}:run", "W", "", "", "", "", "name=projects/*/locations/*/jobs/*"}, + {"cloudscheduler.projects.locations.jobs.pause", "POST", "v1/{+name}:pause", "W", "", "", "", "", "name=projects/*/locations/*/jobs/*"}, + {"cloudscheduler.projects.locations.jobs.resume", "POST", "v1/{+name}:resume", "W", "", "", "", "", "name=projects/*/locations/*/jobs/*"}, + {"cloudscheduler.projects.locations.operations.get", "GET", "v1/{+name}", "R", "lro", "", "", "", "name=projects/*/locations/*/operations/*"}, + {"cloudtasks.projects.locations.list", "GET", "v2/{+name}/locations", "R", "", "locations", "", "filter,extraLocationTypes,pageSize,pageToken", "name=projects/*"}, + {"cloudtasks.projects.locations.get", "GET", "v2/{+name}", "R", "", "", "", "", "name=projects/*/locations/*"}, + {"cloudtasks.projects.locations.queues.list", "GET", "v2/{+parent}/queues", "R", "", "queues", "", "pageToken,pageSize,filter", "parent=projects/*/locations/*"}, + {"cloudtasks.projects.locations.queues.get", "GET", "v2/{+name}", "R", "", "", "", "", "name=projects/*/locations/*/queues/*"}, + {"cloudtasks.projects.locations.queues.create", "POST", "v2/{+parent}/queues", "W", "", "", "appEngineRoutingOverride,name,stackdriverLoggingConfig,state,httpTarget,rateLimits,purgeTime,retryConfig", "", "parent=projects/*/locations/*"}, + {"cloudtasks.projects.locations.queues.patch", "PATCH", "v2/{+name}", "W", "", "", "appEngineRoutingOverride,name,stackdriverLoggingConfig,state,httpTarget,rateLimits,purgeTime,retryConfig", "updateMask", "name=projects/*/locations/*/queues/*"}, + {"cloudtasks.projects.locations.queues.delete", "DELETE", "v2/{+name}", "D", "", "", "", "", "name=projects/*/locations/*/queues/*"}, + {"cloudtasks.projects.locations.queues.pause", "POST", "v2/{+name}:pause", "W", "", "", "", "", "name=projects/*/locations/*/queues/*"}, + {"cloudtasks.projects.locations.queues.resume", "POST", "v2/{+name}:resume", "W", "", "", "", "", "name=projects/*/locations/*/queues/*"}, + {"cloudtasks.projects.locations.queues.purge", "POST", "v2/{+name}:purge", "D", "", "", "", "", "name=projects/*/locations/*/queues/*"}, + {"cloudtasks.projects.locations.queues.getIamPolicy", "POST", "v2/{+resource}:getIamPolicy", "R", "", "", "options", "", "resource=projects/*/locations/*/queues/*"}, + {"cloudtasks.projects.locations.queues.setIamPolicy", "POST", "v2/{+resource}:setIamPolicy", "W", "", "", "policy", "", "resource=projects/*/locations/*/queues/*"}, + {"cloudtasks.projects.locations.queues.testIamPermissions", "POST", "v2/{+resource}:testIamPermissions", "R", "", "", "permissions", "", "resource=projects/*/locations/*/queues/*"}, + {"cloudtasks.projects.locations.queues.tasks.list", "GET", "v2/{+parent}/tasks", "R", "", "tasks", "", "responseView,pageToken,pageSize", "parent=projects/*/locations/*/queues/*"}, + {"cloudtasks.projects.locations.queues.tasks.get", "GET", "v2/{+name}", "R", "", "", "", "responseView", "name=projects/*/locations/*/queues/*/tasks/*"}, + {"cloudtasks.projects.locations.queues.tasks.create", "POST", "v2/{+parent}/tasks", "W", "", "", "responseView,task,parent", "", "parent=projects/*/locations/*/queues/*"}, + {"cloudtasks.projects.locations.queues.tasks.delete", "DELETE", "v2/{+name}", "D", "", "", "", "", "name=projects/*/locations/*/queues/*/tasks/*"}, + {"cloudtasks.projects.locations.queues.tasks.run", "POST", "v2/{+name}:run", "W", "", "", "responseView", "", "name=projects/*/locations/*/queues/*/tasks/*"}, + {"cloudtasks.projects.locations.operations.get", "GET", "v2/{+name}", "R", "lro", "", "", "", "name=projects/*/locations/*/operations/*"}, + {"workflows.projects.locations.list", "GET", "v1/{+name}/locations", "R", "", "locations", "", "extraLocationTypes,pageSize,filter,pageToken", "name=projects/*"}, + {"workflows.projects.locations.get", "GET", "v1/{+name}", "R", "", "", "", "", "name=projects/*/locations/*"}, + {"workflows.projects.locations.workflows.list", "GET", "v1/{+parent}/workflows", "R", "", "workflows", "", "pageToken,pageSize,orderBy,filter", "parent=projects/*/locations/*"}, + {"workflows.projects.locations.workflows.get", "GET", "v1/{+name}", "R", "", "", "", "revisionId", "name=projects/*/locations/*/workflows/*"}, + {"workflows.projects.locations.workflows.create", "POST", "v1/{+parent}/workflows", "W", "lro", "", "description,sourceContents,tags,userEnvVars,serviceAccount,callLogLevel,labels,cryptoKeyName,executionHistoryLevel,name", "workflowId", "parent=projects/*/locations/*"}, + {"workflows.projects.locations.workflows.patch", "PATCH", "v1/{+name}", "W", "lro", "", "description,sourceContents,tags,userEnvVars,serviceAccount,callLogLevel,labels,cryptoKeyName,executionHistoryLevel,name", "updateMask", "name=projects/*/locations/*/workflows/*"}, + {"workflows.projects.locations.workflows.delete", "DELETE", "v1/{+name}", "D", "lro", "", "", "", "name=projects/*/locations/*/workflows/*"}, + {"workflows.projects.locations.workflows.listRevisions", "GET", "v1/{+name}:listRevisions", "R", "", "workflows", "", "pageSize,pageToken", "name=projects/*/locations/*/workflows/*"}, + {"workflows.projects.locations.operations.get", "GET", "v1/{+name}", "R", "lro", "", "", "", "name=projects/*/locations/*/operations/*"}, + {"workflows.projects.locations.operations.list", "GET", "v1/{+name}/operations", "R", "", "operations", "", "pageToken,returnPartialSuccess,pageSize,filter", "name=projects/*/locations/*"}, + {"workflowexecutions.projects.locations.workflows.executions.list", "GET", "v1/{+parent}/executions", "R", "", "executions", "", "view,filter,orderBy,pageToken,pageSize", "parent=projects/*/locations/*/workflows/*"}, + {"workflowexecutions.projects.locations.workflows.executions.get", "GET", "v1/{+name}", "R", "", "", "", "view", "name=projects/*/locations/*/workflows/*/executions/*"}, + {"workflowexecutions.projects.locations.workflows.executions.create", "POST", "v1/{+parent}/executions", "W", "", "", "callLogLevel,disableConcurrencyQuotaOverflowBuffering,argument,labels,executionHistoryLevel", "", "parent=projects/*/locations/*/workflows/*"}, + {"workflowexecutions.projects.locations.workflows.executions.cancel", "POST", "v1/{+name}:cancel", "W", "", "", "", "", "name=projects/*/locations/*/workflows/*/executions/*"}, + {"workflowexecutions.projects.locations.workflows.executions.stepEntries.list", "GET", "v1/{+parent}/stepEntries", "R", "", "stepEntries", "", "orderBy,pageToken,skip,view,pageSize,filter", "parent=projects/*/locations/*/workflows/*/executions/*"}, + {"workflowexecutions.projects.locations.workflows.executions.stepEntries.get", "GET", "v1/{+name}", "R", "", "", "", "view", "name=projects/*/locations/*/workflows/*/executions/*/stepEntries/*"}, + {"eventarc.projects.locations.list", "GET", "v1/{+name}/locations", "R", "", "locations", "", "extraLocationTypes,pageToken,filter,pageSize", "name=projects/*"}, + {"eventarc.projects.locations.get", "GET", "v1/{+name}", "R", "", "", "", "", "name=projects/*/locations/*"}, + {"eventarc.projects.locations.triggers.list", "GET", "v1/{+parent}/triggers", "R", "", "triggers", "", "pageToken,pageSize,filter,orderBy", "parent=projects/*/locations/*"}, + {"eventarc.projects.locations.triggers.get", "GET", "v1/{+name}", "R", "", "", "", "", "name=projects/*/locations/*/triggers/*"}, + {"eventarc.projects.locations.triggers.create", "POST", "v1/{+parent}/triggers", "W", "lro", "", "serviceAccount,transport,destination,channel,eventFilters,name,eventDataContentType,labels,retryPolicy", "triggerId,validateOnly", "parent=projects/*/locations/*"}, + {"eventarc.projects.locations.triggers.patch", "PATCH", "v1/{+name}", "W", "lro", "", "serviceAccount,transport,destination,channel,eventFilters,name,eventDataContentType,labels,retryPolicy", "allowMissing,updateMask,validateOnly", "name=projects/*/locations/*/triggers/*"}, + {"eventarc.projects.locations.triggers.delete", "DELETE", "v1/{+name}", "D", "lro", "", "", "allowMissing,validateOnly,etag", "name=projects/*/locations/*/triggers/*"}, + {"eventarc.projects.locations.triggers.getIamPolicy", "GET", "v1/{+resource}:getIamPolicy", "R", "", "", "", "options.requestedPolicyVersion", "resource=projects/*/locations/*/triggers/*"}, + {"eventarc.projects.locations.triggers.setIamPolicy", "POST", "v1/{+resource}:setIamPolicy", "W", "", "", "policy,updateMask", "", "resource=projects/*/locations/*/triggers/*"}, + {"eventarc.projects.locations.triggers.testIamPermissions", "POST", "v1/{+resource}:testIamPermissions", "R", "", "", "permissions", "", "resource=projects/*/locations/*/triggers/*"}, + {"eventarc.projects.locations.channels.list", "GET", "v1/{+parent}/channels", "R", "", "channels", "", "orderBy,pageToken,pageSize", "parent=projects/*/locations/*"}, + {"eventarc.projects.locations.channels.get", "GET", "v1/{+name}", "R", "", "", "", "", "name=projects/*/locations/*/channels/*"}, + {"eventarc.projects.locations.channels.create", "POST", "v1/{+parent}/channels", "W", "lro", "", "cryptoKeyName,labels,provider,name", "validateOnly,channelId", "parent=projects/*/locations/*"}, + {"eventarc.projects.locations.channels.patch", "PATCH", "v1/{+name}", "W", "lro", "", "cryptoKeyName,labels,provider,name", "validateOnly,updateMask", "name=projects/*/locations/*/channels/*"}, + {"eventarc.projects.locations.channels.delete", "DELETE", "v1/{+name}", "D", "lro", "", "", "validateOnly", "name=projects/*/locations/*/channels/*"}, + {"eventarc.projects.locations.providers.list", "GET", "v1/{+parent}/providers", "R", "", "providers", "", "pageSize,orderBy,filter,pageToken", "parent=projects/*/locations/*"}, + {"eventarc.projects.locations.providers.get", "GET", "v1/{+name}", "R", "", "", "", "", "name=projects/*/locations/*/providers/*"}, + {"eventarc.projects.locations.pipelines.list", "GET", "v1/{+parent}/pipelines", "R", "", "pipelines", "", "orderBy,filter,pageSize,pageToken", "parent=projects/*/locations/*"}, + {"eventarc.projects.locations.pipelines.get", "GET", "v1/{+name}", "R", "", "", "", "", "name=projects/*/locations/*/pipelines/*"}, + {"eventarc.projects.locations.messageBuses.list", "GET", "v1/{+parent}/messageBuses", "R", "", "messageBuses", "", "filter,pageSize,orderBy,pageToken", "parent=projects/*/locations/*"}, + {"eventarc.projects.locations.messageBuses.get", "GET", "v1/{+name}", "R", "", "", "", "", "name=projects/*/locations/*/messageBuses/*"}, + {"eventarc.projects.locations.enrollments.list", "GET", "v1/{+parent}/enrollments", "R", "", "enrollments", "", "filter,pageToken,pageSize,orderBy", "parent=projects/*/locations/*"}, + {"eventarc.projects.locations.enrollments.get", "GET", "v1/{+name}", "R", "", "", "", "", "name=projects/*/locations/*/enrollments/*"}, + {"eventarc.projects.locations.operations.get", "GET", "v1/{+name}", "R", "lro", "", "", "", "name=projects/*/locations/*/operations/*"}, + {"eventarc.projects.locations.operations.list", "GET", "v1/{+name}/operations", "R", "", "operations", "", "filter,pageToken,returnPartialSuccess,pageSize", "name=projects/*/locations/*"}, + {"cloudbilling.billingAccounts.list", "GET", "v1/billingAccounts", "R", "", "billingAccounts", "", "pageToken,pageSize,filter,parent", ""}, + {"cloudbilling.billingAccounts.get", "GET", "v1/{+name}", "R", "", "", "", "", "name=billingAccounts/*"}, + {"cloudbilling.billingAccounts.getIamPolicy", "GET", "v1/{+resource}:getIamPolicy", "R", "", "", "", "options.requestedPolicyVersion", "resource=billingAccounts/*"}, + {"cloudbilling.billingAccounts.testIamPermissions", "POST", "v1/{+resource}:testIamPermissions", "R", "", "", "permissions", "", "resource=billingAccounts/*"}, + {"cloudbilling.billingAccounts.projects.list", "GET", "v1/{+name}/projects", "R", "", "projectBillingInfo", "", "pageToken,pageSize", "name=billingAccounts/*"}, + {"cloudbilling.projects.getBillingInfo", "GET", "v1/{+name}/billingInfo", "R", "", "", "", "", "name=projects/*"}, + {"cloudbilling.projects.updateBillingInfo", "PUT", "v1/{+name}/billingInfo", "W", "", "", "billingAccountName", "", "name=projects/*"}, + {"cloudbilling.services.list", "GET", "v1/services", "R", "", "services", "", "pageSize,pageToken", ""}, + {"cloudbilling.services.skus.list", "GET", "v1/{+parent}/skus", "R", "", "skus", "", "currencyCode,pageToken,pageSize,startTime,endTime", "parent=services/*"}, + {"cloudasset.assets.list", "GET", "v1/{+parent}/assets", "R", "", "assets", "", "relationshipTypes,contentType,readTime,pageSize,assetTypes,pageToken", "parent=*/*"}, + {"cloudasset.searchAllResources", "GET", "v1/{+scope}:searchAllResources", "R", "", "results", "", "query,assetTypes,pageSize,pageToken,orderBy,readMask", "scope=*/*"}, + {"cloudasset.searchAllIamPolicies", "GET", "v1/{+scope}:searchAllIamPolicies", "R", "", "results", "", "orderBy,pageSize,pageToken,query,assetTypes", "scope=*/*"}, + {"cloudasset.batchGetAssetsHistory", "GET", "v1/{+parent}:batchGetAssetsHistory", "R", "", "assets", "", "readTimeWindow.endTime,readTimeWindow.startTime,assetNames,contentType,relationshipTypes", "parent=*/*"}, + {"cloudasset.analyzeIamPolicy", "GET", "v1/{+scope}:analyzeIamPolicy", "R", "", "", "", "analysisQuery.conditionContext.accessTime,executionTimeout,analysisQuery.options.analyzeServiceAccountImpersonation,analysisQuery.options.expandResources,analysisQuery.options.expandRoles,analysisQuery.resourceSelector.fullResourceName,analysisQuery.options.expandGroups,analysisQuery.options.outputGroupEdges,analysisQuery.accessSelector.permissions,analysisQuery.identitySelector.identity,savedAnalysisQuery,analysisQuery.accessSelector.roles,analysisQuery.options.outputResourceEdges", "scope=*/*"}, + {"cloudasset.analyzeMove", "GET", "v1/{+resource}:analyzeMove", "R", "", "", "", "view,destinationParent", "resource=*/*"}, + {"cloudasset.exportAssets", "POST", "v1/{+parent}:exportAssets", "W", "lro", "", "readTime,outputConfig,contentType,relationshipTypes,assetTypes", "", "parent=*/*"}, + {"cloudasset.queryAssets", "POST", "v1/{+parent}:queryAssets", "R", "", "", "statement,timeout,pageSize,readTime,readTimeWindow,jobReference,pageToken,outputConfig", "", "parent=*/*"}, + {"cloudasset.analyzeOrgPolicies", "GET", "v1/{+scope}:analyzeOrgPolicies", "R", "", "orgPolicyResults", "", "pageToken,filter,constraint,pageSize", "scope=*/*"}, + {"cloudasset.feeds.list", "GET", "v1/{+parent}/feeds", "R", "", "feeds", "", "", "parent=*/*"}, + {"cloudasset.feeds.get", "GET", "v1/{+name}", "R", "", "", "", "", "name=*/*/feeds/*"}, + {"cloudasset.savedQueries.list", "GET", "v1/{+parent}/savedQueries", "R", "", "savedQueries", "", "pageSize,pageToken,filter", "parent=*/*"}, + {"cloudasset.savedQueries.get", "GET", "v1/{+name}", "R", "", "", "", "", "name=*/*/savedQueries/*"}, + {"cloudasset.operations.get", "GET", "v1/{+name}", "R", "lro", "", "", "", "name="}, + {"cloudasset.effectiveIamPolicies.batchGet", "GET", "v1/{+scope}/effectiveIamPolicies:batchGet", "R", "", "", "", "names", "scope=*/*"}, + {"orgpolicy.projects.constraints.list", "GET", "v2/{+parent}/constraints", "R", "", "constraints", "", "pageToken,pageSize", "parent=projects/*"}, + {"orgpolicy.folders.constraints.list", "GET", "v2/{+parent}/constraints", "R", "", "constraints", "", "pageToken,pageSize", "parent=folders/*"}, + {"orgpolicy.organizations.constraints.list", "GET", "v2/{+parent}/constraints", "R", "", "constraints", "", "pageToken,pageSize", "parent=organizations/*"}, + {"orgpolicy.projects.policies.list", "GET", "v2/{+parent}/policies", "R", "", "policies", "", "pageSize,pageToken", "parent=projects/*"}, + {"orgpolicy.projects.policies.get", "GET", "v2/{+name}", "R", "", "", "", "", "name=projects/*/policies/*"}, + {"orgpolicy.projects.policies.create", "POST", "v2/{+parent}/policies", "W", "", "", "alternate,spec,name,etag,dryRunSpec", "", "parent=projects/*"}, + {"orgpolicy.projects.policies.patch", "PATCH", "v2/{+name}", "W", "", "", "alternate,spec,name,etag,dryRunSpec", "updateMask", "name=projects/*/policies/*"}, + {"orgpolicy.projects.policies.delete", "DELETE", "v2/{+name}", "D", "", "", "", "etag", "name=projects/*/policies/*"}, + {"orgpolicy.projects.policies.getEffectivePolicy", "GET", "v2/{+name}:getEffectivePolicy", "R", "", "", "", "", "name=projects/*/policies/*"}, + {"orgpolicy.folders.policies.list", "GET", "v2/{+parent}/policies", "R", "", "policies", "", "pageSize,pageToken", "parent=folders/*"}, + {"orgpolicy.folders.policies.get", "GET", "v2/{+name}", "R", "", "", "", "", "name=folders/*/policies/*"}, + {"orgpolicy.folders.policies.create", "POST", "v2/{+parent}/policies", "W", "", "", "alternate,spec,name,etag,dryRunSpec", "", "parent=folders/*"}, + {"orgpolicy.folders.policies.patch", "PATCH", "v2/{+name}", "W", "", "", "alternate,spec,name,etag,dryRunSpec", "updateMask", "name=folders/*/policies/*"}, + {"orgpolicy.folders.policies.delete", "DELETE", "v2/{+name}", "D", "", "", "", "etag", "name=folders/*/policies/*"}, + {"orgpolicy.folders.policies.getEffectivePolicy", "GET", "v2/{+name}:getEffectivePolicy", "R", "", "", "", "", "name=folders/*/policies/*"}, + {"orgpolicy.organizations.policies.list", "GET", "v2/{+parent}/policies", "R", "", "policies", "", "pageToken,pageSize", "parent=organizations/*"}, + {"orgpolicy.organizations.policies.get", "GET", "v2/{+name}", "R", "", "", "", "", "name=organizations/*/policies/*"}, + {"orgpolicy.organizations.policies.create", "POST", "v2/{+parent}/policies", "W", "", "", "alternate,spec,name,etag,dryRunSpec", "", "parent=organizations/*"}, + {"orgpolicy.organizations.policies.patch", "PATCH", "v2/{+name}", "W", "", "", "alternate,spec,name,etag,dryRunSpec", "updateMask", "name=organizations/*/policies/*"}, + {"orgpolicy.organizations.policies.delete", "DELETE", "v2/{+name}", "D", "", "", "", "etag", "name=organizations/*/policies/*"}, + {"orgpolicy.organizations.policies.getEffectivePolicy", "GET", "v2/{+name}:getEffectivePolicy", "R", "", "", "", "", "name=organizations/*/policies/*"}, + {"orgpolicy.organizations.customConstraints.list", "GET", "v2/{+parent}/customConstraints", "R", "", "customConstraints", "", "pageSize,pageToken", "parent=organizations/*"}, + {"orgpolicy.organizations.customConstraints.get", "GET", "v2/{+name}", "R", "", "", "", "", "name=organizations/*/customConstraints/*"}, +}; +// CALLS-END + +const Product* products() { return kProducts; } +std::size_t product_count() { return sizeof(kProducts) / sizeof(kProducts[0]); } +const CallSpec* call_table() { return kCalls; } +std::size_t call_count() { return sizeof(kCalls) / sizeof(kCalls[0]); } + +} // namespace molo::google::ops diff --git a/src/google/ops/calls.h b/src/google/ops/calls.h new file mode 100644 index 0000000..ee96494 --- /dev/null +++ b/src/google/ops/calls.h @@ -0,0 +1,67 @@ +#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 diff --git a/src/google/ops/calls_lookup.cpp b/src/google/ops/calls_lookup.cpp new file mode 100644 index 0000000..62a9c90 --- /dev/null +++ b/src/google/ops/calls_lookup.cpp @@ -0,0 +1,86 @@ +#include "google/ops/calls.h" + +#include "google/errors.h" + +namespace molo::google::ops { + +namespace { +bool in_list(std::string_view list, std::string_view item) { + if (item.empty()) return false; + std::size_t at = 0; + while (at <= list.size()) { + std::size_t end = list.find(',', at); + if (end == std::string_view::npos) end = list.size(); + if (list.substr(at, end - at) == item) return true; + at = end + 1; + } + return false; +} +} // namespace + +Safety CallSpec::safe() const { + return safety[0] == 'R' ? Safety::kRead + : safety[0] == 'D' ? Safety::kDestructive : Safety::kWrite; +} + +clients::Method CallSpec::method() const { + std::string_view m = http; + if (m == "GET") return clients::Method::kGet; + if (m == "POST") return clients::Method::kPost; + if (m == "PATCH") return clients::Method::kPatch; + if (m == "PUT") return clients::Method::kPut; + return clients::Method::kDelete; +} + +std::string CallSpec::product() const { + std::string_view r = rpc; + return std::string(r.substr(0, r.find('.'))); +} + +bool CallSpec::has_body_field(std::string_view f) const { return in_list(body_fields, f); } +bool CallSpec::has_query(std::string_view q) const { return in_list(query_params, q); } + +std::string CallSpec::shape_of(std::string_view param) const { + std::string_view s = path_shapes; + std::size_t at = 0; + while (at < s.size()) { + std::size_t end = s.find(' ', at); + if (end == std::string_view::npos) end = s.size(); + std::string_view item = s.substr(at, end - at); + std::size_t eq = item.find('='); + if (eq != std::string_view::npos && item.substr(0, eq) == param) + return std::string(item.substr(eq + 1)); + at = end + 1; + } + return ""; +} + +const Product& product_named(const std::string& name) { + for (std::size_t i = 0; i < product_count(); ++i) + if (name == products()[i].name) return products()[i]; + throw GoogleError::invalid("unknown ops product: " + name); +} + +const CallSpec* find_call(const std::string& rpc) { + for (std::size_t i = 0; i < call_count(); ++i) + if (rpc == call_table()[i].rpc) return &call_table()[i]; + return nullptr; +} + +const CallSpec& call_named(const std::string& rpc) { + const CallSpec* c = find_call(rpc); + if (!c) throw GoogleError::invalid("unknown ops call: " + rpc); + return *c; +} + +ServiceEndpoint endpoint_of(const Product& p) { + std::string base = p.root_url; + if (p.service_path[0] != '\0') base += std::string("/") + p.service_path; + return {p.name, base}; +} + +ServiceEndpoint operation_endpoint_of(const Product& p) { + return {p.name, std::string(p.root_url) + "/" + p.version}; +} + +} // namespace molo::google::ops diff --git a/src/google/ops/caps.h b/src/google/ops/caps.h new file mode 100644 index 0000000..afd9cf1 --- /dev/null +++ b/src/google/ops/caps.h @@ -0,0 +1,25 @@ +#pragma once + +// Static ceilings for the ops package. Never autotuned. + +#include + +namespace molo::google::ops { + +struct OpsCaps { + static constexpr std::size_t kMaxSegmentChars = 256; // one path segment + static constexpr std::size_t kMaxSegments = 12; // segments of a resource name + static constexpr std::size_t kMaxPathChars = 1024; // rendered path plus query + static constexpr std::size_t kMaxQueryValueChars = 1024; + static constexpr std::size_t kMaxQueryValues = 100; // values of one repeated parameter + static constexpr std::size_t kMaxBodyBytes = 1024 * 1024; + static constexpr std::size_t kMaxOperationNameChars = 512; + static constexpr int kDefaultPageSize = 100; + static constexpr int kMaxListPages = 20; + static constexpr std::size_t kMaxListItems = 5000; + static constexpr std::size_t kMaxBatchNames = 20; // serviceusage batchGet / batchEnable + static constexpr std::size_t kMaxLogEntries = 1000; // logging entries.list + static constexpr std::size_t kMaxSignPayloadBytes = 64 * 1024; +}; + +} // namespace molo::google::ops diff --git a/src/google/ops/cloud_asset.h b/src/google/ops/cloud_asset.h new file mode 100644 index 0000000..97c1fa5 --- /dev/null +++ b/src/google/ops/cloud_asset.h @@ -0,0 +1,60 @@ +#pragma once + +// Cloud Asset v1. `scope` / `parent` is projects/{p}, folders/{f} or +// organizations/{o}. Searches are capped at OpsCaps::kMaxListItems rows. + +#include + +#include "google/ops/ops_product.h" + +namespace molo::google::ops { + +class CloudAsset : public OpsProduct { + public: + using Json = clients::body::Json; + explicit CloudAsset(std::shared_ptr c, Sleeper s = nullptr) + : OpsProduct(std::move(c), "cloudasset", std::move(s)) {} + + Json search_resources(const std::string& scope, const std::string& query = "", + const std::vector& asset_types = {}) const { + Args a = at("scope", scope); + if (!query.empty()) a.query("query", Json(query)); + put_types(a, asset_types); + return list("cloudasset.searchAllResources", a, 5); + } + Json search_iam_policies(const std::string& scope, const std::string& query = "") const { + Args a = at("scope", scope); + if (!query.empty()) a.query("query", Json(query)); + return list("cloudasset.searchAllIamPolicies", a, 5); + } + Json assets(const std::string& parent, const std::vector& asset_types = {}) const { + Args a = at("parent", parent); + put_types(a, asset_types); + return list("cloudasset.assets.list", a, 5); + } + Json feeds(const std::string& parent) const { + return read("cloudasset.feeds.list", at("parent", parent)); + } + Json saved_queries(const std::string& parent) const { + return list("cloudasset.savedQueries.list", at("parent", parent)); + } + Json operation(const std::string& name) const { + return read("cloudasset.operations.get", at("name", name)); + } + + // body: ExportAssetsRequest incl. outputConfig (writes to Cloud Storage or + // BigQuery), so it is a write. + Outcome export_assets(const std::string& parent, const Json& body, bool confirm = false) const { + return call("cloudasset.exportAssets", at("parent", parent).body(body), confirm); + } + + private: + static void put_types(Args& a, const std::vector& types) { + if (types.empty()) return; + Json arr = Json::array(); + for (const std::string& t : types) arr.push(Json(t)); + a.query("assetTypes", arr); + } +}; + +} // namespace molo::google::ops diff --git a/src/google/ops/cloud_build.h b/src/google/ops/cloud_build.h new file mode 100644 index 0000000..19bbcde --- /dev/null +++ b/src/google/ops/cloud_build.h @@ -0,0 +1,59 @@ +#pragma once + +// Cloud Build v1 (regional rows: parent is projects/{p}/locations/{l}, use +// "global" for the default region). + +#include "google/ops/ops_product.h" + +namespace molo::google::ops { + +class CloudBuild : public OpsProduct { + public: + using Json = clients::body::Json; + explicit CloudBuild(std::shared_ptr c, Sleeper s = nullptr) + : OpsProduct(std::move(c), "cloudbuild", std::move(s)) {} + + Json builds(const std::string& parent) const { + return list("cloudbuild.projects.locations.builds.list", at("parent", parent)); + } + Json build(const std::string& name) const { + return read("cloudbuild.projects.locations.builds.get", at("name", name)); + } + Json triggers(const std::string& parent) const { + return list("cloudbuild.projects.locations.triggers.list", at("parent", parent)); + } + Json trigger(const std::string& name) const { + return read("cloudbuild.projects.locations.triggers.get", at("name", name)); + } + Json worker_pools(const std::string& parent) const { + return list("cloudbuild.projects.locations.workerPools.list", at("parent", parent)); + } + Json default_service_account(const std::string& name) const { + return read("cloudbuild.projects.locations.getDefaultServiceAccount", at("name", name)); + } + Json operation(const std::string& name) const { + return read("cloudbuild.projects.locations.operations.get", at("name", name)); + } + + Outcome create_build(const std::string& parent, const Json& build, bool confirm = false) const { + return call("cloudbuild.projects.locations.builds.create", at("parent", parent).body(build), + confirm); + } + Outcome cancel_build(const std::string& name, bool confirm = false) const { + return call("cloudbuild.projects.locations.builds.cancel", at("name", name), confirm); + } + Outcome retry_build(const std::string& name, bool confirm = false) const { + return call("cloudbuild.projects.locations.builds.retry", at("name", name), confirm); + } + Outcome run_trigger(const std::string& name, bool confirm = false) const { + return call("cloudbuild.projects.locations.triggers.run", at("name", name), confirm); + } + Outcome delete_trigger(const std::string& name, bool confirm) const { + return call("cloudbuild.projects.locations.triggers.delete", at("name", name), confirm); + } + Outcome delete_worker_pool(const std::string& name, bool confirm) const { + return call("cloudbuild.projects.locations.workerPools.delete", at("name", name), confirm); + } +}; + +} // namespace molo::google::ops diff --git a/src/google/ops/cloud_functions.h b/src/google/ops/cloud_functions.h new file mode 100644 index 0000000..7ea3890 --- /dev/null +++ b/src/google/ops/cloud_functions.h @@ -0,0 +1,50 @@ +#pragma once + +// Cloud Functions v2 (2nd gen). `parent` is projects/{p}/locations/{l}. + +#include "google/ops/ops_product.h" + +namespace molo::google::ops { + +class CloudFunctions : public OpsProduct { + public: + using Json = clients::body::Json; + explicit CloudFunctions(std::shared_ptr c, Sleeper s = nullptr) + : OpsProduct(std::move(c), "cloudfunctions", std::move(s)) {} + + Json locations(const std::string& project_name) const { + return list("cloudfunctions.projects.locations.list", at("name", project_name)); + } + Json functions(const std::string& parent) const { + return list("cloudfunctions.projects.locations.functions.list", at("parent", parent)); + } + Json function(const std::string& name) const { + return read("cloudfunctions.projects.locations.functions.get", at("name", name)); + } + Json runtimes(const std::string& parent) const { + return list("cloudfunctions.projects.locations.runtimes.list", at("parent", parent)); + } + Json operation(const std::string& name) const { + return read("cloudfunctions.projects.locations.operations.get", at("name", name)); + } + Json iam_policy(const std::string& function_name) const { + return read("cloudfunctions.projects.locations.functions.getIamPolicy", + at("resource", function_name)); + } + + Outcome generate_upload_url(const std::string& parent, bool confirm = false) const { + return call("cloudfunctions.projects.locations.functions.generateUploadUrl", + at("parent", parent), confirm); + } + Outcome create_function(const std::string& parent, const std::string& function_id, + const Json& function, bool confirm = false) const { + Args a = at("parent", parent); + a.query("functionId", Json(function_id)).body(function); + return call("cloudfunctions.projects.locations.functions.create", a, confirm); + } + Outcome delete_function(const std::string& name, bool confirm) const { + return call("cloudfunctions.projects.locations.functions.delete", at("name", name), confirm); + } +}; + +} // namespace molo::google::ops diff --git a/src/google/ops/cloud_logging.h b/src/google/ops/cloud_logging.h new file mode 100644 index 0000000..16c0946 --- /dev/null +++ b/src/google/ops/cloud_logging.h @@ -0,0 +1,84 @@ +#pragma once + +// Cloud Logging v2: read entries and log names, sinks, metrics, exclusions, +// buckets. write_entries and delete_log are explicit (dry run unless +// confirm). Entry reads are capped at OpsCaps::kMaxLogEntries. + +#include + +#include "google/errors.h" +#include "google/ops/ops_product.h" + +namespace molo::google::ops { + +class CloudLogging : public OpsProduct { + public: + using Json = clients::body::Json; + explicit CloudLogging(std::shared_ptr c, Sleeper s = nullptr) + : OpsProduct(std::move(c), "logging", std::move(s)) {} + + // resource_names: projects/p, folders/f, organizations/o, ... + // filter: Logging query language; order_by "timestamp desc" or "timestamp asc". + // Returns at most `limit` entries (1..kMaxLogEntries) from one page. + Json entries(const std::vector& resource_names, const std::string& filter, + const std::string& order_by = "timestamp desc", int limit = 50) const { + if (resource_names.empty() || resource_names.size() > 10) + throw GoogleError::invalid("resourceNames must hold 1..10 names"); + if (limit < 1 || static_cast(limit) > OpsCaps::kMaxLogEntries) + throw GoogleError::invalid("limit must be 1.." + std::to_string(OpsCaps::kMaxLogEntries)); + if (filter.size() > 2048) throw GoogleError::invalid("filter too long"); + if (order_by != "timestamp desc" && order_by != "timestamp asc") + throw GoogleError::invalid("orderBy must be 'timestamp desc' or 'timestamp asc'"); + Json names = Json::array(); + for (const std::string& n : resource_names) names.push(Json(n)); + Args a; + a.field("resourceNames", names).field("orderBy", Json(order_by)).field("pageSize", Json(limit)); + if (!filter.empty()) a.field("filter", Json(filter)); + Json reply = ops_read("logging.entries.list", a); + return reply.find("entries") ? *reply.find("entries") : Json::array(); + } + Json log_names(const std::string& parent) const { + return list("logging.projects.logs.list", at("parent", parent)); + } + Json resource_descriptors() const { return list("logging.monitoredResourceDescriptors.list", Args()); } + Json sinks(const std::string& parent) const { + return list("logging.projects.sinks.list", at("parent", parent)); + } + Json sink(const std::string& name) const { + return read("logging.projects.sinks.get", at("sinkName", name)); + } + Json metrics(const std::string& parent) const { + return list("logging.projects.metrics.list", at("parent", parent)); + } + Json metric(const std::string& name) const { + return read("logging.projects.metrics.get", at("metricName", name)); + } + Json exclusions(const std::string& parent) const { + return list("logging.projects.exclusions.list", at("parent", parent)); + } + Json buckets(const std::string& parent) const { + return list("logging.projects.locations.buckets.list", at("parent", parent)); + } + Json settings(const std::string& name) const { + return read("logging.projects.getSettings", at("name", name)); + } + + // body: LogEntry list etc. as in the API (logName, resource, entries, ...). + Outcome write_entries(const Json& body, bool confirm = false) const { + return call("logging.entries.write", Args().body(body), confirm); + } + Outcome delete_log(const std::string& log_name, bool confirm) const { + return call("logging.projects.logs.delete", at("logName", log_name), confirm); + } + Outcome delete_sink(const std::string& sink_name, bool confirm) const { + return call("logging.projects.sinks.delete", at("sinkName", sink_name), confirm); + } + Outcome delete_metric(const std::string& metric_name, bool confirm) const { + return call("logging.projects.metrics.delete", at("metricName", metric_name), confirm); + } + + private: + Json ops_read(const std::string& rpc, const Args& a) const { return read(rpc, a); } +}; + +} // namespace molo::google::ops diff --git a/src/google/ops/cloud_monitoring.h b/src/google/ops/cloud_monitoring.h new file mode 100644 index 0000000..2d7f515 --- /dev/null +++ b/src/google/ops/cloud_monitoring.h @@ -0,0 +1,71 @@ +#pragma once + +// Cloud Monitoring v3. `name` is projects/{p} unless said otherwise. Time +// series reads need a filter and an interval (RFC 3339 timestamps). + +#include "google/errors.h" +#include "google/ops/ops_product.h" + +namespace molo::google::ops { + +class CloudMonitoring : public OpsProduct { + public: + using Json = clients::body::Json; + explicit CloudMonitoring(std::shared_ptr c, Sleeper s = nullptr) + : OpsProduct(std::move(c), "monitoring", std::move(s)) {} + + // filter: e.g. metric.type = "compute.googleapis.com/instance/cpu/utilization". + Json time_series(const std::string& project_name, const std::string& filter, + const std::string& start_time, const std::string& end_time) const { + if (filter.empty() || filter.size() > 2048) throw GoogleError::invalid("bad filter"); + Args a = at("name", project_name); + a.query("filter", Json(filter)) + .query("interval.startTime", Json(start_time)) + .query("interval.endTime", Json(end_time)); + return list("monitoring.projects.timeSeries.list", a, 5); + } + Json metric_descriptors(const std::string& project_name, const std::string& filter = "") const { + Args a = at("name", project_name); + if (!filter.empty()) a.query("filter", Json(filter)); + return list("monitoring.projects.metricDescriptors.list", a); + } + Json metric_descriptor(const std::string& name) const { + return read("monitoring.projects.metricDescriptors.get", at("name", name)); + } + Json resource_descriptors(const std::string& project_name) const { + return list("monitoring.projects.monitoredResourceDescriptors.list", at("name", project_name)); + } + Json alert_policies(const std::string& project_name) const { + return list("monitoring.projects.alertPolicies.list", at("name", project_name)); + } + Json alert_policy(const std::string& name) const { + return read("monitoring.projects.alertPolicies.get", at("name", name)); + } + Json notification_channels(const std::string& project_name) const { + return list("monitoring.projects.notificationChannels.list", at("name", project_name)); + } + Json groups(const std::string& project_name) const { + return list("monitoring.projects.groups.list", at("name", project_name)); + } + Json uptime_checks(const std::string& project_name) const { + return list("monitoring.projects.uptimeCheckConfigs.list", at("parent", project_name)); + } + Json services(const std::string& project_name) const { + return list("monitoring.services.list", at("parent", project_name)); + } + Json alerts(const std::string& project_name) const { + return list("monitoring.projects.alerts.list", at("parent", project_name)); + } + + Outcome write_time_series(const std::string& project_name, const Json& series, + bool confirm = false) const { + Args a = at("name", project_name); + a.field("timeSeries", series); + return call("monitoring.projects.timeSeries.create", a, confirm); + } + Outcome delete_alert_policy(const std::string& name, bool confirm) const { + return call("monitoring.projects.alertPolicies.delete", at("name", name), confirm); + } +}; + +} // namespace molo::google::ops diff --git a/src/google/ops/cloud_run.h b/src/google/ops/cloud_run.h new file mode 100644 index 0000000..63fcb7f --- /dev/null +++ b/src/google/ops/cloud_run.h @@ -0,0 +1,68 @@ +#pragma once + +// Cloud Run Admin v2: services, revisions, jobs, executions, tasks. +// `parent` is projects/{p}/locations/{l} (see Names::location); service and +// job names are the full resource names. + +#include "google/ops/ops_product.h" + +namespace molo::google::ops { + +class CloudRun : public OpsProduct { + public: + using Json = clients::body::Json; + explicit CloudRun(std::shared_ptr c, Sleeper s = nullptr) + : OpsProduct(std::move(c), "run", std::move(s)) {} + + Json services(const std::string& parent) const { + return list("run.projects.locations.services.list", at("parent", parent)); + } + Json service(const std::string& name) const { + return read("run.projects.locations.services.get", at("name", name)); + } + Json revisions(const std::string& service_name) const { + return list("run.projects.locations.services.revisions.list", at("parent", service_name)); + } + Json jobs(const std::string& parent) const { + return list("run.projects.locations.jobs.list", at("parent", parent)); + } + Json job(const std::string& name) const { + return read("run.projects.locations.jobs.get", at("name", name)); + } + Json executions(const std::string& job_name) const { + return list("run.projects.locations.jobs.executions.list", at("parent", job_name)); + } + Json execution(const std::string& name) const { + return read("run.projects.locations.jobs.executions.get", at("name", name)); + } + Json service_iam_policy(const std::string& service_name) const { + return read("run.projects.locations.services.getIamPolicy", at("resource", service_name)); + } + Json operation(const std::string& name) const { + return read("run.projects.locations.operations.get", at("name", name)); + } + + Outcome run_job(const std::string& name, bool confirm = false) const { + return call("run.projects.locations.jobs.run", at("name", name), confirm); + } + Outcome cancel_execution(const std::string& name, bool confirm = false) const { + return call("run.projects.locations.jobs.executions.cancel", at("name", name), confirm); + } + Outcome create_service(const std::string& parent, const std::string& service_id, + const Json& service, bool confirm = false) const { + Args a = at("parent", parent); + a.query("serviceId", Json(service_id)).body(service); + return call("run.projects.locations.services.create", a, confirm); + } + Outcome delete_service(const std::string& name, bool confirm) const { + return call("run.projects.locations.services.delete", at("name", name), confirm); + } + Outcome delete_job(const std::string& name, bool confirm) const { + return call("run.projects.locations.jobs.delete", at("name", name), confirm); + } + Outcome delete_revision(const std::string& name, bool confirm) const { + return call("run.projects.locations.services.revisions.delete", at("name", name), confirm); + } +}; + +} // namespace molo::google::ops diff --git a/src/google/ops/cloud_scheduler.h b/src/google/ops/cloud_scheduler.h new file mode 100644 index 0000000..e2b90fe --- /dev/null +++ b/src/google/ops/cloud_scheduler.h @@ -0,0 +1,44 @@ +#pragma once + +// Cloud Scheduler v1. `parent` is projects/{p}/locations/{l}. + +#include "google/ops/ops_product.h" + +namespace molo::google::ops { + +class CloudScheduler : public OpsProduct { + public: + using Json = clients::body::Json; + explicit CloudScheduler(std::shared_ptr c, Sleeper s = nullptr) + : OpsProduct(std::move(c), "cloudscheduler", std::move(s)) {} + + Json locations(const std::string& project_name) const { + return list("cloudscheduler.projects.locations.list", at("name", project_name)); + } + Json jobs(const std::string& parent) const { + return list("cloudscheduler.projects.locations.jobs.list", at("parent", parent)); + } + Json job(const std::string& name) const { + return read("cloudscheduler.projects.locations.jobs.get", at("name", name)); + } + + Outcome create_job(const std::string& parent, const Json& job, bool confirm = false) const { + return call("cloudscheduler.projects.locations.jobs.create", at("parent", parent).body(job), + confirm); + } + Outcome pause_job(const std::string& name, bool confirm = false) const { + return call("cloudscheduler.projects.locations.jobs.pause", at("name", name), confirm); + } + Outcome resume_job(const std::string& name, bool confirm = false) const { + return call("cloudscheduler.projects.locations.jobs.resume", at("name", name), confirm); + } + // Fires the job now (runs its target). + Outcome run_job(const std::string& name, bool confirm = false) const { + return call("cloudscheduler.projects.locations.jobs.run", at("name", name), confirm); + } + Outcome delete_job(const std::string& name, bool confirm) const { + return call("cloudscheduler.projects.locations.jobs.delete", at("name", name), confirm); + } +}; + +} // namespace molo::google::ops diff --git a/src/google/ops/cloud_tasks.h b/src/google/ops/cloud_tasks.h new file mode 100644 index 0000000..ecda63c --- /dev/null +++ b/src/google/ops/cloud_tasks.h @@ -0,0 +1,59 @@ +#pragma once + +// Cloud Tasks v2. `parent` is projects/{p}/locations/{l}; tasks hang off a +// full queue name. + +#include "google/ops/ops_product.h" + +namespace molo::google::ops { + +class CloudTasks : public OpsProduct { + public: + using Json = clients::body::Json; + explicit CloudTasks(std::shared_ptr c, Sleeper s = nullptr) + : OpsProduct(std::move(c), "cloudtasks", std::move(s)) {} + + Json queues(const std::string& parent) const { + return list("cloudtasks.projects.locations.queues.list", at("parent", parent)); + } + Json queue(const std::string& name) const { + return read("cloudtasks.projects.locations.queues.get", at("name", name)); + } + Json tasks(const std::string& queue_name) const { + return list("cloudtasks.projects.locations.queues.tasks.list", at("parent", queue_name)); + } + Json task(const std::string& name) const { + return read("cloudtasks.projects.locations.queues.tasks.get", at("name", name)); + } + + Outcome create_queue(const std::string& parent, const Json& queue, bool confirm = false) const { + return call("cloudtasks.projects.locations.queues.create", at("parent", parent).body(queue), + confirm); + } + Outcome pause_queue(const std::string& name, bool confirm = false) const { + return call("cloudtasks.projects.locations.queues.pause", at("name", name), confirm); + } + Outcome resume_queue(const std::string& name, bool confirm = false) const { + return call("cloudtasks.projects.locations.queues.resume", at("name", name), confirm); + } + Outcome create_task(const std::string& queue_name, const Json& task, bool confirm = false) const { + Args a = at("parent", queue_name); + a.field("task", task); + return call("cloudtasks.projects.locations.queues.tasks.create", a, confirm); + } + Outcome run_task(const std::string& name, bool confirm = false) const { + return call("cloudtasks.projects.locations.queues.tasks.run", at("name", name), confirm); + } + // Destructive: no default. + Outcome purge_queue(const std::string& name, bool confirm) const { + return call("cloudtasks.projects.locations.queues.purge", at("name", name), confirm); + } + Outcome delete_queue(const std::string& name, bool confirm) const { + return call("cloudtasks.projects.locations.queues.delete", at("name", name), confirm); + } + Outcome delete_task(const std::string& name, bool confirm) const { + return call("cloudtasks.projects.locations.queues.tasks.delete", at("name", name), confirm); + } +}; + +} // namespace molo::google::ops diff --git a/src/google/ops/compute.h b/src/google/ops/compute.h new file mode 100644 index 0000000..11f2fd2 --- /dev/null +++ b/src/google/ops/compute.h @@ -0,0 +1,93 @@ +#pragma once + +// Compute Engine v1: read the fleet, and start / stop / reset / insert / +// delete instances. Compute operations are not google.longrunning: poll them +// with zone_operation / wait_zone_operation. + +#include "google/ops/ops_product.h" + +namespace molo::google::ops { + +class Compute : public OpsProduct { + public: + explicit Compute(std::shared_ptr c, Sleeper s = nullptr) + : OpsProduct(std::move(c), "compute", std::move(s)) {} + + using Json = clients::body::Json; + + Json instances(const std::string& project, const std::string& zone) const { + return list("compute.instances.list", zonal(project, zone)); + } + Json instance(const std::string& project, const std::string& zone, + const std::string& name) const { + return read("compute.instances.get", zonal(project, zone).path("instance", name)); + } + Json zones(const std::string& project) const { + return list("compute.zones.list", at("project", project)); + } + Json regions(const std::string& project) const { + return list("compute.regions.list", at("project", project)); + } + Json machine_types(const std::string& project, const std::string& zone) const { + return list("compute.machineTypes.list", zonal(project, zone)); + } + Json disks(const std::string& project, const std::string& zone) const { + return list("compute.disks.list", zonal(project, zone)); + } + Json networks(const std::string& project) const { + return list("compute.networks.list", at("project", project)); + } + Json subnetworks(const std::string& project, const std::string& region) const { + return list("compute.subnetworks.list", at("project", project).path("region", region)); + } + Json firewalls(const std::string& project) const { + return list("compute.firewalls.list", at("project", project)); + } + Json images(const std::string& project) const { + return list("compute.images.list", at("project", project)); + } + Json project_info(const std::string& project) const { + return read("compute.projects.get", at("project", project)); + } + Json zone_operation(const std::string& project, const std::string& zone, + const std::string& operation) const { + return read("compute.zoneOperations.get", zonal(project, zone).path("operation", operation)); + } + // Server side wait (Google holds the request up to about two minutes). + Json wait_zone_operation(const std::string& project, const std::string& zone, + const std::string& operation) const { + return read("compute.zoneOperations.wait", zonal(project, zone).path("operation", operation)); + } + + // Writes: dry run unless confirm. + Outcome start_instance(const std::string& project, const std::string& zone, + const std::string& name, bool confirm = false) const { + return call("compute.instances.start", zonal(project, zone).path("instance", name), confirm); + } + Outcome stop_instance(const std::string& project, const std::string& zone, + const std::string& name, bool confirm = false) const { + return call("compute.instances.stop", zonal(project, zone).path("instance", name), confirm); + } + Outcome reset_instance(const std::string& project, const std::string& zone, + const std::string& name, bool confirm = false) const { + return call("compute.instances.reset", zonal(project, zone).path("instance", name), confirm); + } + Outcome insert_instance(const std::string& project, const std::string& zone, + const Json& body, bool confirm = false) const { + return call("compute.instances.insert", zonal(project, zone).body(body), confirm); + } + // Destructive: no default. + Outcome delete_instance(const std::string& project, const std::string& zone, + const std::string& name, bool confirm) const { + return call("compute.instances.delete", zonal(project, zone).path("instance", name), confirm); + } + + private: + static Args zonal(const std::string& project, const std::string& zone) { + Args a; + a.path("project", project).path("zone", zone); + return a; + } +}; + +} // namespace molo::google::ops diff --git a/src/google/ops/eventarc.h b/src/google/ops/eventarc.h new file mode 100644 index 0000000..2aca906 --- /dev/null +++ b/src/google/ops/eventarc.h @@ -0,0 +1,57 @@ +#pragma once + +// Eventarc v1. `parent` is projects/{p}/locations/{l}. + +#include "google/ops/ops_product.h" + +namespace molo::google::ops { + +class Eventarc : public OpsProduct { + public: + using Json = clients::body::Json; + explicit Eventarc(std::shared_ptr c, Sleeper s = nullptr) + : OpsProduct(std::move(c), "eventarc", std::move(s)) {} + + Json locations(const std::string& project_name) const { + return list("eventarc.projects.locations.list", at("name", project_name)); + } + Json triggers(const std::string& parent) const { + return list("eventarc.projects.locations.triggers.list", at("parent", parent)); + } + Json trigger(const std::string& name) const { + return read("eventarc.projects.locations.triggers.get", at("name", name)); + } + Json channels(const std::string& parent) const { + return list("eventarc.projects.locations.channels.list", at("parent", parent)); + } + Json providers(const std::string& parent) const { + return list("eventarc.projects.locations.providers.list", at("parent", parent)); + } + Json pipelines(const std::string& parent) const { + return list("eventarc.projects.locations.pipelines.list", at("parent", parent)); + } + Json message_buses(const std::string& parent) const { + return list("eventarc.projects.locations.messageBuses.list", at("parent", parent)); + } + Json enrollments(const std::string& parent) const { + return list("eventarc.projects.locations.enrollments.list", at("parent", parent)); + } + Json operation(const std::string& name) const { + return read("eventarc.projects.locations.operations.get", at("name", name)); + } + + Outcome create_trigger(const std::string& parent, const std::string& trigger_id, + const Json& trigger, bool confirm = false) const { + Args a = at("parent", parent); + a.query("triggerId", Json(trigger_id)).body(trigger); + return call("eventarc.projects.locations.triggers.create", a, confirm); + } + Outcome delete_trigger(const std::string& name, bool confirm) const { + return call("eventarc.projects.locations.triggers.delete", at("name", name), confirm); + } + Outcome delete_channel(const std::string& name, bool confirm) const { + return call("eventarc.projects.locations.channels.delete", at("name", name), confirm); + } +}; + +} // namespace molo::google::ops diff --git a/src/google/ops/gke.h b/src/google/ops/gke.h new file mode 100644 index 0000000..a292fd3 --- /dev/null +++ b/src/google/ops/gke.h @@ -0,0 +1,63 @@ +#pragma once + +// Google Kubernetes Engine (container v1). `parent` is +// projects/{p}/locations/{l}; l is a region or a zone. GKE operations are not +// google.longrunning: poll `operation(name)` until its status is DONE. + +#include "google/ops/ops_product.h" + +namespace molo::google::ops { + +class Gke : public OpsProduct { + public: + using Json = clients::body::Json; + explicit Gke(std::shared_ptr c, Sleeper s = nullptr) + : OpsProduct(std::move(c), "container", std::move(s)) {} + + Json clusters(const std::string& parent) const { + return read("container.projects.locations.clusters.list", at("parent", parent)); + } + Json cluster(const std::string& name) const { + return read("container.projects.locations.clusters.get", at("name", name)); + } + Json node_pools(const std::string& cluster_name) const { + return read("container.projects.locations.clusters.nodePools.list", + at("parent", cluster_name)); + } + Json node_pool(const std::string& name) const { + return read("container.projects.locations.clusters.nodePools.get", at("name", name)); + } + Json operations(const std::string& parent) const { + return read("container.projects.locations.operations.list", at("parent", parent)); + } + Json operation(const std::string& name) const { + return read("container.projects.locations.operations.get", at("name", name)); + } + Json server_config(const std::string& location_name) const { + return read("container.projects.locations.getServerConfig", at("name", location_name)); + } + Json usable_subnetworks(const std::string& project_name) const { + return list("container.projects.aggregated.usableSubnetworks.list", + at("parent", project_name)); + } + + Outcome create_cluster(const std::string& parent, const Json& request, + bool confirm = false) const { + return call("container.projects.locations.clusters.create", at("parent", parent).body(request), + confirm); + } + Outcome set_node_pool_size(const std::string& name, int node_count, bool confirm = false) const { + Args a = at("name", name); + a.field("nodeCount", Json(node_count)); + return call("container.projects.locations.clusters.nodePools.setSize", a, confirm); + } + Outcome delete_cluster(const std::string& name, bool confirm) const { + return call("container.projects.locations.clusters.delete", at("name", name), confirm); + } + Outcome delete_node_pool(const std::string& name, bool confirm) const { + return call("container.projects.locations.clusters.nodePools.delete", at("name", name), + confirm); + } +}; + +} // namespace molo::google::ops diff --git a/src/google/ops/iam.h b/src/google/ops/iam.h new file mode 100644 index 0000000..137d9aa --- /dev/null +++ b/src/google/ops/iam.h @@ -0,0 +1,97 @@ +#pragma once + +// IAM v1: roles, permissions, service accounts and their keys, policies, +// testIamPermissions. Signing (signJwt, signBlob, access and id tokens) is the +// separate IAM Credentials API: see iam_credentials.h. Needs +// iam.googleapis.com enabled on the project. + +#include + +#include "google/ops/ops_product.h" + +namespace molo::google::ops { + +class Iam : public OpsProduct { + public: + using Json = clients::body::Json; + explicit Iam(std::shared_ptr c, Sleeper s = nullptr) + : OpsProduct(std::move(c), "iam", std::move(s)) {} + + // Predefined roles (roles/...). + Json roles() const { return list("iam.roles.list", Args()); } + Json role(const std::string& name) const { return read("iam.roles.get", at("name", name)); } + Json project_roles(const std::string& project_name) const { + return list("iam.projects.roles.list", at("parent", project_name)); + } + Json organization_roles(const std::string& organization_name) const { + return list("iam.organizations.roles.list", at("parent", organization_name)); + } + // Roles that can be granted on a resource (full resource name). + Json grantable_roles(const std::string& full_resource_name) const { + Args a; + a.field("fullResourceName", Json(full_resource_name)); + return list("iam.roles.queryGrantableRoles", a); + } + Json testable_permissions(const std::string& full_resource_name) const { + Args a; + a.field("fullResourceName", Json(full_resource_name)); + return list("iam.permissions.queryTestablePermissions", a); + } + + Json service_accounts(const std::string& project_name) const { + return list("iam.projects.serviceAccounts.list", at("name", project_name)); + } + Json service_account(const std::string& name) const { + return read("iam.projects.serviceAccounts.get", at("name", name)); + } + Json service_account_keys(const std::string& account_name) const { + return list("iam.projects.serviceAccounts.keys.list", at("name", account_name)); + } + Json service_account_key(const std::string& key_name) const { + return read("iam.projects.serviceAccounts.keys.get", at("name", key_name)); + } + Json service_account_policy(const std::string& account_name) const { + return read("iam.projects.serviceAccounts.getIamPolicy", at("resource", account_name)); + } + // The subset of `permissions` the caller holds on the service account. + Json test_permissions(const std::string& account_name, + const std::vector& permissions) const { + Json list_json = Json::array(); + for (const std::string& p : permissions) list_json.push(Json(p)); + Args a = at("resource", account_name); + a.field("permissions", list_json); + return read("iam.projects.serviceAccounts.testIamPermissions", a); + } + + Outcome create_service_account(const std::string& project_name, const std::string& account_id, + const std::string& display_name, bool confirm = false) const { + Json sa = Json::object(); + sa.set("displayName", Json(display_name)); + Args a = at("name", project_name); + a.field("accountId", Json(account_id)).field("serviceAccount", sa); + return call("iam.projects.serviceAccounts.create", a, confirm); + } + Outcome create_key(const std::string& account_name, bool confirm = false) const { + return call("iam.projects.serviceAccounts.keys.create", at("name", account_name), confirm); + } + Outcome enable_service_account(const std::string& name, bool confirm = false) const { + return call("iam.projects.serviceAccounts.enable", at("name", name), confirm); + } + Outcome disable_service_account(const std::string& name, bool confirm = false) const { + return call("iam.projects.serviceAccounts.disable", at("name", name), confirm); + } + Outcome disable_key(const std::string& key_name, bool confirm = false) const { + return call("iam.projects.serviceAccounts.keys.disable", at("name", key_name), confirm); + } + Outcome delete_service_account(const std::string& name, bool confirm) const { + return call("iam.projects.serviceAccounts.delete", at("name", name), confirm); + } + Outcome delete_key(const std::string& key_name, bool confirm) const { + return call("iam.projects.serviceAccounts.keys.delete", at("name", key_name), confirm); + } + Outcome delete_role(const std::string& name, bool confirm) const { + return call("iam.projects.roles.delete", at("name", name), confirm); + } +}; + +} // namespace molo::google::ops diff --git a/src/google/ops/iam_credentials.h b/src/google/ops/iam_credentials.h new file mode 100644 index 0000000..69e619f --- /dev/null +++ b/src/google/ops/iam_credentials.h @@ -0,0 +1,56 @@ +#pragma once + +// IAM Service Account Credentials v1: signJwt, signBlob, access tokens and id +// tokens for a service account the caller may impersonate. Signing changes no +// state, so these run directly. Payload sizes are capped. + +#include + +#include "google/errors.h" +#include "google/ops/ops_product.h" + +namespace molo::google::ops { + +class IamCredentials : public OpsProduct { + public: + using Json = clients::body::Json; + explicit IamCredentials(std::shared_ptr c, Sleeper s = nullptr) + : OpsProduct(std::move(c), "iamcredentials", std::move(s)) {} + + // payload: a JSON object serialized as a string (the claim set). + Json sign_jwt(const std::string& account_name, const std::string& payload) const { + check_payload(payload); + Args a = at("name", account_name); + a.field("payload", Json(payload)); + return read("iamcredentials.projects.serviceAccounts.signJwt", a); + } + // base64_payload: the bytes to sign, base64 encoded. + Json sign_blob(const std::string& account_name, const std::string& base64_payload) const { + check_payload(base64_payload); + Args a = at("name", account_name); + a.field("payload", Json(base64_payload)); + return read("iamcredentials.projects.serviceAccounts.signBlob", a); + } + Json generate_access_token(const std::string& account_name, + const std::vector& scopes) const { + Json arr = Json::array(); + for (const std::string& s : scopes) arr.push(Json(s)); + Args a = at("name", account_name); + a.field("scope", arr); + return read("iamcredentials.projects.serviceAccounts.generateAccessToken", a); + } + Json generate_id_token(const std::string& account_name, const std::string& audience) const { + Args a = at("name", account_name); + a.field("audience", Json(audience)); + return read("iamcredentials.projects.serviceAccounts.generateIdToken", a); + } + + private: + static void check_payload(const std::string& p) { + if (p.empty() || p.size() > OpsCaps::kMaxSignPayloadBytes) + throw GoogleError::invalid("payload must be 1.." + + std::to_string(OpsCaps::kMaxSignPayloadBytes) + " bytes"); + } +}; + +} // namespace molo::google::ops diff --git a/src/google/ops/ops.h b/src/google/ops/ops.h new file mode 100644 index 0000000..5b03385 --- /dev/null +++ b/src/google/ops/ops.h @@ -0,0 +1,78 @@ +#pragma once + +// Ops: one object holding every product of the package over one GoogleClient. +// `product("run")` reaches a product by Discovery name for generic callers +// (the demo, the conformance tests). + +#include +#include + +#include "google/ops/artifact_registry.h" +#include "google/ops/billing.h" +#include "google/ops/cloud_asset.h" +#include "google/ops/cloud_build.h" +#include "google/ops/cloud_functions.h" +#include "google/ops/cloud_logging.h" +#include "google/ops/cloud_monitoring.h" +#include "google/ops/cloud_run.h" +#include "google/ops/cloud_scheduler.h" +#include "google/ops/cloud_tasks.h" +#include "google/ops/compute.h" +#include "google/ops/eventarc.h" +#include "google/ops/gke.h" +#include "google/ops/iam.h" +#include "google/ops/iam_credentials.h" +#include "google/ops/org_policy.h" +#include "google/ops/resource_manager.h" +#include "google/ops/service_usage.h" +#include "google/ops/workflows.h" + +namespace molo::google::ops { + +class Ops { + public: + explicit Ops(std::shared_ptr client, Sleeper sleeper = nullptr) + : compute(client, sleeper), run(client, sleeper), functions(client, sleeper), + gke(client, sleeper), build(client, sleeper), artifacts(client, sleeper), + iam(client, sleeper), credentials(client, sleeper), projects(client, sleeper), + services(client, sleeper), logging(client, sleeper), monitoring(client, sleeper), + scheduler(client, sleeper), tasks(client, sleeper), workflows(client, sleeper), + executions(client, sleeper), eventarc(client, sleeper), billing(client, sleeper), + assets(client, sleeper), policies(client, sleeper) {} + + Compute compute; + CloudRun run; + CloudFunctions functions; + Gke gke; + CloudBuild build; + ArtifactRegistry artifacts; + Iam iam; + IamCredentials credentials; + ResourceManager projects; + ServiceUsage services; + CloudLogging logging; + CloudMonitoring monitoring; + CloudScheduler scheduler; + CloudTasks tasks; + Workflows workflows; + WorkflowExecutions executions; + Eventarc eventarc; + Billing billing; + CloudAsset assets; + OrgPolicy policies; + + // All products in table order. + std::vector all() const { + return {&compute, &run, &functions, &gke, &build, &artifacts, &iam, + &credentials, &projects, &services, &logging, &monitoring, &scheduler, &tasks, + &workflows, &executions, &eventarc, &billing, &assets, &policies}; + } + // Throws GoogleError::invalid for an unknown name. + const OpsProduct& product(const std::string& name) const { + for (const OpsProduct* p : all()) + if (name == p->product().name) return *p; + throw GoogleError::invalid("unknown ops product: " + name); + } +}; + +} // namespace molo::google::ops diff --git a/src/google/ops/ops_client.cpp b/src/google/ops/ops_client.cpp new file mode 100644 index 0000000..2b1998a --- /dev/null +++ b/src/google/ops/ops_client.cpp @@ -0,0 +1,100 @@ +#include "google/ops/ops_client.h" + +#include "google/errors.h" +#include "google/ops/caps.h" + +namespace molo::google::ops { + +using clients::body::Json; + +Json Outcome::to_json() const { + Json o = Json::object(); + o.set("executed", Json(executed)); + o.set("plan", plan.to_json()); + if (executed) o.set("response", response); + else o.set("hint", Json("dry run: nothing was sent; pass confirm:true to execute")); + return o; +} + +OpsClient::OpsClient(std::shared_ptr client, Sleeper sleeper) + : client_(std::move(client)), sleeper_(std::move(sleeper)) {} + +CallPlan OpsClient::plan(const std::string& rpc, const Args& args) const { + return CallPlan::build(call_named(rpc), args); +} + +Json OpsClient::send(const CallPlan& plan) const { + const std::string name = plan.spec().product(); + const Product& product = product_named(name); + const Json* body = plan.has_body() ? &plan.body() : nullptr; + return client_->request(plan.method(), endpoint_of(product), plan.path(), body); +} + +Json OpsClient::read(const std::string& rpc, const Args& args) const { + const CallSpec& spec = call_named(rpc); + if (spec.safe() != Safety::kRead) throw GoogleError::invalid(rpc + " is not a read call"); + return send(CallPlan::build(spec, args)); +} + +Json OpsClient::list(const std::string& rpc, const Args& args, int max_pages) const { + const CallSpec& spec = call_named(rpc); + if (!spec.is_list() || spec.safe() != Safety::kRead) + throw GoogleError::invalid(rpc + " is not a list call"); + if (max_pages < 1 || max_pages > OpsCaps::kMaxListPages) + throw GoogleError::invalid("max_pages must be 1.." + std::to_string(OpsCaps::kMaxListPages)); + bool by_body = spec.method() == clients::Method::kPost; + const char* size_name = by_body ? (spec.has_body_field("pageSize") ? "pageSize" : nullptr) + : spec.has_query("pageSize") ? "pageSize" + : spec.has_query("maxResults") ? "maxResults" + : nullptr; + Json items = Json::array(); + std::string token; + for (int page = 0; page < max_pages; ++page) { + Args a = args; + if (size_name) { + bool given = by_body ? (a.body_arg().is_object() && a.body_arg().find(size_name)) + : a.query_args().find(size_name) != nullptr; + if (!given) { + if (by_body) a.field(size_name, Json(OpsCaps::kDefaultPageSize)); + else a.query(size_name, Json(OpsCaps::kDefaultPageSize)); + } + } + if (!token.empty()) { + if (by_body) a.field("pageToken", Json(token)); + else a.query("pageToken", Json(token)); + } + Json reply = send(CallPlan::build(spec, a)); + if (const Json* arr = reply.find(spec.items_key); arr && arr->is_array()) + for (const Json& item : arr->as_array()) { + if (items.as_array().size() >= OpsCaps::kMaxListItems) return items; + items.push(item); + } + const Json* next = reply.find("nextPageToken"); + if (!next || !next->is_string() || next->as_string().empty()) break; + token = next->as_string(); + } + return items; +} + +Outcome OpsClient::execute(const std::string& rpc, const Args& args, bool confirm) const { + const CallSpec& spec = call_named(rpc); + Outcome out; + out.plan = CallPlan::build(spec, args); + if (spec.safe() == Safety::kRead || confirm) { + out.response = send(out.plan); + out.executed = true; + } + return out; +} + +Operation OpsClient::wait(const std::string& product, const std::string& name) const { + const Product& p = product_named(product); + if (name.empty() || name.size() > OpsCaps::kMaxOperationNameChars || + name.find("..") != std::string::npos || name.find('?') != std::string::npos || + (name.rfind("projects/", 0) != 0 && name.rfind("organizations/", 0) != 0)) + throw GoogleError::invalid("bad operation name"); + if (!client_->configured()) throw NotConfiguredError(product); + return wait_operation(*client_, operation_endpoint_of(p), name, sleeper_); +} + +} // namespace molo::google::ops diff --git a/src/google/ops/ops_client.h b/src/google/ops/ops_client.h new file mode 100644 index 0000000..02319b9 --- /dev/null +++ b/src/google/ops/ops_client.h @@ -0,0 +1,58 @@ +#pragma once + +// OpsClient runs table calls: plan (validate), send, page walk, wait. Writes +// and destructive calls are dry runs unless `confirm` is true, so nothing +// changes in a cloud project by accident. + +#include +#include + +#include "google/client.h" +#include "google/operation.h" +#include "google/ops/call_plan.h" +#include "google/ops/caps.h" + +namespace molo::google::ops { + +struct Outcome { + bool executed = false; // false: dry run, nothing was sent + CallPlan plan; + clients::body::Json response; // set when executed + // {"executed":bool,"plan":{...},"response":{...}} ; dry runs add "hint". + clients::body::Json to_json() const; + // The reply as a long-running operation (when the row is "lro"). + Operation operation() const { return Operation::from_json(response); } +}; + +class OpsClient { + public: + explicit OpsClient(std::shared_ptr client, Sleeper sleeper = nullptr); + + bool configured() const { return client_->configured(); } + const std::shared_ptr& google() const { return client_; } + + CallPlan plan(const std::string& rpc, const Args& args) const; + + // Safety::kRead rows only (others throw invalid): validate, then send. + clients::body::Json read(const std::string& rpc, const Args& args) const; + // A list row: walks pages (nextPageToken) up to max_pages and kMaxListItems, + // returns the items array. + clients::body::Json list(const std::string& rpc, const Args& args, + int max_pages = OpsCaps::kMaxListPages) const; + // Any row. Reads always run. Writes and destructive rows only run when + // `confirm` is true; no default on purpose. + Outcome execute(const std::string& rpc, const Args& args, bool confirm) const; + + // Polls a google.longrunning operation of `product` until done (capped by + // google::OperationCaps). The name must start with projects/ or + // organizations/ and carry no "..". + Operation wait(const std::string& product, const std::string& operation_name) const; + + private: + clients::body::Json send(const CallPlan& plan) const; + + std::shared_ptr client_; + Sleeper sleeper_; +}; + +} // namespace molo::google::ops diff --git a/src/google/ops/ops_product.cpp b/src/google/ops/ops_product.cpp new file mode 100644 index 0000000..80909f9 --- /dev/null +++ b/src/google/ops/ops_product.cpp @@ -0,0 +1,69 @@ +#include "google/ops/ops_product.h" + +#include "google/errors.h" + +namespace molo::google::ops { + +using clients::body::Json; + +std::string Names::project(const std::string& p) { + if (!valid_name_segment(p)) throw GoogleError::invalid("bad project id"); + return "projects/" + p; +} + +std::string Names::location(const std::string& p, const std::string& l) { + if (!valid_name_segment(l)) throw GoogleError::invalid("bad location"); + return project(p) + "/locations/" + l; +} + +std::string Names::child(const std::string& parent, const std::string& collection, + const std::string& id) { + check_resource_name("parent", parent, ""); + if (!valid_name_segment(collection) || !valid_name_segment(id)) + throw GoogleError::invalid("bad resource id"); + return parent + "/" + collection + "/" + id; +} + +OpsProduct::OpsProduct(std::shared_ptr client, const std::string& product, + Sleeper sleeper) + : Service(client, endpoint_of(product_named(product))), + product_(product_named(product)), + ops_(std::move(client), std::move(sleeper)) {} + +std::vector OpsProduct::rpcs() const { + std::vector out; + for (std::size_t i = 0; i < call_count(); ++i) + if (call_table()[i].product() == product_.name) out.push_back(call_table()[i].rpc); + return out; +} + +void OpsProduct::own(const std::string& rpc) const { + if (call_named(rpc).product() != product_.name) + throw GoogleError::invalid(rpc + " does not belong to " + product_.name); +} + +Json OpsProduct::read(const std::string& rpc, const Args& args) const { + own(rpc); + return ops_.read(rpc, args); +} + +Json OpsProduct::list(const std::string& rpc, const Args& args, int max_pages) const { + own(rpc); + return ops_.list(rpc, args, max_pages); +} + +Outcome OpsProduct::call(const std::string& rpc, const Args& args, bool confirm) const { + own(rpc); + return ops_.execute(rpc, args, confirm); +} + +CallPlan OpsProduct::plan(const std::string& rpc, const Args& args) const { + own(rpc); + return ops_.plan(rpc, args); +} + +Operation OpsProduct::wait(const std::string& name) const { + return ops_.wait(product_.name, name); +} + +} // namespace molo::google::ops diff --git a/src/google/ops/ops_product.h b/src/google/ops/ops_product.h new file mode 100644 index 0000000..9f99751 --- /dev/null +++ b/src/google/ops/ops_product.h @@ -0,0 +1,56 @@ +#pragma once + +// Base class of every ops product (Compute, Cloud Run, ...). A product is a +// Service bound to one Discovery API; its typed methods are thin wrappers over +// table rows. The generic read / list / call are limited to the rows of the +// product, so any table row is reachable even without a typed method. + +#include +#include +#include + +#include "google/ops/ops_client.h" +#include "google/resource.h" +#include "google/service.h" + +namespace molo::google::ops { + +// Resource name helpers (validated, never raw string concatenation by callers). +struct Names { + static std::string project(const std::string& project); // projects/p + static std::string location(const std::string& project, const std::string& l); // projects/p/locations/l + static std::string child(const std::string& parent, const std::string& collection, + const std::string& id); +}; + +class OpsProduct : public Service { + public: + OpsProduct(std::shared_ptr client, const std::string& product, + Sleeper sleeper = nullptr); + + const Product& product() const { return product_; } + // Rpc ids of this product's rows. + std::vector rpcs() const; + + clients::body::Json read(const std::string& rpc, const Args& args) const; + clients::body::Json list(const std::string& rpc, const Args& args, + int max_pages = OpsCaps::kMaxListPages) const; + // Reads run; writes and destructive rows are dry runs unless confirm is true. + Outcome call(const std::string& rpc, const Args& args, bool confirm) const; + CallPlan plan(const std::string& rpc, const Args& args) const; + // Polls a long-running operation of this product. + Operation wait(const std::string& operation_name) const; + + protected: + void own(const std::string& rpc) const; + static Args at(const char* name, const std::string& value) { + Args a; + a.path(name, value); + return a; + } + + Product product_; + OpsClient ops_; +}; + +} // namespace molo::google::ops diff --git a/src/google/ops/org_policy.h b/src/google/ops/org_policy.h new file mode 100644 index 0000000..ba0a2c8 --- /dev/null +++ b/src/google/ops/org_policy.h @@ -0,0 +1,44 @@ +#pragma once + +// Organization Policy v2. `parent` is projects/{p}, folders/{f} or +// organizations/{o}; the typed methods cover the project scope, the generic +// call() reaches folders and organizations. + +#include "google/ops/ops_product.h" + +namespace molo::google::ops { + +class OrgPolicy : public OpsProduct { + public: + using Json = clients::body::Json; + explicit OrgPolicy(std::shared_ptr c, Sleeper s = nullptr) + : OpsProduct(std::move(c), "orgpolicy", std::move(s)) {} + + Json constraints(const std::string& project_name) const { + return list("orgpolicy.projects.constraints.list", at("parent", project_name)); + } + Json policies(const std::string& project_name) const { + return list("orgpolicy.projects.policies.list", at("parent", project_name)); + } + Json policy(const std::string& name) const { + return read("orgpolicy.projects.policies.get", at("name", name)); + } + Json effective_policy(const std::string& name) const { + return read("orgpolicy.projects.policies.getEffectivePolicy", at("name", name)); + } + Json custom_constraints(const std::string& organization_name) const { + return list("orgpolicy.organizations.customConstraints.list", at("parent", organization_name)); + } + + // policy: {"name":".../policies/{constraint}","spec":{...}} + Outcome create_policy(const std::string& project_name, const Json& policy, + bool confirm = false) const { + return call("orgpolicy.projects.policies.create", at("parent", project_name).body(policy), + confirm); + } + Outcome delete_policy(const std::string& name, bool confirm) const { + return call("orgpolicy.projects.policies.delete", at("name", name), confirm); + } +}; + +} // namespace molo::google::ops diff --git a/src/google/ops/resource_manager.h b/src/google/ops/resource_manager.h new file mode 100644 index 0000000..b5ba04f --- /dev/null +++ b/src/google/ops/resource_manager.h @@ -0,0 +1,86 @@ +#pragma once + +// Cloud Resource Manager v3: projects, folders, organizations, liens, tags, +// IAM policies of those resources. Names are projects/{id or number}, +// folders/{n}, organizations/{n}. + +#include + +#include "google/ops/ops_product.h" + +namespace molo::google::ops { + +class ResourceManager : public OpsProduct { + public: + using Json = clients::body::Json; + explicit ResourceManager(std::shared_ptr c, Sleeper s = nullptr) + : OpsProduct(std::move(c), "cloudresourcemanager", std::move(s)) {} + + Json project(const std::string& name) const { + return read("cloudresourcemanager.projects.get", at("name", name)); + } + // query: Google's search syntax, e.g. "displayName:prod*" ("" lists all visible). + Json search_projects(const std::string& query = "") const { + return list("cloudresourcemanager.projects.search", with_query(query)); + } + // Children of a folder or organization (parent = folders/n or organizations/n). + Json projects_under(const std::string& parent) const { + return list("cloudresourcemanager.projects.list", Args().query("parent", Json(parent))); + } + Json folders_under(const std::string& parent) const { + return list("cloudresourcemanager.folders.list", Args().query("parent", Json(parent))); + } + Json search_folders(const std::string& query = "") const { + return list("cloudresourcemanager.folders.search", with_query(query)); + } + Json folder(const std::string& name) const { + return read("cloudresourcemanager.folders.get", at("name", name)); + } + Json search_organizations(const std::string& query = "") const { + return list("cloudresourcemanager.organizations.search", with_query(query)); + } + Json organization(const std::string& name) const { + return read("cloudresourcemanager.organizations.get", at("name", name)); + } + Json project_policy(const std::string& project_name) const { + return read("cloudresourcemanager.projects.getIamPolicy", at("resource", project_name)); + } + // The subset of `permissions` the caller holds on the project. + Json test_project_permissions(const std::string& project_name, + const std::vector& permissions) const { + Json arr = Json::array(); + for (const std::string& p : permissions) arr.push(Json(p)); + Args a = at("resource", project_name); + a.field("permissions", arr); + return read("cloudresourcemanager.projects.testIamPermissions", a); + } + Json liens(const std::string& parent) const { + return list("cloudresourcemanager.liens.list", Args().query("parent", Json(parent))); + } + Json operation(const std::string& name) const { + return read("cloudresourcemanager.operations.get", at("name", name)); + } + + Outcome create_project(const std::string& project_id, const std::string& display_name, + const std::string& parent, bool confirm = false) const { + Args a; + a.field("projectId", Json(project_id)).field("displayName", Json(display_name)); + if (!parent.empty()) a.field("parent", Json(parent)); + return call("cloudresourcemanager.projects.create", a, confirm); + } + Outcome delete_project(const std::string& name, bool confirm) const { + return call("cloudresourcemanager.projects.delete", at("name", name), confirm); + } + Outcome undelete_project(const std::string& name, bool confirm = false) const { + return call("cloudresourcemanager.projects.undelete", at("name", name), confirm); + } + + private: + static Args with_query(const std::string& query) { + Args a; + if (!query.empty()) a.query("query", Json(query)); + return a; + } +}; + +} // namespace molo::google::ops diff --git a/src/google/ops/service_usage.cpp b/src/google/ops/service_usage.cpp new file mode 100644 index 0000000..5242982 --- /dev/null +++ b/src/google/ops/service_usage.cpp @@ -0,0 +1,81 @@ +#include "google/ops/service_usage.h" + +#include "google/errors.h" +#include "google/ops/caps.h" + +namespace molo::google::ops { + +using clients::body::Json; + +namespace { +std::string str(const Json& doc, const char* key) { + const Json* v = doc.find(key); + return v && v->is_string() ? v->as_string() : std::string(); +} +} // namespace + +ServiceState ServiceState::from_json(const Json& doc) { + ServiceState s; + if (!doc.is_object()) return s; + s.name = str(doc, "name"); + s.state = str(doc, "state"); + if (const Json* cfg = doc.find("config"); cfg && cfg->is_object()) { + s.api = str(*cfg, "name"); + s.title = str(*cfg, "title"); + } + return s; +} + +std::string ServiceUsage::service_name(const std::string& project, const std::string& api) { + if (!valid_name_segment(project) || !valid_name_segment(api)) + throw GoogleError::invalid("bad project or service name"); + return "projects/" + project + "/services/" + api; +} + +Json ServiceUsage::list_services(const std::string& parent, const std::string& filter) const { + Args a = at("parent", parent); + if (!filter.empty()) { + if (filter.size() > 128) throw GoogleError::invalid("filter too long"); + a.query("filter", Json(filter)); + } + return list("serviceusage.services.list", a); +} + +std::vector ServiceUsage::enabled_services(const std::string& parent) const { + std::vector out; + Json items = list_services(parent, "state:ENABLED"); + for (const Json& item : items.as_array()) out.push_back(ServiceState::from_json(item)); + return out; +} + +Json ServiceUsage::batch_get(const std::string& parent, + const std::vector& names) const { + if (names.empty() || names.size() > OpsCaps::kMaxBatchNames) + throw GoogleError::invalid("names must hold 1.." + std::to_string(OpsCaps::kMaxBatchNames)); + Json arr = Json::array(); + for (const std::string& n : names) arr.push(Json(n)); + return read("serviceusage.services.batchGet", at("parent", parent).query("names", arr)); +} + +Outcome ServiceUsage::disable(const std::string& name, bool disable_dependents, + bool confirm) const { + Args a = at("name", name); + if (disable_dependents) a.field("disableDependentServices", Json(true)); + return call("serviceusage.services.disable", a, confirm); +} + +Outcome ServiceUsage::batch_enable(const std::string& parent, + const std::vector& api_ids, bool confirm) const { + if (api_ids.empty() || api_ids.size() > OpsCaps::kMaxBatchNames) + throw GoogleError::invalid("serviceIds must hold 1.." + std::to_string(OpsCaps::kMaxBatchNames)); + Json arr = Json::array(); + for (const std::string& id : api_ids) { + if (!valid_name_segment(id)) throw GoogleError::invalid("bad service id"); + arr.push(Json(id)); + } + Args a = at("parent", parent); + a.field("serviceIds", arr); + return call("serviceusage.services.batchEnable", a, confirm); +} + +} // namespace molo::google::ops diff --git a/src/google/ops/service_usage.h b/src/google/ops/service_usage.h new file mode 100644 index 0000000..92cc0d2 --- /dev/null +++ b/src/google/ops/service_usage.h @@ -0,0 +1,55 @@ +#pragma once + +// Service Usage v1: which APIs a project has enabled. Reads run directly. +// enable, disable and batch_enable are explicit methods that are DRY RUNS +// unless confirm is true: enabling an API is a human decision (cost, quota, +// attack surface), so nothing here calls them on its own. + +#include +#include + +#include "google/ops/ops_product.h" + +namespace molo::google::ops { + +struct ServiceState { + std::string name; // projects/123/services/iam.googleapis.com + std::string api; // iam.googleapis.com + std::string state; // ENABLED, DISABLED, STATE_UNSPECIFIED + std::string title; + bool enabled() const { return state == "ENABLED"; } + static ServiceState from_json(const clients::body::Json& doc); +}; + +class ServiceUsage : public OpsProduct { + public: + using Json = clients::body::Json; + explicit ServiceUsage(std::shared_ptr c, Sleeper s = nullptr) + : OpsProduct(std::move(c), "serviceusage", std::move(s)) {} + + // "projects/{id or number}/services/{api}"; api like iam.googleapis.com. + static std::string service_name(const std::string& project, const std::string& api); + + // filter: "state:ENABLED" or "state:DISABLED" (Google's syntax) or "". + Json list_services(const std::string& parent, const std::string& filter = "") const; + std::vector enabled_services(const std::string& parent) const; + Json service(const std::string& name) const { + return read("serviceusage.services.get", at("name", name)); + } + ServiceState state(const std::string& name) const { return ServiceState::from_json(service(name)); } + // Up to OpsCaps::kMaxBatchNames names (full service names) in one call. + Json batch_get(const std::string& parent, const std::vector& names) const; + Json operation(const std::string& name) const { + return read("serviceusage.operations.get", at("name", name)); + } + + Outcome enable(const std::string& name, bool confirm = false) const { + return call("serviceusage.services.enable", at("name", name), confirm); + } + Outcome disable(const std::string& name, bool disable_dependents = false, + bool confirm = false) const; + Outcome batch_enable(const std::string& parent, const std::vector& api_ids, + bool confirm = false) const; +}; + +} // namespace molo::google::ops diff --git a/src/google/ops/tools/check_discovery.py b/src/google/ops/tools/check_discovery.py new file mode 100644 index 0000000..4323a6e --- /dev/null +++ b/src/google/ops/tools/check_discovery.py @@ -0,0 +1,154 @@ +#!/usr/bin/env python3 +"""Check src/google/ops/calls.cpp against Google's Discovery documents. + +Fails (exit 1) when a declared product differs from its Discovery document +(version, root URL, service path) or when a declared call is absent, or its +HTTP method, path, safety class, list item key, long-running kind, request +body fields, query parameters or path shapes differ from what Discovery says. +It also requires the safety class to be consistent (GET is read, DELETE is +destructive) and every declared body field to exist in the request schema. +Python 3 stdlib only, no credentials needed. + + python3 -I src/google/ops/tools/check_discovery.py +""" +import json +import os +import re +import sys +import urllib.request + +HERE = os.path.dirname(os.path.abspath(__file__)) +CALLS = os.path.join(HERE, "..", "calls.cpp") +URL = "https://%s.googleapis.com/$discovery/rest?version=%s" +ROW = re.compile(r'^\s*\{(.*)\},?\s*$') +STR = re.compile(r'"([^"]*)"') +READ_POSTS = {"queryGrantableRoles", "queryTestablePermissions", "testIamPermissions", + "getIamPolicy", "signBlob", "signJwt", "generateAccessToken", "generateIdToken", + "queryAssets", "listRevisions", "wait"} + + +def block(text, begin, end): + a = text.index(begin) + b = text.index(end) + rows = [] + for line in text[a:b].splitlines()[1:]: + m = ROW.match(line) + if m and '"' in line: + rows.append(STR.findall(m.group(1))) + return rows + + +def walk(node, out): + for m in node.get("methods", {}).values(): + out[m["id"]] = m + for c in node.get("resources", {}).values(): + walk(c, out) + + +def shape_of(pattern): + if not pattern or not pattern.startswith("^") or not pattern.endswith("$"): + return "" + out = [] + for p in pattern[1:-1].replace("[^/]+", "\x00").split("/"): + if p == "\x00": + out.append("*") + elif re.fullmatch(r"[A-Za-z0-9_.-]+", p): + out.append(p) + else: + return "" + return "/".join(out) + + +def main(): + text = open(CALLS).read() + products = block(text, "// PRODUCTS-BEGIN", "// PRODUCTS-END") + calls = block(text, "// CALLS-BEGIN", "// CALLS-END") + bad = [] + docs, index = {}, {} + for name, version, root, service_path, revision in products: + with urllib.request.urlopen(URL % (name, version), timeout=60) as r: + doc = json.load(r) + docs[name] = doc + index[name] = {} + walk(doc, index[name]) + if doc["version"] != version: + bad.append("%s: version %s != %s" % (name, version, doc["version"])) + if doc["rootUrl"].rstrip("/") != root: + bad.append("%s: root %s != %s" % (name, root, doc["rootUrl"])) + if doc["servicePath"].rstrip("/") != service_path: + bad.append("%s: servicePath %s != %s" % (name, service_path, doc["servicePath"])) + if doc["revision"] != revision: + print("note: %s revision %s (table generated from %s)" % (name, doc["revision"], revision)) + seen = set() + for rpc, http, path, safety, kind, items, body, query, shapes in calls: + if rpc in seen: + bad.append("duplicate row " + rpc) + seen.add(rpc) + name = rpc.split(".", 1)[0] + if name not in docs: + bad.append("%s: product %s not declared" % (rpc, name)) + continue + doc = docs[name] + m = index[name].get(rpc) + if not m: + bad.append("missing rpc " + rpc) + continue + if m["httpMethod"] != http: + bad.append("%s: http %s != %s" % (rpc, http, m["httpMethod"])) + if m["path"] != path: + bad.append("%s: path %s != %s" % (rpc, path, m["path"])) + verb = rpc.rsplit(".", 1)[1] + if http == "GET" and safety != "R": + bad.append("%s: GET must be read" % rpc) + if http == "DELETE" and safety != "D": + bad.append("%s: DELETE must be destructive" % rpc) + if safety == "R" and http not in ("GET",) and verb not in READ_POSTS and rpc != "logging.entries.list": + bad.append("%s: %s row marked read without being a known read verb" % (rpc, http)) + if safety == "D" and not (http == "DELETE" or verb.startswith("delete") or verb in ("batchDelete", "purge")): + bad.append("%s: destructive without a delete verb" % rpc) + # query parameters + params = m.get("parameters", {}) + want_q = sorted(k for k, v in params.items() if v.get("location") == "query") + if sorted(filter(None, query.split(","))) != want_q: + bad.append("%s: query params differ: %s vs %s" % (rpc, query, ",".join(want_q))) + # request body fields (readOnly fields are never sent) + ref = m.get("request", {}).get("$ref") + props = doc["schemas"].get(ref, {}).get("properties", {}) if ref else {} + want_b = sorted(k for k, v in props.items() if not v.get("readOnly")) + if sorted(filter(None, body.split(","))) != want_b: + bad.append("%s: body fields differ: %s vs %s" % (rpc, body, ",".join(want_b))) + # path shapes + want_s = [] + for pn in re.findall(r"\{\+?([A-Za-z0-9]+)\}", path): + p = params.get(pn) + if p is None or p.get("location") != "path": + bad.append("%s: path param %s absent" % (rpc, pn)) + continue + sh = shape_of(p.get("pattern", "")) if ("{+" + pn + "}") in path else "" + want_s.append("%s=%s" % (pn, sh)) + if shapes.split() != want_s: + bad.append("%s: shapes differ: %s vs %s" % (rpc, shapes, " ".join(want_s))) + # list items key: must be an array property of the response + rref = m.get("response", {}).get("$ref") + rprops = doc["schemas"].get(rref, {}).get("properties", {}) if rref else {} + if items: + if rprops.get(items, {}).get("type") != "array": + bad.append("%s: items key %s is not an array of %s" % (rpc, items, rref)) + # long-running kind + want_kind = "" + if name == "compute": + want_kind = "compute" if rref == "Operation" else "" + elif "done" in rprops and "name" in rprops: + want_kind = "lro" + if kind != want_kind: + bad.append("%s: kind %r != %r" % (rpc, kind, want_kind)) + print("ops discovery: %d products, %d calls" % (len(products), len(calls))) + if bad: + print("\n".join(bad[:100])) + print("%d problems" % len(bad)) + sys.exit(1) + print("discovery ok") + + +if __name__ == "__main__": + main() diff --git a/src/google/ops/tools/gen_calls.py b/src/google/ops/tools/gen_calls.py new file mode 100644 index 0000000..d78cee1 --- /dev/null +++ b/src/google/ops/tools/gen_calls.py @@ -0,0 +1,360 @@ +#!/usr/bin/env python3 +"""Generate src/google/ops/calls.cpp from Google's Discovery documents. + +The SELECTION below names the calls the ops package wraps; every other column +(HTTP method, path, request fields, query parameters, path shapes, list item +key, long-running kind) is READ from Discovery, never typed by hand. After +generating, run tools/check_discovery.py, which re-reads the committed file +and fails on any drift. Python 3 stdlib only, no credentials. + + python3 -I src/google/ops/tools/gen_calls.py > src/google/ops/calls.cpp +""" +import json +import re +import sys +import urllib.request + +PRODUCTS = [ + ("compute", "v1"), ("run", "v2"), ("cloudfunctions", "v2"), ("container", "v1"), + ("cloudbuild", "v1"), ("artifactregistry", "v1"), ("iam", "v1"), + ("iamcredentials", "v1"), ("cloudresourcemanager", "v3"), ("serviceusage", "v1"), + ("logging", "v2"), ("monitoring", "v3"), ("cloudscheduler", "v1"), ("cloudtasks", "v2"), + ("workflows", "v1"), ("workflowexecutions", "v1"), ("eventarc", "v1"), + ("cloudbilling", "v1"), ("cloudasset", "v1"), ("orgpolicy", "v2"), +] + +IAM3 = "getIamPolicy setIamPolicy testIamPermissions" +CRUD = "list get create patch delete" + +# product -> list of (resource prefix, space separated verbs). Ids are +# "..". +SELECTION = { + "compute": [ + ("instances", "list get insert delete start stop reset"), + ("zones", "list get"), ("regions", "list get"), ("machineTypes", "list get"), + ("disks", "list get"), ("networks", "list get"), ("subnetworks", "list get"), + ("firewalls", "list get"), ("images", "list get"), ("addresses", "list"), + ("instanceTemplates", "list get"), ("instanceGroups", "list"), + ("snapshots", "list get"), ("backendServices", "list"), + ("forwardingRules", "list"), ("projects", "get"), + ("zoneOperations", "list get wait"), ("globalOperations", "list get"), + ("regionOperations", "list get"), + ], + "run": [ + ("projects.locations.services", CRUD + " " + IAM3), + ("projects.locations.services.revisions", "list get delete"), + ("projects.locations.jobs", CRUD + " run " + IAM3), + ("projects.locations.jobs.executions", "list get cancel delete"), + ("projects.locations.jobs.executions.tasks", "list get"), + ("projects.locations.operations", "list get wait"), + ], + "cloudfunctions": [ + ("projects.locations.functions", CRUD + " generateUploadUrl generateDownloadUrl " + IAM3), + ("projects.locations", "list"), + ("projects.locations.runtimes", "list"), + ("projects.locations.operations", "list get"), + ], + "container": [ + ("projects.locations", "getServerConfig"), + ("projects.locations.clusters", "list get create update delete fetchClusterUpgradeInfo " + "checkAutopilotCompatibility getJwks"), + ("projects.locations.clusters.nodePools", "list get create update delete setSize rollback"), + ("projects.locations.operations", "list get cancel"), + ("projects.aggregated.usableSubnetworks", "list"), + ], + "cloudbuild": [ + ("projects.locations.builds", "list get create cancel retry approve"), + ("projects.builds", "list get create cancel retry"), + ("projects.locations.triggers", CRUD + " run"), + ("projects.locations.workerPools", CRUD), + ("projects.locations", "getDefaultServiceAccount"), + ("projects.locations.operations", "get cancel"), + ], + "artifactregistry": [ + ("projects.locations", "list get getProjectConfig"), + ("projects", "getProjectSettings"), + ("projects.locations.repositories", CRUD + " " + IAM3), + ("projects.locations.repositories.packages", "list get delete"), + ("projects.locations.repositories.packages.versions", "list get delete batchDelete"), + ("projects.locations.repositories.packages.tags", CRUD), + ("projects.locations.repositories.files", "list get delete"), + ("projects.locations.repositories.dockerImages", "list get"), + ("projects.locations.repositories.mavenArtifacts", "list get"), + ("projects.locations.repositories.npmPackages", "list get"), + ("projects.locations.repositories.pythonPackages", "list get"), + ("projects.locations.repositories.rules", CRUD), + ("projects.locations.repositories.attachments", "list get"), + ("projects.locations.operations", "get"), + ], + "iam": [ + ("roles", "list get queryGrantableRoles"), + ("permissions", "queryTestablePermissions"), + ("projects.roles", "list get create patch delete undelete"), + ("organizations.roles", "list get"), + ("projects.serviceAccounts", "list get create patch update delete undelete enable disable " + "signBlob signJwt " + IAM3), + ("projects.serviceAccounts.keys", "list get create upload delete enable disable"), + ], + "iamcredentials": [ + ("projects.serviceAccounts", "signJwt signBlob generateAccessToken generateIdToken"), + ], + "cloudresourcemanager": [ + ("projects", "get list search create patch delete undelete move " + IAM3), + ("folders", "get list search create patch delete undelete move " + IAM3), + ("organizations", "get search " + IAM3), + ("operations", "get"), + ("liens", "list get create delete"), + ("tagKeys", "list get"), ("tagValues", "list get"), ("tagBindings", "list"), + ], + "serviceusage": [ + ("services", "list get batchGet enable disable batchEnable"), + ("operations", "get list"), + ], + "logging": [ + ("entries", "list write"), + ("projects.logs", "list delete"), + ("monitoredResourceDescriptors", "list"), + ("projects.sinks", "list get create patch delete"), + ("projects.metrics", "list get create update delete"), + ("projects.exclusions", "list get"), + ("projects.locations.buckets", "list get"), + ("projects.getSettings", ""), + ("projects.locations.operations", "get"), + ], + "monitoring": [ + ("projects.timeSeries", "list create"), + ("projects.metricDescriptors", "list get"), + ("projects.monitoredResourceDescriptors", "list get"), + ("projects.alertPolicies", "list get create patch delete"), + ("projects.notificationChannels", "list get"), + ("projects.notificationChannelDescriptors", "list get"), + ("projects.groups", "list get"), + ("projects.uptimeCheckConfigs", "list get"), + ("projects.snoozes", "list get"), + ("projects.alerts", "list get"), + ("services", "list get"), + ("services.serviceLevelObjectives", "list get"), + ], + "cloudscheduler": [ + ("projects.locations", "list get"), + ("projects.locations.jobs", CRUD + " run pause resume"), + ("projects.locations.operations", "get"), + ], + "cloudtasks": [ + ("projects.locations", "list get"), + ("projects.locations.queues", CRUD + " pause resume purge " + IAM3), + ("projects.locations.queues.tasks", "list get create delete run"), + ("projects.locations.operations", "get"), + ], + "workflows": [ + ("projects.locations", "list get"), + ("projects.locations.workflows", "list get create patch delete listRevisions"), + ("projects.locations.operations", "get list"), + ], + "workflowexecutions": [ + ("projects.locations.workflows.executions", "list get create cancel"), + ("projects.locations.workflows.executions.stepEntries", "list get"), + ], + "eventarc": [ + ("projects.locations", "list get"), + ("projects.locations.triggers", CRUD + " " + IAM3), + ("projects.locations.channels", CRUD), + ("projects.locations.providers", "list get"), + ("projects.locations.pipelines", "list get"), + ("projects.locations.messageBuses", "list get"), + ("projects.locations.enrollments", "list get"), + ("projects.locations.operations", "get list"), + ], + "cloudbilling": [ + ("billingAccounts", "list get getIamPolicy testIamPermissions"), + ("billingAccounts.projects", "list"), + ("projects", "getBillingInfo updateBillingInfo"), + ("services", "list"), + ("services.skus", "list"), + ], + "cloudasset": [ + ("assets", "list"), + ("", "searchAllResources searchAllIamPolicies batchGetAssetsHistory analyzeIamPolicy " + "analyzeMove exportAssets queryAssets analyzeOrgPolicies"), + ("feeds", "list get"), ("savedQueries", "list get"), + ("operations", "get"), + ("effectiveIamPolicies", "batchGet"), + ], + "orgpolicy": [ + ("projects.constraints", "list"), + ("folders.constraints", "list"), + ("organizations.constraints", "list"), + ("projects.policies", CRUD + " getEffectivePolicy"), + ("folders.policies", CRUD + " getEffectivePolicy"), + ("organizations.policies", CRUD + " getEffectivePolicy"), + ("organizations.customConstraints", "list get"), + ], +} + +# POST / PATCH rows that only read, or only sign: no state changes. +READ_VERBS = {"queryGrantableRoles", "queryTestablePermissions", "testIamPermissions", + "getIamPolicy", "signBlob", "signJwt", "generateAccessToken", "generateIdToken", + "queryAssets", "listRevisions", "wait"} +READ_IDS = {"logging.entries.list"} + +# Response array key when Discovery's list response is ambiguous. +ITEMS_OVERRIDE = { + "logging.entries.list": "entries", + "iam.roles.queryGrantableRoles": "roles", + "iam.permissions.queryTestablePermissions": "permissions", + "cloudasset.searchAllResources": "results", + "cloudasset.searchAllIamPolicies": "results", + "cloudasset.assets.list": "assets", + "cloudasset.batchGetAssetsHistory": "assets", + "cloudasset.analyzeOrgPolicies": "orgPolicyResults", + "cloudbilling.services.skus.list": "skus", + "cloudbilling.billingAccounts.projects.list": "projectBillingInfo", +} + + +def fetch(name, version): + url = "https://%s.googleapis.com/$discovery/rest?version=%s" % (name, version) + with urllib.request.urlopen(url, timeout=60) as r: + return json.load(r) + + +def walk(node, out): + for m in node.get("methods", {}).values(): + out[m["id"]] = m + for c in node.get("resources", {}).values(): + walk(c, out) + + +def shape_of(pattern): + """'^projects/[^/]+/locations/[^/]+$' -> 'projects/*/locations/*', else ''.""" + if not pattern or not pattern.startswith("^") or not pattern.endswith("$"): + return "" + parts = pattern[1:-1].replace("[^/]+", "\x00").split("/") + out = [] + for p in parts: + if p == "\x00": + out.append("*") + elif re.fullmatch(r"[A-Za-z0-9_.-]+", p): + out.append(p) + else: + return "" + return "/".join(out) + + +def request_fields(doc, m): + ref = m.get("request", {}).get("$ref") + if not ref: + return [] + props = doc["schemas"].get(ref, {}).get("properties", {}) + return [k for k, v in props.items() if not v.get("readOnly")] + + +def items_key(doc, rid, m): + if rid in ITEMS_OVERRIDE: + return ITEMS_OVERRIDE[rid] + verb = rid.rsplit(".", 1)[1] + if not (verb.startswith("list") or verb.startswith("search")): + return "" + ref = m.get("response", {}).get("$ref") + props = doc["schemas"].get(ref, {}).get("properties", {}) + arrays = [k for k, v in props.items() if v.get("type") == "array" and k not in ("unreachable",)] + if len(arrays) == 1: + return arrays[0] + tokens = rid.split(".") + for k in arrays: + if k.lower() == tokens[-2].lower() or k.lower().startswith(tokens[-2].lower()[:5]): + return k + raise SystemExit("ambiguous list key for %s: %s (add to ITEMS_OVERRIDE)" % (rid, arrays)) + + +def kind_of(doc, m): + ref = m.get("response", {}).get("$ref", "") + props = doc["schemas"].get(ref, {}).get("properties", {}) + if doc["name"] == "compute": + return "compute" if ref == "Operation" else "" + if "done" in props and "name" in props: + return "lro" + return "" + + +def main(): + docs, rows, missing = {}, [], [] + out = [] + out.append("// GENERATED by tools/gen_calls.py from Google's Discovery documents; do not edit.") + out.append("// tools/check_discovery.py re-reads this file and fails on any drift.") + out.append('#include "google/ops/calls.h"') + out.append("") + out.append("namespace molo::google::ops {") + out.append("") + out.append("// PRODUCTS-BEGIN (name, version, root url, service path, discovery revision)") + prods = [] + for name, version in PRODUCTS: + doc = fetch(name, version) + docs[name] = doc + idx = {} + walk(doc, idx) + doc["_idx"] = idx + prods.append(' {"%s", "%s", "%s", "%s", "%s"},' % ( + name, doc["version"], doc["rootUrl"].rstrip("/"), doc["servicePath"].rstrip("/"), + doc["revision"])) + out.extend(["static const Product kProducts[] = {"] + prods + ["};"]) + out.append("// PRODUCTS-END") + out.append("") + out.append("// CALLS-BEGIN (rpc, http, path, safety R/W/D, kind, items key, body fields, " + "query params, path shapes)") + out.append("static const CallSpec kCalls[] = {") + count = 0 + for name, _ in PRODUCTS: + doc = docs[name] + idx = doc["_idx"] + for prefix, verbs in SELECTION.get(name, []): + vs = verbs.split() if verbs else [""] + for v in vs: + rid = ".".join(x for x in (name, prefix, v) if x) + if prefix.endswith("getSettings"): + rid = name + "." + prefix + m = idx.get(rid) + if not m: + missing.append(rid) + continue + http = m["httpMethod"] + verb = rid.rsplit(".", 1)[1] + if http == "GET" or verb in READ_VERBS or rid in READ_IDS: + safety = "R" + elif http == "DELETE": + safety = "D" + else: + safety = "W" + # deletes by POST verb names + if verb.startswith("delete") or verb == "batchDelete" or verb == "purge": + safety = "D" + query = [k for k, v in m.get("parameters", {}).items() if v.get("location") == "query"] + shapes = [] + for pn in re.findall(r"\{\+?([A-Za-z0-9]+)\}", m["path"]): + p = m["parameters"][pn] + sh = shape_of(p.get("pattern", "")) if "{+" + pn + "}" in m["path"] else "" + shapes.append("%s=%s" % (pn, sh)) + body = request_fields(doc, m) + rows.append(' {"%s", "%s", "%s", "%s", "%s", "%s", "%s", "%s", "%s"},' % ( + rid, http, m["path"], safety, kind_of(doc, m), items_key(doc, rid, m), + ",".join(body), ",".join(query), " ".join(shapes))) + count += 1 + if missing: + sys.stderr.write("MISSING in Discovery:\n " + "\n ".join(missing) + "\n") + raise SystemExit(1) + out.extend(rows) + out.append("};") + out.append("// CALLS-END") + out.append("") + out.append("const Product* products() { return kProducts; }") + out.append("std::size_t product_count() { return sizeof(kProducts) / sizeof(kProducts[0]); }") + out.append("const CallSpec* call_table() { return kCalls; }") + out.append("std::size_t call_count() { return sizeof(kCalls) / sizeof(kCalls[0]); }") + out.append("") + out.append("} // namespace molo::google::ops") + sys.stdout.write("\n".join(out) + "\n") + sys.stderr.write("generated %d calls\n" % count) + + +if __name__ == "__main__": + main() diff --git a/src/google/ops/workflows.h b/src/google/ops/workflows.h new file mode 100644 index 0000000..3dba8c6 --- /dev/null +++ b/src/google/ops/workflows.h @@ -0,0 +1,73 @@ +#pragma once + +// Workflows v1 (definitions) and Workflow Executions v1 (runs). `parent` is +// projects/{p}/locations/{l}. + +#include "google/ops/ops_product.h" + +namespace molo::google::ops { + +class Workflows : public OpsProduct { + public: + using Json = clients::body::Json; + explicit Workflows(std::shared_ptr c, Sleeper s = nullptr) + : OpsProduct(std::move(c), "workflows", std::move(s)) {} + + Json workflows(const std::string& parent) const { + return list("workflows.projects.locations.workflows.list", at("parent", parent)); + } + Json workflow(const std::string& name) const { + return read("workflows.projects.locations.workflows.get", at("name", name)); + } + Json revisions(const std::string& name) const { + return list("workflows.projects.locations.workflows.listRevisions", at("name", name)); + } + Json operation(const std::string& name) const { + return read("workflows.projects.locations.operations.get", at("name", name)); + } + + Outcome create_workflow(const std::string& parent, const std::string& workflow_id, + const Json& workflow, bool confirm = false) const { + Args a = at("parent", parent); + a.query("workflowId", Json(workflow_id)).body(workflow); + return call("workflows.projects.locations.workflows.create", a, confirm); + } + Outcome delete_workflow(const std::string& name, bool confirm) const { + return call("workflows.projects.locations.workflows.delete", at("name", name), confirm); + } +}; + +class WorkflowExecutions : public OpsProduct { + public: + using Json = clients::body::Json; + explicit WorkflowExecutions(std::shared_ptr c, Sleeper s = nullptr) + : OpsProduct(std::move(c), "workflowexecutions", std::move(s)) {} + + // workflow_name: projects/{p}/locations/{l}/workflows/{w} + Json executions(const std::string& workflow_name) const { + return list("workflowexecutions.projects.locations.workflows.executions.list", + at("parent", workflow_name)); + } + Json execution(const std::string& name) const { + return read("workflowexecutions.projects.locations.workflows.executions.get", + at("name", name)); + } + Json step_entries(const std::string& execution_name) const { + return list("workflowexecutions.projects.locations.workflows.executions.stepEntries.list", + at("parent", execution_name)); + } + + // argument: the workflow input serialized as a JSON string ("" for none). + Outcome start(const std::string& workflow_name, const std::string& argument, + bool confirm = false) const { + Args a = at("parent", workflow_name); + if (!argument.empty()) a.field("argument", Json(argument)); + return call("workflowexecutions.projects.locations.workflows.executions.create", a, confirm); + } + Outcome cancel(const std::string& execution_name, bool confirm = false) const { + return call("workflowexecutions.projects.locations.workflows.executions.cancel", + at("name", execution_name), confirm); + } +}; + +} // namespace molo::google::ops diff --git a/tests/example/google/ops/call_test.cpp b/tests/example/google/ops/call_test.cpp new file mode 100644 index 0000000..2262561 --- /dev/null +++ b/tests/example/google/ops/call_test.cpp @@ -0,0 +1,51 @@ +// Route: POST /google/ops/call (422 first, dry run for changes, 503 for reads) +#include "support/GoogleRig.hpp" + +using namespace molo::example::test; + +int main() { + GoogleRig rig(false); + Fixture f(rig.client); + auto post = [&](const std::string& body) { + return f.client->post("/google/ops/call", body, "application/json"); + }; + // Reads need a credential. + auto read = post("{\"rpc\":\"run.projects.locations.services.get\",\"path\":{\"name\":" + "\"projects/p/locations/l/services/s\"}}"); + check(read.status == 503 && contains(read.body, "google_not_configured"), "read without credential is 503"); + auto list = post("{\"rpc\":\"serviceusage.services.list\",\"path\":{\"parent\":\"projects/p\"}}"); + check(list.status == 503, "list without credential is 503"); + // Writes and deletes are dry runs, even without a credential. + auto enable = post("{\"rpc\":\"serviceusage.services.enable\",\"path\":{\"name\":" + "\"projects/p/services/iam.googleapis.com\"}}"); + check(enable.status == 200 && contains(enable.body, "\"executed\":false") && + contains(enable.body, "iam.googleapis.com:enable"), + "enable is a dry run"); + auto del = post("{\"rpc\":\"iam.projects.serviceAccounts.delete\",\"path\":{\"name\":" + "\"projects/p/serviceAccounts/a@p.iam.gserviceaccount.com\"}}"); + check(del.status == 200 && contains(del.body, "\"safety\":\"destructive\"") && + contains(del.body, "\"executed\":false"), + "delete is a dry run"); + auto sure = post("{\"rpc\":\"iam.projects.serviceAccounts.delete\",\"confirm\":true,\"path\":{\"name\":" + "\"projects/p/serviceAccounts/a@p.iam.gserviceaccount.com\"}}"); + check(sure.status == 503, "confirmed delete without credential is 503"); + // Input is checked against the Discovery-derived table. + check(post("{}").status == 422, "missing rpc is 422"); + check(post("{\"rpc\":\"run.nope\"}").status == 422, "unknown rpc is 422"); + check(post("{\"rpc\":\"run.projects.locations.services.get\"}").status == 422, "missing path param is 422"); + check(post("{\"rpc\":\"run.projects.locations.services.get\",\"path\":{\"name\":\"projects/p/../x\"}}").status == 422, + "traversal is 422"); + check(post("{\"rpc\":\"serviceusage.services.list\",\"path\":{\"parent\":\"projects/p\"}," + "\"query\":{\"bogus\":1}}").status == 422, + "unknown query parameter is 422"); + check(post("{\"rpc\":\"serviceusage.services.batchEnable\",\"path\":{\"parent\":\"projects/p\"}," + "\"body\":{\"typo\":1}}").status == 422, + "unknown body field is 422"); + check(post("{\"rpc\":\"serviceusage.services.list\",\"confirm\":\"yes\"}").status == 422, "non-bool confirm is 422"); + check(post("[]").status == 422, "non-object body is 422"); + check(post("nope").status == 422, "bad json is 422"); + check(post(std::string(300 * 1024, ' ')).status == 413, "oversize body is 413"); + check(f.client->get("/google/ops/call").status == 405, "get is 405"); + check(rig.mock->send_count() == 0, "nothing reached Google"); + return finish("google/ops/call"); +} diff --git a/tests/example/google/ops/iam_test.cpp b/tests/example/google/ops/iam_test.cpp new file mode 100644 index 0000000..5bf57e5 --- /dev/null +++ b/tests/example/google/ops/iam_test.cpp @@ -0,0 +1,47 @@ +// Routes: POST /google/ops/iam, /google/ops/projects, /google/ops/logs +#include "support/GoogleRig.hpp" + +using namespace molo::example::test; + +int main() { + setenv("GOOGLE_CLOUD_PROJECT", "test-project", 1); + GoogleRig rig(false); + Fixture f(rig.client); + auto iam = [&](const std::string& body) { return f.client->post("/google/ops/iam", body, "application/json"); }; + auto proj = [&](const std::string& body) { return f.client->post("/google/ops/projects", body, "application/json"); }; + auto logs = [&](const std::string& body) { return f.client->post("/google/ops/logs", body, "application/json"); }; + + check(iam("{\"action\":\"service_accounts\"}").status == 503, "service accounts without credential is 503"); + check(iam("{\"action\":\"roles\"}").status == 503, "roles without credential is 503"); + check(iam("{\"action\":\"test_permissions\",\"account\":\"a@p.iam.gserviceaccount.com\"," + "\"permissions\":[\"iam.serviceAccounts.get\"]}").status == 503, + "test permissions without credential is 503"); + check(iam("{\"action\":\"test_permissions\",\"account\":\"a@p.iam.gserviceaccount.com\"}").status == 422, + "missing permissions is 422"); + check(iam("{\"action\":\"test_permissions\",\"account\":\"a/b\",\"permissions\":[\"x\"]}").status == 422, + "bad account is 422"); + check(iam("{\"action\":\"sign_jwt\",\"account\":\"a@p.iam.gserviceaccount.com\"," + "\"payload\":\"{\\\"sub\\\":\\\"x\\\"}\"}").status == 503, + "sign_jwt without credential is 503"); + check(iam("{\"action\":\"sign_blob\",\"account\":\"a@p.iam.gserviceaccount.com\"}").status == 422, + "sign_blob without payload is 422"); + check(iam("{\"action\":\"nope\"}").status == 422, "unknown iam action is 422"); + + check(proj("{\"action\":\"get\"}").status == 503, "project get without credential is 503"); + check(proj("{\"action\":\"search\",\"query\":\"displayName:prod*\"}").status == 503, "search is 503"); + check(proj("{\"action\":\"search\",\"query\":\"" + std::string(300, 'x') + "\"}").status == 422, "long query is 422"); + check(proj("{\"action\":\"get\",\"project\":\"../x\"}").status == 422, "bad project is 422"); + check(proj("{\"action\":\"nope\"}").status == 422, "unknown project action is 422"); + + check(logs("{\"filter\":\"severity>=ERROR\"}").status == 503, "logs without credential is 503"); + check(logs("{\"limit\":0}").status == 422, "limit 0 is 422"); + check(logs("{\"limit\":101}").status == 422, "limit over cap is 422"); + check(logs("{\"limit\":\"5\"}").status == 422, "string limit is 422"); + check(logs("{\"filter\":\"" + std::string(3000, 'x') + "\"}").status == 422, "long filter is 422"); + + check(f.client->get("/google/ops/iam").status == 405, "get iam is 405"); + check(f.client->get("/google/ops/projects").status == 405, "get projects is 405"); + check(f.client->get("/google/ops/logs").status == 405, "get logs is 405"); + check(rig.mock->send_count() == 0, "nothing reached Google"); + return finish("google/ops/iam"); +} diff --git a/tests/example/google/ops/services_test.cpp b/tests/example/google/ops/services_test.cpp new file mode 100644 index 0000000..f56b983 --- /dev/null +++ b/tests/example/google/ops/services_test.cpp @@ -0,0 +1,36 @@ +// Route: POST /google/ops/services (enable and disable are dry runs by default) +#include "support/GoogleRig.hpp" + +using namespace molo::example::test; + +int main() { + setenv("GOOGLE_CLOUD_PROJECT", "test-project", 1); + GoogleRig rig(false); + Fixture f(rig.client); + auto post = [&](const std::string& body) { + return f.client->post("/google/ops/services", body, "application/json"); + }; + auto dry = post("{\"action\":\"enable\",\"api\":\"iam.googleapis.com\"}"); + check(dry.status == 200 && contains(dry.body, "\"executed\":false") && + contains(dry.body, "projects/test-project/services/iam.googleapis.com:enable"), + "enable is a dry run on the env project"); + auto off = post("{\"action\":\"disable\",\"api\":\"iam.googleapis.com\",\"project\":\"p2\"}"); + check(off.status == 200 && contains(off.body, "\"executed\":false") && + contains(off.body, "projects/p2/services/iam.googleapis.com:disable"), + "disable is a dry run"); + check(post("{\"action\":\"enable\",\"api\":\"iam.googleapis.com\",\"confirm\":true}").status == 503, + "confirmed enable without credential is 503"); + check(post("{\"action\":\"list\"}").status == 503, "list without credential is 503"); + check(post("{\"action\":\"list\",\"state\":\"BOGUS\"}").status == 422, "bad state is 422"); + check(post("{\"action\":\"get\"}").status == 422, "get without api is 422"); + check(post("{\"action\":\"get\",\"api\":\"a/b\"}").status == 422, "slash api is 422"); + check(post("{\"action\":\"batch_get\",\"apis\":[]}").status == 422, "empty batch is 422"); + check(post("{\"action\":\"batch_get\",\"apis\":[1]}").status == 422, "non-string api is 422"); + check(post("{\"action\":\"batch_get\",\"apis\":[\"run.googleapis.com\"]}").status == 503, "batch_get is 503"); + check(post("{\"action\":\"nope\"}").status == 422, "unknown action is 422"); + check(post("{}").status == 422, "missing action is 422"); + check(post("{\"action\":\"list\",\"project\":\"a/b\"}").status == 422, "bad project is 422"); + check(f.client->get("/google/ops/services").status == 405, "get is 405"); + check(rig.mock->send_count() == 0, "nothing reached Google"); + return finish("google/ops/services"); +} diff --git a/tests/example/google/ops/status_test.cpp b/tests/example/google/ops/status_test.cpp new file mode 100644 index 0000000..9bf4048 --- /dev/null +++ b/tests/example/google/ops/status_test.cpp @@ -0,0 +1,34 @@ +// Route: GET /google/ops, /google/ops/status, /google/ops/calls +#include "support/GoogleRig.hpp" + +using namespace molo::example::test; + +int main() { + setenv("GOOGLE_CLOUD_PROJECT", "test-project", 1); + GoogleRig off(false); + Fixture f(off.client); + auto page = f.client->get("/google/ops"); + check(page.status == 200, "page 200 without a credential"); + check(contains(page.body, "google_ops.js") && contains(page.body, "viewport") == contains(page.body, "viewport"), + "page loads its script"); + auto res = f.client->get("/google/ops/status"); + check(res.status == 200, "status 200"); + check(contains(res.body, "\"configured\":false"), "reports no credential"); + check(contains(res.body, "\"project_set\":true"), "project read from env"); + check(contains(res.body, "\"products\":20"), "20 products"); + auto calls = f.client->get("/google/ops/calls"); + check(calls.status == 200, "calls 200"); + check(contains(calls.body, "serviceusage.services.enable"), "table lists enable"); + check(contains(calls.body, "\"safety\":\"destructive\""), "table shows safety classes"); + auto one = f.client->get("/google/ops/calls?product=iam"); + check(one.status == 200 && contains(one.body, "iam.roles.list") && + !contains(one.body, "serviceusage.services.enable"), + "calls can be filtered by product"); + check(f.client->post("/google/ops/status", "{}", "application/json").status == 405, "post status is 405"); + check(f.client->get("/google/ops/call").status == 405, "get call is 405"); + GoogleRig on; + Fixture g(on.client); + check(contains(g.client->get("/google/ops/status").body, "\"configured\":true"), "reports credential"); + check(on.mock->send_count() == 0 && off.mock->send_count() == 0, "no network"); + return finish("google/ops/status"); +} diff --git a/tests/src/google/ops/test_ops_calls.cpp b/tests/src/google/ops/test_ops_calls.cpp new file mode 100644 index 0000000..66a1e96 --- /dev/null +++ b/tests/src/google/ops/test_ops_calls.cpp @@ -0,0 +1,127 @@ +// Ops call table invariants. The table is generated from Discovery by +// src/google/ops/tools/gen_calls.py and checked against Discovery by +// tools/check_discovery.py; these tests pin the properties the code relies on. +#include +#include +#include + +#include "framework.h" +#include "clients/transports/mock_transport.h" +#include "google/errors.h" +#include "google/ops/calls.h" +#include "google/ops/ops.h" + +using namespace molo::google; +using namespace molo::google::ops; + +TEST(ops_calls, table_is_large_and_unique) { + ASSERT_TRUE(call_count() >= 400); + std::set seen; + for (std::size_t i = 0; i < call_count(); ++i) { + const CallSpec& c = call_table()[i]; + ASSERT_TRUE(seen.insert(c.rpc).second); + ASSERT_TRUE(find_call(c.rpc) == &c); + } +} + +TEST(ops_calls, every_row_has_a_product_and_consistent_safety) { + for (std::size_t i = 0; i < call_count(); ++i) { + const CallSpec& c = call_table()[i]; + product_named(c.product()); + std::string http = c.http; + if (http == "DELETE") ASSERT_TRUE(c.safe() == Safety::kDestructive); + // A GET never changes state. + if (http == "GET") ASSERT_TRUE(c.safe() == Safety::kRead); + // Destructive rows are named delete / purge / batchDelete. + if (c.safe() == Safety::kDestructive) { + std::string rpc = c.rpc; + std::string verb = rpc.substr(rpc.rfind('.') + 1); + ASSERT_TRUE(verb.rfind("delete", 0) == 0 || verb == "batchDelete" || verb == "purge"); + } + // Bodiless verbs declare no body fields. + if (http == "GET" || http == "DELETE") ASSERT_EQ(std::string(c.body_fields), ""); + } +} + +TEST(ops_calls, path_parameters_and_shapes) { + for (std::size_t i = 0; i < call_count(); ++i) { + const CallSpec& c = call_table()[i]; + std::string path = c.path, shapes = c.path_shapes; + std::size_t params = 0; + for (std::size_t at = path.find('{'); at != std::string::npos; at = path.find('{', at + 1)) ++params; + std::size_t entries = shapes.empty() ? 0 : 1; + for (char ch : shapes) entries += ch == ' ' ? 1 : 0; + ASSERT_EQ(params, entries); + } +} + +TEST(ops_calls, list_rows_name_their_items) { + std::size_t lists = 0; + for (std::size_t i = 0; i < call_count(); ++i) { + const CallSpec& c = call_table()[i]; + if (c.is_list()) { + ++lists; + ASSERT_TRUE(c.safe() == Safety::kRead); + } + } + ASSERT_TRUE(lists >= 100); +} + +TEST(ops_calls, every_required_area_is_covered) { + const char* areas[] = { + "compute.instances.list", "run.projects.locations.services.list", + "cloudfunctions.projects.locations.functions.list", "container.projects.locations.clusters.list", + "cloudbuild.projects.locations.builds.list", "artifactregistry.projects.locations.repositories.list", + "iam.roles.list", "iam.projects.serviceAccounts.list", "iam.projects.serviceAccounts.keys.create", + "iam.projects.serviceAccounts.testIamPermissions", "iamcredentials.projects.serviceAccounts.signJwt", + "iamcredentials.projects.serviceAccounts.signBlob", "cloudresourcemanager.projects.get", + "serviceusage.services.enable", "serviceusage.services.disable", "serviceusage.services.list", + "serviceusage.services.batchGet", "logging.entries.list", "monitoring.projects.timeSeries.list", + "cloudscheduler.projects.locations.jobs.list", "cloudtasks.projects.locations.queues.list", + "workflows.projects.locations.workflows.list", "eventarc.projects.locations.triggers.list", + "cloudbilling.billingAccounts.list", "cloudasset.searchAllResources", + "orgpolicy.projects.policies.list"}; + for (const char* rpc : areas) ASSERT_TRUE(find_call(rpc) != nullptr); + ASSERT_EQ(product_count(), 20u); +} + +TEST(ops_calls, enable_and_disable_are_writes) { + ASSERT_TRUE(call_named("serviceusage.services.enable").safe() == Safety::kWrite); + ASSERT_TRUE(call_named("serviceusage.services.disable").safe() == Safety::kWrite); + ASSERT_TRUE(call_named("serviceusage.services.list").safe() == Safety::kRead); + // Signing and permission tests change nothing. + ASSERT_TRUE(call_named("iamcredentials.projects.serviceAccounts.signJwt").safe() == Safety::kRead); + ASSERT_TRUE(call_named("iam.projects.serviceAccounts.testIamPermissions").safe() == Safety::kRead); + ASSERT_TRUE(call_named("iam.projects.serviceAccounts.delete").safe() == Safety::kDestructive); + ASSERT_TRUE(call_named("cloudtasks.projects.locations.queues.purge").safe() == Safety::kDestructive); +} + +TEST(ops_calls, endpoints_come_from_discovery) { + ASSERT_EQ(endpoint_of(product_named("run")).base_url, "https://run.googleapis.com"); + ASSERT_EQ(endpoint_of(product_named("compute")).base_url, + "https://compute.googleapis.com/compute/v1"); + ASSERT_EQ(operation_endpoint_of(product_named("serviceusage")).base_url, + "https://serviceusage.googleapis.com/v1"); + ASSERT_THROW(product_named("nope"), GoogleError); + ASSERT_THROW(call_named("run.nope"), GoogleError); +} + +TEST(ops_calls, no_em_dash_in_table) { + for (std::size_t i = 0; i < call_count(); ++i) { + std::string row = std::string(call_table()[i].rpc) + call_table()[i].path; + ASSERT_TRUE(row.find("\xE2\x80\x94") == std::string::npos); + } +} + +TEST(ops_calls, every_product_object_owns_its_rows) { + Ops ops(std::make_shared( + std::make_unique(), nullptr)); + std::size_t total = 0; + for (const OpsProduct* p : ops.all()) { + auto rpcs = p->rpcs(); + ASSERT_TRUE(!rpcs.empty()); + total += rpcs.size(); + } + // Every row is reachable through exactly one product object. + ASSERT_EQ(total, call_count()); +} diff --git a/tests/src/google/ops/test_ops_live.cpp b/tests/src/google/ops/test_ops_live.cpp new file mode 100644 index 0000000..eecc669 --- /dev/null +++ b/tests/src/google/ops/test_ops_live.cpp @@ -0,0 +1,138 @@ +// Opt-in live, READ-ONLY probes of every ops product (MOLO_LIVE_NET=1, +// GOOGLE_ACCESS_TOKEN, GOOGLE_CLOUD_PROJECT). One list or get per product. +// Nothing is created, changed, enabled, disabled or deleted. A disabled API +// is reported loudly (API NOT ENABLED) and is not a failure: enabling is a +// human decision. A 400 or 401 IS a failure (our request or token is wrong). +#include +#include +#include +#include + +#include "framework.h" +#include "google/credentials.h" +#include "google/errors.h" +#include "google/ops/api_state.h" +#include "google/ops/ops.h" + +using namespace molo::google; +using namespace molo::google::ops; +using molo::clients::body::Json; + +namespace { + +bool ready() { + return std::getenv("MOLO_LIVE_NET") && !Credentials::env("GOOGLE_ACCESS_TOKEN").empty() && + !Credentials::env("GOOGLE_CLOUD_PROJECT").empty(); +} + +struct Tally { + int ok = 0, off = 0, denied = 0, other = 0, broken = 0; +}; + +void probe(Tally& t, const std::string& project, const char* what, + const std::function& call) { + try { + std::string summary = call(); + std::cout << " OK " << what << ": " << summary << "\n"; + ++t.ok; + } catch (const GoogleError& e) { + if (auto d = ApiState::disabled(e, project)) { + std::cout << " " << d->loud() << " (" << what << ")\n"; + ++t.off; + } else if (e.http_status() == 403) { + std::cout << " DENIED " << what << ": 403 " << e.status() << "\n"; + ++t.denied; + } else if (e.http_status() == 400 || e.http_status() == 401) { + std::cout << " BROKEN " << what << ": " << e.http_status() << " " << e.status() << ": " + << e.message() << "\n"; + ++t.broken; + } else { + std::cout << " other " << what << ": " << e.http_status() << " " << e.status() << "\n"; + ++t.other; + } + } +} + +std::string count(const Json& items) { + return std::to_string(items.is_array() ? items.as_array().size() : 0) + " items"; +} + +} // namespace + +TEST(ops_live, read_only_probe_of_every_product) { + if (!ready()) { + std::cout << "SKIP ops_live.read_only_probe_of_every_product (set MOLO_LIVE_NET=1, " + "GOOGLE_ACCESS_TOKEN and GOOGLE_CLOUD_PROJECT)\n"; + return; + } + const std::string project = Credentials::env("GOOGLE_CLOUD_PROJECT"); + const std::string pn = Names::project(project); + const std::string loc = Names::location(project, "us-central1"); + Ops ops(GoogleClient::from_env()); + Tally t; + std::cout << " project " << project << "\n"; + probe(t, project, "serviceusage list enabled", [&] { + auto enabled = ops.services.enabled_services(pn); + return std::to_string(enabled.size()) + " enabled APIs"; + }); + probe(t, project, "serviceusage get iam.googleapis.com", [&] { + ServiceState s = ops.services.state(ServiceUsage::service_name(project, "iam.googleapis.com")); + return s.api + " " + s.state; + }); + probe(t, project, "serviceusage batchGet", [&] { + Json r = ops.services.batch_get(pn, {ServiceUsage::service_name(project, "run.googleapis.com"), + ServiceUsage::service_name(project, "compute.googleapis.com")}); + const Json* s = r.find("services"); + return std::to_string(s && s->is_array() ? s->as_array().size() : 0) + " services"; + }); + probe(t, project, "resourcemanager project", [&] { + return ops.projects.project(pn).find("state")->as_string(); + }); + probe(t, project, "resourcemanager search", [&] { return count(ops.projects.search_projects()); }); + probe(t, project, "compute zones", [&] { return count(ops.compute.zones(project)); }); + probe(t, project, "compute instances", [&] { + return count(ops.compute.instances(project, "us-central1-a")); + }); + probe(t, project, "run services", [&] { return count(ops.run.services(loc)); }); + probe(t, project, "functions", [&] { return count(ops.functions.functions(loc)); }); + probe(t, project, "gke clusters", [&] { + Json r = ops.gke.clusters(Names::location(project, "-")); + const Json* c = r.find("clusters"); + return std::to_string(c && c->is_array() ? c->as_array().size() : 0) + " clusters"; + }); + probe(t, project, "cloudbuild builds", [&] { + return count(ops.build.builds(Names::location(project, "global"))); + }); + probe(t, project, "artifactregistry repositories", [&] { + return count(ops.artifacts.repositories(loc)); + }); + probe(t, project, "iam serviceAccounts", [&] { return count(ops.iam.service_accounts(pn)); }); + probe(t, project, "iam testIamPermissions on the first service account", [&] { + Json accounts = ops.iam.service_accounts(pn); + if (accounts.as_array().empty()) return std::string("no service account"); + const Json* name = accounts.as_array()[0].find("name"); + Json r = ops.iam.test_permissions(name->as_string(), {"iam.serviceAccounts.get"}); + const Json* p = r.find("permissions"); + return std::to_string(p && p->is_array() ? p->as_array().size() : 0) + " of 1 permissions held"; + }); + probe(t, project, "iam roles (first page)", [&] { + return count(ops.iam.list("iam.roles.list", Args().query("pageSize", Json(5)), 1)); + }); + probe(t, project, "logging log names", [&] { return count(ops.logging.log_names(pn)); }); + probe(t, project, "logging entries", [&] { + return count(ops.logging.entries({pn}, "severity>=ERROR", "timestamp desc", 5)); + }); + probe(t, project, "monitoring alert policies", [&] { return count(ops.monitoring.alert_policies(pn)); }); + probe(t, project, "scheduler jobs", [&] { return count(ops.scheduler.jobs(loc)); }); + probe(t, project, "tasks queues", [&] { return count(ops.tasks.queues(loc)); }); + probe(t, project, "workflows", [&] { return count(ops.workflows.workflows(loc)); }); + probe(t, project, "eventarc triggers", [&] { return count(ops.eventarc.triggers(loc)); }); + probe(t, project, "billing project info", [&] { + return std::string(ops.billing.project_billing_info(pn).find("billingEnabled") ? "read" : "empty"); + }); + probe(t, project, "cloudasset search", [&] { return count(ops.assets.search_resources(pn)); }); + probe(t, project, "orgpolicy constraints", [&] { return count(ops.policies.constraints(pn)); }); + std::cout << " ok " << t.ok << ", API NOT ENABLED " << t.off << ", denied " << t.denied + << ", other " << t.other << ", broken " << t.broken << "\n"; + ASSERT_EQ(t.broken, 0); +} diff --git a/tests/src/google/ops/test_ops_plan.cpp b/tests/src/google/ops/test_ops_plan.cpp new file mode 100644 index 0000000..e708a82 --- /dev/null +++ b/tests/src/google/ops/test_ops_plan.cpp @@ -0,0 +1,158 @@ +// CallPlan: path rendering, validation and caps. Nothing here touches the +// network: a plan is built and inspected, never sent. +#include + +#include "framework.h" +#include "google/errors.h" +#include "google/ops/call_plan.h" + +using namespace molo::google; +using namespace molo::google::ops; +using molo::clients::body::Json; + +namespace { +CallPlan plan(const char* rpc, const Args& a) { return CallPlan::build(call_named(rpc), a); } + +template +bool rejects(F&& f) { + try { + f(); + } catch (const GoogleError& e) { + return e.http_status() == 400 && e.status() == "INVALID_ARGUMENT"; + } + return false; +} +} // namespace + +TEST(ops_plan, renders_resource_names_and_plain_params) { + Args a; + a.path("name", "projects/p1/locations/europe-west4/services/web"); + ASSERT_EQ(plan("run.projects.locations.services.get", a).path(), + "/v2/projects/p1/locations/europe-west4/services/web"); + Args z; + z.path("project", "p1").path("zone", "us-central1-a"); + ASSERT_EQ(plan("compute.instances.list", z).path(), "/projects/p1/zones/us-central1-a/instances"); + ASSERT_EQ(plan("compute.instances.list", z).url(), + "https://compute.googleapis.com/compute/v1/projects/p1/zones/us-central1-a/instances"); + Args s; + s.path("name", "projects/p1/services/iam.googleapis.com"); + ASSERT_EQ(plan("serviceusage.services.enable", s).path(), + "/v1/projects/p1/services/iam.googleapis.com:enable"); + ASSERT_TRUE(plan("serviceusage.services.enable", s).has_body()); // POST always sends {} + ASSERT_EQ(plan("serviceusage.services.enable", s).body().dump(), "{}"); + ASSERT_FALSE(plan("run.projects.locations.services.get", a).has_body()); +} + +TEST(ops_plan, query_is_validated_and_encoded) { + Args a; + a.path("parent", "projects/p1"); + a.query("filter", Json("state:ENABLED")).query("pageSize", Json(50)); + std::string p = plan("serviceusage.services.list", a).path(); + ASSERT_TRUE(p.find("filter=state%3AENABLED") != std::string::npos); + ASSERT_TRUE(p.find("pageSize=50") != std::string::npos); + Args names; + names.path("parent", "projects/p1"); + Json arr = Json::array(); + arr.push(Json("a.googleapis.com")); + arr.push(Json("b.googleapis.com")); + names.query("names", arr); + std::string q = plan("serviceusage.services.batchGet", names).path(); + ASSERT_TRUE(q.find("names=a.googleapis.com&names=b.googleapis.com") != std::string::npos); + Args bad; + bad.path("parent", "projects/p1").query("nope", Json("x")); + ASSERT_TRUE(rejects([&] { plan("serviceusage.services.list", bad); })); + Args frac; + frac.path("parent", "projects/p1").query("pageSize", Json(1.5)); + ASSERT_TRUE(rejects([&] { plan("serviceusage.services.list", frac); })); + Args big; + big.path("parent", "projects/p1").query("filter", Json(std::string(2000, 'x'))); + ASSERT_TRUE(rejects([&] { plan("serviceusage.services.list", big); })); +} + +TEST(ops_plan, path_validation) { + auto with = [](const char* key, const std::string& v) { + Args a; + a.path(key, v); + return a; + }; + ASSERT_TRUE(rejects([&] { plan("run.projects.locations.services.get", Args()); })); // missing + ASSERT_TRUE(rejects([&] { + plan("run.projects.locations.services.get", with("name", "projects/p/locations/l")); // shape + })); + ASSERT_TRUE(rejects([&] { + plan("run.projects.locations.services.get", with("name", "projects/p/locations/l/services/../x")); + })); + ASSERT_TRUE(rejects([&] { + plan("run.projects.locations.services.get", with("name", "projects/p/locations/l/services/%2e%2E")); + })); + ASSERT_TRUE(rejects([&] { + plan("run.projects.locations.services.get", with("name", "other/p/locations/l/services/s")); + })); + ASSERT_TRUE(rejects([&] { + plan("run.projects.locations.services.get", with("name", "projects/p/locations/l/services/s?x=1")); + })); + ASSERT_TRUE(rejects([&] { + plan("run.projects.locations.services.get", with("name", "projects/p/locations/l/services/s#f")); + })); + ASSERT_TRUE(rejects([&] { + plan("run.projects.locations.services.get", with("name", "projects/p/locations/l/services/ s")); + })); + ASSERT_TRUE(rejects([&] { plan("compute.instances.get", with("project", "a/b")); })); + ASSERT_TRUE(rejects([&] { + Args a = with("name", "projects/p/locations/l/services/s"); + a.path("extra", "x"); + plan("run.projects.locations.services.get", a); + })); + ASSERT_TRUE(rejects([&] { + plan("run.projects.locations.services.get", + with("name", "projects/p/locations/l/services/" + std::string(300, 'a'))); + })); + // A service account email and an encoded log name are valid segments. + ASSERT_EQ(plan("iam.projects.serviceAccounts.get", + with("name", "projects/p/serviceAccounts/sa@p.iam.gserviceaccount.com")).path(), + "/v1/projects/p/serviceAccounts/sa@p.iam.gserviceaccount.com"); + ASSERT_EQ(plan("logging.projects.logs.delete", + with("logName", "projects/p/logs/cloudaudit.googleapis.com%2Factivity")).path(), + "/v2/projects/p/logs/cloudaudit.googleapis.com%2Factivity"); +} + +TEST(ops_plan, body_is_checked_against_the_table) { + Args a; + a.path("parent", "projects/p1"); + a.field("serviceIds", Json::array()); + ASSERT_EQ(plan("serviceusage.services.batchEnable", a).body().dump(), "{\"serviceIds\":[]}"); + Args typo = a; + typo.field("serviceId", Json("x")); + ASSERT_TRUE(rejects([&] { plan("serviceusage.services.batchEnable", typo); })); + // GET and DELETE take no body. + Args g; + g.path("name", "projects/p/locations/l/services/s").field("x", Json(1)); + ASSERT_TRUE(rejects([&] { plan("run.projects.locations.services.get", g); })); + ASSERT_TRUE(rejects([&] { plan("run.projects.locations.services.delete", g); })); + // Body must be an object and at most 1 MiB. + Args notobj; + notobj.path("parent", "projects/p1").body(Json("str")); + ASSERT_TRUE(rejects([&] { plan("serviceusage.services.batchEnable", notobj); })); + Args huge; + huge.path("parent", "projects/p1").field("serviceIds", Json(std::string(1024 * 1024 + 10, 'x'))); + ASSERT_TRUE(rejects([&] { plan("serviceusage.services.batchEnable", huge); })); +} + +TEST(ops_plan, args_from_json) { + Json doc = Json::parse( + "{\"path\":{\"parent\":\"projects/p1\"},\"query\":{\"pageSize\":5},\"body\":{}}"); + Args a = Args::from_json(doc); + ASSERT_EQ(plan("serviceusage.services.list", a).path(), "/v1/projects/p1/services?pageSize=5"); + ASSERT_TRUE(rejects([] { Args::from_json(Json::parse("{\"path\":{\"x\":1}}")); })); + ASSERT_TRUE(rejects([] { Args::from_json(Json::parse("{\"query\":[]}")); })); + ASSERT_TRUE(rejects([] { Args::from_json(Json::parse("[]")); })); +} + +TEST(ops_plan, plan_json_shows_the_safety_class) { + Args a; + a.path("name", "projects/p/serviceAccounts/x@p.iam.gserviceaccount.com"); + Json j = plan("iam.projects.serviceAccounts.delete", a).to_json(); + ASSERT_EQ(j.find("safety")->as_string(), "destructive"); + ASSERT_EQ(j.find("http")->as_string(), "DELETE"); + ASSERT_TRUE(j.find("url")->as_string().rfind("https://iam.googleapis.com/v1/projects/p", 0) == 0); +} diff --git a/tests/src/google/ops/test_ops_products.cpp b/tests/src/google/ops/test_ops_products.cpp new file mode 100644 index 0000000..d798b96 --- /dev/null +++ b/tests/src/google/ops/test_ops_products.cpp @@ -0,0 +1,243 @@ +// Ops products without a credential: validation happens first, dry runs send +// nothing, confirmed and read calls stop at NotConfiguredError. A second rig +// with a bearer and an UNSCRIPTED mock shows the request that would go out +// (the mock refuses to answer, so no Google reply is invented). +#include + +#include "framework.h" +#include "clients/transports/mock_transport.h" +#include "google/credentials.h" +#include "google/errors.h" +#include "google/ops/api_state.h" +#include "google/ops/ops.h" + +using namespace molo::google; +using namespace molo::google::ops; +using molo::clients::Method; +using molo::clients::body::Json; +using molo::clients::transports::MockTransport; + +namespace { + +struct Rig { + MockTransport* mock = nullptr; + std::shared_ptr client; + explicit Rig(bool bearer = false) { + auto t = std::make_unique(); + mock = t.get(); + client = std::make_shared( + std::move(t), bearer ? Credentials::bearer("tok") : nullptr); + } +}; + +bool invalid(const std::function& f) { + try { + f(); + } catch (const NotConfiguredError&) { + return false; + } catch (const GoogleError& e) { + return e.http_status() == 400 && e.status() == "INVALID_ARGUMENT"; + } + return false; +} + +bool not_configured(const std::function& f) { + try { + f(); + } catch (const NotConfiguredError&) { + return true; + } + return false; +} + +const char* kP = "projects/p1"; +} // namespace + +TEST(ops_products, dry_run_is_the_default_for_writes) { + Rig r; + ServiceUsage su(r.client); + Outcome o = su.enable(ServiceUsage::service_name("p1", "iam.googleapis.com")); + ASSERT_FALSE(o.executed); + ASSERT_EQ(o.plan.path(), "/v1/projects/p1/services/iam.googleapis.com:enable"); + Json j = o.to_json(); + ASSERT_EQ(j.find("executed")->as_bool(), false); + ASSERT_TRUE(j.find("hint") != nullptr); + ASSERT_FALSE(su.disable(ServiceUsage::service_name("p1", "iam.googleapis.com")).executed); + ASSERT_FALSE(su.batch_enable(kP, {"a.googleapis.com"}).executed); + ASSERT_EQ(r.mock->send_count(), 0u); + // Confirmed: stops at the credential check. + ASSERT_TRUE(not_configured([&] { + su.enable(ServiceUsage::service_name("p1", "iam.googleapis.com"), true); + })); + ASSERT_EQ(r.mock->send_count(), 0u); +} + +TEST(ops_products, destructive_calls_have_no_default_and_dry_run) { + Rig r; + Ops ops(r.client); + Outcome d = ops.run.delete_service("projects/p1/locations/l/services/s", false); + ASSERT_FALSE(d.executed); + ASSERT_EQ(d.plan.to_json().find("safety")->as_string(), "destructive"); + ASSERT_FALSE(ops.iam.delete_key("projects/p1/serviceAccounts/a@p1.iam.gserviceaccount.com/keys/k", false).executed); + ASSERT_FALSE(ops.compute.delete_instance("p1", "us-central1-a", "vm", false).executed); + ASSERT_FALSE(ops.tasks.purge_queue("projects/p1/locations/l/queues/q", false).executed); + ASSERT_FALSE(ops.functions.delete_function("projects/p1/locations/l/functions/f", false).executed); + ASSERT_FALSE(ops.projects.delete_project(kP, false).executed); + ASSERT_FALSE(ops.logging.delete_log("projects/p1/logs/x", false).executed); + ASSERT_EQ(r.mock->send_count(), 0u); + ASSERT_TRUE(not_configured([&] { ops.run.delete_service("projects/p1/locations/l/services/s", true); })); +} + +TEST(ops_products, reads_validate_then_need_a_credential) { + Rig r; + Ops ops(r.client); + ASSERT_TRUE(not_configured([&] { ops.services.list_services(kP); })); + ASSERT_TRUE(not_configured([&] { ops.services.service("projects/p1/services/iam.googleapis.com"); })); + ASSERT_TRUE(not_configured([&] { ops.compute.instances("p1", "us-central1-a"); })); + ASSERT_TRUE(not_configured([&] { ops.run.services("projects/p1/locations/europe-west4"); })); + ASSERT_TRUE(not_configured([&] { ops.iam.service_accounts(kP); })); + ASSERT_TRUE(not_configured([&] { ops.logging.entries({kP}, "severity>=ERROR"); })); + ASSERT_TRUE(not_configured([&] { ops.projects.search_projects(); })); + ASSERT_TRUE(not_configured([&] { ops.assets.search_resources(kP); })); + ASSERT_TRUE(invalid([&] { ops.services.list_services("projects/p1/x"); })); // shape * + ASSERT_TRUE(invalid([&] { ops.services.list_services("projects/../x"); })); + ASSERT_TRUE(invalid([&] { ops.run.service("nonsense"); })); + ASSERT_TRUE(invalid([&] { ops.compute.instances("p1", "zone/../x"); })); + ASSERT_TRUE(invalid([&] { ops.iam.service_account("projects/p1"); })); + ASSERT_EQ(r.mock->send_count(), 0u); +} + +TEST(ops_products, caps_and_batches) { + Rig r; + ServiceUsage su(r.client); + std::vector many(OpsCaps::kMaxBatchNames + 1, "projects/p1/services/a.googleapis.com"); + ASSERT_TRUE(invalid([&] { su.batch_get(kP, many); })); + ASSERT_TRUE(invalid([&] { su.batch_get(kP, {}); })); + ASSERT_TRUE(invalid([&] { su.batch_enable(kP, {}, true); })); + ASSERT_TRUE(invalid([&] { su.batch_enable(kP, {"bad/id"}, true); })); + Ops ops(r.client); + ASSERT_TRUE(invalid([&] { ops.logging.entries({}, "x"); })); + ASSERT_TRUE(invalid([&] { ops.logging.entries({kP}, "x", "timestamp desc", 0); })); + ASSERT_TRUE(invalid([&] { ops.logging.entries({kP}, "x", "timestamp desc", 100000); })); + ASSERT_TRUE(invalid([&] { ops.logging.entries({kP}, "x", "severity", 5); })); + ASSERT_TRUE(invalid([&] { ops.logging.entries({kP}, std::string(3000, 'a')); })); + ASSERT_TRUE(invalid([&] { + ops.credentials.sign_jwt("projects/-/serviceAccounts/a@p1.iam.gserviceaccount.com", ""); + })); + ASSERT_TRUE(invalid([&] { + ops.credentials.sign_blob("projects/-/serviceAccounts/a@p1.iam.gserviceaccount.com", + std::string(OpsCaps::kMaxSignPayloadBytes + 1, 'a')); + })); + ASSERT_TRUE(invalid([&] { ServiceUsage::service_name("p/1", "x"); })); + ASSERT_TRUE(invalid([&] { Names::location("p", "a/b"); })); +} + +TEST(ops_products, a_product_only_runs_its_own_rows) { + Rig r; + Ops ops(r.client); + Args a; + a.path("name", "projects/p1/services/iam.googleapis.com"); + ASSERT_TRUE(invalid([&] { ops.run.read("serviceusage.services.get", a); })); + ASSERT_TRUE(invalid([&] { ops.services.call("run.projects.locations.services.get", a, true); })); + ASSERT_TRUE(invalid([&] { ops.services.read("serviceusage.services.enable", a); })); // not a read + ASSERT_TRUE(invalid([&] { ops.services.list("serviceusage.services.get", a); })); // not a list + ASSERT_TRUE(invalid([&] { ops.services.read("serviceusage.nope", a); })); + ASSERT_TRUE(invalid([&] { ops.services.list("serviceusage.services.list", a, 0); })); + ASSERT_TRUE(invalid([&] { ops.services.list("serviceusage.services.list", a, 1000); })); + ASSERT_EQ(ops.product("serviceusage").product().version, std::string("v1")); + ASSERT_THROW(ops.product("nope"), GoogleError); +} + +TEST(ops_products, typed_methods_build_valid_plans) { + Rig r; + Ops ops(r.client); + // Every dry run goes through the real validation of the table row. + ASSERT_EQ(ops.compute.start_instance("p1", "us-central1-a", "vm").plan.path(), + "/projects/p1/zones/us-central1-a/instances/vm/start"); + ASSERT_EQ(ops.iam.create_service_account("projects/p1", "worker", "Worker").plan.body().dump(), + "{\"accountId\":\"worker\",\"serviceAccount\":{\"displayName\":\"Worker\"}}"); + ASSERT_EQ(ops.iam.create_key("projects/p1/serviceAccounts/w@p1.iam.gserviceaccount.com").plan.path(), + "/v1/projects/p1/serviceAccounts/w@p1.iam.gserviceaccount.com/keys"); + ASSERT_EQ(ops.run.run_job("projects/p1/locations/l/jobs/j").plan.path(), + "/v2/projects/p1/locations/l/jobs/j:run"); + ASSERT_EQ(ops.functions.generate_upload_url("projects/p1/locations/l").plan.path(), + "/v2/projects/p1/locations/l/functions:generateUploadUrl"); + ASSERT_EQ(ops.scheduler.pause_job("projects/p1/locations/l/jobs/j").plan.path(), + "/v1/projects/p1/locations/l/jobs/j:pause"); + ASSERT_EQ(ops.tasks.create_task("projects/p1/locations/l/queues/q", Json::object()).plan.body().dump(), + "{\"task\":{}}"); + ASSERT_EQ(ops.workflows.create_workflow("projects/p1/locations/l", "wf", Json::object()).plan.path(), + "/v1/projects/p1/locations/l/workflows?workflowId=wf"); + ASSERT_EQ(ops.executions.start("projects/p1/locations/l/workflows/wf", "{\"a\":1}").plan.body().dump(), + "{\"argument\":\"{\\\"a\\\":1}\"}"); + ASSERT_EQ(ops.eventarc.create_trigger("projects/p1/locations/l", "t", Json::object()).plan.path(), + "/v1/projects/p1/locations/l/triggers?triggerId=t"); + ASSERT_TRUE(ops.billing.link_project(kP, "billingAccounts/000-000-000").plan.method() == + molo::clients::Method::kPut); + ASSERT_EQ(ops.build.cancel_build("projects/p1/locations/l/builds/b").plan.path(), + "/v1/projects/p1/locations/l/builds/b:cancel"); + ASSERT_EQ(ops.artifacts.delete_repository("projects/p1/locations/l/repositories/r", false).plan.path(), + "/v1/projects/p1/locations/l/repositories/r"); + ASSERT_EQ(ops.gke.set_node_pool_size("projects/p1/locations/l/clusters/c/nodePools/n", 3).plan.body().dump(), + "{\"nodeCount\":3}"); + ASSERT_EQ(ops.policies.delete_policy("projects/p1/policies/constraints~foo", false).plan.path(), + "/v2/projects/p1/policies/constraints~foo"); + ASSERT_EQ(ops.assets.export_assets(kP, Json::object()).plan.path(), "/v1/projects/p1:exportAssets"); + ASSERT_EQ(ops.monitoring.delete_alert_policy("projects/p1/alertPolicies/a", false).plan.path(), + "/v3/projects/p1/alertPolicies/a"); + ASSERT_EQ(ops.logging.write_entries(Json::object()).plan.path(), "/v2/entries:write"); + ASSERT_EQ(r.mock->send_count(), 0u); +} + +TEST(ops_products, confirmed_request_goes_out_with_bearer) { + Rig r(true); + ServiceUsage su(r.client); + // The mock has no scripted answer: the call fails, but the request it saw + // is the one a real transport would carry. + try { + su.list_services(kP, "state:ENABLED"); + } catch (const std::exception&) { + } + auto seen = r.mock->seen(); + ASSERT_EQ(seen.size(), 1u); + ASSERT_EQ(seen[0].method, "GET"); + ASSERT_TRUE(seen[0].target.find("/v1/projects/p1/services?") == 0); + ASSERT_TRUE(seen[0].target.find("filter=state%3AENABLED") != std::string::npos); + ASSERT_EQ(seen[0].headers.get_or("Authorization", ""), "Bearer tok"); +} + +TEST(ops_products, wait_checks_the_operation_name) { + Rig r; + ServiceUsage su(r.client); + ASSERT_TRUE(invalid([&] { su.wait(""); })); + ASSERT_TRUE(invalid([&] { su.wait("operations/x"); })); + ASSERT_TRUE(invalid([&] { su.wait("projects/p/../x"); })); + ASSERT_TRUE(invalid([&] { su.wait("projects/p/operations/x?y=1"); })); + ASSERT_TRUE(invalid([&] { su.wait("projects/" + std::string(600, 'a')); })); + ASSERT_TRUE(not_configured([&] { su.wait("projects/p/operations/x"); })); +} + +TEST(ops_products, service_state_parses_google_documents) { + Json doc = Json::parse( + "{\"name\":\"projects/1/services/iam.googleapis.com\",\"state\":\"DISABLED\"," + "\"config\":{\"name\":\"iam.googleapis.com\",\"title\":\"Identity and Access Management (IAM) API\"}}"); + ServiceState s = ServiceState::from_json(doc); + ASSERT_EQ(s.api, "iam.googleapis.com"); + ASSERT_FALSE(s.enabled()); + ASSERT_TRUE(ServiceState::from_json(Json::parse("[]")).name.empty()); +} + +TEST(ops_products, disabled_api_is_recognised_loudly) { + GoogleError e(403, "PERMISSION_DENIED", + "Identity and Access Management (IAM) API has not been used in project 123 before " + "or it is disabled. Enable it by visiting https://console.developers.google.com/" + "apis/api/iam.googleapis.com/overview?project=123 then retry."); + auto d = ApiState::disabled(e, "p1"); + ASSERT_TRUE(d.has_value()); + ASSERT_EQ(d->service, "iam.googleapis.com"); + ASSERT_EQ(d->loud().rfind("API NOT ENABLED: iam.googleapis.com", 0), 0u); + ASSERT_TRUE(d->activation_url.find("project=p1") != std::string::npos); + ASSERT_FALSE(ApiState::disabled(GoogleError(404, "NOT_FOUND", "no such thing"), "p1").has_value()); + ASSERT_FALSE(ApiState::disabled(GoogleError(403, "PERMISSION_DENIED", "caller lacks permission"), "p1") + .has_value()); +}