From e9ecdb082193c0af11963092f88d48c938de09bd Mon Sep 17 00:00:00 2001 From: Everardo J Barojas M Date: Thu, 17 Oct 2024 00:08:12 -0600 Subject: [PATCH 1/2] Enable TLS rediss connections and deal with non-tls connections as well --- rexchain/rexchain/settings.py | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/rexchain/rexchain/settings.py b/rexchain/rexchain/settings.py index 107cd98..2ac0591 100644 --- a/rexchain/rexchain/settings.py +++ b/rexchain/rexchain/settings.py @@ -3,10 +3,13 @@ import ast import dj_database_url +# To parse REDIS_URL +from urllib.parse import urlparse + """ Django settings for RexChain project. -Generated by 'django-admin startproject' using Django 1.11.3. +Generated by 'django-admin startproject' using Django 1.11.3. (oldddddd) """ @@ -193,20 +196,32 @@ # Fixtures DIR for testings FIXTURE_DIRS = [os.path.join(BASE_DIR, 'fixtures')] +# Define REDIS_URL +REDIS_URL = os.getenv("REDIS_URL", 'redis://localhost:6379/0') # Redis Cache CACHES = { "default": { "BACKEND": "django_redis.cache.RedisCache", - "LOCATION": os.getenv('REDIS_TEMPORARY_URL', 'redis://localhost:6379/0'), + "LOCATION": REDIS_URL # os.getenv('REDIS_TEMPORARY_URL', 'redis://localhost:6379/0'), "OPTIONS": { "CLIENT_CLASS": "django_redis.client.DefaultClient", "CONNECTION_POOL_KWARGS": { # config for pool connections - "max_connections": 10 + "max_connections": 10 # Note, we should review this. } } } } + +# Parsing URL in order to single out TSL connections +parsed_url = urlparse(REDIS_URL) + +# Append SSL/TLS configuration if using rediss:// (TLS) +if parsed_url.scheme == 'rediss': + CACHES['default']['OPTIONS']['CONNECTION_POOL_KWARGS'].update({ + 'ssl_cert_reqs': None # or ssl.CERT_REQUIRED with proper CA certs + }) + # Redis Config RQ_QUEUES = { 'default': { From 2defbf28b9a0ac22426e23ba2fae4a33c0d4a880 Mon Sep 17 00:00:00 2001 From: Everardo J Barojas M Date: Thu, 17 Oct 2024 00:11:13 -0600 Subject: [PATCH 2/2] Fix syntax --- rexchain/rexchain/settings.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rexchain/rexchain/settings.py b/rexchain/rexchain/settings.py index 2ac0591..3a82a50 100644 --- a/rexchain/rexchain/settings.py +++ b/rexchain/rexchain/settings.py @@ -202,7 +202,7 @@ CACHES = { "default": { "BACKEND": "django_redis.cache.RedisCache", - "LOCATION": REDIS_URL # os.getenv('REDIS_TEMPORARY_URL', 'redis://localhost:6379/0'), + "LOCATION": REDIS_URL, "OPTIONS": { "CLIENT_CLASS": "django_redis.client.DefaultClient", "CONNECTION_POOL_KWARGS": {