Skip to content

Commit

Permalink
Add rbac enhancement interfaces for V2
Browse files Browse the repository at this point in the history
Signed-off-by: yhmo <[email protected]>
  • Loading branch information
yhmo committed Nov 19, 2024
1 parent 3370072 commit cbf2706
Show file tree
Hide file tree
Showing 12 changed files with 414 additions and 268 deletions.
52 changes: 35 additions & 17 deletions src/main/java/io/milvus/v2/client/MilvusClientV2.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@
import io.milvus.v2.service.index.response.*;
import io.milvus.v2.service.partition.PartitionService;
import io.milvus.v2.service.partition.request.*;
import io.milvus.v2.service.rbac.RoleService;
import io.milvus.v2.service.rbac.UserService;
import io.milvus.v2.service.rbac.RBACService;
import io.milvus.v2.service.rbac.request.*;
import io.milvus.v2.service.rbac.response.*;
import io.milvus.v2.service.utility.UtilityService;
Expand Down Expand Up @@ -73,8 +72,7 @@ public class MilvusClientV2 {
private final IndexService indexService = new IndexService();
private final VectorService vectorService = new VectorService();
private final PartitionService partitionService = new PartitionService();
private final UserService userService = new UserService();
private final RoleService roleService = new RoleService();
private final RBACService rbacService = new RBACService();
private final UtilityService utilityService = new UtilityService();
private ConnectConfig connectConfig;
private RetryConfig retryConfig = RetryConfig.builder().build();
Expand Down Expand Up @@ -625,7 +623,7 @@ public void releasePartitions(ReleasePartitionsReq request) {
* @return List of String usernames
*/
public List<String> listUsers() {
return retry(()->userService.listUsers(this.getRpcStub()));
return retry(()->rbacService.listUsers(this.getRpcStub()));
}
/**
* describe user
Expand All @@ -634,31 +632,31 @@ public List<String> listUsers() {
* @return DescribeUserResp
*/
public DescribeUserResp describeUser(DescribeUserReq request) {
return retry(()->userService.describeUser(this.getRpcStub(), request));
return retry(()->rbacService.describeUser(this.getRpcStub(), request));
}
/**
* create user
*
* @param request create user request
*/
public void createUser(CreateUserReq request) {
retry(()->userService.createUser(this.getRpcStub(), request));
retry(()->rbacService.createUser(this.getRpcStub(), request));
}
/**
* change password
*
* @param request change password request
*/
public void updatePassword(UpdatePasswordReq request) {
retry(()->userService.updatePassword(this.getRpcStub(), request));
retry(()->rbacService.updatePassword(this.getRpcStub(), request));
}
/**
* drop user
*
* @param request drop user request
*/
public void dropUser(DropUserReq request) {
retry(()->userService.dropUser(this.getRpcStub(), request));
retry(()->rbacService.dropUser(this.getRpcStub(), request));
}
// role operations
/**
Expand All @@ -667,7 +665,7 @@ public void dropUser(DropUserReq request) {
* @return List of String role names
*/
public List<String> listRoles() {
return retry(()->roleService.listRoles(this.getRpcStub()));
return retry(()->rbacService.listRoles(this.getRpcStub()));
}
/**
* describe role
Expand All @@ -676,55 +674,75 @@ public List<String> listRoles() {
* @return DescribeRoleResp
*/
public DescribeRoleResp describeRole(DescribeRoleReq request) {
return retry(()->roleService.describeRole(this.getRpcStub(), request));
return retry(()->rbacService.describeRole(this.getRpcStub(), request));
}
/**
* create role
*
* @param request create role request
*/
public void createRole(CreateRoleReq request) {
retry(()->roleService.createRole(this.getRpcStub(), request));
retry(()->rbacService.createRole(this.getRpcStub(), request));
}
/**
* drop role
*
* @param request drop role request
*/
public void dropRole(DropRoleReq request) {
retry(()->roleService.dropRole(this.getRpcStub(), request));
retry(()->rbacService.dropRole(this.getRpcStub(), request));
}
/**
* grant privilege
*
* @param request grant privilege request
*/
public void grantPrivilege(GrantPrivilegeReq request) {
retry(()->roleService.grantPrivilege(this.getRpcStub(), request));
retry(()->rbacService.grantPrivilege(this.getRpcStub(), request));
}
/**
* revoke privilege
*
* @param request revoke privilege request
*/
public void revokePrivilege(RevokePrivilegeReq request) {
retry(()->roleService.revokePrivilege(this.getRpcStub(), request));
retry(()->rbacService.revokePrivilege(this.getRpcStub(), request));
}
/**
* grant role
*
* @param request grant role request
*/
public void grantRole(GrantRoleReq request) {
retry(()->roleService.grantRole(this.getRpcStub(), request));
retry(()->rbacService.grantRole(this.getRpcStub(), request));
}
/**
* revoke role
*
* @param request revoke role request
*/
public void revokeRole(RevokeRoleReq request) {
retry(()->roleService.revokeRole(this.getRpcStub(), request));
retry(()->rbacService.revokeRole(this.getRpcStub(), request));
}

public void createPrivilegeGroup(CreatePrivilegeGroupReq request) {
retry(()->rbacService.createPrivilegeGroup(this.getRpcStub(), request));
}

public void dropPrivilegeGroup(DropPrivilegeGroupReq request) {
retry(()->rbacService.dropPrivilegeGroup(this.getRpcStub(), request));
}

public ListPrivilegeGroupsResp listPrivilegeGroups(ListPrivilegeGroupsReq request) {
return retry(()->rbacService.listPrivilegeGroups(this.getRpcStub(), request));
}

public void addPrivilegesToGroup(AddPrivilegesToGroupReq request) {
retry(()->rbacService.addPrivilegesToGroup(this.getRpcStub(), request));
}

public void removePrivilegesFromGroup(RemovePrivilegesFromGroupReq request) {
retry(()->rbacService.removePrivilegesFromGroup(this.getRpcStub(), request));
}

// Utility Operations
Expand Down
10 changes: 10 additions & 0 deletions src/main/java/io/milvus/v2/service/rbac/Privilege.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package io.milvus.v2.service.rbac;

import lombok.Data;
import lombok.experimental.SuperBuilder;

@Data
@SuperBuilder
public class Privilege {
private String name;
}
16 changes: 16 additions & 0 deletions src/main/java/io/milvus/v2/service/rbac/PrivilegeGroup.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package io.milvus.v2.service.rbac;

import lombok.Builder;
import lombok.Data;
import lombok.experimental.SuperBuilder;

import java.util.ArrayList;
import java.util.List;

@Data
@SuperBuilder
public class PrivilegeGroup {
private String groupName;
@Builder.Default
private List<Privilege> privileges = new ArrayList<>();
}
Loading

0 comments on commit cbf2706

Please sign in to comment.