preliminary ssh host structs, api, ui

This commit is contained in:
Tuan Dang
2025-04-05 22:25:06 -07:00
parent 18c8fc66ee
commit b8f04d6738
154 changed files with 1896 additions and 245 deletions
+2
View File
@@ -0,0 +1,2 @@
export { useCreateSshHost, useDeleteSshHost, useUpdateSshHost } from "./mutations";
export { useGetSshHostById } from "./queries";
@@ -0,0 +1,45 @@
import { useMutation, useQueryClient } from "@tanstack/react-query";
import { apiRequest } from "@app/config/request";
import { workspaceKeys } from "../workspace/query-keys";
import { TCreateSshHostDTO, TDeleteSshHostDTO, TSshHost, TUpdateSshHostDTO } from "./types";
export const useCreateSshHost = () => {
const queryClient = useQueryClient();
return useMutation<TSshHost, object, TCreateSshHostDTO>({
mutationFn: async (body) => {
const { data: host } = await apiRequest.post("/api/v1/ssh/hosts", body);
return host;
},
onSuccess: ({ projectId }) => {
queryClient.invalidateQueries({ queryKey: workspaceKeys.getWorkspaceSshHosts(projectId) });
}
});
};
export const useUpdateSshHost = () => {
const queryClient = useQueryClient();
return useMutation<TSshHost, object, TUpdateSshHostDTO>({
mutationFn: async ({ sshHostId, ...body }) => {
const { data: host } = await apiRequest.patch(`/api/v1/ssh/hosts/${sshHostId}`, body);
return host;
},
onSuccess: ({ projectId }) => {
queryClient.invalidateQueries({ queryKey: workspaceKeys.getWorkspaceSshHosts(projectId) });
}
});
};
export const useDeleteSshHost = () => {
const queryClient = useQueryClient();
return useMutation<TSshHost, object, TDeleteSshHostDTO>({
mutationFn: async ({ sshHostId }) => {
const { data: host } = await apiRequest.delete(`/api/v1/ssh/hosts/${sshHostId}`);
return host;
},
onSuccess: ({ projectId }) => {
queryClient.invalidateQueries({ queryKey: workspaceKeys.getWorkspaceSshHosts(projectId) });
}
});
};
@@ -0,0 +1,20 @@
import { useQuery } from "@tanstack/react-query";
import { apiRequest } from "@app/config/request";
import { TSshHost } from "./types";
export const sshHostKeys = {
getSshHostById: (sshHostId: string) => [{ sshHostId }, "ssh-host"]
};
export const useGetSshHostById = (sshHostId: string) => {
return useQuery({
queryKey: sshHostKeys.getSshHostById(sshHostId),
queryFn: async () => {
const { data: sshHost } = await apiRequest.get<TSshHost>(`/api/v1/ssh/hosts/${sshHostId}`);
return sshHost;
},
enabled: Boolean(sshHostId)
});
};
+37
View File
@@ -0,0 +1,37 @@
export type TSshHost = {
id: string;
projectId: string;
hostname: string;
userCertTtl: string;
hostCertTtl: string;
loginMappings: {
loginUser: string;
allowedPrincipals: string[];
}[];
};
export type TCreateSshHostDTO = {
projectId: string;
hostname: string;
userCertTtl?: string;
hostCertTtl?: string;
loginMappings: {
loginUser: string;
allowedPrincipals: string[];
}[];
};
export type TUpdateSshHostDTO = {
sshHostId: string;
hostname?: string;
userCertTtl?: string;
hostCertTtl?: string;
loginMappings?: {
loginUser: string;
allowedPrincipals: string[];
}[];
};
export type TDeleteSshHostDTO = {
sshHostId: string;
};