Browse Source

Pull request #206: REPORT-95454 bugfix:http配置根据endpoint进行设置

Merge in PG/plugin-repository-s3 from ~OCEAN.HU/plugin-repository-s3:release/11.0 to release/11.0

* commit '9776c12c7119166869b979fd0d5d6dfaaa019e5f':
  REPORT-95454 bugfix:http配置根据endpoint进行设置
release/11.0
Ocean.Hu-胡浩 2 years ago
parent
commit
69e19ba838
  1. 11
      src/main/java/com/fanruan/fs/s3/repository/core/S3RepositoryFactory.java
  2. 7
      src/main/java/com/fanruan/fs/s3/repository/core/S3ResourceRepository.java

11
src/main/java/com/fanruan/fs/s3/repository/core/S3RepositoryFactory.java

@ -13,6 +13,8 @@ import com.fr.io.context.info.RepositoryProfile;
import com.fr.io.repository.ResourceRepository;
import com.fr.stable.StringUtils;
import static com.fanruan.fs.s3.repository.core.S3ResourceRepository.HTTP;
/**
* @author richie
* @version 10.0
@ -42,16 +44,19 @@ public class S3RepositoryFactory extends ConfigRepositoryFactory<S3Config> {
BasicAWSCredentials credentials = new BasicAWSCredentials(config.getAccessKeyId(), config.getPassword());
AmazonS3ClientBuilder amazonS3ClientBuilder = AmazonS3ClientBuilder.standard()
.withEndpointConfiguration(new AwsClientBuilder.EndpointConfiguration(config.getEndPoint(), config.getRegion()))
.withCredentials(new AWSStaticCredentialsProvider(credentials));
.withCredentials(new AWSStaticCredentialsProvider(credentials)).disableChunkedEncoding();
if (config.isEnablePathStyleAccess()) {
amazonS3ClientBuilder = amazonS3ClientBuilder.enablePathStyleAccess();
}
ClientConfiguration clientConfiguration = new ClientConfiguration();
if (StringUtils.isNotEmpty(config.getSignerOverride())) {
ClientConfiguration clientConfiguration = new ClientConfiguration();
clientConfiguration.setSignerOverride(config.getSignerOverride());
}
LogKit.debug("[S3] endpoint is {}", config.getEndPoint());
if (config.getEndPoint().startsWith(HTTP)) {
clientConfiguration.setProtocol(Protocol.HTTP);
amazonS3ClientBuilder = amazonS3ClientBuilder.withClientConfiguration(clientConfiguration);
}
amazonS3ClientBuilder = amazonS3ClientBuilder.withClientConfiguration(clientConfiguration);
AmazonS3 s3 = amazonS3ClientBuilder.build();
s3.listObjects(config.getBucket());
} catch (Exception e) {

7
src/main/java/com/fanruan/fs/s3/repository/core/S3ResourceRepository.java

@ -38,6 +38,8 @@ public class S3ResourceRepository extends BaseResourceRepository {
private static final String DELIMITER = "/";
public static final String HTTP = "http:";
private final AmazonS3 s3;
private final String bucket;
@ -55,7 +57,10 @@ public class S3ResourceRepository extends BaseResourceRepository {
if (StringUtils.isNotEmpty(config.getSignerOverride())) {
clientConfiguration.setSignerOverride(config.getSignerOverride());
}
clientConfiguration.setProtocol(Protocol.HTTP);
LogKit.debug("[S3] endpoint is {}", config.getEndPoint());
if (config.getEndPoint().startsWith(HTTP)) {
clientConfiguration.setProtocol(Protocol.HTTP);
}
amazonS3ClientBuilder = amazonS3ClientBuilder.withClientConfiguration(clientConfiguration);
this.s3 = amazonS3ClientBuilder.build();
this.bucket = config.getBucket();

Loading…
Cancel
Save