Skip to content

Commit

Permalink
DescribeRoleReq support dbName parameter (#1229)
Browse files Browse the repository at this point in the history
Signed-off-by: lentitude2tk <[email protected]>
  • Loading branch information
lentitude2tk authored Dec 12, 2024
1 parent 79a877e commit f29741b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 11 deletions.
27 changes: 16 additions & 11 deletions sdk-core/src/main/java/io/milvus/v2/service/rbac/RBACService.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import io.milvus.v2.service.rbac.response.DescribeRoleResp;
import io.milvus.v2.service.rbac.response.DescribeUserResp;
import io.milvus.v2.service.rbac.response.ListPrivilegeGroupsResp;
import org.apache.commons.lang3.StringUtils;

import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
Expand Down Expand Up @@ -57,22 +58,26 @@ public Void createRole(MilvusServiceGrpc.MilvusServiceBlockingStub blockingStub,

public DescribeRoleResp describeRole(MilvusServiceGrpc.MilvusServiceBlockingStub blockingStub, DescribeRoleReq request) {
String title = "describeRole";
GrantEntity.Builder builder = GrantEntity.newBuilder()
.setRole(RoleEntity.newBuilder()
.setName(request.getRoleName())
.build());
if (StringUtils.isNotEmpty(request.getDbName())) {
builder.setDbName(request.getDbName());
}

SelectGrantRequest selectGrantRequest = SelectGrantRequest.newBuilder()
.setEntity(GrantEntity.newBuilder()
.setRole(RoleEntity.newBuilder()
.setName(request.getRoleName())
.build())
.build())
.setEntity(builder.build())
.build();
SelectGrantResponse response = blockingStub.selectGrant(selectGrantRequest);
rpcUtils.handleResponse(title, response.getStatus());
DescribeRoleResp describeRoleResp = DescribeRoleResp.builder()
.grantInfos(response.getEntitiesList().stream().map(grantEntity -> DescribeRoleResp.GrantInfo.builder()
.dbName(grantEntity.getDbName())
.objectName(grantEntity.getObjectName())
.objectType(grantEntity.getObject().getName())
.privilege(grantEntity.getGrantor().getPrivilege().getName())
.grantor(grantEntity.getGrantor().getUser().getName())
.grantInfos(response.getEntitiesList().stream().map(entity -> DescribeRoleResp.GrantInfo.builder()
.dbName(entity.getDbName())
.objectName(entity.getObjectName())
.objectType(entity.getObject().getName())
.privilege(entity.getGrantor().getPrivilege().getName())
.grantor(entity.getGrantor().getUser().getName())
.build()).collect(Collectors.toList()))
.build();
return describeRoleResp;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,5 @@
@SuperBuilder
public class DescribeRoleReq {
private String roleName;
private String dbName;
}

0 comments on commit f29741b

Please sign in to comment.