This is an automated email from the ASF dual-hosted git repository.

husseinawala pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/airflow.git


The following commit(s) were added to refs/heads/main by this push:
     new 66f9b385f5 Add username authenticating to the Redis hook (#36562)
66f9b385f5 is described below

commit 66f9b385f5a0d135ce5ec821103c761693874c74
Author: shohamy7 <[email protected]>
AuthorDate: Thu Jan 4 00:57:34 2024 +0200

    Add username authenticating to the Redis hook (#36562)
---
 airflow/providers/redis/hooks/redis.py    | 11 ++++++++++-
 tests/providers/redis/hooks/test_redis.py |  2 ++
 2 files changed, 12 insertions(+), 1 deletion(-)

diff --git a/airflow/providers/redis/hooks/redis.py 
b/airflow/providers/redis/hooks/redis.py
index 167d0d83cd..c149071ac4 100644
--- a/airflow/providers/redis/hooks/redis.py
+++ b/airflow/providers/redis/hooks/redis.py
@@ -49,6 +49,7 @@ class RedisHook(BaseHook):
         self.redis = None
         self.host = None
         self.port = None
+        self.username = None
         self.password = None
         self.db = None
 
@@ -57,6 +58,7 @@ class RedisHook(BaseHook):
         conn = self.get_connection(self.redis_conn_id)
         self.host = conn.host
         self.port = conn.port
+        self.username = conn.login
         self.password = None if str(conn.password).lower() in ["none", 
"false", ""] else conn.password
         self.db = conn.extra_dejson.get("db")
 
@@ -79,6 +81,13 @@ class RedisHook(BaseHook):
                 self.port,
                 self.db,
             )
-            self.redis = Redis(host=self.host, port=self.port, 
password=self.password, db=self.db, **ssl_args)
+            self.redis = Redis(
+                host=self.host,
+                port=self.port,
+                username=self.username,
+                password=self.password,
+                db=self.db,
+                **ssl_args,
+            )
 
         return self.redis
diff --git a/tests/providers/redis/hooks/test_redis.py 
b/tests/providers/redis/hooks/test_redis.py
index a9491d5f9d..daab3daddb 100644
--- a/tests/providers/redis/hooks/test_redis.py
+++ b/tests/providers/redis/hooks/test_redis.py
@@ -42,6 +42,7 @@ class TestRedisHook:
     @mock.patch(
         "airflow.providers.redis.hooks.redis.RedisHook.get_connection",
         return_value=Connection(
+            login="user",
             password="password",
             host="remote_host",
             port=1234,
@@ -63,6 +64,7 @@ class TestRedisHook:
         hook.get_conn()
         mock_redis.assert_called_once_with(
             host=connection.host,
+            username=connection.login,
             password=connection.password,
             port=connection.port,
             db=connection.extra_dejson["db"],

Reply via email to