-
Notifications
You must be signed in to change notification settings - Fork 306
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Be/feature/CR-28 #3314
Merged
nelsonwellsredis
merged 11 commits into
feature/dynamic-dependencies
from
be/feature/CR-28
May 30, 2024
Merged
Be/feature/CR-28 #3314
Changes from 5 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
4a7c5aa
CR-28: Add session metadata middleware for web sockets
nelsonwellsredis 2b1b043
CR-28: Add WSSessionMetadata decorator to all gateway methods...
nelsonwellsredis ba61d5c
CR-28: Remove hardcoded session metadata in pub-sub and bulk-actions …
nelsonwellsredis 98d2368
CR-28: Fix unit tests
nelsonwellsredis 25150b2
CR-28: Fix another unit test
nelsonwellsredis 7c74d07
CR-28: code review; move socket session metadata default values from …
nelsonwellsredis be403ec
CR-28: code review; fix integration test by adding missing @Connected…
nelsonwellsredis f71cc4e
CR-28: Add session metadata adapter to integration test harness
nelsonwellsredis 4ed033f
pass SessionMetadata to profiler
a765c6a
fix UTests
bc7bf6a
Merge pull request #3339 from RedisInsight/be/feature/CR-28-fix
nelsonwellsredis File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
redisinsight/api/src/modules/auth/session-metadata/adapters/session-metadata.adapter.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/* eslint-disable no-param-reassign */ | ||
import { INestApplication, Injectable, Logger } from '@nestjs/common'; | ||
import { IoAdapter } from '@nestjs/platform-socket.io'; | ||
import { MessageMappingProperties } from '@nestjs/websockets'; | ||
import { Observable } from 'rxjs'; | ||
import { Socket } from 'socket.io'; | ||
|
||
@Injectable() | ||
export class SessionMetadataAdapter extends IoAdapter { | ||
private logger = new Logger('SessionMetadataAdapter'); | ||
|
||
constructor(private app: INestApplication) { | ||
super(app); | ||
} | ||
|
||
async bindMessageHandlers( | ||
socket: Socket, | ||
handlers: MessageMappingProperties[], | ||
transform: (data: any) => Observable<any>, | ||
) { | ||
// TODO: [USER_CONTEXT] | ||
// Assuming that we'll figure out session data from a JWT token | ||
// but that is up to discovery later on | ||
// eslint-disable-next-line no-param-reassign | ||
const jwt = socket.handshake.headers.authorization?.split(' ')[1]; | ||
socket.data['jwt'] = jwt || null; | ||
|
||
super.bindMessageHandlers(socket, handlers, transform); | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
...insight/api/src/modules/auth/session-metadata/decorators/ws-session-metadata.decorator.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { ExecutionContext, createParamDecorator } from '@nestjs/common'; | ||
import { SessionMetadata } from 'src/common/models'; | ||
import { DEFAULT_SESSION_ID, DEFAULT_USER_ID } from 'src/common/constants'; | ||
|
||
export const WSSessionMetadata = createParamDecorator( | ||
(data: unknown, ctx: ExecutionContext): SessionMetadata => { | ||
const socket = ctx.switchToWs().getClient(); | ||
// TODO: [USER_CONTEXT] - decode the JWT and return a session metadata for the user | ||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
const { jwt } = socket.data; | ||
return { | ||
userId: DEFAULT_SESSION_ID, | ||
sessionId: DEFAULT_USER_ID, | ||
}; | ||
}, | ||
); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's get SessionMetadata from |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
redisinsight/api/src/modules/notification/notification.gateway.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We must calculate (basically hardcode) SessionMetadata here and put into
socket.data
For other builds we will have own Adapter with own custom logic (like validation or whatever is needed for any input) but as result of this adapter we must put SessionMetadata into
socket.data
field