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;
}
Aggregations