From f7a9e1320920a2b57597c79a0bc607fecf511196 Mon Sep 17 00:00:00 2001 From: Sheen Capadngan Date: Thu, 29 May 2025 23:36:31 +0800 Subject: [PATCH 1/2] misc: general improvements --- .../pki-subscriber/pki-subscriber-service.ts | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/backend/src/services/pki-subscriber/pki-subscriber-service.ts b/backend/src/services/pki-subscriber/pki-subscriber-service.ts index 795371c76..5bedbd60c 100644 --- a/backend/src/services/pki-subscriber/pki-subscriber-service.ts +++ b/backend/src/services/pki-subscriber/pki-subscriber-service.ts @@ -137,6 +137,15 @@ export const pkiSubscriberServiceFactory = ({ } } + const ca = await certificateAuthorityDAL.findById(caId); + if (!ca) { + throw new NotFoundError({ message: `CA with ID '${caId}' not found` }); + } + + if (ca.projectId !== projectId) { + throw new BadRequestError({ message: "CA does not belong to the project" }); + } + const newSubscriber = await pkiSubscriberDAL.create({ caId, projectId, @@ -245,6 +254,17 @@ export const pkiSubscriberServiceFactory = ({ } } + if (caId) { + const ca = await certificateAuthorityDAL.findById(caId); + if (!ca) { + throw new NotFoundError({ message: `CA with ID '${caId}' not found` }); + } + + if (ca.projectId !== projectId) { + throw new BadRequestError({ message: "CA does not belong to the project" }); + } + } + const updatedSubscriber = await pkiSubscriberDAL.updateById(subscriber.id, { caId, name, From 5c435f764543b751d3e35f0f9d64fb06df635d0c Mon Sep 17 00:00:00 2001 From: Sheen Capadngan Date: Fri, 30 May 2025 00:09:47 +0800 Subject: [PATCH 2/2] misc: removed updating configuration for internal CAs --- .../certificate-authority/certificate-authority-service.ts | 1 - .../internal/internal-certificate-authority-schemas.ts | 6 +----- frontend/src/hooks/api/ca/mutations.tsx | 6 +++++- .../CertificateAuthoritiesPage/components/CaModal.tsx | 6 +----- 4 files changed, 7 insertions(+), 12 deletions(-) diff --git a/backend/src/services/certificate-authority/certificate-authority-service.ts b/backend/src/services/certificate-authority/certificate-authority-service.ts index fa66758c3..a57c085ba 100644 --- a/backend/src/services/certificate-authority/certificate-authority-service.ts +++ b/backend/src/services/certificate-authority/certificate-authority-service.ts @@ -311,7 +311,6 @@ export const certificateAuthorityServiceFactory = ({ } const updatedCa = await internalCertificateAuthorityService.updateCaById({ - ...configuration, isInternal: true, enableDirectIssuance, caId: certificateAuthority.id, diff --git a/backend/src/services/certificate-authority/internal/internal-certificate-authority-schemas.ts b/backend/src/services/certificate-authority/internal/internal-certificate-authority-schemas.ts index ffec0d762..1cf9a8597 100644 --- a/backend/src/services/certificate-authority/internal/internal-certificate-authority-schemas.ts +++ b/backend/src/services/certificate-authority/internal/internal-certificate-authority-schemas.ts @@ -55,8 +55,4 @@ export const CreateInternalCertificateAuthoritySchema = GenericCreateCertificate configuration: InternalCertificateAuthorityConfigurationSchema }); -export const UpdateInternalCertificateAuthoritySchema = GenericUpdateCertificateAuthorityFieldsSchema( - CaType.INTERNAL -).extend({ - configuration: InternalCertificateAuthorityConfigurationSchema.optional() -}); +export const UpdateInternalCertificateAuthoritySchema = GenericUpdateCertificateAuthorityFieldsSchema(CaType.INTERNAL); diff --git a/frontend/src/hooks/api/ca/mutations.tsx b/frontend/src/hooks/api/ca/mutations.tsx index 9c865d451..c05760beb 100644 --- a/frontend/src/hooks/api/ca/mutations.tsx +++ b/frontend/src/hooks/api/ca/mutations.tsx @@ -31,10 +31,14 @@ export const useUpdateCa = () => { return data; }, - onSuccess: ({ projectId, type }) => { + onSuccess: ({ projectId, type }, { caName }) => { + caKeys.getCaByNameAndProjectId(caName, projectId); queryClient.invalidateQueries({ queryKey: caKeys.listCasByTypeAndProjectId(type, projectId) }); + queryClient.invalidateQueries({ + queryKey: caKeys.getCaByNameAndProjectId(caName, projectId) + }); } }); }; diff --git a/frontend/src/pages/cert-manager/CertificateAuthoritiesPage/components/CaModal.tsx b/frontend/src/pages/cert-manager/CertificateAuthoritiesPage/components/CaModal.tsx index 07bf1493a..d3040576f 100644 --- a/frontend/src/pages/cert-manager/CertificateAuthoritiesPage/components/CaModal.tsx +++ b/frontend/src/pages/cert-manager/CertificateAuthoritiesPage/components/CaModal.tsx @@ -188,11 +188,7 @@ export const CaModal = ({ popUp, handlePopUpToggle }: Props) => { name, type: CaType.INTERNAL, status, - enableDirectIssuance, - configuration: { - ...configuration, - maxPathLength: Number(configuration.maxPathLength) - } + enableDirectIssuance }); } else { // create