diff --git a/backend/src/server/routes/v2/pki-templates-router.ts b/backend/src/server/routes/v2/pki-templates-router.ts index b6b969706..e481af0a2 100644 --- a/backend/src/server/routes/v2/pki-templates-router.ts +++ b/backend/src/server/routes/v2/pki-templates-router.ts @@ -26,7 +26,7 @@ export const registerPkiTemplatesRouter = async (server: FastifyZodProvider) => tags: [ApiDocsTags.PkiCertificateTemplates], body: z.object({ name: slugSchema(), - caId: z.string(), + caName: slugSchema({ field: "caName" }), projectId: z.string(), commonName: validateTemplateRegexField, subjectAlternativeName: validateTemplateRegexField, @@ -72,7 +72,7 @@ export const registerPkiTemplatesRouter = async (server: FastifyZodProvider) => }), body: z.object({ name: slugSchema().optional(), - caId: z.string(), + caName: slugSchema(), projectId: z.string(), commonName: validateTemplateRegexField.optional(), subjectAlternativeName: validateTemplateRegexField.optional(), diff --git a/backend/src/services/pki-templates/pki-templates-service.ts b/backend/src/services/pki-templates/pki-templates-service.ts index e72a2198a..97f910d6e 100644 --- a/backend/src/services/pki-templates/pki-templates-service.ts +++ b/backend/src/services/pki-templates/pki-templates-service.ts @@ -56,7 +56,13 @@ type TPkiTemplatesServiceFactoryDep = { permissionService: Pick; certificateAuthorityDAL: Pick< TCertificateAuthorityDALFactory, - "findByIdWithAssociatedCa" | "findById" | "transaction" | "create" | "updateById" | "findWithAssociatedCa" + | "findByIdWithAssociatedCa" + | "findById" + | "transaction" + | "create" + | "updateById" + | "findWithAssociatedCa" + | "findOne" >; internalCaFns: ReturnType; kmsService: Pick; @@ -92,20 +98,22 @@ export const pkiTemplatesServiceFactory = ({ actorId, actorAuthMethod, actorOrgId, - caId, + caName, commonName, extendedKeyUsages, keyUsages, name, subjectAlternativeName, - ttl + ttl, + projectId }: TCreatePkiTemplateDTO) => { - const ca = await certificateAuthorityDAL.findById(caId); + const ca = await certificateAuthorityDAL.findOne({ name: caName, projectId }); if (!ca) { throw new NotFoundError({ - message: `CA with ID ${caId} not found` + message: `CA with name ${caName} not found` }); } + const { permission } = await permissionService.getProjectPermission({ actor, actorId, @@ -126,7 +134,7 @@ export const pkiTemplatesServiceFactory = ({ } const newTemplate = await pkiTemplatesDAL.create({ - caId, + caId: ca.id, name, commonName, subjectAlternativeName, @@ -143,7 +151,7 @@ export const pkiTemplatesServiceFactory = ({ actorId, actorAuthMethod, actorOrgId, - caId, + caName, commonName, extendedKeyUsages, keyUsages, @@ -173,13 +181,15 @@ export const pkiTemplatesServiceFactory = ({ subject(ProjectPermissionSub.CertificateTemplates, { name: templateName }) ); - if (caId) { - const ca = await certificateAuthorityDAL.findById(caId); + let caId; + if (caName) { + const ca = await certificateAuthorityDAL.findOne({ name: caName, projectId }); if (!ca || ca.projectId !== certTemplate.projectId) { throw new NotFoundError({ - message: `CA with ID ${caId} not found` + message: `CA with name ${caName} not found` }); } + caId = ca.id; } if (name) { diff --git a/backend/src/services/pki-templates/pki-templates-types.ts b/backend/src/services/pki-templates/pki-templates-types.ts index 72d245de1..8dd18c8a9 100644 --- a/backend/src/services/pki-templates/pki-templates-types.ts +++ b/backend/src/services/pki-templates/pki-templates-types.ts @@ -2,7 +2,7 @@ import { TProjectPermission } from "@app/lib/types"; import { CertExtendedKeyUsage, CertKeyUsage } from "@app/services/certificate/certificate-types"; export type TCreatePkiTemplateDTO = { - caId: string; + caName: string; name: string; commonName: string; subjectAlternativeName: string; @@ -13,7 +13,7 @@ export type TCreatePkiTemplateDTO = { export type TUpdatePkiTemplateDTO = { templateName: string; - caId?: string; + caName?: string; name?: string; commonName?: string; subjectAlternativeName?: string; diff --git a/frontend/src/hooks/api/certificateTemplates/types.ts b/frontend/src/hooks/api/certificateTemplates/types.ts index 3e3e728f8..1c2a47178 100644 --- a/frontend/src/hooks/api/certificateTemplates/types.ts +++ b/frontend/src/hooks/api/certificateTemplates/types.ts @@ -65,7 +65,7 @@ export type TDeleteCertificateTemplateDTO = { }; export type TCreateCertificateTemplateV2DTO = { - caId: string; + caName: string; name: string; commonName: string; subjectAlternativeName: string; @@ -77,7 +77,7 @@ export type TCreateCertificateTemplateV2DTO = { export type TUpdateCertificateTemplateV2DTO = { templateName: string; - caId?: string; + caName?: string; name?: string; commonName?: string; subjectAlternativeName?: string; diff --git a/frontend/src/pages/cert-manager/PkiTemplateListPage/PkiTemplateListPage.tsx b/frontend/src/pages/cert-manager/PkiTemplateListPage/PkiTemplateListPage.tsx index 7adf86bc7..895775360 100644 --- a/frontend/src/pages/cert-manager/PkiTemplateListPage/PkiTemplateListPage.tsx +++ b/frontend/src/pages/cert-manager/PkiTemplateListPage/PkiTemplateListPage.tsx @@ -130,7 +130,7 @@ export const PkiTemplateListPage = () => { Name - CA + Issuing CA Last Updated At diff --git a/frontend/src/pages/cert-manager/PkiTemplateListPage/components/PkiTemplateForm.tsx b/frontend/src/pages/cert-manager/PkiTemplateListPage/components/PkiTemplateForm.tsx index 0a78ddac2..19022b4b9 100644 --- a/frontend/src/pages/cert-manager/PkiTemplateListPage/components/PkiTemplateForm.tsx +++ b/frontend/src/pages/cert-manager/PkiTemplateListPage/components/PkiTemplateForm.tsx @@ -1,4 +1,5 @@ import { Controller, useForm } from "react-hook-form"; + import { faQuestionCircle } from "@fortawesome/free-regular-svg-icons"; import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; import { zodResolver } from "@hookform/resolvers/zod"; @@ -133,7 +134,7 @@ export const PkiTemplateForm = ({ certTemplate, handlePopUpToggle }: Props) => { await updateCertTemplate({ templateName: certTemplate.name, projectId: currentWorkspace.id, - caId: ca.id, + caName: ca.name, name, commonName, subjectAlternativeName, @@ -153,7 +154,7 @@ export const PkiTemplateForm = ({ certTemplate, handlePopUpToggle }: Props) => { } else { await createCertTemplate({ projectId: currentWorkspace.id, - caId: ca.id, + caName: ca.name, name, commonName, subjectAlternativeName,