Rename some pageState things.
This commit is contained in:
parent
555825787c
commit
0273793569
|
@ -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),
|
// 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.
|
// 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
|
// 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.
|
// 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
|
// I guess you could make another class that emulates a Array or Map
|
||||||
|
@ -42,57 +42,54 @@ export class PageState {
|
||||||
localStorage.setItem("language", value);
|
localStorage.setItem("language", value);
|
||||||
}
|
}
|
||||||
|
|
||||||
get currentBaseMount(): string {
|
get baseMount(): string {
|
||||||
return localStorage.getItem("currentBaseMount") || "";
|
return localStorage.getItem("baseMount") || "";
|
||||||
}
|
}
|
||||||
set currentBaseMount(value: string) {
|
set baseMount(value: string) {
|
||||||
localStorage.setItem("currentBaseMount", value);
|
localStorage.setItem("baseMount", value);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Since this is a array we can't act directly on it so we need
|
// Since this is a array we can't act directly on it so we need
|
||||||
// functions to do the same modifications.
|
// functions to do the same modifications.
|
||||||
// See the note at the start o
|
// See the note at the start o
|
||||||
popCurrentSecretPath(): void {
|
popSecretPath(): void {
|
||||||
const secPath = this.currentSecretPath;
|
const secPath = this.secretPath;
|
||||||
secPath.pop();
|
secPath.pop();
|
||||||
this.currentSecretPath = secPath;
|
this.secretPath = secPath;
|
||||||
}
|
}
|
||||||
pushCurrentSecretPath(...args: string[]): void {
|
pushSecretPath(...args: string[]): void {
|
||||||
const secPath = this.currentSecretPath;
|
const secPath = this.secretPath;
|
||||||
secPath.push(...args);
|
secPath.push(...args);
|
||||||
this.currentSecretPath = secPath;
|
this.secretPath = secPath;
|
||||||
}
|
}
|
||||||
|
|
||||||
get currentSecretPath(): string[] {
|
get secretPath(): string[] {
|
||||||
return JSON.parse(localStorage.getItem("currentSecretPath") || "[]") as string[];
|
return JSON.parse(localStorage.getItem("secretPath") || "[]") as string[];
|
||||||
}
|
}
|
||||||
set currentSecretPath(value: string[]) {
|
set secretPath(value: string[]) {
|
||||||
localStorage.setItem("currentSecretPath", JSON.stringify(value));
|
localStorage.setItem("secretPath", JSON.stringify(value));
|
||||||
}
|
}
|
||||||
|
|
||||||
get currentSecretVersion(): string | null {
|
get secretVersion(): string | null {
|
||||||
const result = localStorage.getItem("currentSecretVersion");
|
const result = localStorage.getItem("secretVersion");
|
||||||
return result != "null" ? result || null : null;
|
return result != "null" ? result || null : null;
|
||||||
}
|
}
|
||||||
set currentSecretVersion(value: string) {
|
set secretVersion(value: string) {
|
||||||
localStorage.setItem("currentSecretVersion", String(value));
|
localStorage.setItem("secretVersion", String(value));
|
||||||
}
|
}
|
||||||
|
|
||||||
get currentSecret(): string {
|
get secretItem(): string {
|
||||||
return localStorage.getItem("currentSecret") || "";
|
return localStorage.getItem("secretItem") || "";
|
||||||
}
|
}
|
||||||
set currentSecret(value: string) {
|
set secretItem(value: string) {
|
||||||
localStorage.setItem("currentSecret", value);
|
localStorage.setItem("secretItem", value);
|
||||||
}
|
}
|
||||||
|
|
||||||
get currentMountType(): string {
|
get secretMountType(): string {
|
||||||
return localStorage.getItem("currentMountType") || "";
|
return localStorage.getItem("secretMountType") || "";
|
||||||
}
|
}
|
||||||
set currentMountType(value: string) {
|
set secretMountType(value: string) {
|
||||||
localStorage.setItem("currentMountType", value);
|
localStorage.setItem("secretMountType", value);
|
||||||
}
|
|
||||||
get currentPageString(): string {
|
|
||||||
return this.currentPage;
|
|
||||||
}
|
}
|
||||||
get currentPage(): string {
|
get currentPage(): string {
|
||||||
const curPage = localStorage.getItem("currentPage") || "HOME";
|
const curPage = localStorage.getItem("currentPage") || "HOME";
|
||||||
|
|
|
@ -3,7 +3,7 @@ import { removeDoubleSlash } from "../../utils";
|
||||||
|
|
||||||
export async function createOrUpdateSecret(
|
export async function createOrUpdateSecret(
|
||||||
baseMount: string,
|
baseMount: string,
|
||||||
mountType: string,
|
secretMountType: string,
|
||||||
secretPath: string[],
|
secretPath: string[],
|
||||||
name: string,
|
name: string,
|
||||||
data: Record<string, unknown>,
|
data: Record<string, unknown>,
|
||||||
|
@ -11,7 +11,7 @@ export async function createOrUpdateSecret(
|
||||||
let secretURL = "";
|
let secretURL = "";
|
||||||
let APIData = {};
|
let APIData = {};
|
||||||
|
|
||||||
if (mountType == "kv-v2") {
|
if (secretMountType == "kv-v2") {
|
||||||
secretURL = `/v1/${baseMount}/data/${secretPath.join("/")}/${name}`;
|
secretURL = `/v1/${baseMount}/data/${secretPath.join("/")}/${name}`;
|
||||||
APIData = { data: data };
|
APIData = { data: data };
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -3,7 +3,7 @@ import { removeDoubleSlash } from "../../utils";
|
||||||
|
|
||||||
export async function deleteSecret(
|
export async function deleteSecret(
|
||||||
baseMount: string,
|
baseMount: string,
|
||||||
mountType: string,
|
secretMountType: string,
|
||||||
secretPath: string[],
|
secretPath: string[],
|
||||||
name: string,
|
name: string,
|
||||||
version: string | null = null,
|
version: string | null = null,
|
||||||
|
@ -12,7 +12,7 @@ export async function deleteSecret(
|
||||||
|
|
||||||
let request;
|
let request;
|
||||||
|
|
||||||
if (mountType == "kv-v2" && version != null) {
|
if (secretMountType == "kv-v2" && version != null) {
|
||||||
secretURL = `/v1/${baseMount}/delete/${secretPath.join("")}/${name}`;
|
secretURL = `/v1/${baseMount}/delete/${secretPath.join("")}/${name}`;
|
||||||
secretURL = removeDoubleSlash(secretURL).replace(/\/$/, "");
|
secretURL = removeDoubleSlash(secretURL).replace(/\/$/, "");
|
||||||
request = new Request(appendAPIURL(secretURL), {
|
request = new Request(appendAPIURL(secretURL), {
|
||||||
|
@ -24,7 +24,7 @@ export async function deleteSecret(
|
||||||
body: version != null ? JSON.stringify({ versions: [version] }) : "{}",
|
body: version != null ? JSON.stringify({ versions: [version] }) : "{}",
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
if (mountType == "kv-v2") {
|
if (secretMountType == "kv-v2") {
|
||||||
secretURL = `/v1/${baseMount}/metadata/${secretPath.join("")}/${name}`;
|
secretURL = `/v1/${baseMount}/metadata/${secretPath.join("")}/${name}`;
|
||||||
} else {
|
} else {
|
||||||
secretURL = `/v1/${baseMount}/${secretPath.join("")}/${name}`;
|
secretURL = `/v1/${baseMount}/${secretPath.join("")}/${name}`;
|
||||||
|
|
|
@ -2,13 +2,13 @@ import { appendAPIURL, getHeaders } from "../apiUtils";
|
||||||
|
|
||||||
export async function getSecret(
|
export async function getSecret(
|
||||||
baseMount: string,
|
baseMount: string,
|
||||||
mountType: string,
|
secretMountType: string,
|
||||||
secretPath: string[],
|
secretPath: string[],
|
||||||
name: string,
|
name: string,
|
||||||
version: string | null = null,
|
version: string | null = null,
|
||||||
): Promise<Record<string, unknown>> {
|
): Promise<Record<string, unknown>> {
|
||||||
let secretURL = "";
|
let secretURL = "";
|
||||||
if (mountType == "kv-v2") {
|
if (secretMountType == "kv-v2") {
|
||||||
secretURL = `/v1/${baseMount}/data/${secretPath.join("")}/${name}`;
|
secretURL = `/v1/${baseMount}/data/${secretPath.join("")}/${name}`;
|
||||||
if (version != null) secretURL += `?version=${version}`;
|
if (version != null) secretURL += `?version=${version}`;
|
||||||
} else {
|
} else {
|
||||||
|
@ -20,7 +20,7 @@ export async function getSecret(
|
||||||
|
|
||||||
const resp = await fetch(request);
|
const resp = await fetch(request);
|
||||||
const data = (await resp.json()) as unknown;
|
const data = (await resp.json()) as unknown;
|
||||||
if (mountType == "kv-v2") {
|
if (secretMountType == "kv-v2") {
|
||||||
return (data as { data: { data: Record<string, unknown> } }).data.data;
|
return (data as { data: { data: Record<string, unknown> } }).data.data;
|
||||||
} else {
|
} else {
|
||||||
return (data as { data: Record<string, unknown> }).data;
|
return (data as { data: Record<string, unknown> }).data;
|
||||||
|
|
|
@ -3,11 +3,11 @@ import { appendAPIURL, getHeaders } from "../apiUtils";
|
||||||
|
|
||||||
export async function getSecrets(
|
export async function getSecrets(
|
||||||
baseMount: string,
|
baseMount: string,
|
||||||
mountType: string,
|
secretMountType: string,
|
||||||
secretPath: string[],
|
secretPath: string[],
|
||||||
): Promise<string[]> {
|
): Promise<string[]> {
|
||||||
let secretURL = "";
|
let secretURL = "";
|
||||||
if (mountType == "kv-v2") {
|
if (secretMountType == "kv-v2") {
|
||||||
secretURL = `/v1/${baseMount}/metadata/${secretPath.join("")}?list=true`;
|
secretURL = `/v1/${baseMount}/metadata/${secretPath.join("")}?list=true`;
|
||||||
} else {
|
} else {
|
||||||
// cubbyhole and v1 are identical
|
// cubbyhole and v1 are identical
|
||||||
|
|
|
@ -76,7 +76,7 @@ async function onLoad(): Promise<void> {
|
||||||
await playground(pageRouter);
|
await playground(pageRouter);
|
||||||
}
|
}
|
||||||
|
|
||||||
await pageRouter.changePage(pageState.currentPageString);
|
await pageRouter.changePage(pageState.currentPage);
|
||||||
|
|
||||||
setInterval(async () => {
|
setInterval(async () => {
|
||||||
if ((await pageRouter.getCurrentPageID()) != "UNSEAL") {
|
if ((await pageRouter.getCurrentPageID()) != "UNSEAL") {
|
||||||
|
|
|
@ -17,7 +17,7 @@ export function AuthListElement(page: Page, path: string, method: AuthMethod): H
|
||||||
class: "uk-h4 uk-margin-bottom",
|
class: "uk-h4 uk-margin-bottom",
|
||||||
text: path,
|
text: path,
|
||||||
onclick: async () => {
|
onclick: async () => {
|
||||||
page.state.currentBaseMount = path;
|
page.state.baseMount = path;
|
||||||
if (method.type == "userpass") {
|
if (method.type == "userpass") {
|
||||||
await page.router.changePage("USERPASS_USERS_LIST");
|
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",
|
class: "uk-button uk-button-small uk-button-primary",
|
||||||
text: i18next.t("auth_home_view_config"),
|
text: i18next.t("auth_home_view_config"),
|
||||||
onclick: async () => {
|
onclick: async () => {
|
||||||
page.state.currentBaseMount = path;
|
page.state.baseMount = path;
|
||||||
await page.router.changePage("AUTH_VIEW_CONFIG");
|
await page.router.changePage("AUTH_VIEW_CONFIG");
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
|
@ -60,7 +60,7 @@ export class AuthHomePage extends Page {
|
||||||
await this.router.changePage("ACCESS_HOME");
|
await this.router.changePage("ACCESS_HOME");
|
||||||
}
|
}
|
||||||
async render(): Promise<void> {
|
async render(): Promise<void> {
|
||||||
this.state.currentSecretPath = [];
|
this.state.secretPath = [];
|
||||||
|
|
||||||
const authList = objectToMap(await listAuth()) as Map<string, AuthMethod>;
|
const authList = objectToMap(await listAuth()) as Map<string, AuthMethod>;
|
||||||
const contentElement = makeElement({ tag: "div" });
|
const contentElement = makeElement({ tag: "div" });
|
||||||
|
|
|
@ -45,10 +45,10 @@ export class AuthViewConfigPage extends Page {
|
||||||
tableElement.appendChild(contentElement);
|
tableElement.appendChild(contentElement);
|
||||||
|
|
||||||
const authList = objectToMap(await listAuth()) as Map<string, AuthMethod>;
|
const authList = objectToMap(await listAuth()) as Map<string, AuthMethod>;
|
||||||
const authMethod = authList.get(this.state.currentBaseMount);
|
const authMethod = authList.get(this.state.baseMount);
|
||||||
|
|
||||||
contentElement.appendChild(HeaderAndContent("Type", authMethod.type));
|
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("Description", authMethod.description));
|
||||||
contentElement.appendChild(HeaderAndContent("Accessor", authMethod.accessor));
|
contentElement.appendChild(HeaderAndContent("Accessor", authMethod.accessor));
|
||||||
contentElement.appendChild(HeaderAndContent("Local", String(authMethod.local).toString()));
|
contentElement.appendChild(HeaderAndContent("Local", String(authMethod.local).toString()));
|
||||||
|
|
|
@ -16,7 +16,7 @@ export class UserPassUsersListPage extends Page {
|
||||||
const pageContent = makeElement({ tag: "div" });
|
const pageContent = makeElement({ tag: "div" });
|
||||||
await this.router.setPageContent(pageContent);
|
await this.router.setPageContent(pageContent);
|
||||||
|
|
||||||
const users = await listUserPassUsers(this.state.currentBaseMount);
|
const users = await listUserPassUsers(this.state.baseMount);
|
||||||
pageContent.appendChild(
|
pageContent.appendChild(
|
||||||
makeElement({
|
makeElement({
|
||||||
tag: "ul",
|
tag: "ul",
|
||||||
|
|
|
@ -13,10 +13,10 @@ export class HomePage extends Page {
|
||||||
await this.router.setPageContent("");
|
await this.router.setPageContent("");
|
||||||
if (!(await prePageChecks(this.router))) return;
|
if (!(await prePageChecks(this.router))) return;
|
||||||
|
|
||||||
this.state.currentBaseMount = "";
|
this.state.baseMount = "";
|
||||||
this.state.currentSecretPath = [];
|
this.state.secretPath = [];
|
||||||
this.state.currentSecret = "";
|
this.state.secretItem = "";
|
||||||
this.state.currentSecretVersion = null;
|
this.state.secretVersion = null;
|
||||||
|
|
||||||
const homePageContent = makeElement({ tag: "div" });
|
const homePageContent = makeElement({ tag: "div" });
|
||||||
await this.router.setPageContent(homePageContent);
|
await this.router.setPageContent(homePageContent);
|
||||||
|
|
|
@ -9,11 +9,11 @@ export class KeyValueDeletePage extends Page {
|
||||||
super();
|
super();
|
||||||
}
|
}
|
||||||
async goBack(): Promise<void> {
|
async goBack(): Promise<void> {
|
||||||
if (this.state.currentSecretVersion != null) {
|
if (this.state.secretVersion != null) {
|
||||||
this.state.currentSecretVersion = null;
|
this.state.secretVersion = null;
|
||||||
await this.router.changePage("KEY_VALUE_SECRET");
|
await this.router.changePage("KEY_VALUE_SECRET");
|
||||||
} else {
|
} else {
|
||||||
this.state.currentSecret = "";
|
this.state.secretItem = "";
|
||||||
await this.router.changePage("KEY_VALUE_VIEW");
|
await this.router.changePage("KEY_VALUE_VIEW");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -32,11 +32,11 @@ export class KeyValueDeletePage extends Page {
|
||||||
text: i18next.t("kv_delete_btn"),
|
text: i18next.t("kv_delete_btn"),
|
||||||
onclick: async () => {
|
onclick: async () => {
|
||||||
await deleteSecret(
|
await deleteSecret(
|
||||||
this.state.currentBaseMount,
|
this.state.baseMount,
|
||||||
this.state.currentMountType,
|
this.state.secretMountType,
|
||||||
this.state.currentSecretPath,
|
this.state.secretPath,
|
||||||
this.state.currentSecret,
|
this.state.secretItem,
|
||||||
this.state.currentSecretVersion,
|
this.state.secretVersion,
|
||||||
);
|
);
|
||||||
await this.goBack();
|
await this.goBack();
|
||||||
},
|
},
|
||||||
|
|
|
@ -63,15 +63,15 @@ export class KeyValueNewPage extends Page {
|
||||||
const path = formData.get("path") as string;
|
const path = formData.get("path") as string;
|
||||||
let keyData = {};
|
let keyData = {};
|
||||||
|
|
||||||
if (["kv-v1", "cubbyhole"].includes(this.state.currentMountType)) {
|
if (["kv-v1", "cubbyhole"].includes(this.state.secretMountType)) {
|
||||||
keyData = { key: "value" };
|
keyData = { key: "value" };
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await createOrUpdateSecret(
|
await createOrUpdateSecret(
|
||||||
this.state.currentBaseMount,
|
this.state.baseMount,
|
||||||
this.state.currentMountType,
|
this.state.secretMountType,
|
||||||
this.state.currentSecretPath,
|
this.state.secretPath,
|
||||||
path,
|
path,
|
||||||
keyData,
|
keyData,
|
||||||
);
|
);
|
||||||
|
|
|
@ -14,11 +14,11 @@ export class KeyValueSecretPage extends Page {
|
||||||
super();
|
super();
|
||||||
}
|
}
|
||||||
async goBack(): Promise<void> {
|
async goBack(): Promise<void> {
|
||||||
if (this.state.currentSecretVersion != null) {
|
if (this.state.secretVersion != null) {
|
||||||
this.state.currentSecretVersion = null;
|
this.state.secretVersion = null;
|
||||||
await this.router.changePage("KEY_VALUE_VERSIONS");
|
await this.router.changePage("KEY_VALUE_VERSIONS");
|
||||||
} else {
|
} else {
|
||||||
this.state.currentSecret = "";
|
this.state.secretItem = "";
|
||||||
await this.router.changePage("KEY_VALUE_VIEW");
|
await this.router.changePage("KEY_VALUE_VIEW");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -48,20 +48,20 @@ export class KeyValueSecretPage extends Page {
|
||||||
const kvList = document.querySelector("#kvList");
|
const kvList = document.querySelector("#kvList");
|
||||||
let isSecretNestedJson = false;
|
let isSecretNestedJson = false;
|
||||||
const caps = await getCapabilities(
|
const caps = await getCapabilities(
|
||||||
this.state.currentBaseMount,
|
this.state.baseMount,
|
||||||
this.state.currentSecretPath,
|
this.state.secretPath,
|
||||||
this.state.currentSecret,
|
this.state.secretItem,
|
||||||
);
|
);
|
||||||
if (caps.includes("delete")) {
|
if (caps.includes("delete")) {
|
||||||
let deleteButtonText = i18next.t("kv_secret_delete_btn");
|
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");
|
deleteButtonText = i18next.t("kv_secret_delete_all_btn");
|
||||||
} else if (
|
} else if (
|
||||||
this.state.currentMountType == "kv-v2" &&
|
this.state.secretMountType == "kv-v2" &&
|
||||||
this.state.currentSecretVersion != null
|
this.state.secretVersion != null
|
||||||
) {
|
) {
|
||||||
deleteButtonText = i18next.t("kv_secret_delete_version_btn", {
|
deleteButtonText = i18next.t("kv_secret_delete_version_btn", {
|
||||||
version: this.state.currentSecretVersion,
|
version: this.state.secretVersion,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
buttonsBlock.appendChild(
|
buttonsBlock.appendChild(
|
||||||
|
@ -77,7 +77,7 @@ export class KeyValueSecretPage extends Page {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
if (caps.includes("update")) {
|
if (caps.includes("update")) {
|
||||||
if (this.state.currentSecretVersion == null) {
|
if (this.state.secretVersion == null) {
|
||||||
buttonsBlock.appendChild(
|
buttonsBlock.appendChild(
|
||||||
makeElement({
|
makeElement({
|
||||||
tag: "button",
|
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(
|
buttonsBlock.appendChild(
|
||||||
makeElement({
|
makeElement({
|
||||||
tag: "button",
|
tag: "button",
|
||||||
|
@ -106,13 +106,14 @@ export class KeyValueSecretPage extends Page {
|
||||||
}
|
}
|
||||||
|
|
||||||
const secretInfo = await getSecret(
|
const secretInfo = await getSecret(
|
||||||
this.state.currentBaseMount,
|
this.state.baseMount,
|
||||||
this.state.currentMountType,
|
this.state.secretMountType,
|
||||||
this.state.currentSecretPath,
|
this.state.secretPath,
|
||||||
this.state.currentSecret,
|
this.state.secretItem,
|
||||||
this.state.currentSecretVersion,
|
this.state.secretVersion,
|
||||||
);
|
);
|
||||||
if (secretInfo == null && this.state.currentMountType == "kv-v2") {
|
|
||||||
|
if (secretInfo == null && this.state.secretMountType == "kv-v2") {
|
||||||
document.querySelector("#buttonsBlock").remove();
|
document.querySelector("#buttonsBlock").remove();
|
||||||
document.getElementById("loadingText").remove();
|
document.getElementById("loadingText").remove();
|
||||||
|
|
||||||
|
@ -131,12 +132,12 @@ export class KeyValueSecretPage extends Page {
|
||||||
class: ["uk-button", "uk-button-primary"],
|
class: ["uk-button", "uk-button-primary"],
|
||||||
onclick: async () => {
|
onclick: async () => {
|
||||||
await undeleteSecret(
|
await undeleteSecret(
|
||||||
this.state.currentBaseMount,
|
this.state.baseMount,
|
||||||
this.state.currentSecretPath,
|
this.state.secretPath,
|
||||||
this.state.currentSecret,
|
this.state.secretItem,
|
||||||
this.state.currentSecretVersion,
|
this.state.secretVersion,
|
||||||
);
|
);
|
||||||
await this.router.changePage(this.state.currentPageString);
|
await this.router.refresh();
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
|
|
|
@ -45,10 +45,10 @@ export class KeyValueSecretEditPage extends Page {
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
const secretInfo = await getSecret(
|
const secretInfo = await getSecret(
|
||||||
this.state.currentBaseMount,
|
this.state.baseMount,
|
||||||
this.state.currentMountType,
|
this.state.secretMountType,
|
||||||
this.state.currentSecretPath,
|
this.state.secretPath,
|
||||||
this.state.currentSecret,
|
this.state.secretItem,
|
||||||
);
|
);
|
||||||
|
|
||||||
loadingText.remove();
|
loadingText.remove();
|
||||||
|
@ -65,10 +65,10 @@ export class KeyValueSecretEditPage extends Page {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await createOrUpdateSecret(
|
await createOrUpdateSecret(
|
||||||
this.state.currentBaseMount,
|
this.state.baseMount,
|
||||||
this.state.currentMountType,
|
this.state.secretMountType,
|
||||||
this.state.currentSecretPath,
|
this.state.secretPath,
|
||||||
this.state.currentSecret,
|
this.state.secretItem,
|
||||||
JSON.parse(jar.toString()),
|
JSON.parse(jar.toString()),
|
||||||
);
|
);
|
||||||
await this.router.changePage("KEY_VALUE_SECRET");
|
await this.router.changePage("KEY_VALUE_SECRET");
|
||||||
|
|
|
@ -10,8 +10,8 @@ export class KeyValueVersionsPage extends Page {
|
||||||
super();
|
super();
|
||||||
}
|
}
|
||||||
async goBack(): Promise<void> {
|
async goBack(): Promise<void> {
|
||||||
if (this.state.currentSecretVersion != null) {
|
if (this.state.secretVersion != null) {
|
||||||
this.state.currentSecretVersion = null;
|
this.state.secretVersion = null;
|
||||||
}
|
}
|
||||||
await this.router.changePage("KEY_VALUE_SECRET");
|
await this.router.changePage("KEY_VALUE_SECRET");
|
||||||
}
|
}
|
||||||
|
@ -24,9 +24,9 @@ export class KeyValueVersionsPage extends Page {
|
||||||
await this.router.setPageContent(versionsList);
|
await this.router.setPageContent(versionsList);
|
||||||
|
|
||||||
const metadata = await getSecretMetadata(
|
const metadata = await getSecretMetadata(
|
||||||
this.state.currentBaseMount,
|
this.state.baseMount,
|
||||||
this.state.currentSecretPath,
|
this.state.secretPath,
|
||||||
this.state.currentSecret,
|
this.state.secretItem,
|
||||||
);
|
);
|
||||||
|
|
||||||
objectToMap(metadata.versions).forEach((_, ver) => {
|
objectToMap(metadata.versions).forEach((_, ver) => {
|
||||||
|
@ -37,7 +37,7 @@ export class KeyValueVersionsPage extends Page {
|
||||||
tag: "a",
|
tag: "a",
|
||||||
text: `v${ver}`,
|
text: `v${ver}`,
|
||||||
onclick: async () => {
|
onclick: async () => {
|
||||||
this.state.currentSecretVersion = ver;
|
this.state.secretVersion = ver;
|
||||||
await this.router.changePage("KEY_VALUE_SECRET");
|
await this.router.changePage("KEY_VALUE_SECRET");
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
|
|
|
@ -11,20 +11,20 @@ export class KeyValueViewPage extends Page {
|
||||||
super();
|
super();
|
||||||
}
|
}
|
||||||
async goBack(): Promise<void> {
|
async goBack(): Promise<void> {
|
||||||
if (this.state.currentSecretPath.length != 0) {
|
if (this.state.secretPath.length != 0) {
|
||||||
this.state.popCurrentSecretPath();
|
this.state.popSecretPath();
|
||||||
await this.router.changePage("KEY_VALUE_VIEW");
|
await this.router.changePage("KEY_VALUE_VIEW");
|
||||||
} else {
|
} else {
|
||||||
await this.router.changePage("SECRETS_HOME");
|
await this.router.changePage("SECRETS_HOME");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
async render(): Promise<void> {
|
async render(): Promise<void> {
|
||||||
this.state.currentSecret = "";
|
this.state.secretItem = "";
|
||||||
|
|
||||||
const kvViewPageContent = makeElement({ tag: "div" });
|
const kvViewPageContent = makeElement({ tag: "div" });
|
||||||
await this.router.setPageContent(kvViewPageContent);
|
await this.router.setPageContent(kvViewPageContent);
|
||||||
|
|
||||||
if (this.state.currentMountType == "cubbyhole") {
|
if (this.state.secretMountType == "cubbyhole") {
|
||||||
kvViewPageContent.appendChild(
|
kvViewPageContent.appendChild(
|
||||||
makeElement({
|
makeElement({
|
||||||
tag: "p",
|
tag: "p",
|
||||||
|
@ -45,9 +45,9 @@ export class KeyValueViewPage extends Page {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const res = await getSecrets(
|
const res = await getSecrets(
|
||||||
this.state.currentBaseMount,
|
this.state.baseMount,
|
||||||
this.state.currentMountType,
|
this.state.secretMountType,
|
||||||
this.state.currentSecretPath,
|
this.state.secretPath,
|
||||||
);
|
);
|
||||||
|
|
||||||
kvViewPageContent.appendChild(
|
kvViewPageContent.appendChild(
|
||||||
|
@ -63,10 +63,10 @@ export class KeyValueViewPage extends Page {
|
||||||
text: secret,
|
text: secret,
|
||||||
onclick: async () => {
|
onclick: async () => {
|
||||||
if (secret.endsWith("/")) {
|
if (secret.endsWith("/")) {
|
||||||
this.state.pushCurrentSecretPath(secret);
|
this.state.pushSecretPath(secret);
|
||||||
await this.router.changePage("KEY_VALUE_VIEW");
|
await this.router.changePage("KEY_VALUE_VIEW");
|
||||||
} else {
|
} else {
|
||||||
this.state.currentSecret = secret;
|
this.state.secretItem = secret;
|
||||||
await this.router.changePage("KEY_VALUE_SECRET");
|
await this.router.changePage("KEY_VALUE_SECRET");
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -80,7 +80,7 @@ export class KeyValueViewPage extends Page {
|
||||||
const error = e as Error;
|
const error = e as Error;
|
||||||
if (error == DoesNotExistError) {
|
if (error == DoesNotExistError) {
|
||||||
// getSecrets also 404's on no keys so dont go all the way back.
|
// 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();
|
return this.goBack();
|
||||||
} else {
|
} else {
|
||||||
kvViewPageContent.appendChild(
|
kvViewPageContent.appendChild(
|
||||||
|
|
|
@ -75,8 +75,8 @@ export class NewKVEnginePage extends Page {
|
||||||
version: version,
|
version: version,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
this.state.currentMountType = "kv-v" + version;
|
this.state.secretMountType = "kv-v" + version;
|
||||||
this.state.currentBaseMount = name + "/";
|
this.state.baseMount = name + "/";
|
||||||
await this.router.changePage("KEY_VALUE_VIEW");
|
await this.router.changePage("KEY_VALUE_VIEW");
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
const error = e as Error;
|
const error = e as Error;
|
||||||
|
|
|
@ -57,8 +57,8 @@ export class NewTOTPEnginePage extends Page {
|
||||||
name: name,
|
name: name,
|
||||||
type: "totp",
|
type: "totp",
|
||||||
});
|
});
|
||||||
this.state.currentMountType = "totp";
|
this.state.secretMountType = "totp";
|
||||||
this.state.currentBaseMount = name + "/";
|
this.state.baseMount = name + "/";
|
||||||
await this.router.changePage("TOTP");
|
await this.router.changePage("TOTP");
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
const error = e as Error;
|
const error = e as Error;
|
||||||
|
|
|
@ -57,8 +57,8 @@ export class NewTransitEnginePage extends Page {
|
||||||
name: name,
|
name: name,
|
||||||
type: "transit",
|
type: "transit",
|
||||||
});
|
});
|
||||||
this.state.currentMountType = "transit";
|
this.state.secretMountType = "transit";
|
||||||
this.state.currentBaseMount = name + "/";
|
this.state.baseMount = name + "/";
|
||||||
await this.router.changePage("TRANSIT_VIEW");
|
await this.router.changePage("TRANSIT_VIEW");
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
const error = e as Error;
|
const error = e as Error;
|
||||||
|
|
|
@ -3,10 +3,10 @@ import { PageState } from "../../PageState";
|
||||||
import { makeElement } from "z-makeelement";
|
import { makeElement } from "z-makeelement";
|
||||||
|
|
||||||
function currentTitleSecretText(state: PageState, suffix = ""): string {
|
function currentTitleSecretText(state: PageState, suffix = ""): string {
|
||||||
let currentSecretText = state.currentSecret;
|
let secretItemText = state.secretItem;
|
||||||
currentSecretText += suffix;
|
secretItemText += suffix;
|
||||||
if (state.currentSecretVersion !== null) currentSecretText += ` (v${state.currentSecretVersion})`;
|
if (state.secretVersion !== null) secretItemText += ` (v${state.secretVersion})`;
|
||||||
return currentSecretText;
|
return secretItemText;
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function SecretTitleElement(router: PageRouter, suffix = ""): Promise<HTMLElement> {
|
export async function SecretTitleElement(router: PageRouter, suffix = ""): Promise<HTMLElement> {
|
||||||
|
@ -16,29 +16,29 @@ export async function SecretTitleElement(router: PageRouter, suffix = ""): Promi
|
||||||
children: [
|
children: [
|
||||||
makeElement({
|
makeElement({
|
||||||
tag: "a",
|
tag: "a",
|
||||||
text: state.currentBaseMount + " ",
|
text: state.baseMount + " ",
|
||||||
onclick: async () => {
|
onclick: async () => {
|
||||||
state.currentSecretPath = [];
|
state.secretPath = [];
|
||||||
state.currentSecret = "";
|
state.secretItem = "";
|
||||||
state.currentSecretVersion = null;
|
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");
|
await router.changePage("KEY_VALUE_VIEW");
|
||||||
} else if (state.currentMountType == "totp") {
|
} else if (state.secretMountType == "totp") {
|
||||||
await router.changePage("TOTP");
|
await router.changePage("TOTP");
|
||||||
} else if (state.currentMountType == "transit") {
|
} else if (state.secretMountType == "transit") {
|
||||||
await router.changePage("TRANSIT_VIEW");
|
await router.changePage("TRANSIT_VIEW");
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
...state.currentSecretPath.map((secretPath, index, secretPaths) => {
|
...state.secretPath.map((secretPath, index, secretPaths) => {
|
||||||
return makeElement({
|
return makeElement({
|
||||||
tag: "a",
|
tag: "a",
|
||||||
text: secretPath + " ",
|
text: secretPath + " ",
|
||||||
onclick: async () => {
|
onclick: async () => {
|
||||||
state.currentSecretVersion = null;
|
state.secretVersion = null;
|
||||||
if (state.currentMountType.startsWith("kv")) {
|
if (state.secretMountType.startsWith("kv")) {
|
||||||
state.currentSecretPath = secretPaths.slice(0, index + 1);
|
state.secretPath = secretPaths.slice(0, index + 1);
|
||||||
await router.changePage("KEY_VALUE_VIEW");
|
await router.changePage("KEY_VALUE_VIEW");
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -46,7 +46,7 @@ export async function SecretTitleElement(router: PageRouter, suffix = ""): Promi
|
||||||
}),
|
}),
|
||||||
makeElement({
|
makeElement({
|
||||||
tag: "span",
|
tag: "span",
|
||||||
condition: state.currentSecret.length != 0,
|
condition: state.secretItem.length != 0,
|
||||||
text: currentTitleSecretText(state, suffix),
|
text: currentTitleSecretText(state, suffix),
|
||||||
}),
|
}),
|
||||||
],
|
],
|
||||||
|
|
|
@ -34,10 +34,10 @@ export class SecretsHomePage extends Page {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.state.currentBaseMount = "";
|
this.state.baseMount = "";
|
||||||
this.state.currentSecretPath = [];
|
this.state.secretPath = [];
|
||||||
this.state.currentSecret = "";
|
this.state.secretItem = "";
|
||||||
this.state.currentSecretVersion = null;
|
this.state.secretVersion = null;
|
||||||
|
|
||||||
const navList = makeElement({
|
const navList = makeElement({
|
||||||
tag: "ul",
|
tag: "ul",
|
||||||
|
@ -55,7 +55,7 @@ export class SecretsHomePage extends Page {
|
||||||
if (!("type" in mount)) return;
|
if (!("type" in mount)) return;
|
||||||
if (!["kv", "totp", "transit", "cubbyhole"].includes(mount.type)) 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 linkText = "";
|
||||||
let linkPage: string;
|
let linkPage: string;
|
||||||
|
@ -80,8 +80,8 @@ export class SecretsHomePage extends Page {
|
||||||
tag: "a",
|
tag: "a",
|
||||||
text: linkText,
|
text: linkText,
|
||||||
onclick: async () => {
|
onclick: async () => {
|
||||||
this.state.currentBaseMount = baseMount;
|
this.state.baseMount = baseMount;
|
||||||
this.state.currentMountType = mountType;
|
this.state.secretMountType = secretMountType;
|
||||||
await this.router.changePage(linkPage);
|
await this.router.changePage(linkPage);
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
|
|
|
@ -97,7 +97,7 @@ export class NewTOTPPage extends Page {
|
||||||
};
|
};
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await addNewTOTP(this.state.currentBaseMount, parms);
|
await addNewTOTP(this.state.baseMount, parms);
|
||||||
await this.router.changePage("TOTP");
|
await this.router.changePage("TOTP");
|
||||||
} catch (e: unknown) {
|
} catch (e: unknown) {
|
||||||
const error = e as Error;
|
const error = e as Error;
|
||||||
|
|
|
@ -54,7 +54,7 @@ export class TOTPViewPage extends Page {
|
||||||
);
|
);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const res = await getTOTPKeys(this.state.currentBaseMount);
|
const res = await getTOTPKeys(this.state.baseMount);
|
||||||
for (const totpKeyName of res) {
|
for (const totpKeyName of res) {
|
||||||
const totpListElement = this.makeTOTPListElement(totpKeyName);
|
const totpListElement = this.makeTOTPListElement(totpKeyName);
|
||||||
totpList.appendChild(totpListElement);
|
totpList.appendChild(totpListElement);
|
||||||
|
@ -91,7 +91,7 @@ export class TOTPViewPage extends Page {
|
||||||
}
|
}
|
||||||
|
|
||||||
async updateTOTPElement(totpKeyName: string, totpListElement: TOTPListElement): Promise<void> {
|
async updateTOTPElement(totpKeyName: string, totpListElement: TOTPListElement): Promise<void> {
|
||||||
totpListElement.setCode(await getTOTPCode(this.state.currentBaseMount, totpKeyName));
|
totpListElement.setCode(await getTOTPCode(this.state.baseMount, totpKeyName));
|
||||||
}
|
}
|
||||||
|
|
||||||
makeTOTPListElement(totpKeyName: string): TOTPListElement {
|
makeTOTPListElement(totpKeyName: string): TOTPListElement {
|
||||||
|
|
|
@ -74,11 +74,11 @@ export class NewTransitKeyPage extends Page {
|
||||||
const type = formData.get("type") as string;
|
const type = formData.get("type") as string;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await newTransitKey(this.state.currentBaseMount, {
|
await newTransitKey(this.state.baseMount, {
|
||||||
name: name,
|
name: name,
|
||||||
type: type,
|
type: type,
|
||||||
});
|
});
|
||||||
this.state.currentSecret = name;
|
this.state.secretItem = name;
|
||||||
await this.router.changePage("TRANSIT_VIEW_SECRET");
|
await this.router.changePage("TRANSIT_VIEW_SECRET");
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
const error = e as Error;
|
const error = e as Error;
|
||||||
|
|
|
@ -96,7 +96,7 @@ export class TransitDecryptPage extends Page {
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const res = await transitDecrypt(this.state.currentBaseMount, this.state.currentSecret, {
|
const res = await transitDecrypt(this.state.baseMount, this.state.secretItem, {
|
||||||
ciphertext: ciphertext,
|
ciphertext: ciphertext,
|
||||||
});
|
});
|
||||||
let plaintext = res.plaintext;
|
let plaintext = res.plaintext;
|
||||||
|
|
|
@ -98,7 +98,7 @@ export class TransitEncryptPage extends Page {
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const res = await transitEncrypt(this.state.currentBaseMount, this.state.currentSecret, {
|
const res = await transitEncrypt(this.state.baseMount, this.state.secretItem, {
|
||||||
plaintext: plaintext,
|
plaintext: plaintext,
|
||||||
});
|
});
|
||||||
const modal = CopyableModal(
|
const modal = CopyableModal(
|
||||||
|
|
|
@ -24,7 +24,7 @@ export class TransitRewrapPage extends Page {
|
||||||
transitRewrapForm: HTMLFormElement;
|
transitRewrapForm: HTMLFormElement;
|
||||||
|
|
||||||
async render(): Promise<void> {
|
async render(): Promise<void> {
|
||||||
const transitKey = await getTransitKey(this.state.currentBaseMount, this.state.currentSecret);
|
const transitKey = await getTransitKey(this.state.baseMount, this.state.secretItem);
|
||||||
|
|
||||||
const stringVersions = Array.from(
|
const stringVersions = Array.from(
|
||||||
objectToMap(transitKey.keys).keys(),
|
objectToMap(transitKey.keys).keys(),
|
||||||
|
@ -92,7 +92,7 @@ export class TransitRewrapPage extends Page {
|
||||||
async transitRewrapFormHandler(): Promise<void> {
|
async transitRewrapFormHandler(): Promise<void> {
|
||||||
const formData = new FormData(this.transitRewrapForm);
|
const formData = new FormData(this.transitRewrapForm);
|
||||||
try {
|
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,
|
ciphertext: formData.get("ciphertext") as string,
|
||||||
key_version: parseInt(formData.get("version") as string, 10),
|
key_version: parseInt(formData.get("version") as string, 10),
|
||||||
});
|
});
|
||||||
|
|
|
@ -16,7 +16,7 @@ export class TransitViewPage extends Page {
|
||||||
}
|
}
|
||||||
|
|
||||||
async render(): Promise<void> {
|
async render(): Promise<void> {
|
||||||
this.state.currentSecret = "";
|
this.state.secretItem = "";
|
||||||
|
|
||||||
const transitViewContent = makeElement({ tag: "div" });
|
const transitViewContent = makeElement({ tag: "div" });
|
||||||
await this.router.setPageContent(transitViewContent);
|
await this.router.setPageContent(transitViewContent);
|
||||||
|
@ -32,7 +32,7 @@ export class TransitViewPage extends Page {
|
||||||
transitViewContent.appendChild(newButton);
|
transitViewContent.appendChild(newButton);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const res = await getTransitKeys(this.state.currentBaseMount);
|
const res = await getTransitKeys(this.state.baseMount);
|
||||||
|
|
||||||
transitViewContent.appendChild(
|
transitViewContent.appendChild(
|
||||||
makeElement({
|
makeElement({
|
||||||
|
@ -46,7 +46,7 @@ export class TransitViewPage extends Page {
|
||||||
tag: "a",
|
tag: "a",
|
||||||
text: secret,
|
text: secret,
|
||||||
onclick: async () => {
|
onclick: async () => {
|
||||||
this.state.currentSecret = secret;
|
this.state.secretItem = secret;
|
||||||
await this.router.changePage("TRANSIT_VIEW_SECRET");
|
await this.router.changePage("TRANSIT_VIEW_SECRET");
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
|
|
|
@ -15,7 +15,7 @@ export class TransitViewSecretPage extends Page {
|
||||||
}
|
}
|
||||||
|
|
||||||
async render(): Promise<void> {
|
async render(): Promise<void> {
|
||||||
const transitKey = await getTransitKey(this.state.currentBaseMount, this.state.currentSecret);
|
const transitKey = await getTransitKey(this.state.baseMount, this.state.secretItem);
|
||||||
|
|
||||||
await this.router.setPageContent(
|
await this.router.setPageContent(
|
||||||
makeElement({
|
makeElement({
|
||||||
|
|
Loading…
Reference in a new issue