Last active
March 4, 2024 10:07
-
-
Save nymous/104110d0db4fdf4a19b7f93649aa08d1 to your computer and use it in GitHub Desktop.
Vault userscript to display entities and groups names alongside their IDs
This file contains 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
// ==UserScript== | |
// @name Replace Vault IDs with names | |
// @namespace http://tampermonkey.net/ | |
// @version 2024-03-04 | |
// @description try to take over the world! | |
// @author You | |
// @match https://<your vault url>/* | |
// @icon https://icons.duckduckgo.com/ip2/www.vaultproject.io.ico | |
// @grant none | |
// ==/UserScript== | |
(async function() { | |
'use strict'; | |
let lastUrl; | |
setInterval(async () => { | |
let currUrl = window.location.href | |
if (currUrl != lastUrl) { | |
lastUrl = currUrl | |
if (window.location.pathname.match(/^\/ui\/vault\/access\/identity\/entities\/.+\/groups$/)) { | |
const groups = await getGroups(getVaultToken()) | |
const links = Array.from(document.querySelectorAll(".container a[href^='/ui/vault/access/identity/groups/'][href*='/details']")) | |
for (const link of links) { | |
const dest = new URL(link.href).pathname | |
const groupId = dest.match(/^.+groups\/(.+)\/details$/)[1] | |
const groupName = groups[groupId].name | |
link.innerHTML = link.innerHTML.replace(groupId, `${groupName} <i>(${groupId}</i>)`) | |
} | |
} | |
if (window.location.pathname.match(/^\/ui\/vault\/access\/identity\/groups\/.+\/members$/)) { | |
const entities = await getEntities(getVaultToken()) | |
const links = Array.from(document.querySelectorAll(".container a[href^='/ui/vault/access/identity/entities/'][href*='/details']")) | |
for (const link of links) { | |
const dest = new URL(link.href).pathname | |
const entityId = dest.match(/^.+entities\/(.+)\/details$/)[1] | |
const entityName = entities[entityId].name | |
link.innerHTML = link.innerHTML.replace(entityId, `${entityName} <i>(${entityId}</i>)`) | |
} | |
} | |
} | |
}, 300); | |
function getVaultToken() { | |
const localStorageKey = Object.keys(localStorage).find(key => key.includes("☃1")) | |
const token = JSON.parse(localStorage.getItem(localStorageKey)).token | |
return token | |
} | |
function getGroups(token) { | |
return fetch("/v1/identity/group/id?list=true", { | |
"credentials": "omit", | |
"headers": getVaultHeaders(token), | |
"mode": "cors" | |
}) | |
.then(r => r.json()) | |
.then(r => r.data.key_info) | |
} | |
function getEntities(token) { | |
return fetch("/v1/identity/entity/id?list=true", { | |
"credentials": "omit", | |
"headers": getVaultHeaders(token), | |
"mode": "cors" | |
}) | |
.then(r => r.json()) | |
.then(r => r.data.key_info) | |
} | |
function getVaultHeaders(token) { | |
const headers = { | |
"X-Vault-Token": token | |
} | |
const searchParams = new URL(window.location).searchParams | |
if (searchParams.has("namespace")) { | |
headers["X-Vault-Namespace"] = searchParams.get("namespace") | |
} | |
return headers | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment