mirror of
https://github.com/Unleash/unleash.git
synced 2025-01-31 00:16:47 +01:00
cf2bd28ff6
I've tried to use/add the audit info to all events I could see/find. This makes this PR necessarily huge, because we do store quite a few events. I realise it might not be complete yet, but tests run green, and I think we now have a pattern to follow for other events.
22 lines
701 B
TypeScript
22 lines
701 B
TypeScript
import type { IUnleashConfig } from '../types';
|
|
import type { IApiRequest, IAuthRequest } from '../routes/unleash-types';
|
|
import { extractAuditInfo } from '../util';
|
|
|
|
export const auditAccessMiddleware = ({
|
|
getLogger,
|
|
}: Pick<IUnleashConfig, 'getLogger'>): any => {
|
|
const logger = getLogger('/middleware/audit-middleware.ts');
|
|
return (req: IAuthRequest | IApiRequest, _res, next) => {
|
|
if (!req.user) {
|
|
logger.info('Could not find user');
|
|
} else {
|
|
try {
|
|
req.audit = extractAuditInfo(req);
|
|
} catch (e) {
|
|
logger.warn('Could not find audit info in request');
|
|
}
|
|
}
|
|
next();
|
|
};
|
|
};
|