feat(audit): локальный журнал и push в auth-portal
Таблица audit_log, recordAudit на CRUD, GET /api/v1/audit и dual-write source_app=cfdm. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
30447d8380
commit
859ad23006
22 files changed
+1561
-106
No files matched your search
@@ -2,6 +2,7 @@ import type { FastifyInstance } from "fastify";
|
||||
import { bulkUpdateDomainsSchema, updateDomainSchema } from "@cfdm/shared";
|
||||
import { z } from "zod";
|
||||
import * as domainService from "../services/domain-service.js";
|
||||
import { recordAudit } from "../lib/audit.js";
|
||||
|
||||
export async function domainRoutes(app: FastifyInstance) {
|
||||
const createSchema = z.object({
|
||||
@@ -17,12 +18,20 @@ export async function domainRoutes(app: FastifyInstance) {
|
||||
|
||||
app.post("/domains", async (request) => {
|
||||
const body = createSchema.parse(request.body);
|
||||
return domainService.createDomain(
|
||||
const domain = await domainService.createDomain(
|
||||
request.server.db,
|
||||
request.server.cf,
|
||||
body.group_id ?? null,
|
||||
body.zone_name,
|
||||
);
|
||||
recordAudit(request.server, request, {
|
||||
action: "domain.create",
|
||||
targetType: "app_resource",
|
||||
targetId: String(domain.id),
|
||||
summary: `Добавлен домен ${domain.zone_name}`,
|
||||
details: { zone_name: domain.zone_name, group_id: domain.group_id },
|
||||
});
|
||||
return domain;
|
||||
});
|
||||
|
||||
app.post("/domains/bulk", async (request) => {
|
||||
@@ -47,12 +56,29 @@ export async function domainRoutes(app: FastifyInstance) {
|
||||
app.patch("/domains/:id", async (request) => {
|
||||
const { id } = request.params as { id: string };
|
||||
const body = updateDomainSchema.parse(request.body);
|
||||
return domainService.updateDomain(request.server.db, Number(id), body);
|
||||
const domain = domainService.updateDomain(request.server.db, Number(id), body);
|
||||
recordAudit(request.server, request, {
|
||||
action: "domain.update",
|
||||
targetType: "app_resource",
|
||||
targetId: String(domain.id),
|
||||
summary: `Обновлён домен ${domain.zone_name}`,
|
||||
details: body,
|
||||
});
|
||||
return domain;
|
||||
});
|
||||
|
||||
app.delete("/domains/:id", async (request) => {
|
||||
const { id } = request.params as { id: string };
|
||||
const domain = domainService.getDomain(request.server.db, Number(id));
|
||||
domainService.deleteDomain(request.server.db, Number(id));
|
||||
recordAudit(request.server, request, {
|
||||
action: "domain.delete",
|
||||
severity: "warning",
|
||||
targetType: "app_resource",
|
||||
targetId: String(id),
|
||||
summary: `Удалён домен ${domain.zone_name}`,
|
||||
details: { zone_name: domain.zone_name },
|
||||
});
|
||||
return { deleted: true };
|
||||
});
|
||||
|
||||
|
||||
Reference in new issue
Block a user