use of bio.terra.cli.service.SamService.GroupPolicy in project terra-cli by DataBiosphere.
the class UFGroup method print.
/**
* Print out this object in text format.
*/
public void print() {
PrintStream OUT = UserIO.getOut();
List<String> policiesStr = UserIO.sortAndMap(currentUserPolicies, Comparator.comparing(GroupPolicy::name), GroupPolicy::toString);
OUT.println(name);
OUT.println(" Email: " + email);
OUT.println(" # Members: " + (numMembers == null ? "(unknown)" : numMembers));
OUT.println(" Current user's policies: " + String.join(", ", policiesStr));
}
use of bio.terra.cli.service.SamService.GroupPolicy 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;
}
use of bio.terra.cli.service.SamService.GroupPolicy in project terra-cli by DataBiosphere.
the class UFGroupMember method print.
/**
* Print out this object in text format.
*/
public void print() {
PrintStream OUT = UserIO.getOut();
List<String> policiesStr = UserIO.sortAndMap(policies, Comparator.comparing(GroupPolicy::name), GroupPolicy::toString);
OUT.println(email + ": " + String.join(", ", policiesStr));
}
use of bio.terra.cli.service.SamService.GroupPolicy in project terra-cli by DataBiosphere.
the class Group method listMembersByEmail.
/**
* Get the members of a group in a map, to make it easy to lookup a particular user.
*
* @return a map of email -> group member object
*/
private Map<String, Member> listMembersByEmail() {
// call SAM to get the emails + policies for the group
// convert the SAM objects (policy -> list of emails) to CLI objects (email -> list of policies)
Map<String, Member> groupMembers = new HashMap<>();
for (GroupPolicy policy : GroupPolicy.values()) {
List<String> emailsWithPolicy = SamService.fromContext().listUsersInGroup(name, policy);
for (String email : emailsWithPolicy) {
// lowercase the email so there is a consistent way of looking up the email address
// the email address casing in SAM may not match the case of what is provided by the
// user
String emailLowercase = email.toLowerCase();
Member groupMember = groupMembers.get(emailLowercase);
if (groupMember == null) {
groupMember = new Member(emailLowercase, new ArrayList<>());
groupMembers.put(emailLowercase, groupMember);
}
groupMember.addPolicy(policy);
}
}
return groupMembers;
}
Aggregations