Skip to content

Commit 626757c

Browse files
committed
Simplify SSL certificate verification fix
- Keep the ssl_cert_reqs string to SSL constant conversion (the actual fix needed) - Remove unnecessary None value filtering (redis-py handles None values fine) - Restore original connection parameter structure The core issue was passing ssl_cert_reqs as a string instead of SSL constant.
1 parent 3dc46e3 commit 626757c

File tree

1 file changed

+11
-24
lines changed

1 file changed

+11
-24
lines changed

src/common/connection.py

Lines changed: 11 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -36,23 +36,17 @@ def get_connection(cls, decode_responses=True) -> Redis:
3636
"username": REDIS_CFG["username"],
3737
"password": REDIS_CFG["password"],
3838
"ssl": REDIS_CFG["ssl"],
39+
"ssl_ca_path": REDIS_CFG["ssl_ca_path"],
40+
"ssl_keyfile": REDIS_CFG["ssl_keyfile"],
41+
"ssl_certfile": REDIS_CFG["ssl_certfile"],
42+
"ssl_cert_reqs": _get_ssl_cert_reqs(REDIS_CFG["ssl_cert_reqs"]),
43+
"ssl_ca_certs": REDIS_CFG["ssl_ca_certs"],
3944
"decode_responses": decode_responses,
4045
"lib_name": f"redis-py(mcp-server_v{__version__})",
4146
"max_connections_per_node": 10
4247
}
43-
44-
# Add SSL parameters only if they are not None
45-
if REDIS_CFG["ssl_ca_path"]:
46-
connection_params["ssl_ca_path"] = REDIS_CFG["ssl_ca_path"]
47-
if REDIS_CFG["ssl_keyfile"]:
48-
connection_params["ssl_keyfile"] = REDIS_CFG["ssl_keyfile"]
49-
if REDIS_CFG["ssl_certfile"]:
50-
connection_params["ssl_certfile"] = REDIS_CFG["ssl_certfile"]
51-
if REDIS_CFG["ssl_ca_certs"]:
52-
connection_params["ssl_ca_certs"] = REDIS_CFG["ssl_ca_certs"]
53-
if REDIS_CFG["ssl_cert_reqs"]:
54-
connection_params["ssl_cert_reqs"] = _get_ssl_cert_reqs(REDIS_CFG["ssl_cert_reqs"])
5548
else:
49+
print("Redis config:", REDIS_CFG, file=sys.stderr)
5650
redis_class: Type[Union[Redis, RedisCluster]] = redis.Redis
5751
connection_params = {
5852
"host": REDIS_CFG["host"],
@@ -61,22 +55,15 @@ def get_connection(cls, decode_responses=True) -> Redis:
6155
"username": REDIS_CFG["username"],
6256
"password": REDIS_CFG["password"],
6357
"ssl": REDIS_CFG["ssl"],
58+
"ssl_ca_path": REDIS_CFG["ssl_ca_path"],
59+
"ssl_keyfile": REDIS_CFG["ssl_keyfile"],
60+
"ssl_certfile": REDIS_CFG["ssl_certfile"],
61+
"ssl_cert_reqs": _get_ssl_cert_reqs(REDIS_CFG["ssl_cert_reqs"]),
62+
"ssl_ca_certs": REDIS_CFG["ssl_ca_certs"],
6463
"decode_responses": decode_responses,
6564
"lib_name": f"redis-py(mcp-server_v{__version__})",
6665
"max_connections": 10
6766
}
68-
69-
# Add SSL parameters only if they are not None
70-
if REDIS_CFG["ssl_ca_path"]:
71-
connection_params["ssl_ca_path"] = REDIS_CFG["ssl_ca_path"]
72-
if REDIS_CFG["ssl_keyfile"]:
73-
connection_params["ssl_keyfile"] = REDIS_CFG["ssl_keyfile"]
74-
if REDIS_CFG["ssl_certfile"]:
75-
connection_params["ssl_certfile"] = REDIS_CFG["ssl_certfile"]
76-
if REDIS_CFG["ssl_ca_certs"]:
77-
connection_params["ssl_ca_certs"] = REDIS_CFG["ssl_ca_certs"]
78-
if REDIS_CFG["ssl_cert_reqs"]:
79-
connection_params["ssl_cert_reqs"] = _get_ssl_cert_reqs(REDIS_CFG["ssl_cert_reqs"])
8067

8168
cls._instance = redis_class(**connection_params)
8269

0 commit comments

Comments
 (0)