Search in sources :

Example 1 with SpendProfilePolicy

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));
}
Also used : PrintStream(java.io.PrintStream) SpendProfilePolicy(bio.terra.cli.service.SpendProfileManagerService.SpendProfilePolicy)

Example 2 with SpendProfilePolicy

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;
}
Also used : HashMap(java.util.HashMap) AccessPolicyResponseEntry(org.broadinstitute.dsde.workbench.client.sam.model.AccessPolicyResponseEntry) ArrayList(java.util.ArrayList) SpendProfilePolicy(bio.terra.cli.service.SpendProfileManagerService.SpendProfilePolicy)

Aggregations

SpendProfilePolicy (bio.terra.cli.service.SpendProfileManagerService.SpendProfilePolicy)2 PrintStream (java.io.PrintStream)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 AccessPolicyResponseEntry (org.broadinstitute.dsde.workbench.client.sam.model.AccessPolicyResponseEntry)1