Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions sources/core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@
<parent>
<artifactId>tools.dynamia.modules.entityfiles.parent</artifactId>
<groupId>tools.dynamia.modules</groupId>
<version>7.2.2</version>
<version>7.2.3</version>
</parent>
<name>Dynamia Modules - EntityFiles - Core</name>
<artifactId>tools.dynamia.modules.entityfiles</artifactId>
<version>7.2.2</version>
<version>7.2.3</version>
<url>https://www.dynamia.tools/modules/entityfiles</url>

<build>
Expand Down
2 changes: 1 addition & 1 deletion sources/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<groupId>tools.dynamia.modules</groupId>
<artifactId>tools.dynamia.modules.entityfiles.parent</artifactId>
<packaging>pom</packaging>
<version>7.2.2</version>
<version>7.2.3</version>
<name>Dynamia Modules - EntityFiles</name>
<url>https://dynamia.tools/modules/entityfiles</url>
<description>DynamiaTools extension to attach files to entities</description>
Expand Down
4 changes: 2 additions & 2 deletions sources/s3/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@
<parent>
<groupId>tools.dynamia.modules</groupId>
<artifactId>tools.dynamia.modules.entityfiles.parent</artifactId>
<version>7.2.2</version>
<version>7.2.3</version>
</parent>

<name>Dynamia Modules - EntityFiles - S3</name>
<artifactId>tools.dynamia.modules.entityfiles.s3</artifactId>
<version>7.2.2</version>
<version>7.2.3</version>
<url>https://www.dynamia.tools/modules/entityfiles</url>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ public class S3EntityFileStorage implements EntityFileStorage {
public static final String AWS_S3_REGION = "AWS_S3_REGION";
public static final String AWS_S3_BUCKET = "AWS_S3_BUCKET";
private static final Logger log = LoggerFactory.getLogger(S3EntityFileStorage.class);
public static final int PRESIGNED_URL_TIMEOUT = 30;
private final LoggingService logger = new SLF4JLoggingService(S3EntityFileStorage.class, "S3: ");

private final SimpleCache<String, String> URL_CACHE = new SimpleCache<>();
Expand Down Expand Up @@ -199,7 +200,8 @@ public StoredEntityFile download(EntityFile entityFile) {
protected String generateSignedURL(String bucketName, String fileName) {


PresignedGetObjectRequest presignedRequest = S3Utils.generatePresignedObjetRequest(bucketName, fileName, Duration.ofMinutes(30));
PresignedGetObjectRequest presignedRequest = S3Utils.generatePresignedObjetRequest(bucketName, fileName, Duration.ofMinutes(PRESIGNED_URL_TIMEOUT)
, getAccessKey(), getSecretKey(), getRegion());
logger.info("Presigned URL: " + presignedRequest.url().toString());
logger.info("HTTP method: " + presignedRequest.httpRequest().method());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

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.async.AsyncRequestBody;
import software.amazon.awssdk.regions.Region;
import software.amazon.awssdk.services.s3.S3AsyncClient;
Expand Down Expand Up @@ -35,6 +36,17 @@ public static AwsCredentials getCredentials(String accessKey, String secretKey)
return AwsBasicCredentials.create(accessKey, secretKey);
}

/**
* Get credentials provider from access key and secret key
*
* @param accessKey the access key
* @param secretKey the secret key
* @return the aws credentials provider
*/
public static AwsCredentialsProvider credentialsProvider(String accessKey, String secretKey) {
return () -> getCredentials(accessKey, secretKey);
}

/**
* Build S3AsyncClient
*
Expand Down Expand Up @@ -89,11 +101,18 @@ public static CompletableFuture<DeleteObjectResponse> deleteFile(S3AsyncClient s
* @param bucketName the bucket name
* @param key the key
* @param duration the duration
* @param accessKey the access key
* @param secretKey the secret key
* @param region the region
* @return the presigned URL
*/
public static PresignedGetObjectRequest generatePresignedObjetRequest(String bucketName, String key, Duration duration) {
public static PresignedGetObjectRequest generatePresignedObjetRequest(String bucketName, String key, Duration duration,
String accessKey, String secretKey, String region) {

try (S3Presigner presigner = S3Presigner.create()) {
try (S3Presigner presigner = S3Presigner.builder()
.credentialsProvider(credentialsProvider(accessKey, secretKey))
.region(Region.of(region))
.build()) {

GetObjectRequest objectRequest = GetObjectRequest.builder()
.bucket(bucketName)
Expand Down
4 changes: 2 additions & 2 deletions sources/ui/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@
<parent>
<artifactId>tools.dynamia.modules.entityfiles.parent</artifactId>
<groupId>tools.dynamia.modules</groupId>
<version>7.2.2</version>
<version>7.2.3</version>
</parent>
<name>Dynamia Modules - EntityFiles UI</name>
<artifactId>tools.dynamia.modules.entityfiles.ui</artifactId>
<version>7.2.2</version>
<version>7.2.3</version>
<url>https://www.dynamia.tools/modules/entityfiles</url>

<build>
Expand Down