Skip to content

Commit

Permalink
Support for AWS Tools for Windows PowerShell (oktadev#77)
Browse files Browse the repository at this point in the history
* 🌱 Support AWS Tools for Windows PowerShell

 - Set a distinct credentials source_profile name

 - Retain support for AWS CLI and Java SDK downstream commands

* Release JAR including PowerShell support
  • Loading branch information
AlainODea authored and Matt Raible committed Feb 3, 2018
1 parent e40caea commit 907295d
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public void addOrUpdateProfile(String name, String roleToAssume) {

private void writeConfigurationProfile(Profile.Section awsProfile, String name, String roleToAssume) {
awsProfile.put(ROLE_ARN, roleToAssume);
awsProfile.put(SOURCE_PROFILE, name);
awsProfile.put(SOURCE_PROFILE, name + "_source");
awsProfile.put(REGION, REGION_DEFAULT);
}
}
1 change: 1 addition & 0 deletions src/main/java/com/okta/tools/aws/settings/Credentials.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ public Credentials(Reader reader) throws IOException {
* @param awsSessionToken The session token to use for the profile.
*/
public void addOrUpdateProfile(String name, String awsAccessKey, String awsSecretKey, String awsSessionToken) {
name = name + "_source";
final Profile.Section awsProfile = settings.get(name) != null ? settings.get(name) : settings.add(name);
writeCredentialsProfile(awsProfile, awsAccessKey, awsSecretKey, awsSessionToken);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class ConfigurationTest {
private String region = "us-east-1";
private String manualRole = "[profile " + profileName + "]\n"
+ Configuration.ROLE_ARN + " = " + role_arn + "\n"
+ SOURCE_PROFILE + " = " + profileName + "\n"
+ SOURCE_PROFILE + " = " + profileName + "_source\n"
+ Configuration.REGION + " = " + region;

/*
Expand Down Expand Up @@ -72,7 +72,7 @@ void addOrUpdateProfileToNewConfigFile() throws IOException {
// Write an initial profile. This should create a default profile as well.
initiallyEmpty.addOrUpdateProfile(profileName, role_arn);
assertEquals(2, initiallyEmpty.settings.size());
assertEquals(profileName, initiallyEmpty.settings.get(DEFAULTPROFILENAME, SOURCE_PROFILE));
assertEquals(profileName + "_source", initiallyEmpty.settings.get(DEFAULTPROFILENAME, SOURCE_PROFILE));
assertEquals(role_arn, initiallyEmpty.settings.get(DEFAULTPROFILENAME, ROLE_ARN));
// State of the default profile after creating an initial profile.
final Map<String, String> defaultProfileBefore = sectionToMap.apply(initiallyEmpty.settings.get(DEFAULTPROFILENAME));
Expand Down Expand Up @@ -112,7 +112,7 @@ void addOrUpdateProfileToExistingProfile() throws IOException {
final String updatedPrefix = "updated_";
final String expected = "[profile " + profileName + "]\n"
+ Configuration.ROLE_ARN + " = " + updatedPrefix + role_arn + "\n"
+ SOURCE_PROFILE + " = " + profileName + "\n"
+ SOURCE_PROFILE + " = " + profileName + "_source\n"
+ Configuration.REGION + " = " + region
+ "\n\n" + existingProfile;

Expand All @@ -136,4 +136,4 @@ public void constructorClosesReader() throws Exception {
// Causing this to throw an exception
assertThrows(IOException.class, () -> reader.ready(), "Stream closed");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class CredentialsTest {
private String accessKey = "accesskey";
private String secretKey = "secretkey";
private String sessionToken = "sessiontoken";
private String manualRole = "[" + roleName + "]\n"
private String manualRole = "[" + roleName + "_source]\n"
+ Credentials.ACCES_KEY_ID + " = " + accessKey + "\n"
+ Credentials.SECRET_ACCESS_KEY + " = " + secretKey + "\n"
+ Credentials.SESSION_TOKEN + " = " + sessionToken;
Expand Down Expand Up @@ -86,7 +86,7 @@ void addOrUpdateProfileToExistingProfile() throws IOException {

final String updatedPrefix = "updated_";
final String expected = existingCredentials + "\n\n"
+ "[" + roleName + "]\n"
+ "[" + roleName + "_source]\n"
+ Credentials.ACCES_KEY_ID + " = " + updatedPrefix + accessKey + "\n"
+ Credentials.SECRET_ACCESS_KEY + " = " + updatedPrefix + secretKey + "\n"
+ Credentials.SESSION_TOKEN + " = " + updatedPrefix + sessionToken;
Expand All @@ -110,4 +110,4 @@ public void constructorClosesReader() throws Exception {
// Causing this to throw an exception
assertThrows(IOException.class, () -> reader.ready(), "Stream closed");
}
}
}

0 comments on commit 907295d

Please sign in to comment.