Skip to content

Commit

Permalink
fix: grant ManualCompact api doesn't work
Browse files Browse the repository at this point in the history
cause RBAC require to check collection name, but ManualCompact rpc pass
collection id in request, so grant ManualCompact api doesn't work.

This PR refine compact api impl to pass collection name in request.

Signed-off-by: Wei Liu <[email protected]>
  • Loading branch information
weiliu1031 committed Nov 29, 2024
1 parent 24cba21 commit f5132a5
Show file tree
Hide file tree
Showing 12 changed files with 450 additions and 336 deletions.
3 changes: 2 additions & 1 deletion pymilvus/client/grpc_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -1590,12 +1590,13 @@ def compact(
timeout: Optional[float] = None,
**kwargs,
) -> int:
# should be removed, but to be compatible with old milvus server, keep it for now.
request = Prepare.describe_collection_request(collection_name)
rf = self._stub.DescribeCollection.future(request, timeout=timeout)
response = rf.result()
check_status(response.status)

req = Prepare.manual_compaction(response.collectionID, is_clustering)
req = Prepare.manual_compaction(response.collectionID, collection_name, is_clustering)
future = self._stub.ManualCompaction.future(req, timeout=timeout)
response = future.result()
check_status(response.status)
Expand Down
3 changes: 2 additions & 1 deletion pymilvus/client/prepare.py
Original file line number Diff line number Diff line change
Expand Up @@ -1288,7 +1288,7 @@ def load_balance_request(
)

@classmethod
def manual_compaction(cls, collection_id: int, is_clustering: bool):
def manual_compaction(cls, collection_id: int, collection_name: str, is_clustering: bool):
if collection_id is None or not isinstance(collection_id, int):
raise ParamError(message=f"collection_id value {collection_id} is illegal")

Expand All @@ -1297,6 +1297,7 @@ def manual_compaction(cls, collection_id: int, is_clustering: bool):

request = milvus_types.ManualCompactionRequest()
request.collectionID = collection_id
request.collection_name = collection_name
request.majorCompaction = is_clustering

return request
Expand Down
96 changes: 48 additions & 48 deletions pymilvus/grpc_gen/common_pb2.py

Large diffs are not rendered by default.

26 changes: 24 additions & 2 deletions pymilvus/grpc_gen/common_pb2.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ class MsgType(int, metaclass=_enum_type_wrapper.EnumTypeWrapper):
Connect: _ClassVar[MsgType]
ListClientInfos: _ClassVar[MsgType]
AllocTimestamp: _ClassVar[MsgType]
Replicate: _ClassVar[MsgType]
CreateCredential: _ClassVar[MsgType]
GetCredential: _ClassVar[MsgType]
DeleteCredential: _ClassVar[MsgType]
Expand Down Expand Up @@ -322,6 +323,15 @@ class ObjectPrivilege(int, metaclass=_enum_type_wrapper.EnumTypeWrapper):
PrivilegeDropPrivilegeGroup: _ClassVar[ObjectPrivilege]
PrivilegeListPrivilegeGroups: _ClassVar[ObjectPrivilege]
PrivilegeOperatePrivilegeGroup: _ClassVar[ObjectPrivilege]
PrivilegeGroupClusterReadOnly: _ClassVar[ObjectPrivilege]
PrivilegeGroupClusterReadWrite: _ClassVar[ObjectPrivilege]
PrivilegeGroupClusterAdmin: _ClassVar[ObjectPrivilege]
PrivilegeGroupDatabaseReadOnly: _ClassVar[ObjectPrivilege]
PrivilegeGroupDatabaseReadWrite: _ClassVar[ObjectPrivilege]
PrivilegeGroupDatabaseAdmin: _ClassVar[ObjectPrivilege]
PrivilegeGroupCollectionReadOnly: _ClassVar[ObjectPrivilege]
PrivilegeGroupCollectionReadWrite: _ClassVar[ObjectPrivilege]
PrivilegeGroupCollectionAdmin: _ClassVar[ObjectPrivilege]

class StateCode(int, metaclass=_enum_type_wrapper.EnumTypeWrapper):
__slots__ = ()
Expand Down Expand Up @@ -506,6 +516,7 @@ DataNodeTt: MsgType
Connect: MsgType
ListClientInfos: MsgType
AllocTimestamp: MsgType
Replicate: MsgType
CreateCredential: MsgType
GetCredential: MsgType
DeleteCredential: MsgType
Expand Down Expand Up @@ -617,6 +628,15 @@ PrivilegeCreatePrivilegeGroup: ObjectPrivilege
PrivilegeDropPrivilegeGroup: ObjectPrivilege
PrivilegeListPrivilegeGroups: ObjectPrivilege
PrivilegeOperatePrivilegeGroup: ObjectPrivilege
PrivilegeGroupClusterReadOnly: ObjectPrivilege
PrivilegeGroupClusterReadWrite: ObjectPrivilege
PrivilegeGroupClusterAdmin: ObjectPrivilege
PrivilegeGroupDatabaseReadOnly: ObjectPrivilege
PrivilegeGroupDatabaseReadWrite: ObjectPrivilege
PrivilegeGroupDatabaseAdmin: ObjectPrivilege
PrivilegeGroupCollectionReadOnly: ObjectPrivilege
PrivilegeGroupCollectionReadWrite: ObjectPrivilege
PrivilegeGroupCollectionAdmin: ObjectPrivilege
Initializing: StateCode
Healthy: StateCode
Abnormal: StateCode
Expand Down Expand Up @@ -724,12 +744,14 @@ class MsgBase(_message.Message):
def __init__(self, msg_type: _Optional[_Union[MsgType, str]] = ..., msgID: _Optional[int] = ..., timestamp: _Optional[int] = ..., sourceID: _Optional[int] = ..., targetID: _Optional[int] = ..., properties: _Optional[_Mapping[str, str]] = ..., replicateInfo: _Optional[_Union[ReplicateInfo, _Mapping]] = ...) -> None: ...

class ReplicateInfo(_message.Message):
__slots__ = ("isReplicate", "msgTimestamp")
__slots__ = ("isReplicate", "msgTimestamp", "replicateID")
ISREPLICATE_FIELD_NUMBER: _ClassVar[int]
MSGTIMESTAMP_FIELD_NUMBER: _ClassVar[int]
REPLICATEID_FIELD_NUMBER: _ClassVar[int]
isReplicate: bool
msgTimestamp: int
def __init__(self, isReplicate: bool = ..., msgTimestamp: _Optional[int] = ...) -> None: ...
replicateID: str
def __init__(self, isReplicate: bool = ..., msgTimestamp: _Optional[int] = ..., replicateID: _Optional[str] = ...) -> None: ...

class MsgHeader(_message.Message):
__slots__ = ("base",)
Expand Down
438 changes: 222 additions & 216 deletions pymilvus/grpc_gen/milvus_pb2.py

Large diffs are not rendered by default.

39 changes: 35 additions & 4 deletions pymilvus/grpc_gen/milvus_pb2.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ class OperateUserRoleType(int, metaclass=_enum_type_wrapper.EnumTypeWrapper):
AddUserToRole: _ClassVar[OperateUserRoleType]
RemoveUserFromRole: _ClassVar[OperateUserRoleType]

class PrivilegeLevel(int, metaclass=_enum_type_wrapper.EnumTypeWrapper):
__slots__ = ()
Cluster: _ClassVar[PrivilegeLevel]
Database: _ClassVar[PrivilegeLevel]
Collection: _ClassVar[PrivilegeLevel]

class OperatePrivilegeType(int, metaclass=_enum_type_wrapper.EnumTypeWrapper):
__slots__ = ()
Grant: _ClassVar[OperatePrivilegeType]
Expand All @@ -45,6 +51,9 @@ AddPrivilegesToGroup: OperatePrivilegeGroupType
RemovePrivilegesFromGroup: OperatePrivilegeGroupType
AddUserToRole: OperateUserRoleType
RemoveUserFromRole: OperateUserRoleType
Cluster: PrivilegeLevel
Database: PrivilegeLevel
Collection: PrivilegeLevel
Grant: OperatePrivilegeType
Revoke: OperatePrivilegeType
Unknown: QuotaState
Expand Down Expand Up @@ -1221,14 +1230,18 @@ class LoadBalanceRequest(_message.Message):
def __init__(self, base: _Optional[_Union[_common_pb2.MsgBase, _Mapping]] = ..., src_nodeID: _Optional[int] = ..., dst_nodeIDs: _Optional[_Iterable[int]] = ..., sealed_segmentIDs: _Optional[_Iterable[int]] = ..., collectionName: _Optional[str] = ..., db_name: _Optional[str] = ...) -> None: ...

class ManualCompactionRequest(_message.Message):
__slots__ = ("collectionID", "timetravel", "majorCompaction")
__slots__ = ("collectionID", "timetravel", "majorCompaction", "collection_name", "db_name")
COLLECTIONID_FIELD_NUMBER: _ClassVar[int]
TIMETRAVEL_FIELD_NUMBER: _ClassVar[int]
MAJORCOMPACTION_FIELD_NUMBER: _ClassVar[int]
COLLECTION_NAME_FIELD_NUMBER: _ClassVar[int]
DB_NAME_FIELD_NUMBER: _ClassVar[int]
collectionID: int
timetravel: int
majorCompaction: bool
def __init__(self, collectionID: _Optional[int] = ..., timetravel: _Optional[int] = ..., majorCompaction: bool = ...) -> None: ...
collection_name: str
db_name: str
def __init__(self, collectionID: _Optional[int] = ..., timetravel: _Optional[int] = ..., majorCompaction: bool = ..., collection_name: _Optional[str] = ..., db_name: _Optional[str] = ...) -> None: ...

class ManualCompactionResponse(_message.Message):
__slots__ = ("status", "compactionID", "compactionPlanCount")
Expand Down Expand Up @@ -1710,14 +1723,32 @@ class SelectGrantResponse(_message.Message):
def __init__(self, status: _Optional[_Union[_common_pb2.Status, _Mapping]] = ..., entities: _Optional[_Iterable[_Union[GrantEntity, _Mapping]]] = ...) -> None: ...

class OperatePrivilegeRequest(_message.Message):
__slots__ = ("base", "entity", "type")
__slots__ = ("base", "entity", "type", "version")
BASE_FIELD_NUMBER: _ClassVar[int]
ENTITY_FIELD_NUMBER: _ClassVar[int]
TYPE_FIELD_NUMBER: _ClassVar[int]
VERSION_FIELD_NUMBER: _ClassVar[int]
base: _common_pb2.MsgBase
entity: GrantEntity
type: OperatePrivilegeType
def __init__(self, base: _Optional[_Union[_common_pb2.MsgBase, _Mapping]] = ..., entity: _Optional[_Union[GrantEntity, _Mapping]] = ..., type: _Optional[_Union[OperatePrivilegeType, str]] = ...) -> None: ...
version: str
def __init__(self, base: _Optional[_Union[_common_pb2.MsgBase, _Mapping]] = ..., entity: _Optional[_Union[GrantEntity, _Mapping]] = ..., type: _Optional[_Union[OperatePrivilegeType, str]] = ..., version: _Optional[str] = ...) -> None: ...

class OperatePrivilegeV2Request(_message.Message):
__slots__ = ("base", "role", "grantor", "type", "db_name", "collection_name")
BASE_FIELD_NUMBER: _ClassVar[int]
ROLE_FIELD_NUMBER: _ClassVar[int]
GRANTOR_FIELD_NUMBER: _ClassVar[int]
TYPE_FIELD_NUMBER: _ClassVar[int]
DB_NAME_FIELD_NUMBER: _ClassVar[int]
COLLECTION_NAME_FIELD_NUMBER: _ClassVar[int]
base: _common_pb2.MsgBase
role: RoleEntity
grantor: GrantorEntity
type: OperatePrivilegeType
db_name: str
collection_name: str
def __init__(self, base: _Optional[_Union[_common_pb2.MsgBase, _Mapping]] = ..., role: _Optional[_Union[RoleEntity, _Mapping]] = ..., grantor: _Optional[_Union[GrantorEntity, _Mapping]] = ..., type: _Optional[_Union[OperatePrivilegeType, str]] = ..., db_name: _Optional[str] = ..., collection_name: _Optional[str] = ...) -> None: ...

class UserInfo(_message.Message):
__slots__ = ("user", "password", "roles")
Expand Down
33 changes: 33 additions & 0 deletions pymilvus/grpc_gen/milvus_pb2_grpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,11 @@ def __init__(self, channel):
request_serializer=milvus__pb2.OperatePrivilegeRequest.SerializeToString,
response_deserializer=common__pb2.Status.FromString,
)
self.OperatePrivilegeV2 = channel.unary_unary(
'/milvus.proto.milvus.MilvusService/OperatePrivilegeV2',
request_serializer=milvus__pb2.OperatePrivilegeV2Request.SerializeToString,
response_deserializer=common__pb2.Status.FromString,
)
self.SelectGrant = channel.unary_unary(
'/milvus.proto.milvus.MilvusService/SelectGrant',
request_serializer=milvus__pb2.SelectGrantRequest.SerializeToString,
Expand Down Expand Up @@ -889,6 +894,12 @@ def OperatePrivilege(self, request, context):
context.set_details('Method not implemented!')
raise NotImplementedError('Method not implemented!')

def OperatePrivilegeV2(self, request, context):
"""Missing associated documentation comment in .proto file."""
context.set_code(grpc.StatusCode.UNIMPLEMENTED)
context.set_details('Method not implemented!')
raise NotImplementedError('Method not implemented!')

def SelectGrant(self, request, context):
"""Missing associated documentation comment in .proto file."""
context.set_code(grpc.StatusCode.UNIMPLEMENTED)
Expand Down Expand Up @@ -1384,6 +1395,11 @@ def add_MilvusServiceServicer_to_server(servicer, server):
request_deserializer=milvus__pb2.OperatePrivilegeRequest.FromString,
response_serializer=common__pb2.Status.SerializeToString,
),
'OperatePrivilegeV2': grpc.unary_unary_rpc_method_handler(
servicer.OperatePrivilegeV2,
request_deserializer=milvus__pb2.OperatePrivilegeV2Request.FromString,
response_serializer=common__pb2.Status.SerializeToString,
),
'SelectGrant': grpc.unary_unary_rpc_method_handler(
servicer.SelectGrant,
request_deserializer=milvus__pb2.SelectGrantRequest.FromString,
Expand Down Expand Up @@ -2651,6 +2667,23 @@ def OperatePrivilege(request,
options, channel_credentials,
insecure, call_credentials, compression, wait_for_ready, timeout, metadata)

@staticmethod
def OperatePrivilegeV2(request,
target,
options=(),
channel_credentials=None,
call_credentials=None,
insecure=False,
compression=None,
wait_for_ready=None,
timeout=None,
metadata=None):
return grpc.experimental.unary_unary(request, target, '/milvus.proto.milvus.MilvusService/OperatePrivilegeV2',
milvus__pb2.OperatePrivilegeV2Request.SerializeToString,
common__pb2.Status.FromString,
options, channel_credentials,
insecure, call_credentials, compression, wait_for_ready, timeout, metadata)

@staticmethod
def SelectGrant(request,
target,
Expand Down
Loading

0 comments on commit f5132a5

Please sign in to comment.