|
8 | 8 | import com.google.common.annotations.VisibleForTesting; |
9 | 9 | import java.io.IOException; |
10 | 10 | import java.io.InputStream; |
| 11 | +import java.net.URI; |
11 | 12 | import java.time.Duration; |
12 | 13 | import java.util.concurrent.ScheduledExecutorService; |
13 | 14 | import java.util.concurrent.ScheduledFuture; |
|
21 | 22 | import software.amazon.awssdk.core.ResponseInputStream; |
22 | 23 | import software.amazon.awssdk.regions.Region; |
23 | 24 | import software.amazon.awssdk.services.s3.S3Client; |
| 25 | +import software.amazon.awssdk.services.s3.S3ClientBuilder; |
| 26 | +import software.amazon.awssdk.services.s3.S3Configuration; |
24 | 27 | import software.amazon.awssdk.services.s3.model.GetObjectRequest; |
25 | 28 | import software.amazon.awssdk.services.s3.model.GetObjectResponse; |
26 | 29 | import software.amazon.awssdk.services.s3.model.HeadObjectRequest; |
27 | 30 | import software.amazon.awssdk.services.s3.model.HeadObjectResponse; |
| 31 | +import javax.annotation.Nullable; |
28 | 32 |
|
29 | 33 | /** |
30 | 34 | * An S3 object monitor watches a specific object in an S3 bucket and notifies a listener if that object changes. |
@@ -65,6 +69,28 @@ public S3ObjectMonitor( |
65 | 69 | refreshInterval); |
66 | 70 | } |
67 | 71 |
|
| 72 | + // allows specifying a custom S3 endpoint |
| 73 | + static public S3ObjectMonitor createCustomS3(final AwsCredentialsProvider awsCredentialsProvider, |
| 74 | + final URI s3Endpoint, |
| 75 | + final String s3Region, |
| 76 | + final String s3Bucket, |
| 77 | + final String objectKey, |
| 78 | + final long maxObjectSize, |
| 79 | + final ScheduledExecutorService refreshExecutorService, |
| 80 | + final Duration refreshInterval) { |
| 81 | + final S3ClientBuilder s3ClientBuilder = S3Client.builder() |
| 82 | + .region(Region.of(s3Region)) |
| 83 | + .credentialsProvider(awsCredentialsProvider) |
| 84 | + .endpointOverride(s3Endpoint) |
| 85 | + .serviceConfiguration(S3Configuration.builder() |
| 86 | + .pathStyleAccessEnabled(true).build()); |
| 87 | + return new S3ObjectMonitor(s3ClientBuilder.build(), s3Bucket, |
| 88 | + objectKey, |
| 89 | + maxObjectSize, |
| 90 | + refreshExecutorService, |
| 91 | + refreshInterval); |
| 92 | + } |
| 93 | + |
68 | 94 | @VisibleForTesting |
69 | 95 | S3ObjectMonitor( |
70 | 96 | final S3Client s3Client, |
|
0 commit comments