From 907295dab387bf1ba67e22361b7d2b4f29cf6fbf Mon Sep 17 00:00:00 2001 From: Alain O'Dea Date: Sat, 3 Feb 2018 17:52:30 -0330 Subject: [PATCH] Support for AWS Tools for Windows PowerShell (#77) * :seedling: 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 --- .../java/com/okta/tools/aws/settings/Configuration.java | 2 +- .../java/com/okta/tools/aws/settings/Credentials.java | 1 + .../com/okta/tools/aws/settings/ConfigurationTest.java | 8 ++++---- .../java/com/okta/tools/aws/settings/CredentialsTest.java | 6 +++--- 4 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/okta/tools/aws/settings/Configuration.java b/src/main/java/com/okta/tools/aws/settings/Configuration.java index a80201e..cbbfe33 100644 --- a/src/main/java/com/okta/tools/aws/settings/Configuration.java +++ b/src/main/java/com/okta/tools/aws/settings/Configuration.java @@ -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); } } diff --git a/src/main/java/com/okta/tools/aws/settings/Credentials.java b/src/main/java/com/okta/tools/aws/settings/Credentials.java index 0bb58f4..7ad537c 100644 --- a/src/main/java/com/okta/tools/aws/settings/Credentials.java +++ b/src/main/java/com/okta/tools/aws/settings/Credentials.java @@ -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); } diff --git a/src/test/java/com/okta/tools/aws/settings/ConfigurationTest.java b/src/test/java/com/okta/tools/aws/settings/ConfigurationTest.java index 45ed690..bbc9d74 100644 --- a/src/test/java/com/okta/tools/aws/settings/ConfigurationTest.java +++ b/src/test/java/com/okta/tools/aws/settings/ConfigurationTest.java @@ -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; /* @@ -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 defaultProfileBefore = sectionToMap.apply(initiallyEmpty.settings.get(DEFAULTPROFILENAME)); @@ -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; @@ -136,4 +136,4 @@ public void constructorClosesReader() throws Exception { // Causing this to throw an exception assertThrows(IOException.class, () -> reader.ready(), "Stream closed"); } -} \ No newline at end of file +} diff --git a/src/test/java/com/okta/tools/aws/settings/CredentialsTest.java b/src/test/java/com/okta/tools/aws/settings/CredentialsTest.java index 908c00e..651e34c 100644 --- a/src/test/java/com/okta/tools/aws/settings/CredentialsTest.java +++ b/src/test/java/com/okta/tools/aws/settings/CredentialsTest.java @@ -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; @@ -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; @@ -110,4 +110,4 @@ public void constructorClosesReader() throws Exception { // Causing this to throw an exception assertThrows(IOException.class, () -> reader.ready(), "Stream closed"); } -} \ No newline at end of file +}