eventlog: always use AuditSource objects as source field
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
|
||||
class AuditSource {
|
||||
constructor(username, userId, ip) {
|
||||
this.username = username;
|
||||
this.username = username || null; // this can be a real user or a module like cron/apptask/platform
|
||||
this.userId = userId || null;
|
||||
this.ip = ip || null;
|
||||
}
|
||||
@@ -11,14 +11,26 @@ class AuditSource {
|
||||
const ip = req.headers['x-forwarded-for'] || req.connection.remoteAddress || null;
|
||||
return new AuditSource(req.user?.username, req.user?.id, ip);
|
||||
}
|
||||
|
||||
static fromDirectoryServerRequest(req) {
|
||||
const ip = req.connection.ldap.id; // also contains the port
|
||||
return new AuditSource('directoryserver', null, ip);
|
||||
}
|
||||
|
||||
static fromOidcRequest(req) {
|
||||
const ip = req.headers['x-forwarded-for'] || req.connection.remoteAddress || null;
|
||||
return new AuditSource('oidc', req.body?.username, ip);
|
||||
}
|
||||
}
|
||||
|
||||
// these can be static variables but see https://stackoverflow.com/questions/60046847/eslint-does-not-allow-static-class-properties#comment122122927_60464446
|
||||
AuditSource.APPTASK = new AuditSource('apptask');
|
||||
AuditSource.BOOT = new AuditSource('boot');
|
||||
AuditSource.CRON = new AuditSource('cron');
|
||||
AuditSource.EXTERNAL_LDAP_TASK = new AuditSource('externalldap');
|
||||
AuditSource.EXTERNAL_LDAP_AUTO_CREATE = new AuditSource('externalldap');
|
||||
AuditSource.EXTERNAL_LDAP = new AuditSource('externalldap');
|
||||
AuditSource.HEALTH_MONITOR = new AuditSource('healthmonitor');
|
||||
AuditSource.LDAP = new AuditSource('ldap');
|
||||
AuditSource.MAIL = new AuditSource('mail');
|
||||
AuditSource.PLATFORM = new AuditSource('platform');
|
||||
|
||||
exports = module.exports = AuditSource;
|
||||
|
||||
Reference in New Issue
Block a user