feat: review comments addressed

This commit is contained in:
=
2025-05-30 17:53:22 +00:00
committed by Akhil Mohan
parent 5e3d4edec9
commit 09db9e340b
6 changed files with 30 additions and 19 deletions
@@ -26,7 +26,7 @@ export const registerPkiTemplatesRouter = async (server: FastifyZodProvider) =>
tags: [ApiDocsTags.PkiCertificateTemplates], tags: [ApiDocsTags.PkiCertificateTemplates],
body: z.object({ body: z.object({
name: slugSchema(), name: slugSchema(),
caId: z.string(), caName: slugSchema({ field: "caName" }),
projectId: z.string(), projectId: z.string(),
commonName: validateTemplateRegexField, commonName: validateTemplateRegexField,
subjectAlternativeName: validateTemplateRegexField, subjectAlternativeName: validateTemplateRegexField,
@@ -72,7 +72,7 @@ export const registerPkiTemplatesRouter = async (server: FastifyZodProvider) =>
}), }),
body: z.object({ body: z.object({
name: slugSchema().optional(), name: slugSchema().optional(),
caId: z.string(), caName: slugSchema(),
projectId: z.string(), projectId: z.string(),
commonName: validateTemplateRegexField.optional(), commonName: validateTemplateRegexField.optional(),
subjectAlternativeName: validateTemplateRegexField.optional(), subjectAlternativeName: validateTemplateRegexField.optional(),
@@ -56,7 +56,13 @@ type TPkiTemplatesServiceFactoryDep = {
permissionService: Pick<TPermissionServiceFactory, "getProjectPermission">; permissionService: Pick<TPermissionServiceFactory, "getProjectPermission">;
certificateAuthorityDAL: Pick< certificateAuthorityDAL: Pick<
TCertificateAuthorityDALFactory, TCertificateAuthorityDALFactory,
"findByIdWithAssociatedCa" | "findById" | "transaction" | "create" | "updateById" | "findWithAssociatedCa" | "findByIdWithAssociatedCa"
| "findById"
| "transaction"
| "create"
| "updateById"
| "findWithAssociatedCa"
| "findOne"
>; >;
internalCaFns: ReturnType<typeof InternalCertificateAuthorityFns>; internalCaFns: ReturnType<typeof InternalCertificateAuthorityFns>;
kmsService: Pick<TKmsServiceFactory, "generateKmsKey" | "decryptWithKmsKey" | "encryptWithKmsKey">; kmsService: Pick<TKmsServiceFactory, "generateKmsKey" | "decryptWithKmsKey" | "encryptWithKmsKey">;
@@ -92,20 +98,22 @@ export const pkiTemplatesServiceFactory = ({
actorId, actorId,
actorAuthMethod, actorAuthMethod,
actorOrgId, actorOrgId,
caId, caName,
commonName, commonName,
extendedKeyUsages, extendedKeyUsages,
keyUsages, keyUsages,
name, name,
subjectAlternativeName, subjectAlternativeName,
ttl ttl,
projectId
}: TCreatePkiTemplateDTO) => { }: TCreatePkiTemplateDTO) => {
const ca = await certificateAuthorityDAL.findById(caId); const ca = await certificateAuthorityDAL.findOne({ name: caName, projectId });
if (!ca) { if (!ca) {
throw new NotFoundError({ throw new NotFoundError({
message: `CA with ID ${caId} not found` message: `CA with name ${caName} not found`
}); });
} }
const { permission } = await permissionService.getProjectPermission({ const { permission } = await permissionService.getProjectPermission({
actor, actor,
actorId, actorId,
@@ -126,7 +134,7 @@ export const pkiTemplatesServiceFactory = ({
} }
const newTemplate = await pkiTemplatesDAL.create({ const newTemplate = await pkiTemplatesDAL.create({
caId, caId: ca.id,
name, name,
commonName, commonName,
subjectAlternativeName, subjectAlternativeName,
@@ -143,7 +151,7 @@ export const pkiTemplatesServiceFactory = ({
actorId, actorId,
actorAuthMethod, actorAuthMethod,
actorOrgId, actorOrgId,
caId, caName,
commonName, commonName,
extendedKeyUsages, extendedKeyUsages,
keyUsages, keyUsages,
@@ -173,13 +181,15 @@ export const pkiTemplatesServiceFactory = ({
subject(ProjectPermissionSub.CertificateTemplates, { name: templateName }) subject(ProjectPermissionSub.CertificateTemplates, { name: templateName })
); );
if (caId) { let caId;
const ca = await certificateAuthorityDAL.findById(caId); if (caName) {
const ca = await certificateAuthorityDAL.findOne({ name: caName, projectId });
if (!ca || ca.projectId !== certTemplate.projectId) { if (!ca || ca.projectId !== certTemplate.projectId) {
throw new NotFoundError({ throw new NotFoundError({
message: `CA with ID ${caId} not found` message: `CA with name ${caName} not found`
}); });
} }
caId = ca.id;
} }
if (name) { if (name) {
@@ -2,7 +2,7 @@ import { TProjectPermission } from "@app/lib/types";
import { CertExtendedKeyUsage, CertKeyUsage } from "@app/services/certificate/certificate-types"; import { CertExtendedKeyUsage, CertKeyUsage } from "@app/services/certificate/certificate-types";
export type TCreatePkiTemplateDTO = { export type TCreatePkiTemplateDTO = {
caId: string; caName: string;
name: string; name: string;
commonName: string; commonName: string;
subjectAlternativeName: string; subjectAlternativeName: string;
@@ -13,7 +13,7 @@ export type TCreatePkiTemplateDTO = {
export type TUpdatePkiTemplateDTO = { export type TUpdatePkiTemplateDTO = {
templateName: string; templateName: string;
caId?: string; caName?: string;
name?: string; name?: string;
commonName?: string; commonName?: string;
subjectAlternativeName?: string; subjectAlternativeName?: string;
@@ -65,7 +65,7 @@ export type TDeleteCertificateTemplateDTO = {
}; };
export type TCreateCertificateTemplateV2DTO = { export type TCreateCertificateTemplateV2DTO = {
caId: string; caName: string;
name: string; name: string;
commonName: string; commonName: string;
subjectAlternativeName: string; subjectAlternativeName: string;
@@ -77,7 +77,7 @@ export type TCreateCertificateTemplateV2DTO = {
export type TUpdateCertificateTemplateV2DTO = { export type TUpdateCertificateTemplateV2DTO = {
templateName: string; templateName: string;
caId?: string; caName?: string;
name?: string; name?: string;
commonName?: string; commonName?: string;
subjectAlternativeName?: string; subjectAlternativeName?: string;
@@ -130,7 +130,7 @@ export const PkiTemplateListPage = () => {
<THead> <THead>
<Tr> <Tr>
<Th>Name</Th> <Th>Name</Th>
<Th>CA</Th> <Th>Issuing CA</Th>
<Th className="w-64">Last Updated At</Th> <Th className="w-64">Last Updated At</Th>
<Th /> <Th />
</Tr> </Tr>
@@ -1,4 +1,5 @@
import { Controller, useForm } from "react-hook-form"; import { Controller, useForm } from "react-hook-form";
import { faQuestionCircle } from "@fortawesome/free-regular-svg-icons"; import { faQuestionCircle } from "@fortawesome/free-regular-svg-icons";
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import { zodResolver } from "@hookform/resolvers/zod"; import { zodResolver } from "@hookform/resolvers/zod";
@@ -133,7 +134,7 @@ export const PkiTemplateForm = ({ certTemplate, handlePopUpToggle }: Props) => {
await updateCertTemplate({ await updateCertTemplate({
templateName: certTemplate.name, templateName: certTemplate.name,
projectId: currentWorkspace.id, projectId: currentWorkspace.id,
caId: ca.id, caName: ca.name,
name, name,
commonName, commonName,
subjectAlternativeName, subjectAlternativeName,
@@ -153,7 +154,7 @@ export const PkiTemplateForm = ({ certTemplate, handlePopUpToggle }: Props) => {
} else { } else {
await createCertTemplate({ await createCertTemplate({
projectId: currentWorkspace.id, projectId: currentWorkspace.id,
caId: ca.id, caName: ca.name,
name, name,
commonName, commonName,
subjectAlternativeName, subjectAlternativeName,