diff --git a/pom.xml b/pom.xml index 2437f67bb..8c79ef9ea 100644 --- a/pom.xml +++ b/pom.xml @@ -32,7 +32,7 @@ v1-rev20201112-1.30.10 1.17.3 2.31.0 - 3.0.0-RC2 + 3.0.0 true true diff --git a/spring-cloud-config-server/pom.xml b/spring-cloud-config-server/pom.xml index f7cf4cefd..802a6925a 100644 --- a/spring-cloud-config-server/pom.xml +++ b/spring-cloud-config-server/pom.xml @@ -233,6 +233,11 @@ zipkin-sender-urlconnection test + + io.awspring.cloud + spring-cloud-aws-s3 + test + diff --git a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/AwsS3IntegrationTests.java b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/AwsS3IntegrationTests.java index a4b332410..6a9b7112e 100644 --- a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/AwsS3IntegrationTests.java +++ b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/AwsS3IntegrationTests.java @@ -17,7 +17,13 @@ package org.springframework.cloud.config.server; import java.io.IOException; +import java.util.Optional; +import io.awspring.cloud.s3.InMemoryBufferingS3OutputStreamProvider; +import io.awspring.cloud.s3.PropertiesS3ObjectContentTypeResolver; +import io.awspring.cloud.s3.S3ObjectContentTypeResolver; +import io.awspring.cloud.s3.S3OutputStreamProvider; +import io.awspring.cloud.s3.S3ProtocolResolver; import org.json.JSONException; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeAll; @@ -27,7 +33,9 @@ import org.testcontainers.junit.jupiter.Container; import org.testcontainers.junit.jupiter.Testcontainers; import org.testcontainers.utility.DockerImageName; +import software.amazon.awssdk.auth.credentials.AwsBasicCredentials; import software.amazon.awssdk.core.sync.RequestBody; +import software.amazon.awssdk.regions.Region; import software.amazon.awssdk.services.s3.S3Client; import org.springframework.boot.SpringApplication; @@ -35,6 +43,8 @@ import org.springframework.cloud.config.environment.Environment; import org.springframework.cloud.config.server.test.TestConfigServerApplication; import org.springframework.context.ConfigurableApplicationContext; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Import; import org.springframework.test.util.TestSocketUtils; import org.springframework.web.client.RestTemplate; @@ -58,7 +68,7 @@ public class AwsS3IntegrationTests { @BeforeAll public static void startConfigServer() throws IOException, InterruptedException, JSONException { - server = SpringApplication.run(new Class[] { TestConfigServerApplication.class }, + server = SpringApplication.run(new Class[] { TestConfigServerApplication.class, S3AutoConfiguration.class }, new String[] { "--spring.config.name=server", "--spring.profiles.active=awss3", "--server.port=" + configServerPort, "--spring.cloud.config.server.awss3.endpoint=" @@ -71,7 +81,7 @@ public static void startConfigServer() throws IOException, InterruptedException, "--spring.cloud.aws.credentials.secret-key=" + localstack.getSecretKey(), "--spring.cloud.aws.region.static=" + localstack.getRegion() }); - if (server.containsBean(S3Client.class.getName())) { + if (server.getBeanNamesForType(S3Client.class).length > 0) { s3Client = server.getBean(S3Client.class); s3Client.createBucket((request) -> request.bucket("test-bucket")); s3Client.putObject((request) -> request.bucket("test-bucket").key("data.txt"), @@ -86,8 +96,6 @@ public static void startConfigServer() throws IOException, InterruptedException, @Test @Disabled - // TODO uncomment when we have an RC or GA release of Spring Cloud AWS with this fix - // https://github.com/awspring/spring-cloud-aws/pull/652 public void context() throws IOException { RestTemplate rest = new RestTemplateBuilder().build(); String configServerUrl = "http://localhost:" + configServerPort; @@ -104,4 +112,25 @@ public static void after() { server.close(); } + @Import(S3ProtocolResolver.class) + static class S3AutoConfiguration { + + @Bean + S3Client s3Client() { + return S3Client.builder() + .credentialsProvider( + () -> AwsBasicCredentials.create(localstack.getAccessKey(), localstack.getSecretKey())) + .region(Region.of(localstack.getRegion())) + .endpointOverride(localstack.getEndpointOverride(LocalStackContainer.Service.S3)).build(); + } + + @Bean + S3OutputStreamProvider inMemoryBufferingS3StreamProvider(S3Client s3Client, + Optional contentTypeResolver) { + return new InMemoryBufferingS3OutputStreamProvider(s3Client, + contentTypeResolver.orElseGet(PropertiesS3ObjectContentTypeResolver::new)); + } + + } + }