diff --git a/src/main/java/io/milvus/v2/client/MilvusClientV2.java b/src/main/java/io/milvus/v2/client/MilvusClientV2.java index af3f09694..a1d894fa4 100644 --- a/src/main/java/io/milvus/v2/client/MilvusClientV2.java +++ b/src/main/java/io/milvus/v2/client/MilvusClientV2.java @@ -745,6 +745,14 @@ public void removePrivilegesFromGroup(RemovePrivilegesFromGroupReq request) { retry(()->rbacService.removePrivilegesFromGroup(this.getRpcStub(), request)); } + public void grantPrivilegeV2(GrantPrivilegeReqV2 request) { + retry(()->rbacService.grantPrivilegeV2(this.getRpcStub(), request)); + } + + public void revokePrivilegeV2(RevokePrivilegeReqV2 request) { + retry(()->rbacService.revokePrivilegeV2(this.getRpcStub(), request)); + } + // Utility Operations /** diff --git a/src/main/java/io/milvus/v2/service/rbac/PrivilegeGroup.java b/src/main/java/io/milvus/v2/service/rbac/PrivilegeGroup.java index 8a1bd6754..f7c95a1ea 100644 --- a/src/main/java/io/milvus/v2/service/rbac/PrivilegeGroup.java +++ b/src/main/java/io/milvus/v2/service/rbac/PrivilegeGroup.java @@ -31,5 +31,5 @@ public class PrivilegeGroup { private String groupName; @Builder.Default - private List privileges = new ArrayList<>(); + private List privileges = new ArrayList<>(); } diff --git a/src/main/java/io/milvus/v2/service/rbac/RBACService.java b/src/main/java/io/milvus/v2/service/rbac/RBACService.java index c1b4d16c7..c14b33072 100644 --- a/src/main/java/io/milvus/v2/service/rbac/RBACService.java +++ b/src/main/java/io/milvus/v2/service/rbac/RBACService.java @@ -250,9 +250,9 @@ public ListPrivilegeGroupsResp listPrivilegeGroups(MilvusServiceGrpc.MilvusServi List privilegeGroups = new ArrayList<>(); response.getPrivilegeGroupsList().forEach((privilegeGroupInfo)->{ - List privileges = new ArrayList<>(); + List privileges = new ArrayList<>(); privilegeGroupInfo.getPrivilegesList().forEach((privilege)->{ - privileges.add(Privilege.builder().name(privilege.getName()).build()); + privileges.add(privilege.getName()); }); privilegeGroups.add(PrivilegeGroup.builder().privileges(privileges).build()); }); @@ -267,8 +267,8 @@ public Void addPrivilegesToGroup(MilvusServiceGrpc.MilvusServiceBlockingStub blo OperatePrivilegeGroupRequest.Builder builder = OperatePrivilegeGroupRequest.newBuilder() .setGroupName(request.getGroupName()) .setType(OperatePrivilegeGroupType.AddPrivilegesToGroup); - for (Privilege privilege : request.getPrivileges()) { - builder.addPrivileges(PrivilegeEntity.newBuilder().setName(privilege.getName()).build()); + for (String privilege : request.getPrivileges()) { + builder.addPrivileges(PrivilegeEntity.newBuilder().setName(privilege).build()); } Status response = blockingStub.operatePrivilegeGroup(builder.build()); @@ -282,8 +282,8 @@ public Void removePrivilegesFromGroup(MilvusServiceGrpc.MilvusServiceBlockingStu OperatePrivilegeGroupRequest.Builder builder = OperatePrivilegeGroupRequest.newBuilder() .setGroupName(request.getGroupName()) .setType(OperatePrivilegeGroupType.RemovePrivilegesFromGroup); - for (Privilege privilege : request.getPrivileges()) { - builder.addPrivileges(PrivilegeEntity.newBuilder().setName(privilege.getName()).build()); + for (String privilege : request.getPrivileges()) { + builder.addPrivileges(PrivilegeEntity.newBuilder().setName(privilege).build()); } Status response = blockingStub.operatePrivilegeGroup(builder.build()); @@ -291,4 +291,34 @@ public Void removePrivilegesFromGroup(MilvusServiceGrpc.MilvusServiceBlockingStu return null; } + + public Void grantPrivilegeV2(MilvusServiceGrpc.MilvusServiceBlockingStub blockingStub, GrantPrivilegeReqV2 request) { + String title = "grantPrivilegeV2"; + OperatePrivilegeV2Request.Builder builder = OperatePrivilegeV2Request.newBuilder() + .setRole(RoleEntity.newBuilder().setName(request.getRoleName()).build()) + .setGrantor(GrantorEntity.newBuilder().setPrivilege(PrivilegeEntity.newBuilder().setName(request.getPrivilege()).build()).build()) + .setDbName(request.getDbName()) + .setCollectionName(request.getCollectionName()) + .setType(OperatePrivilegeType.Grant); + + Status response = blockingStub.operatePrivilegeV2(builder.build()); + rpcUtils.handleResponse(title, response); + + return null; + } + + public Void revokePrivilegeV2(MilvusServiceGrpc.MilvusServiceBlockingStub blockingStub, RevokePrivilegeReqV2 request) { + String title = "revokePrivilegeV2"; + OperatePrivilegeV2Request.Builder builder = OperatePrivilegeV2Request.newBuilder() + .setRole(RoleEntity.newBuilder().setName(request.getRoleName()).build()) + .setGrantor(GrantorEntity.newBuilder().setPrivilege(PrivilegeEntity.newBuilder().setName(request.getPrivilege()).build()).build()) + .setDbName(request.getDbName()) + .setCollectionName(request.getCollectionName()) + .setType(OperatePrivilegeType.Revoke); + + Status response = blockingStub.operatePrivilegeV2(builder.build()); + rpcUtils.handleResponse(title, response); + + return null; + } } diff --git a/src/main/java/io/milvus/v2/service/rbac/request/AddPrivilegesToGroupReq.java b/src/main/java/io/milvus/v2/service/rbac/request/AddPrivilegesToGroupReq.java index 9d3d2475e..49141b231 100644 --- a/src/main/java/io/milvus/v2/service/rbac/request/AddPrivilegesToGroupReq.java +++ b/src/main/java/io/milvus/v2/service/rbac/request/AddPrivilegesToGroupReq.java @@ -19,7 +19,6 @@ package io.milvus.v2.service.rbac.request; -import io.milvus.v2.service.rbac.Privilege; import lombok.Builder; import lombok.Data; import lombok.experimental.SuperBuilder; @@ -32,5 +31,5 @@ public class AddPrivilegesToGroupReq { private String groupName; @Builder.Default - private List privileges = new ArrayList<>(); + private List privileges = new ArrayList<>(); } diff --git a/src/main/java/io/milvus/v2/service/rbac/Privilege.java b/src/main/java/io/milvus/v2/service/rbac/request/GrantPrivilegeReqV2.java similarity index 81% rename from src/main/java/io/milvus/v2/service/rbac/Privilege.java rename to src/main/java/io/milvus/v2/service/rbac/request/GrantPrivilegeReqV2.java index 8153a8a35..09ab6d984 100644 --- a/src/main/java/io/milvus/v2/service/rbac/Privilege.java +++ b/src/main/java/io/milvus/v2/service/rbac/request/GrantPrivilegeReqV2.java @@ -17,13 +17,16 @@ * under the License. */ -package io.milvus.v2.service.rbac; +package io.milvus.v2.service.rbac.request; import lombok.Data; import lombok.experimental.SuperBuilder; @Data @SuperBuilder -public class Privilege { - private String name; +public class GrantPrivilegeReqV2 { + private String roleName; + private String privilege; + private String dbName; + private String collectionName; } diff --git a/src/main/java/io/milvus/v2/service/rbac/request/RemovePrivilegesFromGroupReq.java b/src/main/java/io/milvus/v2/service/rbac/request/RemovePrivilegesFromGroupReq.java index b7ad89e6c..2d35df1ef 100644 --- a/src/main/java/io/milvus/v2/service/rbac/request/RemovePrivilegesFromGroupReq.java +++ b/src/main/java/io/milvus/v2/service/rbac/request/RemovePrivilegesFromGroupReq.java @@ -19,7 +19,6 @@ package io.milvus.v2.service.rbac.request; -import io.milvus.v2.service.rbac.Privilege; import lombok.Builder; import lombok.Data; import lombok.experimental.SuperBuilder; @@ -32,5 +31,5 @@ public class RemovePrivilegesFromGroupReq { private String groupName; @Builder.Default - private List privileges = new ArrayList<>(); + private List privileges = new ArrayList<>(); } diff --git a/src/main/java/io/milvus/v2/service/rbac/request/RevokePrivilegeReqV2.java b/src/main/java/io/milvus/v2/service/rbac/request/RevokePrivilegeReqV2.java new file mode 100644 index 000000000..6dcdc0955 --- /dev/null +++ b/src/main/java/io/milvus/v2/service/rbac/request/RevokePrivilegeReqV2.java @@ -0,0 +1,32 @@ +/* + * 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. + */ + +package io.milvus.v2.service.rbac.request; + +import lombok.Data; +import lombok.experimental.SuperBuilder; + +@Data +@SuperBuilder +public class RevokePrivilegeReqV2 { + private String roleName; + private String privilege; + private String dbName; + private String collectionName; +}