Search in sources :

Example 1 with ManagedGroupMembershipEntry

use of org.broadinstitute.dsde.workbench.client.sam.model.ManagedGroupMembershipEntry in project terra-cli by DataBiosphere.

the class Group method listGroupsInMap.

/**
 * Get the groups in a map, to make it easy to lookup a particular group.
 *
 * @return a map of name -> group object
 */
private static Map<String, Group> listGroupsInMap() {
    // call SAM to get the list of groups the user is a member of
    List<ManagedGroupMembershipEntry> groupsToPolicies = SamService.fromContext().listGroups();
    // convert the SAM objects (group -> policy) to CLI objects (group -> list of policies)
    Map<String, Group> nameToGroup = new HashMap<>();
    for (ManagedGroupMembershipEntry groupToPolicy : groupsToPolicies) {
        String name = groupToPolicy.getGroupName();
        String email = groupToPolicy.getGroupEmail();
        Group group = nameToGroup.get(name);
        if (group == null) {
            group = new Group(name, email, new ArrayList<>());
            nameToGroup.put(name, group);
        }
        GroupPolicy currentUserPolicy = GroupPolicy.fromSamPolicy(groupToPolicy.getRole());
        group.addCurrentUserPolicy(currentUserPolicy);
    }
    return nameToGroup;
}
Also used : ManagedGroupMembershipEntry(org.broadinstitute.dsde.workbench.client.sam.model.ManagedGroupMembershipEntry) HashMap(java.util.HashMap) GroupPolicy(bio.terra.cli.service.SamService.GroupPolicy) ArrayList(java.util.ArrayList)

Aggregations

GroupPolicy (bio.terra.cli.service.SamService.GroupPolicy)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 ManagedGroupMembershipEntry (org.broadinstitute.dsde.workbench.client.sam.model.ManagedGroupMembershipEntry)1