jscheffl commented on code in PR #61310:
URL: https://github.com/apache/airflow/pull/61310#discussion_r2771336867


##########
airflow-core/src/airflow/api_fastapi/app.py:
##########
@@ -70,16 +68,70 @@ async def lifespan(app: FastAPI):
         app.state.lifespan_called = True
         yield
 
+def get_auth_manager_cls() -> type[BaseAuthManager]:
+    auth_manager_cls = conf.getimport(section="core", key="auth_manager")
+
+    if not auth_manager_cls:
+        raise AirflowConfigException(
+            "No auth manager defined in the config. Please specify one using 
section/key [core/auth_manager]."
+        )
+
+    return auth_manager_cls
+
+
+def _ensure_auth_lock(app: FastAPI) -> None:
+    if not hasattr(app.state, "auth_manager_lock"):
+        app.state.auth_manager_lock = threading.RLock()
+
+
+def _create_auth_manager_if_missing(app: FastAPI) -> BaseAuthManager:
+    _ensure_auth_lock(app)
+
+    with app.state.auth_manager_lock:
+        if not hasattr(app.state, "auth_manager"):
+            auth_manager_cls = get_auth_manager_cls()
+            app.state.auth_manager = auth_manager_cls()
+            app.state.auth_manager_initialized = False
+
+    return app.state.auth_manager
+
+
+def init_auth_manager(app: FastAPI | None = None) -> BaseAuthManager:
+    """
+    Initialize and attach the auth manager to FastAPI app.
+    Thread-safe and app-lifecycle scoped.
+    """
+    if app is None:
+        raise RuntimeError("init_auth_manager requires FastAPI app instance")
+
+    am = _create_auth_manager_if_missing(app)
+
+    with app.state.auth_manager_lock:
+        if not app.state.auth_manager_initialized:
+            am.init()
+            app.state.auth_manager_initialized = True
+
+            auth_manager_fastapi_app = am.get_fastapi_app()
+            if auth_manager_fastapi_app:
+                app.mount("/auth", auth_manager_fastapi_app)
+
+    return am
+
+
+def get_auth_manager(app: FastAPI) -> BaseAuthManager:
+    """
+    Return app-scoped auth manager.
+    """
+    return _create_auth_manager_if_missing(app)
+
 
 @providers_configuration_loaded
 def create_app(apps: str = "all") -> FastAPI:
     apps_list = apps.split(",") if apps else ["all"]
 
     app = FastAPI(
         title="Airflow API",
-        description="Airflow API. All endpoints located under ``/api/v2`` can 
be used safely, are stable and backward compatible. "
-        "Endpoints located under ``/ui`` are dedicated to the UI and are 
subject to breaking change "
-        "depending on the need of the frontend. Users should not rely on those 
but use the public ones instead.",
+        description="Airflow API...",

Review Comment:
   Why dio you change the descriptions in this PR?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to