3
0
Fork 0
mirror of https://github.com/ZeppelinBot/Zeppelin.git synced 2025-05-10 12:25:02 +00:00

Start work on API audit logs

This commit is contained in:
Dragory 2021-09-05 13:58:08 +03:00
parent 947a49761e
commit ff648e7071
No known key found for this signature in database
GPG key ID: 5F387BA66DF8AAC1
4 changed files with 146 additions and 0 deletions

View file

@ -0,0 +1,28 @@
import { BaseRepository } from "./BaseRepository";
import { getRepository, Repository } from "typeorm/index";
import { ApiAuditLogEntry } from "./entities/ApiAuditLogEntry";
import { ApiLogin } from "./entities/ApiLogin";
import { AuditLogEventData, AuditLogEventType } from "./apiAuditLogTypes";
export class ApiAuditLog extends BaseRepository {
private auditLog: Repository<ApiAuditLogEntry<any>>;
constructor() {
super();
this.auditLog = getRepository(ApiAuditLogEntry);
}
addEntry<TEventType extends AuditLogEventType>(
guildId: string,
authorId: string,
eventType: TEventType,
eventData: AuditLogEventData[TEventType],
) {
this.auditLog.insert({
guild_id: guildId,
author_id: authorId,
event_type: eventType as any,
event_data: eventData as any,
});
}
}

View file

@ -0,0 +1,35 @@
export const AuditLogEventTypes = {
ADD_API_PERMISSION: "ADD_API_PERMISSION",
REMOVE_API_PERMISSION: "REMOVE_API_PERMISSION",
EDIT_CONFIG: "EDIT_CONFIG",
};
export type AuditLogEventType = keyof typeof AuditLogEventTypes;
export type AddApiPermissionEventData = {
target_id: string;
permissions: string[];
expires_at: string | null;
};
export type RemoveApiPermissionEventData = {
target_id: string;
};
export type EditConfigEventData = {};
export interface AuditLogEventData extends Record<AuditLogEventType, unknown> {
ADD_API_PERMISSION: {
target_id: string;
permissions: string[];
expires_at: string | null;
};
REMOVE_API_PERMISSION: {
target_id: string;
};
EDIT_CONFIG: {};
}
export type AnyAuditLogEventData = AuditLogEventData[AuditLogEventType];

View file

@ -0,0 +1,25 @@
import { Column, Entity, JoinColumn, ManyToOne, PrimaryColumn } from "typeorm";
import { ApiUserInfo } from "./ApiUserInfo";
import { AuditLogEventData, AuditLogEventType } from "../apiAuditLogTypes";
@Entity("api_audit_log")
export class ApiAuditLogEntry<TEventType extends AuditLogEventType> {
@Column()
@PrimaryColumn()
id: number;
@Column()
guild_id: string;
@Column()
author_id: string;
@Column()
event_type: TEventType;
@Column("simple-json")
event_data: AuditLogEventData[TEventType];
@Column()
created_at: string;
}