From 555825787cd5ee80db4d1727353812d15121b06d Mon Sep 17 00:00:00 2001 From: Kitteh Date: Wed, 19 May 2021 10:45:52 +0100 Subject: [PATCH] Add UserPassUsersListPage. --- src/allPages.ts | 7 +-- src/api/auth/listAuth.ts | 2 +- src/api/auth/userpass/listUserPassUsers.ts | 10 ++++ src/api/types/auth.ts | 12 ++--- src/pageUtils.ts | 4 ++ src/pages/Access/AccessHome.ts | 4 +- src/pages/Access/Auth/AuthHome.ts | 24 +++++---- src/pages/Access/Auth/AuthViewConfig.ts | 54 ++++++++----------- .../Access/Auth/userpass/UserPassUsersList.ts | 42 +++++++++++++++ src/translations/en.js | 3 ++ 10 files changed, 110 insertions(+), 52 deletions(-) create mode 100644 src/api/auth/userpass/listUserPassUsers.ts create mode 100644 src/pages/Access/Auth/userpass/UserPassUsersList.ts diff --git a/src/allPages.ts b/src/allPages.ts index 712aaea..76cd416 100644 --- a/src/allPages.ts +++ b/src/allPages.ts @@ -1,3 +1,4 @@ +import { AccessHomePage } from "./pages/Access/AccessHome"; import { HomePage } from "./pages/Home"; import { KeyValueDeletePage } from "./pages/Secrets/KeyValue/KeyValueDelete"; import { KeyValueNewPage } from "./pages/Secrets/KeyValue/KeyValueNew"; @@ -26,13 +27,12 @@ import { TransitViewPage } from "./pages/Secrets/Transit/TransitView"; import { TransitViewSecretPage } from "./pages/Secrets/Transit/TransitViewSecret"; import { UnsealPage } from "./pages/Unseal"; import { getObjectKeys } from "./utils"; -import { AccessHomePage } from "./pages/Access/AccessHome"; - /* eslint-disable */ -import { PageType } from "z-pagerouter"; import { AuthHomePage } from "./pages/Access/Auth/AuthHome"; import { AuthViewConfigPage } from "./pages/Access/Auth/AuthViewConfig"; +import { PageType } from "z-pagerouter"; +import { UserPassUsersListPage } from "./pages/Access/Auth/userpass/UserPassUsersList"; /* eslint-enable */ type pagesList = { @@ -45,6 +45,7 @@ export const allPages: pagesList = { ACCESS_HOME: new AccessHomePage(), AUTH_HOME: new AuthHomePage(), AUTH_VIEW_CONFIG: new AuthViewConfigPage(), + USERPASS_USERS_LIST: new UserPassUsersListPage(), ME: new MePage(), TOTP: new TOTPViewPage(), NEW_TOTP: new NewTOTPPage(), diff --git a/src/api/auth/listAuth.ts b/src/api/auth/listAuth.ts index b268d82..cf18c87 100644 --- a/src/api/auth/listAuth.ts +++ b/src/api/auth/listAuth.ts @@ -1,5 +1,5 @@ -import { appendAPIURL, getHeaders } from "../apiUtils"; import { AuthListAPIType, AuthListType } from "../types/auth"; +import { appendAPIURL, getHeaders } from "../apiUtils"; export async function listAuth(): Promise { const request = new Request(appendAPIURL(`/v1/sys/auth`), { diff --git a/src/api/auth/userpass/listUserPassUsers.ts b/src/api/auth/userpass/listUserPassUsers.ts new file mode 100644 index 0000000..12f18ee --- /dev/null +++ b/src/api/auth/userpass/listUserPassUsers.ts @@ -0,0 +1,10 @@ +import { appendAPIURL, getHeaders } from "../../apiUtils"; + +export async function listUserPassUsers(path: string): Promise { + const request = new Request(appendAPIURL(`/v1/auth/${path}/users?list=true`), { + headers: getHeaders(), + }); + const resp = await fetch(request); + const data = (await resp.json()) as { data: { keys: string[] } }; + return data.data.keys; +} diff --git a/src/api/types/auth.ts b/src/api/types/auth.ts index fb9e8f1..1d8d731 100644 --- a/src/api/types/auth.ts +++ b/src/api/types/auth.ts @@ -3,17 +3,17 @@ export type AuthMethod = { accessor: string; config: Record; description: string; - external_entropy_access: Boolean; - local: Boolean; + external_entropy_access: boolean; + local: boolean; options: Record; - seal_wrap: Boolean; + seal_wrap: boolean; uuid: string; -} +}; export type AuthListAPIType = { data: AuthListType; -} +}; export type AuthListType = { [path: string]: AuthMethod; -} \ No newline at end of file +}; diff --git a/src/pageUtils.ts b/src/pageUtils.ts index 87f838b..0663cba 100644 --- a/src/pageUtils.ts +++ b/src/pageUtils.ts @@ -76,3 +76,7 @@ export function setErrorText(text: string): void { timeout: 2000, }); } + +export function notImplemented(): void { + setErrorText(i18next.t("not_implemented")); +} diff --git a/src/pages/Access/AccessHome.ts b/src/pages/Access/AccessHome.ts index 99138f8..9ffe97a 100644 --- a/src/pages/Access/AccessHome.ts +++ b/src/pages/Access/AccessHome.ts @@ -1,8 +1,8 @@ import { Page } from "../../types/Page"; +import { Tile } from "../../elements/Tile"; import { makeElement } from "z-makeelement"; import { prePageChecks, setErrorText } from "../../pageUtils"; import i18next from "i18next"; -import { Tile } from "../../elements/Tile"; export class AccessHomePage extends Page { constructor() { @@ -15,7 +15,7 @@ export class AccessHomePage extends Page { await this.router.setPageContent(""); if (!(await prePageChecks(this.router))) return; - this.router.setPageContent( + await this.router.setPageContent( makeElement({ tag: "div", class: "uk-child-width-1-1@s uk-child-width-1-2@m uk-grid-small uk-grid-match", diff --git a/src/pages/Access/Auth/AuthHome.ts b/src/pages/Access/Auth/AuthHome.ts index eaf778f..434e5ad 100644 --- a/src/pages/Access/Auth/AuthHome.ts +++ b/src/pages/Access/Auth/AuthHome.ts @@ -1,9 +1,9 @@ -import { Page } from "../../../types/Page"; -import i18next from "i18next"; -import { listAuth } from "../../../api/auth/listAuth"; -import { objectToMap } from "../../../utils"; import { AuthMethod } from "../../../api/types/auth"; +import { Page } from "../../../types/Page"; +import { listAuth } from "../../../api/auth/listAuth"; import { makeElement } from "z-makeelement"; +import { objectToMap } from "../../../utils"; +import i18next from "i18next"; export function AuthListElement(page: Page, path: string, method: AuthMethod): HTMLElement { const isClickable = method.type != "token"; @@ -16,11 +16,17 @@ export function AuthListElement(page: Page, path: string, method: AuthMethod): H tag: isClickable ? "a" : "span", class: "uk-h4 uk-margin-bottom", text: path, + onclick: async () => { + page.state.currentBaseMount = path; + if (method.type == "userpass") { + await page.router.changePage("USERPASS_USERS_LIST"); + } + }, }), makeElement({ tag: "span", class: "uk-text-muted", - text: ` (${method.accessor})` + text: ` (${method.accessor})`, }), makeElement({ tag: "div", @@ -40,7 +46,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_edit_config"), }), - ] + ], }), ], }); @@ -56,11 +62,11 @@ export class AuthHomePage extends Page { async render(): Promise { this.state.currentSecretPath = []; - let authList = objectToMap(await listAuth()) as Map; + const authList = objectToMap(await listAuth()) as Map; const contentElement = makeElement({ tag: "div" }); - this.router.setPageContent(contentElement); + await this.router.setPageContent(contentElement); for (const [path, details] of authList) { - contentElement.appendChild(AuthListElement(this, path, details)) + contentElement.appendChild(AuthListElement(this, path, details)); } } get name(): string { diff --git a/src/pages/Access/Auth/AuthViewConfig.ts b/src/pages/Access/Auth/AuthViewConfig.ts index d5ce77e..56dca32 100644 --- a/src/pages/Access/Auth/AuthViewConfig.ts +++ b/src/pages/Access/Auth/AuthViewConfig.ts @@ -1,9 +1,9 @@ -import { Page } from "../../../types/Page"; -import i18next from "i18next"; -import { listAuth } from "../../../api/auth/listAuth"; -import { objectToMap } from "../../../utils"; import { AuthMethod } from "../../../api/types/auth"; +import { Page } from "../../../types/Page"; +import { listAuth } from "../../../api/auth/listAuth"; import { makeElement } from "z-makeelement"; +import { objectToMap } from "../../../utils"; +import i18next from "i18next"; export function HeaderAndContent(title: string, content: string): HTMLElement { return makeElement({ @@ -14,7 +14,7 @@ export function HeaderAndContent(title: string, content: string): HTMLElement { children: makeElement({ tag: "h5", text: title, - }) + }), }), makeElement({ tag: "td", @@ -23,11 +23,10 @@ export function HeaderAndContent(title: string, content: string): HTMLElement { text: content, }), }), - ] - }) + ], + }); } - export class AuthViewConfigPage extends Page { constructor() { super(); @@ -41,42 +40,35 @@ export class AuthViewConfigPage extends Page { tag: "table", class: "uk-table", }); - this.router.setPageContent(tableElement); + await this.router.setPageContent(tableElement); const contentElement = makeElement({ tag: "tbody" }); tableElement.appendChild(contentElement); - let authList = objectToMap(await listAuth()) as Map; - let authMethod = authList.get(this.state.currentBaseMount); + const authList = objectToMap(await listAuth()) as Map; + const authMethod = authList.get(this.state.currentBaseMount); + contentElement.appendChild(HeaderAndContent("Type", authMethod.type)); + contentElement.appendChild(HeaderAndContent("Path", this.state.currentBaseMount)); + contentElement.appendChild(HeaderAndContent("Description", authMethod.description)); + contentElement.appendChild(HeaderAndContent("Accessor", authMethod.accessor)); + contentElement.appendChild(HeaderAndContent("Local", String(authMethod.local).toString())); contentElement.appendChild( - HeaderAndContent("Type", authMethod.type) + HeaderAndContent("Seal Wrap", String(authMethod.seal_wrap).toString()), ); contentElement.appendChild( - HeaderAndContent("Path", this.state.currentBaseMount) + HeaderAndContent( + "List when unauthenticated?", + String(authMethod.config.listing_visibility).toString(), + ), ); contentElement.appendChild( - HeaderAndContent("Description", authMethod.description) + HeaderAndContent("Default Lease TTL", String(authMethod.config.default_lease_ttl).toString()), ); contentElement.appendChild( - HeaderAndContent("Accessor", authMethod.accessor) + HeaderAndContent("Max Lease TTL", String(authMethod.config.max_lease_ttl).toString()), ); contentElement.appendChild( - HeaderAndContent("Local", String(authMethod.local).toString()) - ); - contentElement.appendChild( - HeaderAndContent("Seal Wrap", String(authMethod.seal_wrap).toString()) - ); - contentElement.appendChild( - HeaderAndContent("List when unauthenticated?", String(authMethod.config.listing_visibility).toString()) - ); - contentElement.appendChild( - HeaderAndContent("Default Lease TTL", String(authMethod.config.default_lease_ttl).toString()) - ); - contentElement.appendChild( - HeaderAndContent("Max Lease TTL", String(authMethod.config.max_lease_ttl).toString()) - ); - contentElement.appendChild( - HeaderAndContent("Token Type", authMethod.config.token_type as string) + HeaderAndContent("Token Type", authMethod.config.token_type as string), ); } diff --git a/src/pages/Access/Auth/userpass/UserPassUsersList.ts b/src/pages/Access/Auth/userpass/UserPassUsersList.ts new file mode 100644 index 0000000..1057bc8 --- /dev/null +++ b/src/pages/Access/Auth/userpass/UserPassUsersList.ts @@ -0,0 +1,42 @@ +import { Page } from "../../../../types/Page"; +import { listUserPassUsers } from "../../../../api/auth/userpass/listUserPassUsers"; +import { makeElement } from "z-makeelement"; +import { notImplemented } from "../../../../pageUtils"; +import i18next from "i18next"; + +export class UserPassUsersListPage extends Page { + constructor() { + super(); + } + async goBack(): Promise { + await this.router.changePage("AUTH_HOME"); + } + + async render(): Promise { + const pageContent = makeElement({ tag: "div" }); + await this.router.setPageContent(pageContent); + + const users = await listUserPassUsers(this.state.currentBaseMount); + pageContent.appendChild( + makeElement({ + tag: "ul", + children: [ + ...users.map((user) => { + return makeElement({ + tag: "li", + children: makeElement({ + tag: "a", + text: user, + onclick: notImplemented, + }), + }); + }), + ], + }), + ); + } + + get name(): string { + return i18next.t("userpass_users_list_title"); + } +} diff --git a/src/translations/en.js b/src/translations/en.js index b317ac8..862b27c 100644 --- a/src/translations/en.js +++ b/src/translations/en.js @@ -226,4 +226,7 @@ module.exports = { // Auth View Conig Page auth_view_config_title: "Auth View Config", auth_view_config_suffix: " (view config)", + + // userpass Users List + userpass_users_list_title: "Users List", };