Move supportedMountTypes to own constant and lint code.
This commit is contained in:
parent
4c784d9a32
commit
c0f5f5c540
|
@ -2,7 +2,7 @@ import { Component, JSX, render } from "preact";
|
||||||
import { DoesNotExistError } from "../../../types/internalErrors";
|
import { DoesNotExistError } from "../../../types/internalErrors";
|
||||||
import { Page } from "../../../types/Page";
|
import { Page } from "../../../types/Page";
|
||||||
import { SecretTitleElement } from "../SecretTitleElement";
|
import { SecretTitleElement } from "../SecretTitleElement";
|
||||||
import { getCapabilitiesPath, getCapsPath } from "../../../api/sys/getCapabilities";
|
import { getCapabilitiesPath } from "../../../api/sys/getCapabilities";
|
||||||
import { getSecrets } from "../../../api/kv/getSecrets";
|
import { getSecrets } from "../../../api/kv/getSecrets";
|
||||||
import { setErrorText } from "../../../pageUtils";
|
import { setErrorText } from "../../../pageUtils";
|
||||||
import i18next from "i18next";
|
import i18next from "i18next";
|
||||||
|
@ -126,10 +126,7 @@ export class KeyValueViewPage extends Page {
|
||||||
async render(): Promise<void> {
|
async render(): Promise<void> {
|
||||||
const mountsPath = "/sys/mounts/" + this.state.baseMount;
|
const mountsPath = "/sys/mounts/" + this.state.baseMount;
|
||||||
const currentPath = this.state.baseMount + this.state.secretPath.join("/");
|
const currentPath = this.state.baseMount + this.state.secretPath.join("/");
|
||||||
const caps = await getCapabilitiesPath([
|
const caps = await getCapabilitiesPath([mountsPath, currentPath]);
|
||||||
mountsPath,
|
|
||||||
currentPath
|
|
||||||
]);
|
|
||||||
const mountCaps = caps[mountsPath];
|
const mountCaps = caps[mountsPath];
|
||||||
const pathCaps = caps[currentPath];
|
const pathCaps = caps[currentPath];
|
||||||
|
|
||||||
|
|
|
@ -12,11 +12,13 @@ export type MountLinkProps = {
|
||||||
baseMount: string;
|
baseMount: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const supportedMountTypes = ["kv", "totp", "transit", "cubbyhole"];
|
||||||
|
|
||||||
export function isSupportedMount(mount: MountType): boolean {
|
export function isSupportedMount(mount: MountType): boolean {
|
||||||
if (typeof mount != "object") return false;
|
if (typeof mount != "object") return false;
|
||||||
if (mount == null) return false;
|
if (mount == null) return false;
|
||||||
if (!("type" in mount)) 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;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -81,10 +81,7 @@ export class TOTPViewPage extends Page {
|
||||||
this.state.secretItem = "";
|
this.state.secretItem = "";
|
||||||
|
|
||||||
const mountsPath = "/sys/mounts/" + this.state.baseMount;
|
const mountsPath = "/sys/mounts/" + this.state.baseMount;
|
||||||
const caps = await getCapabilitiesPath([
|
const caps = await getCapabilitiesPath([mountsPath, this.state.baseMount]);
|
||||||
mountsPath,
|
|
||||||
this.state.baseMount,
|
|
||||||
]);
|
|
||||||
const mountCaps = caps[mountsPath];
|
const mountCaps = caps[mountsPath];
|
||||||
const totpCaps = caps[this.state.baseMount];
|
const totpCaps = caps[this.state.baseMount];
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import { Component, JSX, render } from "preact";
|
import { Component, JSX, render } from "preact";
|
||||||
import { Page } from "../../../types/Page";
|
import { Page } from "../../../types/Page";
|
||||||
import { SecretTitleElement } from "../SecretTitleElement";
|
import { SecretTitleElement } from "../SecretTitleElement";
|
||||||
import { getCapabilitiesPath, getCapsPath } from "../../../api/sys/getCapabilities";
|
import { getCapabilitiesPath } from "../../../api/sys/getCapabilities";
|
||||||
import { getTransitKeys } from "../../../api/transit/getTransitKeys";
|
import { getTransitKeys } from "../../../api/transit/getTransitKeys";
|
||||||
import i18next from "i18next";
|
import i18next from "i18next";
|
||||||
|
|
||||||
|
@ -82,10 +82,7 @@ export class TransitViewPage extends Page {
|
||||||
this.state.secretItem = "";
|
this.state.secretItem = "";
|
||||||
|
|
||||||
const mountsPath = "/sys/mounts/" + this.state.baseMount;
|
const mountsPath = "/sys/mounts/" + this.state.baseMount;
|
||||||
const caps = await getCapabilitiesPath([
|
const caps = await getCapabilitiesPath([mountsPath, this.state.baseMount]);
|
||||||
mountsPath,
|
|
||||||
this.state.baseMount,
|
|
||||||
]);
|
|
||||||
const mountCaps = caps[mountsPath];
|
const mountCaps = caps[mountsPath];
|
||||||
const transitCaps = caps[this.state.baseMount];
|
const transitCaps = caps[this.state.baseMount];
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue