Skip to content

Commit

Permalink
Entry Expiration Features (#563)
Browse files Browse the repository at this point in the history
  • Loading branch information
mamy-CS authored Jan 23, 2025
2 parents 933b564 + 74b3548 commit 538f5ff
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 9 deletions.
15 changes: 8 additions & 7 deletions frontend/src/components/dashboard/entries-dashboard-table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,14 @@ import { AgentsReducerState, EntriesReducerState } from 'redux/actions/types';
import { RootState } from 'redux/reducers';

const columns: GridColDef[] = [
{ field: "id", headerName: "ID", width: 170, renderCell: renderCellExpand as (params: GridCellParams)=>JSX.Element },
{ field: "spiffeid", headerName: "Name", width: 170, renderCell: renderCellExpand as (params: GridCellParams)=>JSX.Element },
{ field: "parentId", headerName: "Parent ID", width: 170, renderCell: renderCellExpand as (params: GridCellParams)=>JSX.Element },
{ field: "clusterName", headerName: "Cluster Name", width: 150 },
{ field: "entryExpireTime", headerName: "Entry Expire Time", width: 150 },
{ field: "platformType", headerName: "Platform Type", width: 150 },
{ field: "adminFlag", headerName: "Admin Flag", width: 125, type: 'boolean'},
{ field: "id", headerName: "ID", width: 155, renderCell: renderCellExpand as (params: GridCellParams)=>JSX.Element },
{ field: "spiffeid", headerName: "Name", width: 155, renderCell: renderCellExpand as (params: GridCellParams)=>JSX.Element },
{ field: "parentId", headerName: "Parent ID", width: 155, renderCell: renderCellExpand as (params: GridCellParams)=>JSX.Element },
{ field: "clusterName", headerName: "Cluster Name", width: 135 },
{ field: "entryExpireTime", headerName: "Entry Expire Time", width: 135 },
{ field: "expiryStatus", headerName: "Status", width: 105 },
{ field: "platformType", headerName: "Platform Type", width: 135 },
{ field: "adminFlag", headerName: "Admin Flag", width: 110, type: 'boolean'},
];

interface EntriesDashBoardTableProp {
Expand Down
6 changes: 6 additions & 0 deletions frontend/src/components/tornjak-helper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -164,16 +164,22 @@ class TornjakHelper extends Component<TornjakHelperProp, TornjakHelperState> {
// get spire data
var admin = this.SpiffeHelper.getEntryAdminFlag(entry)
var expTime = "No Expiry Time"
var currTime = Date.now();
var expired = 'Active'
if (typeof entry.expires_at !== 'undefined') {
var d = new Date(this.SpiffeHelper.getEntryExpiryMillisecondsFromEpoch(entry))
expTime = d.toLocaleDateString("en-US", { month: 'short', day: 'numeric', year: 'numeric', hour: 'numeric', minute: 'numeric', second: 'numeric', hour12: false })
}
if (entry.expires_at <= Math.floor(currTime / 1000)){
expired = 'Expired'
}
return {
id: entry.id,
spiffeid: thisSpiffeId,
parentId: thisParentId,
adminFlag: admin,
entryExpireTime: expTime,
expiryStatus: expired,
platformType: plugin,
clusterName: cluster,
canonicalAgentId: canonicalParentId,
Expand Down
15 changes: 13 additions & 2 deletions frontend/src/tables/entries-list-table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,20 +62,27 @@ class EntriesListTable extends React.Component<EntriesListTableProp, EntriesList

prepareTableData() {
const { data } = this.props;
var currTime = Date.now();
let listData: { props: { entry: EntriesList; }; }[] | ({ key: string; props: { entry: EntriesList; }; } | JSX.Element)[] = [];
if (typeof (data) === "string" || data === undefined)
return
data.forEach(val => listData.push(Object.assign({}, val)));
let listtabledata: { idx: string; id: string; spiffeid: string; parentid: string; selectors: string; info: string }[] = [];
let listtabledata: { idx: string; id: string; spiffeid: string; parentid: string; selectors: string; info: string; expired: string }[] = [];
let i = 0;
for (i = 0; i < listData.length; i++) {
listtabledata[i] = { "idx": "", "id": "", "spiffeid": "", "parentid": "", "selectors": "", "info": "" };
listtabledata[i] = { "idx": "", "id": "", "spiffeid": "", "parentid": "", "selectors": "", "info": "", "expired": ""};
listtabledata[i]["idx"] = (i + 1).toString();
listtabledata[i]["id"] = listData[i].props.entry.id;
listtabledata[i]["spiffeid"] = "spiffe://" + listData[i].props.entry.spiffe_id.trust_domain + listData[i].props.entry.spiffe_id.path;
listtabledata[i]["parentid"] = "spiffe://" + listData[i].props.entry.parent_id.trust_domain + listData[i].props.entry.parent_id.path;
listtabledata[i]["selectors"] = listData[i].props.entry.selectors.map((s: { type: string; value: string; }) => s.type + ":" + s.value).join(', ');
listtabledata[i]["info"] = JSON.stringify(listData[i].props.entry, null, ' ');
if (listData[i].props.entry.expires_at <= Math.floor(currTime / 1000)) {
listtabledata[i]["expired"] = "Expired";
}
else {
listtabledata[i]["expired"] = "Active";
}
}
this.setState({
listTableData: listtabledata
Expand Down Expand Up @@ -162,6 +169,10 @@ class EntriesListTable extends React.Component<EntriesListTableProp, EntriesList
header: 'Info',
key: 'info',
},
{
header: 'Expiry Status',
key: 'expired',
},
];
return (
<div>
Expand Down
8 changes: 8 additions & 0 deletions frontend/src/tables/table-body.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,14 @@ class Body extends React.Component<BodyProp, BodyState> {
<div style={{ overflowX: 'auto', width: "400px" }}>
<pre>{cell.value}</pre>
</div>
) : cell.info.header === "expired" ? (
cell.value === "Expired" ? (
<div style={{ color: 'red' }}>
<pre>{cell.value}</pre>
</div>
) : (
cell.value
)
) : (
cell.value)}
</TableCell>
Expand Down

0 comments on commit 538f5ff

Please sign in to comment.