Make some code easier to read with capabilities.
This commit is contained in:
parent
5b0b0496be
commit
c379b810a4
|
@ -28,6 +28,10 @@ export async function getCapabilitiesPath(path: string | string[]): Promise<Capa
|
|||
return data;
|
||||
}
|
||||
|
||||
export async function getCapsPath(path: string | string[]): Promise<string[]> {
|
||||
return (await getCapabilitiesPath(path)).capabilities;
|
||||
}
|
||||
|
||||
export async function getCapabilities(
|
||||
baseMount: string,
|
||||
secretPath: string[],
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import { Component, JSX, createRef, render } from "preact";
|
||||
import { Page } from "../types/Page";
|
||||
import { addClipboardNotifications, prePageChecks, setErrorText } from "../pageUtils";
|
||||
import { getCapabilitiesPath } from "../api/sys/getCapabilities";
|
||||
import { getCapsPath } from "../api/sys/getCapabilities";
|
||||
import { renewSelf } from "../api/sys/renewSelf";
|
||||
import { sealVault } from "../api/sys/sealVault";
|
||||
import ClipboardJS from "clipboard";
|
||||
|
@ -34,7 +34,7 @@ export class MePage extends Page {
|
|||
|
||||
let canSealVault = false;
|
||||
try {
|
||||
const caps = (await getCapabilitiesPath("sys/seal")).capabilities;
|
||||
const caps = await getCapsPath("sys/seal");
|
||||
canSealVault = caps.includes("sudo") && caps.includes("update");
|
||||
} catch (e) {
|
||||
canSealVault = false;
|
||||
|
|
|
@ -2,7 +2,7 @@ import { Component, JSX, render } from "preact";
|
|||
import { DoesNotExistError } from "../../../types/internalErrors";
|
||||
import { Page } from "../../../types/Page";
|
||||
import { SecretTitleElement } from "../SecretTitleElement";
|
||||
import { getCapabilitiesPath } from "../../../api/sys/getCapabilities";
|
||||
import { getCapsPath } from "../../../api/sys/getCapabilities";
|
||||
import { getSecrets } from "../../../api/kv/getSecrets";
|
||||
import { setErrorText } from "../../../pageUtils";
|
||||
import i18next from "i18next";
|
||||
|
@ -92,7 +92,6 @@ export class KVKeysList extends Component<KVKeysListProps, KVKeysListState> {
|
|||
<a
|
||||
onClick={async () => {
|
||||
const page = this.props.page;
|
||||
console.log(secret, page.state.secretPath, page.state.baseMount);
|
||||
|
||||
if (secret.endsWith("/")) {
|
||||
page.state.pushSecretPath(secret);
|
||||
|
@ -125,7 +124,7 @@ export class KeyValueViewPage extends Page {
|
|||
}
|
||||
}
|
||||
async render(): Promise<void> {
|
||||
const caps = (await getCapabilitiesPath("/sys/mounts/" + this.state.baseMount)).capabilities;
|
||||
const caps = await getCapsPath("/sys/mounts/" + this.state.baseMount);
|
||||
|
||||
render(
|
||||
<>
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import { JSX, render } from "preact";
|
||||
import { MountType, getMounts } from "../../api/sys/getMounts";
|
||||
import { Page } from "../../types/Page";
|
||||
import { getCapabilitiesPath } from "../../api/sys/getCapabilities";
|
||||
import { getCapsPath } from "../../api/sys/getCapabilities";
|
||||
import { prePageChecks } from "../../pageUtils";
|
||||
import { sortedObjectMap } from "../../utils";
|
||||
import i18next from "i18next";
|
||||
|
@ -73,7 +73,7 @@ export class SecretsHomePage extends Page {
|
|||
this.state.secretItem = "";
|
||||
this.state.secretVersion = null;
|
||||
|
||||
const mountsCapabilities = (await getCapabilitiesPath("/sys/mounts")).capabilities;
|
||||
const mountsCapabilities = await getCapsPath("/sys/mounts");
|
||||
const mounts = await getMounts();
|
||||
// sort it by secretPath so it's in alphabetical order consistantly.
|
||||
const mountsMap = sortedObjectMap(mounts);
|
||||
|
|
|
@ -5,7 +5,7 @@ import { Grid, GridSizes } from "../../../elements/Grid";
|
|||
import { MarginInline } from "../../../elements/MarginInline";
|
||||
import { Page } from "../../../types/Page";
|
||||
import { SecretTitleElement } from "../SecretTitleElement";
|
||||
import { getCapabilitiesPath } from "../../../api/sys/getCapabilities";
|
||||
import { getCapsPath } from "../../../api/sys/getCapabilities";
|
||||
import { getTOTPCode } from "../../../api/totp/getTOTPCode";
|
||||
import { getTOTPKeys } from "../../../api/totp/getTOTPKeys";
|
||||
import { removeDoubleSlash } from "../../../utils";
|
||||
|
@ -80,7 +80,7 @@ export class TOTPViewPage extends Page {
|
|||
async render(): Promise<void> {
|
||||
this.state.secretItem = "";
|
||||
|
||||
const caps = (await getCapabilitiesPath("/sys/mounts/" + this.state.baseMount)).capabilities;
|
||||
const caps = await getCapsPath("/sys/mounts/" + this.state.baseMount);
|
||||
|
||||
render(
|
||||
<div>
|
||||
|
@ -114,11 +114,9 @@ export class TOTPViewPage extends Page {
|
|||
try {
|
||||
const elem = await Promise.all(
|
||||
Array.from(await getTOTPKeys(this.state.baseMount)).map(async (key) => {
|
||||
const caps = (
|
||||
await getCapabilitiesPath(
|
||||
removeDoubleSlash(this.state.baseMount + "code/" + key),
|
||||
)
|
||||
).capabilities;
|
||||
const caps = await getCapsPath(
|
||||
removeDoubleSlash(this.state.baseMount + "code/" + key),
|
||||
);
|
||||
if (caps.includes("read")) {
|
||||
return (
|
||||
<RefreshingTOTPGridItem
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import { Component, JSX, render } from "preact";
|
||||
import { Page } from "../../../types/Page";
|
||||
import { SecretTitleElement } from "../SecretTitleElement";
|
||||
import { getCapabilitiesPath } from "../../../api/sys/getCapabilities";
|
||||
import { getCapsPath } from "../../../api/sys/getCapabilities";
|
||||
import { getTransitKeys } from "../../../api/transit/getTransitKeys";
|
||||
import i18next from "i18next";
|
||||
|
||||
|
@ -81,7 +81,7 @@ export class TransitViewPage extends Page {
|
|||
async render(): Promise<void> {
|
||||
this.state.secretItem = "";
|
||||
|
||||
const caps = (await getCapabilitiesPath("/sys/mounts/" + this.state.baseMount)).capabilities;
|
||||
const caps = await getCapsPath("/sys/mounts/" + this.state.baseMount);
|
||||
|
||||
render(
|
||||
<>
|
||||
|
|
Loading…
Reference in a new issue