import { faCertificate, faEllipsis } from "@fortawesome/free-solid-svg-icons"; import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; import * as x509 from "@peculiar/x509"; import { format } from "date-fns"; import FileSaver from "file-saver"; import { twMerge } from "tailwind-merge"; import { ProjectPermissionCan } from "@app/components/permissions"; import { Badge, DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger, EmptyState, Table, TableContainer, TableSkeleton, TBody, Td, Th, THead, Tr } from "@app/components/v2"; import { ProjectPermissionActions, ProjectPermissionSub } from "@app/context"; import { useGetCaCerts } from "@app/hooks/api"; type Props = { caId: string; }; export const CaCertificatesTable = ({ caId }: Props) => { const { data: caCerts, isPending } = useGetCaCerts(caId); const downloadTxtFile = (filename: string, content: string) => { const blob = new Blob([content], { type: "text/plain;charset=utf-8" }); FileSaver.saveAs(blob, filename); }; return ( {isPending && } {!isPending && caCerts?.map?.((caCert, index) => { const isLastItem = index === caCerts.length - 1; const caCertObj = new x509.X509Certificate(caCert.certificate); return ( ); })}
CA Certificate # Not Before Not After
CA Certificate {caCert.version} {isLastItem && ( Current )}
{format(new Date(caCertObj.notBefore), "yyyy-MM-dd")} {format(new Date(caCertObj.notAfter), "yyyy-MM-dd")}
{(isAllowed) => ( { e.stopPropagation(); downloadTxtFile("cert.pem", caCert.certificate); }} disabled={!isAllowed} > Download CA Certificate )} {(isAllowed) => ( { e.stopPropagation(); downloadTxtFile("chain.pem", caCert.certificateChain); }} disabled={!isAllowed} > Download CA Certificate Chain )}
{!isPending && !caCerts?.length && ( )}
); };