diff --git a/src/api/sys/getCapabilities.ts b/src/api/sys/getCapabilities.ts index dc7f238..8e17833 100644 --- a/src/api/sys/getCapabilities.ts +++ b/src/api/sys/getCapabilities.ts @@ -1,7 +1,18 @@ import { appendAPIURL, checkResponse, getHeaders } from "../apiUtils"; import { removeDoubleSlash } from "../../utils"; -export async function getCapabilitiesPath(path: string): Promise { +export type CapabilitiesType = { + [path: string]: string[]; + capabilities?: string[]; +} + +export async function getCapabilitiesPath(path: string | string[]): Promise { + if (!Array.isArray(path)) { + path = [removeDoubleSlash(path)] + } else { + path = path.map((s) => removeDoubleSlash(s)); + } + const request = new Request(appendAPIURL("/v1/sys/capabilities-self"), { method: "POST", headers: { @@ -9,21 +20,21 @@ export async function getCapabilitiesPath(path: string): Promise { ...getHeaders(), }, body: JSON.stringify({ - paths: [removeDoubleSlash(path)], + paths: path, }), }); const resp = await fetch(request); await checkResponse(resp); const data = (await resp.json()) as { capabilities: string[] }; - return data.capabilities; + return data; } export async function getCapabilities( baseMount: string, secretPath: string[], name: string, -): Promise { +): Promise { return await getCapabilitiesPath( removeDoubleSlash(baseMount + secretPath.join("/") + "/" + name), ); diff --git a/src/pages/Me.tsx b/src/pages/Me.tsx index e4e34bc..b72dd4d 100644 --- a/src/pages/Me.tsx +++ b/src/pages/Me.tsx @@ -34,7 +34,7 @@ export class MePage extends Page { let canSealVault = false; try { - const caps = await getCapabilitiesPath("sys/seal"); + const caps = (await getCapabilitiesPath("sys/seal")).capabilities; canSealVault = caps.includes("sudo") && caps.includes("update"); } catch (e) { canSealVault = false; diff --git a/src/pages/Secrets/KeyValue/KeyValueSecret.tsx b/src/pages/Secrets/KeyValue/KeyValueSecret.tsx index 22d70a5..cb21fff 100644 --- a/src/pages/Secrets/KeyValue/KeyValueSecret.tsx +++ b/src/pages/Secrets/KeyValue/KeyValueSecret.tsx @@ -55,11 +55,11 @@ export class KeyValueSecretPage extends Page { } } async render(): Promise { - const caps = await getCapabilities( + const caps = (await getCapabilities( this.state.baseMount, this.state.secretPath, this.state.secretItem, - ); + )).capabilities; const secretInfo = await getSecret( this.state.baseMount, diff --git a/src/pages/Secrets/SecretsHome.tsx b/src/pages/Secrets/SecretsHome.tsx index 345fe4e..758ada3 100644 --- a/src/pages/Secrets/SecretsHome.tsx +++ b/src/pages/Secrets/SecretsHome.tsx @@ -74,7 +74,7 @@ export class SecretsHomePage extends Page { this.state.secretItem = ""; this.state.secretVersion = null; - const mountsCapabilities = await getCapabilitiesPath("/sys/mounts"); + const mountsCapabilities = (await getCapabilitiesPath("/sys/mounts")).capabilities; const mounts = await getMounts(); // sort it by secretPath so it's in alphabetical order consistantly. const mountsMap = sortedObjectMap(mounts);