mirror of
https://github.com/signalapp/Signal-Server.git
synced 2026-12-01 08:16:47 +00:00
Use transfer acceleration
// FREEBIE
This commit is contained in:
1 parent
ea08f39f6e
commit
1bd66297e2
3 files changed
+35
-2
No files matched your search
@@ -66,7 +66,7 @@
|
||||
<dependency>
|
||||
<groupId>com.amazonaws</groupId>
|
||||
<artifactId>aws-java-sdk-s3</artifactId>
|
||||
<version>1.10.6</version>
|
||||
<version>1.11.115</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.google.protobuf</groupId>
|
||||
|
||||
@@ -21,6 +21,7 @@ import com.amazonaws.auth.AWSCredentials;
|
||||
import com.amazonaws.auth.BasicAWSCredentials;
|
||||
import com.amazonaws.services.s3.AmazonS3;
|
||||
import com.amazonaws.services.s3.AmazonS3Client;
|
||||
import com.amazonaws.services.s3.S3ClientOptions;
|
||||
import com.amazonaws.services.s3.model.GeneratePresignedUrlRequest;
|
||||
import org.whispersystems.textsecuregcm.configuration.S3Configuration;
|
||||
|
||||
@@ -42,10 +43,12 @@ public class UrlSigner {
|
||||
public URL getPreSignedUrl(long attachmentId, HttpMethod method) {
|
||||
AmazonS3 client = new AmazonS3Client(credentials);
|
||||
GeneratePresignedUrlRequest request = new GeneratePresignedUrlRequest(bucket, String.valueOf(attachmentId), method);
|
||||
|
||||
|
||||
request.setExpiration(new Date(System.currentTimeMillis() + DURATION));
|
||||
request.setContentType("application/octet-stream");
|
||||
|
||||
client.setS3ClientOptions(S3ClientOptions.builder().setAccelerateModeEnabled(true).build());
|
||||
|
||||
return client.generatePresignedUrl(request);
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
package org.whispersystems.textsecuregcm.tests.util;
|
||||
|
||||
import com.amazonaws.HttpMethod;
|
||||
import org.junit.Test;
|
||||
import org.whispersystems.textsecuregcm.configuration.S3Configuration;
|
||||
import org.whispersystems.textsecuregcm.util.UrlSigner;
|
||||
|
||||
import java.net.URL;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
public class UrlSignerTest {
|
||||
|
||||
@Test
|
||||
public void testTransferAcceleration() {
|
||||
S3Configuration configuration = mock(S3Configuration.class);
|
||||
when(configuration.getAccessKey()).thenReturn("foo");
|
||||
when(configuration.getAccessSecret()).thenReturn("bar");
|
||||
when(configuration.getAttachmentsBucket()).thenReturn("attachments-test");
|
||||
|
||||
UrlSigner signer = new UrlSigner(configuration);
|
||||
URL url = signer.getPreSignedUrl(1234, HttpMethod.GET);
|
||||
|
||||
System.out.println("The URL: " + url);
|
||||
assertThat(url).hasHost("attachments-test.s3-accelerate.amazonaws.com");
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user