Skip to content

Commit db8ee3e

Browse files
Satoshi-Shsudiptob2
authored andcommitted
Refactored the code since the functions return None. Replaced 'get' with 'set'
1 parent 7bd8516 commit db8ee3e

File tree

5 files changed

+10
-15
lines changed

5 files changed

+10
-15
lines changed

airflow/auth/managers/base_auth_manager.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434

3535
if TYPE_CHECKING:
3636
import connexion
37-
from flask import Blueprint
3837
from flask_appbuilder.menu import MenuItem
3938
from sqlalchemy.orm import Session
4039

@@ -82,8 +81,8 @@ def get_cli_commands() -> list[CLICommand]:
8281
"""
8382
return []
8483

85-
def set_api_endpoints(self, connexion_app: connexion.FlaskApp) -> None | Blueprint:
86-
"""Return API endpoint(s) definition for the auth manager."""
84+
def set_api_endpoints(self, connexion_app: connexion.FlaskApp) -> None:
85+
"""Set API endpoint(s) definition for the auth manager."""
8786
return None
8887

8988
def get_user_name(self) -> str:

airflow/providers/fab/auth_manager/fab_auth_manager.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
from typing import TYPE_CHECKING, Container
2424

2525
from connexion.options import SwaggerUIOptions
26-
from flask import Blueprint, url_for
26+
from flask import url_for
2727
from sqlalchemy import select
2828
from sqlalchemy.orm import Session, joinedload
2929

@@ -150,7 +150,7 @@ def get_cli_commands() -> list[CLICommand]:
150150
SYNC_PERM_COMMAND, # not in a command group
151151
]
152152

153-
def get_api_endpoints(self, connexion_app: connexion.FlaskApp) -> None | Blueprint:
153+
def set_api_endpoints(self, connexion_app: connexion.FlaskApp) -> None:
154154
folder = Path(__file__).parents[0].resolve() # this is airflow/auth/managers/fab/
155155
with folder.joinpath("openapi", "v1.yaml").open() as f:
156156
specification = safe_load(f)
@@ -159,15 +159,15 @@ def get_api_endpoints(self, connexion_app: connexion.FlaskApp) -> None | Bluepri
159159
swagger_ui=conf.getboolean("webserver", "enable_swagger_ui", fallback=True),
160160
)
161161

162-
api = connexion_app.add_api(
162+
connexion_app.add_api(
163163
specification=specification,
164164
resolver=_LazyResolver(),
165165
base_path="/auth/fab/v1",
166166
swagger_ui_options=swagger_ui_options,
167167
strict_validation=True,
168168
validate_responses=True,
169169
)
170-
return api.blueprint if api else None
170+
return None
171171

172172
def get_user_display_name(self) -> str:
173173
"""Return the user's display name associated to the user in session."""

airflow/www/extensions/init_views.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -304,8 +304,4 @@ def init_api_experimental(app):
304304
def init_api_auth_provider(connexion_app: connexion.FlaskApp):
305305
"""Initialize the API offered by the auth manager."""
306306
auth_mgr = get_auth_manager()
307-
blueprint = auth_mgr.get_api_endpoints(connexion_app)
308-
if blueprint:
309-
base_paths.append(blueprint.url_prefix if blueprint.url_prefix else "")
310-
flask_app = connexion_app.app
311-
flask_app.extensions["csrf"].exempt(blueprint)
307+
auth_mgr.set_api_endpoints(connexion_app)

docs/apache-airflow/core-concepts/auth-manager.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ Auth managers may vend CLI commands which will be included in the ``airflow`` co
161161
Rest API
162162
^^^^^^^^
163163

164-
Auth managers may vend Rest API endpoints which will be included in the :doc:`/stable-rest-api-ref` by implementing the ``get_api_endpoints`` method. The endpoints can be used to manage resources such as users, groups, roles (if any) handled by your auth manager. Endpoints are only vended for the currently configured auth manager.
164+
Auth managers may vend Rest API endpoints which will be included in the :doc:`/stable-rest-api-ref` by implementing the ``set_api_endpoints`` method. The endpoints can be used to manage resources such as users, groups, roles (if any) handled by your auth manager. Endpoints are only vended for the currently configured auth manager.
165165

166166
Next Steps
167167
^^^^^^^^^^

tests/auth/managers/test_base_auth_manager.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,8 @@ class TestBaseAuthManager:
121121
def test_get_cli_commands_return_empty_list(self, auth_manager):
122122
assert auth_manager.get_cli_commands() == []
123123

124-
def test_get_api_endpoints_return_none(self, auth_manager):
125-
assert auth_manager.get_api_endpoints() is None
124+
def test_set_api_endpoints_return_none(self, auth_manager):
125+
assert auth_manager.set_api_endpoints() is None
126126

127127
def test_get_user_name(self, auth_manager):
128128
user = Mock()

0 commit comments

Comments
 (0)