Skip to content

Commit

Permalink
feat: Implement api key management (#403)
Browse files Browse the repository at this point in the history
Signed-off-by: Raul-Cristian Kele <raulkeleblk@gmail.com>
  • Loading branch information
raulkele committed Feb 18, 2024
1 parent e037c6c commit 33524ce
Show file tree
Hide file tree
Showing 18 changed files with 902 additions and 66 deletions.
210 changes: 176 additions & 34 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,15 @@
"@mui/lab": "^5.0.0-alpha.89",
"@mui/material": "^5.8.6",
"@mui/styles": "^5.8.6",
"@mui/x-date-pickers": "^6.18.4",
"@testing-library/jest-dom": "^5.16.1",
"@testing-library/react": "^12.1.2",
"@testing-library/user-event": "^13.5.0",
"axios": "^0.24.0",
"downshift": "^6.1.12",
"export-from-json": "^1.7.3",
"lodash": "^4.17.21",
"luxon": "^2.5.2",
"luxon": "^3.4.4",
"markdown-to-jsx": "^7.1.7",
"react": "^17.0.2",
"react-dom": "^17.0.2",
Expand Down
6 changes: 4 additions & 2 deletions src/App.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import React, { useState } from 'react';
import { BrowserRouter as Router, Routes, Route, Navigate } from 'react-router-dom';

import { isAuthenticated } from 'utilities/authUtilities';
import { isAuthenticated, isApiKeyEnabled } from 'utilities/authUtilities';
import { AuthWrapper } from 'utilities/AuthWrapper';

import HomePage from './pages/HomePage';
import LoginPage from './pages/LoginPage';
import { AuthWrapper } from 'utilities/AuthWrapper';
import RepoPage from 'pages/RepoPage';
import TagPage from 'pages/TagPage';
import ExplorePage from 'pages/ExplorePage';
import UserManagementPage from 'pages/UserManagementPage';

import './App.css';

Expand All @@ -25,6 +26,7 @@ function App() {
<Route path="/explore" element={<ExplorePage />} />
<Route path="/image/:name" element={<RepoPage />} />
<Route path="/image/:reponame/tag/:tag" element={<TagPage />} />
{isApiKeyEnabled() && <Route path="/user/apikey" element={<UserManagementPage />} />}
<Route path="*" element={<Navigate to="/home" />} />
</Route>
<Route element={<AuthWrapper isLoggedIn={!isLoggedIn} redirect="/" />}>
Expand Down
6 changes: 5 additions & 1 deletion src/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,14 @@ const api = {
return axios.put(urli, payload, config);
},

delete(urli, abortSignal, cfg) {
delete(urli, params, abortSignal, cfg) {
let config = isEmpty(cfg) ? this.getRequestCfg() : cfg;
if (!isEmpty(abortSignal) && isEmpty(config.signal)) {
config = { ...config, signal: abortSignal };
}
if (!isEmpty(params)) {
config = { ...config, params };
}
return axios.delete(urli, config);
}
};
Expand All @@ -81,6 +84,7 @@ const endpoints = {
authConfig: `/v2/_zot/ext/mgmt`,
openidAuth: `/zot/auth/login`,
logout: `/zot/auth/logout`,
apiKeys: '/zot/auth/apikey',
deleteImage: (name, tag) => `/v2/${name}/manifests/${tag}`,
repoList: ({ pageNumber = 1, pageSize = 15 } = {}) =>
`/v2/_zot/ext/search?query={RepoListWithNewestImage(requestedPage: {limit:${pageSize} offset:${
Expand Down
10 changes: 9 additions & 1 deletion src/components/Header/UserAccountMenu.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,17 @@ import React, { useState } from 'react';

import { Menu, MenuItem, IconButton, Avatar, Divider } from '@mui/material';

import { getLoggedInUser, logoutUser } from '../../utilities/authUtilities';
import { getLoggedInUser, logoutUser, isApiKeyEnabled } from '../../utilities/authUtilities';
import { useNavigate } from 'react-router-dom';

function UserAccountMenu() {
const [anchorEl, setAnchorEl] = useState(null);
const openMenu = Boolean(anchorEl);
const navigate = useNavigate();

const apiKeyManagement = () => {
navigate('/user/apikey');
};

const handleUserClick = (event) => {
setAnchorEl(event.currentTarget);
Expand Down Expand Up @@ -37,6 +43,8 @@ function UserAccountMenu() {
>
<MenuItem onClick={handleUserClose}>{getLoggedInUser()}</MenuItem>
<Divider />
{isApiKeyEnabled() && <MenuItem onClick={apiKeyManagement}>API Keys</MenuItem>}
<Divider />
<MenuItem onClick={logoutUser}>Log out</MenuItem>
</Menu>
</>
Expand Down
Loading

0 comments on commit 33524ce

Please sign in to comment.