Commit
·
01785f3
1
Parent(s):
ee5adc7
- rabbit_base.py +11 -11
rabbit_base.py
CHANGED
|
@@ -8,10 +8,6 @@ ExchangeResolver = Callable[[str], str] # exchangeName -> exchangeType
|
|
| 8 |
|
| 9 |
|
| 10 |
def _parse_amqp_url(url: str) -> dict:
|
| 11 |
-
"""
|
| 12 |
-
Convert an AMQP URL into kwargs for aio_pika.connect_robust,
|
| 13 |
-
so we don't pass the raw URL (and leak the password in logs).
|
| 14 |
-
"""
|
| 15 |
parts = urlsplit(url)
|
| 16 |
return {
|
| 17 |
"host": parts.hostname or "localhost",
|
|
@@ -19,7 +15,7 @@ def _parse_amqp_url(url: str) -> dict:
|
|
| 19 |
"login": parts.username or "guest",
|
| 20 |
"password": parts.password or "guest",
|
| 21 |
"virtualhost": unquote(parts.path[1:] or "/"),
|
| 22 |
-
"ssl": parts.scheme == "amqps",
|
| 23 |
}
|
| 24 |
|
| 25 |
|
|
@@ -38,14 +34,18 @@ class RabbitBase:
|
|
| 38 |
|
| 39 |
conn_kwargs = _parse_amqp_url(str(settings.AMQP_URL))
|
| 40 |
|
| 41 |
-
#
|
|
|
|
| 42 |
if conn_kwargs.get("ssl"):
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
conn_kwargs["ssl"] = ctx # <-- pass the context here, not via ssl_options
|
| 47 |
|
| 48 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 49 |
self._chan = await self._conn.channel()
|
| 50 |
await self._chan.set_qos(prefetch_count=settings.RABBIT_PREFETCH)
|
| 51 |
|
|
|
|
| 8 |
|
| 9 |
|
| 10 |
def _parse_amqp_url(url: str) -> dict:
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
parts = urlsplit(url)
|
| 12 |
return {
|
| 13 |
"host": parts.hostname or "localhost",
|
|
|
|
| 15 |
"login": parts.username or "guest",
|
| 16 |
"password": parts.password or "guest",
|
| 17 |
"virtualhost": unquote(parts.path[1:] or "/"),
|
| 18 |
+
"ssl": parts.scheme == "amqps",
|
| 19 |
}
|
| 20 |
|
| 21 |
|
|
|
|
| 34 |
|
| 35 |
conn_kwargs = _parse_amqp_url(str(settings.AMQP_URL))
|
| 36 |
|
| 37 |
+
# Build an SSLContext that DISABLES verification
|
| 38 |
+
ssl_ctx = None
|
| 39 |
if conn_kwargs.get("ssl"):
|
| 40 |
+
ssl_ctx = ssl.create_default_context()
|
| 41 |
+
ssl_ctx.check_hostname = False
|
| 42 |
+
ssl_ctx.verify_mode = ssl.CERT_NONE
|
|
|
|
| 43 |
|
| 44 |
+
# Pass ssl_context explicitly – this is what aio-pika supports
|
| 45 |
+
self._conn = await aio_pika.connect_robust(
|
| 46 |
+
**conn_kwargs,
|
| 47 |
+
ssl_context=ssl_ctx # <- key bit
|
| 48 |
+
)
|
| 49 |
self._chan = await self._conn.channel()
|
| 50 |
await self._chan.set_qos(prefetch_count=settings.RABBIT_PREFETCH)
|
| 51 |
|