Skip to content

Commit

Permalink
Add configurable override for s3 url
Browse files Browse the repository at this point in the history
  • Loading branch information
lucko committed Apr 15, 2023
1 parent 4d77104 commit a820389
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/main/java/me/lucko/bytebin/Bytebin.java
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ public Bytebin(Configuration config) throws Exception {

// schedule invalidation task
if (expiryHandler.hasExpiryTimes() || metrics) {
this.executor.scheduleWithFixedDelay(storageHandler::runInvalidationAndRecordMetrics, 5, 60 * 5, TimeUnit.SECONDS);
this.executor.scheduleWithFixedDelay(storageHandler::runInvalidationAndRecordMetrics, 5, 5, TimeUnit.MINUTES);
}

if (config.getBoolean(Option.AUDIT_ON_STARTUP, false)) {
Expand Down
11 changes: 10 additions & 1 deletion src/main/java/me/lucko/bytebin/content/storage/S3Backend.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import software.amazon.awssdk.core.ResponseInputStream;
import software.amazon.awssdk.core.sync.RequestBody;
import software.amazon.awssdk.services.s3.S3Client;
import software.amazon.awssdk.services.s3.S3ClientBuilder;
import software.amazon.awssdk.services.s3.model.DeleteObjectRequest;
import software.amazon.awssdk.services.s3.model.GetObjectRequest;
import software.amazon.awssdk.services.s3.model.GetObjectResponse;
Expand All @@ -44,6 +45,7 @@
import software.amazon.awssdk.services.s3.model.S3Object;
import software.amazon.awssdk.services.s3.paginators.ListObjectsV2Iterable;

import java.net.URI;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
Expand All @@ -68,7 +70,14 @@ public S3Backend(String backendId, String bucketName) {
this.bucketName = bucketName;

// configure with environment variables: AWS_REGION, AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY
this.client = S3Client.builder().build();
S3ClientBuilder builder = S3Client.builder();

String s3EndpointUrl = System.getenv("AWS_S3_ENDPOINT_URL");
if (s3EndpointUrl != null && !s3EndpointUrl.isBlank()) {
builder = builder.endpointOverride(URI.create(s3EndpointUrl));
}

this.client = builder.build();
}

@Override
Expand Down

0 comments on commit a820389

Please sign in to comment.