Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for role array in AWS managed policies #20

Merged
merged 2 commits into from
Dec 28, 2016
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Support for role array in managed policies
  • Loading branch information
raphaellondner-okta committed Dec 8, 2016
commit 1479153bf0d48a83a2a78aca8d594309635ae373
Binary file modified out/oktaawscli.jar
Binary file not shown.
41 changes: 38 additions & 3 deletions src/main/java/com/okta/tools/awscli.java
Original file line number Diff line number Diff line change
Expand Up @@ -553,17 +553,52 @@ private static String ProcessPolicyDocument(String policyDoc) {
}
}
if (resource != null) {
strRoleToAssume = resource.textValue();
logger.debug("Role to assume: " + roleToAssume);
if(resource.isArray()) { //if we're handling a policy with an array of AssumeRole attributes
ArrayList<String> lstRoles = new ArrayList<String>();
for(final JsonNode node: resource) {
lstRoles.add(node.asText());
}
strRoleToAssume = SelectRole(lstRoles);
}
else {
strRoleToAssume = resource.textValue();
logger.debug("Role to assume: " + roleToAssume);
}
}
} catch (IOException ioe) {
}
} catch (UnsupportedEncodingException uee) {

}
return strRoleToAssume;
}

/* Prompts the user to select a role in case the role policy contains an array of roles instead of a single role
*/
private static String SelectRole(List<String> lstRoles) {
String strSelectedRole = null;

return strRoleToAssume;
System.out.println("\nPlease select the role you want to assume: ");

//Gather list of roles for the selected managed policy
int i = 1;
for (String strRoleName : lstRoles) {
System.out.println("[ " + i + " ]: " + strRoleName);
i++;
}

//Prompt user for policy selection
int selection = numSelection(lstRoles.size());

if(selection < 0 && lstRoles.size() > selection) {
System.out.println("\nYou entered an invalid number. Please try again.");
return SelectRole(lstRoles);
}
else {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: you don't need else clause here, because you have return in if

strSelectedRole = lstRoles.get(selection);
}

return strSelectedRole;
}

/* Retrieves AWS credentials from AWS's assumedRoleResult and write the to aws credential file
Expand Down