-
Notifications
You must be signed in to change notification settings - Fork 988
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c12eeac
commit 2e84b7e
Showing
7 changed files
with
106 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; |