feat: review comments addressed

This commit is contained in:
=
2025-05-30 22:38:56 +05:30
committed by Akhil Mohan
parent 5e3d4edec9
commit 09db9e340b
6 changed files with 30 additions and 19 deletions

View File

@@ -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(),

View File

@@ -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) {

View File

@@ -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;

View File

@@ -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;

View File

@@ -130,7 +130,7 @@ export const PkiTemplateListPage = () => {
<THead>
<Tr>
<Th>Name</Th>
<Th>CA</Th>
<Th>Issuing CA</Th>
<Th className="w-64">Last Updated At</Th>
<Th />
</Tr>

View File

@@ -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,