forked from runabol/piper
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathS3GetUrl.java
41 lines (30 loc) · 1.12 KB
/
S3GetUrl.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package com.creactiviti.piper.taskhandler.s3;
import org.springframework.stereotype.Component;
import com.creactiviti.piper.core.task.TaskExecution;
import com.creactiviti.piper.core.task.TaskHandler;
import software.amazon.awssdk.services.s3.S3Client;
import software.amazon.awssdk.services.s3.model.GetUrlRequest;
/**
* Returns the URL for an object stored in Amazon S3. If the object identified
* by the given bucket and key has public read permissions, then this URL can
* be directly accessed to retrieve the object's data.
*
* @author Arik Cohen
* @since Feb, 20 2020
*/
@Component("s3/getUrl")
class S3GetUrl implements TaskHandler<String> {
@Override
public String handle (TaskExecution aTask) throws Exception {
AmazonS3URI s3Uri = new AmazonS3URI(aTask.getRequiredString("uri"));
String bucketName = s3Uri.getBucket();
String key = s3Uri.getKey();
S3Client s3 = S3Client.builder().build();
return s3.utilities().getUrl(
GetUrlRequest.builder()
.bucket(bucketName)
.key(key)
.build()
).toString();
}
}