From d8040d3d0c8b4be279bd2c1f07bd8cdd8196dd1e Mon Sep 17 00:00:00 2001 From: FORESTIER Fabien <fabien.forestier@soprasteria.com> Date: Wed, 27 Feb 2019 16:24:22 +0100 Subject: [PATCH] Add log in groups middleware --- src/guards/groups.guards.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/guards/groups.guards.ts b/src/guards/groups.guards.ts index 3b9ae9d..7028262 100644 --- a/src/guards/groups.guards.ts +++ b/src/guards/groups.guards.ts @@ -1,4 +1,4 @@ -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(); -- GitLab