mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-16 03:31:27 +00:00
Continue cert mgmt mvp
This commit is contained in:
@@ -0,0 +1,2 @@
|
||||
export { useDeleteCert } from "./mutations";
|
||||
export { useGetCertById, useGetCertCert } from "./queries";
|
||||
@@ -0,0 +1,26 @@
|
||||
import { useMutation, useQueryClient } from "@tanstack/react-query";
|
||||
|
||||
import { apiRequest } from "@app/config/request";
|
||||
|
||||
import { workspaceKeys } from "../workspace/queries";
|
||||
import { TCertificate } from "./types";
|
||||
|
||||
export type TDeleteCaDTO = {
|
||||
projectSlug: string;
|
||||
certId: string;
|
||||
};
|
||||
|
||||
export const useDeleteCert = () => {
|
||||
const queryClient = useQueryClient();
|
||||
return useMutation<TCertificate, {}, TDeleteCaDTO>({
|
||||
mutationFn: async ({ certId }) => {
|
||||
const {
|
||||
data: { certificate }
|
||||
} = await apiRequest.delete<{ certificate: TCertificate }>(`/api/v1/certificates/${certId}`);
|
||||
return certificate;
|
||||
},
|
||||
onSuccess: (_, { projectSlug }) => {
|
||||
queryClient.invalidateQueries(workspaceKeys.getWorkspaceCertificates(projectSlug));
|
||||
}
|
||||
});
|
||||
};
|
||||
@@ -0,0 +1,40 @@
|
||||
import { useQuery } from "@tanstack/react-query";
|
||||
|
||||
import { apiRequest } from "@app/config/request";
|
||||
|
||||
import { TCertificate } from "./types";
|
||||
|
||||
export const certKeys = {
|
||||
getCertById: (certId: string) => [{ certId }, "cert"],
|
||||
getCertCert: (certId: string) => [{ certId }, "certCert"]
|
||||
};
|
||||
|
||||
export const useGetCertById = (certId: string) => {
|
||||
return useQuery({
|
||||
queryKey: certKeys.getCertById(certId),
|
||||
queryFn: async () => {
|
||||
const {
|
||||
data: { certificate }
|
||||
} = await apiRequest.get<{ certificate: TCertificate }>(`/api/v1/certificates/${certId}`);
|
||||
return certificate;
|
||||
},
|
||||
enabled: Boolean(certId)
|
||||
});
|
||||
};
|
||||
|
||||
export const useGetCertCert = (certId: string) => {
|
||||
return useQuery({
|
||||
queryKey: certKeys.getCertCert(certId),
|
||||
queryFn: async () => {
|
||||
const { data } = await apiRequest.get<{
|
||||
certificate: string;
|
||||
certificateChain: string;
|
||||
issuingCaCertificate: string;
|
||||
privateKey: string;
|
||||
serialNumber: string;
|
||||
}>(`/api/v1/certificates/${certId}/certificate`);
|
||||
return data;
|
||||
},
|
||||
enabled: Boolean(certId)
|
||||
});
|
||||
};
|
||||
@@ -0,0 +1,7 @@
|
||||
export type TCertificate = {
|
||||
id: string;
|
||||
caId: string;
|
||||
commonName: string;
|
||||
notBefore: string;
|
||||
notAfter: string;
|
||||
};
|
||||
Reference in New Issue
Block a user