35
35
import java .util .Map ;
36
36
import java .util .Objects ;
37
37
import java .util .Set ;
38
+ import java .util .function .Function ;
38
39
39
40
/**
40
41
* A container for settings used to create an S3 client.
@@ -103,6 +104,14 @@ final class S3ClientSettings {
103
104
static final Setting .AffixSetting <Boolean > DISABLE_CHUNKED_ENCODING = Setting .affixKeySetting (PREFIX , "disable_chunked_encoding" ,
104
105
key -> Setting .boolSetting (key , false , Property .NodeScope ));
105
106
107
+ /** An override for the s3 region to use for signing requests. */
108
+ static final Setting .AffixSetting <String > REGION = Setting .affixKeySetting (PREFIX , "region" ,
109
+ key -> new Setting <>(key , "" , Function .identity (), Property .NodeScope ));
110
+
111
+ /** An override for the signer to use. */
112
+ static final Setting .AffixSetting <String > SIGNER_OVERRIDE = Setting .affixKeySetting (PREFIX , "signer_override" ,
113
+ key -> new Setting <>(key , "" , Function .identity (), Property .NodeScope ));
114
+
106
115
/** Credentials to authenticate with s3. */
107
116
final S3BasicCredentials credentials ;
108
117
@@ -141,10 +150,16 @@ final class S3ClientSettings {
141
150
/** Whether chunked encoding should be disabled or not. */
142
151
final boolean disableChunkedEncoding ;
143
152
153
+ /** Region to use for signing requests or empty string to use default. */
154
+ final String region ;
155
+
156
+ /** Signer override to use or empty string to use default. */
157
+ final String signerOverride ;
158
+
144
159
private S3ClientSettings (S3BasicCredentials credentials , String endpoint , Protocol protocol ,
145
160
String proxyHost , int proxyPort , String proxyUsername , String proxyPassword ,
146
161
int readTimeoutMillis , int maxRetries , boolean throttleRetries ,
147
- boolean pathStyleAccess , boolean disableChunkedEncoding ) {
162
+ boolean pathStyleAccess , boolean disableChunkedEncoding , String region , String signerOverride ) {
148
163
this .credentials = credentials ;
149
164
this .endpoint = endpoint ;
150
165
this .protocol = protocol ;
@@ -157,6 +172,8 @@ private S3ClientSettings(S3BasicCredentials credentials, String endpoint, Protoc
157
172
this .throttleRetries = throttleRetries ;
158
173
this .pathStyleAccess = pathStyleAccess ;
159
174
this .disableChunkedEncoding = disableChunkedEncoding ;
175
+ this .region = region ;
176
+ this .signerOverride = signerOverride ;
160
177
}
161
178
162
179
/**
@@ -182,10 +199,13 @@ S3ClientSettings refine(RepositoryMetaData metadata) {
182
199
final boolean usePathStyleAccess = getRepoSettingOrDefault (USE_PATH_STYLE_ACCESS , normalizedSettings , pathStyleAccess );
183
200
final boolean newDisableChunkedEncoding = getRepoSettingOrDefault (
184
201
DISABLE_CHUNKED_ENCODING , normalizedSettings , disableChunkedEncoding );
202
+ final String newRegion = getRepoSettingOrDefault (REGION , normalizedSettings , region );
203
+ final String newSignerOverride = getRepoSettingOrDefault (SIGNER_OVERRIDE , normalizedSettings , signerOverride );
185
204
if (Objects .equals (endpoint , newEndpoint ) && protocol == newProtocol && Objects .equals (proxyHost , newProxyHost )
186
205
&& proxyPort == newProxyPort && newReadTimeoutMillis == readTimeoutMillis && maxRetries == newMaxRetries
187
206
&& newThrottleRetries == throttleRetries
188
- && newDisableChunkedEncoding == disableChunkedEncoding ) {
207
+ && newDisableChunkedEncoding == disableChunkedEncoding
208
+ && Objects .equals (region , newRegion ) && Objects .equals (signerOverride , newSignerOverride )) {
189
209
return this ;
190
210
}
191
211
return new S3ClientSettings (
@@ -200,7 +220,9 @@ S3ClientSettings refine(RepositoryMetaData metadata) {
200
220
newMaxRetries ,
201
221
newThrottleRetries ,
202
222
usePathStyleAccess ,
203
- newDisableChunkedEncoding
223
+ newDisableChunkedEncoding ,
224
+ newRegion ,
225
+ newSignerOverride
204
226
);
205
227
}
206
228
@@ -266,7 +288,9 @@ static S3ClientSettings getClientSettings(final Settings settings, final String
266
288
getConfigValue (settings , clientName , MAX_RETRIES_SETTING ),
267
289
getConfigValue (settings , clientName , USE_THROTTLE_RETRIES_SETTING ),
268
290
getConfigValue (settings , clientName , USE_PATH_STYLE_ACCESS ),
269
- getConfigValue (settings , clientName , DISABLE_CHUNKED_ENCODING )
291
+ getConfigValue (settings , clientName , DISABLE_CHUNKED_ENCODING ),
292
+ getConfigValue (settings , clientName , REGION ),
293
+ getConfigValue (settings , clientName , SIGNER_OVERRIDE )
270
294
);
271
295
}
272
296
}
@@ -290,13 +314,15 @@ public boolean equals(final Object o) {
290
314
Objects .equals (proxyHost , that .proxyHost ) &&
291
315
Objects .equals (proxyUsername , that .proxyUsername ) &&
292
316
Objects .equals (proxyPassword , that .proxyPassword ) &&
293
- Objects .equals (disableChunkedEncoding , that .disableChunkedEncoding );
317
+ Objects .equals (disableChunkedEncoding , that .disableChunkedEncoding ) &&
318
+ Objects .equals (region , that .region ) &&
319
+ Objects .equals (signerOverride , that .signerOverride );
294
320
}
295
321
296
322
@ Override
297
323
public int hashCode () {
298
324
return Objects .hash (credentials , endpoint , protocol , proxyHost , proxyPort , proxyUsername , proxyPassword ,
299
- readTimeoutMillis , maxRetries , throttleRetries , disableChunkedEncoding );
325
+ readTimeoutMillis , maxRetries , throttleRetries , disableChunkedEncoding , region , signerOverride );
300
326
}
301
327
302
328
private static <T > T getConfigValue (Settings settings , String clientName ,
0 commit comments