more package declarations
This commit is contained in:
@@ -7,39 +7,97 @@ function getUserId(request: FastifyRequest): string | undefined {
|
||||
return (request.user as AuthUser | undefined)?.id;
|
||||
}
|
||||
|
||||
const timeWindowSchema = {
|
||||
type: "object",
|
||||
properties: {
|
||||
timeWindow: { type: "integer", minimum: 1, maximum: 10080 },
|
||||
},
|
||||
};
|
||||
|
||||
const paginatedQuerySchema = {
|
||||
type: "object",
|
||||
properties: {
|
||||
timeWindow: { type: "integer", minimum: 1, maximum: 10080 },
|
||||
limit: { type: "integer", minimum: 1, maximum: 200 },
|
||||
offset: { type: "integer", minimum: 0, maximum: 10000 },
|
||||
},
|
||||
};
|
||||
|
||||
export function correlationRoutes(fastify: FastifyInstance) {
|
||||
fastify.get("/dashboard", async (request, reply) => {
|
||||
const userId = getUserId(request);
|
||||
if (!userId || userId === "anonymous") {
|
||||
return reply.code(401).send({ error: "User not authenticated" });
|
||||
fastify.get(
|
||||
"/dashboard",
|
||||
{
|
||||
schema: {
|
||||
...timeWindowSchema,
|
||||
response: {
|
||||
"400": {
|
||||
type: "object",
|
||||
properties: {
|
||||
error: { type: "string" },
|
||||
},
|
||||
},
|
||||
"401": {
|
||||
type: "object",
|
||||
properties: {
|
||||
error: { type: "string" },
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
async (request, reply) => {
|
||||
const userId = getUserId(request);
|
||||
if (!userId || userId === "anonymous") {
|
||||
return reply.code(401).send({ error: "User not authenticated" });
|
||||
}
|
||||
|
||||
const query = request.query as Record<string, string | number>;
|
||||
const timeWindow =
|
||||
typeof query.timeWindow === "number" ? query.timeWindow : 60;
|
||||
const data = await correlationService.getDashboardData(userId, timeWindow);
|
||||
return reply.send(data);
|
||||
}
|
||||
);
|
||||
|
||||
const timeWindow =
|
||||
parseInt(
|
||||
(request.query as Record<string, string>).timeWindow as string
|
||||
) || 60;
|
||||
const data = await correlationService.getDashboardData(userId, timeWindow);
|
||||
return reply.send(data);
|
||||
});
|
||||
fastify.get(
|
||||
"/groups",
|
||||
{
|
||||
schema: {
|
||||
...paginatedQuerySchema,
|
||||
response: {
|
||||
"400": {
|
||||
type: "object",
|
||||
properties: {
|
||||
error: { type: "string" },
|
||||
},
|
||||
},
|
||||
"401": {
|
||||
type: "object",
|
||||
properties: {
|
||||
error: { type: "string" },
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
async (request, reply) => {
|
||||
const userId = getUserId(request);
|
||||
if (!userId || userId === "anonymous") {
|
||||
return reply.code(401).send({ error: "User not authenticated" });
|
||||
}
|
||||
|
||||
fastify.get("/groups", async (request, reply) => {
|
||||
const userId = getUserId(request);
|
||||
if (!userId || userId === "anonymous") {
|
||||
return reply.code(401).send({ error: "User not authenticated" });
|
||||
const query = request.query as Record<string, string | number>;
|
||||
const result = await correlationService.getCorrelationGroups({
|
||||
userId,
|
||||
status: (query.status as any) || undefined,
|
||||
timeWindowMinutes:
|
||||
typeof query.timeWindow === "number" ? query.timeWindow : 60,
|
||||
limit: typeof query.limit === "number" ? query.limit : 50,
|
||||
offset: typeof query.offset === "number" ? query.offset : 0,
|
||||
});
|
||||
return reply.send(result);
|
||||
}
|
||||
|
||||
const query = request.query as Record<string, string>;
|
||||
const result = await correlationService.getCorrelationGroups({
|
||||
userId,
|
||||
status: (query.status as any) || undefined,
|
||||
timeWindowMinutes: query.timeWindow
|
||||
? parseInt(query.timeWindow)
|
||||
: 60,
|
||||
limit: query.limit ? parseInt(query.limit) : 50,
|
||||
offset: query.offset ? parseInt(query.offset) : 0,
|
||||
});
|
||||
return reply.send(result);
|
||||
});
|
||||
);
|
||||
|
||||
fastify.get(
|
||||
"/groups/:groupId",
|
||||
@@ -114,26 +172,47 @@ export function correlationRoutes(fastify: FastifyInstance) {
|
||||
}
|
||||
);
|
||||
|
||||
fastify.get("/alerts", async (request, reply) => {
|
||||
const userId = getUserId(request);
|
||||
if (!userId || userId === "anonymous") {
|
||||
return reply.code(401).send({ error: "User not authenticated" });
|
||||
}
|
||||
fastify.get(
|
||||
"/alerts",
|
||||
{
|
||||
schema: {
|
||||
...paginatedQuerySchema,
|
||||
response: {
|
||||
"400": {
|
||||
type: "object",
|
||||
properties: {
|
||||
error: { type: "string" },
|
||||
},
|
||||
},
|
||||
"401": {
|
||||
type: "object",
|
||||
properties: {
|
||||
error: { type: "string" },
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
async (request, reply) => {
|
||||
const userId = getUserId(request);
|
||||
if (!userId || userId === "anonymous") {
|
||||
return reply.code(401).send({ error: "User not authenticated" });
|
||||
}
|
||||
|
||||
const query = request.query as Record<string, string>;
|
||||
const result = await correlationService.getCorrelatedAlerts({
|
||||
userId,
|
||||
source: (query.source as any) || undefined,
|
||||
category: (query.category as any) || undefined,
|
||||
severity: (query.severity as any) || undefined,
|
||||
timeWindowMinutes: query.timeWindow
|
||||
? parseInt(query.timeWindow)
|
||||
: 60,
|
||||
limit: query.limit ? parseInt(query.limit) : 50,
|
||||
offset: query.offset ? parseInt(query.offset) : 0,
|
||||
});
|
||||
return reply.send(result);
|
||||
});
|
||||
const query = request.query as Record<string, string | number>;
|
||||
const result = await correlationService.getCorrelatedAlerts({
|
||||
userId,
|
||||
source: (query.source as any) || undefined,
|
||||
category: (query.category as any) || undefined,
|
||||
severity: (query.severity as any) || undefined,
|
||||
timeWindowMinutes:
|
||||
typeof query.timeWindow === "number" ? query.timeWindow : 60,
|
||||
limit: typeof query.limit === "number" ? query.limit : 50,
|
||||
offset: typeof query.offset === "number" ? query.offset : 0,
|
||||
});
|
||||
return reply.send(result);
|
||||
}
|
||||
);
|
||||
|
||||
fastify.post(
|
||||
"/ingest/darkwatch",
|
||||
|
||||
Reference in New Issue
Block a user