rishabhdaim commented on code in PR #2558:
URL: https://github.com/apache/jackrabbit-oak/pull/2558#discussion_r2416422230
##########
oak-blob-cloud/src/main/java/org/apache/jackrabbit/oak/blob/cloud/s3/Utils.java:
##########
@@ -67,70 +102,84 @@ public final class Utils {
public static final String AWSDOTCOM = "amazonaws.com";
public static final String S3 = "s3";
+ public static final String S3_ACCELERATION = "s3-accelerate";
public static final String DOT = ".";
public static final String DASH = "-";
/**
- * private constructor so that class cannot initialized from outside.
+ * private constructor so that class cannot initialize from outside.
*/
private Utils() {
}
/**
- * Create AmazonS3Client from properties.
- *
- * @param prop properties to configure @link {@link AmazonS3Client}
- * @return {@link AmazonS3Client}
+ * Create S3Client from properties.
+ *
+ * @param prop properties to configure @link {@link S3Client}
+ * @param accReq boolean indicating whether to accelerate requests
+ * @return {@link S3Client}
*/
- public static AmazonS3Client openService(final Properties prop) {
- String accessKey = prop.getProperty(S3Constants.ACCESS_KEY);
- String secretKey = prop.getProperty(S3Constants.SECRET_KEY);
- AmazonS3Client s3service = null;
- if (StringUtils.isEmpty(accessKey)
- || StringUtils.isEmpty(secretKey)) {
- LOG.info("Configuring Amazon Client from environment");
- s3service = new AmazonS3Client(getClientConfiguration(prop));
- } else {
- LOG.info("Configuring Amazon Client from property file.");
- AWSCredentials credentials = new BasicAWSCredentials(accessKey,
- secretKey);
- s3service = new AmazonS3Client(credentials,
- getClientConfiguration(prop));
- }
- String region = prop.getProperty(S3Constants.S3_REGION);
- String endpoint = null;
- String propEndPoint = prop.getProperty(S3Constants.S3_END_POINT);
- if ((propEndPoint != null) & !"".equals(propEndPoint)) {
- endpoint = propEndPoint;
- } else {
- if (StringUtils.isEmpty(region)) {
- com.amazonaws.regions.Region s3Region =
Regions.getCurrentRegion();
- if (s3Region != null) {
- region = s3Region.getName();
- } else {
- throw new AmazonClientException(
- "parameter ["
- + S3Constants.S3_REGION
- + "] not configured and cannot be derived
from environment");
- }
- }
- if (DEFAULT_AWS_BUCKET_REGION.equals(region)) {
- endpoint = S3 + DOT + AWSDOTCOM;
- } else {
- endpoint = S3 + DOT + region + DOT + AWSDOTCOM;
- }
- }
- /*
- * setting endpoint to remove latency of redirection. If endpoint is
- * not set, invocation first goes us standard region, which
- * redirects it to correct location.
- */
- s3service.setEndpoint(endpoint);
- LOG.info("S3 service endpoint [{}] ", endpoint);
- return s3service;
+ public static S3Client openService(final Properties prop, boolean accReq) {
+
+ S3ClientBuilder builder = S3Client.builder();
+
+ builder.credentialsProvider(getAwsCredentials(prop));
+ builder.overrideConfiguration(getClientConfiguration(prop));
+ builder.httpClient(getSdkHttpClient(prop));
+
+ String region = getRegion(prop);
+ builder.endpointOverride(getEndPointUri(prop, accReq, region));
+
+ // region is mandatory even with endpointOverride
+ builder.region(Region.of(region));
+ // to enable cross region bucket access
+ builder.crossRegionAccessEnabled(true);
Review Comment:
We can have a property with a default to `true`.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]