Skip to content

Commit

Permalink
Implement grantPrivilegeV2/revokePrivilegeV2 (#1190)
Browse files Browse the repository at this point in the history
Signed-off-by: yhmo <[email protected]>
  • Loading branch information
yhmo authored Nov 20, 2024
1 parent edfd1f8 commit ad0fe75
Show file tree
Hide file tree
Showing 7 changed files with 85 additions and 14 deletions.
8 changes: 8 additions & 0 deletions src/main/java/io/milvus/v2/client/MilvusClientV2.java
Original file line number Diff line number Diff line change
Expand Up @@ -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

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,5 @@
public class PrivilegeGroup {
private String groupName;
@Builder.Default
private List<Privilege> privileges = new ArrayList<>();
private List<String> privileges = new ArrayList<>();
}
42 changes: 36 additions & 6 deletions src/main/java/io/milvus/v2/service/rbac/RBACService.java
Original file line number Diff line number Diff line change
Expand Up @@ -250,9 +250,9 @@ public ListPrivilegeGroupsResp listPrivilegeGroups(MilvusServiceGrpc.MilvusServi

List<PrivilegeGroup> privilegeGroups = new ArrayList<>();
response.getPrivilegeGroupsList().forEach((privilegeGroupInfo)->{
List<Privilege> privileges = new ArrayList<>();
List<String> 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());
});
Expand All @@ -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());
Expand All @@ -282,13 +282,43 @@ 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());
rpcUtils.handleResponse(title, response);

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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -32,5 +31,5 @@
public class AddPrivilegesToGroupReq {
private String groupName;
@Builder.Default
private List<Privilege> privileges = new ArrayList<>();
private List<String> privileges = new ArrayList<>();
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -32,5 +31,5 @@
public class RemovePrivilegesFromGroupReq {
private String groupName;
@Builder.Default
private List<Privilege> privileges = new ArrayList<>();
private List<String> privileges = new ArrayList<>();
}
Original file line number Diff line number Diff line change
@@ -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;
}

0 comments on commit ad0fe75

Please sign in to comment.