From 027379356981561b607bc056bdc88d3478884220 Mon Sep 17 00:00:00 2001 From: Kitteh Date: Thu, 20 May 2021 14:12:12 +0100 Subject: [PATCH] Rename some pageState things. --- src/PageState.ts | 57 +++++++++---------- src/api/kv/createOrUpdateSecret.ts | 4 +- src/api/kv/deleteSecret.ts | 6 +- src/api/kv/getSecret.ts | 6 +- src/api/kv/getSecrets.ts | 4 +- src/main.ts | 2 +- src/pages/Access/Auth/AuthHome.ts | 6 +- src/pages/Access/Auth/AuthViewConfig.ts | 4 +- .../Access/Auth/userpass/UserPassUsersList.ts | 2 +- src/pages/Home.ts | 8 +-- src/pages/Secrets/KeyValue/KeyValueDelete.ts | 16 +++--- src/pages/Secrets/KeyValue/KeyValueNew.ts | 8 +-- src/pages/Secrets/KeyValue/KeyValueSecret.ts | 47 +++++++-------- .../Secrets/KeyValue/KeyValueSecretsEdit.ts | 16 +++--- .../Secrets/KeyValue/KeyValueVersions.ts | 12 ++-- src/pages/Secrets/KeyValue/KeyValueView.ts | 20 +++---- src/pages/Secrets/NewEngines/NewKVEngine.ts | 4 +- src/pages/Secrets/NewEngines/NewTOTPEngine.ts | 4 +- .../Secrets/NewEngines/NewTransitEngine.ts | 4 +- src/pages/Secrets/SecretTitleElement.ts | 32 +++++------ src/pages/Secrets/SecretsHome.ts | 14 ++--- src/pages/Secrets/TOTP/NewTOTP.ts | 2 +- src/pages/Secrets/TOTP/TOTPView.ts | 4 +- src/pages/Secrets/Transit/NewTransitKey.ts | 4 +- src/pages/Secrets/Transit/TransitDecrypt.ts | 2 +- src/pages/Secrets/Transit/TransitEncrypt.ts | 2 +- src/pages/Secrets/Transit/TransitRewrap.ts | 4 +- src/pages/Secrets/Transit/TransitView.ts | 6 +- .../Secrets/Transit/TransitViewSecret.ts | 2 +- 29 files changed, 150 insertions(+), 152 deletions(-) diff --git a/src/PageState.ts b/src/PageState.ts index 03c4bd6..5b29b14 100644 --- a/src/PageState.ts +++ b/src/PageState.ts @@ -5,7 +5,7 @@ export class PageState { // NOTE: When a item in the page state isn't a string (e.g it is a array or object), // you need to add helper methods to mutate it or else it wont save. - // example: currentSecretPath is a array so when you try to .push() to it + // example: secretPath is a array so when you try to .push() to it // it will modify the object that was getted from this class // then when you try to access it again, there will be a different object. // I guess you could make another class that emulates a Array or Map @@ -42,57 +42,54 @@ export class PageState { localStorage.setItem("language", value); } - get currentBaseMount(): string { - return localStorage.getItem("currentBaseMount") || ""; + get baseMount(): string { + return localStorage.getItem("baseMount") || ""; } - set currentBaseMount(value: string) { - localStorage.setItem("currentBaseMount", value); + set baseMount(value: string) { + localStorage.setItem("baseMount", value); } // Since this is a array we can't act directly on it so we need // functions to do the same modifications. // See the note at the start o - popCurrentSecretPath(): void { - const secPath = this.currentSecretPath; + popSecretPath(): void { + const secPath = this.secretPath; secPath.pop(); - this.currentSecretPath = secPath; + this.secretPath = secPath; } - pushCurrentSecretPath(...args: string[]): void { - const secPath = this.currentSecretPath; + pushSecretPath(...args: string[]): void { + const secPath = this.secretPath; secPath.push(...args); - this.currentSecretPath = secPath; + this.secretPath = secPath; } - get currentSecretPath(): string[] { - return JSON.parse(localStorage.getItem("currentSecretPath") || "[]") as string[]; + get secretPath(): string[] { + return JSON.parse(localStorage.getItem("secretPath") || "[]") as string[]; } - set currentSecretPath(value: string[]) { - localStorage.setItem("currentSecretPath", JSON.stringify(value)); + set secretPath(value: string[]) { + localStorage.setItem("secretPath", JSON.stringify(value)); } - get currentSecretVersion(): string | null { - const result = localStorage.getItem("currentSecretVersion"); + get secretVersion(): string | null { + const result = localStorage.getItem("secretVersion"); return result != "null" ? result || null : null; } - set currentSecretVersion(value: string) { - localStorage.setItem("currentSecretVersion", String(value)); + set secretVersion(value: string) { + localStorage.setItem("secretVersion", String(value)); } - get currentSecret(): string { - return localStorage.getItem("currentSecret") || ""; + get secretItem(): string { + return localStorage.getItem("secretItem") || ""; } - set currentSecret(value: string) { - localStorage.setItem("currentSecret", value); + set secretItem(value: string) { + localStorage.setItem("secretItem", value); } - get currentMountType(): string { - return localStorage.getItem("currentMountType") || ""; + get secretMountType(): string { + return localStorage.getItem("secretMountType") || ""; } - set currentMountType(value: string) { - localStorage.setItem("currentMountType", value); - } - get currentPageString(): string { - return this.currentPage; + set secretMountType(value: string) { + localStorage.setItem("secretMountType", value); } get currentPage(): string { const curPage = localStorage.getItem("currentPage") || "HOME"; diff --git a/src/api/kv/createOrUpdateSecret.ts b/src/api/kv/createOrUpdateSecret.ts index 5d2aba4..9f9fd85 100644 --- a/src/api/kv/createOrUpdateSecret.ts +++ b/src/api/kv/createOrUpdateSecret.ts @@ -3,7 +3,7 @@ import { removeDoubleSlash } from "../../utils"; export async function createOrUpdateSecret( baseMount: string, - mountType: string, + secretMountType: string, secretPath: string[], name: string, data: Record, @@ -11,7 +11,7 @@ export async function createOrUpdateSecret( let secretURL = ""; let APIData = {}; - if (mountType == "kv-v2") { + if (secretMountType == "kv-v2") { secretURL = `/v1/${baseMount}/data/${secretPath.join("/")}/${name}`; APIData = { data: data }; } else { diff --git a/src/api/kv/deleteSecret.ts b/src/api/kv/deleteSecret.ts index 03aa3d3..b9fbfb1 100644 --- a/src/api/kv/deleteSecret.ts +++ b/src/api/kv/deleteSecret.ts @@ -3,7 +3,7 @@ import { removeDoubleSlash } from "../../utils"; export async function deleteSecret( baseMount: string, - mountType: string, + secretMountType: string, secretPath: string[], name: string, version: string | null = null, @@ -12,7 +12,7 @@ export async function deleteSecret( let request; - if (mountType == "kv-v2" && version != null) { + if (secretMountType == "kv-v2" && version != null) { secretURL = `/v1/${baseMount}/delete/${secretPath.join("")}/${name}`; secretURL = removeDoubleSlash(secretURL).replace(/\/$/, ""); request = new Request(appendAPIURL(secretURL), { @@ -24,7 +24,7 @@ export async function deleteSecret( body: version != null ? JSON.stringify({ versions: [version] }) : "{}", }); } else { - if (mountType == "kv-v2") { + if (secretMountType == "kv-v2") { secretURL = `/v1/${baseMount}/metadata/${secretPath.join("")}/${name}`; } else { secretURL = `/v1/${baseMount}/${secretPath.join("")}/${name}`; diff --git a/src/api/kv/getSecret.ts b/src/api/kv/getSecret.ts index 0f01c7b..a4c10ec 100644 --- a/src/api/kv/getSecret.ts +++ b/src/api/kv/getSecret.ts @@ -2,13 +2,13 @@ import { appendAPIURL, getHeaders } from "../apiUtils"; export async function getSecret( baseMount: string, - mountType: string, + secretMountType: string, secretPath: string[], name: string, version: string | null = null, ): Promise> { let secretURL = ""; - if (mountType == "kv-v2") { + if (secretMountType == "kv-v2") { secretURL = `/v1/${baseMount}/data/${secretPath.join("")}/${name}`; if (version != null) secretURL += `?version=${version}`; } else { @@ -20,7 +20,7 @@ export async function getSecret( const resp = await fetch(request); const data = (await resp.json()) as unknown; - if (mountType == "kv-v2") { + if (secretMountType == "kv-v2") { return (data as { data: { data: Record } }).data.data; } else { return (data as { data: Record }).data; diff --git a/src/api/kv/getSecrets.ts b/src/api/kv/getSecrets.ts index f513144..59f8b22 100644 --- a/src/api/kv/getSecrets.ts +++ b/src/api/kv/getSecrets.ts @@ -3,11 +3,11 @@ import { appendAPIURL, getHeaders } from "../apiUtils"; export async function getSecrets( baseMount: string, - mountType: string, + secretMountType: string, secretPath: string[], ): Promise { let secretURL = ""; - if (mountType == "kv-v2") { + if (secretMountType == "kv-v2") { secretURL = `/v1/${baseMount}/metadata/${secretPath.join("")}?list=true`; } else { // cubbyhole and v1 are identical diff --git a/src/main.ts b/src/main.ts index 0cc0a84..dfaf2c8 100644 --- a/src/main.ts +++ b/src/main.ts @@ -76,7 +76,7 @@ async function onLoad(): Promise { await playground(pageRouter); } - await pageRouter.changePage(pageState.currentPageString); + await pageRouter.changePage(pageState.currentPage); setInterval(async () => { if ((await pageRouter.getCurrentPageID()) != "UNSEAL") { diff --git a/src/pages/Access/Auth/AuthHome.ts b/src/pages/Access/Auth/AuthHome.ts index 434e5ad..d95de06 100644 --- a/src/pages/Access/Auth/AuthHome.ts +++ b/src/pages/Access/Auth/AuthHome.ts @@ -17,7 +17,7 @@ export function AuthListElement(page: Page, path: string, method: AuthMethod): H class: "uk-h4 uk-margin-bottom", text: path, onclick: async () => { - page.state.currentBaseMount = path; + page.state.baseMount = path; if (method.type == "userpass") { await page.router.changePage("USERPASS_USERS_LIST"); } @@ -37,7 +37,7 @@ export function AuthListElement(page: Page, path: string, method: AuthMethod): H class: "uk-button uk-button-small uk-button-primary", text: i18next.t("auth_home_view_config"), onclick: async () => { - page.state.currentBaseMount = path; + page.state.baseMount = path; await page.router.changePage("AUTH_VIEW_CONFIG"); }, }), @@ -60,7 +60,7 @@ export class AuthHomePage extends Page { await this.router.changePage("ACCESS_HOME"); } async render(): Promise { - this.state.currentSecretPath = []; + this.state.secretPath = []; const authList = objectToMap(await listAuth()) as Map; const contentElement = makeElement({ tag: "div" }); diff --git a/src/pages/Access/Auth/AuthViewConfig.ts b/src/pages/Access/Auth/AuthViewConfig.ts index 56dca32..e961ac6 100644 --- a/src/pages/Access/Auth/AuthViewConfig.ts +++ b/src/pages/Access/Auth/AuthViewConfig.ts @@ -45,10 +45,10 @@ export class AuthViewConfigPage extends Page { tableElement.appendChild(contentElement); const authList = objectToMap(await listAuth()) as Map; - const authMethod = authList.get(this.state.currentBaseMount); + const authMethod = authList.get(this.state.baseMount); contentElement.appendChild(HeaderAndContent("Type", authMethod.type)); - contentElement.appendChild(HeaderAndContent("Path", this.state.currentBaseMount)); + contentElement.appendChild(HeaderAndContent("Path", this.state.baseMount)); contentElement.appendChild(HeaderAndContent("Description", authMethod.description)); contentElement.appendChild(HeaderAndContent("Accessor", authMethod.accessor)); contentElement.appendChild(HeaderAndContent("Local", String(authMethod.local).toString())); diff --git a/src/pages/Access/Auth/userpass/UserPassUsersList.ts b/src/pages/Access/Auth/userpass/UserPassUsersList.ts index 1057bc8..d7f7648 100644 --- a/src/pages/Access/Auth/userpass/UserPassUsersList.ts +++ b/src/pages/Access/Auth/userpass/UserPassUsersList.ts @@ -16,7 +16,7 @@ export class UserPassUsersListPage extends Page { const pageContent = makeElement({ tag: "div" }); await this.router.setPageContent(pageContent); - const users = await listUserPassUsers(this.state.currentBaseMount); + const users = await listUserPassUsers(this.state.baseMount); pageContent.appendChild( makeElement({ tag: "ul", diff --git a/src/pages/Home.ts b/src/pages/Home.ts index 707c764..458aaf9 100644 --- a/src/pages/Home.ts +++ b/src/pages/Home.ts @@ -13,10 +13,10 @@ export class HomePage extends Page { await this.router.setPageContent(""); if (!(await prePageChecks(this.router))) return; - this.state.currentBaseMount = ""; - this.state.currentSecretPath = []; - this.state.currentSecret = ""; - this.state.currentSecretVersion = null; + this.state.baseMount = ""; + this.state.secretPath = []; + this.state.secretItem = ""; + this.state.secretVersion = null; const homePageContent = makeElement({ tag: "div" }); await this.router.setPageContent(homePageContent); diff --git a/src/pages/Secrets/KeyValue/KeyValueDelete.ts b/src/pages/Secrets/KeyValue/KeyValueDelete.ts index f74e662..7de8715 100644 --- a/src/pages/Secrets/KeyValue/KeyValueDelete.ts +++ b/src/pages/Secrets/KeyValue/KeyValueDelete.ts @@ -9,11 +9,11 @@ export class KeyValueDeletePage extends Page { super(); } async goBack(): Promise { - if (this.state.currentSecretVersion != null) { - this.state.currentSecretVersion = null; + if (this.state.secretVersion != null) { + this.state.secretVersion = null; await this.router.changePage("KEY_VALUE_SECRET"); } else { - this.state.currentSecret = ""; + this.state.secretItem = ""; await this.router.changePage("KEY_VALUE_VIEW"); } } @@ -32,11 +32,11 @@ export class KeyValueDeletePage extends Page { text: i18next.t("kv_delete_btn"), onclick: async () => { await deleteSecret( - this.state.currentBaseMount, - this.state.currentMountType, - this.state.currentSecretPath, - this.state.currentSecret, - this.state.currentSecretVersion, + this.state.baseMount, + this.state.secretMountType, + this.state.secretPath, + this.state.secretItem, + this.state.secretVersion, ); await this.goBack(); }, diff --git a/src/pages/Secrets/KeyValue/KeyValueNew.ts b/src/pages/Secrets/KeyValue/KeyValueNew.ts index e0c1b9e..71b5459 100644 --- a/src/pages/Secrets/KeyValue/KeyValueNew.ts +++ b/src/pages/Secrets/KeyValue/KeyValueNew.ts @@ -63,15 +63,15 @@ export class KeyValueNewPage extends Page { const path = formData.get("path") as string; let keyData = {}; - if (["kv-v1", "cubbyhole"].includes(this.state.currentMountType)) { + if (["kv-v1", "cubbyhole"].includes(this.state.secretMountType)) { keyData = { key: "value" }; } try { await createOrUpdateSecret( - this.state.currentBaseMount, - this.state.currentMountType, - this.state.currentSecretPath, + this.state.baseMount, + this.state.secretMountType, + this.state.secretPath, path, keyData, ); diff --git a/src/pages/Secrets/KeyValue/KeyValueSecret.ts b/src/pages/Secrets/KeyValue/KeyValueSecret.ts index 6abaf1e..9450ef8 100644 --- a/src/pages/Secrets/KeyValue/KeyValueSecret.ts +++ b/src/pages/Secrets/KeyValue/KeyValueSecret.ts @@ -14,11 +14,11 @@ export class KeyValueSecretPage extends Page { super(); } async goBack(): Promise { - if (this.state.currentSecretVersion != null) { - this.state.currentSecretVersion = null; + if (this.state.secretVersion != null) { + this.state.secretVersion = null; await this.router.changePage("KEY_VALUE_VERSIONS"); } else { - this.state.currentSecret = ""; + this.state.secretItem = ""; await this.router.changePage("KEY_VALUE_VIEW"); } } @@ -48,20 +48,20 @@ export class KeyValueSecretPage extends Page { const kvList = document.querySelector("#kvList"); let isSecretNestedJson = false; const caps = await getCapabilities( - this.state.currentBaseMount, - this.state.currentSecretPath, - this.state.currentSecret, + this.state.baseMount, + this.state.secretPath, + this.state.secretItem, ); if (caps.includes("delete")) { let deleteButtonText = i18next.t("kv_secret_delete_btn"); - if (this.state.currentMountType == "kv-v2" && this.state.currentSecretVersion == null) { + if (this.state.secretMountType == "kv-v2" && this.state.secretVersion == null) { deleteButtonText = i18next.t("kv_secret_delete_all_btn"); } else if ( - this.state.currentMountType == "kv-v2" && - this.state.currentSecretVersion != null + this.state.secretMountType == "kv-v2" && + this.state.secretVersion != null ) { deleteButtonText = i18next.t("kv_secret_delete_version_btn", { - version: this.state.currentSecretVersion, + version: this.state.secretVersion, }); } buttonsBlock.appendChild( @@ -77,7 +77,7 @@ export class KeyValueSecretPage extends Page { ); } if (caps.includes("update")) { - if (this.state.currentSecretVersion == null) { + if (this.state.secretVersion == null) { buttonsBlock.appendChild( makeElement({ tag: "button", @@ -91,7 +91,7 @@ export class KeyValueSecretPage extends Page { ); } } - if (this.state.currentMountType == "kv-v2") { + if (this.state.secretMountType == "kv-v2") { buttonsBlock.appendChild( makeElement({ tag: "button", @@ -106,13 +106,14 @@ export class KeyValueSecretPage extends Page { } const secretInfo = await getSecret( - this.state.currentBaseMount, - this.state.currentMountType, - this.state.currentSecretPath, - this.state.currentSecret, - this.state.currentSecretVersion, + this.state.baseMount, + this.state.secretMountType, + this.state.secretPath, + this.state.secretItem, + this.state.secretVersion, ); - if (secretInfo == null && this.state.currentMountType == "kv-v2") { + + if (secretInfo == null && this.state.secretMountType == "kv-v2") { document.querySelector("#buttonsBlock").remove(); document.getElementById("loadingText").remove(); @@ -131,12 +132,12 @@ export class KeyValueSecretPage extends Page { class: ["uk-button", "uk-button-primary"], onclick: async () => { await undeleteSecret( - this.state.currentBaseMount, - this.state.currentSecretPath, - this.state.currentSecret, - this.state.currentSecretVersion, + this.state.baseMount, + this.state.secretPath, + this.state.secretItem, + this.state.secretVersion, ); - await this.router.changePage(this.state.currentPageString); + await this.router.refresh(); }, }), ); diff --git a/src/pages/Secrets/KeyValue/KeyValueSecretsEdit.ts b/src/pages/Secrets/KeyValue/KeyValueSecretsEdit.ts index 61215a4..bfb7fac 100644 --- a/src/pages/Secrets/KeyValue/KeyValueSecretsEdit.ts +++ b/src/pages/Secrets/KeyValue/KeyValueSecretsEdit.ts @@ -45,10 +45,10 @@ export class KeyValueSecretEditPage extends Page { }), ); const secretInfo = await getSecret( - this.state.currentBaseMount, - this.state.currentMountType, - this.state.currentSecretPath, - this.state.currentSecret, + this.state.baseMount, + this.state.secretMountType, + this.state.secretPath, + this.state.secretItem, ); loadingText.remove(); @@ -65,10 +65,10 @@ export class KeyValueSecretEditPage extends Page { try { await createOrUpdateSecret( - this.state.currentBaseMount, - this.state.currentMountType, - this.state.currentSecretPath, - this.state.currentSecret, + this.state.baseMount, + this.state.secretMountType, + this.state.secretPath, + this.state.secretItem, JSON.parse(jar.toString()), ); await this.router.changePage("KEY_VALUE_SECRET"); diff --git a/src/pages/Secrets/KeyValue/KeyValueVersions.ts b/src/pages/Secrets/KeyValue/KeyValueVersions.ts index d971f00..de6ea75 100644 --- a/src/pages/Secrets/KeyValue/KeyValueVersions.ts +++ b/src/pages/Secrets/KeyValue/KeyValueVersions.ts @@ -10,8 +10,8 @@ export class KeyValueVersionsPage extends Page { super(); } async goBack(): Promise { - if (this.state.currentSecretVersion != null) { - this.state.currentSecretVersion = null; + if (this.state.secretVersion != null) { + this.state.secretVersion = null; } await this.router.changePage("KEY_VALUE_SECRET"); } @@ -24,9 +24,9 @@ export class KeyValueVersionsPage extends Page { await this.router.setPageContent(versionsList); const metadata = await getSecretMetadata( - this.state.currentBaseMount, - this.state.currentSecretPath, - this.state.currentSecret, + this.state.baseMount, + this.state.secretPath, + this.state.secretItem, ); objectToMap(metadata.versions).forEach((_, ver) => { @@ -37,7 +37,7 @@ export class KeyValueVersionsPage extends Page { tag: "a", text: `v${ver}`, onclick: async () => { - this.state.currentSecretVersion = ver; + this.state.secretVersion = ver; await this.router.changePage("KEY_VALUE_SECRET"); }, }), diff --git a/src/pages/Secrets/KeyValue/KeyValueView.ts b/src/pages/Secrets/KeyValue/KeyValueView.ts index 9651bcc..39027e7 100644 --- a/src/pages/Secrets/KeyValue/KeyValueView.ts +++ b/src/pages/Secrets/KeyValue/KeyValueView.ts @@ -11,20 +11,20 @@ export class KeyValueViewPage extends Page { super(); } async goBack(): Promise { - if (this.state.currentSecretPath.length != 0) { - this.state.popCurrentSecretPath(); + if (this.state.secretPath.length != 0) { + this.state.popSecretPath(); await this.router.changePage("KEY_VALUE_VIEW"); } else { await this.router.changePage("SECRETS_HOME"); } } async render(): Promise { - this.state.currentSecret = ""; + this.state.secretItem = ""; const kvViewPageContent = makeElement({ tag: "div" }); await this.router.setPageContent(kvViewPageContent); - if (this.state.currentMountType == "cubbyhole") { + if (this.state.secretMountType == "cubbyhole") { kvViewPageContent.appendChild( makeElement({ tag: "p", @@ -45,9 +45,9 @@ export class KeyValueViewPage extends Page { try { const res = await getSecrets( - this.state.currentBaseMount, - this.state.currentMountType, - this.state.currentSecretPath, + this.state.baseMount, + this.state.secretMountType, + this.state.secretPath, ); kvViewPageContent.appendChild( @@ -63,10 +63,10 @@ export class KeyValueViewPage extends Page { text: secret, onclick: async () => { if (secret.endsWith("/")) { - this.state.pushCurrentSecretPath(secret); + this.state.pushSecretPath(secret); await this.router.changePage("KEY_VALUE_VIEW"); } else { - this.state.currentSecret = secret; + this.state.secretItem = secret; await this.router.changePage("KEY_VALUE_SECRET"); } }, @@ -80,7 +80,7 @@ export class KeyValueViewPage extends Page { const error = e as Error; if (error == DoesNotExistError) { // getSecrets also 404's on no keys so dont go all the way back. - if (this.state.currentSecretPath.length != 0) { + if (this.state.secretPath.length != 0) { return this.goBack(); } else { kvViewPageContent.appendChild( diff --git a/src/pages/Secrets/NewEngines/NewKVEngine.ts b/src/pages/Secrets/NewEngines/NewKVEngine.ts index 0eea261..586159d 100644 --- a/src/pages/Secrets/NewEngines/NewKVEngine.ts +++ b/src/pages/Secrets/NewEngines/NewKVEngine.ts @@ -75,8 +75,8 @@ export class NewKVEnginePage extends Page { version: version, }, }); - this.state.currentMountType = "kv-v" + version; - this.state.currentBaseMount = name + "/"; + this.state.secretMountType = "kv-v" + version; + this.state.baseMount = name + "/"; await this.router.changePage("KEY_VALUE_VIEW"); } catch (e) { const error = e as Error; diff --git a/src/pages/Secrets/NewEngines/NewTOTPEngine.ts b/src/pages/Secrets/NewEngines/NewTOTPEngine.ts index 96525cf..5af2a84 100644 --- a/src/pages/Secrets/NewEngines/NewTOTPEngine.ts +++ b/src/pages/Secrets/NewEngines/NewTOTPEngine.ts @@ -57,8 +57,8 @@ export class NewTOTPEnginePage extends Page { name: name, type: "totp", }); - this.state.currentMountType = "totp"; - this.state.currentBaseMount = name + "/"; + this.state.secretMountType = "totp"; + this.state.baseMount = name + "/"; await this.router.changePage("TOTP"); } catch (e) { const error = e as Error; diff --git a/src/pages/Secrets/NewEngines/NewTransitEngine.ts b/src/pages/Secrets/NewEngines/NewTransitEngine.ts index 0ef2acb..c038b2d 100644 --- a/src/pages/Secrets/NewEngines/NewTransitEngine.ts +++ b/src/pages/Secrets/NewEngines/NewTransitEngine.ts @@ -57,8 +57,8 @@ export class NewTransitEnginePage extends Page { name: name, type: "transit", }); - this.state.currentMountType = "transit"; - this.state.currentBaseMount = name + "/"; + this.state.secretMountType = "transit"; + this.state.baseMount = name + "/"; await this.router.changePage("TRANSIT_VIEW"); } catch (e) { const error = e as Error; diff --git a/src/pages/Secrets/SecretTitleElement.ts b/src/pages/Secrets/SecretTitleElement.ts index a11e7b0..c275ecf 100644 --- a/src/pages/Secrets/SecretTitleElement.ts +++ b/src/pages/Secrets/SecretTitleElement.ts @@ -3,10 +3,10 @@ import { PageState } from "../../PageState"; import { makeElement } from "z-makeelement"; function currentTitleSecretText(state: PageState, suffix = ""): string { - let currentSecretText = state.currentSecret; - currentSecretText += suffix; - if (state.currentSecretVersion !== null) currentSecretText += ` (v${state.currentSecretVersion})`; - return currentSecretText; + let secretItemText = state.secretItem; + secretItemText += suffix; + if (state.secretVersion !== null) secretItemText += ` (v${state.secretVersion})`; + return secretItemText; } export async function SecretTitleElement(router: PageRouter, suffix = ""): Promise { @@ -16,29 +16,29 @@ export async function SecretTitleElement(router: PageRouter, suffix = ""): Promi children: [ makeElement({ tag: "a", - text: state.currentBaseMount + " ", + text: state.baseMount + " ", onclick: async () => { - state.currentSecretPath = []; - state.currentSecret = ""; - state.currentSecretVersion = null; + state.secretPath = []; + state.secretItem = ""; + state.secretVersion = null; - if (state.currentMountType.startsWith("kv") || state.currentMountType == "cubbyhole") { + if (state.secretMountType.startsWith("kv") || state.secretMountType == "cubbyhole") { await router.changePage("KEY_VALUE_VIEW"); - } else if (state.currentMountType == "totp") { + } else if (state.secretMountType == "totp") { await router.changePage("TOTP"); - } else if (state.currentMountType == "transit") { + } else if (state.secretMountType == "transit") { await router.changePage("TRANSIT_VIEW"); } }, }), - ...state.currentSecretPath.map((secretPath, index, secretPaths) => { + ...state.secretPath.map((secretPath, index, secretPaths) => { return makeElement({ tag: "a", text: secretPath + " ", onclick: async () => { - state.currentSecretVersion = null; - if (state.currentMountType.startsWith("kv")) { - state.currentSecretPath = secretPaths.slice(0, index + 1); + state.secretVersion = null; + if (state.secretMountType.startsWith("kv")) { + state.secretPath = secretPaths.slice(0, index + 1); await router.changePage("KEY_VALUE_VIEW"); } }, @@ -46,7 +46,7 @@ export async function SecretTitleElement(router: PageRouter, suffix = ""): Promi }), makeElement({ tag: "span", - condition: state.currentSecret.length != 0, + condition: state.secretItem.length != 0, text: currentTitleSecretText(state, suffix), }), ], diff --git a/src/pages/Secrets/SecretsHome.ts b/src/pages/Secrets/SecretsHome.ts index 38a2f47..ca1446b 100644 --- a/src/pages/Secrets/SecretsHome.ts +++ b/src/pages/Secrets/SecretsHome.ts @@ -34,10 +34,10 @@ export class SecretsHomePage extends Page { ); } - this.state.currentBaseMount = ""; - this.state.currentSecretPath = []; - this.state.currentSecret = ""; - this.state.currentSecretVersion = null; + this.state.baseMount = ""; + this.state.secretPath = []; + this.state.secretItem = ""; + this.state.secretVersion = null; const navList = makeElement({ tag: "ul", @@ -55,7 +55,7 @@ export class SecretsHomePage extends Page { if (!("type" in mount)) return; if (!["kv", "totp", "transit", "cubbyhole"].includes(mount.type)) return; - const mountType = mount.type == "kv" ? "kv-v" + String(mount.options.version) : mount.type; + const secretMountType = mount.type == "kv" ? "kv-v" + String(mount.options.version) : mount.type; let linkText = ""; let linkPage: string; @@ -80,8 +80,8 @@ export class SecretsHomePage extends Page { tag: "a", text: linkText, onclick: async () => { - this.state.currentBaseMount = baseMount; - this.state.currentMountType = mountType; + this.state.baseMount = baseMount; + this.state.secretMountType = secretMountType; await this.router.changePage(linkPage); }, }), diff --git a/src/pages/Secrets/TOTP/NewTOTP.ts b/src/pages/Secrets/TOTP/NewTOTP.ts index 6e4970d..7050a5f 100644 --- a/src/pages/Secrets/TOTP/NewTOTP.ts +++ b/src/pages/Secrets/TOTP/NewTOTP.ts @@ -97,7 +97,7 @@ export class NewTOTPPage extends Page { }; try { - await addNewTOTP(this.state.currentBaseMount, parms); + await addNewTOTP(this.state.baseMount, parms); await this.router.changePage("TOTP"); } catch (e: unknown) { const error = e as Error; diff --git a/src/pages/Secrets/TOTP/TOTPView.ts b/src/pages/Secrets/TOTP/TOTPView.ts index c6de492..4bf7c6f 100644 --- a/src/pages/Secrets/TOTP/TOTPView.ts +++ b/src/pages/Secrets/TOTP/TOTPView.ts @@ -54,7 +54,7 @@ export class TOTPViewPage extends Page { ); try { - const res = await getTOTPKeys(this.state.currentBaseMount); + const res = await getTOTPKeys(this.state.baseMount); for (const totpKeyName of res) { const totpListElement = this.makeTOTPListElement(totpKeyName); totpList.appendChild(totpListElement); @@ -91,7 +91,7 @@ export class TOTPViewPage extends Page { } async updateTOTPElement(totpKeyName: string, totpListElement: TOTPListElement): Promise { - totpListElement.setCode(await getTOTPCode(this.state.currentBaseMount, totpKeyName)); + totpListElement.setCode(await getTOTPCode(this.state.baseMount, totpKeyName)); } makeTOTPListElement(totpKeyName: string): TOTPListElement { diff --git a/src/pages/Secrets/Transit/NewTransitKey.ts b/src/pages/Secrets/Transit/NewTransitKey.ts index 8b34b09..8d9d0c4 100644 --- a/src/pages/Secrets/Transit/NewTransitKey.ts +++ b/src/pages/Secrets/Transit/NewTransitKey.ts @@ -74,11 +74,11 @@ export class NewTransitKeyPage extends Page { const type = formData.get("type") as string; try { - await newTransitKey(this.state.currentBaseMount, { + await newTransitKey(this.state.baseMount, { name: name, type: type, }); - this.state.currentSecret = name; + this.state.secretItem = name; await this.router.changePage("TRANSIT_VIEW_SECRET"); } catch (e) { const error = e as Error; diff --git a/src/pages/Secrets/Transit/TransitDecrypt.ts b/src/pages/Secrets/Transit/TransitDecrypt.ts index e281cd0..e13b8d9 100644 --- a/src/pages/Secrets/Transit/TransitDecrypt.ts +++ b/src/pages/Secrets/Transit/TransitDecrypt.ts @@ -96,7 +96,7 @@ export class TransitDecryptPage extends Page { } try { - const res = await transitDecrypt(this.state.currentBaseMount, this.state.currentSecret, { + const res = await transitDecrypt(this.state.baseMount, this.state.secretItem, { ciphertext: ciphertext, }); let plaintext = res.plaintext; diff --git a/src/pages/Secrets/Transit/TransitEncrypt.ts b/src/pages/Secrets/Transit/TransitEncrypt.ts index 3d6879a..4a160c4 100644 --- a/src/pages/Secrets/Transit/TransitEncrypt.ts +++ b/src/pages/Secrets/Transit/TransitEncrypt.ts @@ -98,7 +98,7 @@ export class TransitEncryptPage extends Page { } try { - const res = await transitEncrypt(this.state.currentBaseMount, this.state.currentSecret, { + const res = await transitEncrypt(this.state.baseMount, this.state.secretItem, { plaintext: plaintext, }); const modal = CopyableModal( diff --git a/src/pages/Secrets/Transit/TransitRewrap.ts b/src/pages/Secrets/Transit/TransitRewrap.ts index 0f74315..94e4c87 100644 --- a/src/pages/Secrets/Transit/TransitRewrap.ts +++ b/src/pages/Secrets/Transit/TransitRewrap.ts @@ -24,7 +24,7 @@ export class TransitRewrapPage extends Page { transitRewrapForm: HTMLFormElement; async render(): Promise { - const transitKey = await getTransitKey(this.state.currentBaseMount, this.state.currentSecret); + const transitKey = await getTransitKey(this.state.baseMount, this.state.secretItem); const stringVersions = Array.from( objectToMap(transitKey.keys).keys(), @@ -92,7 +92,7 @@ export class TransitRewrapPage extends Page { async transitRewrapFormHandler(): Promise { const formData = new FormData(this.transitRewrapForm); try { - const res = await transitRewrap(this.state.currentBaseMount, this.state.currentSecret, { + const res = await transitRewrap(this.state.baseMount, this.state.secretItem, { ciphertext: formData.get("ciphertext") as string, key_version: parseInt(formData.get("version") as string, 10), }); diff --git a/src/pages/Secrets/Transit/TransitView.ts b/src/pages/Secrets/Transit/TransitView.ts index 8a96dd3..7b4af87 100644 --- a/src/pages/Secrets/Transit/TransitView.ts +++ b/src/pages/Secrets/Transit/TransitView.ts @@ -16,7 +16,7 @@ export class TransitViewPage extends Page { } async render(): Promise { - this.state.currentSecret = ""; + this.state.secretItem = ""; const transitViewContent = makeElement({ tag: "div" }); await this.router.setPageContent(transitViewContent); @@ -32,7 +32,7 @@ export class TransitViewPage extends Page { transitViewContent.appendChild(newButton); try { - const res = await getTransitKeys(this.state.currentBaseMount); + const res = await getTransitKeys(this.state.baseMount); transitViewContent.appendChild( makeElement({ @@ -46,7 +46,7 @@ export class TransitViewPage extends Page { tag: "a", text: secret, onclick: async () => { - this.state.currentSecret = secret; + this.state.secretItem = secret; await this.router.changePage("TRANSIT_VIEW_SECRET"); }, }), diff --git a/src/pages/Secrets/Transit/TransitViewSecret.ts b/src/pages/Secrets/Transit/TransitViewSecret.ts index 3d8fc14..f737fbe 100644 --- a/src/pages/Secrets/Transit/TransitViewSecret.ts +++ b/src/pages/Secrets/Transit/TransitViewSecret.ts @@ -15,7 +15,7 @@ export class TransitViewSecretPage extends Page { } async render(): Promise { - const transitKey = await getTransitKey(this.state.currentBaseMount, this.state.currentSecret); + const transitKey = await getTransitKey(this.state.baseMount, this.state.secretItem); await this.router.setPageContent( makeElement({