Files
moloapp/src/google/ops/api_state.cpp
T
retoorandClaude Sonnet 5.5 18ec8b720e feat(clients): ops: 20 Google Cloud operations APIs, 418 Discovery-derived calls
Compute, Cloud Run, Functions, GKE, Build, Artifact Registry, IAM, IAM
Credentials, Resource Manager, Service Usage, Logging, Monitoring, Scheduler,
Tasks, Workflows, Eventarc, Billing, Asset, Org Policy. Generated call table
checked against Discovery, validated plans, dry-run default for writes
(enable/disable never live), /google/ops demo routes, live read-only probe.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-25 15:23:56 +01:00

43 lines
1.5 KiB
C++

#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<DisabledApi> 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