Skip to content

Commit

Permalink
add ssl support for redis with sentinel (#1327)
Browse files Browse the repository at this point in the history
* add tls support for redis when using sentinel+redis

* fix non ssl case
  • Loading branch information
cyberjunk committed Sep 1, 2024
1 parent 652ce08 commit 12e4032
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions flower/utils/broker.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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)
Expand Down

0 comments on commit 12e4032

Please sign in to comment.