82 lines
3.1 KiB
JavaScript
82 lines
3.1 KiB
JavaScript
// Google Cloud operations page: thin client over /google/ops/* (all limits server side).
|
|||
|
|
(function () {
|
||
|
|
"use strict";
|
||
|
|
var $ = function (id) { return document.getElementById(id); };
|
||
|
|
var out = $("go-out"), err = $("go-error");
|
||
|
|
var calls = [];
|
||
|
|
|
||
|
|
function show(res) {
|
||
|
|
return res.text().then(function (t) {
|
||
|
|
var j;
|
||
|
|
try { j = JSON.parse(t); } catch (e) { j = { message: t }; }
|
||
|
|
if (!res.ok) { err.textContent = j.message || ("HTTP " + res.status); out.textContent = ""; }
|
||
|
|
else { out.textContent = JSON.stringify(j, null, 2); }
|
||
|
|
});
|
||
|
|
}
|
||
|
|
function post(path, body) {
|
||
|
|
err.textContent = "";
|
||
|
|
out.textContent = "...";
|
||
|
|
return fetch(path, {
|
||
|
|
method: "POST",
|
||
|
|
headers: { "Content-Type": "application/json" },
|
||
|
|
body: JSON.stringify(body)
|
||
|
|
}).then(show).catch(function (e) { err.textContent = String(e); out.textContent = ""; });
|
||
|
|
}
|
||
|
|
function json(id) {
|
||
|
|
try { return JSON.parse($(id).value || "{}"); }
|
||
|
|
catch (e) { err.textContent = "Field " + id + " is not valid JSON"; return null; }
|
||
|
|
}
|
||
|
|
function project() { return $("go-project").value.trim(); }
|
||
|
|
|
||
|
|
fetch("/google/ops/status").then(function (r) { return r.json(); }).then(function (s) {
|
||
|
|
$("go-config").textContent = s.configured
|
||
|
|
? "Google credential found. " + s.calls + " calls in " + s.products + " products."
|
||
|
|
: "No Google credential: calls answer 503 until one is configured.";
|
||
|
|
});
|
||
|
|
|
||
|
|
function fillRpcs() {
|
||
|
|
var p = $("go-product").value, sel = $("go-rpc");
|
||
|
|
sel.innerHTML = "";
|
||
|
|
calls.filter(function (c) { return c.rpc.split(".")[0] === p; }).forEach(function (c) {
|
||
|
|
var o = document.createElement("option");
|
||
|
|
o.value = c.rpc;
|
||
|
|
o.textContent = c.rpc.substring(p.length + 1) + " [" + c.safety + "]";
|
||
|
|
sel.appendChild(o);
|
||
|
|
});
|
||
|
|
describe();
|
||
|
|
}
|
||
|
|
function describe() {
|
||
|
|
var c = calls.filter(function (x) { return x.rpc === $("go-rpc").value; })[0];
|
||
|
|
$("go-info").textContent = c ? c.http + " " + c.path + (c.query ? " query: " + c.query : "") +
|
||
|
|
(c.body_fields ? " body: " + c.body_fields : "") : "";
|
||
|
|
}
|
||
|
|
fetch("/google/ops/calls").then(function (r) { return r.json(); }).then(function (d) {
|
||
|
|
calls = d.calls;
|
||
|
|
var sel = $("go-product");
|
||
|
|
d.products.forEach(function (p) {
|
||
|
|
var o = document.createElement("option");
|
||
|
|
o.value = p.name;
|
||
|
|
o.textContent = p.name + " " + p.version;
|
||
|
|
sel.appendChild(o);
|
||
|
|
});
|
||
|
|
fillRpcs();
|
||
|
|
});
|
||
|
|
$("go-product").onchange = fillRpcs;
|
||
|
|
$("go-rpc").onchange = describe;
|
||
|
|
|
||
|
|
$("go-enabled").onclick = function () {
|
||
|
|
post("/google/ops/services", { action: "list", state: "ENABLED", project: project() });
|
||
|
|
};
|
||
|
|
$("go-iam").onclick = function () {
|
||
|
|
post("/google/ops/services", { action: "get", api: "iam.googleapis.com", project: project() });
|
||
|
|
};
|
||
|
|
$("go-send").onclick = function () {
|
||
|
|
var path = json("go-path"), query = json("go-query"), body = json("go-body");
|
||
|
|
if (path === null || query === null || body === null) return;
|
||
|
|
post("/google/ops/call", {
|
||
|
|
rpc: $("go-rpc").value, path: path, query: query, body: body,
|
||
|
|
confirm: $("go-confirm").checked
|
||
|
|
});
|
||
|
|
};
|
||
|
|
})();
|