Skip to content

Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.

Initial schema ideas for logging

Tuan Dang2e84b7e3549b
diff --git a/backend/src/controllers/index.ts b/backend/src/controllers/index.ts
index 2d3debfb58..e52d021b18 100644
--- a/backend/src/controllers/index.ts
+++ b/backend/src/controllers/index.ts
@@ -13,6 +13,7 @@ import * as stripeController from './stripeController';
import * as userActionController from './userActionController';
import * as userController from './userController';
import * as workspaceController from './workspaceController';
+import * as logController from './logController';
export {
authController,
@@ -29,5 +30,6 @@ export {
stripeController,
userActionController,
userController,
- workspaceController
+ workspaceController,
+ logController
};
diff --git a/backend/src/controllers/logController.ts b/backend/src/controllers/logController.ts
new file mode 100644
index 0000000000..3e1d7d5353
--- /dev/null
+++ b/backend/src/controllers/logController.ts
@@ -0,0 +1,30 @@
+import { Request, Response } from 'express';
+import * as Sentry from '@sentry/node';
+import {
+ Log
+} from '../models';
+
+
+export const getLogs = async (req: Request, res: Response) => {
+ // get logs
+
+ console.log('getLogs');
+ let logs;
+ try {
+ const { workspaceId } = req.params;
+
+ logs = await Log.find({
+ workspace: workspaceId
+ });
+ } catch (err) {
+ Sentry.setUser({ email: req.user.email });
+ Sentry.captureException(err);
+ return res.status(400).send({
+ message: 'Failed to get audit logs'
+ });
+ }
+
+ return res.status(200).send({
+ logs
+ });
+}
\ No newline at end of file
diff --git a/backend/src/index.ts b/backend/src/index.ts
index 28e27cc9af..fd4f867af4 100644
--- a/backend/src/index.ts
+++ b/backend/src/index.ts
@@ -38,7 +38,8 @@ import {
password as passwordRouter,
stripe as stripeRouter,
integration as integrationRouter,
- integrationAuth as integrationAuthRouter
+ integrationAuth as integrationAuthRouter,
+ log as logRouter
} from './routes';
const connectWithRetry = () => {
@@ -92,6 +93,7 @@ app.use('/api/v1/password', passwordRouter);
app.use('/api/v1/stripe', stripeRouter);
app.use('/api/v1/integration', integrationRouter);
app.use('/api/v1/integration-auth', integrationAuthRouter);
+app.use('/api/v1/log', logRouter);
const server = http.createServer(app);
diff --git a/backend/src/models/index.ts b/backend/src/models/index.ts
index 9b07f67668..53f5a395a9 100644
--- a/backend/src/models/index.ts
+++ b/backend/src/models/index.ts
@@ -12,6 +12,7 @@ import Token, { IToken } from './token';
import User, { IUser } from './user';
import UserAction, { IUserAction } from './userAction';
import Workspace, { IWorkspace } from './workspace';
+import Log, { ILog } from './log';
export {
BackupPrivateKey,
@@ -41,5 +42,7 @@ export {
UserAction,
IUserAction,
Workspace,
- IWorkspace
+ IWorkspace,
+ Log,
+ ILog
};
diff --git a/backend/src/models/log.ts b/backend/src/models/log.ts
new file mode 100644
index 0000000000..7078ae52f1
--- /dev/null
+++ b/backend/src/models/log.ts
@@ -0,0 +1,46 @@
+import { Schema, model, Types } from 'mongoose';
+
+export interface ILog {
+ _id: Types.ObjectId;
+ user: Types.ObjectId;
+ workspace: Types.ObjectId;
+ event: string;
+ source: string;
+ ipAddress: string;
+}
+
+// TODO: need a way to store payload info for each
+// log
+
+// which secret is being ref etc.
+
+const logSchema = new Schema<ILog>(
+ {
+ user: {
+ type: Schema.Types.ObjectId,
+ ref: 'User'
+ },
+ workspace: {
+ type: Schema.Types.ObjectId,
+ ref: 'Workspace'
+ },
+ event: {
+ type: String,
+ required: true
+ },
+ source: { // should this just be a payload attr?
+ type: String,
+ required: true
+ },
+ ipAddress: { // store in bytes?
+ type: String,
+ required: true
+ }
+ }, {
+ timestamps: true
+ }
+);
+
+const Log = model<ILog>('Log', logSchema);
+
+export default Log;
\ No newline at end of file
diff --git a/backend/src/routes/index.ts b/backend/src/routes/index.ts
index cf015abfb1..97dc72c830 100644
--- a/backend/src/routes/index.ts
+++ b/backend/src/routes/index.ts
@@ -14,6 +14,7 @@ import password from './password';
import stripe from './stripe';
import integration from './integration';
import integrationAuth from './integrationAuth';
+import log from './log';
export {
signup,
@@ -31,5 +32,6 @@ export {
password,
stripe,
integration,
- integrationAuth
+ integrationAuth,
+ log
};
diff --git a/backend/src/routes/log.ts b/backend/src/routes/log.ts
new file mode 100644
index 0000000000..43d91d7acf
--- /dev/null
+++ b/backend/src/routes/log.ts
@@ -0,0 +1,17 @@
+import express from 'express';
+const router = express.Router();
+import {
+ requireAuth,
+ validateRequest
+} from '../middleware';
+import { logController } from '../controllers';
+
+// TODO: workspaceId validation
+router.get(
+ '/:workspaceId',
+ requireAuth,
+ validateRequest,
+ logController.getLogs
+);
+
+export default router;
\ No newline at end of file