From c0f5f5c54075fd52c6602f22d3b4dbbc37ec0d62 Mon Sep 17 00:00:00 2001 From: Kitteh Date: Mon, 31 May 2021 10:29:36 +0100 Subject: [PATCH] Move supportedMountTypes to own constant and lint code. --- src/pages/Secrets/KeyValue/KeyValueView.tsx | 7 ++----- src/pages/Secrets/SecretsHome.tsx | 4 +++- src/pages/Secrets/TOTP/TOTPView.tsx | 5 +---- src/pages/Secrets/Transit/TransitView.tsx | 7 ++----- 4 files changed, 8 insertions(+), 15 deletions(-) diff --git a/src/pages/Secrets/KeyValue/KeyValueView.tsx b/src/pages/Secrets/KeyValue/KeyValueView.tsx index ee29ae9..5566fad 100644 --- a/src/pages/Secrets/KeyValue/KeyValueView.tsx +++ b/src/pages/Secrets/KeyValue/KeyValueView.tsx @@ -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 { 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]; diff --git a/src/pages/Secrets/SecretsHome.tsx b/src/pages/Secrets/SecretsHome.tsx index bbf9806..fdf2b50 100644 --- a/src/pages/Secrets/SecretsHome.tsx +++ b/src/pages/Secrets/SecretsHome.tsx @@ -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; } diff --git a/src/pages/Secrets/TOTP/TOTPView.tsx b/src/pages/Secrets/TOTP/TOTPView.tsx index 8fb4957..c9d2a60 100644 --- a/src/pages/Secrets/TOTP/TOTPView.tsx +++ b/src/pages/Secrets/TOTP/TOTPView.tsx @@ -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]; diff --git a/src/pages/Secrets/Transit/TransitView.tsx b/src/pages/Secrets/Transit/TransitView.tsx index b453fcb..0bebc4d 100644 --- a/src/pages/Secrets/Transit/TransitView.tsx +++ b/src/pages/Secrets/Transit/TransitView.tsx @@ -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];