|
|
@ -1,5 +1,7 @@ |
|
|
|
package com.fanruan.fs.s3.repository.core; |
|
|
|
package com.fanruan.fs.s3.repository.core; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import com.amazonaws.ClientConfiguration; |
|
|
|
|
|
|
|
import com.amazonaws.Protocol; |
|
|
|
import com.amazonaws.auth.AWSStaticCredentialsProvider; |
|
|
|
import com.amazonaws.auth.AWSStaticCredentialsProvider; |
|
|
|
import com.amazonaws.auth.BasicAWSCredentials; |
|
|
|
import com.amazonaws.auth.BasicAWSCredentials; |
|
|
|
import com.amazonaws.client.builder.AwsClientBuilder; |
|
|
|
import com.amazonaws.client.builder.AwsClientBuilder; |
|
|
@ -17,6 +19,7 @@ import com.fanruan.api.util.StringKit; |
|
|
|
import com.fr.io.repository.FineFileEntry; |
|
|
|
import com.fr.io.repository.FineFileEntry; |
|
|
|
import com.fr.io.repository.base.BaseResourceRepository; |
|
|
|
import com.fr.io.repository.base.BaseResourceRepository; |
|
|
|
import com.fr.stable.Filter; |
|
|
|
import com.fr.stable.Filter; |
|
|
|
|
|
|
|
import com.fr.stable.StringUtils; |
|
|
|
import com.fr.workspace.resource.ResourceIOException; |
|
|
|
import com.fr.workspace.resource.ResourceIOException; |
|
|
|
|
|
|
|
|
|
|
|
import java.io.ByteArrayInputStream; |
|
|
|
import java.io.ByteArrayInputStream; |
|
|
@ -42,9 +45,19 @@ public class S3ResourceRepository extends BaseResourceRepository { |
|
|
|
public S3ResourceRepository(String repoName, String workRoot, S3Config config) { |
|
|
|
public S3ResourceRepository(String repoName, String workRoot, S3Config config) { |
|
|
|
super(repoName, workRoot); |
|
|
|
super(repoName, workRoot); |
|
|
|
BasicAWSCredentials credentials = new BasicAWSCredentials(config.getAccessKeyId(), config.getPassword()); |
|
|
|
BasicAWSCredentials credentials = new BasicAWSCredentials(config.getAccessKeyId(), config.getPassword()); |
|
|
|
this.s3 = AmazonS3ClientBuilder.standard() |
|
|
|
AmazonS3ClientBuilder amazonS3ClientBuilder = AmazonS3ClientBuilder.standard() |
|
|
|
.withEndpointConfiguration(new AwsClientBuilder.EndpointConfiguration(config.getEndPoint(), config.getRegion())) |
|
|
|
.withEndpointConfiguration(new AwsClientBuilder.EndpointConfiguration(config.getEndPoint(), config.getRegion())) |
|
|
|
.withCredentials(new AWSStaticCredentialsProvider(credentials)).build(); |
|
|
|
.withCredentials(new AWSStaticCredentialsProvider(credentials)); |
|
|
|
|
|
|
|
if (config.isEnablePathStyleAccess()) { |
|
|
|
|
|
|
|
amazonS3ClientBuilder = amazonS3ClientBuilder.enablePathStyleAccess(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (StringUtils.isNotEmpty(config.getSignerOverride())) { |
|
|
|
|
|
|
|
ClientConfiguration clientConfiguration = new ClientConfiguration(); |
|
|
|
|
|
|
|
clientConfiguration.setSignerOverride(config.getSignerOverride()); |
|
|
|
|
|
|
|
clientConfiguration.setProtocol(Protocol.HTTP); |
|
|
|
|
|
|
|
amazonS3ClientBuilder = amazonS3ClientBuilder.withClientConfiguration(clientConfiguration); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
this.s3 = amazonS3ClientBuilder.build(); |
|
|
|
this.bucket = config.getBucket(); |
|
|
|
this.bucket = config.getBucket(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|