Polish pr 2053 (#2234)

* AWS S3 environment repository can read the default property file as well a profile-specific file. Fixes gh-1611.

* Unit test to assert no default profile when querying S3 repository

* Polishing PR

---------

Co-authored-by: Daniel Aiken <dmaiken13@gmail.com>
Co-authored-by: Ryan Baxter <524254+ryanjbaxter@users.noreply.github.com>
This commit is contained in:
Ryan Baxter
2023-02-24 16:55:56 -05:00
committed by GitHub
parent 920013a5ce
commit da14c2debe
2 changed files with 45 additions and 14 deletions

View File

@@ -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<String> 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) {

View File

@@ -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