mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-08 08:27:53 +00:00
Continue developing activity logs backend
This commit is contained in:
@@ -1,4 +1,7 @@
|
|||||||
import { EVENT_PUSH_SECRETS } from '../variables';
|
import {
|
||||||
|
EVENT_PUSH_SECRETS,
|
||||||
|
EVENT_PULL_SECRETS
|
||||||
|
} from '../variables';
|
||||||
|
|
||||||
interface PushSecret {
|
interface PushSecret {
|
||||||
ciphertextKey: string;
|
ciphertextKey: string;
|
||||||
@@ -19,7 +22,7 @@ interface PushSecret {
|
|||||||
* @returns
|
* @returns
|
||||||
*/
|
*/
|
||||||
const eventPushSecrets = ({
|
const eventPushSecrets = ({
|
||||||
workspaceId,
|
workspaceId
|
||||||
}: {
|
}: {
|
||||||
workspaceId: string;
|
workspaceId: string;
|
||||||
}) => {
|
}) => {
|
||||||
@@ -32,6 +35,26 @@ const eventPushSecrets = ({
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return event for pulling secrets
|
||||||
|
* @param {Object} obj
|
||||||
|
* @param {String} obj.workspaceId - id of workspace to pull secrets from
|
||||||
|
* @returns
|
||||||
|
*/
|
||||||
|
const eventPullSecrets = ({
|
||||||
|
workspaceId,
|
||||||
|
}: {
|
||||||
|
workspaceId: string;
|
||||||
|
}) => {
|
||||||
|
return ({
|
||||||
|
name: EVENT_PULL_SECRETS,
|
||||||
|
workspaceId,
|
||||||
|
payload: {
|
||||||
|
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
export {
|
export {
|
||||||
eventPushSecrets
|
eventPushSecrets
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,25 @@
|
|||||||
|
import { Log, ILog } from '../models';
|
||||||
|
import * as Sentry from '@sentry/node';
|
||||||
|
import {
|
||||||
|
EVENT_PUSH_SECRETS,
|
||||||
|
EVENT_PULL_SECRETS
|
||||||
|
} from '../variables';
|
||||||
|
|
||||||
|
|
||||||
|
const handleLogHelper = async ({
|
||||||
|
log
|
||||||
|
}: {
|
||||||
|
log: ILog
|
||||||
|
}) => {
|
||||||
|
try {
|
||||||
|
switch (log.event) {
|
||||||
|
case EVENT_PULL_SECRETS:
|
||||||
|
// TODO
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (err){
|
||||||
|
Sentry.setUser(null);
|
||||||
|
Sentry.captureException(err);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -5,6 +5,7 @@ export interface ILog {
|
|||||||
user?: Types.ObjectId;
|
user?: Types.ObjectId;
|
||||||
workspace: Types.ObjectId;
|
workspace: Types.ObjectId;
|
||||||
event: string;
|
event: string;
|
||||||
|
groupId: string;
|
||||||
payload: {
|
payload: {
|
||||||
numberofSecrets?: number;
|
numberofSecrets?: number;
|
||||||
environment?: string;
|
environment?: string;
|
||||||
@@ -13,6 +14,52 @@ export interface ILog {
|
|||||||
ipAddress?: string;
|
ipAddress?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// log group consists of logs (each log is associated with 1 event)
|
||||||
|
// scenario:
|
||||||
|
|
||||||
|
// do we in the future record old and new values for secrets? (when you log update secret,
|
||||||
|
// do you want to know what the old secret value was changed to?)
|
||||||
|
|
||||||
|
// Option 1:
|
||||||
|
|
||||||
|
// action 1: pushed secrets (top-level event)
|
||||||
|
// - log 1 (groupId: ABC): modified 10 secrets (sub-level event)
|
||||||
|
// ---- array of secret ids that were modified
|
||||||
|
// - log 2 (groupId: ABC): deleted 5 secrets
|
||||||
|
// ---- array of secret ids that were deleted
|
||||||
|
// - log 3 (groupId: ABC): created 10 secrets
|
||||||
|
// ---- array of secret ids that were created
|
||||||
|
|
||||||
|
// action 2: pull secrets
|
||||||
|
// - log 4 (groupId: DEF): read 20 secrets
|
||||||
|
// ---- array of secret ids that were read
|
||||||
|
|
||||||
|
// Option 2 (many logs):
|
||||||
|
|
||||||
|
// action 1: pushed secrets (top-level event)
|
||||||
|
// - log 1 (groupId: ABC): modified secret abc
|
||||||
|
// - log 2 (groupId: ABC): modified secret def
|
||||||
|
// - log 3 (groupId: ABC): modified secret ghi
|
||||||
|
// - log 4 (groupId: ABC): created secret jkl
|
||||||
|
// - log 5 (groupId: ABC): created secret mno
|
||||||
|
// - log 6 (groupId: ABC): deleted secret pqr
|
||||||
|
|
||||||
|
// action 2: pull secrets (pulling 100 secrets = 100 logs; 10 times per day, 5 people => 5000 logs)
|
||||||
|
// - log 7 (groupId: DEF): read secret abc
|
||||||
|
// - log 8 (groupId: DEF): read secret def
|
||||||
|
// - log 9 (groupId: DEF): read secret ghi
|
||||||
|
// - log 10 (groupId: DEF): read secret jkl
|
||||||
|
// - log 11 (groupId: DEF): read secret mno
|
||||||
|
|
||||||
|
// logGroup
|
||||||
|
// ---- log (query for log groups by person and by secret etc.)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Action: save secrets
|
||||||
|
* -
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
const logSchema = new Schema<ILog>(
|
const logSchema = new Schema<ILog>(
|
||||||
{
|
{
|
||||||
user: {
|
user: {
|
||||||
@@ -23,17 +70,19 @@ const logSchema = new Schema<ILog>(
|
|||||||
type: Schema.Types.ObjectId,
|
type: Schema.Types.ObjectId,
|
||||||
ref: 'Workspace'
|
ref: 'Workspace'
|
||||||
},
|
},
|
||||||
event: { // push, pull
|
event: { // CRUD secrets
|
||||||
type: String,
|
type: String,
|
||||||
required: true
|
required: true
|
||||||
},
|
},
|
||||||
|
groupId: {
|
||||||
|
type: String,
|
||||||
|
required: true,
|
||||||
|
},
|
||||||
payload: {
|
payload: {
|
||||||
numberOfSecrets: {
|
secrets: [{
|
||||||
type: Number
|
type: Schema.Types.ObjectId,
|
||||||
},
|
ref: 'Secret'
|
||||||
environment: {
|
}]
|
||||||
type: String
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
channel: {
|
channel: {
|
||||||
type: String,
|
type: String,
|
||||||
|
|||||||
@@ -0,0 +1,25 @@
|
|||||||
|
import { Schema, model, Types } from 'mongoose';
|
||||||
|
|
||||||
|
export interface ILogGroup {
|
||||||
|
workspace: Types.ObjectId,
|
||||||
|
logs: [Types.ObjectId]
|
||||||
|
}
|
||||||
|
|
||||||
|
const logGroupSchema = new Schema<ILogGroup>(
|
||||||
|
{
|
||||||
|
workspace: {
|
||||||
|
type: Schema.Types.ObjectId,
|
||||||
|
ref: 'Workspace'
|
||||||
|
},
|
||||||
|
logs: [{
|
||||||
|
type: Schema.Types.ObjectId,
|
||||||
|
ref: 'Log'
|
||||||
|
}]
|
||||||
|
}, {
|
||||||
|
timestamps: true
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
const LogGroup = model<ILogGroup>('LogGroup', logGroupSchema);
|
||||||
|
|
||||||
|
export default LogGroup;
|
||||||
Reference in New Issue
Block a user