mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-07 13:27:46 +00:00
140 lines
4.0 KiB
TypeScript
140 lines
4.0 KiB
TypeScript
import { z } from "zod";
|
|
|
|
import { AuditLogsSchema, SecretSnapshotsSchema } from "@app/db/schemas";
|
|
import { EventType, UserAgentType } from "@app/ee/services/audit-log/audit-log-types";
|
|
import { verifyAuth } from "@app/server/plugins/auth/verify-auth";
|
|
import { AuthMode } from "@app/services/auth/auth-type";
|
|
|
|
export const registerProjectRouter = async (server: FastifyZodProvider) => {
|
|
server.route({
|
|
method: "GET",
|
|
url: "/:workspaceId/secret-snapshots",
|
|
schema: {
|
|
params: z.object({
|
|
workspaceId: z.string().trim()
|
|
}),
|
|
querystring: z.object({
|
|
environment: z.string().trim(),
|
|
path: z.string().trim().default("/"),
|
|
offset: z.coerce.number().default(0),
|
|
limit: z.coerce.number().default(20)
|
|
}),
|
|
response: {
|
|
200: z.object({
|
|
secretSnapshots: SecretSnapshotsSchema.array()
|
|
})
|
|
}
|
|
},
|
|
onRequest: verifyAuth([AuthMode.JWT, AuthMode.API_KEY, AuthMode.IDENTITY_ACCESS_TOKEN]),
|
|
handler: async (req) => {
|
|
const secretSnapshots = await server.services.snapshot.listSnapshots({
|
|
actor: req.permission.type,
|
|
actorId: req.permission.id,
|
|
projectId: req.params.workspaceId,
|
|
...req.query
|
|
});
|
|
return { secretSnapshots };
|
|
}
|
|
});
|
|
|
|
server.route({
|
|
method: "GET",
|
|
url: "/:workspaceId/secret-snapshots/count",
|
|
schema: {
|
|
params: z.object({
|
|
workspaceId: z.string().trim()
|
|
}),
|
|
querystring: z.object({
|
|
environment: z.string().trim(),
|
|
path: z.string().trim().default("/")
|
|
}),
|
|
response: {
|
|
200: z.object({
|
|
count: z.number()
|
|
})
|
|
}
|
|
},
|
|
onRequest: verifyAuth([AuthMode.JWT, AuthMode.API_KEY, AuthMode.IDENTITY_ACCESS_TOKEN]),
|
|
handler: async (req) => {
|
|
const count = await server.services.snapshot.projectSecretSnapshotCount({
|
|
actor: req.permission.type,
|
|
actorId: req.permission.id,
|
|
projectId: req.params.workspaceId,
|
|
environment: req.query.environment,
|
|
path: req.query.path
|
|
});
|
|
return { count };
|
|
}
|
|
});
|
|
|
|
server.route({
|
|
method: "GET",
|
|
url: "/:workspaceId/audit-logs",
|
|
schema: {
|
|
params: z.object({
|
|
workspaceId: z.string().trim()
|
|
}),
|
|
querystring: z.object({
|
|
eventType: z.nativeEnum(EventType).optional(),
|
|
userAgentType: z.nativeEnum(UserAgentType).optional(),
|
|
startDate: z.string().datetime().optional(),
|
|
endDate: z.string().datetime().optional(),
|
|
offset: z.coerce.number().default(0),
|
|
limit: z.coerce.number().default(20),
|
|
actor: z.string().optional()
|
|
}),
|
|
response: {
|
|
200: z.object({
|
|
auditLogs: AuditLogsSchema.omit({
|
|
eventMetadata: true,
|
|
eventType: true,
|
|
actor: true,
|
|
actorMetadata: true
|
|
})
|
|
.merge(
|
|
z.object({
|
|
event: z.object({
|
|
type: z.string(),
|
|
metadata: z.any()
|
|
}),
|
|
actor: z.object({
|
|
type: z.string(),
|
|
metadata: z.any()
|
|
})
|
|
})
|
|
)
|
|
.array()
|
|
})
|
|
}
|
|
},
|
|
onRequest: verifyAuth([AuthMode.JWT, AuthMode.API_KEY, AuthMode.IDENTITY_ACCESS_TOKEN]),
|
|
handler: async (req) => {
|
|
const auditLogs = await server.services.auditLog.listProjectAuditLogs({
|
|
actorId: req.permission.id,
|
|
projectId: req.params.workspaceId,
|
|
...req.query,
|
|
auditLogActor: req.query.actor,
|
|
actor: req.permission.type
|
|
});
|
|
return { auditLogs };
|
|
}
|
|
});
|
|
|
|
server.route({
|
|
method: "GET",
|
|
url: "/:workspaceId/audit-logs/filters/actors",
|
|
schema: {
|
|
params: z.object({
|
|
workspaceId: z.string().trim()
|
|
}),
|
|
response: {
|
|
200: z.object({
|
|
actors: z.string().array()
|
|
})
|
|
}
|
|
},
|
|
onRequest: verifyAuth([AuthMode.JWT]),
|
|
handler: async () => ({ actors: [] })
|
|
});
|
|
};
|