mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-06 13:27:22 +00:00
Add frontend uniqueness check for ssh hostnames
This commit is contained in:
@@ -23,6 +23,7 @@ import {
|
|||||||
useCreateSshHost,
|
useCreateSshHost,
|
||||||
useGetSshHostById,
|
useGetSshHostById,
|
||||||
useGetWorkspaceUsers,
|
useGetWorkspaceUsers,
|
||||||
|
useListWorkspaceSshHosts,
|
||||||
useUpdateSshHost
|
useUpdateSshHost
|
||||||
} from "@app/hooks/api";
|
} from "@app/hooks/api";
|
||||||
import { UsePopUpState } from "@app/hooks/usePopUp";
|
import { UsePopUpState } from "@app/hooks/usePopUp";
|
||||||
@@ -58,6 +59,7 @@ export type FormData = z.infer<typeof schema>;
|
|||||||
export const SshHostModal = ({ popUp, handlePopUpToggle }: Props) => {
|
export const SshHostModal = ({ popUp, handlePopUpToggle }: Props) => {
|
||||||
const { currentWorkspace } = useWorkspace();
|
const { currentWorkspace } = useWorkspace();
|
||||||
const projectId = currentWorkspace?.id || "";
|
const projectId = currentWorkspace?.id || "";
|
||||||
|
const { data: sshHosts } = useListWorkspaceSshHosts(currentWorkspace.id);
|
||||||
const { data: members = [] } = useGetWorkspaceUsers(projectId);
|
const { data: members = [] } = useGetWorkspaceUsers(projectId);
|
||||||
const [expandedMappings, setExpandedMappings] = useState<Record<number, boolean>>({});
|
const [expandedMappings, setExpandedMappings] = useState<Record<number, boolean>>({});
|
||||||
|
|
||||||
@@ -116,6 +118,18 @@ export const SshHostModal = ({ popUp, handlePopUpToggle }: Props) => {
|
|||||||
try {
|
try {
|
||||||
if (!projectId) return;
|
if (!projectId) return;
|
||||||
|
|
||||||
|
// check if there is already a different host with the same hostname
|
||||||
|
const existingHostnames =
|
||||||
|
sshHosts?.filter((h) => h.id !== sshHost?.id).map((h) => h.hostname) || [];
|
||||||
|
|
||||||
|
if (existingHostnames.includes(hostname)) {
|
||||||
|
createNotification({
|
||||||
|
text: "A host with this hostname already exists.",
|
||||||
|
type: "error"
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (sshHost) {
|
if (sshHost) {
|
||||||
await updateMutateAsync({
|
await updateMutateAsync({
|
||||||
sshHostId: sshHost.id,
|
sshHostId: sshHost.id,
|
||||||
|
|||||||
Reference in New Issue
Block a user