use of com.cloudera.thunderhead.service.usermanagement.UserManagementProto.ListGroupsForMemberResponse in project cloudbreak by hortonworks.
the class UmsClient method listGroupsForMembers.
/**
* Wraps calls to ListGroupsForMember with an Account ID and member CRN.
*
* @param requestId the request ID for the request
* @param accountId the account ID
* @param memberCrn member (e.g., user) CRN for which groups are fetched.
* @return the list of group CRNs
*/
public List<String> listGroupsForMembers(String requestId, String accountId, String memberCrn) {
validateAccountIdWithWarning(accountId);
checkNotNull(memberCrn, "memberCrn should not be null.");
Crn crn = Crn.safeFromString(memberCrn);
Actor.Builder actor = Actor.newBuilder().setAccountId(accountId);
switch(crn.getResourceType()) {
case USER:
actor.setUserIdOrCrn(memberCrn);
break;
case MACHINE_USER:
actor.setMachineUserNameOrCrn(memberCrn);
break;
default:
throw new IllegalArgumentException(String.format("memberCrn %s is not a USER or MACHINE_USER", memberCrn));
}
ListGroupsForMemberRequest.Builder request = ListGroupsForMemberRequest.newBuilder().setMember(actor.build());
ListGroupsForMemberResponse response;
List<String> groups = new ArrayList<>();
do {
response = newStub(requestId).listGroupsForMember(request.build());
for (int i = 0; i < response.getGroupCrnCount(); i++) {
String grpCRN = response.getGroupCrn(i);
groups.add(grpCRN);
}
request.setPageToken(response.getNextPageToken());
} while (response.hasNextPageToken());
return groups;
}
Aggregations