Files
zeekay 7098a20d92 client: the document is the one cloud emits, named by commit
This client read hanzoai/openapi's hanzo.yaml at branch `main` and carried no
lock, so it named its document by something that moves and could not say which
bytes it was a projection of. It now reads what hanzoai/cloud emits, at the
commit .spec-lock names, digest-checked on every fetch — the same document and
the same four-line receipt every other Hanzo client carries. This repo's own
hanzo.yml had already declared that move; the script had not made it, so the
lane and the script named two different documents.

Nothing is lost, measured route by route: cloud's document is a strict SUPERSET
of the projection — 2479 operations against 2456, with 0 routes only in
hanzo.yaml and 23 only in cloud. The projection's one addition for this
language, a `default` response injected into every operation that declares
none, buys nothing here: a `default` with no content produces the same void
return that no `responses` does, so both documents yield the identical 834
void-returning methods. Generated, that is 2502 methods against 2455 committed.

The 7.24.0 generator floor is gone, and it was not wrong when written — both
defects it named lived in schemas the document no longer carries
(vector_NamedVectors under additionalProperties, framework_Document.docstatus).
Re-measured at the locked commit, 7.14.0 and 7.24.0 emit the same library apart
from the version string in each file's header and one doc comment on
ConsoleSettings::getOidcConfig. So this repo is on the fleet's 7.14.0 pin and is
no longer an exception on version. It stays out of sdks.yaml for one reason
only, and that one is measured too: without templates/cpp-restsdk the library
fails with 8 errors in ModelBase.h, and a template is a file that has to sit
beside the invocation.

One flag joins the invocation, and it is the fleet's own. o11y.GettableAgentCheckIn
publishes integration_config beside integrationConfig and removed_at beside
removedAt so older agents keep working; C++ camel-cases a property into its
accessor, so each pair declared one method twice and the library did not
compile. Renaming the accessor keeps both wire keys — all four are present in
the emitted model, each under its own name — which is what the python, go,
java, kotlin, ruby and php rows already do for the same two schemas.

Four flows changed route, none of them because of this move: their old
operations are untyped or absent in hanzo.yaml too, measured by regenerating
from it, so the committed tree simply predated the change. hello, chat, money
and tools move to the typed route for the same job; agent keeps its route and
reads the run from the typed list, because the run POST declares no body and no
response. Each says so in its own header, and the rule they follow is that an
example has to demonstrate a call the document types.

packageVersion leaves the invocation as inert: measured with a sentinel it
reaches the generator's own README and no file under include/ or src/, so the
library version in CMakeLists.txt is this repo's to choose and is coupled to
nothing.

Measured on aarch64 Ubuntu 24.04, g++ 13.3, generator 7.14.0, document
49389cf9: 2663 sources, library 0 errors, six examples 0 errors.
2026-08-14 20:28:34 -07:00

80 lines
2.6 KiB
C++

// store — KV round-trip: create a store, read it back, delete it.
//
// Operations: postKv (POST /v1/kv)
// getKvByName (GET /v1/kv/{name})
// deleteKvByName (DELETE /v1/kv/{name})
//
// The delete is in a scope guard, so a failed read still cleans up instead of
// leaving the store behind for the next run to collide with.
//
// This is the PROVISIONING plane, and it is the one that answers. The value
// plane (/v1/kv/keys/{key}) is authored in the document and mounted nowhere:
// auth middleware runs before the handler, so a route that exists refuses with
// 403 and one that does not is 404 — /v1/kv, /v1/kv/demo and /v1/kv/keys all
// answer 403 "X-Org-Id required" while /v1/kv/keys/x answers 404.
//
// HANZO_API_KEY=hk-... HANZO_ORG_ID=... ./build/examples/store
#include <ctime>
#include <iostream>
#include <string>
#include "hanzo.h"
#include "hanzo/api/KvApi.h"
namespace {
// Runs must not collide, so the name is unique per run rather than fixed.
utility::string_t uniqueName() {
return utility::conversions::to_string_t("hanzo-cpp-example-" +
std::to_string(std::time(nullptr)));
}
// Delete on the way out, however we leave.
class Cleanup {
public:
Cleanup(const hanzo::api::KvApi& kv, utility::string_t name)
: m_kv(kv), m_name(std::move(name)) {}
~Cleanup() {
try {
m_kv.deleteKvByName(m_name).get();
hanzo::examples::print(U("deleted "), m_name);
} catch (const std::exception& e) {
std::cerr << "delete failed: " << e.what() << std::endl;
}
}
private:
const hanzo::api::KvApi& m_kv;
utility::string_t m_name;
};
} // namespace
int main() {
using namespace hanzo;
api::KvApi kv(examples::client());
const utility::string_t name = uniqueName();
try {
auto request = std::make_shared<model::ProvisionRequest>();
request->setName(name);
std::shared_ptr<model::ProvisionResult> created =
kv.postKv(request).get();
examples::print(U("created "), created->getName());
examples::print(U("kind "), created->getKind());
examples::print(U("status "), created->getStatus());
Cleanup cleanup(kv, name);
std::shared_ptr<model::ProvisionedResource> read =
kv.getKvByName(name).get();
examples::print(U("read "), read->getName());
examples::print(U("host "), read->getHost());
examples::print(U("port "), static_cast<int64_t>(read->getPort()));
} catch (const std::exception& e) {
return examples::fail(U("kv"), e);
}
return 0;
}