Skip to content

Commit c04db4a

Browse files
committed
Update CI/CD to VPC
1 parent 6039f16 commit c04db4a

File tree

1 file changed

+21
-5
lines changed

1 file changed

+21
-5
lines changed

app/services/celery/celery_config.py

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import logging
22
import os
33
from urllib.parse import quote_plus
4+
import re
45

56
# Set up logging
67
logging.basicConfig(level=logging.INFO)
@@ -42,14 +43,29 @@ def make_celery():
4243
redis_host = os.getenv('REDIS_HOST', 'localhost')
4344
redis_port = os.getenv('REDIS_PORT', '6379')
4445
redis_password = os.getenv('REDIS_PASSWORD')
45-
46+
4647
if redis_password:
47-
redis_password = quote_plus(redis_password)
48-
redis_url = f'redis://:{redis_password}@{redis_host}:{redis_port}/0'
48+
# Password exists, quote it and build URL
49+
quoted_password = quote_plus(redis_password)
50+
redis_url = f'redis://:{quoted_password}@{redis_host}:{redis_port}/0'
51+
# Log with masking using the original password
52+
logger.info(f"Configuring Celery with Redis URL: {redis_url.replace(redis_password, '***')}")
4953
else:
54+
# No password, build simple URL
5055
redis_url = f'redis://{redis_host}:{redis_port}/0'
51-
52-
logger.info(f"Configuring Celery with Redis URL: {redis_url.replace(redis_password if redis_password else '', '***')}")
56+
# Log without masking
57+
logger.info(f"Configuring Celery with Redis URL: {redis_url}")
58+
else:
59+
# REDIS_URL was provided, try to mask if password pattern is detected
60+
# Basic pattern matching for password in URL (adjust if needed)
61+
match = re.match(r"redis://:(?P<password>[^@]+)@", redis_url)
62+
if match:
63+
password_to_mask = match.group("password")
64+
masked_url = redis_url.replace(password_to_mask, "***")
65+
logger.info(f"Configuring Celery with Redis URL: {masked_url}")
66+
else:
67+
# Assume no password or couldn't detect it, log as is
68+
logger.info(f"Configuring Celery with Redis URL: {redis_url}")
5369

5470
celery = Celery(
5571
'worker',

0 commit comments

Comments
 (0)