|
| 1 | +// This file is part of MinIO Console Server |
| 2 | +// Copyright (c) 2022 MinIO, Inc. |
| 3 | +// |
| 4 | +// This program is free software: you can redistribute it and/or modify |
| 5 | +// it under the terms of the GNU Affero General Public License as published by |
| 6 | +// the Free Software Foundation, either version 3 of the License, or |
| 7 | +// (at your option) any later version. |
| 8 | +// |
| 9 | +// This program is distributed in the hope that it will be useful, |
| 10 | +// but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | +// GNU Affero General Public License for more details. |
| 13 | +// |
| 14 | +// You should have received a copy of the GNU Affero General Public License |
| 15 | +// along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 16 | + |
| 17 | +import React, { useEffect, useState, Fragment } from "react"; |
| 18 | +import {useDispatch} from "react-redux"; |
| 19 | +import { Theme } from "@mui/material/styles"; |
| 20 | +import createStyles from "@mui/styles/createStyles"; |
| 21 | +import withStyles from "@mui/styles/withStyles"; |
| 22 | +import { |
| 23 | + setErrorSnackMessage, |
| 24 | +} from "../../../../systemSlice"; |
| 25 | +import { |
| 26 | + actionsTray, |
| 27 | + containerForHeader, |
| 28 | + searchField, tableStyles, |
| 29 | +} from "../../Common/FormComponents/common/styleLibrary"; |
| 30 | +import { ErrorResponseHandler } from "../../../../common/types"; |
| 31 | +import api from "../../../../common/api"; |
| 32 | +import TableContainer from "@mui/material/TableContainer"; |
| 33 | +import Paper from "@mui/material/Paper"; |
| 34 | +import Table from "@mui/material/Table"; |
| 35 | +import TableHead from "@mui/material/TableHead"; |
| 36 | +import TableRow from "@mui/material/TableRow"; |
| 37 | +import TableCell from "@mui/material/TableCell"; |
| 38 | +import TableBody from "@mui/material/TableBody"; |
| 39 | + |
| 40 | +interface ITenantCSRProps { |
| 41 | + classes: any; |
| 42 | + match: any; |
| 43 | + loadingTenant: boolean; |
| 44 | + setErrorSnackMessage: typeof setErrorSnackMessage; |
| 45 | +} |
| 46 | + |
| 47 | +const styles = (theme: Theme) => |
| 48 | + createStyles({ |
| 49 | + tableWrapper: { |
| 50 | + height: "450px", |
| 51 | + }, |
| 52 | + ...actionsTray, |
| 53 | + ...searchField, |
| 54 | + ...tableStyles, |
| 55 | + ...containerForHeader(theme.spacing(4)), |
| 56 | + }); |
| 57 | + |
| 58 | +const TenantCSR = ({ |
| 59 | + classes, |
| 60 | + match, |
| 61 | + loadingTenant, |
| 62 | + setErrorSnackMessage, |
| 63 | + }: ITenantCSRProps) => { |
| 64 | + const [loading, setLoading] = useState<boolean>(true); |
| 65 | + const tenantName = match.params["tenantName"]; |
| 66 | + const tenantNamespace = match.params["tenantNamespace"]; |
| 67 | + const [csrStatus] = useState([""]); |
| 68 | + const [csrName] = useState([""]); |
| 69 | + const [csrAnnotations] = useState([""]); |
| 70 | + const dispatch = useDispatch(); |
| 71 | + useEffect(() => { |
| 72 | + if (loadingTenant) { |
| 73 | + setLoading(true); |
| 74 | + } |
| 75 | + }, [loadingTenant]); |
| 76 | + |
| 77 | + useEffect(() => { |
| 78 | + if (loading) { |
| 79 | + api |
| 80 | + .invoke( |
| 81 | + "GET", |
| 82 | + `/api/v1/namespaces/${tenantNamespace}/tenants/${tenantName}/csr` |
| 83 | + ) |
| 84 | + .then((res) => { |
| 85 | + for (var _i = 0; _i < res.csrElement.length; _i++) { |
| 86 | + var entry = res.csrElement[_i]; |
| 87 | + csrStatus.push(entry.status) |
| 88 | + csrName.push(entry.name) |
| 89 | + csrAnnotations.push(entry.annotations) |
| 90 | + } |
| 91 | + setLoading(false); |
| 92 | + }) |
| 93 | + .catch((err: ErrorResponseHandler) => { |
| 94 | + dispatch(setErrorSnackMessage(err)); |
| 95 | + }); |
| 96 | + } |
| 97 | + }, [loading, tenantNamespace, tenantName, setErrorSnackMessage, csrAnnotations, csrName, csrStatus, dispatch]); |
| 98 | + |
| 99 | + return ( |
| 100 | + <Fragment> |
| 101 | + <h1 className={classes.sectionTitle}>Certificate Signing Requests</h1> |
| 102 | + <TableContainer component={Paper}> |
| 103 | + <Table aria-label="collapsible table"> |
| 104 | + <TableHead> |
| 105 | + <TableRow> |
| 106 | + <TableCell>Name</TableCell> |
| 107 | + <TableCell>Status</TableCell> |
| 108 | + <TableCell>Annotation</TableCell> |
| 109 | + <TableCell /> |
| 110 | + </TableRow> |
| 111 | + </TableHead> |
| 112 | + <TableBody> |
| 113 | + <TableRow> |
| 114 | + <TableCell> |
| 115 | + {csrName.map((csrName)=><p>{csrName}</p>)} |
| 116 | + </TableCell> |
| 117 | + <TableCell> |
| 118 | + {csrStatus.map((csrStatus)=><p>{csrStatus}</p>)} |
| 119 | + </TableCell> |
| 120 | + <TableCell> |
| 121 | + {csrAnnotations.map((csrAnnotations)=><p>{csrAnnotations}</p>)} |
| 122 | + </TableCell> |
| 123 | + </TableRow> |
| 124 | + </TableBody> |
| 125 | + </Table> |
| 126 | + </TableContainer> |
| 127 | + </Fragment> |
| 128 | + ); |
| 129 | +}; |
| 130 | + |
| 131 | +export default withStyles(styles)(TenantCSR); |
0 commit comments