feat(clients): sandbox: data plane (JWT proxy, CDP WebSocket), operations, SDK chunk shapes
Data plane per the computer use quickstart and SDK 2.6.0 source: signJwt minted JWT, /cdp /tabs /cdp_ws_endpoint over HTTP with routing headers, CDP over the live WsClient with capped reconnect. Operations methods wrapped, input/output chunk shapes settled from the SDK, ComputerUse moved off execute. Execution paths remain verified by Discovery, docs and SDK only. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,60 @@
|
||||
#include "google/sandbox/data_plane_connector.h"
|
||||
|
||||
#include "google/credentials.h"
|
||||
#include "google/errors.h"
|
||||
#include "google/sandbox/sandboxes.h"
|
||||
#include "google/service_account.h"
|
||||
|
||||
namespace molo::google::sandbox {
|
||||
|
||||
DataPlaneOptions DataPlaneOptions::from_env() {
|
||||
DataPlaneOptions o;
|
||||
o.service_account_email = Credentials::env("GOOGLE_SERVICE_ACCOUNT_EMAIL");
|
||||
if (o.service_account_email.empty()) {
|
||||
std::string path = Credentials::env("GOOGLE_APPLICATION_CREDENTIALS");
|
||||
if (!path.empty()) {
|
||||
try {
|
||||
o.service_account_email = ServiceAccountKey::load_file(path).client_email;
|
||||
} catch (const std::exception&) {
|
||||
// No usable key file: the data plane stays unavailable, loudly, at use.
|
||||
}
|
||||
}
|
||||
}
|
||||
return o;
|
||||
}
|
||||
|
||||
DataPlaneConnector::DataPlaneConnector(std::shared_ptr<GoogleClient> client,
|
||||
DataPlaneOptions options,
|
||||
std::shared_ptr<ITokenSource> tokens)
|
||||
: SandboxService(client), options_(std::move(options)), tokens_(std::move(tokens)) {
|
||||
if (!tokens_ && !options_.service_account_email.empty())
|
||||
tokens_ = std::make_shared<IamJwtSource>(client, options_.service_account_email,
|
||||
options_.jwt_ttl_seconds);
|
||||
}
|
||||
|
||||
SandboxEnvironment DataPlaneConnector::environment(const std::string& sandbox_name) const {
|
||||
return Sandboxes(client_).get(sandbox_name);
|
||||
}
|
||||
|
||||
std::shared_ptr<DataPlane> DataPlaneConnector::open(const std::string& sandbox_name) const {
|
||||
SandboxNames::parse_sandbox(sandbox_name);
|
||||
if (!client_->configured()) throw NotConfiguredError("sandbox-data-plane");
|
||||
// No signer is a configuration gap, not bad input: 503 like a missing credential.
|
||||
if (!tokens_) throw NotConfiguredError("sandbox-data-plane (set GOOGLE_SERVICE_ACCOUNT_EMAIL)");
|
||||
SandboxEnvironment env = environment(sandbox_name);
|
||||
if (!env.running())
|
||||
throw GoogleError(409, "FAILED_PRECONDITION",
|
||||
"sandbox is " + (env.state.empty() ? std::string("in an unknown state") : env.state) +
|
||||
", not STATE_RUNNING",
|
||||
"sandbox-data-plane");
|
||||
DataPlaneTarget target = DataPlaneTarget::from_environment(
|
||||
env, options_.psc_endpoint, options_.loopback_override, options_.port);
|
||||
return std::make_shared<DataPlane>(std::move(target), tokens_, nullptr, options_.timeout_ms);
|
||||
}
|
||||
|
||||
std::unique_ptr<CdpSession> DataPlaneConnector::open_cdp(const std::string& sandbox_name,
|
||||
CdpOptions options) const {
|
||||
return std::make_unique<CdpSession>(open(sandbox_name), std::move(options));
|
||||
}
|
||||
|
||||
} // namespace molo::google::sandbox
|
||||
Reference in New Issue
Block a user