eventlog: always use AuditSource objects as source field

This commit is contained in:
Girish Ramakrishnan
2023-08-26 08:18:58 +05:30
parent 246c45c1bc
commit d2c702f890
9 changed files with 34 additions and 19 deletions

View File

@@ -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;