feat(release): v1.14.0 discovery and conf pages
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
'use strict';
|
||||
const conf = require('@simpleworkjs/conf');
|
||||
const VAULT_URL = 'http://openbao:8200';
|
||||
const VAULT_TOKEN = 'root';
|
||||
|
||||
async function getVaultConf() {
|
||||
try {
|
||||
const res = await fetch(`${VAULT_URL}/v1/secret/data/sso-manager/conf`, {
|
||||
headers: { 'X-Vault-Token': VAULT_TOKEN }
|
||||
});
|
||||
if (res.status === 200) {
|
||||
const json = await res.json();
|
||||
return json.data.data;
|
||||
}
|
||||
} catch (err) {
|
||||
console.error('Error fetching conf from Vault:', err);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
async function setVaultConf(newConf) {
|
||||
const res = await fetch(`${VAULT_URL}/v1/secret/data/sso-manager/conf`, {
|
||||
method: 'POST',
|
||||
headers: { 'X-Vault-Token': VAULT_TOKEN, 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ data: newConf })
|
||||
});
|
||||
if (!res.ok) {
|
||||
const text = await res.text();
|
||||
throw new Error(`Vault API error: ${res.status} ${text}`);
|
||||
}
|
||||
applyConf(newConf);
|
||||
}
|
||||
|
||||
function applyConf(newConf) {
|
||||
if (!newConf) return;
|
||||
// Deep merge into conf
|
||||
for (const key of Object.keys(newConf)) {
|
||||
if (typeof newConf[key] === 'object' && newConf[key] !== null && !Array.isArray(newConf[key])) {
|
||||
conf[key] = { ...conf[key], ...newConf[key] };
|
||||
} else {
|
||||
conf[key] = newConf[key];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async function init() {
|
||||
const vaultConf = await getVaultConf();
|
||||
if (vaultConf) {
|
||||
applyConf(vaultConf);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = { getVaultConf, setVaultConf, init };
|
||||
+3
-1
@@ -43,8 +43,10 @@ module.exports = {
|
||||
// non-admin had no signposted destination at all.
|
||||
{href: '/', icon: 'fa-solid fa-compass', label: 'Catalog', groups: []},
|
||||
{href: '/users', icon: 'fa-solid fa-users', label: 'Users', groups: ['app_sso_admin', 'admin']},
|
||||
{href: '/groups', icon: 'fa-solid fa-users-viewfinder', label: 'Groups', groups: ['app_sso_admin', 'admin']},
|
||||
{href: '/groups', icon: 'fas fa-users-cog', label: 'Groups', groups: ['app_sso_admin']},
|
||||
{href: '/conf', icon: 'fas fa-cogs', label: 'Configuration', groups: ['app_sso_admin']},
|
||||
{href: '/directory', icon: 'fa-solid fa-server', label: 'Directory', groups: ['app_sso_admin', 'app_sso_directory_admin', 'admin']},
|
||||
{href: '/vault', icon: 'fa-solid fa-vault', label: 'Vault', groups: []},
|
||||
{href: '/overview', icon: 'fa-solid fa-gauge-high', label: 'Overview', groups: ['app_sso_admin', 'admin']},
|
||||
],
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user