Merge registry module (Agent Registry, Gateway, Identity)
This commit is contained in:
@@ -0,0 +1,59 @@
|
||||
// Agent registry page: thin client over /agent/registry/*. Every Google call
|
||||
// is a POST; the status route says whether a credential is configured.
|
||||
(function () {
|
||||
"use strict";
|
||||
var $ = function (id) { return document.getElementById(id); };
|
||||
var out = $("r-out"), err = $("r-error");
|
||||
|
||||
function show(text, isError) {
|
||||
(isError ? err : out).textContent = text;
|
||||
if (isError) out.textContent = ""; else err.textContent = "";
|
||||
}
|
||||
function post(path, body) {
|
||||
return fetch(path, {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify(body || {})
|
||||
}).then(function (res) {
|
||||
return res.text().then(function (text) {
|
||||
if (!res.ok) {
|
||||
var msg = "HTTP " + res.status;
|
||||
try { var j = JSON.parse(text); msg = (j.error || "") + ": " + (j.message || msg); } catch (e) {}
|
||||
throw new Error(msg);
|
||||
}
|
||||
return JSON.parse(text);
|
||||
});
|
||||
});
|
||||
}
|
||||
function get(path) {
|
||||
return fetch(path).then(function (res) { return res.json(); });
|
||||
}
|
||||
function run(promise) {
|
||||
promise.then(function (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 }));
|
||||
});
|
||||
$("r-search").addEventListener("click", function () {
|
||||
run(post("/agent/registry/search", { kind: $("r-kind").value, q: $("r-q").value }));
|
||||
});
|
||||
$("r-get").addEventListener("click", function () {
|
||||
run(post("/agent/registry/get", { kind: $("r-kind").value, id: $("r-q").value }));
|
||||
});
|
||||
$("r-gov-go").addEventListener("click", function () {
|
||||
var which = $("r-gov").value;
|
||||
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 === "approvals") run(get("/agent/registry/approvals"));
|
||||
else run(get("/agent/registry/audit"));
|
||||
});
|
||||
|
||||
get("/agent/registry/status").then(function (s) {
|
||||
$("r-config").textContent = s.configured && s.project_set
|
||||
? "Google credential and project are set."
|
||||
: "Not configured: set a Google credential and GOOGLE_CLOUD_PROJECT to call Google.";
|
||||
}).catch(function () { $("r-config").textContent = "Status unavailable."; });
|
||||
})();
|
||||
Reference in New Issue
Block a user