use of bio.terra.cli.service.SpendProfileManagerService.SpendProfilePolicy in project terra-cli by DataBiosphere.
the class UFSpendProfileUser method print.
/**
* Print out this object in text format.
*/
public void print() {
PrintStream OUT = UserIO.getOut();
List<String> policiesStr = UserIO.sortAndMap(policies, Comparator.comparing(SpendProfilePolicy::name), SpendProfilePolicy::toString);
OUT.println(email + ": " + String.join(", ", policiesStr));
}
use of bio.terra.cli.service.SpendProfileManagerService.SpendProfilePolicy in project terra-cli by DataBiosphere.
the class SpendProfileUser method listUsersInMap.
/**
* Get the users of the default WSM spend profile in a map, to make it easy to lookup a particular
* user.
*
* @return a map of email -> spend profile user object
*/
private static Map<String, SpendProfileUser> listUsersInMap() {
// call SAM to get the users + policies for the WSM default spend profile resource
List<AccessPolicyResponseEntry> accessPolicies = SpendProfileManagerService.fromContext().listUsersOfDefaultSpendProfile();
// convert the SAM objects (policy -> list of emails) to CLI objects (email -> list of policies)
Map<String, SpendProfileUser> spendProfileUsers = new HashMap<>();
accessPolicies.forEach(accessPolicy -> {
SpendProfilePolicy spendPolicy = SpendProfilePolicy.valueOf(accessPolicy.getPolicyName().toUpperCase());
for (String email : accessPolicy.getPolicy().getMemberEmails()) {
// 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();
SpendProfileUser spendProfileUser = spendProfileUsers.get(emailLowercase);
if (spendProfileUser == null) {
spendProfileUser = new SpendProfileUser(emailLowercase, new ArrayList<>());
spendProfileUsers.put(emailLowercase, spendProfileUser);
}
spendProfileUser.policies.add(spendPolicy);
}
});
return spendProfileUsers;
}
Aggregations