Skip to content
Snippets Groups Projects
Commit d8040d3d authored by FORESTIER Fabien's avatar FORESTIER Fabien
Browse files

Add log in groups middleware

parent eeff7d3f
No related branches found
No related tags found
No related merge requests found
Pipeline #
import { Injectable, CanActivate, ExecutionContext } from '@nestjs/common';
import { Injectable, CanActivate, ExecutionContext, Logger } from '@nestjs/common';
import { Reflector } from '@nestjs/core';
import { ConfigService } from '../configuration/config.service';
......@@ -7,6 +7,7 @@ export class GroupsGuard implements CanActivate {
constructor(private readonly reflector: Reflector, private configService: ConfigService) {}
canActivate(context: ExecutionContext): boolean {
Logger.log('[+] GroupMiddleware');
// We get the groups specified on the endpoint with the @Groups annotation
// We need then to get the real group names associated to those keys from the config file
const groups = this.reflector.get<string[]>('groups', context.getHandler()).map((e) => {
......@@ -23,10 +24,14 @@ export class GroupsGuard implements CanActivate {
const groupHeader = request.headers[this.configService.config.groupHeader];
if (!groupHeader) {
Logger.log(' [-] no group header');
return false;
}
const consumerGroups = groupHeader.split(',').map(e => e.trim());
Logger.log(` [-] consumer groups: ${consumerGroups}`);
const hasGroup = () => consumerGroups.some((group) => groups.includes(group));
return consumerGroups && hasGroup();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment