Add support for multiple application config in aws s3 repository. (#1726)

* Updated so that multiple application configs can be retrieved with comma separators from the AWS S3 Repository.

* Added space after comma.

* Add test code for AWS S3 Repository multi-application configuration.
This commit is contained in:
David Choi
2021-01-12 06:43:54 +09:00
committed by GitHub
parent 4302c6f09f
commit df5566e6b0
2 changed files with 27 additions and 9 deletions

View File

@@ -75,22 +75,30 @@ public class AwsS3EnvironmentRepository implements EnvironmentRepository, Ordere
final String label = StringUtils.isEmpty(specifiedLabel) ? serverProperties.getDefaultLabel() : specifiedLabel;
String[] profileArray = parseProfiles(profiles);
String[] apps = new String[] { application };
if (application != null) {
apps = StringUtils.commaDelimitedListToStringArray(application.replace(" ", ""));
}
final Environment environment = new Environment(application, profileArray);
environment.setLabel(label);
for (String profile : profileArray) {
S3ConfigFile s3ConfigFile = getS3ConfigFile(application, profile, label);
if (s3ConfigFile != null) {
environment.setVersion(s3ConfigFile.getVersion());
for (String app : apps) {
S3ConfigFile s3ConfigFile = getS3ConfigFile(app, profile, label);
if (s3ConfigFile != null) {
environment.setVersion(s3ConfigFile.getVersion());
final Properties config = s3ConfigFile.read();
config.putAll(serverProperties.getOverrides());
StringBuilder propertySourceName = new StringBuilder().append("s3:").append(application);
if (profile != null) {
propertySourceName.append("-").append(profile);
final Properties config = s3ConfigFile.read();
config.putAll(serverProperties.getOverrides());
StringBuilder propertySourceName = new StringBuilder().append("s3:")
.append(app);
if (profile != null) {
propertySourceName.append("-").append(profile);
}
environment
.add(new PropertySource(propertySourceName.toString(), config));
}
environment.add(new PropertySource(propertySourceName.toString(), config));
}
}

View File

@@ -175,6 +175,16 @@ public class AwsS3EnvironmentRepositoryTests {
assertExpectedEnvironment(env, "foo", null, "v1", 1, "bar");
}
@Test
public void findWithMultipleApplicationAllFound() throws UnsupportedEncodingException {
setupS3("foo-profile1.yml", jsonContent);
setupS3("bar-profile1.yml", jsonContent);
final Environment env = envRepo.findOne("foo,bar", "profile1", null);
assertExpectedEnvironment(env, "foo,bar", null, null, 2, "profile1");
}
private void setupS3(String fileName, String propertyContent) throws UnsupportedEncodingException {
setupS3(fileName, null, propertyContent);
}