vincbeck commented on code in PR #47043:
URL: https://github.com/apache/airflow/pull/47043#discussion_r1970295450
##########
providers/fab/src/airflow/providers/fab/auth_manager/api_endpoints/login.py:
##########
@@ -0,0 +1,56 @@
+# Licensed to the Apache Software Foundation (ASF) under one
Review Comment:
`api_endpoints` contains endpoints from Flask, I dont think we should mix
Flask and Fastapi routes. Usually we put `fastapi` routes in a `routes` module.
Could you create a new one and put it there?
##########
providers/fab/src/airflow/providers/fab/auth_manager/security_manager/override.py:
##########
@@ -589,6 +598,7 @@ def reset_user_sessions(self, user: User) -> None:
"warning",
)
+ # Check
Review Comment:
?
##########
providers/fab/src/airflow/providers/fab/auth_manager/api_endpoints/login.py:
##########
@@ -0,0 +1,56 @@
+# 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 datetime import timedelta
+from typing import cast
+
+from starlette import status
+
+from airflow.api_fastapi.app import get_auth_manager
+from airflow.api_fastapi.common.router import AirflowRouter
+from airflow.api_fastapi.core_api.openapi.exceptions import
create_openapi_http_exception_doc
+from airflow.configuration import conf
+from airflow.providers.fab.auth_manager.fab_auth_manager import FabAuthManager
+from airflow.providers.fab.auth_manager.models.login import CLIAPITokenResponse
+
+login_router = AirflowRouter(tags=["FabAuthManager"])
+
+
+@login_router.post(
+ "/token/cli",
+ response_model=CLIAPITokenResponse,
+ status_code=status.HTTP_201_CREATED,
+ responses=create_openapi_http_exception_doc([status.HTTP_400_BAD_REQUEST,
status.HTTP_401_UNAUTHORIZED]),
+)
+def create_token_cli() -> CLIAPITokenResponse:
+ """Generate a new CLI API token."""
+ auth_manager = cast(FabAuthManager, get_auth_manager())
+
+ # There is no user base expiration in FAB, so we can't use this.
+ # We can only set this globally but this would impact global expiration
time for all tokens.
+ auth_manager.appbuilder.app.config["JWT_ACCESS_TOKEN_EXPIRES"] = timedelta(
+ seconds=conf.getint("api", "auth_jwt_cli_expiration_time")
+ )
+
+ # Get token for implementing custom expiration time for JWT token
+ # token = auth_manager.get_jwt_token(user=auth_manager.get_user())
Review Comment:
Delete?
##########
providers/fab/src/airflow/providers/fab/auth_manager/api_endpoints/login.py:
##########
@@ -0,0 +1,56 @@
+# 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 datetime import timedelta
+from typing import cast
+
+from starlette import status
+
+from airflow.api_fastapi.app import get_auth_manager
+from airflow.api_fastapi.common.router import AirflowRouter
+from airflow.api_fastapi.core_api.openapi.exceptions import
create_openapi_http_exception_doc
+from airflow.configuration import conf
+from airflow.providers.fab.auth_manager.fab_auth_manager import FabAuthManager
+from airflow.providers.fab.auth_manager.models.login import CLIAPITokenResponse
+
+login_router = AirflowRouter(tags=["FabAuthManager"])
+
+
+@login_router.post(
+ "/token/cli",
+ response_model=CLIAPITokenResponse,
+ status_code=status.HTTP_201_CREATED,
+ responses=create_openapi_http_exception_doc([status.HTTP_400_BAD_REQUEST,
status.HTTP_401_UNAUTHORIZED]),
+)
+def create_token_cli() -> CLIAPITokenResponse:
Review Comment:
We should have unit test for it
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]