Created
March 10, 2026 09:44
-
-
Save FreePhoenix888/c457de95476dd875f47a36f6fa595095 to your computer and use it in GitHub Desktop.
Copy Vault Data To Another Namespace
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (async () => { | |
| // ⚠️ Вставь свой актуальный токен сюда | |
| const TOKEN = "my vault token"; | |
| // В данном случае я переношу енвы из pkbbridge/dev в bnpl/pkbbridge/dev | |
| const sourceBaseUrl = "https://vault-url.com/v1/secret/pkbbridge/dev/data"; | |
| const destBaseUrl = "https://vault-url.com/v1/secret/bnpl/pkbbridge/dev/data"; | |
| // Динамически собираем ключи прямо из DOM-дерева страницы | |
| const keys = [...document.body.querySelectorAll('.list-item-row')].map(element => element.textContent.trim()); | |
| if (keys.length === 0) { | |
| console.error("❌ Ключи не найдены! Убедись, что ты находишься на нужной странице со списком секретов."); | |
| return; | |
| } | |
| console.log(`🚀 Начинаем миграцию ${keys.length} секретов...`); | |
| for (const key of keys) { | |
| // Пропускаем пустые строки на всякий случай, если селектор зацепил что-то лишнее | |
| if (!key) continue; | |
| try { | |
| // 1. Читаем секрет из старого пути | |
| const getRes = await fetch(`${sourceBaseUrl}/${key}`, { | |
| method: "GET", | |
| headers: { | |
| "x-vault-token": TOKEN | |
| } | |
| }); | |
| if (!getRes.ok) { | |
| console.warn(`⚠️ Пропущен [${key}]: ошибка GET ${getRes.status}`); | |
| continue; | |
| } | |
| const getJson = await getRes.json(); | |
| const secretValue = getJson?.data?.data?.value; | |
| if (secretValue === undefined) { | |
| console.warn(`⚠️ Пропущен [${key}]: поле 'value' не найдено в ответе`); | |
| continue; | |
| } | |
| // 2. Пишем секрет в новый путь | |
| const postRes = await fetch(`${destBaseUrl}/${key}`, { | |
| method: "POST", | |
| headers: { | |
| "content-type": "application/json; charset=utf-8", | |
| "x-vault-token": TOKEN | |
| }, | |
| body: JSON.stringify({ | |
| data: { | |
| value: secretValue | |
| } | |
| }) | |
| }); | |
| if (!postRes.ok) { | |
| console.error(`❌ Ошибка сохранения [${key}]: POST ${postRes.status}`); | |
| } else { | |
| console.log(`✅ Скопирован: ${key}`); | |
| } | |
| } catch (err) { | |
| console.error(`🚨 Ошибка сети при обработке [${key}]:`, err); | |
| } | |
| } | |
| console.log("🎉 Миграция завершена!"); | |
| })(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment