jedcunningham commented on code in PR #45472:
URL: https://github.com/apache/airflow/pull/45472#discussion_r1907383030


##########
providers/src/airflow/providers/fab/www/extensions/init_appbuilder.py:
##########
@@ -283,6 +283,12 @@ def _add_admin_views(self):
         self.indexview = self._check_and_init(self.indexview)
         self.add_view_no_menu(self.indexview)
 
+        try:
+            get_auth_manager().register_views()
+        except AttributeError:
+            # TODO: remove when min airflow version >= 3

Review Comment:
   It'd already >= 3 :)



##########
providers/src/airflow/providers/fab/www/extensions/init_views.py:
##########
@@ -18,17 +18,47 @@
 
 import logging
 from functools import cached_property
+from pathlib import Path
 from typing import TYPE_CHECKING
 
-from connexion import Resolver
+from connexion import FlaskApi, Resolver
 from connexion.decorators.validation import RequestBodyValidator
-from connexion.exceptions import BadRequestProblem
+from connexion.exceptions import BadRequestProblem, ProblemException
+from flask import request
+
+from airflow.api_connexion.exceptions import common_error_handler
+from airflow.api_fastapi.app import get_auth_manager
+from airflow.configuration import conf
+from airflow.providers.fab.www.constants import SWAGGER_BUNDLE, SWAGGER_ENABLED
+from airflow.utils.yaml import safe_load
 
 if TYPE_CHECKING:
     from flask import Flask
 
 log = logging.getLogger(__name__)
 
+# airflow/www/extensions/init_views.py => airflow/
+ROOT_APP_DIR = Path(__file__).parents[7].joinpath("airflow").resolve()

Review Comment:
   ```suggestion
   # providers/src/airflow/providers/fab/www/extensions/init_views.py => 
airflow/
   ROOT_APP_DIR = Path(__file__).parents[7].joinpath("airflow").resolve()
   ```



##########
providers/src/airflow/providers/fab/www/extensions/init_views.py:
##########
@@ -78,6 +108,59 @@ def validate_schema(self, data, url):
         return super().validate_schema(data, url)
 
 
+base_paths: list[str] = []  # contains the list of base paths that have api 
endpoints
+
+
+def init_api_error_handlers(app: Flask) -> None:
+    """Add error handlers for 404 and 405 errors for existing API paths."""
+
+    @app.errorhandler(404)
+    def _handle_api_not_found(ex):
+        if any([request.path.startswith(p) for p in base_paths]):
+            # 404 errors are never handled on the blueprint level
+            # unless raised from a view func so actual 404 errors,
+            # i.e. "no route for it" defined, need to be handled
+            # here on the application level
+            return common_error_handler(ex)
+        else:
+            from airflow.providers.fab.www.views import not_found
+
+            return not_found(ex)
+
+    @app.errorhandler(405)
+    def _handle_method_not_allowed(ex):
+        if any([request.path.startswith(p) for p in base_paths]):
+            return common_error_handler(ex)
+        else:
+            from airflow.providers.fab.www.views import method_not_allowed
+
+            return method_not_allowed(ex)
+
+    app.register_error_handler(ProblemException, common_error_handler)
+
+
+def init_api_connexion(app: Flask) -> None:

Review Comment:
   We are probably at a point we can rip out the old api, to be honest - I 
think aip-84 is far enough along.
   
   If we want to keep it for now, that's fine, however we might want to leave a 
breadcrumb that this needs to go before AF3.



-- 
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