73
73
@ SdkPublicApi
74
74
public final class S3Utilities {
75
75
private final Region region ;
76
+ private final URI endpoint ;
76
77
private final S3Configuration s3Configuration ;
77
78
private final ProfileFile profileFile ;
78
79
private final String profileName ;
@@ -83,6 +84,7 @@ public final class S3Utilities {
83
84
*/
84
85
private S3Utilities (Builder builder ) {
85
86
this .region = Validate .paramNotNull (builder .region , "Region" );
87
+ this .endpoint = builder .endpoint ;
86
88
this .s3Configuration = builder .s3Configuration ;
87
89
this .profileFile = builder .profileFile ;
88
90
this .profileName = builder .profileName ;
@@ -100,6 +102,7 @@ public static Builder builder() {
100
102
static S3Utilities create (SdkClientConfiguration clientConfiguration ) {
101
103
return S3Utilities .builder ()
102
104
.region (clientConfiguration .option (AwsClientOption .AWS_REGION ))
105
+ .endpoint (clientConfiguration .option (SdkClientOption .ENDPOINT ))
103
106
.s3Configuration ((S3Configuration ) clientConfiguration .option (SdkClientOption .SERVICE_CONFIGURATION ))
104
107
.profileFile (clientConfiguration .option (SdkClientOption .PROFILE_FILE ))
105
108
.profileName (clientConfiguration .option (SdkClientOption .PROFILE_NAME ))
@@ -188,8 +191,9 @@ private Region resolveRegionForGetUrl(GetUrlRequest getUrlRequest) {
188
191
/**
189
192
* If endpoint is not present, construct a default endpoint using the region information.
190
193
*/
191
- private URI resolveEndpoint (URI endpoint , Region region ) {
192
- return endpoint != null ? endpoint
194
+ private URI resolveEndpoint (URI requestOverrideEndpoint , Region region ) {
195
+ URI overrideEndpoint = requestOverrideEndpoint != null ? requestOverrideEndpoint : endpoint ;
196
+ return overrideEndpoint != null ? overrideEndpoint
193
197
: new DefaultServiceEndpointBuilder ("s3" , "https" ).withRegion (region )
194
198
.withProfileFile (profileFile )
195
199
.withProfileName (profileName )
@@ -227,6 +231,7 @@ private SdkHttpFullRequest createMarshalledRequest(GetUrlRequest getUrlRequest,
227
231
*/
228
232
public static final class Builder {
229
233
private Region region ;
234
+ private URI endpoint ;
230
235
231
236
private S3Configuration s3Configuration ;
232
237
private ProfileFile profileFile ;
@@ -248,6 +253,19 @@ public Builder region(Region region) {
248
253
return this ;
249
254
}
250
255
256
+ /**
257
+ * The default endpoint to use when working with the methods in {@link S3Utilities} class.
258
+ *
259
+ * There can be methods in {@link S3Utilities} that don't need the endpoint info.
260
+ * In that case, this option will be ignored when using those methods.
261
+ *
262
+ * @return This object for method chaining
263
+ */
264
+ public Builder endpoint (URI endpoint ) {
265
+ this .endpoint = endpoint ;
266
+ return this ;
267
+ }
268
+
251
269
/**
252
270
* Sets the S3 configuration to enable options like path style access, dual stack, accelerate mode etc.
253
271
*
0 commit comments