1
0
Fork 0

Move supportedMountTypes to own constant and lint code.

This commit is contained in:
Kitteh 2021-05-31 10:29:36 +01:00
parent 4c784d9a32
commit c0f5f5c540
4 changed files with 8 additions and 15 deletions

View file

@ -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, getCapsPath } from "../../../api/sys/getCapabilities";
import { getCapabilitiesPath } from "../../../api/sys/getCapabilities";
import { getSecrets } from "../../../api/kv/getSecrets";
import { setErrorText } from "../../../pageUtils";
import i18next from "i18next";
@ -126,10 +126,7 @@ export class KeyValueViewPage extends Page {
async render(): Promise<void> {
const mountsPath = "/sys/mounts/" + this.state.baseMount;
const currentPath = this.state.baseMount + this.state.secretPath.join("/");
const caps = await getCapabilitiesPath([
mountsPath,
currentPath
]);
const caps = await getCapabilitiesPath([mountsPath, currentPath]);
const mountCaps = caps[mountsPath];
const pathCaps = caps[currentPath];

View file

@ -12,11 +12,13 @@ export type MountLinkProps = {
baseMount: string;
};
const supportedMountTypes = ["kv", "totp", "transit", "cubbyhole"];
export function isSupportedMount(mount: MountType): boolean {
if (typeof mount != "object") return false;
if (mount == null) return false;
if (!("type" in mount)) return false;
if (!["kv", "totp", "transit", "cubbyhole"].includes(mount.type)) return false;
if (!supportedMountTypes.includes(mount.type)) return false;
return true;
}

View file

@ -81,10 +81,7 @@ export class TOTPViewPage extends Page {
this.state.secretItem = "";
const mountsPath = "/sys/mounts/" + this.state.baseMount;
const caps = await getCapabilitiesPath([
mountsPath,
this.state.baseMount,
]);
const caps = await getCapabilitiesPath([mountsPath, this.state.baseMount]);
const mountCaps = caps[mountsPath];
const totpCaps = caps[this.state.baseMount];

View file

@ -1,7 +1,7 @@
import { Component, JSX, render } from "preact";
import { Page } from "../../../types/Page";
import { SecretTitleElement } from "../SecretTitleElement";
import { getCapabilitiesPath, getCapsPath } from "../../../api/sys/getCapabilities";
import { getCapabilitiesPath } from "../../../api/sys/getCapabilities";
import { getTransitKeys } from "../../../api/transit/getTransitKeys";
import i18next from "i18next";
@ -82,10 +82,7 @@ export class TransitViewPage extends Page {
this.state.secretItem = "";
const mountsPath = "/sys/mounts/" + this.state.baseMount;
const caps = await getCapabilitiesPath([
mountsPath,
this.state.baseMount,
]);
const caps = await getCapabilitiesPath([mountsPath, this.state.baseMount]);
const mountCaps = caps[mountsPath];
const transitCaps = caps[this.state.baseMount];