Add http events

This commit is contained in:
Fang-Pen Lin
2025-12-05 12:07:41 -08:00
parent 30b451469b
commit 73f2c2b2e5
2 changed files with 27 additions and 2 deletions
@@ -7,6 +7,7 @@ import { MySQLSessionCredentialsSchema } from "@app/ee/services/pam-resource/mys
import { PostgresSessionCredentialsSchema } from "@app/ee/services/pam-resource/postgres/postgres-resource-schemas"; import { PostgresSessionCredentialsSchema } from "@app/ee/services/pam-resource/postgres/postgres-resource-schemas";
import { SSHSessionCredentialsSchema } from "@app/ee/services/pam-resource/ssh/ssh-resource-schemas"; import { SSHSessionCredentialsSchema } from "@app/ee/services/pam-resource/ssh/ssh-resource-schemas";
import { import {
HttpEventSchema,
PamSessionCommandLogSchema, PamSessionCommandLogSchema,
SanitizedSessionSchema, SanitizedSessionSchema,
TerminalEventSchema TerminalEventSchema
@@ -91,7 +92,7 @@ export const registerPamSessionRouter = async (server: FastifyZodProvider) => {
sessionId: z.string().uuid() sessionId: z.string().uuid()
}), }),
body: z.object({ body: z.object({
logs: z.array(z.union([PamSessionCommandLogSchema, TerminalEventSchema])) logs: z.array(z.union([PamSessionCommandLogSchema, TerminalEventSchema, HttpEventSchema]))
}), }),
response: { response: {
200: z.object({ 200: z.object({
@@ -11,6 +11,8 @@ export const PamSessionCommandLogSchema = z.object({
// SSH Terminal Event schemas // SSH Terminal Event schemas
export const TerminalEventTypeSchema = z.enum(["input", "output", "resize", "error"]); export const TerminalEventTypeSchema = z.enum(["input", "output", "resize", "error"]);
export const HttpEventTypeSchema = z.enum(["request", "response"]);
export const TerminalEventSchema = z.object({ export const TerminalEventSchema = z.object({
timestamp: z.coerce.date(), timestamp: z.coerce.date(),
eventType: TerminalEventTypeSchema, eventType: TerminalEventTypeSchema,
@@ -18,8 +20,30 @@ export const TerminalEventSchema = z.object({
elapsedTime: z.number() // Seconds since session start (for replay) elapsedTime: z.number() // Seconds since session start (for replay)
}); });
export const HttpBaseEventSchema = z.object({
timestamp: z.coerce.date(),
requestId: z.string(),
eventType: TerminalEventTypeSchema,
headers: z.record(z.string(), z.string())
});
export const HttpRequestEventSchema = HttpBaseEventSchema.extend({
eventType: z.literal(HttpEventTypeSchema.Values.request),
method: z.string(),
url: z.string(),
body: z.string()
});
export const HttpResponseEventSchema = HttpBaseEventSchema.extend({
eventType: z.literal(HttpEventTypeSchema.Values.response),
status: z.string(),
body: z.string()
});
export const HttpEventSchema = z.discriminatedUnion("eventType", [HttpRequestEventSchema, HttpResponseEventSchema]);
export const SanitizedSessionSchema = PamSessionsSchema.omit({ export const SanitizedSessionSchema = PamSessionsSchema.omit({
encryptedLogsBlob: true encryptedLogsBlob: true
}).extend({ }).extend({
logs: z.array(z.union([PamSessionCommandLogSchema, TerminalEventSchema])) logs: z.array(z.union([PamSessionCommandLogSchema, TerminalEventSchema, HttpEventSchema]))
}); });