Initial support for multiple labels for AWS S3 (#2564)

Co-authored-by: Ryan Baxter <524254+ryanjbaxter@users.noreply.github.com>
This commit is contained in:
Ryan Baxter
2024-10-02 10:15:17 -04:00
committed by GitHub
parent 0e64e810d0
commit ecb237c6d9
2 changed files with 38 additions and 5 deletions

View File

@@ -20,6 +20,7 @@ import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Properties;
@@ -93,15 +94,28 @@ public class AwsS3EnvironmentRepository implements EnvironmentRepository, Ordere
final Environment environment = new Environment(application, profileArray);
environment.setLabel(label);
for (String profile : profileArray) {
for (String app : apps) {
addPropertySource(environment, app, profile, label);
List<String> labels;
if (StringUtils.hasText(label) && label.contains(",")) {
labels = Arrays.asList(StringUtils.commaDelimitedListToStringArray(label));
Collections.reverse(labels);
}
else {
labels = Collections.singletonList(label);
}
for (String l : labels) {
for (String profile : profileArray) {
for (String app : apps) {
addPropertySource(environment, app, profile, l);
}
}
}
// Add propertysources without profiles as well
for (String app : apps) {
addPropertySource(environment, app, null, label);
for (String l : labels) {
for (String app : apps) {
addPropertySource(environment, app, null, l);
}
}
if (LOG.isDebugEnabled()) {

View File

@@ -103,6 +103,15 @@ public class AwsS3IntegrationTests {
objectResponse = s3Client.putObject((request) -> request.bucket("test-bucket").key("data-dev.properties"),
RequestBody.fromString("bar=1"));
LOG.info("object response " + objectResponse);
objectResponse = s3Client.putObject((request) -> request.bucket("test-bucket").key("main/foo.properties"),
RequestBody.fromString("foo=1"));
LOG.info("object response " + objectResponse);
objectResponse = s3Client.putObject((request) -> request.bucket("test-bucket").key("dev/foo.properties"),
RequestBody.fromString("devfoo=1"));
LOG.info("object response " + objectResponse);
objectResponse = s3Client.putObject((request) -> request.bucket("test-bucket").key("test/foo.properties"),
RequestBody.fromString("testfoo=1"));
LOG.info("object response " + objectResponse);
}
@AfterAll
@@ -124,6 +133,16 @@ public class AwsS3IntegrationTests {
.isEqualTo("this is a test");
}
@Test
public void testMultipleLabels() throws IOException {
RestTemplate rest = new RestTemplateBuilder().build();
String configServerUrl = "http://localhost:" + configServerPort;
Environment env = rest.getForObject(configServerUrl + "/foo/default/main,dev,test", Environment.class);
assertThat(env.getPropertySources().get(0).getSource().get("testfoo")).isEqualTo("1");
assertThat(env.getPropertySources().get(1).getSource().get("devfoo")).isEqualTo("1");
assertThat(env.getPropertySources().get(2).getSource().get("foo")).isEqualTo("1");
}
@Test
public void defaultApplicationAndProfileIncluded() throws IOException {
RestTemplate rest = new RestTemplateBuilder().build();