|
|
|
@ -1,5 +1,11 @@
|
|
|
|
|
package com.fanruan.fs.s3.repository.core; |
|
|
|
|
|
|
|
|
|
import com.amazonaws.auth.AWSStaticCredentialsProvider; |
|
|
|
|
import com.amazonaws.auth.BasicAWSCredentials; |
|
|
|
|
import com.amazonaws.client.builder.AwsClientBuilder; |
|
|
|
|
import com.amazonaws.services.s3.AmazonS3; |
|
|
|
|
import com.amazonaws.services.s3.AmazonS3ClientBuilder; |
|
|
|
|
import com.fanruan.api.log.LogKit; |
|
|
|
|
import com.fr.io.base.provider.impl.ConfigRepositoryFactory; |
|
|
|
|
import com.fr.io.context.info.RepositoryProfile; |
|
|
|
|
import com.fr.io.repository.ResourceRepository; |
|
|
|
@ -28,9 +34,19 @@ public class S3RepositoryFactory extends ConfigRepositoryFactory<S3Config> {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public boolean verifyConfig(S3Config s3Config) { |
|
|
|
|
public boolean verifyConfig(S3Config config) { |
|
|
|
|
try { |
|
|
|
|
BasicAWSCredentials credentials = new BasicAWSCredentials(config.getAccessKeyId(), config.getAccessKeySecret()); |
|
|
|
|
AmazonS3 s3 = AmazonS3ClientBuilder.standard() |
|
|
|
|
.withEndpointConfiguration(new AwsClientBuilder.EndpointConfiguration(config.getEndPoint(), config.getRegion())) |
|
|
|
|
.withCredentials(new AWSStaticCredentialsProvider(credentials)).build(); |
|
|
|
|
s3.listObjects(config.getBucket()); |
|
|
|
|
} catch (Exception e) { |
|
|
|
|
LogKit.error(e.getMessage(), e); |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public ResourceRepository produce(String repoName, String workRoot, S3Config config) { |
|
|
|
|