-
Notifications
You must be signed in to change notification settings - Fork 847
[#10782] feat(client-python): add User authorization management #11058
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
jerryshao
merged 4 commits into
apache:main
from
sunyuhan1998:feature/python-sdk-auth-user
May 14, 2026
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
687f945
[#10782] feat(client-python): add User authorization management
sunyuhan1998 2236d4b
Merge branch 'main' into feature/python-sdk-auth-user
jerryshao a893a02
[#10782] feat(client-python): address PR #11058 review feedback
sunyuhan1998 e0bd2e0
[#10782] fix(client-python): fix pylint errors in delegate tests
sunyuhan1998 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
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,47 @@ | ||
| # 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 abc import abstractmethod | ||
|
|
||
| from gravitino.api.auditable import Auditable | ||
|
|
||
|
|
||
| class User(Auditable): | ||
| """The interface of a user. The user is a basic entity in the authorization system.""" | ||
|
|
||
| @abstractmethod | ||
| def name(self) -> str: | ||
| """ | ||
| The name of the user. | ||
|
|
||
| Returns: | ||
| str: The name of the user. | ||
| """ | ||
| raise NotImplementedError() | ||
|
|
||
| @abstractmethod | ||
| def roles(self) -> list[str]: | ||
| """ | ||
| The roles of the user. A user can have multiple roles. | ||
| Every role binds several privileges. | ||
|
|
||
| Returns: | ||
| list[str]: The role names of the user. | ||
| """ | ||
| raise NotImplementedError() |
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
91 changes: 91 additions & 0 deletions
91
clients/client-python/gravitino/dto/authorization/user_dto.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,91 @@ | ||
| # 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 dataclasses import dataclass, field | ||
| from typing import Optional | ||
|
|
||
| from dataclasses_json import config, dataclass_json | ||
|
|
||
| from gravitino.api.authorization.user import User | ||
| from gravitino.dto.audit_dto import AuditDTO | ||
|
|
||
|
|
||
| @dataclass_json | ||
| @dataclass | ||
| class UserDTO(User): | ||
| """Represents a User Data Transfer Object (DTO).""" | ||
|
|
||
| _name: str = field(metadata=config(field_name="name")) | ||
| _roles: tuple[str, ...] = field( | ||
| default_factory=tuple, metadata=config(field_name="roles") | ||
| ) | ||
| _audit: Optional[AuditDTO] = field( | ||
| default=None, metadata=config(field_name="audit") | ||
| ) | ||
|
|
||
| def __eq__(self, other: object) -> bool: | ||
| if not isinstance(other, UserDTO): | ||
| return False | ||
| return ( | ||
| self._name == other._name | ||
| and self._roles == other._roles | ||
| and self._audit == other._audit | ||
| ) | ||
|
|
||
| def __hash__(self) -> int: | ||
| return hash((self._name, tuple(self._roles), self._audit)) | ||
|
|
||
|
sunyuhan1998 marked this conversation as resolved.
|
||
| @staticmethod | ||
| def builder() -> UserDTO.Builder: | ||
| return UserDTO.Builder() | ||
|
|
||
| def name(self) -> str: | ||
| return self._name | ||
|
|
||
| def roles(self) -> list[str]: | ||
| return list(self._roles) if self._roles else [] | ||
|
|
||
| def audit_info(self) -> Optional[AuditDTO]: | ||
| return self._audit | ||
|
|
||
| class Builder: | ||
| """Helper class to build a UserDTO object.""" | ||
|
|
||
| def __init__(self) -> None: | ||
| self._name: str = "" | ||
| self._roles: tuple[str, ...] = () | ||
| self._audit: Optional[AuditDTO] = None | ||
|
|
||
| def with_name(self, name: str) -> UserDTO.Builder: | ||
| self._name = name | ||
| return self | ||
|
|
||
| def with_roles(self, roles: list[str]) -> UserDTO.Builder: | ||
| if roles is not None: | ||
| self._roles = tuple(roles) | ||
| return self | ||
|
|
||
| def with_audit(self, audit: AuditDTO) -> UserDTO.Builder: | ||
| self._audit = audit | ||
| return self | ||
|
|
||
| def build(self) -> UserDTO: | ||
| if not self._name: | ||
| raise ValueError("name cannot be null or empty") | ||
| return UserDTO(self._name, self._roles, self._audit) | ||
Oops, something went wrong.
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.