misc: added audit logs for certificate template

This commit is contained in:
Sheen Capadngan
2024-08-16 23:08:01 +08:00
parent 6fe1d77375
commit ed0463e3e4
7 changed files with 138 additions and 8 deletions
@@ -162,7 +162,11 @@ export enum EventType {
UPDATE_PROJECT_KMS = "update-project-kms",
GET_PROJECT_KMS_BACKUP = "get-project-kms-backup",
LOAD_PROJECT_KMS_BACKUP = "load-project-kms-backup",
ORG_ADMIN_ACCESS_PROJECT = "org-admin-accessed-project"
ORG_ADMIN_ACCESS_PROJECT = "org-admin-accessed-project",
CREATE_CERTIFICATE_TEMPLATE = "create-certificate-template",
UPDATE_CERTIFICATE_TEMPLATE = "update-certificate-template",
DELETE_CERTIFICATE_TEMPLATE = "delete-certificate-template",
GET_CERTIFICATE_TEMPLATE = "get-certificate-template"
}
interface UserActorMetadata {
@@ -1365,6 +1369,34 @@ interface LoadProjectKmsBackupEvent {
metadata: Record<string, string>; // no metadata yet
}
interface CreateCertificateTemplate {
type: EventType.CREATE_CERTIFICATE_TEMPLATE;
metadata: {
certificateTemplateId: string;
};
}
interface GetCertificateTemplate {
type: EventType.GET_CERTIFICATE_TEMPLATE;
metadata: {
certificateTemplateId: string;
};
}
interface UpdateCertificateTemplate {
type: EventType.UPDATE_CERTIFICATE_TEMPLATE;
metadata: {
certificateTemplateId: string;
};
}
interface DeleteCertificateTemplate {
type: EventType.DELETE_CERTIFICATE_TEMPLATE;
metadata: {
certificateTemplateId: string;
};
}
interface OrgAdminAccessProjectEvent {
type: EventType.ORG_ADMIN_ACCESS_PROJECT;
metadata: {
@@ -1498,4 +1530,8 @@ export type Event =
| UpdateProjectKmsEvent
| GetProjectKmsBackupEvent
| LoadProjectKmsBackupEvent
| OrgAdminAccessProjectEvent;
| OrgAdminAccessProjectEvent
| CreateCertificateTemplate
| UpdateCertificateTemplate
| GetCertificateTemplate
| DeleteCertificateTemplate;
@@ -2,6 +2,7 @@ import ms from "ms";
import { z } from "zod";
import { CertificateTemplatesSchema } from "@app/db/schemas";
import { EventType } from "@app/ee/services/audit-log/audit-log-types";
import { readLimit, writeLimit } from "@app/server/config/rateLimiter";
import { verifyAuth } from "@app/server/plugins/auth/verify-auth";
import { AuthMode } from "@app/services/auth/auth-type";
@@ -49,6 +50,17 @@ export const registerCertificateTemplateRouter = async (server: FastifyZodProvid
actorOrgId: req.permission.orgId
});
await server.services.auditLog.createAuditLog({
...req.auditLogInfo,
projectId: certificateTemplate.projectId,
event: {
type: EventType.GET_CERTIFICATE_TEMPLATE,
metadata: {
certificateTemplateId: certificateTemplate.id
}
}
});
return { certificateTemplate };
}
});
@@ -84,6 +96,17 @@ export const registerCertificateTemplateRouter = async (server: FastifyZodProvid
...req.body
});
await server.services.auditLog.createAuditLog({
...req.auditLogInfo,
projectId: certificateTemplate.projectId,
event: {
type: EventType.CREATE_CERTIFICATE_TEMPLATE,
metadata: {
certificateTemplateId: certificateTemplate.id
}
}
});
return { certificateTemplate };
}
});
@@ -126,6 +149,17 @@ export const registerCertificateTemplateRouter = async (server: FastifyZodProvid
actorOrgId: req.permission.orgId
});
await server.services.auditLog.createAuditLog({
...req.auditLogInfo,
projectId: certificateTemplate.projectId,
event: {
type: EventType.UPDATE_CERTIFICATE_TEMPLATE,
metadata: {
certificateTemplateId: certificateTemplate.id
}
}
});
return { certificateTemplate };
}
});
@@ -156,6 +190,17 @@ export const registerCertificateTemplateRouter = async (server: FastifyZodProvid
actorOrgId: req.permission.orgId
});
await server.services.auditLog.createAuditLog({
...req.auditLogInfo,
projectId: certificateTemplate.projectId,
event: {
type: EventType.DELETE_CERTIFICATE_TEMPLATE,
metadata: {
certificateTemplateId: certificateTemplate.id
}
}
});
return { certificateTemplate };
}
});
@@ -66,7 +66,7 @@ export const certificateTemplateServiceFactory = ({
ttl
});
return certificateTemplate;
return { ...certificateTemplate, projectId: ca.projectId };
};
const updateCertTemplate = async ({
@@ -120,7 +120,7 @@ export const certificateTemplateServiceFactory = ({
ttl
});
return updatedCertTemplate;
return { ...updatedCertTemplate, projectId: certTemplate.projectId };
};
const deleteCertTemplate = async ({ id, actorId, actorAuthMethod, actor, actorOrgId }: TDeleteCertTemplateDTO) => {
@@ -146,7 +146,7 @@ export const certificateTemplateServiceFactory = ({
const deletedCertTemplate = await certificateTemplateDAL.deleteById(certTemplate.id);
return deletedCertTemplate;
return { ...deletedCertTemplate, projectId: certTemplate.projectId };
};
const getCertTemplate = async ({ id, actorId, actorAuthMethod, actor, actorOrgId }: TGetCertTemplateDTO) => {