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