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],
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(),
@@ -56,7 +56,13 @@ type TPkiTemplatesServiceFactoryDep = {
permissionService: Pick<TPermissionServiceFactory, "getProjectPermission">;
certificateAuthorityDAL: Pick<
TCertificateAuthorityDALFactory,
"findByIdWithAssociatedCa" | "findById" | "transaction" | "create" | "updateById" | "findWithAssociatedCa"
| "findByIdWithAssociatedCa"
| "findById"
| "transaction"
| "create"
| "updateById"
| "findWithAssociatedCa"
| "findOne"
>;
internalCaFns: ReturnType<typeof InternalCertificateAuthorityFns>;
kmsService: Pick<TKmsServiceFactory, "generateKmsKey" | "decryptWithKmsKey" | "encryptWithKmsKey">;
@@ -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) {
@@ -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;