Skip to content

Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.

Fix merge conflicts

Tuan Dang47ea4ae9a617
diff --cc backend/src/db/migrations/20240818184238_add-certificate-template.ts
index 7135c24e08,0000000000..7135c24e08
mode 100644,000000..100644
--- a/backend/src/db/migrations/20240818184238_add-certificate-template.ts
+++ b/backend/src/db/migrations/20240818184238_add-certificate-template.ts
diff --cc backend/src/server/routes/v1/index.ts
index c588187c4f,01bec65ad7..e5f35565fd
--- a/backend/src/server/routes/v1/index.ts
+++ b/backend/src/server/routes/v1/index.ts
@@@ -77,9 -76,8 +77,9 @@@ export const registerV1Routes = async (
async (pkiRouter) => {
await pkiRouter.register(registerCaRouter, { prefix: "/ca" });
await pkiRouter.register(registerCertRouter, { prefix: "/certificates" });
+ await pkiRouter.register(registerCertificateTemplateRouter, { prefix: "/certificate-templates" });
- await server.register(registerPkiAlertRouter, { prefix: "/alerts" });
- await server.register(registerPkiCollectionRouter, { prefix: "/collections" });
+ await pkiRouter.register(registerPkiAlertRouter, { prefix: "/alerts" });
+ await pkiRouter.register(registerPkiCollectionRouter, { prefix: "/collections" });
},
{ prefix: "/pki" }
);
diff --cc frontend/src/views/Project/CertificatesPage/components/CertificatesTab/components/CertificateTemplatesSection.tsx
index 82c4c8d3a2,0000000000..3341e521cd
mode 100644,000000..100644
--- a/frontend/src/views/Project/CertificatesPage/components/CertificatesTab/components/CertificateTemplatesSection.tsx
+++ b/frontend/src/views/Project/CertificatesPage/components/CertificatesTab/components/CertificateTemplatesSection.tsx
@@@ -1,87 -1,0 +1,87 @@@
+import { faPlus } from "@fortawesome/free-solid-svg-icons";
+import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
+
+import { createNotification } from "@app/components/notifications";
+import { ProjectPermissionCan } from "@app/components/permissions";
+import { Button, DeleteActionModal } from "@app/components/v2";
+import { ProjectPermissionActions, ProjectPermissionSub, useWorkspace } from "@app/context";
+import { usePopUp } from "@app/hooks";
+import { useDeleteCertTemplate } from "@app/hooks/api";
+
+import { CertificateTemplateModal } from "./CertificateTemplateModal";
+import { CertificateTemplatesTable } from "./CertificateTemplatesTable";
+
+export const CertificateTemplatesSection = () => {
+ const { popUp, handlePopUpOpen, handlePopUpClose, handlePopUpToggle } = usePopUp([
+ "certificateTemplate",
+ "deleteCertificateTemplate"
+ ] as const);
+
+ const { currentWorkspace } = useWorkspace();
+ const { mutateAsync: deleteCertTemplate } = useDeleteCertTemplate();
+
+ const onRemoveCertificateTemplateSubmit = async (id: string) => {
+ if (!currentWorkspace?.id) {
+ return;
+ }
+
+ try {
+ await deleteCertTemplate({
+ id,
+ projectId: currentWorkspace.id
+ });
+
+ await createNotification({
+ text: "Successfully deleted certificate template",
+ type: "success"
+ });
+
+ handlePopUpClose("deleteCertificateTemplate");
+ } catch (err) {
+ console.error(err);
+ createNotification({
+ text: "Failed to delete certificate template",
+ type: "error"
+ });
+ }
+ };
+
+ return (
+ <div className="mb-6 rounded-lg border border-mineshaft-600 bg-mineshaft-900 p-4">
+ <div className="mb-4 flex justify-between">
+ <p className="text-xl font-semibold text-mineshaft-100">Certificate Templates</p>
+ <ProjectPermissionCan
+ I={ProjectPermissionActions.Create}
+ a={ProjectPermissionSub.Certificates}
+ >
+ {(isAllowed) => (
+ <Button
+ colorSchema="primary"
+ type="submit"
+ leftIcon={<FontAwesomeIcon icon={faPlus} />}
+ onClick={() => handlePopUpOpen("certificateTemplate")}
+ isDisabled={!isAllowed}
+ >
- Create Certificate Template
++ Create
+ </Button>
+ )}
+ </ProjectPermissionCan>
+ </div>
+ <CertificateTemplatesTable handlePopUpOpen={handlePopUpOpen} />
+ <CertificateTemplateModal popUp={popUp} handlePopUpToggle={handlePopUpToggle} />
+ <DeleteActionModal
+ isOpen={popUp.deleteCertificateTemplate.isOpen}
+ title={`Are you sure want to delete the certificate template ${
+ (popUp?.deleteCertificateTemplate?.data as { name: string })?.name || ""
+ } from the project?`}
+ onChange={(isOpen) => handlePopUpToggle("deleteCertificateTemplate", isOpen)}
+ deleteKey="confirm"
+ onDeleteApproved={() =>
+ onRemoveCertificateTemplateSubmit(
+ (popUp?.deleteCertificateTemplate?.data as { id: string })?.id
+ )
+ }
+ />
+ </div>
+ );
+};
diff --cc frontend/src/views/Project/CertificatesPage/components/CertificatesTab/components/CertificateTemplatesTable.tsx
index 297b2d8178,0000000000..e504c95210
mode 100644,000000..100644
--- a/frontend/src/views/Project/CertificatesPage/components/CertificatesTab/components/CertificateTemplatesTable.tsx
+++ b/frontend/src/views/Project/CertificatesPage/components/CertificatesTab/components/CertificateTemplatesTable.tsx
@@@ -1,117 -1,0 +1,117 @@@
- import { faEllipsis, faGear, faTrash } from "@fortawesome/free-solid-svg-icons";
++import { faEllipsis, faFileAlt, faTrash } from "@fortawesome/free-solid-svg-icons";
+import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
+import { twMerge } from "tailwind-merge";
+
+import { ProjectPermissionCan } from "@app/components/permissions";
+import {
+ DropdownMenu,
+ DropdownMenuContent,
+ DropdownMenuItem,
+ DropdownMenuTrigger,
+ EmptyState,
+ Table,
+ TableContainer,
+ TableSkeleton,
+ TBody,
+ Td,
+ Th,
+ THead,
+ Tooltip,
+ Tr
+} from "@app/components/v2";
+import { ProjectPermissionActions, ProjectPermissionSub, useWorkspace } from "@app/context";
+import { useListWorkspaceCertificateTemplates } from "@app/hooks/api";
+import { UsePopUpState } from "@app/hooks/usePopUp";
+
+type Props = {
+ handlePopUpOpen: (
+ popUpName: keyof UsePopUpState<["certificateTemplate", "deleteCertificateTemplate"]>,
+ data?: {
+ id?: string;
+ name?: string;
+ }
+ ) => void;
+};
+
+export const CertificateTemplatesTable = ({ handlePopUpOpen }: Props) => {
+ const { currentWorkspace } = useWorkspace();
+ const { data, isLoading } = useListWorkspaceCertificateTemplates({
+ workspaceId: currentWorkspace?.id ?? ""
+ });
+
+ return (
+ <div>
+ <TableContainer>
+ <Table>
+ <THead>
+ <Tr>
+ <Th>Name</Th>
+ <Th>Certificate Authority</Th>
+ <Th />
+ </Tr>
+ </THead>
+ <TBody>
+ {isLoading && <TableSkeleton columns={2} innerKey="project-cas" />}
+ {!isLoading &&
+ data?.certificateTemplates.map((certificateTemplate) => {
+ return (
+ <Tr className="h-10" key={`certificate-${certificateTemplate.id}`}>
+ <Td>{certificateTemplate.name}</Td>
+ <Td>{certificateTemplate.caName}</Td>
+ <Td className="flex justify-end">
+ <DropdownMenu>
+ <DropdownMenuTrigger asChild className="rounded-lg">
+ <div className="hover:text-primary-400 data-[state=open]:text-primary-400">
+ <Tooltip content="More options">
+ <FontAwesomeIcon size="lg" icon={faEllipsis} />
+ </Tooltip>
+ </div>
+ </DropdownMenuTrigger>
+ <DropdownMenuContent align="start" className="p-1">
+ <DropdownMenuItem
+ onClick={() =>
+ handlePopUpOpen("certificateTemplate", {
+ id: certificateTemplate.id
+ })
+ }
- icon={<FontAwesomeIcon icon={faGear} />}
++ icon={<FontAwesomeIcon icon={faFileAlt} />}
+ >
+ Manage Policies
+ </DropdownMenuItem>
+ <ProjectPermissionCan
+ I={ProjectPermissionActions.Delete}
+ a={ProjectPermissionSub.CertificateTemplates}
+ >
+ {(isAllowed) => (
+ <DropdownMenuItem
+ className={twMerge(
+ !isAllowed && "pointer-events-none cursor-not-allowed opacity-50"
+ )}
+ disabled={!isAllowed}
+ icon={<FontAwesomeIcon icon={faTrash} />}
+ onClick={() =>
+ handlePopUpOpen("deleteCertificateTemplate", {
+ id: certificateTemplate.id,
+ name: certificateTemplate.name
+ })
+ }
+ >
+ Delete Template
+ </DropdownMenuItem>
+ )}
+ </ProjectPermissionCan>
+ </DropdownMenuContent>
+ </DropdownMenu>
+ </Td>
+ </Tr>
+ );
+ })}
+ </TBody>
+ </Table>
+ {!isLoading && !data?.certificateTemplates?.length && (
- <EmptyState title="No certificate templates have been created" icon={faGear} />
++ <EmptyState title="No certificate templates have been created" icon={faFileAlt} />
+ )}
+ </TableContainer>
+ </div>
+ );
+};
diff --cc frontend/src/views/Project/CertificatesPage/components/CertificatesTab/components/CertificatesSection.tsx
index 58bb8ef4cf,58bb8ef4cf..962083b22c
--- a/frontend/src/views/Project/CertificatesPage/components/CertificatesTab/components/CertificatesSection.tsx
+++ b/frontend/src/views/Project/CertificatesPage/components/CertificatesTab/components/CertificatesSection.tsx
@@@ -61,7 -61,7 +61,7 @@@ export const CertificatesSection = () =
onClick={() => handlePopUpOpen("certificate")}
isDisabled={!isAllowed}
>
-- Issue Certificate
++ Issue
</Button>
)}
</ProjectPermissionCan>
diff --cc frontend/src/views/Project/CertificatesPage/components/CertificatesTab/components/CertificatesTable.tsx
index f23299aa8f,bd2086ade3..a3a6106f36
--- a/frontend/src/views/Project/CertificatesPage/components/CertificatesTab/components/CertificatesTable.tsx
+++ b/frontend/src/views/Project/CertificatesPage/components/CertificatesTab/components/CertificatesTable.tsx
@@@ -60,146 -62,155 +62,155 @@@ export const CertificatesTable = ({ han
});
return (
- <div>
- <TableContainer>
- <Table>
- <THead>
- <Tr>
- <Th>Friendly Name</Th>
- <Th>Status</Th>
- <Th>Valid Until</Th>
- <Th />
- </Tr>
- </THead>
- <TBody>
- {isLoading && <TableSkeleton columns={3} innerKey="project-cas" />}
- {!isLoading &&
- data?.certificates.map((certificate) => {
- return (
- <Tr className="h-10" key={`certificate-${certificate.id}`}>
- <Td>{certificate.friendlyName}</Td>
- <Td>{certStatusToNameMap[certificate.status]}</Td>
- <Td>
- {certificate.notAfter
- ? format(new Date(certificate.notAfter), "yyyy-MM-dd")
- : "-"}
- </Td>
- <Td className="flex justify-end">
- <DropdownMenu>
- <DropdownMenuTrigger asChild className="rounded-lg">
- <div className="hover:text-primary-400 data-[state=open]:text-primary-400">
- <Tooltip content="More options">
- <FontAwesomeIcon size="lg" icon={faEllipsis} />
- </Tooltip>
- </div>
- </DropdownMenuTrigger>
- <DropdownMenuContent align="start" className="p-1">
- <ProjectPermissionCan
- I={ProjectPermissionActions.Read}
- a={ProjectPermissionSub.Certificates}
- >
- {(isAllowed) => (
- <DropdownMenuItem
- className={twMerge(
- !isAllowed && "pointer-events-none cursor-not-allowed opacity-50"
- )}
- onClick={async () =>
- handlePopUpOpen("certificateCert", {
- serialNumber: certificate.serialNumber
- })
- }
- disabled={!isAllowed}
- icon={<FontAwesomeIcon icon={faFileExport} />}
- >
- Export Certificate
- </DropdownMenuItem>
- )}
- </ProjectPermissionCan>
- <ProjectPermissionCan
- I={ProjectPermissionActions.Read}
- a={ProjectPermissionSub.Certificates}
- >
- {(isAllowed) => (
- <DropdownMenuItem
- className={twMerge(
- !isAllowed && "pointer-events-none cursor-not-allowed opacity-50"
- )}
- onClick={async () =>
- handlePopUpOpen("certificate", {
- serialNumber: certificate.serialNumber
- })
- }
- disabled={!isAllowed}
- icon={<FontAwesomeIcon icon={faEye} />}
- >
- View Details
- </DropdownMenuItem>
- )}
- </ProjectPermissionCan>
- <ProjectPermissionCan
- I={ProjectPermissionActions.Delete}
- a={ProjectPermissionSub.Certificates}
- >
- {(isAllowed) => (
- <DropdownMenuItem
- className={twMerge(
- !isAllowed && "pointer-events-none cursor-not-allowed opacity-50"
- )}
- onClick={async () =>
- handlePopUpOpen("revokeCertificate", {
- serialNumber: certificate.serialNumber
- })
- }
- disabled={!isAllowed}
- icon={<FontAwesomeIcon icon={faBan} />}
- >
- Revoke Certificate
- </DropdownMenuItem>
- )}
- </ProjectPermissionCan>
- <ProjectPermissionCan
- I={ProjectPermissionActions.Delete}
- a={ProjectPermissionSub.Certificates}
- >
- {(isAllowed) => (
- <DropdownMenuItem
- className={twMerge(
- !isAllowed && "pointer-events-none cursor-not-allowed opacity-50"
- )}
- onClick={async () =>
- handlePopUpOpen("deleteCertificate", {
- serialNumber: certificate.serialNumber,
- commonName: certificate.commonName
- })
- }
- disabled={!isAllowed}
- icon={<FontAwesomeIcon icon={faTrash} />}
- >
- Delete Certificate
- </DropdownMenuItem>
- )}
- </ProjectPermissionCan>
- </DropdownMenuContent>
- </DropdownMenu>
- </Td>
- </Tr>
- );
- })}
- </TBody>
- </Table>
- {!isLoading && data?.totalCount !== undefined && data.totalCount >= PER_PAGE_INIT && (
- <Pagination
- count={data.totalCount}
- page={page}
- perPage={perPage}
- onChangePage={(newPage) => setPage(newPage)}
- onChangePerPage={(newPerPage) => setPerPage(newPerPage)}
- />
- )}
- {!isLoading && !data?.certificates?.length && (
- <EmptyState title="No certificates have been created" icon={faCertificate} />
- )}
- </TableContainer>
- </div>
+ <TableContainer>
+ <Table>
+ <THead>
+ <Tr>
+ <Th>Friendly Name</Th>
+ <Th>Status</Th>
+ <Th>Not Before</Th>
+ <Th>Not After</Th>
+ <Th />
+ </Tr>
+ </THead>
+ <TBody>
+ {isLoading && <TableSkeleton columns={3} innerKey="project-cas" />}
+ {!isLoading &&
+ data?.certificates.map((certificate) => {
+ const { variant, label } = getCertValidUntilBadgeDetails(certificate.notAfter);
+ return (
+ <Tr className="h-10" key={`certificate-${certificate.id}`}>
+ <Td>{certificate.friendlyName}</Td>
+ <Td>
+ <Badge className="" variant={variant}>
+ {label}
+ </Badge>
+ </Td>
+ <Td>
+ {certificate.notBefore
+ ? format(new Date(certificate.notBefore), "yyyy-MM-dd")
+ : "-"}
+ </Td>
+ <Td>
+ {certificate.notAfter
+ ? format(new Date(certificate.notAfter), "yyyy-MM-dd")
+ : "-"}
+ </Td>
+ <Td className="flex justify-end">
+ <DropdownMenu>
+ <DropdownMenuTrigger asChild className="rounded-lg">
+ <div className="hover:text-primary-400 data-[state=open]:text-primary-400">
+ <Tooltip content="More options">
+ <FontAwesomeIcon size="lg" icon={faEllipsis} />
+ </Tooltip>
+ </div>
+ </DropdownMenuTrigger>
+ <DropdownMenuContent align="start" className="p-1">
+ <ProjectPermissionCan
+ I={ProjectPermissionActions.Read}
+ a={ProjectPermissionSub.Certificates}
+ >
+ {(isAllowed) => (
+ <DropdownMenuItem
+ className={twMerge(
+ !isAllowed && "pointer-events-none cursor-not-allowed opacity-50"
+ )}
+ onClick={async () =>
+ handlePopUpOpen("certificateCert", {
+ serialNumber: certificate.serialNumber
+ })
+ }
+ disabled={!isAllowed}
+ icon={<FontAwesomeIcon icon={faFileExport} />}
+ >
+ Export Certificate
+ </DropdownMenuItem>
+ )}
+ </ProjectPermissionCan>
+ <ProjectPermissionCan
+ I={ProjectPermissionActions.Read}
+ a={ProjectPermissionSub.Certificates}
+ >
+ {(isAllowed) => (
+ <DropdownMenuItem
+ className={twMerge(
+ !isAllowed && "pointer-events-none cursor-not-allowed opacity-50"
+ )}
+ onClick={async () =>
+ handlePopUpOpen("certificate", {
+ serialNumber: certificate.serialNumber
+ })
+ }
+ disabled={!isAllowed}
+ icon={<FontAwesomeIcon icon={faEye} />}
+ >
+ View Details
+ </DropdownMenuItem>
+ )}
+ </ProjectPermissionCan>
+ <ProjectPermissionCan
+ I={ProjectPermissionActions.Delete}
+ a={ProjectPermissionSub.Certificates}
+ >
+ {(isAllowed) => (
+ <DropdownMenuItem
+ className={twMerge(
+ !isAllowed && "pointer-events-none cursor-not-allowed opacity-50"
+ )}
+ onClick={async () =>
+ handlePopUpOpen("revokeCertificate", {
+ serialNumber: certificate.serialNumber
+ })
+ }
+ disabled={!isAllowed}
+ icon={<FontAwesomeIcon icon={faBan} />}
+ >
+ Revoke Certificate
+ </DropdownMenuItem>
+ )}
+ </ProjectPermissionCan>
+ <ProjectPermissionCan
+ I={ProjectPermissionActions.Delete}
+ a={ProjectPermissionSub.Certificates}
+ >
+ {(isAllowed) => (
+ <DropdownMenuItem
+ className={twMerge(
+ !isAllowed && "pointer-events-none cursor-not-allowed opacity-50"
+ )}
+ onClick={async () =>
+ handlePopUpOpen("deleteCertificate", {
+ serialNumber: certificate.serialNumber,
+ commonName: certificate.commonName
+ })
+ }
+ disabled={!isAllowed}
+ icon={<FontAwesomeIcon icon={faTrash} />}
+ >
+ Delete Certificate
+ </DropdownMenuItem>
+ )}
+ </ProjectPermissionCan>
+ </DropdownMenuContent>
+ </DropdownMenu>
+ </Td>
+ </Tr>
+ );
+ })}
+ </TBody>
+ </Table>
+ {!isLoading && data?.totalCount !== undefined && data.totalCount >= PER_PAGE_INIT && (
+ <Pagination
+ count={data.totalCount}
+ page={page}
+ perPage={perPage}
+ onChangePage={(newPage) => setPage(newPage)}
+ onChangePerPage={(newPerPage) => setPerPage(newPerPage)}
+ />
+ )}
+ {!isLoading && !data?.certificates?.length && (
- <EmptyState title="No certificates have been created" icon={faCertificate} />
++ <EmptyState title="No certificates have been issued" icon={faCertificate} />
+ )}
+ </TableContainer>
);
};