-
Notifications
You must be signed in to change notification settings - Fork 67
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- update storages to call same signature convert method as canConvert - update s3 tests and ci to use real S3, localstack is no longer working with later versions of s3 sdk
- Loading branch information
1 parent
8c87e7c
commit 451f7f8
Showing
9 changed files
with
1,172 additions
and
1,106 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
152 changes: 76 additions & 76 deletions
152
spring-content-s3/src/test/java/internal/org/springframework/content/s3/it/LocalStack.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,76 +1,76 @@ | ||
package internal.org.springframework.content.s3.it; | ||
|
||
import java.io.Serializable; | ||
import java.net.URI; | ||
import java.net.URISyntaxException; | ||
|
||
import org.testcontainers.containers.localstack.LocalStackContainer; | ||
import org.testcontainers.utility.DockerImageName; | ||
|
||
import com.amazonaws.auth.AWSCredentials; | ||
import com.amazonaws.auth.AWSCredentialsProvider; | ||
import com.github.dockerjava.zerodep.shaded.org.apache.hc.core5.net.URIBuilder; | ||
|
||
import software.amazon.awssdk.auth.credentials.AwsBasicCredentials; | ||
import software.amazon.awssdk.auth.credentials.AwsCredentials; | ||
import software.amazon.awssdk.auth.credentials.AwsCredentialsProvider; | ||
import software.amazon.awssdk.core.ServiceConfiguration; | ||
import software.amazon.awssdk.services.s3.S3Client; | ||
|
||
public class LocalStack extends LocalStackContainer implements Serializable { | ||
|
||
private static final DockerImageName IMAGE_NAME = DockerImageName.parse("localstack/localstack"); | ||
|
||
private static LocalStack INSTANCE = null; | ||
|
||
private LocalStack() { | ||
super(IMAGE_NAME); | ||
withServices(Service.S3); | ||
start(); | ||
} | ||
|
||
public static LocalStack singleton() { | ||
if (INSTANCE == null) { | ||
INSTANCE = new LocalStack(); | ||
} | ||
return INSTANCE; | ||
} | ||
|
||
public static S3Client getAmazonS3Client() throws URISyntaxException { | ||
return S3Client.builder() | ||
.endpointOverride(new URI(LocalStack.singleton().getEndpointConfiguration(LocalStackContainer.Service.S3).getServiceEndpoint())) | ||
.credentialsProvider(new LocalStack.CrossAwsCredentialsProvider(LocalStack.singleton().getDefaultCredentialsProvider())) | ||
.serviceConfiguration((serviceBldr) -> {serviceBldr.pathStyleAccessEnabled(true);}) | ||
.build(); | ||
} | ||
|
||
@Override | ||
public URI getEndpointOverride(EnabledService service) { | ||
try { | ||
// super method converts localhost to 127.0.0.1 which fails on macos | ||
// need to revert it back to whatever getContainerIpAddress() returns | ||
return new URIBuilder(super.getEndpointOverride(service)).setHost(getContainerIpAddress()).build(); | ||
} catch (URISyntaxException e) { | ||
throw new IllegalStateException("Cannot obtain endpoint URL", e); | ||
} | ||
} | ||
|
||
@SuppressWarnings("unused") // Serializable safe singleton usage | ||
protected LocalStack readResolve() { | ||
return singleton(); | ||
} | ||
|
||
|
||
private static class CrossAwsCredentialsProvider implements AwsCredentialsProvider { | ||
private final AWSCredentials credentials; | ||
|
||
public CrossAwsCredentialsProvider(AWSCredentialsProvider provider) { | ||
this.credentials = provider.getCredentials(); | ||
} | ||
|
||
@Override | ||
public AwsCredentials resolveCredentials() { | ||
return AwsBasicCredentials.create(credentials.getAWSAccessKeyId(), credentials.getAWSSecretKey()); | ||
} | ||
} | ||
} | ||
//package internal.org.springframework.content.s3.it; | ||
// | ||
//import java.io.Serializable; | ||
//import java.net.URI; | ||
//import java.net.URISyntaxException; | ||
// | ||
//import org.testcontainers.containers.localstack.LocalStackContainer; | ||
//import org.testcontainers.utility.DockerImageName; | ||
// | ||
//import com.amazonaws.auth.AWSCredentials; | ||
//import com.amazonaws.auth.AWSCredentialsProvider; | ||
//import com.github.dockerjava.zerodep.shaded.org.apache.hc.core5.net.URIBuilder; | ||
// | ||
//import software.amazon.awssdk.auth.credentials.AwsBasicCredentials; | ||
//import software.amazon.awssdk.auth.credentials.AwsCredentials; | ||
//import software.amazon.awssdk.auth.credentials.AwsCredentialsProvider; | ||
//import software.amazon.awssdk.core.ServiceConfiguration; | ||
//import software.amazon.awssdk.services.s3.S3Client; | ||
// | ||
//public class LocalStack extends LocalStackContainer implements Serializable { | ||
// | ||
// private static final DockerImageName IMAGE_NAME = DockerImageName.parse("localstack/localstack"); | ||
// | ||
// private static LocalStack INSTANCE = null; | ||
// | ||
// private LocalStack() { | ||
// super(IMAGE_NAME); | ||
// withServices(Service.S3); | ||
// start(); | ||
// } | ||
// | ||
// public static LocalStack singleton() { | ||
// if (INSTANCE == null) { | ||
// INSTANCE = new LocalStack(); | ||
// } | ||
// return INSTANCE; | ||
// } | ||
// | ||
// public static S3Client getAmazonS3Client() throws URISyntaxException { | ||
// return S3Client.builder() | ||
// .endpointOverride(new URI(LocalStack.singleton().getEndpointConfiguration(LocalStackContainer.Service.S3).getServiceEndpoint())) | ||
// .credentialsProvider(new LocalStack.CrossAwsCredentialsProvider(LocalStack.singleton().getDefaultCredentialsProvider())) | ||
// .serviceConfiguration((serviceBldr) -> {serviceBldr.pathStyleAccessEnabled(true);}) | ||
// .build(); | ||
// } | ||
// | ||
// @Override | ||
// public URI getEndpointOverride(EnabledService service) { | ||
// try { | ||
// // super method converts localhost to 127.0.0.1 which fails on macos | ||
// // need to revert it back to whatever getContainerIpAddress() returns | ||
// return new URIBuilder(super.getEndpointOverride(service)).setHost(getContainerIpAddress()).build(); | ||
// } catch (URISyntaxException e) { | ||
// throw new IllegalStateException("Cannot obtain endpoint URL", e); | ||
// } | ||
// } | ||
// | ||
// @SuppressWarnings("unused") // Serializable safe singleton usage | ||
// protected LocalStack readResolve() { | ||
// return singleton(); | ||
// } | ||
// | ||
// | ||
// private static class CrossAwsCredentialsProvider implements AwsCredentialsProvider { | ||
// private final AWSCredentials credentials; | ||
// | ||
// public CrossAwsCredentialsProvider(AWSCredentialsProvider provider) { | ||
// this.credentials = provider.getCredentials(); | ||
// } | ||
// | ||
// @Override | ||
// public AwsCredentials resolveCredentials() { | ||
// return AwsBasicCredentials.create(credentials.getAWSAccessKeyId(), credentials.getAWSSecretKey()); | ||
// } | ||
// } | ||
//} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.