Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
mailer
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
web-et-numerique
web-et-numerique-internet
data.grandlyon.com
web-portal
components
services
mailer
Commits
d8040d3d
There was a problem fetching the pipeline summary.
Commit
d8040d3d
authored
6 years ago
by
FORESTIER Fabien
Browse files
Options
Downloads
Patches
Plain Diff
Add log in groups middleware
parent
eeff7d3f
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Pipeline
#
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/guards/groups.guards.ts
+6
-1
6 additions, 1 deletion
src/guards/groups.guards.ts
with
6 additions
and
1 deletion
src/guards/groups.guards.ts
+
6
−
1
View file @
d8040d3d
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
();
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment