32 lines
970 B
Python
32 lines
970 B
Python
from base58 import b58encode
|
|
|
|
from frostfs_sdk.models.dto.owner_id import OwnerId
|
|
from frostfs_sdk.protos.models.refs import types_pb2 as types_pb2_refs
|
|
|
|
class OwnerIdMapper:
|
|
@staticmethod
|
|
def to_grpc_message(owner_id: OwnerId) -> types_pb2_refs.OwnerID:
|
|
"""
|
|
Converts OwnerId DTO to gRPC message
|
|
"""
|
|
if not owner_id:
|
|
return None
|
|
|
|
return types_pb2_refs.OwnerID(
|
|
value=owner_id.to_hash(),
|
|
)
|
|
|
|
@staticmethod
|
|
def to_model(owner_id_grpc: types_pb2_refs.OwnerID) -> OwnerId:
|
|
"""
|
|
Converts gRPC message to OwnerId DTO
|
|
"""
|
|
if not owner_id_grpc or owner_id_grpc.ByteSize() == 0:
|
|
return None
|
|
|
|
try:
|
|
return OwnerId(
|
|
value=b58encode(owner_id_grpc.value).decode('utf-8')
|
|
)
|
|
except Exception as e:
|
|
raise ValueError(f"Failed to encode Base58 value: {owner_id_grpc.value}")
|