1
0
Fork 0

Add secret engine deletion page.

This commit is contained in:
Kitteh 2021-05-30 10:02:20 +01:00
parent 36fd734dd6
commit df796d3506
10 changed files with 111 additions and 15 deletions

View file

@ -6,6 +6,7 @@ import { PageType } from "z-pagerouter";
import { AccessHomePage } from "./pages/Access/AccessHome";
import { AuthHomePage } from "./pages/Access/Auth/AuthHome";
import { AuthViewConfigPage } from "./pages/Access/Auth/AuthViewConfig";
import { DeleteSecretsEnginePage } from "./pages/Secrets/DeleteSecretsEngine";
import { HomePage } from "./pages/Home";
import { KeyValueDeletePage } from "./pages/Secrets/KeyValue/KeyValueDelete";
import { KeyValueNewPage } from "./pages/Secrets/KeyValue/KeyValueNew";
@ -96,6 +97,8 @@ export const allPages: pagesList = {
KEY_VALUE_DELETE: new KeyValueDeletePage(),
KEY_VALUE_SECRET_EDIT: new KeyValueSecretEditPage(),
DELETE_SECRET_ENGINE: new DeleteSecretsEnginePage(),
NEW_SECRETS_ENGINE: new NewSecretsEnginePage(),
NEW_KV_ENGINE: new NewKVEnginePage(),
NEW_TOTP_ENGINE: new NewTOTPEnginePage(),

View file

@ -0,0 +1,10 @@
import { appendAPIURL, checkResponse, getHeaders } from "../apiUtils";
export async function deleteMount(mountPath: string): Promise<void> {
const request = new Request(appendAPIURL("/v1/sys/mounts/" + mountPath), {
method: "DELETE",
headers: getHeaders(),
});
const resp = await fetch(request);
await checkResponse(resp);
}

View file

@ -54,7 +54,6 @@ async function onLoad(): Promise<void> {
resetElementContent: !true,
});
reloadNavBar(pageRouter);
pageRouter.addEventListener("pageChanged", async function (_) {

View file

@ -0,0 +1,48 @@
import { Form } from "../../elements/Form";
import { MarginInline } from "../../elements/MarginInline";
import { Page } from "../../types/Page";
import { deleteMount } from "../../api/sys/deleteMount";
import { render } from "preact";
import { setErrorText } from "../../pageUtils";
import i18next from "i18next";
export class DeleteSecretsEnginePage extends Page {
constructor() {
super();
}
async render(): Promise<void> {
render(
<Form
onSubmit={async () => {
await this.onSubmit();
}}
>
<p>{i18next.t("delete_secrets_engine_message")}</p>
<p class="uk-text-danger" id="errorText" />
<MarginInline>
<button class="uk-button uk-button-danger" type="submit">
{i18next.t("delete_secrets_engine_delete_btn")}
</button>
</MarginInline>
</Form>,
this.router.pageContentElement,
);
}
async onSubmit(): Promise<void> {
try {
await deleteMount(this.state.baseMount);
await this.router.changePage("SECRETS_HOME");
} catch (e: unknown) {
const error = e as Error;
setErrorText(error.message);
}
}
get name(): string {
return i18next.t("delete_secrets_engine_title", { mount: this.state.baseMount });
}
}

View file

@ -126,16 +126,26 @@ export class KeyValueViewPage extends Page {
async render(): Promise<void> {
render(
<>
<div id="buttonsBox">
<p>
<button
class="uk-button uk-button-primary uk-margin-bottom"
class="uk-button uk-button-primary"
onClick={async () => {
await this.router.changePage("KEY_VALUE_NEW_SECRET");
}}
>
{i18next.t("kv_view_new_btn")}
</button>
</div>
{this.state.secretPath.length == 0 && (
<button
class="uk-button uk-button-danger"
onClick={async () => {
await this.router.changePage("DELETE_SECRET_ENGINE");
}}
>
{i18next.t("kv_view_delete_btn")}
</button>
)}
</p>
{this.state.secretMountType == "cubbyhole" && <p>{i18next.t("kv_view_cubbyhole_text")}</p>}
<KVKeysList
page={this}

View file

@ -66,7 +66,6 @@ export class SecretsHomePage extends Page {
await this.router.changePage("HOME");
}
async render(): Promise<void> {
await this.router.setPageContent("");
if (!(await prePageChecks(this.router))) return;
this.state.baseMount = "";

View file

@ -55,7 +55,7 @@ export class RefreshingTOTPGridItem extends Component<
await page.router.changePage("TOTP_DELETE");
}}
>
{i18next.t("totp_view_delete_btn")}
{i18next.t("totp_view_secret_delete_btn")}
</button>
)}
</MarginInline>
@ -81,14 +81,24 @@ export class TOTPViewPage extends Page {
this.state.secretItem = "";
render(
<div>
<button
class="uk-button uk-button-primary uk-margin-bottom"
onClick={async () => {
await this.router.changePage("TOTP_NEW");
}}
>
{i18next.t("totp_view_new_btn")}
</button>
<p>
<button
class="uk-button uk-button-primary"
onClick={async () => {
await this.router.changePage("TOTP_NEW");
}}
>
{i18next.t("totp_view_new_btn")}
</button>
<button
class="uk-button uk-button-danger"
onClick={async () => {
await this.router.changePage("DELETE_SECRET_ENGINE");
}}
>
{i18next.t("totp_view_delete_btn")}
</button>
</p>
<br />
<br />
<div id="totpList">

View file

@ -90,6 +90,14 @@ export class TransitViewPage extends Page {
>
{i18next.t("transit_view_new_btn")}
</button>
<button
class="uk-button uk-button-danger"
onClick={async () => {
await this.router.changePage("DELETE_SECRET_ENGINE");
}}
>
{i18next.t("transit_view_delete_btn")}
</button>
</p>
<TransitViewListItem page={this} />
</>,

View file

@ -146,12 +146,14 @@ module.exports = {
kv_view_cubbyhole_text:
"In cubbyhole, secrets can be stored as long as the lease of your token is valid. They will be deleted when lease is expired and can only be viewed by your current token.",
kv_view_new_btn: "New",
kv_view_delete_btn: "Delete",
kv_view_none_here_text: "You seem to have no secrets here, would you like to create one?",
// TOTP View Page
totp_view_title: "TOTP",
totp_view_new_btn: "New",
totp_view_delete_btn: "Delete",
totp_view_secret_delete_btn: "Delete",
totp_view_loading: "Loading TOTP Codes..",
totp_view_empty: "You seem to have no TOTP codes here, would you like to create one?",
totp_view_loading_box: "Loading..",
@ -177,6 +179,7 @@ module.exports = {
// Transit View Page
transit_view_title: "Transit View",
transit_view_new_btn: "New",
transit_view_delete_btn: "Delete",
transit_view_none_here_text:
"You seem to have no transit keys here, would you like to create one?",
@ -222,6 +225,12 @@ module.exports = {
transit_rewrap_rewrap_btn: "Rewrap",
transit_rewrap_result_modal_title: "Rewrap Result",
// Delete Secret Engine Page
delete_secrets_engine_title: "Delete Secret Engine ({{mount}})",
delete_secrets_engine_message:
"Are you sure you want to delete this secrets engine and all the data stored within? This can't be reversed.",
delete_secrets_engine_delete_btn: "Delete",
// Access Home
access_home_page_title: "Access",
access_auth_methods_title: "Authentication Methods",

View file

@ -152,7 +152,7 @@ module.exports = {
// TOTP View Page
totp_view_title: "TOTP",
totp_view_new_btn: "Добавить",
totp_view_delete_btn: "Удалить",
totp_view_secret_delete_btn: "Удалить",
totp_view_loading: "Загрузка кодов TOTP..",
totp_view_empty: "У вас на данный момент нет кодов TOTP. Хотите ли вы их создать?",
totp_view_loading_box: "Загрузка..",