diff --git a/plugin.xml b/plugin.xml index ee7dd10..252efe0 100644 --- a/plugin.xml +++ b/plugin.xml @@ -5,12 +5,13 @@ com.fanruan.fs yes no - 1.3.2 + 1.3.3 11.0~11.0 2021-08-30 richie [2022-06-13]第三方组件升级
[2022-03-10]第三方组件升级
[2021-12-29]插件引用的url更改
diff --git a/src/main/java/com/fanruan/fs/s3/repository/core/S3Config.java b/src/main/java/com/fanruan/fs/s3/repository/core/S3Config.java index 8bb23c4..5821864 100644 --- a/src/main/java/com/fanruan/fs/s3/repository/core/S3Config.java +++ b/src/main/java/com/fanruan/fs/s3/repository/core/S3Config.java @@ -32,6 +32,12 @@ public class S3Config extends CommonRepoConfig { @Identifier("bucket") private Conf bucket = HolderKit.simple(StringUtils.EMPTY); + @Identifier("enablePathStyleAccess") + private Conf enablePathStyleAccess = HolderKit.simple(false); + + @Identifier("signerOverride") + private Conf signerOverride = HolderKit.simple(StringUtils.EMPTY); + @GetConfig("endPoint") public String getEndPoint() { return endPoint.get(); @@ -72,6 +78,26 @@ public class S3Config extends CommonRepoConfig { this.bucket.set(bucket); } + @GetConfig("enablePathStyleAccess") + public boolean isEnablePathStyleAccess() { + return enablePathStyleAccess.get(); + } + + @SetConfig("enablePathStyleAccess") + public void setEnablePathStyleAccess(boolean enablePathStyleAccess) { + this.enablePathStyleAccess.set(enablePathStyleAccess); + } + + @GetConfig("signerOverride") + public String getSignerOverride() { + return signerOverride.get(); + } + + @SetConfig("signerOverride") + public void setSignerOverride(String signerOverride) { + this.signerOverride.set(signerOverride); + } + @Override public void update(String key) { super.update(key); @@ -81,6 +107,8 @@ public class S3Config extends CommonRepoConfig { this.setRegion(newConfig.getRegion()); this.setAccessKeyId(newConfig.getAccessKeyId()); this.setBucket(newConfig.getBucket()); + this.setEnablePathStyleAccess(newConfig.isEnablePathStyleAccess()); + this.setSignerOverride(newConfig.getSignerOverride()); } } @@ -91,6 +119,8 @@ public class S3Config extends CommonRepoConfig { cloned.region = (Conf) region.clone(); cloned.accessKeyId = (Conf) accessKeyId.clone(); cloned.bucket = (Conf) bucket.clone(); + cloned.enablePathStyleAccess = (Conf) enablePathStyleAccess.clone(); + cloned.signerOverride = (Conf) signerOverride.clone(); return cloned; } } diff --git a/src/main/java/com/fanruan/fs/s3/repository/core/S3RepositoryFactory.java b/src/main/java/com/fanruan/fs/s3/repository/core/S3RepositoryFactory.java index c10815a..560d81e 100644 --- a/src/main/java/com/fanruan/fs/s3/repository/core/S3RepositoryFactory.java +++ b/src/main/java/com/fanruan/fs/s3/repository/core/S3RepositoryFactory.java @@ -1,5 +1,7 @@ package com.fanruan.fs.s3.repository.core; +import com.amazonaws.ClientConfiguration; +import com.amazonaws.Protocol; import com.amazonaws.auth.AWSStaticCredentialsProvider; import com.amazonaws.auth.BasicAWSCredentials; import com.amazonaws.client.builder.AwsClientBuilder; @@ -9,6 +11,7 @@ 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; +import com.fr.stable.StringUtils; /** * @author richie @@ -37,9 +40,19 @@ public class S3RepositoryFactory extends ConfigRepositoryFactory { public boolean verifyConfig(S3Config config) { try { BasicAWSCredentials credentials = new BasicAWSCredentials(config.getAccessKeyId(), config.getPassword()); - AmazonS3 s3 = AmazonS3ClientBuilder.standard() + AmazonS3ClientBuilder amazonS3ClientBuilder = AmazonS3ClientBuilder.standard() .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); + } + AmazonS3 s3 = amazonS3ClientBuilder.build(); s3.listObjects(config.getBucket()); } catch (Exception e) { LogKit.error(e.getMessage(), e); diff --git a/src/main/java/com/fanruan/fs/s3/repository/core/S3ResourceRepository.java b/src/main/java/com/fanruan/fs/s3/repository/core/S3ResourceRepository.java index c2bbc6e..28d95e2 100644 --- a/src/main/java/com/fanruan/fs/s3/repository/core/S3ResourceRepository.java +++ b/src/main/java/com/fanruan/fs/s3/repository/core/S3ResourceRepository.java @@ -1,5 +1,7 @@ package com.fanruan.fs.s3.repository.core; +import com.amazonaws.ClientConfiguration; +import com.amazonaws.Protocol; import com.amazonaws.auth.AWSStaticCredentialsProvider; import com.amazonaws.auth.BasicAWSCredentials; 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.base.BaseResourceRepository; import com.fr.stable.Filter; +import com.fr.stable.StringUtils; import com.fr.workspace.resource.ResourceIOException; import java.io.ByteArrayInputStream; @@ -42,9 +45,19 @@ public class S3ResourceRepository extends BaseResourceRepository { public S3ResourceRepository(String repoName, String workRoot, S3Config config) { super(repoName, workRoot); BasicAWSCredentials credentials = new BasicAWSCredentials(config.getAccessKeyId(), config.getPassword()); - this.s3 = AmazonS3ClientBuilder.standard() + AmazonS3ClientBuilder amazonS3ClientBuilder = AmazonS3ClientBuilder.standard() .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(); }