v0.5.148: move impersonation-check to /v2/app?impersonation-check
This commit is contained in:
@@ -90,31 +90,6 @@ function createV2Router() {
|
||||
}
|
||||
});
|
||||
|
||||
// ── GET /v2/impersonation-check — IAM impersonation: все GET эндпоинты ─
|
||||
router.get('/impersonation-check', async (req, res) => {
|
||||
const token = req.session && req.session.token;
|
||||
if (!token) return res.send('<h2>Нет токена</h2><p><a href="/v2/login">Войти</a></p>');
|
||||
|
||||
const endpoints = [
|
||||
{ name: 'status', url: 'https://auth-api.ngcloud.ru/api/v1/impersonation/status' },
|
||||
{ name: 'history', url: 'https://auth-api.ngcloud.ru/api/v1/impersonation/history' },
|
||||
{ name: 'history/all', url: 'https://auth-api.ngcloud.ru/api/v1/impersonation/history/all' },
|
||||
];
|
||||
|
||||
const results = {};
|
||||
for (const ep of endpoints) {
|
||||
try {
|
||||
const data = await iamFetch(token, ep.url);
|
||||
results[ep.name] = { ok: true, data };
|
||||
} catch (e) {
|
||||
results[ep.name] = { ok: false, error: e.message };
|
||||
}
|
||||
}
|
||||
|
||||
res.set('Content-Type', 'text/html; charset=utf-8');
|
||||
res.send(iamStatPage(results));
|
||||
});
|
||||
|
||||
// ── /v2/app — пользовательский CRUD (только с сессией) ──────────────
|
||||
router.use('/app', enhanceImpersonation, resolveContext, createUserRouter());
|
||||
|
||||
@@ -187,63 +162,4 @@ function debugPage(u, version) {
|
||||
</body></html>`;
|
||||
}
|
||||
|
||||
function iamStatPage(results) {
|
||||
function fmt(data, depth) {
|
||||
if (data === null || data === undefined) return '<span style="color:#888">null</span>';
|
||||
if (typeof data === 'string') return '<span style="color:#ce93d8">"' + data.replace(/</g, '<') + '"</span>';
|
||||
if (typeof data === 'number' || typeof data === 'boolean') return '<span style="color:#81c784">' + data + '</span>';
|
||||
if (Array.isArray(data)) {
|
||||
if (data.length === 0) return '<span style="color:#888">[]</span>';
|
||||
let html = '<span style="color:#888">[</span><div style="padding-left:20px">';
|
||||
for (const item of data) html += '<div>' + fmt(item, depth + 1) + ',</div>';
|
||||
html += '</div><span style="color:#888">]</span>';
|
||||
return html;
|
||||
}
|
||||
if (typeof data === 'object') {
|
||||
let html = '<span style="color:#888">{</span><div style="padding-left:20px">';
|
||||
for (const [k, v] of Object.entries(data)) {
|
||||
html += '<div><span style="color:#82aaff">"' + k + '"</span>: ' + fmt(v, depth + 1) + '</div>';
|
||||
}
|
||||
html += '</div><span style="color:#888">}</span>';
|
||||
return html;
|
||||
}
|
||||
return String(data).replace(/</g, '<');
|
||||
}
|
||||
|
||||
let html = '<!DOCTYPE html><html><head><meta charset="utf-8"><title>IAM Impersonation</title>';
|
||||
html += '<style>body{font-family:monospace;background:#111;color:#eee;padding:20px;font-size:14px}';
|
||||
html += 'h2{color:#4fc3f7}.ok{color:#81c784}.err{color:#ef5350}';
|
||||
html += '.card{background:#1a1a2e;border-radius:8px;padding:15px;margin-bottom:15px;overflow-x:auto}';
|
||||
html += '.card-title{color:#b39ddb;font-size:18px;font-weight:bold;margin-bottom:10px}';
|
||||
html += 'a{color:#80cbc4;text-decoration:none}a:hover{text-decoration:underline}';
|
||||
html += '.nav{display:flex;gap:15px;margin-bottom:20px;flex-wrap:wrap}';
|
||||
html += '.nav a{background:#1a1a2e;padding:8px 16px;border-radius:6px;font-size:14px}';
|
||||
html += '</style></head><body>';
|
||||
html += '<h2>🧪 IAM Impersonation — GET эндпоинты</h2>';
|
||||
html += '<div class="nav">';
|
||||
html += '<a href="/v2/iam">← Сессия</a>';
|
||||
html += '<a href="/v2/app">CRUD</a>';
|
||||
html += '<a href="/v2/admin">Админка</a>';
|
||||
html += '<a href="/v2/iam_response">IAM PROD</a>';
|
||||
html += '<a href="/v2/iam_response_test">IAM TEST</a>';
|
||||
html += '<a href="/v2/iam_response_dev">IAM DEV</a>';
|
||||
html += '</div>';
|
||||
|
||||
for (const [name, r] of Object.entries(results)) {
|
||||
html += '<div class="card">';
|
||||
html += '<div class="card-title">GET /impersonation/' + name + '</div>';
|
||||
if (r.ok) {
|
||||
html += '<div style="font-family:monospace;white-space:pre-wrap;tab-size:2">';
|
||||
html += fmt(r.data, 0);
|
||||
html += '</div>';
|
||||
} else {
|
||||
html += '<div class="err">❌ ' + r.error.replace(/</g, '<') + '</div>';
|
||||
}
|
||||
html += '</div>';
|
||||
}
|
||||
|
||||
html += '</body></html>';
|
||||
return html;
|
||||
}
|
||||
|
||||
module.exports = { createV2Router };
|
||||
|
||||
Reference in New Issue
Block a user