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
/**
@@ -188,10 +205,13 @@ S3ClientSettings refine(RepositoryMetaData metadata) {
188
205
} else {
189
206
newCredentials = credentials ;
190
207
}
208
+ final String newRegion = getRepoSettingOrDefault (REGION , normalizedSettings , region );
209
+ final String newSignerOverride = getRepoSettingOrDefault (SIGNER_OVERRIDE , normalizedSettings , signerOverride );
191
210
if (Objects .equals (endpoint , newEndpoint ) && protocol == newProtocol && Objects .equals (proxyHost , newProxyHost )
192
211
&& proxyPort == newProxyPort && newReadTimeoutMillis == readTimeoutMillis && maxRetries == newMaxRetries
193
212
&& newThrottleRetries == throttleRetries && Objects .equals (credentials , newCredentials )
194
- && newDisableChunkedEncoding == disableChunkedEncoding ) {
213
+ && newDisableChunkedEncoding == disableChunkedEncoding
214
+ && Objects .equals (region , newRegion ) && Objects .equals (signerOverride , newSignerOverride )) {
195
215
return this ;
196
216
}
197
217
return new S3ClientSettings (
@@ -206,7 +226,9 @@ S3ClientSettings refine(RepositoryMetaData metadata) {
206
226
newMaxRetries ,
207
227
newThrottleRetries ,
208
228
usePathStyleAccess ,
209
- newDisableChunkedEncoding
229
+ newDisableChunkedEncoding ,
230
+ newRegion ,
231
+ newSignerOverride
210
232
);
211
233
}
212
234
@@ -295,7 +317,9 @@ static S3ClientSettings getClientSettings(final Settings settings, final String
295
317
getConfigValue (settings , clientName , MAX_RETRIES_SETTING ),
296
318
getConfigValue (settings , clientName , USE_THROTTLE_RETRIES_SETTING ),
297
319
getConfigValue (settings , clientName , USE_PATH_STYLE_ACCESS ),
298
- getConfigValue (settings , clientName , DISABLE_CHUNKED_ENCODING )
320
+ getConfigValue (settings , clientName , DISABLE_CHUNKED_ENCODING ),
321
+ getConfigValue (settings , clientName , REGION ),
322
+ getConfigValue (settings , clientName , SIGNER_OVERRIDE )
299
323
);
300
324
}
301
325
}
@@ -319,13 +343,15 @@ public boolean equals(final Object o) {
319
343
Objects .equals (proxyHost , that .proxyHost ) &&
320
344
Objects .equals (proxyUsername , that .proxyUsername ) &&
321
345
Objects .equals (proxyPassword , that .proxyPassword ) &&
322
- Objects .equals (disableChunkedEncoding , that .disableChunkedEncoding );
346
+ Objects .equals (disableChunkedEncoding , that .disableChunkedEncoding ) &&
347
+ Objects .equals (region , that .region ) &&
348
+ Objects .equals (signerOverride , that .signerOverride );
323
349
}
324
350
325
351
@ Override
326
352
public int hashCode () {
327
353
return Objects .hash (credentials , endpoint , protocol , proxyHost , proxyPort , proxyUsername , proxyPassword ,
328
- readTimeoutMillis , maxRetries , throttleRetries , disableChunkedEncoding );
354
+ readTimeoutMillis , maxRetries , throttleRetries , disableChunkedEncoding , region , signerOverride );
329
355
}
330
356
331
357
private static <T > T getConfigValue (Settings settings , String clientName ,
0 commit comments