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
2 changes: 2 additions & 0 deletions storage/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ This is an implementation of the ``artifacts`` interface using s3 and should wor

`MinIO <https://min.io/product/overview>`_ is an open source s3 compatible object storage, it can be used standalone or can add a s3 api layer on top of existing providers using MinIO Gateway, for example, `NAS <https://docs.min.io/docs/minio-gateway-for-nas.html>`_

If s3.access_key or s3.secret_key are omitted, will follow the `default credentials chain <https://docs.aws.amazon.com/sdk-for-java/v1/developer-guide/credentials.html>`_

Configuration
^^^^^^^^^^^^^

Expand Down
23 changes: 14 additions & 9 deletions storage/src/main/java/org/openmbee/mms/storage/S3Storage.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.amazonaws.auth.AWSCredentials;
import com.amazonaws.auth.AWSStaticCredentialsProvider;
import com.amazonaws.auth.BasicAWSCredentials;
import com.amazonaws.auth.DefaultAWSCredentialsProviderChain;
import com.amazonaws.client.builder.AwsClientBuilder;
import com.amazonaws.services.s3.AmazonS3;
import com.amazonaws.services.s3.AmazonS3ClientBuilder;
Expand Down Expand Up @@ -36,11 +37,11 @@ public class S3Storage implements ArtifactStorage {
@Value("${s3.endpoint}")
private String ENDPOINT;

@Value("${s3.access_key}")
private String ACCESS_KEY;
@Value("${s3.access_key:#{null}}")
private Optional<String> ACCESS_KEY;

@Value("${s3.secret_key}")
private String SECRET_KEY;
@Value("${s3.secret_key:#{null}}")
private Optional<String> SECRET_KEY;

@Value("${s3.region}")
private String REGION;
Expand All @@ -53,18 +54,21 @@ public class S3Storage implements ArtifactStorage {

private AmazonS3 getClient() {
if (s3Client == null) {
AWSCredentials credentials = new BasicAWSCredentials(ACCESS_KEY, SECRET_KEY);
ClientConfiguration clientConfiguration = new ClientConfiguration();
clientConfiguration.setSignerOverride("AWSS3V4SignerType");

s3Client = AmazonS3ClientBuilder
AmazonS3ClientBuilder builder = AmazonS3ClientBuilder
.standard()
.withEndpointConfiguration(new AwsClientBuilder.EndpointConfiguration(ENDPOINT, REGION))
.withPathStyleAccessEnabled(true)
.withClientConfiguration(clientConfiguration)
.withCredentials(new AWSStaticCredentialsProvider(credentials))
.build();
.withClientConfiguration(clientConfiguration);

if (ACCESS_KEY.isPresent() && SECRET_KEY.isPresent()) {
AWSCredentials credentials = new BasicAWSCredentials(ACCESS_KEY.get(), SECRET_KEY.get());
s3Client = builder.withCredentials(new AWSStaticCredentialsProvider(credentials)).build();
} else {
s3Client = builder.withCredentials(DefaultAWSCredentialsProviderChain.getInstance()).build();
}
if (!s3Client.doesBucketExistV2(getBucket())) {
try {
s3Client.createBucket(getBucket());
Expand Down Expand Up @@ -99,6 +103,7 @@ public String store(byte[] data, ElementJson element, String mimetype) {
try {
getClient().putObject(por);
} catch (RuntimeException e) {
logger.error("Error storing artifact: ", e);
throw new InternalErrorException(e);
}
return location;
Expand Down