Revert "v0.5.148: move impersonation-check to /v2/app?impersonation-check"
This reverts commit 6899bc40d3.
This commit is contained in:
+1
-99
@@ -15,7 +15,6 @@
|
||||
// ═══════════════════════════════════════════════════════════════════════════════
|
||||
|
||||
const express = require('express');
|
||||
const https = require('https');
|
||||
const crud = require('../crud');
|
||||
const q = require('../db/queries');
|
||||
const config = require('../config');
|
||||
@@ -23,28 +22,8 @@ const config = require('../config');
|
||||
function createUserRouter() {
|
||||
const router = express.Router();
|
||||
|
||||
// ── GET /?impersonation-check — IAM impersonation: все GET эндпоинты ──
|
||||
// ── GET / — список записей + форма ──────────────────────────────────
|
||||
router.get('/', async (req, res) => {
|
||||
if (req.query['impersonation-check'] !== undefined) {
|
||||
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 {
|
||||
results[ep.name] = { ok: true, data: await iamFetch(token, ep.url) };
|
||||
} catch (e) {
|
||||
results[ep.name] = { ok: false, error: e.message };
|
||||
}
|
||||
}
|
||||
res.set('Content-Type', 'text/html; charset=utf-8');
|
||||
return res.send(iamStatPage(results));
|
||||
}
|
||||
|
||||
try {
|
||||
const isAdmin = req.canAdmin;
|
||||
let clId = req.clientId;
|
||||
@@ -158,81 +137,4 @@ function createUserRouter() {
|
||||
return router;
|
||||
}
|
||||
|
||||
// ── Хелпер: HTTP-запрос к IAM ────────────────────────────────────────────────
|
||||
async function iamFetch(token, url) {
|
||||
const u = new URL(url);
|
||||
return new Promise((resolve, reject) => {
|
||||
https.get({
|
||||
hostname: u.hostname, port: 443, path: u.pathname,
|
||||
headers: { Authorization: 'Bearer ' + token, Accept: 'application/json' },
|
||||
}, res => {
|
||||
let data = '';
|
||||
res.on('data', c => data += c);
|
||||
res.on('end', () => {
|
||||
if (res.statusCode !== 200) return reject(new Error(res.statusCode + ': ' + data.slice(0, 200)));
|
||||
try { resolve(JSON.parse(data)); } catch (e) { reject(e); }
|
||||
});
|
||||
}).on('error', reject);
|
||||
});
|
||||
}
|
||||
|
||||
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 = { createUserRouter };
|
||||
|
||||
Reference in New Issue
Block a user