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

Update AWS SDK for Java to v2.x #341

Open
wants to merge 7 commits into
base: develop
Choose a base branch
from
Open
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
8 changes: 8 additions & 0 deletions datasafe-business/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,14 @@
<scope>provided</scope>
</dependency>

<dependency>
<groupId>software.amazon.awssdk</groupId>
<artifactId>s3</artifactId>
<version>2.26.22</version>
<scope>runtime</scope>
</dependency>


<dependency>
<groupId>de.adorsys</groupId>
<artifactId>datasafe-test-storages</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package de.adorsys.datasafe.business.impl.e2e;

import com.amazonaws.services.s3.AmazonS3;
import com.amazonaws.services.s3.model.S3ObjectSummary;
import dagger.Lazy;
import de.adorsys.datasafe.business.impl.service.DaggerDefaultDatasafeServices;
import de.adorsys.datasafe.business.impl.service.DefaultDatasafeServices;
Expand Down Expand Up @@ -47,6 +45,10 @@
import org.testcontainers.containers.GenericContainer;
import org.testcontainers.containers.wait.strategy.Wait;
import org.testcontainers.shaded.com.google.common.collect.ImmutableMap;
import software.amazon.awssdk.services.s3.S3Client;
import software.amazon.awssdk.services.s3.model.ListObjectsV2Request;
import software.amazon.awssdk.services.s3.model.ListObjectsV2Response;
import software.amazon.awssdk.services.s3.model.S3Object;

import java.io.InputStream;
import java.io.OutputStream;
Expand Down Expand Up @@ -94,7 +96,7 @@ class MultiDFSFunctionalityIT extends BaseMockitoTest {
static void initDistributedMinios() {
// Create all required minio-backed S3 buckets:
Stream.of(CREDENTIALS, KEYSTORE, FILES_ONE, FILES_TWO, INBOX).forEach(it -> {
GenericContainer minio = new GenericContainer("minio/minio:RELEASE.2019-08-01T22-18-54Z")
GenericContainer minio = new GenericContainer("minio/minio:RELEASE.2023-06-02T23-17-26Z")
.withExposedPorts(9000)
.withEnv("MINIO_ACCESS_KEY", accessKey(it))
.withEnv("MINIO_SECRET_KEY", secretKey(it))
Expand All @@ -112,11 +114,11 @@ static void initDistributedMinios() {
log.info("ENDPOINT IS {}", endpoint);
endpointsByHostNoBucket.put(it, endpoint);

AmazonS3 client = S3ClientFactory.getClient(
endpoint,
REGION,
accessKey(it),
secretKey(it)
S3Client client = S3ClientFactory.getClient(
endpoint,
REGION,
accessKey(it),
secretKey(it)
);

AwsClientRetry.createBucketWithRetry(client, it);
Expand Down Expand Up @@ -290,19 +292,24 @@ private void registerUser(UserIDAuth auth) {
}

private List<String> listInBucket(String bucket) {
return S3ClientFactory.getClient(
endpointsByHostNoBucket.get(bucket),
REGION,
accessKey(bucket),
secretKey(bucket)
)
.listObjects(bucket, "")
.getObjectSummaries()
.stream()
.map(S3ObjectSummary::getKey)
.collect(Collectors.toList());
S3Client s3 = S3ClientFactory.getClient(
endpointsByHostNoBucket.get(bucket),
REGION,
accessKey(bucket),
secretKey(bucket)
);
ListObjectsV2Request request = ListObjectsV2Request.builder()
.bucket(bucket)
.build();
ListObjectsV2Response response = s3.listObjectsV2(request);

return response.contents()
.stream()
.map(S3Object::key)
.collect(Collectors.toList());
}


@SneakyThrows
private void writeToPrivate(UserIDAuth user, StorageIdentifier id, String path, String data) {
try (OutputStream os = datasafeServices.privateService().write(WriteRequest.forPrivate(user, id, path))) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package de.adorsys.datasafe.business.impl.e2e;

import com.amazonaws.services.s3.model.AmazonS3Exception;
import com.google.common.io.ByteStreams;
import de.adorsys.datasafe.business.impl.service.DefaultDatasafeServices;
import de.adorsys.datasafe.encrypiton.api.types.UserIDAuth;
Expand All @@ -14,6 +13,7 @@
import lombok.SneakyThrows;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.DisabledIfSystemProperty;
import software.amazon.awssdk.services.s3.model.S3Exception;

import java.io.ByteArrayOutputStream;
import java.io.InputStream;
Expand Down Expand Up @@ -73,7 +73,7 @@ void testVersionedRemoveManually() {
writeAndGetVersion(jane, FILE, "Hello 3");

removeByVersion(jane, FILE, new StorageVersion(oldVersion));
assertThrows(AmazonS3Exception.class, () -> readByVersion(jane, FILE, new StorageVersion(oldVersion)));
assertThrows(S3Exception.class, () -> readByVersion(jane, FILE, new StorageVersion(oldVersion)));
assertThat(readPrivateUsingPrivateKey(jane, BasePrivateResource.forPrivate(FILE))).isEqualTo("Hello 3");
}

Expand Down
9 changes: 9 additions & 0 deletions datasafe-cli/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,15 @@
<artifactId>mockito-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>software.amazon.awssdk</groupId>
<artifactId>auth</artifactId>
</dependency>
<dependency>
<groupId>software.amazon.awssdk</groupId>
<artifactId>protocol-core</artifactId>
<version>2.26.23</version>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
package de.adorsys.datasafe.cli.config;

import com.amazonaws.ClientConfiguration;
import com.amazonaws.Protocol;
import com.amazonaws.auth.AWSStaticCredentialsProvider;
import com.amazonaws.auth.BasicAWSCredentials;
import com.amazonaws.client.builder.AwsClientBuilder;
import com.amazonaws.services.s3.AmazonS3;
import com.amazonaws.services.s3.AmazonS3ClientBuilder;
import com.google.common.collect.ImmutableMap;
import dagger.Lazy;
import de.adorsys.datasafe.business.impl.service.DaggerDefaultDatasafeServices;
Expand All @@ -29,7 +22,12 @@
import lombok.experimental.Delegate;
import lombok.experimental.UtilityClass;
import lombok.extern.slf4j.Slf4j;
import software.amazon.awssdk.auth.credentials.AwsBasicCredentials;
import software.amazon.awssdk.auth.credentials.StaticCredentialsProvider;
import software.amazon.awssdk.regions.Region;
import software.amazon.awssdk.services.s3.S3Client;

import java.net.URI;
import java.nio.file.Path;
import java.util.regex.Pattern;

Expand Down Expand Up @@ -103,44 +101,28 @@ private WithCredentialProvider(Lazy<StorageKeyStoreOperations> storageKeyStoreOp
super(null);
this.delegate = new RegexAccessServiceWithStorageCredentialsImpl(storageKeyStoreOperations);
}

}

private static S3StorageService getStorageService(String accessKey, String secretKey, String url, String region,
String bucket) {
AmazonS3ClientBuilder amazonS3ClientBuilder = AmazonS3ClientBuilder.standard()
.withCredentials(
new AWSStaticCredentialsProvider(
new BasicAWSCredentials(
accessKey,
secretKey))
)
.enablePathStyleAccess();

AwsClientBuilder.EndpointConfiguration endpoint = new AwsClientBuilder.EndpointConfiguration(
url,
region
);
amazonS3ClientBuilder.withEndpointConfiguration(endpoint);

if (! url.toLowerCase().startsWith("https")) {
log.info("Creating S3 client without https");
ClientConfiguration clientConfig = new ClientConfiguration();
clientConfig.setProtocol(Protocol.HTTP);
clientConfig.disableSocketProxy();
amazonS3ClientBuilder.withClientConfiguration(clientConfig);
}
S3Client s3 = S3Client.builder()
.endpointOverride(URI.create(url))
.region(Region.of(region))
.credentialsProvider(StaticCredentialsProvider.create(
AwsBasicCredentials.create(accessKey, secretKey)
))
.build();

AmazonS3 amazons3 = amazonS3ClientBuilder.build();

return new S3StorageService(
amazons3,
s3,
bucket,
ExecutorServiceUtil
.submitterExecutesOnStarvationExecutingService(
5,
5
)
);
}
}
}}

Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@
},
{
"pattern": "lib/commons-logging-1.1.3.jar"
},
}
,
{
"pattern": "lib/dagger-2.17.jar"
},
Expand Down
10 changes: 10 additions & 0 deletions datasafe-examples/datasafe-examples-multidfs/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,16 @@
<type>test-jar</type>
<scope>test</scope>
</dependency>


<dependency>
<groupId>software.amazon.awssdk</groupId>
<artifactId>s3</artifactId>
<version>2.26.22</version>
</dependency>



</dependencies>

<!-- Disable maven-dependency-plugin - that's ok to have undeclared transitive dependencies here-->
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package de.adorsys.datasafe.examples.business.s3;

import com.amazonaws.services.s3.AmazonS3;
import dagger.Lazy;
import de.adorsys.datasafe.business.impl.service.DaggerDefaultDatasafeServices;
import de.adorsys.datasafe.business.impl.service.DefaultDatasafeServices;
Expand Down Expand Up @@ -35,6 +34,10 @@
import org.testcontainers.containers.GenericContainer;
import org.testcontainers.containers.wait.strategy.Wait;
import org.testcontainers.shaded.com.google.common.collect.ImmutableMap;
import software.amazon.awssdk.auth.credentials.AwsBasicCredentials;
import software.amazon.awssdk.auth.credentials.StaticCredentialsProvider;
import software.amazon.awssdk.regions.Region;
import software.amazon.awssdk.services.s3.S3Client;

import java.io.OutputStream;
import java.net.URI;
Expand Down Expand Up @@ -64,7 +67,7 @@ class MultiDfsWithCredentialsExampleIT{
private static final ExecutorService EXECUTOR = ExecutorServiceUtil.submitterExecutesOnStarvationExecutingService(4, 4);

private static Map<MinioContainerId, GenericContainer> minios = new EnumMap<>(MinioContainerId.class);
private static AmazonS3 directoryClient = null;
private static S3Client directoryClient = null;
private static Map<MinioContainerId, String> endpointsByHost = new HashMap<>();

@BeforeAll
Expand All @@ -79,13 +82,12 @@ static void startup() {
log.info("MINIO for {} is available at: {} with access: '{}'/'{}'", it, endpoint, it.getAccessKey(),
it.getSecretKey());

AmazonS3 client = S3ClientFactory.getClient(
endpoint,
REGION,
it.getAccessKey(),
it.getSecretKey()
);

S3Client client = S3Client.builder()
.credentialsProvider(StaticCredentialsProvider.create(
AwsBasicCredentials.create(it.getAccessKey(), it.getSecretKey())))
.region(Region.of(REGION))
.endpointOverride(URI.create(endpoint))
.build();
AwsClientRetry.createBucketWithRetry(client, it.getBucketName());

if (it.equals(DIRECTORY_BUCKET)) {
Expand Down
Loading