671 lines
19 KiB
HTML
671 lines
19 KiB
HTML
<!doctype html>
|
|
<html lang="ru">
|
|
<head>
|
|
<meta charset="utf-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
<title>NUBES Fission Console</title>
|
|
<link rel="icon" type="image/png" href="https://terra.k8c.ru/docs/nubes/nubes/2.0.2/30_registry/assets/favicon.png">
|
|
<script>
|
|
if (window.location.protocol !== 'https:' && window.location.hostname !== 'localhost' && window.location.hostname !== '127.0.0.1') {
|
|
window.location.replace('https://' + window.location.host + window.location.pathname + window.location.search + window.location.hash);
|
|
}
|
|
</script>
|
|
<style>
|
|
:root {
|
|
--bg-page: #001120;
|
|
--bg-surface: #001929;
|
|
--bg-navbar: #001c34;
|
|
--border: #0b2d50;
|
|
--accent: #1a7fd4;
|
|
--text-primary: #e2ecf6;
|
|
--text-secondary: #6b8eaa;
|
|
}
|
|
|
|
* { box-sizing: border-box; margin: 0; padding: 0; }
|
|
|
|
body {
|
|
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
|
|
background: var(--bg-page);
|
|
color: var(--text-primary);
|
|
min-height: 100vh;
|
|
}
|
|
|
|
.navbar {
|
|
height: 56px;
|
|
display: flex;
|
|
align-items: center;
|
|
justify-content: space-between;
|
|
padding: 0 20px;
|
|
background: var(--bg-navbar);
|
|
border-bottom: 1px solid var(--border);
|
|
}
|
|
|
|
.title {
|
|
font-weight: 700;
|
|
letter-spacing: .3px;
|
|
}
|
|
|
|
.brand {
|
|
display: flex;
|
|
align-items: center;
|
|
gap: 10px;
|
|
}
|
|
|
|
.brand-mark {
|
|
width: 30px;
|
|
height: 30px;
|
|
border-radius: 8px;
|
|
background: linear-gradient(135deg, #009dff 0%, #0055d4 100%);
|
|
color: #fff;
|
|
display: grid;
|
|
place-items: center;
|
|
font-size: 14px;
|
|
font-weight: 800;
|
|
letter-spacing: .02em;
|
|
box-shadow: 0 6px 18px rgba(0, 125, 255, .35);
|
|
}
|
|
|
|
.brand-text {
|
|
display: flex;
|
|
flex-direction: column;
|
|
line-height: 1.08;
|
|
}
|
|
|
|
.brand-text .nubes {
|
|
font-size: 12px;
|
|
letter-spacing: .22em;
|
|
font-weight: 800;
|
|
color: #8bc7ff;
|
|
}
|
|
|
|
.brand-text .product {
|
|
font-size: 13px;
|
|
font-weight: 700;
|
|
letter-spacing: .04em;
|
|
}
|
|
|
|
.btn {
|
|
background: var(--accent);
|
|
color: #fff;
|
|
border: 0;
|
|
border-radius: 6px;
|
|
padding: 8px 12px;
|
|
cursor: pointer;
|
|
font-size: 13px;
|
|
line-height: 1.2;
|
|
}
|
|
|
|
.btn:disabled {
|
|
opacity: .6;
|
|
cursor: not-allowed;
|
|
}
|
|
|
|
.btn.danger {
|
|
background: #b43232;
|
|
}
|
|
|
|
.btn.ghost {
|
|
background: #0c2b49;
|
|
}
|
|
|
|
.wrap {
|
|
max-width: 1100px;
|
|
margin: 0 auto;
|
|
padding: 20px;
|
|
}
|
|
|
|
.grid {
|
|
display: grid;
|
|
grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
|
|
gap: 12px;
|
|
margin-bottom: 16px;
|
|
}
|
|
|
|
.card {
|
|
background: var(--bg-surface);
|
|
border: 1px solid var(--border);
|
|
border-radius: 8px;
|
|
padding: 14px;
|
|
}
|
|
|
|
.k {
|
|
color: var(--text-secondary);
|
|
font-size: 12px;
|
|
text-transform: uppercase;
|
|
letter-spacing: .06em;
|
|
}
|
|
|
|
.v {
|
|
font-size: 24px;
|
|
font-weight: 700;
|
|
margin-top: 6px;
|
|
}
|
|
|
|
.box {
|
|
background: var(--bg-surface);
|
|
border: 1px solid var(--border);
|
|
border-radius: 8px;
|
|
padding: 14px;
|
|
margin-top: 12px;
|
|
}
|
|
|
|
.toolbar {
|
|
display: flex;
|
|
justify-content: space-between;
|
|
gap: 10px;
|
|
align-items: center;
|
|
margin-bottom: 10px;
|
|
}
|
|
|
|
table {
|
|
width: 100%;
|
|
border-collapse: collapse;
|
|
font-size: 13px;
|
|
margin-top: 8px;
|
|
}
|
|
|
|
th, td {
|
|
text-align: left;
|
|
padding: 8px;
|
|
border-bottom: 1px solid #0b2a48;
|
|
}
|
|
|
|
.hint {
|
|
color: var(--text-secondary);
|
|
font-size: 12px;
|
|
margin-top: 8px;
|
|
}
|
|
|
|
.mono {
|
|
font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
|
|
font-size: 12px;
|
|
}
|
|
|
|
.status {
|
|
margin-top: 10px;
|
|
padding: 9px 10px;
|
|
border-radius: 6px;
|
|
font-size: 13px;
|
|
background: #0c2b49;
|
|
border: 1px solid #1d486d;
|
|
display: none;
|
|
}
|
|
|
|
.status.ok {
|
|
background: #103625;
|
|
border-color: #236843;
|
|
}
|
|
|
|
.status.err {
|
|
background: #411d1d;
|
|
border-color: #7a2f2f;
|
|
}
|
|
|
|
.chip {
|
|
display: inline-block;
|
|
padding: 2px 7px;
|
|
border-radius: 999px;
|
|
border: 1px solid #1d486d;
|
|
background: #0c2b49;
|
|
font-size: 11px;
|
|
margin-right: 4px;
|
|
}
|
|
|
|
.modal {
|
|
position: fixed;
|
|
inset: 0;
|
|
background: rgba(0,0,0,.45);
|
|
display: none;
|
|
align-items: center;
|
|
justify-content: center;
|
|
padding: 16px;
|
|
}
|
|
|
|
.modal.open { display: flex; }
|
|
|
|
.panel {
|
|
width: min(820px, 100%);
|
|
max-height: 90vh;
|
|
overflow: auto;
|
|
background: var(--bg-surface);
|
|
border: 1px solid var(--border);
|
|
border-radius: 10px;
|
|
padding: 16px;
|
|
}
|
|
|
|
.panel h3 {
|
|
margin-bottom: 10px;
|
|
font-size: 16px;
|
|
}
|
|
|
|
.row {
|
|
display: flex;
|
|
gap: 10px;
|
|
margin-bottom: 10px;
|
|
flex-wrap: wrap;
|
|
}
|
|
|
|
.field {
|
|
flex: 1;
|
|
min-width: 180px;
|
|
}
|
|
|
|
label {
|
|
display: block;
|
|
margin-bottom: 4px;
|
|
font-size: 12px;
|
|
color: var(--text-secondary);
|
|
}
|
|
|
|
input, select, textarea {
|
|
width: 100%;
|
|
border: 1px solid #1d486d;
|
|
background: #03192c;
|
|
color: var(--text-primary);
|
|
border-radius: 6px;
|
|
padding: 8px 10px;
|
|
font-size: 13px;
|
|
}
|
|
|
|
textarea {
|
|
min-height: 220px;
|
|
resize: vertical;
|
|
font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
|
|
}
|
|
|
|
.actions {
|
|
display: flex;
|
|
gap: 8px;
|
|
justify-content: flex-end;
|
|
margin-top: 8px;
|
|
flex-wrap: wrap;
|
|
}
|
|
|
|
.nowrap {
|
|
white-space: nowrap;
|
|
}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<div class="navbar">
|
|
<div class="brand">
|
|
<div class="brand-mark">N</div>
|
|
<div class="brand-text">
|
|
<div class="nubes">NUBES</div>
|
|
<div class="product">FISSION CONSOLE</div>
|
|
</div>
|
|
</div>
|
|
<div class="row" style="margin:0;">
|
|
<button class="btn ghost" onclick="reloadAll()">Refresh</button>
|
|
<button class="btn" onclick="openCreate()">+ Create Function</button>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="wrap">
|
|
<div class="grid">
|
|
<div class="card"><div class="k">Environments</div><div id="env-count" class="v">-</div></div>
|
|
<div class="card"><div class="k">Packages</div><div id="pkg-count" class="v">-</div></div>
|
|
<div class="card"><div class="k">Functions</div><div id="fn-count" class="v">-</div></div>
|
|
<div class="card"><div class="k">HTTP Triggers</div><div id="http-count" class="v">-</div></div>
|
|
<div class="card"><div class="k">Time Triggers</div><div id="time-count" class="v">-</div></div>
|
|
</div>
|
|
|
|
<div class="box">
|
|
<div class="toolbar">
|
|
<div style="font-weight:600;">Functions</div>
|
|
<div class="hint">Actions: view, edit code, invoke, delete</div>
|
|
</div>
|
|
<table>
|
|
<thead>
|
|
<tr><th>Name</th><th>Environment</th><th>Package</th><th>Route</th><th>Methods</th><th class="nowrap">Actions</th></tr>
|
|
</thead>
|
|
<tbody id="fn-rows"></tbody>
|
|
</table>
|
|
<div id="status" class="status"></div>
|
|
<div class="hint">Namespace: default. CRUD происходит напрямую через CRD Fission.</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div id="create-modal" class="modal">
|
|
<div class="panel">
|
|
<h3>Create Function</h3>
|
|
<div class="row">
|
|
<div class="field">
|
|
<label>Name</label>
|
|
<input id="c-name" placeholder="demo-fn">
|
|
</div>
|
|
<div class="field">
|
|
<label>Environment</label>
|
|
<select id="c-env"></select>
|
|
</div>
|
|
<div class="field">
|
|
<label>Entrypoint</label>
|
|
<input id="c-entry" value="main.main">
|
|
</div>
|
|
</div>
|
|
<div class="row">
|
|
<div class="field">
|
|
<label>Route</label>
|
|
<input id="c-route" placeholder="/demo-fn">
|
|
</div>
|
|
<div class="field">
|
|
<label>Methods (comma separated)</label>
|
|
<input id="c-methods" value="GET">
|
|
</div>
|
|
</div>
|
|
<div>
|
|
<label>Code</label>
|
|
<textarea id="c-code">def main(ctx):
|
|
return {"ok": True, "msg": "hello from fission console"}
|
|
</textarea>
|
|
</div>
|
|
<div class="actions">
|
|
<button class="btn ghost" onclick="closeCreate()">Cancel</button>
|
|
<button id="c-submit" class="btn" onclick="submitCreate()">Create</button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div id="edit-modal" class="modal">
|
|
<div class="panel">
|
|
<h3 id="e-title">Edit Code</h3>
|
|
<div class="row">
|
|
<div class="field">
|
|
<label>Name</label>
|
|
<input id="e-name" disabled>
|
|
</div>
|
|
<div class="field">
|
|
<label>Environment</label>
|
|
<input id="e-env" disabled>
|
|
</div>
|
|
<div class="field">
|
|
<label>Entrypoint</label>
|
|
<input id="e-entry" disabled>
|
|
</div>
|
|
</div>
|
|
<div>
|
|
<label>Code</label>
|
|
<textarea id="e-code"></textarea>
|
|
</div>
|
|
<div class="actions">
|
|
<button class="btn ghost" onclick="closeEdit()">Cancel</button>
|
|
<button id="e-submit" class="btn" onclick="submitEdit()">Save</button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div id="invoke-modal" class="modal">
|
|
<div class="panel">
|
|
<h3 id="i-title">Invoke</h3>
|
|
<div>
|
|
<label>JSON payload</label>
|
|
<textarea id="i-body">{"name":"world"}</textarea>
|
|
</div>
|
|
<div class="actions">
|
|
<button class="btn ghost" onclick="closeInvoke()">Cancel</button>
|
|
<button id="i-submit" class="btn" onclick="submitInvoke()">Invoke</button>
|
|
</div>
|
|
<div style="margin-top:10px;">
|
|
<label>Response</label>
|
|
<textarea id="i-resp" readonly style="min-height:160px;"></textarea>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<script>
|
|
const API_BASE = window.location.pathname.startsWith('/console') ? '/console/api' : '/api';
|
|
|
|
const S = {
|
|
envs: [],
|
|
fns: [],
|
|
triggers: [],
|
|
currentEdit: null,
|
|
currentInvoke: null
|
|
};
|
|
|
|
async function getJSON(url) {
|
|
const r = await fetch(url);
|
|
if (!r.ok) {
|
|
let msg = '';
|
|
try {
|
|
const body = await r.json();
|
|
msg = body.error || JSON.stringify(body);
|
|
} catch (_) {
|
|
msg = await r.text();
|
|
}
|
|
throw new Error(url + ': ' + r.status + (msg ? ' - ' + msg : ''));
|
|
}
|
|
return r.json();
|
|
}
|
|
|
|
async function requestJSON(url, method, body) {
|
|
const r = await fetch(url, {
|
|
method: method,
|
|
headers: { 'Content-Type': 'application/json' },
|
|
body: body ? JSON.stringify(body) : undefined
|
|
});
|
|
let data = {};
|
|
try { data = await r.json(); } catch (_) {}
|
|
if (!r.ok) {
|
|
throw new Error(data.error || (url + ': ' + r.status));
|
|
}
|
|
return data;
|
|
}
|
|
|
|
function setText(id, value) {
|
|
document.getElementById(id).textContent = String(value);
|
|
}
|
|
|
|
function showStatus(message, kind) {
|
|
const el = document.getElementById('status');
|
|
el.style.display = 'block';
|
|
el.className = 'status ' + (kind || '');
|
|
el.textContent = message;
|
|
}
|
|
|
|
function clearStatus() {
|
|
const el = document.getElementById('status');
|
|
el.style.display = 'none';
|
|
el.className = 'status';
|
|
el.textContent = '';
|
|
}
|
|
|
|
function parseMethods(v) {
|
|
const items = String(v || '').split(',').map(s => s.trim().toUpperCase()).filter(Boolean);
|
|
return items.length ? Array.from(new Set(items)) : ['GET'];
|
|
}
|
|
|
|
function triggerByFn(fnName) {
|
|
return (S.triggers || []).find(function (t) {
|
|
return t.spec && t.spec.functionref && t.spec.functionref.name === fnName;
|
|
});
|
|
}
|
|
|
|
function h(v) {
|
|
return String(v == null ? '' : v)
|
|
.replaceAll('&', '&')
|
|
.replaceAll('<', '<')
|
|
.replaceAll('>', '>')
|
|
.replaceAll('"', '"')
|
|
.replaceAll("'", ''');
|
|
}
|
|
|
|
function openCreate() {
|
|
const envSel = document.getElementById('c-env');
|
|
envSel.innerHTML = (S.envs || []).map(function (e) {
|
|
const n = (e.metadata && e.metadata.name) || '';
|
|
return '<option value="' + h(n) + '">' + h(n) + '</option>';
|
|
}).join('');
|
|
document.getElementById('create-modal').classList.add('open');
|
|
document.getElementById('c-name').focus();
|
|
}
|
|
|
|
function closeCreate() {
|
|
document.getElementById('create-modal').classList.remove('open');
|
|
}
|
|
|
|
async function submitCreate() {
|
|
const btn = document.getElementById('c-submit');
|
|
btn.disabled = true;
|
|
try {
|
|
const name = document.getElementById('c-name').value.trim();
|
|
if (!name) throw new Error('name is required');
|
|
const env = document.getElementById('c-env').value.trim();
|
|
if (!env) throw new Error('environment is required');
|
|
|
|
await requestJSON(API_BASE + '/functions', 'POST', {
|
|
name: name,
|
|
environment: env,
|
|
entrypoint: document.getElementById('c-entry').value.trim(),
|
|
route: document.getElementById('c-route').value.trim(),
|
|
methods: parseMethods(document.getElementById('c-methods').value),
|
|
code: document.getElementById('c-code').value
|
|
});
|
|
|
|
closeCreate();
|
|
showStatus('Function created: ' + name, 'ok');
|
|
await reloadAll();
|
|
} catch (e) {
|
|
showStatus('Create failed: ' + e.message, 'err');
|
|
} finally {
|
|
btn.disabled = false;
|
|
}
|
|
}
|
|
|
|
async function openEdit(name) {
|
|
try {
|
|
const fn = await getJSON(API_BASE + '/functions/' + encodeURIComponent(name));
|
|
S.currentEdit = fn;
|
|
document.getElementById('e-title').textContent = 'Edit Code: ' + name;
|
|
document.getElementById('e-name').value = name;
|
|
document.getElementById('e-env').value = fn.environment || '';
|
|
document.getElementById('e-entry').value = fn.entrypoint || '';
|
|
document.getElementById('e-code').value = fn.code || '';
|
|
document.getElementById('edit-modal').classList.add('open');
|
|
} catch (e) {
|
|
showStatus('Load function failed: ' + e.message, 'err');
|
|
}
|
|
}
|
|
|
|
function closeEdit() {
|
|
document.getElementById('edit-modal').classList.remove('open');
|
|
S.currentEdit = null;
|
|
}
|
|
|
|
async function submitEdit() {
|
|
if (!S.currentEdit) return;
|
|
const btn = document.getElementById('e-submit');
|
|
btn.disabled = true;
|
|
try {
|
|
const name = S.currentEdit.name;
|
|
await requestJSON(API_BASE + '/functions/' + encodeURIComponent(name) + '/code', 'PUT', {
|
|
code: document.getElementById('e-code').value
|
|
});
|
|
closeEdit();
|
|
showStatus('Code updated: ' + name, 'ok');
|
|
} catch (e) {
|
|
showStatus('Update failed: ' + e.message, 'err');
|
|
} finally {
|
|
btn.disabled = false;
|
|
}
|
|
}
|
|
|
|
function openInvoke(name) {
|
|
S.currentInvoke = name;
|
|
document.getElementById('i-title').textContent = 'Invoke: ' + name;
|
|
document.getElementById('i-resp').value = '';
|
|
document.getElementById('invoke-modal').classList.add('open');
|
|
}
|
|
|
|
function closeInvoke() {
|
|
document.getElementById('invoke-modal').classList.remove('open');
|
|
S.currentInvoke = null;
|
|
}
|
|
|
|
async function submitInvoke() {
|
|
if (!S.currentInvoke) return;
|
|
const btn = document.getElementById('i-submit');
|
|
btn.disabled = true;
|
|
try {
|
|
const raw = document.getElementById('i-body').value.trim();
|
|
let parsed = {};
|
|
if (raw) parsed = JSON.parse(raw);
|
|
const result = await requestJSON(API_BASE + '/functions/' + encodeURIComponent(S.currentInvoke) + '/invoke', 'POST', parsed);
|
|
document.getElementById('i-resp').value = JSON.stringify(result, null, 2);
|
|
} catch (e) {
|
|
document.getElementById('i-resp').value = 'Invoke failed: ' + e.message;
|
|
} finally {
|
|
btn.disabled = false;
|
|
}
|
|
}
|
|
|
|
async function removeFn(name) {
|
|
if (!confirm('Delete function ' + name + '?')) return;
|
|
try {
|
|
await requestJSON(API_BASE + '/functions/' + encodeURIComponent(name), 'DELETE');
|
|
showStatus('Function deleted: ' + name, 'ok');
|
|
await reloadAll();
|
|
} catch (e) {
|
|
showStatus('Delete failed: ' + e.message, 'err');
|
|
}
|
|
}
|
|
|
|
async function reloadAll() {
|
|
try {
|
|
const [envs, pkgs, fns, http, time] = await Promise.all([
|
|
getJSON(API_BASE + '/environments'),
|
|
getJSON(API_BASE + '/packages'),
|
|
getJSON(API_BASE + '/functions'),
|
|
getJSON(API_BASE + '/httptriggers'),
|
|
getJSON(API_BASE + '/timetriggers')
|
|
]);
|
|
|
|
S.envs = envs || [];
|
|
S.fns = fns || [];
|
|
S.triggers = http || [];
|
|
|
|
setText('env-count', envs.length || 0);
|
|
setText('pkg-count', pkgs.length || 0);
|
|
setText('fn-count', fns.length || 0);
|
|
setText('http-count', http.length || 0);
|
|
setText('time-count', time.length || 0);
|
|
|
|
const rows = (fns || []).map(function (f) {
|
|
const spec = f.spec || {};
|
|
const env = (spec.environment && spec.environment.name) || '-';
|
|
const pkg = (spec.package && spec.package.packageref && spec.package.packageref.name) || '-';
|
|
const name = (f.metadata && f.metadata.name) || '-';
|
|
const trig = triggerByFn(name) || {};
|
|
const route = (trig.spec && trig.spec.relativeurl) || '-';
|
|
const methods = (trig.spec && trig.spec.methods) || [];
|
|
const chips = methods.map(function (m) { return '<span class="chip">' + h(m) + '</span>'; }).join('');
|
|
const actions = [
|
|
'<button class="btn ghost" onclick="openEdit(\'' + h(name) + '\')">Edit</button>',
|
|
'<button class="btn ghost" onclick="openInvoke(\'' + h(name) + '\')">Invoke</button>',
|
|
'<button class="btn danger" onclick="removeFn(\'' + h(name) + '\')">Delete</button>'
|
|
].join(' ');
|
|
return '<tr>' +
|
|
'<td class="mono">' + h(name) + '</td>' +
|
|
'<td>' + h(env) + '</td>' +
|
|
'<td class="mono">' + h(pkg) + '</td>' +
|
|
'<td class="mono">' + h(route) + '</td>' +
|
|
'<td>' + chips + '</td>' +
|
|
'<td class="nowrap">' + actions + '</td>' +
|
|
'</tr>';
|
|
}).join('');
|
|
|
|
document.getElementById('fn-rows').innerHTML = rows || '<tr><td colspan="3">No functions</td></tr>';
|
|
if (!rows) {
|
|
document.getElementById('fn-rows').innerHTML = '<tr><td colspan="6">No functions</td></tr>';
|
|
}
|
|
} catch (e) {
|
|
document.getElementById('fn-rows').innerHTML = '<tr><td colspan="6">Load error: ' + e.message + '</td></tr>';
|
|
showStatus('Reload failed: ' + e.message, 'err');
|
|
}
|
|
}
|
|
|
|
reloadAll();
|
|
</script>
|
|
</body>
|
|
</html>
|