Skip to content
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

fix: [2.4] fix list aliases rpc call and grant/revoke v2 #2404

Merged
merged 2 commits into from
Dec 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions pymilvus/client/grpc_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -1868,8 +1868,8 @@ def grant_privilege_v2(
self,
role_name: str,
privilege: str,
collection_name: str,
db_name: Optional[str] = None,
collection_name: Optional[str] = None,
timeout: Optional[float] = None,
**kwargs,
):
Expand All @@ -1888,8 +1888,8 @@ def revoke_privilege_v2(
self,
role_name: str,
privilege: str,
collection_name: str,
db_name: Optional[str] = None,
collection_name: Optional[str] = None,
timeout: Optional[float] = None,
**kwargs,
):
Expand Down
3 changes: 1 addition & 2 deletions pymilvus/client/prepare.py
Original file line number Diff line number Diff line change
Expand Up @@ -1337,12 +1337,11 @@ def operate_privilege_v2_request(
check_pass_param(
role_name=role_name,
privilege=privilege,
collection_name=collection_name,
operate_privilege_type=operate_privilege_type,
)
if db_name:
check_pass_param(db_name=db_name)
if collection_name:
check_pass_param(collection_name=collection_name)
return milvus_types.OperatePrivilegeV2Request(
role=milvus_types.RoleEntity(name=role_name),
grantor=milvus_types.GrantorEntity(
Expand Down
8 changes: 4 additions & 4 deletions pymilvus/milvus_client/milvus_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -1008,17 +1008,17 @@ def grant_privilege_v2(
self,
role_name: str,
privilege: str,
collection_name: str,
db_name: Optional[str] = None,
collection_name: Optional[str] = None,
timeout: Optional[float] = None,
**kwargs,
):
conn = self._get_connection()
conn.grant_privilege_v2(
role_name,
privilege,
collection_name,
db_name=db_name,
collection_name=collection_name,
timeout=timeout,
**kwargs,
)
Expand All @@ -1027,17 +1027,17 @@ def revoke_privilege_v2(
self,
role_name: str,
privilege: str,
collection_name: str,
db_name: Optional[str] = None,
collection_name: Optional[str] = None,
timeout: Optional[float] = None,
**kwargs,
):
conn = self._get_connection()
conn.revoke_privilege_v2(
role_name,
privilege,
collection_name,
db_name=db_name,
collection_name=collection_name,
timeout=timeout,
**kwargs,
)
Expand Down
34 changes: 18 additions & 16 deletions pymilvus/orm/role.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,48 +178,50 @@ def revoke(self, object: str, object_name: str, privilege: str, db_name: str = "
self._name, object, object_name, privilege, db_name
)

def grant_v2(
self, privilege: str, db_name: Optional[str] = None, collection_name: Optional[str] = None
):
def grant_v2(self, privilege: str, collection_name: str, db_name: Optional[str] = None):
"""Grant a privilege for the role
:param privilege: privilege name.
:type privilege: str
:param db_name: db name. Optional
:type db_name: str
:param collection_name: collection name. Optional
:param collection_name: collection name.
:type collection_name: str
:param db_name: db name. Optional. If None, use the default db.
:type db_name: str

:example:
>>> from pymilvus import connections
>>> from pymilvus.orm.role import Role
>>> connections.connect()
>>> role = Role(role_name)
>>> role.grant_v2("Insert", db_name, collection_name)
>>> role.grant_v2("Insert", collection_name, db_name=db_name)
"""
return self._get_connection().grant_privilege_v2(
self._name, privilege, db_name=db_name, collection_name=collection_name
self._name,
privilege,
collection_name,
db_name=db_name,
)

def revoke_v2(
self, privilege: str, db_name: Optional[str] = None, collection_name: Optional[str] = None
):
def revoke_v2(self, privilege: str, collection_name: str, db_name: Optional[str] = None):
"""Revoke a privilege for the role
:param privilege: privilege name.
:type privilege: str
:param db_name: db name. Optional
:type db_name: str
:param collection_name: collection name. Optional
:param collection_name: collection name.
:type collection_name: str
:param db_name: db name. Optional. If None, use the default db.
:type db_name: str

:example:
>>> from pymilvus import connections
>>> from pymilvus.orm.role import Role
>>> connections.connect()
>>> role = Role(role_name)
>>> role.revoke_v2("Insert", db_name, collection_name)
>>> role.revoke_v2("Insert", collection_name, db_name=db_name)
"""
return self._get_connection().revoke_privilege_v2(
self._name, privilege, db_name=db_name, collection_name=collection_name
self._name,
privilege,
collection_name,
db_name=db_name,
)

def list_grant(self, object: str, object_name: str, db_name: str = ""):
Expand Down
2 changes: 1 addition & 1 deletion pymilvus/orm/utility.py
Original file line number Diff line number Diff line change
Expand Up @@ -774,7 +774,7 @@ def list_aliases(collection_name: str, timeout: Optional[float] = None, using: s
['tom']
"""
conn = _get_connection(using)
resp = conn.describe_collection(collection_name, timeout=timeout)
resp = conn.list_aliases(collection_name, timeout=timeout)
return resp["aliases"]


Expand Down
Loading