From 12e4032ef916eeb8a54a21b9f80c5bd080c5e798 Mon Sep 17 00:00:00 2001 From: Clint Banzhaf Date: Sun, 1 Sep 2024 11:24:07 +0200 Subject: [PATCH] add ssl support for redis with sentinel (#1327) * add tls support for redis when using sentinel+redis * fix non ssl case --- flower/utils/broker.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/flower/utils/broker.py b/flower/utils/broker.py index 51255c4a..7b0fe89e 100644 --- a/flower/utils/broker.py +++ b/flower/utils/broker.py @@ -159,11 +159,12 @@ class RedisSentinel(RedisBase): def __init__(self, broker_url, *args, **kwargs): super().__init__(broker_url, *args, **kwargs) broker_options = kwargs.get('broker_options', {}) + broker_use_ssl = kwargs.get('broker_use_ssl', None) self.host = self.host or 'localhost' self.port = self.port or 26379 self.vhost = self._prepare_virtual_host(self.vhost) self.master_name = self._prepare_master_name(broker_options) - self.redis = self._get_redis_client(broker_options) + self.redis = self._get_redis_client(broker_options, broker_use_ssl) def _prepare_virtual_host(self, vhost): if not isinstance(vhost, numbers.Integral): @@ -184,11 +185,14 @@ def _prepare_master_name(self, broker_options): raise ValueError('master_name is required for Sentinel broker') from exc return master_name - def _get_redis_client(self, broker_options): + def _get_redis_client(self, broker_options, broker_use_ssl): connection_kwargs = { 'password': self.password, 'sentinel_kwargs': broker_options.get('sentinel_kwargs') } + if isinstance(broker_use_ssl, dict): + connection_kwargs['ssl'] = True + connection_kwargs.update(broker_use_ssl) # get all sentinel hosts from Celery App config and use them to initialize Sentinel sentinel = redis.sentinel.Sentinel( [(self.host, self.port)], **connection_kwargs)