mirror of
https://github.com/Infisical/infisical.git
synced 2025-03-25 14:05:03 +00:00
Initial schema ideas for logging
This commit is contained in:
@ -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
|
||||
};
|
||||
|
30
backend/src/controllers/logController.ts
Normal file
30
backend/src/controllers/logController.ts
Normal file
@ -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
|
||||
});
|
||||
}
|
@ -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);
|
||||
|
||||
|
@ -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
|
||||
};
|
||||
|
46
backend/src/models/log.ts
Normal file
46
backend/src/models/log.ts
Normal file
@ -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;
|
@ -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
|
||||
};
|
||||
|
17
backend/src/routes/log.ts
Normal file
17
backend/src/routes/log.ts
Normal file
@ -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;
|
Reference in New Issue
Block a user