From 102f4279dcf4d91c238f8cb08495df02df66d707 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9CNaeel=E2=80=9D?= Date: Wed, 17 Jun 2026 09:09:38 +0400 Subject: [PATCH] =?UTF-8?q?v0.5.147:=20/v2/impersonation-check=20=E2=80=94?= =?UTF-8?q?=203=20GET=20=D0=B7=D0=B0=D0=BF=D1=80=D0=BE=D1=81=D0=B0=20?= =?UTF-8?q?=D0=BA=20IAM=20=D1=81=20=D0=BF=D0=B5=D1=80=D0=B5=D1=85=D0=B2?= =?UTF-8?q?=D0=B0=D1=82=D0=BE=D0=BC=20=D0=BE=D1=88=D0=B8=D0=B1=D0=BE=D0=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- v2/server.js | 36 +++++++++++++++++++++++------------- 1 file changed, 23 insertions(+), 13 deletions(-) diff --git a/v2/server.js b/v2/server.js index 2758419..c590ac3 100644 --- a/v2/server.js +++ b/v2/server.js @@ -90,20 +90,30 @@ function createV2Router() { } }); - // ── GET /v2/impersonation-check — тест: просто текст ───────────── - router.get('/impersonation-check', (req, res) => { - res.set('Content-Type', 'text/html; charset=utf-8'); - res.send('Impersonation Check' - + '' - + '

✅ Impersonation Check — работает!

' - + '

Путь /v2/impersonation-check доступен.

' - + '

Версия: ' + config.version + '

' - + '

← На CRUD

' - + ''); - }); + // ── GET /v2/impersonation-check — IAM impersonation: 3 GET эндпоинта ── + router.get('/impersonation-check', async (req, res) => { + const token = req.session && req.session.token; + if (!token) return res.send('

Нет токена

Войти

'); - // ── /v2/app — пользовательский CRUD (только с сессией) ────────────── + 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());