-
Notifications
You must be signed in to change notification settings - Fork 17k
Let auth managers provide their own API endpoints #34349
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 13 commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
1472fa0
move user & role API endpoints to fab folder
vandonr-amz a3632f9
add a method to init API from auth provider
vandonr-amz 7cfe915
add user & role APIs in fab auth manager
vandonr-amz 43f3e5d
mark existing api endpoints as deprecated
vandonr-amz 6f835d8
Merge remote-tracking branch 'apache/main' into vandonr/fab
vandonr-amz 3c0490d
move tests
vandonr-amz f67eac3
test fixes
vandonr-amz 32e67aa
apply suggestion
vandonr-amz 8a8c738
docstring change
vandonr-amz 8c104aa
more test fixing
vandonr-amz 5ee06cf
change endpoint path to auth/fab
vandonr-amz 7183e9b
Merge remote-tracking branch 'apache/main' into vandonr/fab
vandonr-amz 51f8038
add intermediate layer on moved endpoints to check provider
vandonr-amz ec46600
a bit more detail in http error
vandonr-amz 8566e29
static check fix
vandonr-amz 73d014b
Merge remote-tracking branch 'apache/main' into vandonr/fab
vandonr-amz 9301bb5
Merge branch 'main' into vandonr/fab
vandonr-amz 95d57a2
Merge branch 'main' into vandonr/fab
vincbeck df4c63f
Add file `airflow/auth/managers/fab/openapi/v1.yaml` to MANIFEST.in
vincbeck 1ad6988
Merge branch 'main' into vandonr/fab
vincbeck 94ae9a2
Fix comment
vincbeck b89f301
Fix airflow/auth/managers/fab/openapi/v1.yaml
vincbeck 6e6eb9c
Merge branch 'main' into vandonr/fab
vincbeck cc17098
Replace `get_api_blueprint` by `get_api_endpoints`
vincbeck d9ca5bf
Merge branch 'main' into vandonr/fab
vincbeck File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
124 changes: 124 additions & 0 deletions
124
airflow/api_connexion/endpoints/forward_to_fab_endpoint.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,124 @@ | ||
| # 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 | ||
|
|
||
| import warnings | ||
| from typing import TYPE_CHECKING | ||
|
|
||
| from airflow.api_connexion.exceptions import BadRequest | ||
| from airflow.auth.managers.fab.api_endpoints import role_and_permission_endpoint, user_endpoint | ||
| from airflow.www.extensions.init_auth_manager import get_auth_manager | ||
|
|
||
| if TYPE_CHECKING: | ||
| from typing import Callable | ||
|
|
||
| from airflow.api_connexion.types import APIResponse | ||
|
|
||
|
|
||
| def _require_fab(func: Callable) -> Callable: | ||
| """ | ||
| Raise an HTTP error 400 if the provider is not FAB. | ||
|
vincbeck marked this conversation as resolved.
Outdated
|
||
|
|
||
| Intended to decorate endpoints that have been migrated from Airflow API to FAB API. | ||
| """ | ||
|
|
||
| def inner(*args, **kwargs): | ||
| from airflow.auth.managers.fab.fab_auth_manager import FabAuthManager | ||
|
|
||
| auth_mgr = get_auth_manager() | ||
| if not isinstance(auth_mgr, FabAuthManager): | ||
| raise BadRequest(detail="This endpoint is only available when using the default auth manager.") | ||
|
vandonr-amz marked this conversation as resolved.
Outdated
|
||
| else: | ||
| warnings.warn( | ||
| "This API endpoint is deprecated. " | ||
| "Please use the API under /auth/fab/v1 instead for this operation.", | ||
| DeprecationWarning, | ||
| ) | ||
| return func(*args, **kwargs) | ||
|
|
||
| return inner | ||
|
|
||
|
|
||
| ### role | ||
|
|
||
|
|
||
| @_require_fab | ||
| def get_role(**kwargs) -> APIResponse: | ||
| """Get role.""" | ||
| return role_and_permission_endpoint.get_role(**kwargs) | ||
|
|
||
|
|
||
| @_require_fab | ||
| def get_roles(**kwargs) -> APIResponse: | ||
| """Get roles.""" | ||
| return role_and_permission_endpoint.get_roles(**kwargs) | ||
|
|
||
|
|
||
| @_require_fab | ||
| def delete_role(**kwargs) -> APIResponse: | ||
| """Delete a role.""" | ||
| return role_and_permission_endpoint.delete_role(**kwargs) | ||
|
|
||
|
|
||
| @_require_fab | ||
| def patch_role(**kwargs) -> APIResponse: | ||
| """Update a role.""" | ||
| return role_and_permission_endpoint.patch_role(**kwargs) | ||
|
|
||
|
|
||
| @_require_fab | ||
| def post_role(**kwargs) -> APIResponse: | ||
| """Create a new role.""" | ||
| return role_and_permission_endpoint.post_role(**kwargs) | ||
|
|
||
|
|
||
| ### permissions | ||
| @_require_fab | ||
| def get_permissions(**kwargs) -> APIResponse: | ||
| """Get permissions.""" | ||
| return role_and_permission_endpoint.get_permissions(**kwargs) | ||
|
|
||
|
|
||
| ### user | ||
| @_require_fab | ||
| def get_user(**kwargs) -> APIResponse: | ||
| """Get a user.""" | ||
| return user_endpoint.get_user(**kwargs) | ||
|
|
||
|
|
||
| @_require_fab | ||
| def get_users(**kwargs) -> APIResponse: | ||
| """Get users.""" | ||
| return user_endpoint.get_users(**kwargs) | ||
|
|
||
|
|
||
| @_require_fab | ||
| def post_user(**kwargs) -> APIResponse: | ||
| """Create a new user.""" | ||
| return user_endpoint.post_user(**kwargs) | ||
|
|
||
|
|
||
| @_require_fab | ||
| def patch_user(**kwargs) -> APIResponse: | ||
| """Update a user.""" | ||
| return user_endpoint.patch_user(**kwargs) | ||
|
|
||
|
|
||
| @_require_fab | ||
| def delete_user(**kwargs) -> APIResponse: | ||
| """Delete a user.""" | ||
| return user_endpoint.delete_user(**kwargs) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| # 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. |
File renamed without changes.
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.