Add interceptor logic to websocket server
Problem
Once gitlab-org/duo-workflow/duo-workflow-service#361 (closed) is complete, we will need to add interceptor logic to the websocket server. All connections via websocket should still honor the interceptors laid out in the server.py file currently.
Desired Outcome
The server supports the following interceptors, and any other interceptors that the gRPC server supports.
CorrelationIdInterceptor(),
AuthenticationInterceptor(),
FeatureFlagInterceptor(),
InternalEventsInterceptor(),
MonitoringInterceptor(),
Implementation Plan
Implementation will probably need to happen something like:
- Adapt gRPC interceptors for Websocket use. Might be able to be done by creating a WebSocketInterceptorAdapter class to map websocket headers to equivalent grpc metadata format.
- Import existing interceptors from interceptors directory
- Create adapter implementations that reuse logic from existing interceptors:
- Extract header handling and context setup from existing interceptors
- Reuse authentication logic, feature flag parsing, event context creation, etc.
- Modify WebSocketServer class to: - Initialize with the adapted interceptors - Apply them during WebSocket lifecycle events
- Update websocket_serve() to use the same interceptor chain:
server = WebSocketServer(
interceptor_adapters=[
CorrelationIdInterceptorAdapter(),
AuthenticationInterceptorAdapter(),
FeatureFlagInterceptorAdapter(),
InternalEventsInterceptorAdapter(),
MonitoringInterceptorAdapter(),
]
)
await server.run(port)
Edited by Jeff Park