Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove spring cloud aws dependency #690

Merged
merged 2 commits into from
Dec 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@
import org.springframework.support.TestUtils;
import org.springframework.util.ReflectionUtils;

import com.amazonaws.regions.Regions;
import com.amazonaws.services.s3.AmazonS3;
import com.github.paulcwarren.ginkgo4j.Ginkgo4jConfiguration;
import com.github.paulcwarren.ginkgo4j.Ginkgo4jRunner;

Expand All @@ -39,14 +37,14 @@
@Ginkgo4jConfiguration(threads = 1)
public class ContentS3AutoConfigurationTest {

private static AmazonS3 client;
private static S3Client client;

static {
client = mock(AmazonS3.class);
client = mock(S3Client.class);

try {
Map<String,String> props = new HashMap<>();
props.put("AWS_REGION", Regions.US_WEST_1.getName());
props.put("AWS_REGION", "us-west-1");
props.put("AWS_ACCESS_KEY_ID", "user");
props.put("AWS_SECRET_KEY", "password");
TestUtils.setEnv(props);
Expand All @@ -65,8 +63,8 @@ public class ContentS3AutoConfigurationTest {
context.refresh();

assertThat(context.getBean(TestEntityContentRepository.class), is(not(nullValue())));
assertThat(context.getBean(AmazonS3.class), is(not(nullValue())));
assertThat(context.getBean(AmazonS3.class), is(client));
assertThat(context.getBean(S3Client.class), is(not(nullValue())));
assertThat(context.getBean(S3Client.class), is(client));

context.close();
});
Expand Down Expand Up @@ -160,7 +158,7 @@ public class ContentS3AutoConfigurationTest {
public static class TestConfig {

@Bean
public AmazonS3 s3Client() {
public S3Client s3Client() {
return client;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.support.TestEntity;

import com.amazonaws.regions.Regions;
import com.amazonaws.services.s3.AmazonS3;
import com.github.paulcwarren.ginkgo4j.Ginkgo4jConfiguration;
import com.github.paulcwarren.ginkgo4j.Ginkgo4jRunner;

Expand All @@ -39,11 +37,11 @@
public class S3AutoConfigurationTest {

static {
mock(AmazonS3.class);
mock(S3Client.class);

try {
Map<String,String> props = new HashMap<>();
props.put("AWS_REGION", Regions.US_WEST_1.getName());
props.put("AWS_REGION", "us-west-1");
props.put("AWS_ACCESS_KEY_ID", "user");
props.put("AWS_SECRET_KEY", "password");
setEnv(props);
Expand Down
11 changes: 6 additions & 5 deletions spring-content-s3/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,6 @@
<artifactId>spring-content-commons</artifactId>
<version>1.2.7-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>io.awspring.cloud</groupId>
<artifactId>spring-cloud-aws-context</artifactId>
<version>2.3.2</version>
</dependency>
<dependency>
<groupId>software.amazon.awssdk</groupId>
<artifactId>s3</artifactId>
Expand Down Expand Up @@ -83,6 +78,12 @@
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.awspring.cloud</groupId>
<artifactId>spring-cloud-aws-context</artifactId>
<version>2.3.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.testcontainers</groupId>
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,18 +1,24 @@
package internal.org.springframework.content.s3.config;

import java.io.Serializable;
import java.util.List;
import java.util.Objects;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.content.commons.annotations.ContentId;
import org.springframework.content.commons.repository.StoreAccessException;
import org.springframework.content.commons.utils.BeanUtils;
import org.springframework.content.commons.utils.PlacementService;
import org.springframework.content.commons.utils.PlacementServiceImpl;
import org.springframework.content.s3.S3ObjectIdResolver;
import org.springframework.content.s3.config.S3ObjectIdResolvers;
import org.springframework.content.s3.Bucket;
import org.springframework.content.s3.S3ObjectId;
import org.springframework.content.s3.config.S3StoreConfigurer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.convert.converter.Converter;
import org.springframework.core.convert.converter.ConverterRegistry;

import java.util.List;

@Configuration
public class S3StoreConfiguration {

Expand All @@ -22,25 +28,10 @@ public class S3StoreConfiguration {
@Value("${spring.content.s3.bucket:#{environment.AWS_BUCKET}}")
private String bucket;

@Bean
public S3ObjectIdResolvers contentIdResolvers() {
S3ObjectIdResolvers resolvers = new S3ObjectIdResolvers();
if (configurers != null) {
for (S3StoreConfigurer configurer : configurers) {
configurer.configureS3ObjectIdResolvers(resolvers);
}
}
return resolvers;
}

@Bean
public PlacementService s3StorePlacementService() {
PlacementService conversion = new PlacementServiceImpl();

for (S3ObjectIdResolver resolver : contentIdResolvers()) {
conversion.addConverter(new S3ObjectIdResolverConverter(resolver, bucket));
}

addDefaultS3ObjectIdConverters(conversion, bucket);
addConverters(conversion);

Expand All @@ -49,9 +40,51 @@ public PlacementService s3StorePlacementService() {

public static void addDefaultS3ObjectIdConverters(PlacementService conversion, String bucket) {
// Serializable -> S3ObjectId
conversion.addConverter(new S3ObjectIdResolverConverter(S3StoreFactoryBean.DEFAULT_S3OBJECTID_RESOLVER_STORE, bucket));
conversion.addConverter(new Converter<Serializable, S3ObjectId>() {

private String defaultBucket = bucket;

@Override
public S3ObjectId convert(Serializable id) {
return new S3ObjectId(defaultBucket, Objects.requireNonNull(id, "ContentId must not be null").toString());
}

});

// Object -> S3ObjectId
conversion.addConverter(new S3ObjectIdResolverConverter(new DefaultAssociativeStoreS3ObjectIdResolver(), bucket));
conversion.addConverter(new Converter<Object, S3ObjectId>() {

private String defaultBucket = bucket;

@Override
public S3ObjectId convert(Object idOrEntity) {

String strBucket = null;
Object bucket = BeanUtils.getFieldWithAnnotation(idOrEntity, Bucket.class);
if (bucket == null) {
bucket = defaultBucket;
}
if (bucket == null) {
throw new StoreAccessException("Bucket not set");
} else {
strBucket = bucket.toString();
}


// if an entity return @ContentId
String key = null;
if (BeanUtils.hasFieldWithAnnotation(idOrEntity, ContentId.class)) {
Object contentId = BeanUtils.getFieldWithAnnotation(idOrEntity, ContentId.class);
key = (contentId != null) ? contentId.toString() : null;
// otherwise it is the id
} else {
key = idOrEntity.toString();
}

return (key != null) ? new S3ObjectId(strBucket, key) : null;
}

});
}

private void addConverters(ConverterRegistry registry) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
package internal.org.springframework.content.s3.config;

import java.io.Serializable;

import org.springframework.aop.framework.ProxyFactory;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.content.commons.repository.factory.AbstractStoreFactoryBean;
import org.springframework.content.commons.utils.PlacementService;
import org.springframework.content.s3.S3ObjectIdResolver;
import org.springframework.content.s3.config.MultiTenantAmazonS3Provider;
import org.springframework.context.ApplicationContext;
import org.springframework.core.io.DefaultResourceLoader;
Expand All @@ -21,7 +18,7 @@
@SuppressWarnings("rawtypes")
public class S3StoreFactoryBean extends AbstractStoreFactoryBean {

public static final S3ObjectIdResolver<Serializable> DEFAULT_S3OBJECTID_RESOLVER_STORE = S3ObjectIdResolver.createDefaultS3ObjectIdHelper();
// public static final S3ObjectIdResolver<Serializable> DEFAULT_S3OBJECTID_RESOLVER_STORE = S3ObjectIdResolver.createDefaultS3ObjectIdHelper();

@Autowired
private ApplicationContext context;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.springframework.content.commons.utils.BeanUtils;
import org.springframework.content.commons.utils.Condition;
import org.springframework.content.commons.utils.PlacementService;
import org.springframework.content.s3.S3ObjectId;
import org.springframework.content.s3.config.MultiTenantAmazonS3Provider;
import org.springframework.context.ApplicationContext;
import org.springframework.core.convert.TypeDescriptor;
Expand All @@ -34,8 +35,6 @@
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.Assert;

import com.amazonaws.services.s3.model.S3ObjectId;

import internal.org.springframework.content.s3.io.S3StoreResource;
import internal.org.springframework.content.s3.io.SimpleStorageProtocolResolver;
import software.amazon.awssdk.services.s3.S3Client;
Expand Down
Loading