mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-15 05:19:49 +00:00
misc: addressed first set of review comments
This commit is contained in:
@@ -12,8 +12,8 @@ export {
|
||||
useUpdateUnifiedCa
|
||||
} from "./mutations";
|
||||
export {
|
||||
useGetCa,
|
||||
useGetCaById,
|
||||
useGetCaByTypeAndId,
|
||||
useGetCaCert,
|
||||
useGetCaCerts,
|
||||
useGetCaCertTemplates,
|
||||
|
||||
@@ -26,15 +26,13 @@ import {
|
||||
export const useUpdateUnifiedCa = () => {
|
||||
const queryClient = useQueryClient();
|
||||
return useMutation<TUnifiedCertificateAuthority, object, TUpdateUnifiedCertificateAuthorityDTO>({
|
||||
mutationFn: async ({ id, ...body }) => {
|
||||
const {
|
||||
data: { certificateAuthority }
|
||||
} = await apiRequest.patch<{ certificateAuthority: TUnifiedCertificateAuthority }>(
|
||||
`/api/v1/pki/ca/${body.type}/${id}`,
|
||||
mutationFn: async ({ caName, ...body }) => {
|
||||
const { data } = await apiRequest.patch<TUnifiedCertificateAuthority>(
|
||||
`/api/v1/pki/ca/${body.type}/${caName}`,
|
||||
body
|
||||
);
|
||||
|
||||
return certificateAuthority;
|
||||
return data;
|
||||
},
|
||||
onSuccess: ({ projectId, type }) => {
|
||||
queryClient.invalidateQueries({
|
||||
@@ -65,11 +63,16 @@ export const useCreateUnifiedCa = () => {
|
||||
export const useDeleteUnifiedCa = () => {
|
||||
const queryClient = useQueryClient();
|
||||
return useMutation<TUnifiedCertificateAuthority, object, TDeleteUnifiedCertificateAuthorityDTO>({
|
||||
mutationFn: async ({ caId, type }) => {
|
||||
mutationFn: async ({ caName, type, projectId }) => {
|
||||
const {
|
||||
data: { certificateAuthority }
|
||||
} = await apiRequest.delete<{ certificateAuthority: TUnifiedCertificateAuthority }>(
|
||||
`/api/v1/pki/ca/${type}/${caId}`
|
||||
`/api/v1/pki/ca/${type}/${caName}`,
|
||||
{
|
||||
data: {
|
||||
projectId
|
||||
}
|
||||
}
|
||||
);
|
||||
return certificateAuthority;
|
||||
},
|
||||
|
||||
@@ -8,7 +8,7 @@ import { TCertificateAuthority, TUnifiedCertificateAuthority } from "./types";
|
||||
|
||||
export const caKeys = {
|
||||
getCaById: (caId: string) => [{ caId }, "ca"],
|
||||
getCaByTypeAndId: (type: CaType, caId: string) => [{ type, caId }, "ca"],
|
||||
getCaByNameAndProjectId: (caName: string, projectId: string) => [{ caName, projectId }, "ca"],
|
||||
listCasByTypeAndProjectId: (type: CaType, projectId: string) => [{ type, projectId }, "cas"],
|
||||
listCasByProjectId: (projectId: string) => [{ projectId }, "cas"],
|
||||
getCaCerts: (caId: string) => [{ caId }, "ca-cert"],
|
||||
@@ -20,18 +20,24 @@ export const caKeys = {
|
||||
getCaEstConfig: (caId: string) => [{ caId }, "ca-est-config"]
|
||||
};
|
||||
|
||||
export const useGetCaByTypeAndId = (type: CaType, caId: string) => {
|
||||
export const useGetCa = ({
|
||||
caName,
|
||||
projectId,
|
||||
type
|
||||
}: {
|
||||
caName: string;
|
||||
projectId: string;
|
||||
type: CaType;
|
||||
}) => {
|
||||
return useQuery({
|
||||
queryKey: caKeys.getCaByTypeAndId(type, caId),
|
||||
queryKey: caKeys.getCaByNameAndProjectId(caName, projectId),
|
||||
queryFn: async () => {
|
||||
const {
|
||||
data: { certificateAuthority }
|
||||
} = await apiRequest.get<{ certificateAuthority: TUnifiedCertificateAuthority }>(
|
||||
`/api/v1/pki/ca/${type}/${caId}`
|
||||
const { data } = await apiRequest.get<TUnifiedCertificateAuthority>(
|
||||
`/api/v1/pki/ca/${type}/${caName}?projectId=${projectId}`
|
||||
);
|
||||
return certificateAuthority;
|
||||
return data;
|
||||
},
|
||||
enabled: Boolean(caId)
|
||||
enabled: Boolean(caName && projectId && type)
|
||||
});
|
||||
};
|
||||
|
||||
@@ -39,11 +45,11 @@ export const useListCasByTypeAndProjectId = (type: CaType, projectId: string) =>
|
||||
return useQuery({
|
||||
queryKey: caKeys.listCasByTypeAndProjectId(type, projectId),
|
||||
queryFn: async () => {
|
||||
const { data } = await apiRequest.get<{
|
||||
certificateAuthorities: TUnifiedCertificateAuthority[];
|
||||
}>(`/api/v1/pki/ca/${type}?projectId=${projectId}`);
|
||||
const { data } = await apiRequest.get<TUnifiedCertificateAuthority[]>(
|
||||
`/api/v1/pki/ca/${type}?projectId=${projectId}`
|
||||
);
|
||||
|
||||
return data.certificateAuthorities;
|
||||
return data;
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
@@ -7,7 +7,7 @@ export type TAcmeCertificateAuthority = {
|
||||
type: CaType.ACME;
|
||||
status: CaStatus;
|
||||
name: string;
|
||||
disableDirectIssuance: boolean;
|
||||
enableDirectIssuance: boolean;
|
||||
configuration: {
|
||||
dnsAppConnectionId: string;
|
||||
dnsProviderConfig: {
|
||||
@@ -25,7 +25,7 @@ export type TInternalCertificateAuthority = {
|
||||
type: CaType.INTERNAL;
|
||||
status: CaStatus;
|
||||
name: string;
|
||||
disableDirectIssuance: boolean;
|
||||
enableDirectIssuance: boolean;
|
||||
configuration: {
|
||||
type: InternalCaType;
|
||||
friendlyName?: string;
|
||||
@@ -52,12 +52,13 @@ export type TUnifiedCertificateAuthority =
|
||||
|
||||
export type TCreateUnifiedCertificateAuthorityDTO = Omit<TUnifiedCertificateAuthority, "id">;
|
||||
export type TUpdateUnifiedCertificateAuthorityDTO = Partial<TUnifiedCertificateAuthority> & {
|
||||
id: string;
|
||||
caName: string;
|
||||
projectId: string;
|
||||
type: CaType;
|
||||
};
|
||||
|
||||
export type TDeleteUnifiedCertificateAuthorityDTO = {
|
||||
caId: string;
|
||||
caName: string;
|
||||
type: CaType;
|
||||
projectId: string;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user