mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-09-22 13:39:35 +00:00
misc: resolved export for pkcs12
This commit is contained in:
@@ -731,7 +731,7 @@ export const certificateServiceFactory = ({
|
||||
|
||||
// Get certificate bundle (certificate, chain, private key)
|
||||
const { certificate, certificateChain, privateKey } = await getCertBundle({
|
||||
serialNumber,
|
||||
id: cert.id,
|
||||
actor,
|
||||
actorId,
|
||||
actorAuthMethod,
|
||||
|
||||
@@ -149,10 +149,10 @@ export const useUpdateRenewalConfig = () => {
|
||||
|
||||
export const useDownloadCertPkcs12 = () => {
|
||||
return useMutation<void, object, TDownloadPkcs12DTO>({
|
||||
mutationFn: async ({ serialNumber, projectSlug, password, alias }) => {
|
||||
mutationFn: async ({ certificateId, projectSlug, password, alias }) => {
|
||||
try {
|
||||
const response = await apiRequest.post(
|
||||
`/api/v1/cert-manager/certificates/${serialNumber}/pkcs12`,
|
||||
`/api/v1/cert-manager/certificates/${certificateId}/pkcs12`,
|
||||
{
|
||||
password,
|
||||
alias
|
||||
@@ -168,7 +168,7 @@ export const useDownloadCertPkcs12 = () => {
|
||||
const url = window.URL.createObjectURL(blob);
|
||||
const link = document.createElement("a");
|
||||
link.href = url;
|
||||
link.download = `certificate-${serialNumber}.p12`;
|
||||
link.download = `certificate-${certificateId}.p12`;
|
||||
document.body.appendChild(link);
|
||||
link.click();
|
||||
document.body.removeChild(link);
|
||||
|
||||
@@ -74,7 +74,7 @@ export type TUpdateRenewalConfigDTO = {
|
||||
};
|
||||
|
||||
export type TDownloadPkcs12DTO = {
|
||||
serialNumber: string;
|
||||
certificateId: string;
|
||||
projectSlug: string;
|
||||
password: string;
|
||||
alias: string;
|
||||
|
||||
@@ -21,7 +21,13 @@ type Props = {
|
||||
) => void;
|
||||
onFormatSelected: (
|
||||
format: "pem" | "pkcs12",
|
||||
serialNumber: string,
|
||||
{
|
||||
certificateId,
|
||||
serialNumber
|
||||
}: {
|
||||
certificateId: string;
|
||||
serialNumber: string;
|
||||
},
|
||||
options?: ExportOptions
|
||||
) => void;
|
||||
};
|
||||
@@ -42,8 +48,11 @@ export const CertificateExportModal = ({ popUp, handlePopUpToggle, onFormatSelec
|
||||
alias: ""
|
||||
});
|
||||
|
||||
const serialNumber =
|
||||
(popUp?.certificateExport?.data as { serialNumber: string })?.serialNumber || "";
|
||||
const { certificateId, serialNumber } =
|
||||
(popUp?.certificateExport?.data as {
|
||||
certificateId: string;
|
||||
serialNumber: string;
|
||||
}) || {};
|
||||
|
||||
// Reset form whenever the modal opens
|
||||
useEffect(() => {
|
||||
@@ -64,14 +73,21 @@ export const CertificateExportModal = ({ popUp, handlePopUpToggle, onFormatSelec
|
||||
};
|
||||
|
||||
const handleExport = () => {
|
||||
if (serialNumber && isFormValid()) {
|
||||
if ((certificateId || serialNumber) && isFormValid()) {
|
||||
const options: ExportOptions = {};
|
||||
|
||||
if (selectedFormat === "pkcs12") {
|
||||
options.pkcs12 = pkcs12Options;
|
||||
}
|
||||
|
||||
onFormatSelected(selectedFormat, serialNumber, options);
|
||||
onFormatSelected(
|
||||
selectedFormat,
|
||||
{
|
||||
certificateId,
|
||||
serialNumber
|
||||
},
|
||||
options
|
||||
);
|
||||
handlePopUpToggle("certificateExport", false);
|
||||
}
|
||||
};
|
||||
@@ -151,7 +167,7 @@ export const CertificateExportModal = ({ popUp, handlePopUpToggle, onFormatSelec
|
||||
colorSchema="primary"
|
||||
leftIcon={<FontAwesomeIcon icon={faDownload} />}
|
||||
onClick={handleExport}
|
||||
disabled={!serialNumber || !isFormValid()}
|
||||
disabled={!(certificateId || serialNumber) || !isFormValid()}
|
||||
>
|
||||
Export {selectedFormat.toUpperCase()}
|
||||
</Button>
|
||||
|
||||
@@ -57,7 +57,13 @@ export const CertificatesSection = () => {
|
||||
|
||||
const handleCertificateExport = async (
|
||||
format: "pem" | "pkcs12",
|
||||
serialNumber: string,
|
||||
{
|
||||
certificateId,
|
||||
serialNumber
|
||||
}: {
|
||||
certificateId: string;
|
||||
serialNumber: string;
|
||||
},
|
||||
options?: ExportOptions
|
||||
) => {
|
||||
if (format === "pem") {
|
||||
@@ -75,7 +81,7 @@ export const CertificatesSection = () => {
|
||||
|
||||
try {
|
||||
await downloadCertPkcs12({
|
||||
serialNumber,
|
||||
certificateId,
|
||||
projectSlug: currentProject.slug,
|
||||
password: options.pkcs12.password,
|
||||
alias: options.pkcs12.alias
|
||||
|
||||
@@ -277,6 +277,7 @@ export const CertificatesTable = ({ handlePopUpOpen }: Props) => {
|
||||
)}
|
||||
onClick={async () =>
|
||||
handlePopUpOpen("certificateExport", {
|
||||
certificateId: certificate.id,
|
||||
serialNumber: certificate.serialNumber
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user