1
0
Fork 0
VaultUI/src/api/sys/getCapabilities.ts
2021-05-09 11:18:18 +01:00

32 lines
820 B
TypeScript

import { appendAPIURL, getHeaders } from "../apiUtils";
import { removeDoubleSlash } from "../../utils";
export async function getCapabilitiesPath(path: string): Promise<string[]> {
const request = new Request(appendAPIURL("/v1/sys/capabilities-self"), {
method: "POST",
headers: {
'Content-Type': 'application/json',
...getHeaders(),
},
body: JSON.stringify(
{
"paths": [removeDoubleSlash(path)]
}
)
});
return fetch(request).then(response => {
return response.json();
}).then(data => {
return data.capabilities;
});
}
export async function getCapabilities(
baseMount: string,
secretPath: string[],
name: string
): Promise<string[]> {
return await getCapabilitiesPath(removeDoubleSlash(baseMount + secretPath.join("/") + "/" + name));
}