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>
This commit is contained in:
@@ -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 <vector>
|
||||
|
||||
#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<GoogleClient> 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<std::string>& 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
|
||||
Reference in New Issue
Block a user