Search in sources :

Example 1 with ListGroupsForMemberResponse

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;
}
Also used : Actor(com.cloudera.thunderhead.service.usermanagement.UserManagementProto.Actor) ArrayList(java.util.ArrayList) ListGroupsForMemberRequest(com.cloudera.thunderhead.service.usermanagement.UserManagementProto.ListGroupsForMemberRequest) ListGroupsForMemberResponse(com.cloudera.thunderhead.service.usermanagement.UserManagementProto.ListGroupsForMemberResponse) Crn(com.sequenceiq.cloudbreak.auth.crn.Crn)

Aggregations

Actor (com.cloudera.thunderhead.service.usermanagement.UserManagementProto.Actor)1 ListGroupsForMemberRequest (com.cloudera.thunderhead.service.usermanagement.UserManagementProto.ListGroupsForMemberRequest)1 ListGroupsForMemberResponse (com.cloudera.thunderhead.service.usermanagement.UserManagementProto.ListGroupsForMemberResponse)1 Crn (com.sequenceiq.cloudbreak.auth.crn.Crn)1 ArrayList (java.util.ArrayList)1