Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.
TypeScript acmeagentsai-agentscertificate-managementdevsecopsenvironment-variableskubernetesopen-sourcepampkipostgresprivate-caprivileged-access-managementsecret-managementsecret-managersecretssecrets-managementsecuritysecurity-toolsvault
improvement(frontend): migrate kmip servers page to v3 components (#8066)
claude[bot]c7f46c4ffe9b
diff --git a/frontend/src/pages/organization/KmipServersPage/KmipServersPage.tsx b/frontend/src/pages/organization/KmipServersPage/KmipServersPage.tsxindex 8e32131be2..acb18f3778 100644--- a/frontend/src/pages/organization/KmipServersPage/KmipServersPage.tsx+++ b/frontend/src/pages/organization/KmipServersPage/KmipServersPage.tsx@@ -9,10 +9,8 @@ export const KmipServersPage = () => {<title>Infisical | KMIP Servers</title><meta property="og:image" content="/images/message.png" /></Helmet>- <div className="flex w-full justify-center bg-bunker-800 text-white">- <div className="w-full max-w-8xl">- <KmipServerTab />- </div>+ <div className="mx-auto flex w-full max-w-8xl flex-col">+ <KmipServerTab /></div></>);diff --git a/frontend/src/pages/organization/KmipServersPage/components/CreateKmipServerModal.tsx b/frontend/src/pages/organization/KmipServersPage/components/CreateKmipServerModal.tsxnew file mode 100644index 0000000000..71d23a5d57--- /dev/null+++ b/frontend/src/pages/organization/KmipServersPage/components/CreateKmipServerModal.tsx@@ -0,0 +1,208 @@+import { Controller, useForm } from "react-hook-form";+import { zodResolver } from "@hookform/resolvers/zod";+import { useNavigate } from "@tanstack/react-router";+import { z } from "zod";++import {+ Button,+ Dialog,+ DialogClose,+ DialogContent,+ DialogDescription,+ DialogFooter,+ DialogHeader,+ DialogTitle,+ Field,+ FieldDescription,+ FieldError,+ FieldLabel,+ Input,+ Select,+ SelectContent,+ SelectItem,+ SelectTrigger,+ SelectValue+} from "@app/components/v3";+import { useOrganization } from "@app/context";+import { useScopeVariant } from "@app/hooks";+import {+ certKeyAlgorithms,+ certKeyAlgorithmToNameMap,+ isPqcAlgorithm+} from "@app/hooks/api/certificates/constants";+import { CertKeyAlgorithm } from "@app/hooks/api/certificates/enums";+import { useCreateKmipServer } from "@app/hooks/api/kmipServers";++const schema = z.object({+ name: z.string().trim().min(1, "Name is required"),+ hostnamesOrIps: z+ .string()+ .trim()+ .min(1, "At least one hostname or IP is required")+ .max(4096, "Hostnames or IPs must be at most 4096 characters"),+ keyAlgorithm: z.nativeEnum(CertKeyAlgorithm)+});++const keyAlgorithmOptions = certKeyAlgorithms.filter(({ value }) => !isPqcAlgorithm(value));++export const CreateKmipServerModal = ({ isOpen, onOpenChange }: Props) => {+ const { currentOrg } = useOrganization();+ const orgId = currentOrg?.id || "";+ const navigate = useNavigate();+ const scopeVariant = useScopeVariant();+ const { mutateAsync: createKmipServer } = useCreateKmipServer();++ const {+ control,+ handleSubmit,+ reset,+ formState: { isSubmitting }+ } = useForm<FormData>({+ resolver: zodResolver(schema),+ defaultValues: {+ name: "",+ hostnamesOrIps: "",+ keyAlgorithm: CertKeyAlgorithm.RSA_2048+ }+ });++ const onSubmit = async (form: FormData) => {+ try {+ const kmipServer = await createKmipServer({+ name: form.name,+ hostnamesOrIps: form.hostnamesOrIps,+ keyAlgorithm: form.keyAlgorithm,+ authMethod: { method: "token" }+ });++ onOpenChange(false);+ navigate({+ to: "/organizations/$orgId/projects/kms/kmip-servers/$kmipServerId",+ params: { orgId, kmipServerId: kmipServer.id }+ });+ } catch {+ // MutationCache.onError already surfaces the API error.+ }+ };++ const handleClose = (open: boolean) => {+ if (!open) reset();+ onOpenChange(open);+ };++ return (+ <Dialog open={isOpen} onOpenChange={handleClose}>+ <DialogContent>+ <DialogHeader>+ <DialogTitle>Create KMIP Server</DialogTitle>+ <DialogDescription>+ Create a new KMIP server. You can generate an enrollment token and deploy it from the+ KMIP server detail page.+ </DialogDescription>+ </DialogHeader>+ <form onSubmit={handleSubmit(onSubmit)} className="flex flex-col gap-4">+ <Controller+ control={control}+ name="name"+ render={({ field, fieldState: { error } }) => (+ <Field data-invalid={Boolean(error)}>+ <FieldLabel htmlFor="kmip-server-name">+ Name+ <span aria-hidden className="text-danger">+ *+ </span>+ </FieldLabel>+ <Input+ {...field}+ id="kmip-server-name"+ placeholder="my-kmip-server"+ aria-required+ isError={Boolean(error)}+ autoFocus+ />+ <FieldError>{error?.message}</FieldError>+ </Field>+ )}+ />+ <Controller+ control={control}+ name="hostnamesOrIps"+ render={({ field, fieldState: { error } }) => (+ <Field data-invalid={Boolean(error)}>+ <FieldLabel htmlFor="kmip-server-hostnames">+ Hostnames or IPs+ <span aria-hidden className="text-danger">+ *+ </span>+ </FieldLabel>+ <Input+ {...field}+ id="kmip-server-hostnames"+ placeholder="kmip.example.com, 10.0.0.5"+ aria-required+ isError={Boolean(error)}+ />+ <FieldDescription>+ Comma-separated list of the hostnames or IPs that KMIP clients will use to reach+ this server. These become the server certificate's subject alternative names.+ </FieldDescription>+ <FieldError>{error?.message}</FieldError>+ </Field>+ )}+ />+ <Controller+ control={control}+ name="keyAlgorithm"+ render={({ field: { onChange, value }, fieldState: { error } }) => (+ <Field data-invalid={Boolean(error)}>+ <FieldLabel htmlFor="kmip-server-key-algorithm">Key algorithm</FieldLabel>+ <Select value={value} onValueChange={onChange}>+ <SelectTrigger+ id="kmip-server-key-algorithm"+ isError={Boolean(error)}+ className="w-full"+ >+ <SelectValue />+ </SelectTrigger>+ <SelectContent>+ {keyAlgorithmOptions.map(({ value: algorithm }) => (+ <SelectItem value={algorithm} key={algorithm}>+ {certKeyAlgorithmToNameMap[algorithm]}+ </SelectItem>+ ))}+ </SelectContent>+ </Select>+ <FieldDescription>+ Key algorithm used to sign the server certificate.+ </FieldDescription>+ <FieldError>{error?.message}</FieldError>+ </Field>+ )}+ />+ <DialogFooter>+ <DialogClose asChild>+ <Button variant="ghost" type="button">+ Cancel+ </Button>+ </DialogClose>+ <Button+ variant={scopeVariant}+ type="submit"+ isPending={isSubmitting}+ isDisabled={isSubmitting}+ >+ Create KMIP Server+ </Button>+ </DialogFooter>+ </form>+ </DialogContent>+ </Dialog>+ );+};++type FormData = z.infer<typeof schema>;++type Props = {+ isOpen: boolean;+ onOpenChange: (isOpen: boolean) => void;+};diff --git a/frontend/src/pages/organization/KmipServersPage/components/KmipServerTab.tsx b/frontend/src/pages/organization/KmipServersPage/components/KmipServerTab.tsxindex d365cf1e4e..06927fb89a 100644--- a/frontend/src/pages/organization/KmipServersPage/components/KmipServerTab.tsx+++ b/frontend/src/pages/organization/KmipServersPage/components/KmipServerTab.tsx@@ -1,50 +1,65 @@import { useState } from "react";-import {- faCopy,- faEllipsisV,- faMagnifyingGlass,- faPlus,- faSearch,- faServer,- faTrash-} from "@fortawesome/free-solid-svg-icons";-import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";import { useNavigate } from "@tanstack/react-router";import { formatRelative } from "date-fns";+import {+ CopyIcon,+ MoreHorizontalIcon,+ PlusIcon,+ SearchIcon,+ ServerIcon,+ TrashIcon+} from "lucide-react";import { createNotification } from "@app/components/notifications";import { OrgPermissionCan } from "@app/components/permissions";import {+ Alert,+ AlertDescription,Button,- DeleteActionModal,+ Card,+ CardAction,+ CardContent,+ CardDescription,+ CardHeader,+ CardTitle,+ DeleteConfirmDialog,+ DocumentationLinkBadge,DropdownMenu,DropdownMenuContent,DropdownMenuItem,DropdownMenuTrigger,- EmptyState,+ Empty,+ EmptyDescription,+ EmptyHeader,+ EmptyMedia,+ EmptyTitle,IconButton,- Input,+ InputGroup,+ InputGroupAddon,+ InputGroupInput,+ Skeleton,Table,- TableContainer,- TableSkeleton,- TBody,- Td,- Th,- THead,- Tooltip,- Tr-} from "@app/components/v2";-import { DocumentationLinkBadge } from "@app/components/v3";+ TableBody,+ TableCell,+ TableHead,+ TableHeader,+ TableHeadLabel,+ TableRow+} from "@app/components/v3";import { useOrganization } from "@app/context";import {OrgKmipServerPermissionActions,OrgPermissionSubjects} from "@app/context/OrgPermissionContext/types";import { withPermission } from "@app/hoc";-import { usePopUp } from "@app/hooks";+import { usePopUp, useScopeVariant } from "@app/hooks";import { useDeleteKmipServerById, useGetKmipServers } from "@app/hooks/api/kmipServers";+import { TKmipServer } from "@app/hooks/api/kmipServers/types";++import { CreateKmipServerModal } from "./CreateKmipServerModal";-import { KmipServerDeployModal } from "./components/KmipServerDeployModal";+const SKELETON_ROWS = ["first", "second", "third"];+const SKELETON_CELLS = ["name", "created", "actions"];export const KmipServerTab = withPermission(() => {@@ -52,10 +67,11 @@ export const KmipServerTab = withPermission(const { data: kmipServers, isPending: isLoading } = useGetKmipServers();const { currentOrg } = useOrganization();const orgId = currentOrg?.id || "";+ const scopeVariant = useScopeVariant();const { popUp, handlePopUpOpen, handlePopUpToggle } = usePopUp(["deleteKmipServer",- "deployKmipServer"+ "createKmipServer"] as const);const navigate = useNavigate();@@ -77,60 +93,93 @@ export const KmipServerTab = withPermission(el.name.toLowerCase().includes(search.toLowerCase()));+ const kmipServerToDelete = popUp.deleteKmipServer.data as TKmipServer | undefined;+ const isTableEmpty = !isLoading && !filteredKmipServers?.length;+return (- <div className="mb-6 rounded-lg border border-mineshaft-600 bg-mineshaft-900 p-4">- <div className="mb-2 flex items-center justify-between">- <div className="flex grow items-center gap-x-2">- <h3 className="text-lg font-medium text-mineshaft-100">KMIP Servers</h3>+ <Card>+ <CardHeader>+ <CardTitle>+ KMIP Servers<DocumentationLinkBadge href="https://infisical.com/docs/documentation/platform/kms/kmip" />- <div className="flex grow" />+ </CardTitle>+ <CardDescription>+ Create and configure KMIP servers that proxy KMIP requests to Infisical KMS+ </CardDescription>+ <CardAction><OrgPermissionCanI={OrgKmipServerPermissionActions.CreateKmipServers}a={OrgPermissionSubjects.KmipServer}>{(isAllowed) => (<Button- variant="outline_bg"- leftIcon={<FontAwesomeIcon icon={faPlus} />}+ variant={scopeVariant}isDisabled={!isAllowed}- onClick={() => handlePopUpOpen("deployKmipServer")}+ onClick={() => handlePopUpOpen("createKmipServer")}>+ <PlusIcon />Create KMIP Server</Button>)}</OrgPermissionCan>- </div>- </div>- <p className="mb-4 text-sm text-mineshaft-400">- Create and configure KMIP servers that proxy KMIP requests to Infisical KMS- </p>- <div>- <div className="flex gap-2">- <Input+ </CardAction>+ </CardHeader>+ <CardContent>+ <InputGroup className="mb-4">+ <InputGroupAddon align="inline-start">+ <SearchIcon />+ </InputGroupAddon>+ <InputGroupInputvalue={search}onChange={(e) => setSearch(e.target.value)}- leftIcon={<FontAwesomeIcon icon={faMagnifyingGlass} />}- placeholder="Search KMIP server..."- className="flex-1"+ placeholder="Search KMIP servers..."/>- </div>- <TableContainer className="mt-4">+ </InputGroup>+ {isTableEmpty ? (+ <Empty className="border">+ <EmptyHeader>+ <EmptyMedia variant="icon">+ {kmipServers?.length ? <SearchIcon /> : <ServerIcon />}+ </EmptyMedia>+ <EmptyTitle>+ {kmipServers?.length+ ? "No KMIP servers match your search"+ : "No KMIP servers configured"}+ </EmptyTitle>+ <EmptyDescription>+ {kmipServers?.length+ ? "Try a different search term."+ : "Create a KMIP server to proxy KMIP requests to Infisical KMS."}+ </EmptyDescription>+ </EmptyHeader>+ </Empty>+ ) : (<Table>- <THead>- <Tr>- <Th className="w-2/3">Name</Th>- <Th>Created</Th>- <Th className="w-5" />- </Tr>- </THead>- <TBody>- {isLoading && (- <TableSkeleton innerKey="kmip-server-table" columns={3} key="kmip-server-table" />- )}+ <TableHeader>+ <TableRow>+ <TableHead className="w-2/3">+ <TableHeadLabel>Name</TableHeadLabel>+ </TableHead>+ <TableHead>+ <TableHeadLabel>Created</TableHeadLabel>+ </TableHead>+ <TableHead variant="action" />+ </TableRow>+ </TableHeader>+ <TableBody>+ {isLoading &&+ SKELETON_ROWS.map((row) => (+ <TableRow key={`kmip-server-skeleton-${row}`}>+ {SKELETON_CELLS.map((cell) => (+ <TableCell key={`kmip-server-skeleton-${row}-${cell}`}>+ <Skeleton className="h-4 w-full" />+ </TableCell>+ ))}+ </TableRow>+ ))}{filteredKmipServers?.map((el) => (- <Tr+ <TableRowkey={el.id}- className="cursor-pointer hover:bg-mineshaft-700"onClick={() => {navigate({to: "/organizations/$orgId/projects/kms/kmip-servers/$kmipServerId",@@ -138,83 +187,66 @@ export const KmipServerTab = withPermission(});}}>- <Td>{el.name}</Td>- <Td>{formatRelative(new Date(el.createdAt), new Date())}</Td>- <Td className="w-5">- <Tooltip className="max-w-sm text-center" content="Options">- <DropdownMenu>- <DropdownMenuTrigger asChild>- <IconButton- ariaLabel="Options"- colorSchema="secondary"- className="w-6"- variant="plain"- >- <FontAwesomeIcon icon={faEllipsisV} />- </IconButton>- </DropdownMenuTrigger>- <DropdownMenuContent align="end">- <DropdownMenuItem- icon={<FontAwesomeIcon icon={faCopy} />}- onClick={(e) => {- e.stopPropagation();- navigator.clipboard.writeText(el.id);- }}- >- Copy ID- </DropdownMenuItem>- <OrgPermissionCan- I={OrgKmipServerPermissionActions.DeleteKmipServers}- a={OrgPermissionSubjects.KmipServer}- >- {(isAllowed: boolean) => (- <DropdownMenuItem- isDisabled={!isAllowed}- icon={<FontAwesomeIcon icon={faTrash} />}- className="text-red"- onClick={(e) => {- e.stopPropagation();- handlePopUpOpen("deleteKmipServer", el);- }}- >- Delete KMIP Server- </DropdownMenuItem>- )}- </OrgPermissionCan>- </DropdownMenuContent>- </DropdownMenu>- </Tooltip>- </Td>- </Tr>+ <TableCell isTruncatable>{el.name}</TableCell>+ <TableCell>{formatRelative(new Date(el.createdAt), new Date())}</TableCell>+ <TableCell variant="action" onClick={(e) => e.stopPropagation()}>+ <DropdownMenu>+ <DropdownMenuTrigger asChild>+ <IconButton aria-label="KMIP server options" variant="ghost" size="sm">+ <MoreHorizontalIcon />+ </IconButton>+ </DropdownMenuTrigger>+ <DropdownMenuContent align="end">+ <DropdownMenuItem onClick={() => navigator.clipboard.writeText(el.id)}>+ <CopyIcon />+ Copy ID+ </DropdownMenuItem>+ <OrgPermissionCan+ I={OrgKmipServerPermissionActions.DeleteKmipServers}+ a={OrgPermissionSubjects.KmipServer}+ >+ {(isAllowed: boolean) => (+ <DropdownMenuItem+ isDisabled={!isAllowed}+ variant="danger"+ onClick={() => handlePopUpOpen("deleteKmipServer", el)}+ >+ <TrashIcon />+ Delete KMIP Server+ </DropdownMenuItem>+ )}+ </OrgPermissionCan>+ </DropdownMenuContent>+ </DropdownMenu>+ </TableCell>+ </TableRow>))}- </TBody>+ </TableBody></Table>- {!isLoading && !filteredKmipServers?.length && (- <EmptyState- title={- kmipServers?.length- ? "No KMIP servers match search..."- : "No KMIP servers have been configured"- }- icon={kmipServers?.length ? faSearch : faServer}- />- )}- <DeleteActionModal- isOpen={popUp.deleteKmipServer.isOpen}- title={`Are you sure you want to delete KMIP server ${- (popUp?.deleteKmipServer?.data as { name: string })?.name || ""- }?`}- onChange={(isOpen) => handlePopUpToggle("deleteKmipServer", isOpen)}- deleteKey="confirm"- onDeleteApproved={() => handleDeleteKmipServer()}- />- <KmipServerDeployModal- isOpen={popUp.deployKmipServer.isOpen}- onOpenChange={(isOpen) => handlePopUpToggle("deployKmipServer", isOpen)}- />- </TableContainer>- </div>- </div>+ )}+ </CardContent>+ <DeleteConfirmDialog+ isOpen={popUp.deleteKmipServer.isOpen}+ onOpenChange={(isOpen) => handlePopUpToggle("deleteKmipServer", isOpen)}+ title={`Delete KMIP Server ${kmipServerToDelete?.name || ""}?`}+ description={+ <Alert variant="danger" appearance="borderless">+ <AlertDescription>+ This permanently removes the KMIP server {kmipServerToDelete?.name} from your+ organization. This cannot be undone.+ </AlertDescription>+ </Alert>+ }+ confirmKey={kmipServerToDelete?.name || ""}+ confirmLabel="Delete KMIP Server"+ isPending={deleteKmipServerById.isPending}+ onConfirm={handleDeleteKmipServer}+ />+ <CreateKmipServerModal+ isOpen={popUp.createKmipServer.isOpen}+ onOpenChange={(isOpen) => handlePopUpToggle("createKmipServer", isOpen)}+ />+ </Card>);},{diff --git a/frontend/src/pages/organization/KmipServersPage/components/components/KmipServerDeployModal.tsx b/frontend/src/pages/organization/KmipServersPage/components/components/KmipServerDeployModal.tsxdeleted file mode 100644index 45c4dedf0c..0000000000--- a/frontend/src/pages/organization/KmipServersPage/components/components/KmipServerDeployModal.tsx+++ /dev/null@@ -1,169 +0,0 @@-import { Controller, useForm } from "react-hook-form";-import { zodResolver } from "@hookform/resolvers/zod";-import { useNavigate } from "@tanstack/react-router";-import { z } from "zod";--import { createNotification } from "@app/components/notifications";-import {- Button,- FormControl,- Input,- Modal,- ModalClose,- ModalContent,- Select,- SelectItem-} from "@app/components/v2";-import { useOrganization } from "@app/context";-import {- certKeyAlgorithms,- certKeyAlgorithmToNameMap,- isPqcAlgorithm-} from "@app/hooks/api/certificates/constants";-import { CertKeyAlgorithm } from "@app/hooks/api/certificates/enums";-import { useCreateKmipServer } from "@app/hooks/api/kmipServers";--const schema = z.object({- name: z.string().trim().min(1, "Name is required"),- hostnamesOrIps: z- .string()- .trim()- .min(1, "At least one hostname or IP is required")- .max(4096, "Hostnames or IPs must be at most 4096 characters"),- keyAlgorithm: z.nativeEnum(CertKeyAlgorithm)-});--type FormData = z.infer<typeof schema>;--type Props = {- isOpen: boolean;- onOpenChange: (isOpen: boolean) => void;-};--export const KmipServerDeployModal = ({ isOpen, onOpenChange }: Props) => {- const { currentOrg } = useOrganization();- const orgId = currentOrg?.id || "";- const navigate = useNavigate();- const { mutateAsync: createKmipServer } = useCreateKmipServer();-- const {- control,- handleSubmit,- reset,- formState: { isSubmitting }- } = useForm<FormData>({- resolver: zodResolver(schema),- defaultValues: {- name: "",- hostnamesOrIps: "",- keyAlgorithm: CertKeyAlgorithm.RSA_2048- }- });-- const onSubmit = async (form: FormData) => {- try {- const kmipServer = await createKmipServer({- name: form.name,- hostnamesOrIps: form.hostnamesOrIps,- keyAlgorithm: form.keyAlgorithm,- authMethod: { method: "token" }- });-- onOpenChange(false);- navigate({- to: "/organizations/$orgId/projects/kms/kmip-servers/$kmipServerId",- params: { orgId, kmipServerId: kmipServer.id }- });- } catch (err: any) {- createNotification({- type: "error",- text: err?.message || "Failed to create KMIP server"- });- }- };-- const handleClose = (open: boolean) => {- if (!open) reset();- onOpenChange(open);- };-- return (- <Modal isOpen={isOpen} onOpenChange={handleClose}>- <ModalContent- className="max-w-lg"- title="Create KMIP Server"- subTitle="Create a new KMIP server. You can generate an enrollment token and deploy it from the KMIP server detail page."- bodyClassName="overflow-visible"- >- <form onSubmit={handleSubmit(onSubmit)}>- <Controller- control={control}- name="name"- render={({ field, fieldState: { error } }) => (- <FormControl- label="Name"- isRequired- isError={Boolean(error)}- errorText={error?.message}- >- <Input {...field} placeholder="my-kmip-server" />- </FormControl>- )}- />- <Controller- control={control}- name="hostnamesOrIps"- render={({ field, fieldState: { error } }) => (- <FormControl- label="Hostnames or IPs"- isRequired- isError={Boolean(error)}- errorText={error?.message}- helperText="Comma-separated list of the hostnames or IPs that KMIP clients will use to reach this server. These become the server certificate's subject alternative names."- >- <Input {...field} placeholder="kmip.example.com, 10.0.0.5" />- </FormControl>- )}- />- <Controller- control={control}- name="keyAlgorithm"- render={({ field: { onChange, ...field }, fieldState: { error } }) => (- <FormControl- label="Key Algorithm"- isError={Boolean(error)}- errorText={error?.message}- helperText="Key algorithm used to sign the server certificate."- >- <Select- defaultValue={field.value}- {...field}- onValueChange={(e) => onChange(e)}- className="w-full"- >- {certKeyAlgorithms- .filter(({ value }) => !isPqcAlgorithm(value))- .map(({ value }) => (- <SelectItem value={String(value || "")} key={value}>- {certKeyAlgorithmToNameMap[value]}- </SelectItem>- ))}- </Select>- </FormControl>- )}- />- <div className="mt-6 flex items-center gap-2">- <Button type="submit" isLoading={isSubmitting} isDisabled={isSubmitting} size="sm">- Create KMIP Server- </Button>- <ModalClose asChild>- <Button size="sm" colorSchema="secondary">- Cancel- </Button>- </ModalClose>- </div>- </form>- </ModalContent>- </Modal>- );-};