Skip to content

Commit

Permalink
Merge pull request #208 from scireum/feature/aha/web-update
Browse files Browse the repository at this point in the history
Updates to the latest sirius-kernel and -web + AWS toolkit
  • Loading branch information
andyHa committed Oct 5, 2022
2 parents 131e67b + 5abcd90 commit de5a25b
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 21 deletions.
6 changes: 3 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
<url>http://s3ninja.net</url>

<properties>
<sirius.kernel>dev-31.1.0</sirius.kernel>
<sirius.web>dev-52.1.1</sirius.web>
<sirius.kernel>dev-33.1.0</sirius.kernel>
<sirius.web>dev-57.3.0</sirius.web>
</properties>

<repositories>
Expand Down Expand Up @@ -55,7 +55,7 @@
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-s3</artifactId>
<version>1.12.261</version>
<version>1.12.307</version>
</dependency>
</dependencies>
</project>
2 changes: 1 addition & 1 deletion src/main/java/ninja/Bucket.java
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ public List<StoredObject> getObjects(@Nullable String query, Limit limit) {
.filter(currentFile -> isMatchingObject(query, currentFile))
.filter(limit.asPredicate())
.map(StoredObject::new)
.collect(Collectors.toList());
.toList();
} catch (IOException e) {
throw Exceptions.handle(e);
}
Expand Down
25 changes: 8 additions & 17 deletions src/main/java/ninja/S3Dispatcher.java
Original file line number Diff line number Diff line change
Expand Up @@ -137,16 +137,6 @@ private static class S3Request {
.withChronology(IsoChronology.INSTANCE)
.withZone(ZoneOffset.ofHours(0));

/**
* RFC 822 date/time formatter.
*/
public static final DateTimeFormatter RFC822_INSTANT =
new DateTimeFormatterBuilder().appendPattern("EEE, dd MMM yyyy HH:mm:ss 'GMT'")
.toFormatter()
.withLocale(Locale.ENGLISH)
.withChronology(IsoChronology.INSTANCE)
.withZone(ZoneOffset.ofHours(0));

private static final Map<String, String> headerOverrides;

static {
Expand Down Expand Up @@ -658,10 +648,10 @@ private void deleteObject(final WebContext webContext, final Bucket bucket, fina
object.markDeleted();
} catch (IOException ignored) {
signalObjectError(webContext,
bucket.getName(),
id,
S3ErrorCode.InternalError,
Strings.apply("Error while marking file as deleted"));
bucket.getName(),
id,
S3ErrorCode.InternalError,
Strings.apply("Error while marking file as deleted"));
return;
}
}
Expand Down Expand Up @@ -794,7 +784,8 @@ private void getObject(WebContext webContext, Bucket bucket, String id, boolean
StoredObject object = bucket.getObject(id);
if (!object.exists() && !object.isMarkedDeleted() && awsUpstream.isConfigured()) {
URL fetchURL = awsUpstream.generateGetObjectURL(bucket, object, sendFile);
Consumer<BoundRequestBuilder> requestTuner = requestBuilder -> requestBuilder.setMethod(sendFile ? "GET" : "HEAD");
Consumer<BoundRequestBuilder> requestTuner =
requestBuilder -> requestBuilder.setMethod(sendFile ? "GET" : "HEAD");
webContext.enableTiming(null).respondWith().tunnel(fetchURL.toString(), requestTuner, null, null);
return;
}
Expand Down Expand Up @@ -829,7 +820,7 @@ private void getObject(WebContext webContext, Bucket bucket, String id, boolean
String contentType = MimeHelper.guessMimeType(object.getFile().getName());
response.addHeader(HttpHeaderNames.CONTENT_TYPE, contentType);
response.addHeader(HttpHeaderNames.LAST_MODIFIED,
RFC822_INSTANT.format(Instant.ofEpochMilli(object.getFile().lastModified())));
Response.RFC822_INSTANT.format(Instant.ofEpochMilli(object.getFile().lastModified())));
response.addHeader(HttpHeaderNames.CONTENT_LENGTH, object.getFile().length());
response.status(HttpResponseStatus.OK);
}
Expand Down Expand Up @@ -967,7 +958,7 @@ private void completeMultipartUpload(WebContext webContext,
.stream()
.sorted(Comparator.comparing(Map.Entry::getKey))
.map(Map.Entry::getValue)
.collect(Collectors.toList()));
.toList());

file.deleteOnExit();
if (!file.exists()) {
Expand Down
19 changes: 19 additions & 0 deletions src/main/resources/application.conf
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,25 @@ storage {
awsSecretKey = "wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY"
}

# Configures an upstream S3 instance which can be used in case an object is not found locally.
upstreamAWS {
# The secret key to connect to the upstream S3 instance.
secretKey = ""

# The access key to connect to the upstream S3 instance.
accessKey = ""
# The endpoint used to connect to the upstream S3 instance.
endPoint = ""

# The signing region used to connect to the upstream S3 instance.
# If not given, the value "EU" is used.
signingRegion = ""

# The signer type used to connect to the upstream S3 instance.
# This config is optional and will be ignored if missing.
signerType = ""
}

cache {
public-bucket-access {
maxSize = 128
Expand Down

0 comments on commit de5a25b

Please sign in to comment.