Skip to content

Commit

Permalink
Add swagger path to FAB Auth manager and Internal API (#37525)
Browse files Browse the repository at this point in the history
  • Loading branch information
Taragolis committed Feb 19, 2024
1 parent e6f5d45 commit 79603f9
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 9 deletions.
5 changes: 2 additions & 3 deletions airflow/providers/fab/auth_manager/fab_auth_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@
)
from airflow.utils.session import NEW_SESSION, provide_session
from airflow.utils.yaml import safe_load
from airflow.www.constants import SWAGGER_BUNDLE, SWAGGER_ENABLED
from airflow.www.extensions.init_views import _CustomErrorRequestBodyValidator, _LazyResolver

if TYPE_CHECKING:
Expand Down Expand Up @@ -156,9 +157,7 @@ def get_api_endpoints(self) -> None | Blueprint:
specification=specification,
resolver=_LazyResolver(),
base_path="/auth/fab/v1",
options={
"swagger_ui": conf.getboolean("webserver", "enable_swagger_ui", fallback=True),
},
options={"swagger_ui": SWAGGER_ENABLED, "swagger_path": SWAGGER_BUNDLE.__fspath__()},
strict_validation=True,
validate_responses=True,
validator_map={"body": _CustomErrorRequestBodyValidator},
Expand Down
28 changes: 28 additions & 0 deletions airflow/www/constants.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
from __future__ import annotations

from pathlib import Path

from airflow.configuration import conf

WWW = Path(__file__).resolve().parent
# There is a difference with configuring Swagger in Connexion 2.x and Connexion 3.x
# Connexion 2: https://connexion.readthedocs.io/en/2.14.2/quickstart.html#the-swagger-ui-console
# Connexion 3: https://connexion.readthedocs.io/en/stable/swagger_ui.html#configuring-the-swagger-ui
SWAGGER_ENABLED = conf.getboolean("webserver", "enable_swagger_ui", fallback=True)
SWAGGER_BUNDLE = WWW.joinpath("static", "dist", "swagger-ui")
9 changes: 3 additions & 6 deletions airflow/www/extensions/init_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
from __future__ import annotations

import logging
import os
import warnings
from functools import cached_property
from pathlib import Path
Expand All @@ -33,6 +32,7 @@
from airflow.exceptions import RemovedInAirflow3Warning
from airflow.security import permissions
from airflow.utils.yaml import safe_load
from airflow.www.constants import SWAGGER_BUNDLE, SWAGGER_ENABLED
from airflow.www.extensions.init_auth_manager import get_auth_manager

if TYPE_CHECKING:
Expand Down Expand Up @@ -273,10 +273,7 @@ def init_api_connexion(app: Flask) -> None:
specification=specification,
resolver=_LazyResolver(),
base_path=base_path,
options={
"swagger_ui": conf.getboolean("webserver", "enable_swagger_ui", fallback=True),
"swagger_path": os.fspath(ROOT_APP_DIR.joinpath("www", "static", "dist", "swagger-ui")),
},
options={"swagger_ui": SWAGGER_ENABLED, "swagger_path": SWAGGER_BUNDLE.__fspath__()},
strict_validation=True,
validate_responses=True,
validator_map={"body": _CustomErrorRequestBodyValidator},
Expand All @@ -298,7 +295,7 @@ def init_api_internal(app: Flask, standalone_api: bool = False) -> None:
api_bp = FlaskApi(
specification=specification,
base_path="/internal_api/v1",
options={"swagger_ui": conf.getboolean("webserver", "enable_swagger_ui", fallback=True)},
options={"swagger_ui": SWAGGER_ENABLED, "swagger_path": SWAGGER_BUNDLE.__fspath__()},
strict_validation=True,
validate_responses=True,
).blueprint
Expand Down

0 comments on commit 79603f9

Please sign in to comment.