mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-15 15:41:27 +00:00
feat: finished up integration for est config management
This commit is contained in:
@@ -1,10 +1,20 @@
|
||||
export { CaRenewalType,CaStatus, CaType } from "./enums";
|
||||
export { CaRenewalType, CaStatus, CaType } from "./enums";
|
||||
export {
|
||||
useCreateCa,
|
||||
useCreateCaEstConfig,
|
||||
useCreateCertificate,
|
||||
useDeleteCa,
|
||||
useImportCaCertificate,
|
||||
useRenewCa,
|
||||
useSignIntermediate,
|
||||
useUpdateCa} from "./mutations";
|
||||
export { useGetCaById, useGetCaCert, useGetCaCerts, useGetCaCrl, useGetCaCsr } from "./queries";
|
||||
useUpdateCa,
|
||||
useUpdateCaEstConfig
|
||||
} from "./mutations";
|
||||
export {
|
||||
useGetCaById,
|
||||
useGetCaCert,
|
||||
useGetCaCerts,
|
||||
useGetCaCrl,
|
||||
useGetCaCsr,
|
||||
useGetCaEstConfig
|
||||
} from "./queries";
|
||||
|
||||
@@ -7,6 +7,7 @@ import { caKeys } from "./queries";
|
||||
import {
|
||||
TCertificateAuthority,
|
||||
TCreateCaDTO,
|
||||
TCreateCaEstConfigDTO,
|
||||
TCreateCertificateDTO,
|
||||
TCreateCertificateResponse,
|
||||
TDeleteCaDTO,
|
||||
@@ -16,7 +17,9 @@ import {
|
||||
TRenewCaResponse,
|
||||
TSignIntermediateDTO,
|
||||
TSignIntermediateResponse,
|
||||
TUpdateCaDTO} from "./types";
|
||||
TUpdateCaDTO,
|
||||
TUpdateCaEstConfigDTO
|
||||
} from "./types";
|
||||
|
||||
export const useCreateCa = () => {
|
||||
const queryClient = useQueryClient();
|
||||
@@ -130,3 +133,29 @@ export const useRenewCa = () => {
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
export const useCreateCaEstConfig = () => {
|
||||
const queryClient = useQueryClient();
|
||||
return useMutation<{}, {}, TCreateCaEstConfigDTO>({
|
||||
mutationFn: async (body) => {
|
||||
const { data } = await apiRequest.post(`/api/v1/pki/ca/${body.caId}/est-config`, body);
|
||||
return data;
|
||||
},
|
||||
onSuccess: (_, { caId }) => {
|
||||
queryClient.invalidateQueries(caKeys.getCaEstConfig(caId));
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
export const useUpdateCaEstConfig = () => {
|
||||
const queryClient = useQueryClient();
|
||||
return useMutation<{}, {}, TUpdateCaEstConfigDTO>({
|
||||
mutationFn: async (body) => {
|
||||
const { data } = await apiRequest.patch(`/api/v1/pki/ca/${body.caId}/est-config`, body);
|
||||
return data;
|
||||
},
|
||||
onSuccess: (_, { caId }) => {
|
||||
queryClient.invalidateQueries(caKeys.getCaEstConfig(caId));
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
@@ -2,14 +2,15 @@ import { useQuery } from "@tanstack/react-query";
|
||||
|
||||
import { apiRequest } from "@app/config/request";
|
||||
|
||||
import { TCertificateAuthority } from "./types";
|
||||
import { TCaEstConfig, TCertificateAuthority } from "./types";
|
||||
|
||||
export const caKeys = {
|
||||
getCaById: (caId: string) => [{ caId }, "ca"],
|
||||
getCaCerts: (caId: string) => [{ caId }, "ca-cert"],
|
||||
getCaCert: (caId: string) => [{ caId }, "ca-cert"],
|
||||
getCaCsr: (caId: string) => [{ caId }, "ca-csr"],
|
||||
getCaCrl: (caId: string) => [{ caId }, "ca-crl"]
|
||||
getCaCrl: (caId: string) => [{ caId }, "ca-crl"],
|
||||
getCaEstConfig: (caId: string) => [{ caId }, "ca-est-config"]
|
||||
};
|
||||
|
||||
export const useGetCaById = (caId: string) => {
|
||||
@@ -87,3 +88,19 @@ export const useGetCaCrl = (caId: string) => {
|
||||
enabled: Boolean(caId)
|
||||
});
|
||||
};
|
||||
|
||||
export const useGetCaEstConfig = (caId: string) => {
|
||||
return useQuery({
|
||||
queryKey: caKeys.getCaEstConfig(caId),
|
||||
queryFn: async () => {
|
||||
const {
|
||||
data: { caEstConfig }
|
||||
} = await apiRequest.get<{
|
||||
caEstConfig: TCaEstConfig;
|
||||
}>(`/api/v1/pki/ca/${caId}/est-config`);
|
||||
|
||||
return caEstConfig;
|
||||
},
|
||||
enabled: Boolean(caId)
|
||||
});
|
||||
};
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { CertKeyAlgorithm } from "../certificates/enums";
|
||||
import { CaRenewalType,CaStatus, CaType } from "./enums";
|
||||
import { CaRenewalType, CaStatus, CaType } from "./enums";
|
||||
|
||||
export type TCertificateAuthority = {
|
||||
id: string;
|
||||
@@ -107,3 +107,23 @@ export type TRenewCaResponse = {
|
||||
certificateChain: string;
|
||||
serialNumber: string;
|
||||
};
|
||||
|
||||
export type TCaEstConfig = {
|
||||
caId: string;
|
||||
caChain: string;
|
||||
isEnabled: false;
|
||||
};
|
||||
|
||||
export type TCreateCaEstConfigDTO = {
|
||||
caId: string;
|
||||
caChain: string;
|
||||
passphrase: string;
|
||||
isEnabled: boolean;
|
||||
};
|
||||
|
||||
export type TUpdateCaEstConfigDTO = {
|
||||
caId: string;
|
||||
caChain?: string;
|
||||
passphrase?: string;
|
||||
isEnabled?: boolean;
|
||||
};
|
||||
|
||||
@@ -125,7 +125,9 @@ export const CaDetailsSection = ({ caId, handlePopUpOpen }: Props) => {
|
||||
colorSchema="secondary"
|
||||
type="submit"
|
||||
onClick={() => {
|
||||
handlePopUpOpen("enrollmentOptions");
|
||||
handlePopUpOpen("enrollmentOptions", {
|
||||
caId
|
||||
});
|
||||
}}
|
||||
>
|
||||
Enrollment Options
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { useEffect } from "react";
|
||||
import { Controller, useForm } from "react-hook-form";
|
||||
import { zodResolver } from "@hookform/resolvers/zod";
|
||||
import z from "zod";
|
||||
@@ -14,6 +15,7 @@ import {
|
||||
Switch,
|
||||
TextArea
|
||||
} from "@app/components/v2";
|
||||
import { useCreateCaEstConfig, useGetCaEstConfig, useUpdateCaEstConfig } from "@app/hooks/api";
|
||||
import { UsePopUpState } from "@app/hooks/usePopUp";
|
||||
|
||||
enum EnrollmentMethod {
|
||||
@@ -28,32 +30,73 @@ type Props = {
|
||||
) => void;
|
||||
};
|
||||
|
||||
const schema = z
|
||||
.object({
|
||||
method: z.nativeEnum(EnrollmentMethod),
|
||||
caChain: z.string(),
|
||||
passphrase: z.string(),
|
||||
isEnabled: z.boolean()
|
||||
})
|
||||
.required();
|
||||
const schema = z.object({
|
||||
method: z.nativeEnum(EnrollmentMethod),
|
||||
caChain: z.string(),
|
||||
passphrase: z.string().optional(),
|
||||
isEnabled: z.boolean()
|
||||
});
|
||||
|
||||
export type FormData = z.infer<typeof schema>;
|
||||
|
||||
export const CaEnrollmentModal = ({ popUp, handlePopUpToggle }: Props) => {
|
||||
const popUpData = popUp?.enrollmentOptions?.data as {
|
||||
caId: string;
|
||||
};
|
||||
const caId = popUpData?.caId;
|
||||
|
||||
const { data } = useGetCaEstConfig(caId);
|
||||
|
||||
const {
|
||||
control,
|
||||
handleSubmit,
|
||||
reset,
|
||||
setError,
|
||||
formState: { isSubmitting }
|
||||
} = useForm<FormData>({
|
||||
resolver: zodResolver(schema),
|
||||
defaultValues: {
|
||||
isEnabled: false
|
||||
}
|
||||
resolver: zodResolver(schema)
|
||||
});
|
||||
|
||||
const { mutateAsync: createCaEstConfig } = useCreateCaEstConfig();
|
||||
const { mutateAsync: updateCaEstConfig } = useUpdateCaEstConfig();
|
||||
|
||||
useEffect(() => {
|
||||
if (data) {
|
||||
reset({
|
||||
caChain: data.caChain,
|
||||
isEnabled: data.isEnabled
|
||||
});
|
||||
} else {
|
||||
reset({
|
||||
caChain: "",
|
||||
isEnabled: false
|
||||
});
|
||||
}
|
||||
}, [data]);
|
||||
|
||||
const onFormSubmit = async ({ caChain, passphrase, isEnabled }: FormData) => {
|
||||
try {
|
||||
if (data) {
|
||||
await updateCaEstConfig({
|
||||
caId,
|
||||
caChain,
|
||||
passphrase,
|
||||
isEnabled
|
||||
});
|
||||
} else {
|
||||
if (!passphrase) {
|
||||
setError("passphrase", { message: "Passphrase is required to setup EST enrollment." });
|
||||
return;
|
||||
}
|
||||
|
||||
await createCaEstConfig({
|
||||
caId,
|
||||
caChain,
|
||||
passphrase,
|
||||
isEnabled
|
||||
});
|
||||
}
|
||||
|
||||
handlePopUpToggle("enrollmentOptions", false);
|
||||
|
||||
createNotification({
|
||||
@@ -102,7 +145,6 @@ export const CaEnrollmentModal = ({ popUp, handlePopUpToggle }: Props) => {
|
||||
/>
|
||||
<Controller
|
||||
control={control}
|
||||
defaultValue=""
|
||||
name="caChain"
|
||||
render={({ field, fieldState: { error } }) => (
|
||||
<FormControl
|
||||
@@ -117,15 +159,9 @@ export const CaEnrollmentModal = ({ popUp, handlePopUpToggle }: Props) => {
|
||||
/>
|
||||
<Controller
|
||||
control={control}
|
||||
defaultValue=""
|
||||
name="passphrase"
|
||||
render={({ field, fieldState: { error } }) => (
|
||||
<FormControl
|
||||
label="Passphrase"
|
||||
isError={Boolean(error)}
|
||||
errorText={error?.message}
|
||||
isRequired
|
||||
>
|
||||
<FormControl label="Passphrase" isError={Boolean(error)} errorText={error?.message}>
|
||||
<Input {...field} type="password" />
|
||||
</FormControl>
|
||||
)}
|
||||
|
||||
Reference in New Issue
Block a user