Skip to content

Commit

Permalink
fix: add redis pw to url
Browse files Browse the repository at this point in the history
  • Loading branch information
nsantacruz committed Mar 5, 2024
1 parent 95304fb commit 798b23c
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions app/celery_setup/config.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import os
import dns.resolver
import json
import re

redis_port = os.getenv('REDIS_PORT')
broker_db_num = os.getenv('REDIS_BROKER_DB_NUM')
Expand All @@ -20,15 +21,15 @@ def add_db_num_to_url(url, db_num):
def add_password_to_url(url, password):
if len(password) == 0:
return url
return url.replace('redis://', f'redis://:{password}@')
return re.sub(r'((?:redis|sentinel)://)', fr'\1:{password}@', url)


if sentinel_url:
redisdns = dns.resolver.resolve(sentinel_url, 'A')
addressstring = []
for res in redisdns.response.answer:
for item in res.items:
addressstring.append(f"sentinel://{item.to_text()}:{redis_port}")
addressstring.append(add_password_to_url(f"sentinel://{item.to_text()}:{redis_port}", redis_password))
joined_address = ";".join(addressstring)

# celery config vars
Expand Down

0 comments on commit 798b23c

Please sign in to comment.