refactor(lightspeed): add middleware for resolving user identity#3227
Conversation
Code Review by Qodo
1.
|
Changed Packages
|
Review Summary by QodoRefactor user identity resolution into reusable middleware
WalkthroughsDescription• Centralizes user identity resolution via middleware to eliminate code duplication • Extends Express Request type with credentials and userEntityRef fields • Implements identity middleware in both lightspeed and notebooks routers • Adds comprehensive tests for middleware, permission denial, and identity deduplication Diagramflowchart LR
A["Express Request"] -->|"createIdentityMiddleware"| B["Resolve Credentials & UserEntityRef"]
B -->|"Attach to req"| C["Request with Identity"]
C -->|"getIdentity"| D["Extract & Validate Identity"]
D -->|"Return typed object"| E["Route Handlers"]
E -->|"Use credentials & userEntityRef"| F["Authorization & Operations"]
File Changes1. workspaces/lightspeed/plugins/lightspeed-backend/src/service/express.d.ts
|
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #3227 +/- ##
==========================================
+ Coverage 53.61% 53.62% +0.01%
==========================================
Files 2408 2409 +1
Lines 86622 86633 +11
Branches 24010 24012 +2
==========================================
+ Hits 46439 46456 +17
+ Misses 38683 38677 -6
Partials 1500 1500
*This pull request uses carry forward flags. Click here to find out more. Continue to review full report in Codecov by Sentry.
🚀 New features to boost your workflow:
|
231d37a to
e5744e4
Compare
ede49bf to
c2c8bed
Compare
| req.userEntityRef = user.userEntityRef; | ||
| return next(); | ||
| } catch (error) { | ||
| logger.error('Identity resolution failed for request'); |
There was a problem hiding this comment.
the actual error object is not logged here. do we want to log the error?
logger.error('Identity resolution failed for request', { error });
There was a problem hiding this comment.
I've added the logging of the error in 7fa3d14
| if (error instanceof NotAllowedError) { | ||
| return res.status(403).json({ error: 'Forbidden' }); | ||
| } | ||
| return res.status(401).json({ error: 'Unauthorized' }); |
There was a problem hiding this comment.
getting credentials/identity only have 401/403 errors?
what if internal errors?
There was a problem hiding this comment.
Good catch, I updated the handling to check explicitly for 401/403, then log as a server error for the rest that are unexpected in 7fa3d14
yangcao77
left a comment
There was a problem hiding this comment.
generally looks good to me. just some minor comments on error handling
Signed-off-by: Jordan Dubrick <jdubrick@redhat.com>
Signed-off-by: Jordan Dubrick <jdubrick@redhat.com>
Signed-off-by: Jordan Dubrick <jdubrick@redhat.com>
…ebooks Signed-off-by: Jordan Dubrick <jdubrick@redhat.com>
Signed-off-by: Jordan Dubrick <jdubrick@redhat.com>
Signed-off-by: Jordan Dubrick <jdubrick@redhat.com>
Signed-off-by: Jordan Dubrick <jdubrick@redhat.com>
c2c8bed to
7fa3d14
Compare
|



Hey, I just made a Pull Request!
Moves the resolution of the user identity to a middleware step, this reduces a lot of the duplicated resolving code and makes it easier to extend for tasks in 2.1.0. This adds the user identity to the individual request by extending the Express Request type, so it is easy to reference.
✔️ Checklist