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

potiuk 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 d6a1a522e7f Change directory used by simple auth manager to store 
generated passwords (#42860)
d6a1a522e7f is described below

commit d6a1a522e7f7e456dbfe3ff4d44ff26f99fd085a
Author: Vincent <97131062+vincb...@users.noreply.github.com>
AuthorDate: Sun Oct 13 18:06:59 2024 -0400

    Change directory used by simple auth manager to store generated passwords 
(#42860)
    
    * Change directory used by simple auth manager to store generated passwords
    
    * Update airflow/auth/managers/simple/simple_auth_manager.py
    
    Co-authored-by: Jens Scheffler <95105677+jsche...@users.noreply.github.com>
    
    ---------
    
    Co-authored-by: Jens Scheffler <95105677+jsche...@users.noreply.github.com>
---
 Dockerfile.ci                                        |  3 +++
 airflow/auth/managers/simple/simple_auth_manager.py  | 20 +++++++++++---------
 scripts/docker/entrypoint_ci.sh                      |  3 +++
 .../auth/managers/simple/test_simple_auth_manager.py |  4 ++--
 tests/auth/managers/simple/views/test_auth.py        |  2 +-
 5 files changed, 20 insertions(+), 12 deletions(-)

diff --git a/Dockerfile.ci b/Dockerfile.ci
index 464e33f147f..7e0ee74556f 100644
--- a/Dockerfile.ci
+++ b/Dockerfile.ci
@@ -914,6 +914,9 @@ function environment_initialization() {
     # Added to have run-tests on path
     export PATH=${PATH}:${AIRFLOW_SOURCES}
 
+    # Directory where simple auth manager store generated passwords
+    export AIRFLOW_AUTH_MANAGER_CREDENTIAL_DIRECTORY="/files"
+
     mkdir -pv "${AIRFLOW_HOME}/logs/"
 
     # Change the default worker_concurrency for tests
diff --git a/airflow/auth/managers/simple/simple_auth_manager.py 
b/airflow/auth/managers/simple/simple_auth_manager.py
index 4a9639a998c..78dccf7c2a9 100644
--- a/airflow/auth/managers/simple/simple_auth_manager.py
+++ b/airflow/auth/managers/simple/simple_auth_manager.py
@@ -30,7 +30,7 @@ from termcolor import colored
 from airflow.auth.managers.base_auth_manager import BaseAuthManager, 
ResourceMethod
 from airflow.auth.managers.simple.user import SimpleAuthManagerUser
 from airflow.auth.managers.simple.views.auth import 
SimpleAuthManagerAuthenticationViews
-from hatch_build import AIRFLOW_ROOT_PATH
+from airflow.configuration import AIRFLOW_HOME
 
 if TYPE_CHECKING:
     from airflow.auth.managers.models.base_user import BaseUser
@@ -78,20 +78,22 @@ class SimpleAuthManager(BaseAuthManager):
     :param appbuilder: the flask app builder
     """
 
-    # File that contains the generated passwords
-    GENERATED_PASSWORDS_FILE = (
-        AIRFLOW_ROOT_PATH / "generated" / 
"simple_auth_manager_passwords.json.generated"
-    )
-
     # Cache containing the password associated to a username
     passwords: dict[str, str] = {}
 
+    @staticmethod
+    def get_generated_password_file() -> str:
+        return os.path.join(
+            os.getenv("AIRFLOW_AUTH_MANAGER_CREDENTIAL_DIRECTORY", 
AIRFLOW_HOME),
+            "simple_auth_manager_passwords.json.generated",
+        )
+
     def init(self) -> None:
         user_passwords_from_file = {}
 
         # Read passwords from file
-        if os.path.isfile(self.GENERATED_PASSWORDS_FILE):
-            with open(self.GENERATED_PASSWORDS_FILE) as file:
+        if os.path.isfile(self.get_generated_password_file()):
+            with open(self.get_generated_password_file()) as file:
                 passwords_str = file.read().strip()
                 user_passwords_from_file = json.loads(passwords_str)
 
@@ -109,7 +111,7 @@ class SimpleAuthManager(BaseAuthManager):
 
             self._print_output(f"Password for user '{user['username']}': 
{self.passwords[user['username']]}")
 
-        with open(self.GENERATED_PASSWORDS_FILE, "w") as file:
+        with open(self.get_generated_password_file(), "w") as file:
             file.write(json.dumps(self.passwords))
 
     def is_logged_in(self) -> bool:
diff --git a/scripts/docker/entrypoint_ci.sh b/scripts/docker/entrypoint_ci.sh
index d0946b39e0e..a96e58b9c21 100755
--- a/scripts/docker/entrypoint_ci.sh
+++ b/scripts/docker/entrypoint_ci.sh
@@ -139,6 +139,9 @@ function environment_initialization() {
     # Added to have run-tests on path
     export PATH=${PATH}:${AIRFLOW_SOURCES}
 
+    # Directory where simple auth manager store generated passwords
+    export AIRFLOW_AUTH_MANAGER_CREDENTIAL_DIRECTORY="/files"
+
     mkdir -pv "${AIRFLOW_HOME}/logs/"
 
     # Change the default worker_concurrency for tests
diff --git a/tests/auth/managers/simple/test_simple_auth_manager.py 
b/tests/auth/managers/simple/test_simple_auth_manager.py
index d4bd4e4fbfe..434c0d60fcc 100644
--- a/tests/auth/managers/simple/test_simple_auth_manager.py
+++ b/tests/auth/managers/simple/test_simple_auth_manager.py
@@ -50,7 +50,7 @@ class TestSimpleAuthManager:
     @pytest.mark.db_test
     def test_init_with_no_user(self, auth_manager_with_appbuilder):
         auth_manager_with_appbuilder.init()
-        with open(SimpleAuthManager.GENERATED_PASSWORDS_FILE) as file:
+        with open(auth_manager_with_appbuilder.get_generated_password_file()) 
as file:
             passwords_str = file.read().strip()
             user_passwords_from_file = json.loads(passwords_str)
 
@@ -65,7 +65,7 @@ class TestSimpleAuthManager:
             }
         ]
         auth_manager_with_appbuilder.init()
-        with open(SimpleAuthManager.GENERATED_PASSWORDS_FILE) as file:
+        with open(auth_manager_with_appbuilder.get_generated_password_file()) 
as file:
             passwords_str = file.read().strip()
             user_passwords_from_file = json.loads(passwords_str)
 
diff --git a/tests/auth/managers/simple/views/test_auth.py 
b/tests/auth/managers/simple/views/test_auth.py
index a4e2a12fdcf..f61a9278f79 100644
--- a/tests/auth/managers/simple/views/test_auth.py
+++ b/tests/auth/managers/simple/views/test_auth.py
@@ -37,7 +37,7 @@ def simple_app():
             ): 
"airflow.auth.managers.simple.simple_auth_manager.SimpleAuthManager",
         }
     ):
-        with open(SimpleAuthManager.GENERATED_PASSWORDS_FILE, "w") as file:
+        with open(SimpleAuthManager.get_generated_password_file(), "w") as 
file:
             user = {"test": "test"}
             file.write(json.dumps(user))
 

Reply via email to