mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-15 21:40:31 +00:00
preliminary ssh host structs, api, ui
This commit is contained in:
@@ -41,6 +41,7 @@ export * from "./serverDetails";
|
||||
export * from "./serviceTokens";
|
||||
export * from "./sshCa";
|
||||
export * from "./sshCertificateTemplates";
|
||||
export * from "./sshHost";
|
||||
export * from "./ssoConfig";
|
||||
export * from "./subscriptions";
|
||||
export * from "./tags";
|
||||
|
||||
@@ -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)
|
||||
});
|
||||
};
|
||||
@@ -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;
|
||||
};
|
||||
@@ -35,6 +35,7 @@ export {
|
||||
useListWorkspaceSshCas,
|
||||
useListWorkspaceSshCertificates,
|
||||
useListWorkspaceSshCertificateTemplates,
|
||||
useListWorkspaceSshHosts,
|
||||
useNameWorkspaceSecrets,
|
||||
useToggleAutoCapitalization,
|
||||
useUpdateIdentityWorkspaceRole,
|
||||
|
||||
@@ -17,6 +17,7 @@ import { TPkiCollection } from "../pkiCollections/types";
|
||||
import { EncryptedSecret } from "../secrets/types";
|
||||
import { TSshCertificate, TSshCertificateAuthority } from "../sshCa/types";
|
||||
import { TSshCertificateTemplate } from "../sshCertificateTemplates/types";
|
||||
import { TSshHost } from "../sshHost/types";
|
||||
import { userKeys } from "../users/query-keys";
|
||||
import { TWorkspaceUser } from "../users/types";
|
||||
import { ProjectSlackConfig } from "../workflowIntegrations/types";
|
||||
@@ -809,6 +810,19 @@ export const useListWorkspaceSshCas = (projectId: string) => {
|
||||
});
|
||||
};
|
||||
|
||||
export const useListWorkspaceSshHosts = (projectId: string) => {
|
||||
return useQuery({
|
||||
queryKey: workspaceKeys.getWorkspaceSshHosts(projectId),
|
||||
queryFn: async () => {
|
||||
const {
|
||||
data: { hosts }
|
||||
} = await apiRequest.get<{ hosts: TSshHost[] }>(`/api/v2/workspace/${projectId}/ssh-hosts`);
|
||||
return hosts;
|
||||
},
|
||||
enabled: Boolean(projectId)
|
||||
});
|
||||
};
|
||||
|
||||
export const useListWorkspaceSshCertificateTemplates = (projectId: string) => {
|
||||
return useQuery({
|
||||
queryKey: workspaceKeys.getWorkspaceSshCertificateTemplates(projectId),
|
||||
|
||||
@@ -57,6 +57,7 @@ export const workspaceKeys = {
|
||||
getWorkspaceSshCas: (projectId: string) => [{ projectId }, "workspace-ssh-cas"] as const,
|
||||
allWorkspaceSshCertificates: (projectId: string) =>
|
||||
[{ projectId }, "workspace-ssh-certificates"] as const,
|
||||
getWorkspaceSshHosts: (projectId: string) => [{ projectId }, "workspace-ssh-hosts"] as const,
|
||||
specificWorkspaceSshCertificates: ({
|
||||
offset,
|
||||
limit,
|
||||
|
||||
Reference in New Issue
Block a user