From 502ae9f920534e8d775ff0d694e16c65cd7ffee1 Mon Sep 17 00:00:00 2001 From: John Cantrell Date: Sat, 26 Mar 2022 08:22:23 -0400 Subject: [PATCH] add simple token management in web admin --- src/grpc/admin.rs | 3 + src/main.rs | 2 +- web-admin/package-lock.json | 14 +- web-admin/package.json | 2 +- web-admin/src/App.tsx | 4 + web-admin/src/layouts/AppLayout.tsx | 27 ++- .../src/tokens/components/NewTokenForm.tsx | 88 +++++++ .../src/tokens/components/TokensList.tsx | 226 ++++++++++++++++++ .../src/tokens/mutations/createAccessToken.ts | 7 + .../src/tokens/mutations/deleteAccessToken.ts | 7 + web-admin/src/tokens/pages/NewTokenPage.tsx | 34 +++ web-admin/src/tokens/pages/TokensPage.tsx | 31 +++ .../src/tokens/queries/getAccessTokens.ts | 7 + 13 files changed, 432 insertions(+), 20 deletions(-) create mode 100644 web-admin/src/tokens/components/NewTokenForm.tsx create mode 100644 web-admin/src/tokens/components/TokensList.tsx create mode 100644 web-admin/src/tokens/mutations/createAccessToken.ts create mode 100644 web-admin/src/tokens/mutations/deleteAccessToken.ts create mode 100644 web-admin/src/tokens/pages/NewTokenPage.tsx create mode 100644 web-admin/src/tokens/pages/TokensPage.tsx create mode 100644 web-admin/src/tokens/queries/getAccessTokens.ts diff --git a/src/grpc/admin.rs b/src/grpc/admin.rs index e012f4b..126d14c 100644 --- a/src/grpc/admin.rs +++ b/src/grpc/admin.rs @@ -316,6 +316,9 @@ pub fn get_scope_from_request(request: &AdminRequest) -> Option<&'static str> { AdminRequest::ListNodes { .. } => Some("nodes/list"), AdminRequest::DeleteNode { .. } => Some("nodes/delete"), AdminRequest::StopNode { .. } => Some("nodes/stop"), + AdminRequest::ListTokens { .. } => Some("tokens/list"), + AdminRequest::CreateToken { .. } => Some("tokens/create"), + AdminRequest::DeleteToken { .. } => Some("tokens/delete"), _ => None, } } diff --git a/src/main.rs b/src/main.rs index fd3b5dc..3d3c63f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -166,7 +166,7 @@ async fn main() { let router = add_node_routes(router); let origins = vec![ - "http://localhost:3000".parse().unwrap(), + "http://localhost:3001".parse().unwrap(), "http://localhost:5401".parse().unwrap(), ]; let http_service = router diff --git a/web-admin/package-lock.json b/web-admin/package-lock.json index a08fb51..d26ac81 100644 --- a/web-admin/package-lock.json +++ b/web-admin/package-lock.json @@ -10,7 +10,7 @@ "dependencies": { "@headlessui/react": "^1.4.2", "@heroicons/react": "^1.0.5", - "@l2-technology/sensei-client": "^0.1.4", + "@l2-technology/sensei-client": "^0.1.7", "@tailwindcss/aspect-ratio": "^0.4.0", "@tailwindcss/forms": "^0.4.0", "@tailwindcss/typography": "^0.5.0", @@ -3188,9 +3188,9 @@ } }, "node_modules/@l2-technology/sensei-client": { - "version": "0.1.4", - "resolved": "https://registry.npmjs.org/@l2-technology/sensei-client/-/sensei-client-0.1.4.tgz", - "integrity": "sha512-G1/1EmSB3J18MpMG0WJ6gOyHTAPSe8xaGVEOmJ5IyZ8npDCcRzCl0JZC6dMAQzzkdO2umo9xU0QLeW3rCgn/Ug==", + "version": "0.1.7", + "resolved": "https://registry.npmjs.org/@l2-technology/sensei-client/-/sensei-client-0.1.7.tgz", + "integrity": "sha512-qEZGbxTu7MhWU9UKBa4EVWYCMLao5u/ztbmNF4mihPXQiW0vp9z320O1zLsOwV1KH+t+agpX9Mi2E0SIOJvxjw==", "dependencies": { "cross-fetch": "^3.1.5" } @@ -25727,9 +25727,9 @@ } }, "@l2-technology/sensei-client": { - "version": "0.1.4", - "resolved": "https://registry.npmjs.org/@l2-technology/sensei-client/-/sensei-client-0.1.4.tgz", - "integrity": "sha512-G1/1EmSB3J18MpMG0WJ6gOyHTAPSe8xaGVEOmJ5IyZ8npDCcRzCl0JZC6dMAQzzkdO2umo9xU0QLeW3rCgn/Ug==", + "version": "0.1.7", + "resolved": "https://registry.npmjs.org/@l2-technology/sensei-client/-/sensei-client-0.1.7.tgz", + "integrity": "sha512-qEZGbxTu7MhWU9UKBa4EVWYCMLao5u/ztbmNF4mihPXQiW0vp9z320O1zLsOwV1KH+t+agpX9Mi2E0SIOJvxjw==", "requires": { "cross-fetch": "^3.1.5" } diff --git a/web-admin/package.json b/web-admin/package.json index a043987..8829644 100644 --- a/web-admin/package.json +++ b/web-admin/package.json @@ -6,7 +6,7 @@ "dependencies": { "@headlessui/react": "^1.4.2", "@heroicons/react": "^1.0.5", - "@l2-technology/sensei-client": "^0.1.4", + "@l2-technology/sensei-client": "^0.1.7", "@tailwindcss/aspect-ratio": "^0.4.0", "@tailwindcss/forms": "^0.4.0", "@tailwindcss/typography": "^0.5.0", diff --git a/web-admin/src/App.tsx b/web-admin/src/App.tsx index ba37bd0..e8ba1d9 100644 --- a/web-admin/src/App.tsx +++ b/web-admin/src/App.tsx @@ -23,6 +23,8 @@ import ErrorModal from "./components/layout/app/ErrorModal"; import NotificationContainer from "./components/layout/app/NotificationContainer"; import OpenChannelPage from "./channels/pages/OpenChannelPage"; import LogoutPage from "./auth/pages/LogoutPage"; +import TokensPage from "./tokens/pages/TokensPage"; +import NewTokenPage from "./tokens/pages/NewTokenPage"; function App() { const { isLoading, data } = useQuery("status", getStatus, { @@ -58,6 +60,8 @@ function App() { } /> } /> } /> + } /> + } /> diff --git a/web-admin/src/layouts/AppLayout.tsx b/web-admin/src/layouts/AppLayout.tsx index dbc369e..e4977a5 100644 --- a/web-admin/src/layouts/AppLayout.tsx +++ b/web-admin/src/layouts/AppLayout.tsx @@ -12,7 +12,8 @@ import { CollectionIcon, ShoppingCartIcon, QrcodeIcon, - LinkIcon + LinkIcon, + KeyIcon, } from "@heroicons/react/outline"; import { NavLink } from "react-router-dom"; @@ -23,7 +24,7 @@ import { useAuth } from "../contexts/auth"; const AppLayout = () => { const auth = useAuth(); const [sidebarOpen, setSidebarOpen] = useState(false); - const navigation = [] + const navigation = []; if (auth.isAdmin()) { navigation.push({ @@ -37,15 +38,13 @@ const AppLayout = () => { name: "Fund Node", href: "/admin/fund", icon: QrcodeIcon, - }) + }); - navigation.push( - { - name: "Chain", - href: "/admin/chain", - icon: LinkIcon, - }, - ); + navigation.push({ + name: "Chain", + href: "/admin/chain", + icon: LinkIcon, + }); navigation.push({ name: "Channels", @@ -65,6 +64,12 @@ const AppLayout = () => { icon: CashIcon, }); + navigation.push({ + name: "Access Tokens", + href: "/admin/tokens", + icon: KeyIcon, + }); + navigation.push({ name: "Logout", href: "/admin/logout", icon: LogoutIcon }); return ( @@ -191,7 +196,7 @@ const AppLayout = () => {
- +