Fix Path Style Access Setting Priority (#55439) (#55444)

* Fix Path Style Access Setting Priority

Fixing obvious bug in handling path style access if it's the only setting overridden by the
repository settings.

Closes #55407
This commit is contained in:
Armin Braun 2020-04-20 11:47:41 +02:00 committed by GitHub
parent e98b68b5f5
commit 5550d8f3f6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 3 deletions

View File

@ -196,7 +196,7 @@ final class S3ClientSettings {
getRepoSettingOrDefault(READ_TIMEOUT_SETTING, normalizedSettings, TimeValue.timeValueMillis(readTimeoutMillis)).millis()); getRepoSettingOrDefault(READ_TIMEOUT_SETTING, normalizedSettings, TimeValue.timeValueMillis(readTimeoutMillis)).millis());
final int newMaxRetries = getRepoSettingOrDefault(MAX_RETRIES_SETTING, normalizedSettings, maxRetries); final int newMaxRetries = getRepoSettingOrDefault(MAX_RETRIES_SETTING, normalizedSettings, maxRetries);
final boolean newThrottleRetries = getRepoSettingOrDefault(USE_THROTTLE_RETRIES_SETTING, normalizedSettings, throttleRetries); final boolean newThrottleRetries = getRepoSettingOrDefault(USE_THROTTLE_RETRIES_SETTING, normalizedSettings, throttleRetries);
final boolean usePathStyleAccess = getRepoSettingOrDefault(USE_PATH_STYLE_ACCESS, normalizedSettings, pathStyleAccess); final boolean newPathStyleAccess = getRepoSettingOrDefault(USE_PATH_STYLE_ACCESS, normalizedSettings, pathStyleAccess);
final boolean newDisableChunkedEncoding = getRepoSettingOrDefault( final boolean newDisableChunkedEncoding = getRepoSettingOrDefault(
DISABLE_CHUNKED_ENCODING, normalizedSettings, disableChunkedEncoding); DISABLE_CHUNKED_ENCODING, normalizedSettings, disableChunkedEncoding);
final S3BasicCredentials newCredentials; final S3BasicCredentials newCredentials;
@ -210,6 +210,7 @@ final class S3ClientSettings {
if (Objects.equals(endpoint, newEndpoint) && protocol == newProtocol && Objects.equals(proxyHost, newProxyHost) if (Objects.equals(endpoint, newEndpoint) && protocol == newProtocol && Objects.equals(proxyHost, newProxyHost)
&& proxyPort == newProxyPort && newReadTimeoutMillis == readTimeoutMillis && maxRetries == newMaxRetries && proxyPort == newProxyPort && newReadTimeoutMillis == readTimeoutMillis && maxRetries == newMaxRetries
&& newThrottleRetries == throttleRetries && Objects.equals(credentials, newCredentials) && newThrottleRetries == throttleRetries && Objects.equals(credentials, newCredentials)
&& newPathStyleAccess == pathStyleAccess
&& newDisableChunkedEncoding == disableChunkedEncoding && newDisableChunkedEncoding == disableChunkedEncoding
&& Objects.equals(region, newRegion) && Objects.equals(signerOverride, newSignerOverride)) { && Objects.equals(region, newRegion) && Objects.equals(signerOverride, newSignerOverride)) {
return this; return this;
@ -225,7 +226,7 @@ final class S3ClientSettings {
newReadTimeoutMillis, newReadTimeoutMillis,
newMaxRetries, newMaxRetries,
newThrottleRetries, newThrottleRetries,
usePathStyleAccess, newPathStyleAccess,
newDisableChunkedEncoding, newDisableChunkedEncoding,
newRegion, newRegion,
newSignerOverride newSignerOverride

View File

@ -131,7 +131,7 @@ public class S3ClientSettingsTests extends ESTestCase {
{ {
final S3ClientSettings refinedSettings = baseSettings.refine(new RepositoryMetadata("name", "type", Settings.EMPTY)); final S3ClientSettings refinedSettings = baseSettings.refine(new RepositoryMetadata("name", "type", Settings.EMPTY));
assertTrue(refinedSettings == baseSettings); assertSame(refinedSettings, baseSettings);
} }
{ {
@ -144,6 +144,16 @@ public class S3ClientSettingsTests extends ESTestCase {
assertThat(credentials.getAWSSecretKey(), is("secret_key")); assertThat(credentials.getAWSSecretKey(), is("secret_key"));
assertThat(credentials.getSessionToken(), is("session_token")); assertThat(credentials.getSessionToken(), is("session_token"));
} }
{
final S3ClientSettings refinedSettings = baseSettings.refine(new RepositoryMetadata("name", "type",
Settings.builder().put("path_style_access", true).build()));
assertThat(refinedSettings.pathStyleAccess, is(true));
S3BasicSessionCredentials credentials = (S3BasicSessionCredentials) refinedSettings.credentials;
assertThat(credentials.getAWSAccessKeyId(), is("access_key"));
assertThat(credentials.getAWSSecretKey(), is("secret_key"));
assertThat(credentials.getSessionToken(), is("session_token"));
}
} }
public void testPathStyleAccessCanBeSet() { public void testPathStyleAccessCanBeSet() {