mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-15 20:25:43 +00:00
Finish preliminary loop on SSH certificates
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
export {
|
||||
useCreateSshCertTemplate,
|
||||
useDeleteSshCertTemplate,
|
||||
useUpdateSshCertTemplate} from "./mutations";
|
||||
export { useGetSshCertTemplate } from "./queries";
|
||||
@@ -0,0 +1,59 @@
|
||||
import { useMutation, useQueryClient } from "@tanstack/react-query";
|
||||
|
||||
import { apiRequest } from "@app/config/request";
|
||||
|
||||
import { sshCaKeys } from "../ssh-ca/queries";
|
||||
import {
|
||||
TCreateSshCertificateTemplateDTO,
|
||||
TDeleteSshCertificateTemplateDTO,
|
||||
TSshCertificateTemplate,
|
||||
TUpdateSshCertificateTemplateDTO
|
||||
} from "./types";
|
||||
|
||||
export const useCreateSshCertTemplate = () => {
|
||||
const queryClient = useQueryClient();
|
||||
return useMutation<TSshCertificateTemplate, {}, TCreateSshCertificateTemplateDTO>({
|
||||
mutationFn: async (data) => {
|
||||
const { data: certificateTemplate } = await apiRequest.post<TSshCertificateTemplate>(
|
||||
"/api/v1/ssh/certificate-templates",
|
||||
data
|
||||
);
|
||||
return certificateTemplate;
|
||||
},
|
||||
onSuccess: ({ sshCaId }) => {
|
||||
queryClient.invalidateQueries(sshCaKeys.getSshCaCertTemplates(sshCaId));
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
export const useUpdateSshCertTemplate = () => {
|
||||
const queryClient = useQueryClient();
|
||||
return useMutation<TSshCertificateTemplate, {}, TUpdateSshCertificateTemplateDTO>({
|
||||
mutationFn: async (data) => {
|
||||
const { data: certificateTemplate } = await apiRequest.patch<TSshCertificateTemplate>(
|
||||
`/api/v1/ssh/certificate-templates/${data.id}`,
|
||||
data
|
||||
);
|
||||
|
||||
return certificateTemplate;
|
||||
},
|
||||
onSuccess: ({ sshCaId }) => {
|
||||
queryClient.invalidateQueries(sshCaKeys.getSshCaCertTemplates(sshCaId));
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
export const useDeleteSshCertTemplate = () => {
|
||||
const queryClient = useQueryClient();
|
||||
return useMutation<TSshCertificateTemplate, {}, TDeleteSshCertificateTemplateDTO>({
|
||||
mutationFn: async (data) => {
|
||||
const { data: certificateTemplate } = await apiRequest.delete<TSshCertificateTemplate>(
|
||||
`/api/v1/ssh/certificate-templates/${data.id}`
|
||||
);
|
||||
return certificateTemplate;
|
||||
},
|
||||
onSuccess: ({ sshCaId }) => {
|
||||
queryClient.invalidateQueries(sshCaKeys.getSshCaCertTemplates(sshCaId));
|
||||
}
|
||||
});
|
||||
};
|
||||
@@ -0,0 +1,22 @@
|
||||
import { useQuery } from "@tanstack/react-query";
|
||||
|
||||
import { apiRequest } from "@app/config/request";
|
||||
|
||||
import { TSshCertificateTemplate } from "./types";
|
||||
|
||||
export const certTemplateKeys = {
|
||||
getSshCertTemplateById: (id: string) => [{ id }, "ssh-cert-template"]
|
||||
};
|
||||
|
||||
export const useGetSshCertTemplate = (id: string) => {
|
||||
return useQuery({
|
||||
queryKey: certTemplateKeys.getSshCertTemplateById(id),
|
||||
queryFn: async () => {
|
||||
const { data: certificateTemplate } = await apiRequest.get<TSshCertificateTemplate>(
|
||||
`/api/v1/ssh/certificate-templates/${id}`
|
||||
);
|
||||
return certificateTemplate;
|
||||
},
|
||||
enabled: Boolean(id)
|
||||
});
|
||||
};
|
||||
@@ -0,0 +1,40 @@
|
||||
export type TSshCertificateTemplate = {
|
||||
id: string;
|
||||
sshCaId: string;
|
||||
name: string;
|
||||
ttl: string;
|
||||
maxTTL: string;
|
||||
allowedUsers: string[];
|
||||
allowedHosts: string[];
|
||||
allowUserCertificates: boolean;
|
||||
allowHostCertificates: boolean;
|
||||
allowCustomKeyIds: boolean;
|
||||
};
|
||||
|
||||
export type TCreateSshCertificateTemplateDTO = {
|
||||
sshCaId: string;
|
||||
name: string;
|
||||
ttl: string;
|
||||
maxTTL: string;
|
||||
allowedUsers: string[];
|
||||
allowedHosts: string[];
|
||||
allowUserCertificates: boolean;
|
||||
allowHostCertificates: boolean;
|
||||
allowCustomKeyIds: boolean;
|
||||
};
|
||||
|
||||
export type TUpdateSshCertificateTemplateDTO = {
|
||||
id: string;
|
||||
name?: string;
|
||||
ttl?: string;
|
||||
maxTTL?: string;
|
||||
allowedUsers?: string[];
|
||||
allowedHosts?: string[];
|
||||
allowUserCertificates?: boolean;
|
||||
allowHostCertificates?: boolean;
|
||||
allowCustomKeyIds?: boolean;
|
||||
};
|
||||
|
||||
export type TDeleteSshCertificateTemplateDTO = {
|
||||
id: string;
|
||||
};
|
||||
Reference in New Issue
Block a user