Browse Source

Pull request #61: REPORT-74814 feat: 新增两个后台配置项

Merge in PG/plugin-repository-s3 from ~AFLY/plugin-repository-s3:release/11.0 to release/11.0

* commit 'a3901cd06e54b5920341f061661f5de9f34926ee':
  REPORT-74814 feat: 新增两个后台配置项
release/11.0
Afly 3 years ago
parent
commit
77ee1d9227
  1. 3
      plugin.xml
  2. 30
      src/main/java/com/fanruan/fs/s3/repository/core/S3Config.java
  3. 17
      src/main/java/com/fanruan/fs/s3/repository/core/S3RepositoryFactory.java
  4. 17
      src/main/java/com/fanruan/fs/s3/repository/core/S3ResourceRepository.java

3
plugin.xml

@ -5,12 +5,13 @@
<main-package>com.fanruan.fs</main-package>
<active>yes</active>
<hidden>no</hidden>
<version>1.3.2</version>
<version>1.3.3</version>
<env-version>11.0~11.0</env-version>
<jartime>2021-08-30</jartime>
<vendor>richie</vendor>
<description><![CDATA[使用支持S3协议的云存储文件系统作为文件服务器。]]></description>
<change-notes><![CDATA[
[2022-06-30]新增enablePathStyleAccess、signerOverride后台配置<br/>
[2022-06-13]第三方组件升级<br/>
[2022-03-10]第三方组件升级<br/>
[2021-12-29]插件引用的url更改<br/>

30
src/main/java/com/fanruan/fs/s3/repository/core/S3Config.java

@ -32,6 +32,12 @@ public class S3Config extends CommonRepoConfig {
@Identifier("bucket")
private Conf<String> bucket = HolderKit.simple(StringUtils.EMPTY);
@Identifier("enablePathStyleAccess")
private Conf<Boolean> enablePathStyleAccess = HolderKit.simple(false);
@Identifier("signerOverride")
private Conf<String> 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<String>) region.clone();
cloned.accessKeyId = (Conf<String>) accessKeyId.clone();
cloned.bucket = (Conf<String>) bucket.clone();
cloned.enablePathStyleAccess = (Conf<Boolean>) enablePathStyleAccess.clone();
cloned.signerOverride = (Conf<String>) signerOverride.clone();
return cloned;
}
}

17
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<S3Config> {
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);

17
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();
}

Loading…
Cancel
Save