misc: resolved export for pkcs12

This commit is contained in:
Sheen Capadngan
2025-11-26 22:45:49 +08:00
parent f1ac487d49
commit 96d36bf1a6
6 changed files with 36 additions and 13 deletions
@@ -731,7 +731,7 @@ export const certificateServiceFactory = ({
// Get certificate bundle (certificate, chain, private key) // Get certificate bundle (certificate, chain, private key)
const { certificate, certificateChain, privateKey } = await getCertBundle({ const { certificate, certificateChain, privateKey } = await getCertBundle({
serialNumber, id: cert.id,
actor, actor,
actorId, actorId,
actorAuthMethod, actorAuthMethod,
@@ -149,10 +149,10 @@ export const useUpdateRenewalConfig = () => {
export const useDownloadCertPkcs12 = () => { export const useDownloadCertPkcs12 = () => {
return useMutation<void, object, TDownloadPkcs12DTO>({ return useMutation<void, object, TDownloadPkcs12DTO>({
mutationFn: async ({ serialNumber, projectSlug, password, alias }) => { mutationFn: async ({ certificateId, projectSlug, password, alias }) => {
try { try {
const response = await apiRequest.post( const response = await apiRequest.post(
`/api/v1/cert-manager/certificates/${serialNumber}/pkcs12`, `/api/v1/cert-manager/certificates/${certificateId}/pkcs12`,
{ {
password, password,
alias alias
@@ -168,7 +168,7 @@ export const useDownloadCertPkcs12 = () => {
const url = window.URL.createObjectURL(blob); const url = window.URL.createObjectURL(blob);
const link = document.createElement("a"); const link = document.createElement("a");
link.href = url; link.href = url;
link.download = `certificate-${serialNumber}.p12`; link.download = `certificate-${certificateId}.p12`;
document.body.appendChild(link); document.body.appendChild(link);
link.click(); link.click();
document.body.removeChild(link); document.body.removeChild(link);
+1 -1
View File
@@ -74,7 +74,7 @@ export type TUpdateRenewalConfigDTO = {
}; };
export type TDownloadPkcs12DTO = { export type TDownloadPkcs12DTO = {
serialNumber: string; certificateId: string;
projectSlug: string; projectSlug: string;
password: string; password: string;
alias: string; alias: string;
@@ -21,7 +21,13 @@ type Props = {
) => void; ) => void;
onFormatSelected: ( onFormatSelected: (
format: "pem" | "pkcs12", format: "pem" | "pkcs12",
serialNumber: string, {
certificateId,
serialNumber
}: {
certificateId: string;
serialNumber: string;
},
options?: ExportOptions options?: ExportOptions
) => void; ) => void;
}; };
@@ -42,8 +48,11 @@ export const CertificateExportModal = ({ popUp, handlePopUpToggle, onFormatSelec
alias: "" alias: ""
}); });
const serialNumber = const { certificateId, serialNumber } =
(popUp?.certificateExport?.data as { serialNumber: string })?.serialNumber || ""; (popUp?.certificateExport?.data as {
certificateId: string;
serialNumber: string;
}) || {};
// Reset form whenever the modal opens // Reset form whenever the modal opens
useEffect(() => { useEffect(() => {
@@ -64,14 +73,21 @@ export const CertificateExportModal = ({ popUp, handlePopUpToggle, onFormatSelec
}; };
const handleExport = () => { const handleExport = () => {
if (serialNumber && isFormValid()) { if ((certificateId || serialNumber) && isFormValid()) {
const options: ExportOptions = {}; const options: ExportOptions = {};
if (selectedFormat === "pkcs12") { if (selectedFormat === "pkcs12") {
options.pkcs12 = pkcs12Options; options.pkcs12 = pkcs12Options;
} }
onFormatSelected(selectedFormat, serialNumber, options); onFormatSelected(
selectedFormat,
{
certificateId,
serialNumber
},
options
);
handlePopUpToggle("certificateExport", false); handlePopUpToggle("certificateExport", false);
} }
}; };
@@ -151,7 +167,7 @@ export const CertificateExportModal = ({ popUp, handlePopUpToggle, onFormatSelec
colorSchema="primary" colorSchema="primary"
leftIcon={<FontAwesomeIcon icon={faDownload} />} leftIcon={<FontAwesomeIcon icon={faDownload} />}
onClick={handleExport} onClick={handleExport}
disabled={!serialNumber || !isFormValid()} disabled={!(certificateId || serialNumber) || !isFormValid()}
> >
Export {selectedFormat.toUpperCase()} Export {selectedFormat.toUpperCase()}
</Button> </Button>
@@ -57,7 +57,13 @@ export const CertificatesSection = () => {
const handleCertificateExport = async ( const handleCertificateExport = async (
format: "pem" | "pkcs12", format: "pem" | "pkcs12",
serialNumber: string, {
certificateId,
serialNumber
}: {
certificateId: string;
serialNumber: string;
},
options?: ExportOptions options?: ExportOptions
) => { ) => {
if (format === "pem") { if (format === "pem") {
@@ -75,7 +81,7 @@ export const CertificatesSection = () => {
try { try {
await downloadCertPkcs12({ await downloadCertPkcs12({
serialNumber, certificateId,
projectSlug: currentProject.slug, projectSlug: currentProject.slug,
password: options.pkcs12.password, password: options.pkcs12.password,
alias: options.pkcs12.alias alias: options.pkcs12.alias
@@ -277,6 +277,7 @@ export const CertificatesTable = ({ handlePopUpOpen }: Props) => {
)} )}
onClick={async () => onClick={async () =>
handlePopUpOpen("certificateExport", { handlePopUpOpen("certificateExport", {
certificateId: certificate.id,
serialNumber: certificate.serialNumber serialNumber: certificate.serialNumber
}) })
} }