diff --git a/catalog-rest-service/src/main/java/org/openmetadata/catalog/airflow/AirflowRESTClient.java b/catalog-rest-service/src/main/java/org/openmetadata/catalog/airflow/AirflowRESTClient.java index 543af31ab6a..cc6165f0395 100644 --- a/catalog-rest-service/src/main/java/org/openmetadata/catalog/airflow/AirflowRESTClient.java +++ b/catalog-rest-service/src/main/java/org/openmetadata/catalog/airflow/AirflowRESTClient.java @@ -188,7 +188,7 @@ public class AirflowRESTClient extends PipelineServiceClient { @Override public HttpResponse getServiceStatus() { try { - HttpResponse response = requestAuthenticatedForJsonContent("%s/rest_api/api?api=rest_status", serviceURL); + HttpResponse response = requestNoAuthForJsonContent("%s/rest_api/health", serviceURL); if (response.statusCode() == 200) { return response; } @@ -243,4 +243,11 @@ public class AirflowRESTClient extends PipelineServiceClient { .build(); return client.send(request, HttpResponse.BodyHandlers.ofString()); } + + private HttpResponse requestNoAuthForJsonContent(String stringUrlFormat, Object... stringReplacement) + throws IOException, InterruptedException { + String url = String.format(stringUrlFormat, stringReplacement); + HttpRequest request = HttpRequest.newBuilder(URI.create(url)).header(CONTENT_HEADER, CONTENT_TYPE).GET().build(); + return client.send(request, HttpResponse.BodyHandlers.ofString()); + } } diff --git a/openmetadata-airflow-apis/src/openmetadata/api/apis_metadata.py b/openmetadata-airflow-apis/src/openmetadata/api/apis_metadata.py index 77be7230b9c..3fcb4a3784d 100644 --- a/openmetadata-airflow-apis/src/openmetadata/api/apis_metadata.py +++ b/openmetadata-airflow-apis/src/openmetadata/api/apis_metadata.py @@ -92,11 +92,6 @@ APIS_METADATA = [ }, ], }, - { - "name": "rest_status", - "description": "Get the status of Airflow REST status", - "http_method": "GET", - }, { "name": "enable_dag", "description": "Mark the DAG as enabled to run on the next schedule.", diff --git a/openmetadata-airflow-apis/src/openmetadata/api/rest_api.py b/openmetadata-airflow-apis/src/openmetadata/api/rest_api.py index e907793ff47..fe40e859a4a 100644 --- a/openmetadata-airflow-apis/src/openmetadata/api/rest_api.py +++ b/openmetadata-airflow-apis/src/openmetadata/api/rest_api.py @@ -93,6 +93,21 @@ class REST_API(AppBuilderBaseView): rbac_authentication_enabled=True, ) + @csrf.exempt # Exempt the CSRF token + @app_builder_expose("/health", methods=["GET"]) # for Flask AppBuilder + def health(self): + """ + /health endpoint to check Airflow REST status without auth + """ + + try: + return ApiResponse.success({"status": "healthy"}) + except Exception as err: + return ApiResponse.error( + status=ApiResponse.STATUS_SERVER_ERROR, + error=f"Internal error obtaining REST status - {err} - {traceback.format_exc()}", + ) + # '/api' REST Endpoint where API requests should all come in @csrf.exempt # Exempt the CSRF token @admin_expose("/api", methods=["GET", "POST", "DELETE"]) # for Flask Admin @@ -119,8 +134,6 @@ class REST_API(AppBuilderBaseView): # Deciding which function to use based off the API object that was requested. # Some functions are custom and need to be manually routed to. - if api == "rest_status": - return self.rest_status() if api == "deploy_dag": return self.deploy_dag() if api == "trigger_dag": @@ -142,23 +155,6 @@ class REST_API(AppBuilderBaseView): f"Invalid api param {api}. Expected deploy_dag or trigger_dag." ) - @staticmethod - def rest_status() -> Response: - """ - Check that the Airflow REST is reachable - and running correctly. - """ - try: - url = AIRFLOW_WEBSERVER_BASE_URL + REST_API_ENDPOINT - return ApiResponse.success( - {"message": f"Airflow REST {REST_API_PLUGIN_VERSION} running at {url}"} - ) - except Exception as err: - return ApiResponse.error( - status=ApiResponse.STATUS_SERVER_ERROR, - error=f"Internal error obtaining REST status - {err} - {traceback.format_exc()}", - ) - def deploy_dag(self) -> Response: """ Custom Function for the deploy_dag API