Skip to content

Commit f5a6a5f

Browse files
committed
Add Endpoint to S3ClientConfiguration used to configure S3TransferManager
1 parent a0d9faf commit f5a6a5f

File tree

6 files changed

+73
-6
lines changed

6 files changed

+73
-6
lines changed

services-custom/s3-transfer-manager/src/main/java/software/amazon/awssdk/transfer/s3/S3ClientConfiguration.java

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,15 @@
3535
@SdkPreviewApi
3636
public final class S3ClientConfiguration implements ToCopyableBuilder<S3ClientConfiguration.Builder, S3ClientConfiguration> {
3737
private final AwsCredentialsProvider credentialsProvider;
38+
private final String endpoint;
3839
private final Region region;
3940
private final Long minimumPartSizeInBytes;
4041
private final Double targetThroughputInGbps;
4142
private final Integer maxConcurrency;
4243

4344
private S3ClientConfiguration(DefaultBuilder builder) {
4445
this.credentialsProvider = builder.credentialsProvider;
46+
this.endpoint = builder.endpoint;
4547
this.region = builder.region;
4648
this.minimumPartSizeInBytes = Validate.isPositiveOrNull(builder.minimumPartSizeInBytes, "minimumPartSizeInBytes");
4749
this.targetThroughputInGbps = Validate.isPositiveOrNull(builder.targetThroughputInGbps, "targetThroughputInGbps");
@@ -56,6 +58,13 @@ public Optional<AwsCredentialsProvider> credentialsProvider() {
5658
return Optional.ofNullable(credentialsProvider);
5759
}
5860

61+
/**
62+
* @return the optional endpoint with which the SDK should communicate.
63+
*/
64+
public Optional<String> endpoint() {
65+
return Optional.ofNullable(endpoint);
66+
}
67+
5968
/**
6069
* @return the optional region with which the SDK should communicate.
6170
*/
@@ -103,6 +112,9 @@ public boolean equals(Object o) {
103112
if (!Objects.equals(credentialsProvider, that.credentialsProvider)) {
104113
return false;
105114
}
115+
if (!Objects.equals(endpoint, that.endpoint)) {
116+
return false;
117+
}
106118
if (!Objects.equals(region, that.region)) {
107119
return false;
108120
}
@@ -118,6 +130,7 @@ public boolean equals(Object o) {
118130
@Override
119131
public int hashCode() {
120132
int result = credentialsProvider != null ? credentialsProvider.hashCode() : 0;
133+
result = 31 * result + (endpoint != null ? endpoint.hashCode() : 0);
121134
result = 31 * result + (region != null ? region.hashCode() : 0);
122135
result = 31 * result + (minimumPartSizeInBytes != null ? minimumPartSizeInBytes.hashCode() : 0);
123136
result = 31 * result + (targetThroughputInGbps != null ? targetThroughputInGbps.hashCode() : 0);
@@ -159,6 +172,16 @@ public interface Builder extends CopyableBuilder<Builder, S3ClientConfiguration>
159172
*/
160173
Builder credentialsProvider(AwsCredentialsProvider credentialsProvider);
161174

175+
/**
176+
* Configure the endpoint with which the SDK should communicate.
177+
*
178+
* <p>If this is not specified, the SDK will attempt to identify the endpoint automatically using the region parameter.
179+
*
180+
* @param endpoint the endpoint to be used
181+
* @return this builder for method chaining.
182+
*/
183+
Builder endpoint(String endpoint);
184+
162185
/**
163186
* Configure the region with which the SDK should communicate.
164187
*
@@ -220,6 +243,7 @@ public interface Builder extends CopyableBuilder<Builder, S3ClientConfiguration>
220243

221244
private static final class DefaultBuilder implements Builder {
222245
private AwsCredentialsProvider credentialsProvider;
246+
private String endpoint;
223247
private Region region;
224248
private Long minimumPartSizeInBytes;
225249
private Double targetThroughputInGbps;
@@ -230,6 +254,7 @@ private DefaultBuilder() {
230254

231255
private DefaultBuilder(S3ClientConfiguration configuration) {
232256
this.credentialsProvider = configuration.credentialsProvider;
257+
this.endpoint = configuration.endpoint;
233258
this.region = configuration.region;
234259
this.minimumPartSizeInBytes = configuration.minimumPartSizeInBytes;
235260
this.targetThroughputInGbps = configuration.targetThroughputInGbps;
@@ -242,6 +267,12 @@ public Builder credentialsProvider(AwsCredentialsProvider credentialsProvider) {
242267
return this;
243268
}
244269

270+
@Override
271+
public Builder endpoint(String endpoint) {
272+
this.endpoint = endpoint;
273+
return this;
274+
}
275+
245276
@Override
246277
public Builder region(Region region) {
247278
this.region = region;

services-custom/s3-transfer-manager/src/main/java/software/amazon/awssdk/transfer/s3/internal/DefaultS3CrtAsyncClient.java

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
import software.amazon.awssdk.core.async.AsyncRequestBody;
2626
import software.amazon.awssdk.core.async.AsyncResponseTransformer;
2727
import software.amazon.awssdk.core.client.config.ClientAsyncConfiguration;
28+
import software.amazon.awssdk.crt.s3.S3Client;
29+
import software.amazon.awssdk.crt.s3.S3ClientOptions;
2830
import software.amazon.awssdk.http.SdkHttpResponse;
2931
import software.amazon.awssdk.regions.Region;
3032
import software.amazon.awssdk.services.s3.model.GetObjectRequest;
@@ -42,6 +44,7 @@ public final class DefaultS3CrtAsyncClient implements S3CrtAsyncClient {
4244
public DefaultS3CrtAsyncClient(DefaultS3CrtClientBuilder builder) {
4345
S3NativeClientConfiguration.Builder configBuilder =
4446
S3NativeClientConfiguration.builder()
47+
.endpoint(builder.endpoint)
4548
.targetThroughputInGbps(builder.targetThroughputInGbps())
4649
.partSizeInBytes(builder.minimumPartSizeInBytes())
4750
.maxConcurrency(builder.maxConcurrency)
@@ -53,12 +56,16 @@ public DefaultS3CrtAsyncClient(DefaultS3CrtClientBuilder builder) {
5356

5457
configuration = configBuilder.build();
5558

56-
this.s3NativeClient = new S3NativeClient(configuration.signingRegion(),
57-
configuration.clientBootstrap(),
58-
configuration.credentialsProvider(),
59-
configuration.partSizeBytes(),
60-
configuration.targetThroughputInGbps(),
61-
configuration.maxConcurrency());
59+
S3ClientOptions s3ClientOptions =
60+
new S3ClientOptions().withEndpoint(configuration.endpoint())
61+
.withRegion(configuration.signingRegion())
62+
.withClientBootstrap(configuration.clientBootstrap())
63+
.withCredentialsProvider(configuration.credentialsProvider())
64+
.withPartSize(configuration.partSizeBytes())
65+
.withThroughputTargetGbps(configuration.targetThroughputInGbps())
66+
.withMaxConnections(configuration.maxConcurrency());
67+
68+
this.s3NativeClient = new S3NativeClient(configuration.signingRegion(), new S3Client(s3ClientOptions));
6269
this.crtErrorHandler = new CrtErrorHandler();
6370
}
6471

@@ -157,6 +164,7 @@ public void close() {
157164

158165
public static final class DefaultS3CrtClientBuilder implements S3CrtAsyncClientBuilder {
159166
private AwsCredentialsProvider credentialsProvider;
167+
private String endpoint;
160168
private Region region;
161169
private Long minimalPartSizeInBytes;
162170
private Double targetThroughputInGbps;
@@ -167,6 +175,10 @@ public AwsCredentialsProvider credentialsProvider() {
167175
return credentialsProvider;
168176
}
169177

178+
public String endpoint() {
179+
return endpoint;
180+
}
181+
170182
public Region region() {
171183
return region;
172184
}
@@ -189,6 +201,12 @@ public S3CrtAsyncClientBuilder credentialsProvider(AwsCredentialsProvider creden
189201
return this;
190202
}
191203

204+
@Override
205+
public S3CrtAsyncClientBuilder endpoint(String endpoint) {
206+
this.endpoint = endpoint;
207+
return this;
208+
}
209+
192210
@Override
193211
public S3CrtAsyncClientBuilder region(Region region) {
194212
this.region = region;

services-custom/s3-transfer-manager/src/main/java/software/amazon/awssdk/transfer/s3/internal/DefaultS3TransferManager.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ private TransferManagerConfiguration resolveTransferManagerConfiguration(Default
8181
private S3CrtAsyncClient initializeS3CrtClient(DefaultBuilder tmBuilder) {
8282
S3CrtAsyncClient.S3CrtAsyncClientBuilder clientBuilder = S3CrtAsyncClient.builder();
8383
tmBuilder.s3ClientConfiguration.credentialsProvider().ifPresent(clientBuilder::credentialsProvider);
84+
tmBuilder.s3ClientConfiguration.endpoint().ifPresent(clientBuilder::endpoint);
8485
tmBuilder.s3ClientConfiguration.maxConcurrency().ifPresent(clientBuilder::maxConcurrency);
8586
tmBuilder.s3ClientConfiguration.minimumPartSizeInBytes().ifPresent(clientBuilder::minimumPartSizeInBytes);
8687
tmBuilder.s3ClientConfiguration.region().ifPresent(clientBuilder::region);

services-custom/s3-transfer-manager/src/main/java/software/amazon/awssdk/transfer/s3/internal/S3CrtAsyncClient.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ public interface S3CrtAsyncClient extends S3AsyncClient {
3333
interface S3CrtAsyncClientBuilder extends SdkBuilder<S3CrtAsyncClientBuilder, S3CrtAsyncClient> {
3434
S3CrtAsyncClientBuilder credentialsProvider(AwsCredentialsProvider credentialsProvider);
3535

36+
S3CrtAsyncClientBuilder endpoint(String endpoint);
37+
3638
S3CrtAsyncClientBuilder region(Region region);
3739

3840
S3CrtAsyncClientBuilder minimumPartSizeInBytes(Long uploadPartSize);

services-custom/s3-transfer-manager/src/main/java/software/amazon/awssdk/transfer/s3/internal/S3NativeClientConfiguration.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
public class S3NativeClientConfiguration implements SdkAutoCloseable {
4444
private static final long DEFAULT_PART_SIZE_IN_BYTES = 8L * SizeConstant.MB;
4545
private static final long DEFAULT_TARGET_THROUGHPUT_IN_GBPS = 5;
46+
private final String endpoint;
4647
private final String signingRegion;
4748
private final ClientBootstrap clientBootstrap;
4849
private final CrtCredentialsProviderAdapter credentialProviderAdapter;
@@ -53,6 +54,7 @@ public class S3NativeClientConfiguration implements SdkAutoCloseable {
5354
private final Executor futureCompletionExecutor;
5455

5556
public S3NativeClientConfiguration(Builder builder) {
57+
this.endpoint = builder.endpoint;
5658
this.signingRegion = builder.signingRegion == null ? DefaultAwsRegionProviderChain.builder().build().getRegion().id() :
5759
builder.signingRegion;
5860
this.clientBootstrap = new ClientBootstrap(null, null);
@@ -79,6 +81,10 @@ public static Builder builder() {
7981
return new Builder();
8082
}
8183

84+
public String endpoint() {
85+
return endpoint;
86+
}
87+
8288
public String signingRegion() {
8389
return signingRegion;
8490
}
@@ -150,6 +156,7 @@ private void shutdownIfExecutorService(Object object) {
150156
}
151157

152158
public static final class Builder {
159+
private String endpoint;
153160
private String signingRegion;
154161
private AwsCredentialsProvider credentialsProvider;
155162
private Long partSizeInBytes;
@@ -160,6 +167,11 @@ public static final class Builder {
160167
private Builder() {
161168
}
162169

170+
public Builder endpoint(String endpoint) {
171+
this.endpoint = endpoint;
172+
return this;
173+
}
174+
163175
public Builder signingRegion(String signingRegion) {
164176
this.signingRegion = signingRegion;
165177
return this;

services-custom/s3-transfer-manager/src/test/java/software/amazon/awssdk/transfer/s3/S3ClientConfigurationTest.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,12 +72,14 @@ public void build_allProperties() {
7272
.credentialsProvider(credentials)
7373
.maxConcurrency(100)
7474
.targetThroughputInGbps(10.0)
75+
.endpoint("https://s3.us-west-2.amazonaws.com")
7576
.region(Region.US_WEST_2)
7677
.minimumPartSizeInBytes(5 * MB)
7778
.build();
7879

7980
assertThat(configuration.credentialsProvider()).contains(credentials);
8081
assertThat(configuration.maxConcurrency()).contains(100);
82+
assertThat(configuration.endpoint()).contains("https://s3.us-west-2.amazonaws.com");
8183
assertThat(configuration.region()).contains(Region.US_WEST_2);
8284
assertThat(configuration.targetThroughputInGbps()).contains(10.0);
8385
assertThat(configuration.minimumPartSizeInBytes()).contains(5 * MB);
@@ -90,6 +92,7 @@ public void build_emptyBuilder() {
9092

9193
assertThat(configuration.credentialsProvider()).isEmpty();
9294
assertThat(configuration.maxConcurrency()).isEmpty();
95+
assertThat(configuration.endpoint()).isEmpty();
9396
assertThat(configuration.region()).isEmpty();
9497
assertThat(configuration.targetThroughputInGbps()).isEmpty();
9598
assertThat(configuration.minimumPartSizeInBytes()).isEmpty();

0 commit comments

Comments
 (0)