-
Notifications
You must be signed in to change notification settings - Fork 164
refactor(BA-3587): Define DTO types for auth handler's soft migration #8353
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
Open
kwonkwonn
wants to merge
4
commits into
main
Choose a base branch
from
refactor/Add-dto-for-auth-pydantic
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+223
−10
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
9b06817
refactor: Define DTO types for response migration
kwonkwonn 00a8e4c
refactor: enhance action-service for auth api
kwonkwonn b5e471f
refactor: modify existing auth.py to work the same with before
kwonkwonn e33f3d0
fix lint errors and type error from test file
kwonkwonn 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
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 @@ | ||
| On perpose of soft merging for manager's auth apis, defining DTO's and actions, moving auth into seperated directory. |
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,8 @@ | ||
| """ | ||
| Common DTOs for auth system used by both Client SDK and Manager. | ||
|
|
||
| Import directly from submodules: | ||
| - types: AuthTokenType, AuthResponseType, TwoFactorType, AuthResponse, etc. | ||
| - request: AuthorizeRequest, SignupRequest, SignoutRequest, etc. | ||
| - response: AuthorizeResponse, SignupResponse, SignoutResponse, etc. | ||
| """ |
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,105 @@ | ||
| """ | ||
| Request DTOs for auth system. | ||
| Shared between Client SDK and Manager API. | ||
| """ | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| from typing import Optional | ||
| from uuid import UUID | ||
|
|
||
| from pydantic import AliasChoices, Field | ||
|
|
||
| from ai.backend.common.api_handlers import BaseRequestModel | ||
|
|
||
| from .types import AuthTokenType | ||
|
|
||
| __all__ = ( | ||
| "AuthorizeRequest", | ||
| "GetRoleRequest", | ||
| "SignupRequest", | ||
| "SignoutRequest", | ||
| "UpdateFullNameRequest", | ||
| "UpdatePasswordRequest", | ||
| "UpdatePasswordNoAuthRequest", | ||
| "UploadSSHKeypairRequest", | ||
| "VerifyAuthRequest", | ||
| ) | ||
|
|
||
|
|
||
| class AuthorizeRequest(BaseRequestModel): | ||
| """Request to authorize a user.""" | ||
|
|
||
| type: AuthTokenType = Field(description="Authentication type (keypair or jwt)") | ||
| domain: str = Field(description="Domain name") | ||
| username: str = Field(description="Username or email") | ||
| password: str = Field(description="Password") | ||
| stoken: Optional[str] = Field( | ||
| default=None, | ||
| description="Session token", | ||
| validation_alias=AliasChoices("stoken", "sToken"), | ||
| ) | ||
|
|
||
|
|
||
| class GetRoleRequest(BaseRequestModel): | ||
| """Request to get user role.""" | ||
|
|
||
| group: Optional[UUID] = Field(default=None, description="Group ID to check role for") | ||
|
|
||
|
|
||
| class SignupRequest(BaseRequestModel): | ||
| """Request to sign up a new user.""" | ||
|
|
||
| domain: str = Field(description="Domain name") | ||
| email: str = Field(description="Email address") | ||
| password: str = Field(description="Password") | ||
| username: Optional[str] = Field(default=None, description="Username") | ||
| full_name: Optional[str] = Field(default=None, description="Full name") | ||
| description: Optional[str] = Field(default=None, description="Description") | ||
|
|
||
|
|
||
| class SignoutRequest(BaseRequestModel): | ||
| """Request to sign out a user.""" | ||
|
|
||
| email: str = Field( | ||
| description="Email address", | ||
| validation_alias=AliasChoices("email", "username"), | ||
| ) | ||
| password: str = Field(description="Password") | ||
|
|
||
|
|
||
| class UpdateFullNameRequest(BaseRequestModel): | ||
| """Request to update user's full name.""" | ||
|
|
||
| email: str = Field(description="Email address") | ||
| full_name: str = Field(description="New full name") | ||
|
|
||
|
|
||
| class UpdatePasswordRequest(BaseRequestModel): | ||
| """Request to update password (authenticated).""" | ||
|
|
||
| old_password: str = Field(description="Current password") | ||
| new_password: str = Field(description="New password") | ||
| new_password2: str = Field(description="New password confirmation") | ||
|
|
||
|
|
||
| class UpdatePasswordNoAuthRequest(BaseRequestModel): | ||
| """Request to update password without authentication.""" | ||
|
|
||
| domain: str = Field(description="Domain name") | ||
| username: str = Field(description="Username or email") | ||
| current_password: str = Field(description="Current password") | ||
| new_password: str = Field(description="New password") | ||
|
|
||
|
|
||
| class UploadSSHKeypairRequest(BaseRequestModel): | ||
| """Request to upload SSH keypair.""" | ||
|
|
||
| pubkey: str = Field(description="SSH public key") | ||
| privkey: str = Field(description="SSH private key") | ||
|
|
||
|
|
||
| class VerifyAuthRequest(BaseRequestModel): | ||
| """Request to verify authentication.""" | ||
|
|
||
| echo: str = Field(description="Echo string for auth verification") |
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,84 @@ | ||
| """ | ||
| Response DTOs for auth system. | ||
| Shared between Client SDK and Manager API. | ||
| """ | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| from typing import Optional | ||
|
|
||
| from pydantic import Field | ||
|
|
||
| from ai.backend.common.api_handlers import BaseResponseModel | ||
|
|
||
| from .types import AuthSuccessResponse | ||
|
|
||
| __all__ = ( | ||
| "AuthorizeResponse", | ||
| "GetRoleResponse", | ||
| "SignupResponse", | ||
| "SignoutResponse", | ||
| "UpdateFullNameResponse", | ||
| "UpdatePasswordResponse", | ||
| "UpdatePasswordNoAuthResponse", | ||
| "GetSSHKeypairResponse", | ||
| "SSHKeypairResponse", | ||
| ) | ||
|
|
||
|
|
||
| class AuthorizeResponse(BaseResponseModel): | ||
| """Response for authorization.""" | ||
|
|
||
| data: AuthSuccessResponse = Field(description="Authorization result data") | ||
|
|
||
|
|
||
| class GetRoleResponse(BaseResponseModel): | ||
| """Response for get role.""" | ||
|
|
||
| global_role: str = Field(description="Global role") | ||
| domain_role: str = Field(description="Domain role") | ||
| group_role: Optional[str] = Field(default=None, description="Group role") | ||
|
|
||
|
|
||
| class SignupResponse(BaseResponseModel): | ||
| """Response for signup.""" | ||
|
|
||
| access_key: str = Field(description="Generated access key") | ||
| secret_key: str = Field(description="Generated secret key") | ||
|
|
||
|
|
||
| class SignoutResponse(BaseResponseModel): | ||
| """Response for signout (empty response).""" | ||
|
|
||
| pass | ||
|
|
||
|
|
||
| class UpdateFullNameResponse(BaseResponseModel): | ||
| """Response for update full name (empty response).""" | ||
|
|
||
| pass | ||
|
|
||
|
|
||
| class UpdatePasswordResponse(BaseResponseModel): | ||
| """Response for update password.""" | ||
|
|
||
| error_msg: Optional[str] = Field(default=None, description="Error message if failed") | ||
|
|
||
|
|
||
| class UpdatePasswordNoAuthResponse(BaseResponseModel): | ||
| """Response for update password without auth.""" | ||
|
|
||
| password_changed_at: str = Field(description="Timestamp when password was changed (ISO 8601)") | ||
|
|
||
|
|
||
| class GetSSHKeypairResponse(BaseResponseModel): | ||
| """Response for get SSH keypair (public key only).""" | ||
|
|
||
| ssh_public_key: str = Field(description="SSH public key") | ||
|
|
||
|
|
||
| class SSHKeypairResponse(BaseResponseModel): | ||
| """Response for generate/upload SSH keypair (both keys).""" | ||
|
|
||
| ssh_public_key: str = Field(description="SSH public key") | ||
| ssh_private_key: str = Field(description="SSH private key") |
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
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Have you checked if moving the directory might cause issues? Also, it doesn't seem necessary to change the existing handlers this time. I'd like to clarify the current work direction, and I think declaring it deprecated is too hasty a decision. To mark it deprecated, we need to have a new alternative API already in place to guide users.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
when i had a investigate before migrating,
I thought it could be alright if we retain sub-servers name the same.
But i understand the concern, and it seems subapp would detect ./auth.py faster than /auth/init.py
it will be much more safer to migrate into legacy with handler/adapter pattern fully assured.
thanks you!