Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(ui): support delete all expired token in project roles #21782

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ interface ProjectRoleDefaultParams {
interface ProjectRoleEditPanelProps {
nameReadonly?: boolean;
submit: (params: ProjectRoleParams) => any;
createJWTToken: (params: CreateJWTTokenParams) => void;
deleteJWTToken: (params: DeleteJWTTokenParams) => void;
createJWTToken: (params: CreateJWTTokenParams) => Promise<void>;
deleteJWTToken: (params: DeleteJWTTokenParams) => Promise<void>;
hideJWTToken: () => void;
token: string;
getApi?: (formApi: FormApi) => void;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,29 @@
right: 1em;
top: 1em;
cursor: pointer;
}
}

.project-role-jwt-tokens__id {
display: flex;
align-items: center;
}

.project-role-jwt-tokens__id-tooltip {
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}

.project-role-jwt-tokens__expired-token {
color: white;
font-size: 1.2em;
padding-left: 0.5em;
padding-right: 0.5em;
line-height: 1.4em;
background-color: #8FA4B1;
margin-left: 0.2em;
border-radius: 0.2em;
transform: scale(0.8);
flex: 0;
min-width: fit-content;
}
Original file line number Diff line number Diff line change
@@ -1,31 +1,54 @@
import {FormField, Tooltip} from 'argo-ui';
import {FormField, NotificationType, Tooltip} from 'argo-ui';
import * as React from 'react';
import {Form, FormApi, Text} from 'react-form';

import {Consumer, ContextApis} from '../../../shared/context';
import {JwtToken} from '../../../shared/models';
import {CreateJWTTokenParams, DeleteJWTTokenParams} from '../../../shared/services';
import {convertExpiresInToSeconds, validExpiresIn} from '../utils';
import {Button} from '../../../shared/components/button';
import {ProgressPopup} from '../../../shared/components';

interface ProjectRoleJWTTokensProps {
projName: string;
roleName: string;
tokens: JwtToken[];
token: string;
createJWTToken: (params: CreateJWTTokenParams) => void;
deleteJWTToken: (params: DeleteJWTTokenParams) => void;
createJWTToken: (params: CreateJWTTokenParams) => Promise<void>;
deleteJWTToken: (params: DeleteJWTTokenParams) => Promise<void>;
hideJWTToken: () => void;
getApi?: (formApi: FormApi) => void;
}

require('./project-role-jwt-tokens.scss');

export const ProjectRoleJWTTokens = (props: ProjectRoleJWTTokensProps) => {
const [progress, setProgress] = React.useState<{percentage: number; title: string} | null>(null);

return (
<Consumer>
{ctx => (
<React.Fragment>
<h4>JWT Tokens</h4>
<h4 style={{marginTop: '20px'}}>
JWT Tokens
{progress !== null && <ProgressPopup title={progress.title} percentage={progress.percentage} onClose={() => setProgress(null)} />}
<Button
title='Delete All Expired Tokens'
style={{marginLeft: '10px'}}
onClick={async () => {
const expiredTokens = props.tokens.filter(token => new Date(token.exp * 1000) < new Date());
if (expiredTokens.length === 0) {
ctx.notifications.show({
content: 'No expired tokens found for this role',
type: NotificationType.Warning
});
return;
}
await deleteJWTTokens(props, ctx, expiredTokens, setProgress);
}}>
Delete Expired
</Button>
</h4>
<div>Generate JWT tokens to bind to this role</div>
{props.tokens && props.tokens.length > 0 && (
<div className='argo-table-list'>
Expand Down Expand Up @@ -121,17 +144,45 @@ async function deleteJWTToken(props: ProjectRoleJWTTokensProps, iat: number, ctx
}
}

async function deleteJWTTokens(props: ProjectRoleJWTTokensProps, ctx: any, tokens: JwtToken[], setProgress: (progress: {percentage: number; title: string}) => void) {
const confirmed = await ctx.popup.confirm(
'Delete Expired JWT Tokens',
`Are you sure you want to delete all ${tokens.length} expired tokens for role '${props.roleName}' in project '${props.projName}'?`
);
if (confirmed) {
setProgress({percentage: 0, title: 'Deleting Expired Tokens'});
let i = 0;
const promises = tokens.map(token =>
props.deleteJWTToken({project: props.projName, role: props.roleName, iat: token.iat} as DeleteJWTTokenParams).then(() => {
setProgress({percentage: Number(((i / tokens.length) * 100).toFixed(2)), title: `Deleting token ${i + 1} of ${tokens.length}(${token.id})`});
i++;
})
);
await Promise.all(promises);

setProgress({percentage: 100, title: 'Delete Expired Tokens Complete'});
}
}

function renderJWTRow(props: ProjectRoleJWTTokensProps, ctx: ContextApis, jwToken: JwtToken): React.ReactFragment {
const issuedAt = new Date(jwToken.iat * 1000).toISOString();
const expiresAt = jwToken.exp == null ? 'Never' : new Date(jwToken.exp * 1000).toISOString();
const isExpired = jwToken.exp && jwToken.exp < Date.now() / 1000;

return (
<React.Fragment>
<div className='argo-table-list__row' key={`${jwToken.iat}`}>
<div className='row'>
<Tooltip content={jwToken.id}>
<div className='columns small-3'>{jwToken.id}</div>
</Tooltip>
<div className='columns small-3 project-role-jwt-tokens__id'>
<Tooltip content={jwToken.id}>
<span className='project-role-jwt-tokens__id-tooltip'>{jwToken.id}</span>
</Tooltip>
{isExpired && (
<span title='Expired' className='project-role-jwt-tokens__expired-token'>
Expired
</span>
)}
</div>
<Tooltip content={issuedAt}>
<div className='columns small-4'>{issuedAt}</div>
</Tooltip>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@ exports[`ProgressPopup.0% 1`] = `
<div
className="row popup-container__header popup-container__header__normal"
>

<span
className="progress-popup__title"
>

</span>
</div>
<div
className="row popup-container__body"
Expand All @@ -19,39 +23,39 @@ exports[`ProgressPopup.0% 1`] = `
className="columns large-12 popup-container__body__hasNoIcon"
>
<div
style={
{
"background": "#CCD6DD",
"borderRadius": "5px",
"height": "10px",
"margin": "15px auto",
"width": "90%",
}
}
className="progress-popup__content"
>
<div
style={
{
"background": "#18BE94",
"borderRadius": "inherit",
"height": "100%",
"transition": "width 0.1s ease-in",
"width": "0%",
"background": "#CCD6DD",
"borderRadius": "5px",
"height": "10px",
"margin": "15px auto",
"width": "90%",
}
}
/>
>
<div
style={
{
"background": "#18BE94",
"borderRadius": "inherit",
"height": "100%",
"transition": "width 0.1s ease-in",
"width": "0%",
}
}
/>
</div>
</div>
</div>
</div>
<div
className="row popup-container__footer"
>
<div
style={
{
"textAlign": "right",
}
}
className="progress-popup__footer"
/>
</div>
</div>
Expand All @@ -68,7 +72,11 @@ exports[`ProgressPopup.50% 1`] = `
<div
className="row popup-container__header popup-container__header__normal"
>
My Title
<span
className="progress-popup__title"
>
My Title
</span>
</div>
<div
className="row popup-container__body"
Expand All @@ -77,39 +85,39 @@ exports[`ProgressPopup.50% 1`] = `
className="columns large-12 popup-container__body__hasNoIcon"
>
<div
style={
{
"background": "#CCD6DD",
"borderRadius": "5px",
"height": "10px",
"margin": "15px auto",
"width": "90%",
}
}
className="progress-popup__content"
>
<div
style={
{
"background": "#18BE94",
"borderRadius": "inherit",
"height": "100%",
"transition": "width 0.1s ease-in",
"width": "100%",
"background": "#CCD6DD",
"borderRadius": "5px",
"height": "10px",
"margin": "15px auto",
"width": "90%",
}
}
/>
>
<div
style={
{
"background": "#18BE94",
"borderRadius": "inherit",
"height": "100%",
"transition": "width 0.1s ease-in",
"width": "100%",
}
}
/>
</div>
</div>
</div>
</div>
<div
className="row popup-container__footer"
>
<div
style={
{
"textAlign": "right",
}
}
className="progress-popup__footer"
/>
</div>
</div>
Expand All @@ -126,7 +134,11 @@ exports[`ProgressPopup.100% 1`] = `
<div
className="row popup-container__header popup-container__header__normal"
>

<span
className="progress-popup__title"
>

</span>
</div>
<div
className="row popup-container__body"
Expand All @@ -135,39 +147,39 @@ exports[`ProgressPopup.100% 1`] = `
className="columns large-12 popup-container__body__hasNoIcon"
>
<div
style={
{
"background": "#CCD6DD",
"borderRadius": "5px",
"height": "10px",
"margin": "15px auto",
"width": "90%",
}
}
className="progress-popup__content"
>
<div
style={
{
"background": "#18BE94",
"borderRadius": "inherit",
"height": "100%",
"transition": "width 0.1s ease-in",
"width": "100%",
"background": "#CCD6DD",
"borderRadius": "5px",
"height": "10px",
"margin": "15px auto",
"width": "90%",
}
}
/>
>
<div
style={
{
"background": "#18BE94",
"borderRadius": "inherit",
"height": "100%",
"transition": "width 0.1s ease-in",
"width": "100%",
}
}
/>
</div>
</div>
</div>
</div>
<div
className="row popup-container__footer"
>
<div
style={
{
"textAlign": "right",
}
}
className="progress-popup__footer"
>
<button
className="argo-button argo-button--base-o"
Expand Down
15 changes: 15 additions & 0 deletions ui/src/app/shared/components/progress/progress-popup.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
.progress-popup__title {
font-family: "Heebo", sans-serif;
font-weight: normal;
font-size: 16px;
font-style: normal;
color: #495763;
}

.progress-popup__footer {
text-align: right;
}

.progress-popup__content {
padding-top: 15px;
}
Loading