作者:钰铭、瑞丹
Dataphin版本:2.9.2及以上
需开通OpenAPI模块:Dataphin-OpenAPI(平台管理)
一、管理Dataphin成员案例
- 当有新员工加入,且为某个项目的数据研发时:
- 调用AddUser,将用户加为Dataphin成员
- 调用AddProjectMembers,并传入项目开发角色,成为项目的开发
- 当有员工离职时,
- 调用DeleteProjectMembers,从项目中删除该成员
- 调用RemoveUser,从Dataphin中删除该成员。
请注意:目前OpenAPI暂不支持删除服务的成员,转交资源权限和负责人,调用删除用户接口的时候需注意该成员不是数据服务的成员,且已经从各个项目中删除掉该用户。
二、样例代码
1. 当有新员工加入,且为某个项目的数据研发时:
a. 调用AddUser,将用户加为Dataphin成员
b. 调用AddProjectMembers,并传入项目开发角色,成为项目的开发
// 将用户加为Dataphin成员 AddUserRequest request = new AddUserRequest(); AddUserRequest.AddUserCommand command = new AddUserRequest.AddUserCommand(); command.setSourceId("123456"); command.setDisplayName("openapi_display"); command.setAccountName("openapi_account"); request.setAddUserCommand(command); AddUserResponse response = client.getAcsResponse(request); Assertions.assertNotNull(response.getUserId()); // 向项目Id为6634543679050880的DEV项目增加角色Id为306473334的开发角色 // 角色映射表以openApiSdk为准 AddProjectMembersRequest request = new AddProjectMembersRequest(); AddProjectMembersRequest.AddProjectMemberCommand addProjectMemberCommand = new AddProjectMembersRequest.AddProjectMemberCommand(); addProjectMemberCommand.setProjectId(6634543679050880L); addProjectMemberCommand.setEnv("DEV"); addProjectMemberCommand.setModifiedRoleIds(Collections.singletonList(2)); addProjectMemberCommand.setUserIdList(Arrays.asList("306473334")); request.setUpdateProjectMemberCommand(addProjectMemberCommand); AddProjectMembersResponse response = client.getAcsResponse(request); Assertions.assertEquals(response.getCode(), "OK");
2. 当有员工离职时:
a. 调用DeleteProjectMembers,从项目中删除该成员
b. 调用RemoveUser,从Dataphin中删除该成员。
// 删除项目Id为6634543679050880的DEV项目的角色Id为306473334的角色 DeleteProjectMembersRequest.DeleteProjectMemberCommand deleteProjectMemberCommand = new DeleteProjectMembersRequest.DeleteProjectMemberCommand(); deleteProjectMemberCommand.setProjectId(6634543679050880L); deleteProjectMemberCommand.setEnv("DEV"); deleteProjectMemberCommand.setUserIdList(Arrays.asList("306473334")); request.setUpdateProjectMemberCommand(deleteProjectMemberCommand); DeleteProjectMembersResponse response = client.getAcsResponse(request); // 从Dataphin中删除该成员 RemoveUserRequest request = new RemoveUserRequest(); RemoveUserRequest.RemoveUserCommand command = new RemoveUserRequest.RemoveUserCommand(); command.setSourceType("BUC"); command.setSourceId("123456"); RemoveUserResponse response = client.getAcsResponse(request); Assertions.assertTrue(response.getData());