You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by ms...@apache.org on 2022/12/20 05:06:56 UTC

[airflow] branch main updated: Allow Users to disable SwaggerUI via configuration (#28354)

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

msumit 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 032a542fee Allow Users to disable SwaggerUI via configuration (#28354)
032a542fee is described below

commit 032a542feeb617d1f92580b97fa0ad3cdca09d63
Author: Glenn Schuurman <gl...@gmail.com>
AuthorDate: Tue Dec 20 06:06:21 2022 +0100

    Allow Users to disable SwaggerUI via configuration (#28354)
    
    Due to potential issues, we want to give teams the opportunity to
    disable the swaggerUI. This can now be done via the configuration
    key: webserver.enable_swagger_ui. For backwards compatibility,
    this has been set to true by default, but for teams willing to disable
    this it can be set to false.
---
 airflow/config_templates/config.yml             |  7 +++++++
 airflow/config_templates/default_airflow.cfg    |  3 +++
 airflow/www/extensions/init_appbuilder_links.py | 15 +++++++++------
 airflow/www/extensions/init_views.py            |  6 ++++--
 4 files changed, 23 insertions(+), 8 deletions(-)

diff --git a/airflow/config_templates/config.yml b/airflow/config_templates/config.yml
index 21d787cb56..9005a54885 100644
--- a/airflow/config_templates/config.yml
+++ b/airflow/config_templates/config.yml
@@ -1513,6 +1513,13 @@
       type: string
       example: "dagrun_cleared,failed"
       default: ~
+    - name: enable_swagger_ui
+      description: |
+        Boolean for running SwaggerUI in the webserver.
+      version_added: 2.6.0
+      type: boolean
+      example: ~
+      default: "True"
     - name: run_internal_api
       description: |
         Boolean for running Internal API in the webserver.
diff --git a/airflow/config_templates/default_airflow.cfg b/airflow/config_templates/default_airflow.cfg
index a3aff78e95..4bd2883563 100644
--- a/airflow/config_templates/default_airflow.cfg
+++ b/airflow/config_templates/default_airflow.cfg
@@ -771,6 +771,9 @@ audit_view_excluded_events = gantt,landing_times,tries,duration,calendar,graph,g
 # Example: audit_view_included_events = dagrun_cleared,failed
 # audit_view_included_events =
 
+# Boolean for running SwaggerUI in the webserver.
+enable_swagger_ui = True
+
 # Boolean for running Internal API in the webserver.
 run_internal_api = False
 
diff --git a/airflow/www/extensions/init_appbuilder_links.py b/airflow/www/extensions/init_appbuilder_links.py
index 619d302fb3..67bd1f6bb4 100644
--- a/airflow/www/extensions/init_appbuilder_links.py
+++ b/airflow/www/extensions/init_appbuilder_links.py
@@ -16,6 +16,7 @@
 # under the License.
 from __future__ import annotations
 
+from airflow.configuration import conf
 from airflow.utils.docs import get_docs_url
 
 
@@ -36,12 +37,14 @@ def init_appbuilder_links(app):
     appbuilder.add_link(
         name="Documentation", label="GitHub Repo", href="https://github.com/apache/airflow", category="Docs"
     )
-    appbuilder.add_link(
-        name="Documentation",
-        label="REST API Reference (Swagger UI)",
-        href="/api/v1./api/v1_swagger_ui_index",
-        category="Docs",
-    )
+
+    if conf.getboolean("webserver", "enable_swagger_ui", fallback=True):
+        appbuilder.add_link(
+            name="Documentation",
+            label="REST API Reference (Swagger UI)",
+            href="/api/v1./api/v1_swagger_ui_index",
+            category="Docs",
+        )
     appbuilder.add_link(
         name="Documentation", label="REST API Reference (Redoc)", href="RedocView.redoc", category="Docs"
     )
diff --git a/airflow/www/extensions/init_views.py b/airflow/www/extensions/init_views.py
index 86f94d2f22..ca4ef6cd5e 100644
--- a/airflow/www/extensions/init_views.py
+++ b/airflow/www/extensions/init_views.py
@@ -208,7 +208,8 @@ def init_api_connexion(app: Flask) -> None:
             return views.method_not_allowed(ex)
 
     spec_dir = path.join(ROOT_APP_DIR, "api_connexion", "openapi")
-    connexion_app = App(__name__, specification_dir=spec_dir, skip_error_handlers=True)
+    options = {"swagger_ui": conf.getboolean("webserver", "enable_swagger_ui", fallback=True)}
+    connexion_app = App(__name__, specification_dir=spec_dir, skip_error_handlers=True, options=options)
     connexion_app.app = app
     api_bp = connexion_app.add_api(
         specification="v1.yaml", base_path=base_path, validate_responses=True, strict_validation=True
@@ -227,7 +228,8 @@ def init_api_internal(app: Flask) -> None:
     base_path = "/internal_api/v1"
 
     spec_dir = path.join(ROOT_APP_DIR, "api_internal", "openapi")
-    internal_app = App(__name__, specification_dir=spec_dir, skip_error_handlers=True)
+    options = {"swagger_ui": conf.getboolean("webserver", "enable_swagger_ui", fallback=True)}
+    internal_app = App(__name__, specification_dir=spec_dir, skip_error_handlers=True, options=options)
     internal_app.app = app
     api_bp = internal_app.add_api(
         specification="internal_api_v1.yaml",