1
0
Fork 0

Change signature o getCapabilities.

This commit is contained in:
Kitteh 2021-05-29 10:19:18 +01:00
parent 4c4a69464f
commit b079d485db
4 changed files with 19 additions and 8 deletions

View file

@ -1,7 +1,18 @@
import { appendAPIURL, checkResponse, getHeaders } from "../apiUtils";
import { removeDoubleSlash } from "../../utils";
export async function getCapabilitiesPath(path: string): Promise<string[]> {
export type CapabilitiesType = {
[path: string]: string[];
capabilities?: string[];
}
export async function getCapabilitiesPath(path: string | string[]): Promise<CapabilitiesType> {
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<string[]> {
...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<string[]> {
): Promise<CapabilitiesType> {
return await getCapabilitiesPath(
removeDoubleSlash(baseMount + secretPath.join("/") + "/" + name),
);

View file

@ -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;

View file

@ -55,11 +55,11 @@ export class KeyValueSecretPage extends Page {
}
}
async render(): Promise<void> {
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,

View file

@ -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);