Merge sessions, registry, optimize, armor gaps
This commit is contained in:
@@ -9,12 +9,14 @@
|
||||
#include "../../fw/Templates.hpp"
|
||||
#include "../../fw/Validate.hpp"
|
||||
#include "clients/body/json.h"
|
||||
#include "google/armor/agent_categories.h"
|
||||
#include "google/armor/armor_util.h"
|
||||
#include "google/armor/caps.h"
|
||||
#include "google/armor/dashboard.h"
|
||||
#include "google/armor/findings.h"
|
||||
#include "google/armor/guarded_model.h"
|
||||
#include "google/armor/model_armor.h"
|
||||
#include "google/armor/security_admin.h"
|
||||
#include "google/credentials.h"
|
||||
#include "google/endpoints.h"
|
||||
|
||||
@@ -157,6 +159,8 @@ OAuth access token, not an API key.</p>
|
||||
<option value="floor/get">Floor settings</option>
|
||||
<option value="findings">Agent findings</option>
|
||||
<option value="dashboard">Security summary</option>
|
||||
<option value="scc/availability">Security Command Center status</option>
|
||||
<option value="scc/configs/list">List SCC configs</option>
|
||||
</select></label>
|
||||
<label>Template id <input id="a-template" type="text" maxlength="128" placeholder="my-template"></label>
|
||||
<label>Text <textarea id="a-text" rows="4" maxlength="4000" placeholder="Text to check"></textarea></label>
|
||||
@@ -164,6 +168,12 @@ OAuth access token, not an API key.</p>
|
||||
<label>Severity
|
||||
<select id="a-severity"><option value="">any</option><option>CRITICAL</option>
|
||||
<option>HIGH</option><option>MEDIUM</option><option>LOW</option></select></label>
|
||||
<label>Agent threat category family
|
||||
<select id="a-family"><option value="">any category</option><option value="agent">all agent categories</option>
|
||||
<option value="runtime">runtime</option><option value="control_plane">control plane</option></select></label>
|
||||
<label>SCC config kind
|
||||
<select id="a-kind"><option>muteConfigs</option><option>notificationConfigs</option>
|
||||
<option>bigQueryExports</option></select></label>
|
||||
<button id="a-run" type="button" class="primary">Run</button>
|
||||
<p id="a-error" class="error" role="alert"></p>
|
||||
<pre id="a-out" class="out"></pre>
|
||||
@@ -354,6 +364,12 @@ void register_agent_armor_demo(fw::Router& router, Services& services) {
|
||||
q.severity = field(in, "severity");
|
||||
q.state = field(in, "state");
|
||||
if (!field(in, "category").empty()) q.categories = {field(in, "category")};
|
||||
// family selects the documented Agent Platform Threat Detection categories.
|
||||
std::string family = field(in, "family");
|
||||
if (family == "runtime") q.categories = armor::AgentCategories::strings(armor::AgentFamily::kRuntime);
|
||||
else if (family == "control_plane") q.categories = armor::AgentCategories::strings(armor::AgentFamily::kControlPlane);
|
||||
else if (family == "agent") q.categories = armor::AgentCategories::strings();
|
||||
else if (!family.empty()) bad("family must be runtime, control_plane or agent");
|
||||
q.order_by = field(in, "order_by");
|
||||
q.page_size = int_field(in, "page_size", 0, armor::ArmorCaps::kMaxFindingsPageSize);
|
||||
q.max_pages = static_cast<std::size_t>(int_field(in, "max_pages", 1, armor::ArmorCaps::kMaxFindingPages));
|
||||
@@ -378,6 +394,8 @@ void register_agent_armor_demo(fw::Router& router, Services& services) {
|
||||
Json o = Json::object();
|
||||
o.set("findings", items);
|
||||
o.set("truncated", page.truncated);
|
||||
o.set("count", static_cast<long>(page.findings.size()));
|
||||
o.set("cap_findings", static_cast<long>(armor::ArmorCaps::kMaxFindings));
|
||||
o.set("total_size", static_cast<long>(page.total_size));
|
||||
return json_out(o);
|
||||
});
|
||||
@@ -393,6 +411,126 @@ void register_agent_armor_demo(fw::Router& router, Services& services) {
|
||||
return json_out(dash.summarize(q).to_json());
|
||||
});
|
||||
});
|
||||
|
||||
// ---- Documented Agent Threat Detection categories (no credential needed).
|
||||
router.get("/agent/armor/categories", "agent-armor-categories", [](fw::Request req) {
|
||||
(void)req;
|
||||
Json arr = Json::array();
|
||||
for (const armor::AgentCategory& c : armor::AgentCategories::all()) {
|
||||
Json o = Json::object();
|
||||
o.set("category", c.category);
|
||||
o.set("alt", c.alt);
|
||||
o.set("module", c.module);
|
||||
o.set("family", c.family == armor::AgentFamily::kRuntime ? "runtime" : "control_plane");
|
||||
arr.push(o);
|
||||
}
|
||||
Json o = Json::object();
|
||||
o.set("count", static_cast<long>(arr.as_array().size()));
|
||||
o.set("anomaly_detection", "no documented category string; recognised by the agentAnomaly member");
|
||||
o.set("categories", arr);
|
||||
return json_out(o);
|
||||
});
|
||||
|
||||
// ---- Security Command Center administration (SecurityAdmin).
|
||||
auto kind_of = [](const Form& in) {
|
||||
std::string k = field(in, "kind");
|
||||
if (k == "muteConfigs") return armor::SccCollection::kMuteConfigs;
|
||||
if (k == "notificationConfigs") return armor::SccCollection::kNotificationConfigs;
|
||||
if (k == "bigQueryExports") return armor::SccCollection::kBigQueryExports;
|
||||
bad("kind must be muteConfigs, notificationConfigs or bigQueryExports");
|
||||
};
|
||||
|
||||
router.post("/agent/armor/scc/availability", "agent-armor-scc-availability", [client](fw::Request req) {
|
||||
Form in = fw::parse_json_object_flat(req.body);
|
||||
std::string scope = field(in, "scope");
|
||||
if (scope.empty()) {
|
||||
google::CloudContext ctx = google::CloudContext::from_env();
|
||||
if (!ctx.project.empty()) scope = "projects/" + ctx.project;
|
||||
}
|
||||
return guarded([&] {
|
||||
Json o = Json::object();
|
||||
o.set("scope", scope);
|
||||
o.set("state", armor::availability_name(armor::SecurityAdmin(client).availability(scope)));
|
||||
return json_out(o);
|
||||
});
|
||||
});
|
||||
|
||||
router.post("/agent/armor/scc/configs/list", "agent-armor-scc-configs-list", [client, kind_of](fw::Request req) {
|
||||
Form in = fw::parse_json_object_flat(req.body);
|
||||
armor::SccCollection kind = kind_of(in);
|
||||
std::string parent = field(in, "parent");
|
||||
return guarded([&] { return json_out(armor::SecurityAdmin(client).list_configs(kind, parent).to_json()); });
|
||||
});
|
||||
|
||||
router.post("/agent/armor/scc/configs/get", "agent-armor-scc-configs-get", [client, kind_of](fw::Request req) {
|
||||
Form in = fw::parse_json_object_flat(req.body);
|
||||
armor::SccCollection kind = kind_of(in);
|
||||
std::string name = field(in, "name");
|
||||
return guarded([&] { return json_out(armor::SecurityAdmin(client).get_config(kind, name)); });
|
||||
});
|
||||
|
||||
// Destructive and explicit: one config, DELETE only.
|
||||
router.del("/agent/armor/scc/configs", "agent-armor-scc-configs-delete", [client](fw::Request req) {
|
||||
Form in = {{"kind", req.query_or("kind", "")}};
|
||||
armor::SccCollection kind;
|
||||
if (in["kind"] == "muteConfigs") kind = armor::SccCollection::kMuteConfigs;
|
||||
else if (in["kind"] == "notificationConfigs") kind = armor::SccCollection::kNotificationConfigs;
|
||||
else if (in["kind"] == "bigQueryExports") kind = armor::SccCollection::kBigQueryExports;
|
||||
else bad("kind must be muteConfigs, notificationConfigs or bigQueryExports");
|
||||
std::string name = req.query_or("name", "");
|
||||
return guarded([&] {
|
||||
armor::SecurityAdmin(client).delete_config(kind, name);
|
||||
Json o = Json::object();
|
||||
o.set("deleted", true);
|
||||
return json_out(o);
|
||||
});
|
||||
});
|
||||
|
||||
router.post("/agent/armor/scc/finding/state", "agent-armor-scc-finding-state", [client](fw::Request req) {
|
||||
Form in = fw::parse_json_object_flat(req.body);
|
||||
std::string state = field(in, "state");
|
||||
if (state != "ACTIVE" && state != "INACTIVE") bad("state must be ACTIVE or INACTIVE");
|
||||
std::string finding = field(in, "finding");
|
||||
return guarded([&] {
|
||||
return json_out(armor::SecurityAdmin(client).set_finding_state(
|
||||
finding, state == "ACTIVE" ? armor::FindingState::kActive : armor::FindingState::kInactive));
|
||||
});
|
||||
});
|
||||
|
||||
router.post("/agent/armor/scc/finding/mute", "agent-armor-scc-finding-mute", [client](fw::Request req) {
|
||||
Form in = fw::parse_json_object_flat(req.body);
|
||||
std::string mute = field(in, "mute");
|
||||
if (mute != "MUTED" && mute != "UNMUTED" && mute != "UNDEFINED") bad("mute must be MUTED, UNMUTED or UNDEFINED");
|
||||
std::string finding = field(in, "finding");
|
||||
return guarded([&] {
|
||||
return json_out(armor::SecurityAdmin(client).set_finding_mute(
|
||||
finding, mute == "MUTED" ? armor::MuteValue::kMuted
|
||||
: mute == "UNMUTED" ? armor::MuteValue::kUnmuted : armor::MuteValue::kUndefined));
|
||||
});
|
||||
});
|
||||
|
||||
// Mass change: needs a filter and confirm=bulk-mute.
|
||||
router.post("/agent/armor/scc/bulk-mute", "agent-armor-scc-bulk-mute", [client](fw::Request req) {
|
||||
Form in = fw::parse_json_object_flat(req.body);
|
||||
if (field(in, "confirm") != "bulk-mute") bad("confirm must be bulk-mute");
|
||||
std::string value = field(in, "value");
|
||||
if (value != "MUTED" && value != "UNDEFINED") bad("value must be MUTED or UNDEFINED");
|
||||
std::string parent = field(in, "parent"), filter = field(in, "filter");
|
||||
return guarded([&] {
|
||||
google::Operation op = armor::SecurityAdmin(client).bulk_mute(
|
||||
parent, filter, value == "MUTED" ? armor::BulkMuteValue::kMuted : armor::BulkMuteValue::kUndefined);
|
||||
Json o = Json::object();
|
||||
o.set("operation", op.name);
|
||||
o.set("done", op.done);
|
||||
return json_out(o);
|
||||
});
|
||||
});
|
||||
|
||||
router.post("/agent/armor/scc/operations/list", "agent-armor-scc-operations", [client](fw::Request req) {
|
||||
Form in = fw::parse_json_object_flat(req.body);
|
||||
std::string org = field(in, "organization");
|
||||
return guarded([&] { return json_out(armor::SecurityAdmin(client).list_operations(org).to_json()); });
|
||||
});
|
||||
}
|
||||
|
||||
} // namespace molo::example::app
|
||||
|
||||
@@ -8,11 +8,13 @@
|
||||
#include "google/optimize/autorater.h"
|
||||
#include "google/optimize/calls.h"
|
||||
#include "google/optimize/clusterer.h"
|
||||
#include "google/optimize/direct_model.h"
|
||||
#include "google/optimize/model_factory.h"
|
||||
#include "google/optimize/eval_requests.h"
|
||||
#include "google/optimize/eval_resources.h"
|
||||
#include "google/optimize/evaluation_api.h"
|
||||
#include "google/optimize/observability.h"
|
||||
#include "google/optimize/operations_api.h"
|
||||
#include "google/optimize/telemetry_writer.h"
|
||||
#include "google/optimize/optimizer.h"
|
||||
#include "google/optimize/simulator.h"
|
||||
|
||||
@@ -131,7 +133,7 @@ void register_agent_optimize_demo(fw::Router& router, Services& services) {
|
||||
services.add_feature("agent optimize", "/agent/optimize");
|
||||
|
||||
auto model_for = [gclient]() {
|
||||
return google::optimize::DirectModel::from_env(gclient);
|
||||
return google::optimize::make_gemini_model(gclient);
|
||||
};
|
||||
|
||||
router.get("/agent/optimize", "agent-optimize-page", [env](fw::Request req) {
|
||||
@@ -287,6 +289,117 @@ void register_agent_optimize_demo(fw::Router& router, Services& services) {
|
||||
});
|
||||
});
|
||||
|
||||
// generateSyntheticData: `request` is the Discovery request object (or its
|
||||
// JSON text); top-level fields are checked against the call table.
|
||||
router.post("/agent/optimize/synthetic", "agent-optimize-synthetic", [gclient](fw::Request req) {
|
||||
Json body = parse_body(req);
|
||||
const Json* r = body.find("request");
|
||||
Json request;
|
||||
if (r && r->is_object()) request = *r;
|
||||
else if (r && r->is_string()) {
|
||||
try { request = Json::parse(r->as_string()); } catch (const clients::body::JsonError&) {}
|
||||
}
|
||||
if (!request.is_object() || request.as_object().empty())
|
||||
throw fw::HttpError(422, "validation_error", "request must be a non-empty JSON object");
|
||||
google::CloudContext ctx = require_context();
|
||||
return guarded([&] { return json_out(opt::EvaluationApi(gclient, ctx).generate_synthetic_data(request)); });
|
||||
});
|
||||
|
||||
// Operations of online evaluators (get, list, server-side wait, cancel;
|
||||
// delete is a DELETE route and removes the operation record only).
|
||||
auto op_json = [](const google::Operation& op) {
|
||||
Json o = Json::object();
|
||||
o.set("name", Json(op.name));
|
||||
o.set("done", Json(op.done));
|
||||
if (op.failed()) o.set("error_message", Json(op.error_message));
|
||||
return o;
|
||||
};
|
||||
router.post("/agent/optimize/operations/list", "agent-optimize-ops-list", [gclient, op_json](fw::Request req) {
|
||||
Json body = parse_body(req);
|
||||
std::string evaluator = text_field(body, "evaluator", true, 512);
|
||||
int limit = int_field(body, "limit", 20, 1, 100);
|
||||
google::CloudContext ctx = require_context();
|
||||
return guarded([&] {
|
||||
opt::OperationPage page = opt::OnlineEvaluatorOperations(gclient, ctx).list(evaluator, "", limit);
|
||||
Json arr = Json::array();
|
||||
for (const google::Operation& op : page.operations) arr.push(op_json(op));
|
||||
Json out = Json::object();
|
||||
out.set("operations", arr);
|
||||
out.set("count", Json(static_cast<int>(page.operations.size())));
|
||||
out.set("truncated", Json(page.truncated));
|
||||
out.set("next_page_token", Json(page.next_page_token));
|
||||
return json_out(out);
|
||||
});
|
||||
});
|
||||
router.post("/agent/optimize/operations/get", "agent-optimize-ops-get", [gclient](fw::Request req) {
|
||||
Json body = parse_body(req);
|
||||
std::string name = text_field(body, "name", true, 512);
|
||||
google::CloudContext ctx = require_context();
|
||||
return guarded([&] { return json_out(opt::OnlineEvaluatorOperations(gclient, ctx).get(name)); });
|
||||
});
|
||||
router.post("/agent/optimize/operations/wait", "agent-optimize-ops-wait", [gclient, op_json](fw::Request req) {
|
||||
Json body = parse_body(req);
|
||||
std::string name = text_field(body, "name", true, 512);
|
||||
int seconds = int_field(body, "timeout_seconds", 30, 1, opt::OptimizeCaps::kMaxServerWaitSeconds);
|
||||
google::CloudContext ctx = require_context();
|
||||
return guarded([&] {
|
||||
return json_out(op_json(opt::OnlineEvaluatorOperations(gclient, ctx).wait_server(name, seconds)));
|
||||
});
|
||||
});
|
||||
router.post("/agent/optimize/operations/cancel", "agent-optimize-ops-cancel", [gclient](fw::Request req) {
|
||||
Json body = parse_body(req);
|
||||
std::string name = text_field(body, "name", true, 512);
|
||||
google::CloudContext ctx = require_context();
|
||||
return guarded([&] {
|
||||
opt::OnlineEvaluatorOperations(gclient, ctx).cancel(name);
|
||||
Json out = Json::object();
|
||||
out.set("cancel_requested", Json(true));
|
||||
return json_out(out);
|
||||
});
|
||||
});
|
||||
router.del("/agent/optimize/operations", "agent-optimize-ops-delete", [gclient](fw::Request req) {
|
||||
std::string name = req.query_or("name", "");
|
||||
if (name.empty() || !opt::OnlineEvaluatorOperations::is_operation_name(name))
|
||||
throw fw::HttpError(422, "validation_error", "name must be an online evaluator operation name");
|
||||
google::CloudContext ctx = require_context();
|
||||
return guarded([&] {
|
||||
opt::OnlineEvaluatorOperations(gclient, ctx).remove(name);
|
||||
Json out = Json::object();
|
||||
out.set("deleted", Json(true));
|
||||
return json_out(out);
|
||||
});
|
||||
});
|
||||
|
||||
// entries:write. A dry run (nothing stored) unless confirm is "write".
|
||||
router.post("/agent/optimize/logs/write", "agent-optimize-logs-write", [gclient](fw::Request req) {
|
||||
Json body = parse_body(req);
|
||||
std::string log_id = text_field(body, "log_id", true, 100);
|
||||
std::string text = text_field(body, "text", true, 4000);
|
||||
std::string confirm = text_field(body, "confirm", false, 16);
|
||||
if (!google::valid_segment(log_id))
|
||||
throw fw::HttpError(422, "validation_error", "log_id has invalid characters");
|
||||
google::CloudContext ctx = require_context();
|
||||
bool real = confirm == "write";
|
||||
Json entry = Json::object();
|
||||
entry.set("textPayload", Json(text));
|
||||
Json entries = Json::array();
|
||||
entries.push(entry);
|
||||
Json resource = Json::object();
|
||||
resource.set("type", Json("global"));
|
||||
Json request = Json::object();
|
||||
request.set("logName", Json("projects/" + ctx.project + "/logs/" + log_id));
|
||||
request.set("resource", resource);
|
||||
request.set("entries", entries);
|
||||
request.set("dryRun", Json(!real));
|
||||
return guarded([&] {
|
||||
opt::LogWriter(gclient).write(request);
|
||||
Json out = Json::object();
|
||||
out.set("dry_run", Json(!real));
|
||||
out.set("written", Json(real));
|
||||
return json_out(out);
|
||||
});
|
||||
});
|
||||
|
||||
// Local autorater over a pasted transcript ("user: ..." / "agent: ...").
|
||||
router.post("/agent/optimize/score", "agent-optimize-score", [model_for](fw::Request req) {
|
||||
Json body = parse_body(req);
|
||||
|
||||
@@ -53,6 +53,19 @@ fw::Response json_reply(const Json& j, int status = 200) {
|
||||
return res;
|
||||
}
|
||||
|
||||
// A list answer. Truncation is part of the answer, never hidden: `truncated`
|
||||
// is true when more existed past the stated cap, `cap_items` names the cap.
|
||||
Json list_answer(const reg::ListResult& list, const char* items_key) {
|
||||
Json j = Json::object();
|
||||
j.set("count", Json(static_cast<int>(list.size())));
|
||||
j.set("pages", Json(static_cast<int>(list.pages)));
|
||||
j.set("truncated", Json(list.truncated));
|
||||
j.set("next_page_token", Json(list.next_page_token));
|
||||
j.set("cap_items", Json(static_cast<int>(reg::RegistryCaps::kMaxItems)));
|
||||
j.set(items_key, list.items);
|
||||
return j;
|
||||
}
|
||||
|
||||
std::string field(std::map<std::string, std::string>& in, const char* key) {
|
||||
auto it = in.find(key);
|
||||
return it == in.end() ? "" : it->second;
|
||||
@@ -87,7 +100,9 @@ class RegistryDemo {
|
||||
void require_credential() const {
|
||||
if (!configured()) throw google::NotConfiguredError("registry");
|
||||
}
|
||||
reg::AgentRegistry registry() const { return reg::AgentRegistry(client_, ready()); }
|
||||
reg::AgentRegistry registry(reg::RegistryVersion v = reg::RegistryVersion::kV1) const {
|
||||
return reg::AgentRegistry(client_, ready(), v);
|
||||
}
|
||||
reg::AgentGateway gateway() const { return reg::AgentGateway(client_, ready()); }
|
||||
reg::GatewayPolicies policies() const { return reg::GatewayPolicies(client_, ready()); }
|
||||
reg::AgentIdentity identity() const { return reg::AgentIdentity(client_, ready()); }
|
||||
@@ -122,6 +137,11 @@ here is a local list: the registry API has no approve method.</p>
|
||||
<option value="skills">Skills</option>
|
||||
<option value="bindings">Bindings</option>
|
||||
</select></label>
|
||||
<label class="inline">API version
|
||||
<select id="r-version">
|
||||
<option value="v1">v1</option>
|
||||
<option value="v1alpha">v1alpha</option>
|
||||
</select></label>
|
||||
<input id="r-q" type="text" maxlength="200" placeholder="Search text or asset id" autocomplete="off">
|
||||
<div class="registry-actions">
|
||||
<button id="r-list" type="button" class="primary">List</button>
|
||||
@@ -133,10 +153,14 @@ here is a local list: the registry API has no approve method.</p>
|
||||
<option value="gateways">Agent gateways</option>
|
||||
<option value="policies">Gateway policies</option>
|
||||
<option value="identity">Agent identity (engine id)</option>
|
||||
<option value="ops-registry">Operations: registry</option>
|
||||
<option value="ops-gateways">Operations: gateways</option>
|
||||
<option value="ops-policies">Operations: policies</option>
|
||||
<option value="approvals">Approvals (local)</option>
|
||||
<option value="audit">Approval audit (local)</option>
|
||||
</select></label>
|
||||
<button id="r-gov-go" type="button">Show</button>
|
||||
<p id="r-truncated" class="error" role="status" hidden></p>
|
||||
<p id="r-error" class="error" role="alert"></p>
|
||||
<pre id="r-out" class="scroll"></pre>
|
||||
</section>
|
||||
@@ -169,6 +193,7 @@ void register_agent_registry_demo(fw::Router& router, Services& services) {
|
||||
Json caps = Json::object();
|
||||
caps.set("page_size", Json(reg::RegistryCaps::kPageSize));
|
||||
caps.set("max_pages", Json(static_cast<int>(reg::RegistryCaps::kMaxPages)));
|
||||
caps.set("max_items", Json(static_cast<int>(reg::RegistryCaps::kMaxItems)));
|
||||
caps.set("max_ledger_entries", Json(static_cast<int>(reg::RegistryCaps::kMaxLedgerEntries)));
|
||||
caps.set("max_audit_entries", Json(static_cast<int>(reg::RegistryCaps::kMaxAuditEntries)));
|
||||
j.set("caps", caps);
|
||||
@@ -259,15 +284,17 @@ void register_agent_registry_demo(fw::Router& router, Services& services) {
|
||||
reg::AssetKind::kSkills, reg::AssetKind::kBindings,
|
||||
reg::AssetKind::kPublishers});
|
||||
bool approved_only = field(in, "approved_only") == "true";
|
||||
std::string version = field(in, "version");
|
||||
if (!version.empty() && version != "v1" && version != "v1alpha") bad("version must be v1 or v1alpha");
|
||||
return guarded([&] {
|
||||
reg::AgentRegistry registry = demo->registry();
|
||||
Json items = approved_only ? registry.list_approved(kind, demo->ledger())
|
||||
: registry.list(kind);
|
||||
Json j = Json::object();
|
||||
reg::AgentRegistry registry = demo->registry(version == "v1alpha" ? reg::RegistryVersion::kV1Alpha
|
||||
: reg::RegistryVersion::kV1);
|
||||
reg::ListResult list = approved_only ? registry.list_approved(kind, demo->ledger())
|
||||
: registry.list(kind);
|
||||
Json j = list_answer(list, "items");
|
||||
j.set("kind", Json(reg::asset_collection(kind)));
|
||||
j.set("version", Json(registry.version()));
|
||||
j.set("approved_only", Json(approved_only));
|
||||
j.set("count", Json(static_cast<int>(items.as_array().size())));
|
||||
j.set("items", items);
|
||||
return json_reply(j);
|
||||
});
|
||||
});
|
||||
@@ -377,11 +404,7 @@ void register_agent_registry_demo(fw::Router& router, Services& services) {
|
||||
// ---- Gateways and policies (reads, plus an explicit delete).
|
||||
router.post("/agent/registry/gateways/list", "agent-registry-gateways", [demo](fw::Request) {
|
||||
return guarded([&] {
|
||||
Json items = demo->gateway().list();
|
||||
Json j = Json::object();
|
||||
j.set("count", Json(static_cast<int>(items.as_array().size())));
|
||||
j.set("gateways", items);
|
||||
return json_reply(j);
|
||||
return json_reply(list_answer(demo->gateway().list(), "gateways"));
|
||||
});
|
||||
});
|
||||
|
||||
@@ -400,14 +423,92 @@ void register_agent_registry_demo(fw::Router& router, Services& services) {
|
||||
|
||||
router.post("/agent/registry/policies/list", "agent-registry-policies", [demo](fw::Request) {
|
||||
return guarded([&] {
|
||||
Json items = demo->policies().list();
|
||||
Json j = Json::object();
|
||||
j.set("count", Json(static_cast<int>(items.as_array().size())));
|
||||
j.set("policies", items);
|
||||
return json_reply(list_answer(demo->policies().list(), "policies"));
|
||||
});
|
||||
});
|
||||
|
||||
// ---- Operations of the three registry-side hosts. Reads are POST (they
|
||||
// call out); delete is DELETE and explicit (the operation record only).
|
||||
auto scope_of = [](std::map<std::string, std::string>& in) {
|
||||
std::string s = field(in, "scope");
|
||||
if (s != "registry" && s != "gateways" && s != "policies")
|
||||
bad("scope must be registry, gateways or policies");
|
||||
return s;
|
||||
};
|
||||
router.post("/agent/registry/operations/list", "agent-registry-operations", [demo, scope_of](fw::Request req) {
|
||||
auto in = fw::parse_json_object_flat(req.body);
|
||||
std::string scope = scope_of(in);
|
||||
return guarded([&] {
|
||||
reg::ListResult ops = scope == "registry" ? demo->registry().operations()
|
||||
: scope == "gateways" ? demo->gateway().operations()
|
||||
: demo->policies().operations();
|
||||
Json j = list_answer(ops, "operations");
|
||||
j.set("scope", Json(scope));
|
||||
return json_reply(j);
|
||||
});
|
||||
});
|
||||
|
||||
router.post("/agent/registry/operations/cancel", "agent-registry-operation-cancel",
|
||||
[demo, scope_of](fw::Request req) {
|
||||
auto in = fw::parse_json_object_flat(req.body);
|
||||
std::string scope = scope_of(in);
|
||||
std::string id = field(in, "id");
|
||||
if (!google::valid_segment(id)) bad("id is empty or has invalid characters");
|
||||
return guarded([&] {
|
||||
Json r = scope == "registry" ? demo->registry().cancel_operation(id)
|
||||
: scope == "gateways" ? demo->gateway().cancel_operation(id)
|
||||
: demo->policies().cancel_operation(id);
|
||||
Json j = Json::object();
|
||||
j.set("scope", Json(scope));
|
||||
j.set("cancel_requested", Json(true));
|
||||
j.set("reply", r);
|
||||
return json_reply(j);
|
||||
});
|
||||
});
|
||||
|
||||
router.del("/agent/registry/operations", "agent-registry-operation-delete", [demo](fw::Request req) {
|
||||
std::string scope = req.query_or("scope", "");
|
||||
std::string id = req.query_or("id", "");
|
||||
if (scope != "registry" && scope != "gateways" && scope != "policies")
|
||||
bad("scope must be registry, gateways or policies");
|
||||
if (!google::valid_segment(id)) bad("id is empty or has invalid characters");
|
||||
return guarded([&] {
|
||||
Json r = scope == "registry" ? demo->registry().delete_operation(id)
|
||||
: scope == "gateways" ? demo->gateway().delete_operation(id)
|
||||
: demo->policies().delete_operation(id);
|
||||
Json j = Json::object();
|
||||
j.set("deleted", Json(true));
|
||||
j.set("reply", r);
|
||||
return json_reply(j);
|
||||
});
|
||||
});
|
||||
|
||||
// ---- IAM deny policies (iam v2) and boundary bindings (iam v3).
|
||||
router.post("/agent/registry/deny-policies/list", "agent-registry-deny-policies", [demo](fw::Request req) {
|
||||
auto in = fw::parse_json_object_flat(req.body);
|
||||
std::string number = field(in, "project_number");
|
||||
if (number.empty() || number.size() > 20 || number.find_first_not_of("0123456789") != std::string::npos)
|
||||
bad("project_number must be numeric");
|
||||
return guarded([&] {
|
||||
return json_reply(list_answer(
|
||||
demo->identity().deny_policies(reg::AgentIdentity::attachment_for_project(number)),
|
||||
"policies"));
|
||||
});
|
||||
});
|
||||
|
||||
router.post("/agent/registry/boundaries/bindings", "agent-registry-boundary-bindings",
|
||||
[demo](fw::Request req) {
|
||||
auto in = fw::parse_json_object_flat(req.body);
|
||||
std::string org = field(in, "org_id");
|
||||
std::string id = field(in, "id");
|
||||
if (org.empty() || org.size() > 20 || org.find_first_not_of("0123456789") != std::string::npos)
|
||||
bad("org_id must be numeric");
|
||||
if (!google::valid_segment(id)) bad("id is empty or has invalid characters");
|
||||
return guarded([&] {
|
||||
return json_reply(list_answer(demo->identity().boundary_bindings(org, id), "bindings"));
|
||||
});
|
||||
});
|
||||
|
||||
// ---- Identity of one deployed agent (engine id).
|
||||
router.post("/agent/registry/identity", "agent-registry-identity", [demo](fw::Request req) {
|
||||
auto in = fw::parse_json_object_flat(req.body);
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
#include "google/sessions/caps.h"
|
||||
#include "google/sessions/calls.h"
|
||||
#include "google/sessions/memory_bank.h"
|
||||
#include "google/sessions/serving_profile.h"
|
||||
#include "google/sessions/sessions.h"
|
||||
|
||||
namespace molo::example::app {
|
||||
@@ -52,6 +53,15 @@ Every call below is a JSON POST (or DELETE) and answers 503
|
||||
<tr><td>DELETE /agent/sessions/memories/memory</td><td>query: engine, id</td></tr>
|
||||
<tr><td>POST /agent/sessions/memories/profiles</td><td>engine, scope_key, scope_value</td></tr>
|
||||
<tr><td>POST /agent/sessions/memories/purge</td><td>engine, filter, force?, confirm? (dry run by default)</td></tr>
|
||||
<tr><td>POST /agent/sessions/operations/list</td><td>engine, parent? (engine, session or memory name), filter?</td></tr>
|
||||
<tr><td>POST /agent/sessions/operations/get</td><td>engine, name</td></tr>
|
||||
<tr><td>POST /agent/sessions/operations/wait</td><td>engine, name, timeout_seconds (server-side wait, 1..60)</td></tr>
|
||||
<tr><td>POST /agent/sessions/operations/cancel</td><td>engine, name</td></tr>
|
||||
<tr><td>DELETE /agent/sessions/operations/operation</td><td>query: engine, name</td></tr>
|
||||
<tr><td>POST /agent/sessions/serving-profiles/list</td><td>location? (id or projects/P/locations/L)</td></tr>
|
||||
<tr><td>POST /agent/sessions/serving-profiles/get</td><td>location?, profile_id</td></tr>
|
||||
<tr><td>POST /agent/sessions/serving-profiles/create</td><td>location?, profile_id, display_name, scope, description?</td></tr>
|
||||
<tr><td>DELETE /agent/sessions/serving-profiles/profile</td><td>query: location?, id</td></tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
@@ -106,6 +116,29 @@ class SessionsRoutes {
|
||||
return gs::MemoryBank(client_, engine_of(engine));
|
||||
}
|
||||
|
||||
// A full "projects/P/locations/L" name, or a location id (project from
|
||||
// GOOGLE_CLOUD_PROJECT, empty: GOOGLE_CLOUD_LOCATION or us-central1).
|
||||
gs::LocationName location_of(const std::string& value) const {
|
||||
if (value.rfind("projects/", 0) == 0) return gs::LocationName(value);
|
||||
google::CloudContext ctx = google::CloudContext::from_env();
|
||||
if (!value.empty()) ctx.location = value;
|
||||
return gs::LocationName(ctx.parent());
|
||||
}
|
||||
gs::ServingProfiles profiles(const std::string& location) const {
|
||||
return gs::ServingProfiles(client_, location_of(location));
|
||||
}
|
||||
|
||||
static GJson operation_json(const google::Operation& op) {
|
||||
GJson o = GJson::object();
|
||||
o.set("name", GJson(op.name));
|
||||
o.set("done", GJson(op.done));
|
||||
if (op.failed()) {
|
||||
o.set("error_code", GJson(op.error_code));
|
||||
o.set("error_message", GJson(op.error_message));
|
||||
}
|
||||
return o;
|
||||
}
|
||||
|
||||
static gs::StringMap scope_of(const Flat& in) {
|
||||
gs::StringMap scope;
|
||||
if (!field(in, "scope_key").empty() || !field(in, "scope_value").empty())
|
||||
@@ -147,6 +180,8 @@ void register_agent_sessions_demo(fw::Router& router, Services& services) {
|
||||
caps.set("max_session_id_chars", GJson(static_cast<int>(gs::SessionsCaps::kMaxIdChars)));
|
||||
caps.set("max_list_items", GJson(static_cast<int>(gs::SessionsCaps::kMaxListItems)));
|
||||
caps.set("max_top_k", GJson(gs::MemoryCaps::kMaxTopK));
|
||||
caps.set("max_server_wait_seconds",
|
||||
GJson(static_cast<int>(gs::SessionsCaps::kMaxServerWaitSeconds)));
|
||||
caps.set("max_fact_chars", GJson(static_cast<int>(gs::MemoryCaps::kMaxFactChars)));
|
||||
out.set("caps", caps);
|
||||
return answer(out);
|
||||
@@ -355,6 +390,113 @@ void register_agent_sessions_demo(fw::Router& router, Services& services) {
|
||||
return answer(out);
|
||||
});
|
||||
});
|
||||
|
||||
// Operations (engine, session, memory) -----------------------------------
|
||||
|
||||
router.post("/agent/sessions/operations/list", "agent-sessions-operations-list",
|
||||
[routes](fw::Request req) {
|
||||
Flat in = fw::parse_json_object_flat(req.body);
|
||||
return guarded([&] {
|
||||
gs::OperationListOptions options;
|
||||
options.filter = field(in, "filter");
|
||||
GJson arr = GJson::array();
|
||||
for (const google::Operation& op :
|
||||
routes->sessions(field(in, "engine")).list_operations(field(in, "parent"), options))
|
||||
arr.push(SessionsRoutes::operation_json(op));
|
||||
GJson out = GJson::object();
|
||||
out.set("operations", arr);
|
||||
return answer(out);
|
||||
});
|
||||
});
|
||||
|
||||
router.post("/agent/sessions/operations/get", "agent-sessions-operations-get",
|
||||
[routes](fw::Request req) {
|
||||
Flat in = fw::parse_json_object_flat(req.body);
|
||||
return guarded([&] {
|
||||
return answer(routes->sessions(field(in, "engine")).operation(field(in, "name")));
|
||||
});
|
||||
});
|
||||
|
||||
// One server-side wait (POST :wait); done=false when the timeout passed first.
|
||||
router.post("/agent/sessions/operations/wait", "agent-sessions-operations-wait",
|
||||
[routes](fw::Request req) {
|
||||
Flat in = fw::parse_json_object_flat(req.body);
|
||||
return guarded([&] {
|
||||
int seconds = field(in, "timeout_seconds").empty()
|
||||
? 30
|
||||
: std::atoi(field(in, "timeout_seconds").c_str());
|
||||
return answer(SessionsRoutes::operation_json(
|
||||
routes->sessions(field(in, "engine")).wait_server(field(in, "name"), seconds)));
|
||||
});
|
||||
});
|
||||
|
||||
router.post("/agent/sessions/operations/cancel", "agent-sessions-operations-cancel",
|
||||
[routes](fw::Request req) {
|
||||
Flat in = fw::parse_json_object_flat(req.body);
|
||||
return guarded([&] {
|
||||
routes->sessions(field(in, "engine")).cancel_operation(field(in, "name"));
|
||||
GJson out = GJson::object();
|
||||
out.set("cancel_requested", GJson(true));
|
||||
return answer(out);
|
||||
});
|
||||
});
|
||||
|
||||
router.del("/agent/sessions/operations/operation", "agent-sessions-operations-delete",
|
||||
[routes](fw::Request req) {
|
||||
return guarded([&] {
|
||||
routes->sessions(req.query_or("engine", "")).delete_operation(req.query_or("name", ""));
|
||||
GJson out = GJson::object();
|
||||
out.set("deleted", GJson(true));
|
||||
return answer(out);
|
||||
});
|
||||
});
|
||||
|
||||
// Serving profiles (location level) ---------------------------------------
|
||||
|
||||
router.post("/agent/sessions/serving-profiles/list", "agent-serving-profiles-list",
|
||||
[routes](fw::Request req) {
|
||||
Flat in = fw::parse_json_object_flat(req.body);
|
||||
return guarded([&] {
|
||||
GJson arr = GJson::array();
|
||||
for (const gs::ServingProfile& p : routes->profiles(field(in, "location")).list())
|
||||
arr.push(p.to_json());
|
||||
GJson out = GJson::object();
|
||||
out.set("serving_profiles", arr);
|
||||
return answer(out);
|
||||
});
|
||||
});
|
||||
|
||||
router.post("/agent/sessions/serving-profiles/get", "agent-serving-profiles-get",
|
||||
[routes](fw::Request req) {
|
||||
Flat in = fw::parse_json_object_flat(req.body);
|
||||
return guarded([&] {
|
||||
return answer(
|
||||
routes->profiles(field(in, "location")).get(field(in, "profile_id")).to_json());
|
||||
});
|
||||
});
|
||||
|
||||
router.post("/agent/sessions/serving-profiles/create", "agent-serving-profiles-create",
|
||||
[routes](fw::Request req) {
|
||||
Flat in = fw::parse_json_object_flat(req.body);
|
||||
return guarded([&] {
|
||||
gs::ServingProfileSpec spec;
|
||||
spec.profile_id = field(in, "profile_id");
|
||||
spec.display_name = field(in, "display_name");
|
||||
spec.description = field(in, "description");
|
||||
spec.scope = gs::serving_scope_from(field(in, "scope"));
|
||||
return answer(routes->profiles(field(in, "location")).create(spec).to_json(), 201);
|
||||
});
|
||||
});
|
||||
|
||||
router.del("/agent/sessions/serving-profiles/profile", "agent-serving-profiles-delete",
|
||||
[routes](fw::Request req) {
|
||||
return guarded([&] {
|
||||
routes->profiles(req.query_or("location", "")).remove(req.query_or("id", ""));
|
||||
GJson out = GJson::object();
|
||||
out.set("deleted", GJson(true));
|
||||
return answer(out);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
} // namespace molo::example::app
|
||||
|
||||
@@ -16,13 +16,15 @@
|
||||
"templates/create": ["a-template"],
|
||||
"templates/delete": ["a-template"],
|
||||
"floor/get": ["a-scope"],
|
||||
"findings": ["a-scope", "a-severity"],
|
||||
"dashboard": ["a-scope", "a-severity"]
|
||||
"findings": ["a-scope", "a-severity", "a-family"],
|
||||
"dashboard": ["a-scope", "a-severity", "a-family"],
|
||||
"scc/availability": ["a-scope"],
|
||||
"scc/configs/list": ["a-scope", "a-kind"]
|
||||
};
|
||||
|
||||
function sync() {
|
||||
var shown = uses[action.value] || [];
|
||||
["a-template", "a-text", "a-scope", "a-severity"].forEach(function (id) {
|
||||
["a-template", "a-text", "a-scope", "a-severity", "a-family", "a-kind"].forEach(function (id) {
|
||||
$(id).parentNode.style.display = shown.indexOf(id) >= 0 ? "" : "none";
|
||||
});
|
||||
}
|
||||
@@ -34,6 +36,8 @@
|
||||
if (text.value) b.text = text.value;
|
||||
if (scope.value) b.scope = scope.value;
|
||||
if (severity.value) b.severity = severity.value;
|
||||
if ($("a-family").value) b.family = $("a-family").value;
|
||||
if (a === "scc/configs/list") { b.kind = $("a-kind").value; b.parent = scope.value; delete b.scope; }
|
||||
if (a === "templates/create") {
|
||||
b.pi = "MEDIUM_AND_ABOVE";
|
||||
b.malicious_uri = "true";
|
||||
|
||||
@@ -17,6 +17,15 @@
|
||||
fields: [["agent_instruction", "area"], ["instruction", "text"], ["count", "text:5"]] },
|
||||
runs: { help: "List evaluation runs (needs OAuth).", fields: [["limit", "text:10"]] },
|
||||
traces: { help: "Cloud Trace summary (needs OAuth).", fields: [["limit", "text:20"], ["filter", "text"]] },
|
||||
synthetic: { help: "generateSyntheticData: paste the request JSON (needs OAuth).",
|
||||
fields: [["request", "area:{ ... }"]] },
|
||||
"operations/list": { help: "Operations of an online evaluator (needs OAuth).",
|
||||
fields: [["evaluator", "text:projects/P/locations/L/onlineEvaluators/ID"], ["limit", "text:20"]] },
|
||||
"operations/get": { help: "One online evaluator operation.", fields: [["name", "text"]] },
|
||||
"operations/wait": { help: "Server-side wait, 1..60 seconds.",
|
||||
fields: [["name", "text"], ["timeout_seconds", "text:30"]] },
|
||||
"logs/write": { help: "Write one log entry. Dry run unless confirm is write.",
|
||||
fields: [["log_id", "text:agent-check"], ["text", "text"], ["confirm", "text"]] },
|
||||
logs: { help: "Cloud Logging entries (needs OAuth).", fields: [["limit", "text:20"], ["trace_id", "text"], ["filter", "text"]] }
|
||||
};
|
||||
var $ = function (id) { return document.getElementById(id); };
|
||||
|
||||
@@ -28,13 +28,25 @@
|
||||
function get(path) {
|
||||
return fetch(path).then(function (res) { return res.json(); });
|
||||
}
|
||||
// A list that hit its cap says so loudly; it is never presented as complete.
|
||||
function banner(j) {
|
||||
var el = $("r-truncated");
|
||||
if (j && j.truncated === true) {
|
||||
el.textContent = "TRUNCATED: showing " + j.count + " of more than " + j.cap_items +
|
||||
" items (" + j.pages + " pages). Narrow the query or continue from the page token.";
|
||||
el.hidden = false;
|
||||
} else {
|
||||
el.hidden = true;
|
||||
el.textContent = "";
|
||||
}
|
||||
}
|
||||
function run(promise) {
|
||||
promise.then(function (j) { show(JSON.stringify(j, null, 2), false); })
|
||||
promise.then(function (j) { banner(j); show(JSON.stringify(j, null, 2), false); })
|
||||
.catch(function (e) { show(e.message, true); });
|
||||
}
|
||||
|
||||
$("r-list").addEventListener("click", function () {
|
||||
run(post("/agent/registry/list", { kind: $("r-kind").value }));
|
||||
run(post("/agent/registry/list", { kind: $("r-kind").value, version: $("r-version").value }));
|
||||
});
|
||||
$("r-search").addEventListener("click", function () {
|
||||
run(post("/agent/registry/search", { kind: $("r-kind").value, q: $("r-q").value }));
|
||||
@@ -47,6 +59,8 @@
|
||||
if (which === "gateways") run(post("/agent/registry/gateways/list"));
|
||||
else if (which === "policies") run(post("/agent/registry/policies/list"));
|
||||
else if (which === "identity") run(post("/agent/registry/identity", { engine_id: $("r-q").value }));
|
||||
else if (which.indexOf("ops-") === 0)
|
||||
run(post("/agent/registry/operations/list", { scope: which.substring(4) }));
|
||||
else if (which === "approvals") run(get("/agent/registry/approvals"));
|
||||
else run(get("/agent/registry/audit"));
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user