jason810496 commented on code in PR #57480:
URL: https://github.com/apache/airflow/pull/57480#discussion_r2508018957


##########
scripts/in_container/install_airflow_and_providers.py:
##########


Review Comment:
   Thanks for the fix! Although this is a small change but it would be better 
to split it into another PR.
   Since it will be much more easier to backport. Thanks!



##########
providers/fab/src/airflow/providers/fab/auth_manager/api_fastapi/routes/users.py:
##########
@@ -0,0 +1,52 @@
+# 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 typing import TYPE_CHECKING
+
+from fastapi import Depends, status
+
+from airflow.api_fastapi.common.router import AirflowRouter
+from airflow.api_fastapi.core_api.openapi.exceptions import 
create_openapi_http_exception_doc
+from airflow.providers.fab.auth_manager.api_fastapi.datamodels.users import 
UserBody, UserResponse
+from airflow.providers.fab.auth_manager.api_fastapi.security import 
requires_fab_custom_view
+from airflow.providers.fab.auth_manager.api_fastapi.services.users import 
FABAuthManagerUsers
+from airflow.providers.fab.auth_manager.cli_commands.utils import 
get_application_builder
+from airflow.providers.fab.www.security import permissions
+
+if TYPE_CHECKING:
+    from airflow.providers.fab.auth_manager.api_fastapi.datamodels.users 
import UserBody, UserResponse
+
+users_router = AirflowRouter(prefix="/fab/v1", tags=["FabAuthManager"])

Review Comment:
   Non-blocking nit, can be done in follow-up PR:
   How about adding a common root router for all 
`providers/fab/src/airflow/providers/fab/auth_manager/api_fastapi/routes/<entity>.py`?
 Then we could specified the `prefix` and `tags` in single source.



##########
providers/fab/src/airflow/providers/fab/auth_manager/api_fastapi/datamodels/users.py:
##########
@@ -0,0 +1,62 @@
+# 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 datetime, timezone
+from typing import TYPE_CHECKING
+
+from pydantic import Field, SecretStr, field_validator
+
+from airflow.api_fastapi.core_api.base import BaseModel, StrictBaseModel
+from airflow.providers.fab.auth_manager.api_fastapi.datamodels.roles import 
Role
+
+if TYPE_CHECKING:
+    from airflow.providers.fab.auth_manager.api_fastapi.datamodels.roles 
import Role

Review Comment:
   It seems we don't need the `TYPE_CHECKING` as we already imported in line 25.
   
   ```suggestion
   ```



##########
providers/fab/src/airflow/providers/fab/auth_manager/api_fastapi/datamodels/users.py:
##########
@@ -0,0 +1,62 @@
+# 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 datetime, timezone
+from typing import TYPE_CHECKING
+
+from pydantic import Field, SecretStr, field_validator
+
+from airflow.api_fastapi.core_api.base import BaseModel, StrictBaseModel
+from airflow.providers.fab.auth_manager.api_fastapi.datamodels.roles import 
Role
+
+if TYPE_CHECKING:
+    from airflow.providers.fab.auth_manager.api_fastapi.datamodels.roles 
import Role
+
+
+class UserBody(StrictBaseModel):
+    """Incoming payload for creating a user."""
+
+    username: str = Field(min_length=1)
+    email: str = Field(min_length=1)
+    first_name: str = Field(min_length=1)
+    last_name: str = Field(min_length=1)
+    roles: list[Role] | None = None
+    password: SecretStr
+
+
+class UserResponse(BaseModel):
+    """Outgoing representation of a user (no password)."""
+
+    username: str
+    email: str
+    first_name: str
+    last_name: str
+    roles: list[Role] | None = None
+    active: bool | None = None
+    last_login: datetime | None = None
+    login_count: int | None = None
+    fail_login_count: int | None = None
+    created_on: datetime | None = None
+    changed_on: datetime | None = None
+
+    @field_validator("created_on", "changed_on")
+    @classmethod
+    def _coerce_tzaware(cls, v: datetime | None) -> datetime | None:
+        if v is None:
+            return None
+        return v if (v.tzinfo and v.utcoffset() is not None) else 
v.replace(tzinfo=timezone.utc)

Review Comment:
   Would it be possible to leverage `UtcDateTime` ? Then we don't need to 
handle the common timezone validation for this case.
   
   
https://github.com/apache/airflow/blob/bc3a750af476b991ca34e6c696208f8e75ff99a7/airflow-core/src/airflow/api_fastapi/execution_api/datamodels/taskinstance.py#L282-L283
   
   



##########
providers/fab/src/airflow/providers/fab/auth_manager/api_fastapi/routes/users.py:
##########
@@ -0,0 +1,52 @@
+# 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 typing import TYPE_CHECKING
+
+from fastapi import Depends, status
+
+from airflow.api_fastapi.common.router import AirflowRouter
+from airflow.api_fastapi.core_api.openapi.exceptions import 
create_openapi_http_exception_doc
+from airflow.providers.fab.auth_manager.api_fastapi.datamodels.users import 
UserBody, UserResponse
+from airflow.providers.fab.auth_manager.api_fastapi.security import 
requires_fab_custom_view
+from airflow.providers.fab.auth_manager.api_fastapi.services.users import 
FABAuthManagerUsers
+from airflow.providers.fab.auth_manager.cli_commands.utils import 
get_application_builder
+from airflow.providers.fab.www.security import permissions
+
+if TYPE_CHECKING:
+    from airflow.providers.fab.auth_manager.api_fastapi.datamodels.users 
import UserBody, UserResponse

Review Comment:
   ```suggestion
   ```



-- 
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]

Reply via email to