Skip to content

Commit 98b3d8c

Browse files
committed
Move ssl cert into websocket controller for collab
1 parent a7998e0 commit 98b3d8c

File tree

2 files changed

+18
-15
lines changed

2 files changed

+18
-15
lines changed

collaboration-svc/controllers/websocket_controller.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,21 @@
22
from utils.utils import get_envvar
33
from utils.logger import log
44
import websockets
5+
import ssl
56
from websockets.exceptions import ConnectionClosed
67
from websockets import ClientConnection
78

89
ENV_API_WEBSOCKET_URL = "GATEWAY_WEBSOCKET_URL"
910

1011

1112
class WebSocketManager:
12-
def __init__(self,ssl_context):
13+
def __init__(self):
1314
self.active_connection = None
15+
16+
# Create SSL context that verifies certificates properly
17+
ssl_context = ssl.create_default_context()
18+
ssl_context.check_hostname = False
19+
ssl_context.verify_mode = ssl.CERT_NONE
1420
self.ssl_context = ssl_context
1521

1622
def get_websocket_connection(self) -> ClientConnection:

collaboration-svc/routes.py

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import asyncio
2-
import ssl
2+
33
from contextlib import asynccontextmanager
44
from controllers.heartbeat_controller import (
55
INSTANCE_ID,
@@ -40,11 +40,8 @@ async def lifespan(app: FastAPI):
4040
"""
4141
app.state.event_queue_connection = connect_to_redis_event_queue()
4242
app.state.room_connection = await connect_to_redis_room_service()
43-
# Create SSL context that verifies certificates properly
44-
app.state.ssl_context = ssl.create_default_context()
45-
app.state.ssl_context.check_hostname = False
46-
app.state.ssl_context.verify_mode = ssl.CERT_NONE
47-
app.state.websocket_manager = WebSocketManager( app.state.ssl_context)
43+
44+
app.state.websocket_manager = WebSocketManager()
4845

4946
await app.state.websocket_manager.connect()
5047

@@ -141,8 +138,7 @@ async def terminate_user_match(
141138
return {"message": "match has been terminated"}
142139

143140

144-
145-
if get_envvar("ENVIRONMENT") =="DEV":
141+
if get_envvar("ENVIRONMENT") == "DEV":
146142
# --- Redis Debugging Endpoints
147143
@app.get("/print-all")
148144
async def print_all_from_redis_aioredis():
@@ -151,6 +147,7 @@ async def print_all_from_redis_aioredis():
151147
and returns them. Also prints them to the server console.
152148
"""
153149
result = {}
150+
154151
async def printall(r, result):
155152
async for key in r.scan_iter("*"):
156153
try:
@@ -162,10 +159,12 @@ async def printall(r, result):
162159
elif key_type == "hash":
163160
value = await r.hgetall(key)
164161
elif key_type == "list":
165-
value = await r.lrange(key, 0, -1) # Get all elements of the list
162+
value = await r.lrange(
163+
key, 0, -1
164+
) # Get all elements of the list
166165
print(" Value (list elements):")
167166
for item in value:
168-
print(f" - {item}") # Decode list items
167+
print(f" - {item}") # Decode list items
169168
else:
170169
value = f"<{key_type} type>"
171170
print(f" Value: {value}")
@@ -175,11 +174,12 @@ async def printall(r, result):
175174
except Exception as e:
176175
print(f"Error processing key {key}: {e}")
177176
result[key] = f"<error: {str(e)}>"
177+
178178
await printall(app.state.event_queue_connection, result)
179179
await printall(app.state.room_connection, result)
180180

181181
return result
182-
182+
183183
@app.delete("/flush-all")
184184
async def flush_all_redis():
185185
"""
@@ -192,6 +192,3 @@ async def flush_all_redis():
192192
return {"message": "All Redis databases have been flushed successfully"}
193193
except Exception as e:
194194
return {"error": f"Failed to flush Redis: {str(e)}"}
195-
196-
197-

0 commit comments

Comments
 (0)