diff --git a/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/environment/AwsS3EnvironmentRepository.java b/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/environment/AwsS3EnvironmentRepository.java index 1286ea9a..629bf54e 100644 --- a/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/environment/AwsS3EnvironmentRepository.java +++ b/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/environment/AwsS3EnvironmentRepository.java @@ -18,7 +18,10 @@ package org.springframework.cloud.config.server.environment; import java.io.IOException; import java.io.InputStream; +import java.util.Arrays; +import java.util.List; import java.util.Properties; +import java.util.stream.Collectors; import software.amazon.awssdk.core.ResponseInputStream; import software.amazon.awssdk.services.s3.S3Client; @@ -37,6 +40,7 @@ import org.springframework.util.StringUtils; /** * @author Clay McCoy * @author Scott Frederick + * @author Daniel Aiken */ public class AwsS3EnvironmentRepository implements EnvironmentRepository, Ordered, SearchPathLocator { @@ -105,10 +109,15 @@ public class AwsS3EnvironmentRepository implements EnvironmentRepository, Ordere } private String[] parseProfiles(String profiles) { - if (profiles.equals(serverProperties.getDefaultProfile())) { - return new String[] { profiles, null }; + if (ObjectUtils.isEmpty(profiles)) { + return new String[] { "" }; } - return StringUtils.commaDelimitedListToStringArray(profiles); + List parsedProfiles = Arrays.stream(profiles.split(",")) + .collect(Collectors.collectingAndThen(Collectors.toList(), p -> { + p.add(""); + return p; + })); + return parsedProfiles.toArray(new String[0]); } private S3ConfigFile getS3ConfigFile(String application, String profile, String label) { diff --git a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/AwsS3EnvironmentRepositoryTests.java b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/AwsS3EnvironmentRepositoryTests.java index 5626cf6e..c2c44bdd 100644 --- a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/AwsS3EnvironmentRepositoryTests.java +++ b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/AwsS3EnvironmentRepositoryTests.java @@ -145,7 +145,7 @@ public class AwsS3EnvironmentRepositoryTests { final Environment env = envRepo.findOne("foo", "bar", null); - assertExpectedEnvironment(env, "foo", null, versionId, 1, "bar"); + assertExpectedEnvironment(env, "foo", null, versionId, 1, "bar", ""); } @Test @@ -154,7 +154,7 @@ public class AwsS3EnvironmentRepositoryTests { final Environment env = envRepo.findOne("foo", "bar", null); - assertExpectedEnvironment(env, "foo", null, versionId, 1, "bar"); + assertExpectedEnvironment(env, "foo", null, versionId, 1, "bar", ""); } @Test @@ -163,7 +163,7 @@ public class AwsS3EnvironmentRepositoryTests { final Environment env = envRepo.findOne("foo", "bar", null); - assertExpectedEnvironment(env, "foo", null, versionId, 1, "bar"); + assertExpectedEnvironment(env, "foo", null, versionId, 1, "bar", ""); } @Test @@ -172,7 +172,7 @@ public class AwsS3EnvironmentRepositoryTests { final Environment env = envRepo.findOne("foo", "bar", null); - assertExpectedEnvironment(env, "foo", null, versionId, 1, "bar"); + assertExpectedEnvironment(env, "foo", null, versionId, 1, "bar", ""); } @Test @@ -181,7 +181,7 @@ public class AwsS3EnvironmentRepositoryTests { final Environment env = envRepo.findOne("foo", null, null); - assertExpectedEnvironment(env, "foo", null, versionId, 1, "default", null); + assertExpectedEnvironment(env, "foo", null, versionId, 1, "default", ""); } @Test @@ -190,7 +190,7 @@ public class AwsS3EnvironmentRepositoryTests { final Environment env = envRepo.findOne("foo", null, null); - assertExpectedEnvironment(env, "foo", null, versionId, 1, "default", null); + assertExpectedEnvironment(env, "foo", null, versionId, 1, "default", ""); } @Test @@ -200,7 +200,7 @@ public class AwsS3EnvironmentRepositoryTests { final Environment env = envRepo.findOne("foo", "profile1,profile2", null); - assertExpectedEnvironment(env, "foo", null, versionId, 2, "profile1", "profile2"); + assertExpectedEnvironment(env, "foo", null, versionId, 2, "profile1", "profile2", ""); } @Test @@ -209,7 +209,28 @@ public class AwsS3EnvironmentRepositoryTests { final Environment env = envRepo.findOne("foo", "profile1,profile2", null); - assertExpectedEnvironment(env, "foo", null, versionId, 1, "profile1", "profile2"); + assertExpectedEnvironment(env, "foo", null, versionId, 1, "profile1", "profile2", ""); + } + + @Test + public void findWithOneProfileDefaultOneFound() throws UnsupportedEncodingException { + putFiles("foo-profile1.yml", jsonContent); + String versionId = putFiles("foo.yml", yamlContent); + + final Environment env = envRepo.findOne("foo", "profile1", null); + + assertExpectedEnvironment(env, "foo", null, versionId, 2, "profile1", ""); + } + + @Test + public void findWithNoProfileAndNoServerDefaultOneFound() throws UnsupportedEncodingException { + server.setDefaultProfile(null); + String versionId = putFiles("foo.yml", yamlContent); + + final Environment env = envRepo.findOne("foo", null, null); + + assertExpectedEnvironment(env, "foo", null, versionId, 1, ""); + } @Test @@ -218,7 +239,7 @@ public class AwsS3EnvironmentRepositoryTests { final Environment env = envRepo.findOne("foo", "bar", "label1"); - assertExpectedEnvironment(env, "foo", "label1", versionId, 1, "bar"); + assertExpectedEnvironment(env, "foo", "label1", versionId, 1, "bar", ""); } @Test @@ -227,7 +248,7 @@ public class AwsS3EnvironmentRepositoryTests { final Environment env = envRepo.findOne("foo", "bar", null); - assertExpectedEnvironment(env, "foo", null, versionId, 1, "bar"); + assertExpectedEnvironment(env, "foo", null, versionId, 1, "bar", ""); } @Test @@ -237,7 +258,8 @@ public class AwsS3EnvironmentRepositoryTests { final Environment env = envRepo.findOne("foo,bar", "profile1", null); - assertExpectedEnvironment(env, "foo,bar", null, versionId, 2, "profile1"); + assertExpectedEnvironment(env, "foo,bar", null, versionId, 2, "profile1", ""); + } @Test