sunyuhan1998 commented on code in PR #11210: URL: https://github.com/apache/gravitino/pull/11210#discussion_r3298032081
########## clients/client-python/gravitino/dto/authorization/securable_object_dto.py: ########## @@ -0,0 +1,119 @@ +# 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 List, Optional + +from dataclasses_json import config, dataclass_json + +from gravitino.api.authorization.privileges import Privilege +from gravitino.api.authorization.securable_objects import SecurableObject +from gravitino.api.metadata_object import MetadataObject +from gravitino.dto.authorization.privilege_dto import PrivilegeDTO + + +def _encode_metadata_type(type_: MetadataObject.Type) -> str: + return type_.value + + +def _decode_metadata_type(val: str) -> MetadataObject.Type: + return MetadataObject.Type(val) + + +@dataclass_json +@dataclass +class SecurableObjectDTO(SecurableObject): + """Data transfer object representing a securable object.""" + + _full_name: str = field(metadata=config(field_name="fullName")) + _type: MetadataObject.Type = field( + metadata=config( + field_name="type", + encoder=_encode_metadata_type, + decoder=_decode_metadata_type, + ) + ) + _privileges: List[PrivilegeDTO] = field( + default_factory=list, metadata=config(field_name="privileges") + ) + + def __post_init__(self): + if self._full_name and "." in self._full_name: + index = self._full_name.rfind(".") + self._parent = self._full_name[:index] + self._name = self._full_name[index + 1 :] + else: + self._parent = None + self._name = self._full_name if self._full_name else "" + + def parent(self) -> Optional[str]: + return self._parent + + def name(self) -> str: + return self._name + + def full_name(self) -> str: + return self._full_name + + def type(self) -> MetadataObject.Type: + return self._type + + def privileges(self) -> List[Privilege]: + return list(self._privileges) if self._privileges else [] + + def __eq__(self, other: object) -> bool: + if not isinstance(other, SecurableObject): + return False + return self._full_name == other.full_name() and self._type == other.type() + + def __hash__(self) -> int: + return hash((self._full_name, self._type)) Review Comment: This is intentional — the Java `SecurableObjectDTO` in `common` module also does not override `equals/hashCode` (it uses default reference equality). Only the API-layer `SecurableObjects.SecurableObjectImpl` includes privileges in equality. The Python DTO follows the same pattern as the Java DTO. -- 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]
