-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: implement S3 upload of transformation result
Adds a simple S3 upload service that uploads the transformations result when the necessary details and credentials were provided in the transformation message. SVC-1398
- Loading branch information
1 parent
e546491
commit d2c7a1f
Showing
5 changed files
with
147 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
src/main/java/to/wetransform/hale/transformer/io/s3/S3Service.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package to.wetransform.hale.transformer.io.s3; | ||
|
||
import java.io.File; | ||
import java.net.URI; | ||
import java.nio.file.Path; | ||
|
||
import software.amazon.awssdk.auth.credentials.AwsCredentials; | ||
import software.amazon.awssdk.auth.credentials.StaticCredentialsProvider; | ||
import software.amazon.awssdk.regions.Region; | ||
import software.amazon.awssdk.services.s3.S3Client; | ||
import software.amazon.awssdk.services.s3.S3ClientBuilder; | ||
import software.amazon.awssdk.services.s3.model.PutObjectRequest; | ||
import software.amazon.awssdk.services.s3.model.PutObjectResponse; | ||
|
||
/** | ||
* Adapter for S3 object storages | ||
*/ | ||
public class S3Service implements AutoCloseable { | ||
private final S3Client s3Client; | ||
|
||
/** | ||
* Creates an S3 service instance with the given parameters. | ||
* | ||
* @param region S3 region to connect to | ||
* @param credentials Credentials for accessing S3 | ||
* @param endpoint Optional endpoint URL. If null, AWS S3 endpoints are used. | ||
*/ | ||
public S3Service(Region region, AwsCredentials credentials, URI endpoint) { | ||
S3ClientBuilder builder = | ||
S3Client.builder().region(region).credentialsProvider(StaticCredentialsProvider.create(credentials)); | ||
|
||
if (endpoint != null) { | ||
builder = builder.endpointOverride(endpoint); | ||
} | ||
|
||
this.s3Client = builder.build(); | ||
} | ||
|
||
/** | ||
* Upload a file to an S3 bucket | ||
* | ||
* @param bucketName Name of the target bucket | ||
* @param key Key (file name) of the created object | ||
* @param file File to upload | ||
* @return API response | ||
*/ | ||
public PutObjectResponse putObject(String bucketName, String key, File file) { | ||
PutObjectRequest req = | ||
PutObjectRequest.builder().bucket(bucketName).key(key).build(); | ||
|
||
return s3Client.putObject(req, Path.of(file.toURI())); | ||
} | ||
|
||
/** | ||
* Close the S3 connection | ||
*/ | ||
public void close() { | ||
this.s3Client.close(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
spring: | ||
rabbitmq: | ||
host: ${RABBITMQ_HOSTNAME} | ||
username: ${RABBITMQ_USERNAME} | ||
password: ${RABBITMQ_PASSWORD} | ||
|
||
management: | ||
health: | ||
probes: | ||
enabled: true |