Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add ssl support for redis with sentinel #1327

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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