mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-15 02:51:51 +00:00
misc: migrated internal CA to use new CA endpoint
This commit is contained in:
@@ -2,14 +2,11 @@ export { AcmeDnsProvider, CaRenewalType, CaStatus, CaType, InternalCaType } from
|
||||
export {
|
||||
useCreateCa,
|
||||
useCreateCertificate,
|
||||
useCreateUnifiedCa,
|
||||
useDeleteCa,
|
||||
useDeleteUnifiedCa,
|
||||
useImportCaCertificate,
|
||||
useRenewCa,
|
||||
useSignIntermediate,
|
||||
useUpdateCa,
|
||||
useUpdateUnifiedCa
|
||||
useUpdateCa
|
||||
} from "./mutations";
|
||||
export {
|
||||
useGetCa,
|
||||
|
||||
@@ -3,15 +3,13 @@ import { useMutation, useQueryClient } from "@tanstack/react-query";
|
||||
import { apiRequest } from "@app/config/request";
|
||||
|
||||
import { workspaceKeys } from "../workspace";
|
||||
import { CaType } from "./enums";
|
||||
import { caKeys } from "./queries";
|
||||
import {
|
||||
TCertificateAuthority,
|
||||
TCreateCaDTO,
|
||||
TCreateCertificateAuthorityDTO,
|
||||
TCreateCertificateDTO,
|
||||
TCreateCertificateResponse,
|
||||
TCreateUnifiedCertificateAuthorityDTO,
|
||||
TDeleteCaDTO,
|
||||
TDeleteUnifiedCertificateAuthorityDTO,
|
||||
TDeleteCertificateAuthorityDTO,
|
||||
TImportCaCertificateDTO,
|
||||
TImportCaCertificateResponse,
|
||||
TRenewCaDTO,
|
||||
@@ -19,13 +17,12 @@ import {
|
||||
TSignIntermediateDTO,
|
||||
TSignIntermediateResponse,
|
||||
TUnifiedCertificateAuthority,
|
||||
TUpdateCaDTO,
|
||||
TUpdateUnifiedCertificateAuthorityDTO
|
||||
TUpdateCertificateAuthorityDTO
|
||||
} from "./types";
|
||||
|
||||
export const useUpdateUnifiedCa = () => {
|
||||
export const useUpdateCa = () => {
|
||||
const queryClient = useQueryClient();
|
||||
return useMutation<TUnifiedCertificateAuthority, object, TUpdateUnifiedCertificateAuthorityDTO>({
|
||||
return useMutation<TUnifiedCertificateAuthority, object, TUpdateCertificateAuthorityDTO>({
|
||||
mutationFn: async ({ caName, ...body }) => {
|
||||
const { data } = await apiRequest.patch<TUnifiedCertificateAuthority>(
|
||||
`/api/v1/pki/ca/${body.type}/${caName}`,
|
||||
@@ -42,9 +39,9 @@ export const useUpdateUnifiedCa = () => {
|
||||
});
|
||||
};
|
||||
|
||||
export const useCreateUnifiedCa = () => {
|
||||
export const useCreateCa = () => {
|
||||
const queryClient = useQueryClient();
|
||||
return useMutation<TUnifiedCertificateAuthority, object, TCreateUnifiedCertificateAuthorityDTO>({
|
||||
return useMutation<TUnifiedCertificateAuthority, object, TCreateCertificateAuthorityDTO>({
|
||||
mutationFn: async (body) => {
|
||||
const { data } = await apiRequest.post<TUnifiedCertificateAuthority>(
|
||||
`/api/v1/pki/ca/${body.type}`,
|
||||
@@ -60,13 +57,11 @@ export const useCreateUnifiedCa = () => {
|
||||
});
|
||||
};
|
||||
|
||||
export const useDeleteUnifiedCa = () => {
|
||||
export const useDeleteCa = () => {
|
||||
const queryClient = useQueryClient();
|
||||
return useMutation<TUnifiedCertificateAuthority, object, TDeleteUnifiedCertificateAuthorityDTO>({
|
||||
return useMutation<TUnifiedCertificateAuthority, object, TDeleteCertificateAuthorityDTO>({
|
||||
mutationFn: async ({ caName, type, projectId }) => {
|
||||
const {
|
||||
data: { certificateAuthority }
|
||||
} = await apiRequest.delete<{ certificateAuthority: TUnifiedCertificateAuthority }>(
|
||||
const { data } = await apiRequest.delete<TUnifiedCertificateAuthority>(
|
||||
`/api/v1/pki/ca/${type}/${caName}`,
|
||||
{
|
||||
data: {
|
||||
@@ -74,7 +69,7 @@ export const useDeleteUnifiedCa = () => {
|
||||
}
|
||||
}
|
||||
);
|
||||
return certificateAuthority;
|
||||
return data;
|
||||
},
|
||||
onSuccess: (_, { type, projectId }) => {
|
||||
queryClient.invalidateQueries({
|
||||
@@ -84,52 +79,6 @@ export const useDeleteUnifiedCa = () => {
|
||||
});
|
||||
};
|
||||
|
||||
export const useCreateCa = () => {
|
||||
const queryClient = useQueryClient();
|
||||
return useMutation<TCertificateAuthority, object, TCreateCaDTO>({
|
||||
mutationFn: async (body) => {
|
||||
const {
|
||||
data: { ca }
|
||||
} = await apiRequest.post<{ ca: TCertificateAuthority }>("/api/v1/pki/ca/", body);
|
||||
return ca;
|
||||
},
|
||||
onSuccess: (_, { projectSlug }) => {
|
||||
queryClient.invalidateQueries({ queryKey: workspaceKeys.getWorkspaceCas({ projectSlug }) });
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
export const useUpdateCa = () => {
|
||||
const queryClient = useQueryClient();
|
||||
return useMutation<TCertificateAuthority, object, TUpdateCaDTO>({
|
||||
mutationFn: async ({ caId, projectSlug, ...body }) => {
|
||||
const {
|
||||
data: { ca }
|
||||
} = await apiRequest.patch<{ ca: TCertificateAuthority }>(`/api/v1/pki/ca/${caId}`, body);
|
||||
return ca;
|
||||
},
|
||||
onSuccess: ({ id }, { projectSlug }) => {
|
||||
queryClient.invalidateQueries({ queryKey: workspaceKeys.getWorkspaceCas({ projectSlug }) });
|
||||
queryClient.invalidateQueries({ queryKey: caKeys.getCaById(id) });
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
export const useDeleteCa = () => {
|
||||
const queryClient = useQueryClient();
|
||||
return useMutation<TCertificateAuthority, object, TDeleteCaDTO>({
|
||||
mutationFn: async ({ caId }) => {
|
||||
const {
|
||||
data: { ca }
|
||||
} = await apiRequest.delete<{ ca: TCertificateAuthority }>(`/api/v1/pki/ca/${caId}`);
|
||||
return ca;
|
||||
},
|
||||
onSuccess: (_, { projectSlug }) => {
|
||||
queryClient.invalidateQueries({ queryKey: workspaceKeys.getWorkspaceCas({ projectSlug }) });
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
export const useSignIntermediate = () => {
|
||||
// TODO: consider renaming
|
||||
return useMutation<TSignIntermediateResponse, object, TSignIntermediateDTO>({
|
||||
@@ -143,7 +92,7 @@ export const useSignIntermediate = () => {
|
||||
});
|
||||
};
|
||||
|
||||
export const useImportCaCertificate = () => {
|
||||
export const useImportCaCertificate = (projectId: string) => {
|
||||
const queryClient = useQueryClient();
|
||||
return useMutation<TImportCaCertificateResponse, object, TImportCaCertificateDTO>({
|
||||
mutationFn: async ({ caId, ...body }) => {
|
||||
@@ -157,6 +106,9 @@ export const useImportCaCertificate = () => {
|
||||
queryClient.invalidateQueries({ queryKey: workspaceKeys.getWorkspaceCas({ projectSlug }) });
|
||||
queryClient.invalidateQueries({ queryKey: caKeys.getCaCerts(caId) });
|
||||
queryClient.invalidateQueries({ queryKey: caKeys.getCaCert(caId) });
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: caKeys.listCasByTypeAndProjectId(CaType.INTERNAL, projectId)
|
||||
});
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
@@ -39,10 +39,10 @@ export type TInternalCertificateAuthority = {
|
||||
keyAlgorithm: CertKeyAlgorithm;
|
||||
notAfter?: string;
|
||||
notBefore?: string;
|
||||
dn: string;
|
||||
dn?: string;
|
||||
parentCaId?: string;
|
||||
serialNumber: string;
|
||||
activeCaCertId: string;
|
||||
serialNumber?: string;
|
||||
activeCaCertId?: string;
|
||||
};
|
||||
};
|
||||
|
||||
@@ -50,14 +50,14 @@ export type TUnifiedCertificateAuthority =
|
||||
| TAcmeCertificateAuthority
|
||||
| TInternalCertificateAuthority;
|
||||
|
||||
export type TCreateUnifiedCertificateAuthorityDTO = Omit<TUnifiedCertificateAuthority, "id">;
|
||||
export type TUpdateUnifiedCertificateAuthorityDTO = Partial<TUnifiedCertificateAuthority> & {
|
||||
export type TCreateCertificateAuthorityDTO = Omit<TUnifiedCertificateAuthority, "id">;
|
||||
export type TUpdateCertificateAuthorityDTO = Partial<TUnifiedCertificateAuthority> & {
|
||||
caName: string;
|
||||
projectId: string;
|
||||
type: CaType;
|
||||
};
|
||||
|
||||
export type TDeleteUnifiedCertificateAuthorityDTO = {
|
||||
export type TDeleteCertificateAuthorityDTO = {
|
||||
caName: string;
|
||||
type: CaType;
|
||||
projectId: string;
|
||||
@@ -87,22 +87,6 @@ export type TCertificateAuthority = {
|
||||
updatedAt: string;
|
||||
};
|
||||
|
||||
export type TCreateCaDTO = {
|
||||
projectSlug: string;
|
||||
type: string;
|
||||
friendlyName?: string;
|
||||
organization: string;
|
||||
ou: string;
|
||||
country: string;
|
||||
province: string;
|
||||
locality: string;
|
||||
commonName: string;
|
||||
notAfter?: string;
|
||||
maxPathLength: number;
|
||||
keyAlgorithm: CertKeyAlgorithm;
|
||||
requireTemplateForIssuance: boolean;
|
||||
};
|
||||
|
||||
export type TUpdateCaDTO = {
|
||||
projectSlug: string;
|
||||
caId: string;
|
||||
|
||||
Reference in New Issue
Block a user