From 7ca3a883c91119660931b9e12ab2f81c15e61594 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Ferreira?= Date: Mon, 5 Feb 2024 10:46:10 +0000 Subject: [PATCH 01/18] remove dependency on com.amazonaws.Protocol from HttpClientSettingsKey --- .../client/core/HttpClientSettingsKey.java | 5 ++--- .../snowflake/client/core/HttpProtocol.java | 19 +++++++++++++++++++ .../net/snowflake/client/core/HttpUtil.java | 15 +++++++++++++-- .../client/jdbc/CustomProxyLatestIT.java | 8 ++++---- 4 files changed, 38 insertions(+), 9 deletions(-) create mode 100644 src/main/java/net/snowflake/client/core/HttpProtocol.java diff --git a/src/main/java/net/snowflake/client/core/HttpClientSettingsKey.java b/src/main/java/net/snowflake/client/core/HttpClientSettingsKey.java index 183655be7..33f6b3ef8 100644 --- a/src/main/java/net/snowflake/client/core/HttpClientSettingsKey.java +++ b/src/main/java/net/snowflake/client/core/HttpClientSettingsKey.java @@ -4,7 +4,6 @@ package net.snowflake.client.core; -import com.amazonaws.Protocol; import com.google.common.base.Strings; import java.io.Serializable; @@ -132,8 +131,8 @@ public String getNonProxyHosts() { return this.nonProxyHosts; } - public Protocol getProxyProtocol() { - return this.proxyProtocol.equalsIgnoreCase("https") ? Protocol.HTTPS : Protocol.HTTP; + public HttpProtocol getProxyProtocol() { + return this.proxyProtocol.equalsIgnoreCase("https") ? HttpProtocol.HTTPS : HttpProtocol.HTTP; } public Boolean getGzipDisabled() { diff --git a/src/main/java/net/snowflake/client/core/HttpProtocol.java b/src/main/java/net/snowflake/client/core/HttpProtocol.java new file mode 100644 index 000000000..3975e4167 --- /dev/null +++ b/src/main/java/net/snowflake/client/core/HttpProtocol.java @@ -0,0 +1,19 @@ +package net.snowflake.client.core; + +public enum HttpProtocol { + + HTTP("http"), + + HTTPS("https"); + + private final String protocol; + + HttpProtocol(String protocol) { + this.protocol = protocol; + } + + @Override + public String toString() { + return protocol; + } +} diff --git a/src/main/java/net/snowflake/client/core/HttpUtil.java b/src/main/java/net/snowflake/client/core/HttpUtil.java index 628d0e28d..3338169cf 100644 --- a/src/main/java/net/snowflake/client/core/HttpUtil.java +++ b/src/main/java/net/snowflake/client/core/HttpUtil.java @@ -123,7 +123,7 @@ public static void closeExpiredAndIdleConnections() { */ public static void setProxyForS3(HttpClientSettingsKey key, ClientConfiguration clientConfig) { if (key != null && key.usesProxy()) { - clientConfig.setProxyProtocol(key.getProxyProtocol()); + clientConfig.setProxyProtocol(toAwsProtocol(key.getProxyProtocol())); clientConfig.setProxyHost(key.getProxyHost()); clientConfig.setProxyPort(key.getProxyPort()); clientConfig.setNonProxyHosts(key.getNonProxyHosts()); @@ -135,6 +135,17 @@ public static void setProxyForS3(HttpClientSettingsKey key, ClientConfiguration } } + private static Protocol toAwsProtocol(HttpProtocol protocol) { + switch (protocol) { + case HTTP: + return Protocol.HTTP; + case HTTPS: + return Protocol.HTTPS; + default: + throw new IllegalArgumentException("Unknown protocol: " + protocol); + } + } + /** * A static function to set S3 proxy params for sessionless connections using the proxy params * from the StageInfo @@ -379,7 +390,7 @@ public static CloseableHttpClient buildHttpClient( new SnowflakeMutableProxyRoutePlanner( key.getProxyHost(), key.getProxyPort(), - key.getProxyProtocol(), + toAwsProtocol(key.getProxyProtocol()), key.getNonProxyHosts())); httpClientBuilder = httpClientBuilder.setProxy(proxy).setRoutePlanner(sdkProxyRoutePlanner); if (!Strings.isNullOrEmpty(key.getProxyUser()) diff --git a/src/test/java/net/snowflake/client/jdbc/CustomProxyLatestIT.java b/src/test/java/net/snowflake/client/jdbc/CustomProxyLatestIT.java index b8379f985..54320beb1 100644 --- a/src/test/java/net/snowflake/client/jdbc/CustomProxyLatestIT.java +++ b/src/test/java/net/snowflake/client/jdbc/CustomProxyLatestIT.java @@ -9,7 +9,6 @@ import static org.hamcrest.MatcherAssert.assertThat; import static org.junit.Assert.assertTrue; -import com.amazonaws.Protocol; import java.io.File; import java.net.Authenticator; import java.net.PasswordAuthentication; @@ -17,6 +16,7 @@ import java.util.Properties; import net.snowflake.client.category.TestCategoryOthers; import net.snowflake.client.core.HttpClientSettingsKey; +import net.snowflake.client.core.HttpProtocol; import net.snowflake.client.core.HttpUtil; import net.snowflake.client.core.SFSession; import net.snowflake.common.core.SqlState; @@ -596,7 +596,7 @@ public void testSetJVMProxyHttp() throws SQLException { "jdbc:snowflake://s3testaccount.us-east-1.snowflakecomputing.com", props); SFSession sfSession = con.unwrap(SnowflakeConnectionV1.class).getSfSession(); HttpClientSettingsKey clientSettingsKey = sfSession.getHttpClientKey(); - assertEquals(Protocol.HTTP, clientSettingsKey.getProxyProtocol()); + assertEquals(HttpProtocol.HTTP, clientSettingsKey.getProxyProtocol()); con.close(); } @@ -622,7 +622,7 @@ public void testSetJVMProxyHttps() throws SQLException { "jdbc:snowflake://s3testaccount.us-east-1.snowflakecomputing.com", props); SFSession sfSession = con.unwrap(SnowflakeConnectionV1.class).getSfSession(); HttpClientSettingsKey clientSettingsKey = sfSession.getHttpClientKey(); - assertEquals(Protocol.HTTPS, clientSettingsKey.getProxyProtocol()); + assertEquals(HttpProtocol.HTTPS, clientSettingsKey.getProxyProtocol()); con.close(); } @@ -647,7 +647,7 @@ public void testSetJVMProxyDefaultHttps() throws SQLException { "jdbc:snowflake://s3testaccount.us-east-1.snowflakecomputing.com", props); SFSession sfSession = con.unwrap(SnowflakeConnectionV1.class).getSfSession(); HttpClientSettingsKey clientSettingsKey = sfSession.getHttpClientKey(); - assertEquals(Protocol.HTTPS, clientSettingsKey.getProxyProtocol()); + assertEquals(HttpProtocol.HTTPS, clientSettingsKey.getProxyProtocol()); con.close(); } From a6c26ce1d7a028b236b18c71b16adce92aa550de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Ferreira?= Date: Tue, 6 Feb 2024 18:53:21 +0000 Subject: [PATCH 02/18] keep backwards compatibility --- .../client/core/HttpClientSettingsKey.java | 10 +++++++++- .../net/snowflake/client/core/HttpUtil.java | 17 +++-------------- .../net/snowflake/client/core/SFSession.java | 2 +- .../client/jdbc/CustomProxyLatestIT.java | 6 +++--- 4 files changed, 16 insertions(+), 19 deletions(-) diff --git a/src/main/java/net/snowflake/client/core/HttpClientSettingsKey.java b/src/main/java/net/snowflake/client/core/HttpClientSettingsKey.java index 33f6b3ef8..2e844195e 100644 --- a/src/main/java/net/snowflake/client/core/HttpClientSettingsKey.java +++ b/src/main/java/net/snowflake/client/core/HttpClientSettingsKey.java @@ -131,7 +131,15 @@ public String getNonProxyHosts() { return this.nonProxyHosts; } - public HttpProtocol getProxyProtocol() { + /** + * @deprecated Use {@link #getProxyHttpProtocol()} + * @return ProxyProtocol + */ + @Deprecated + public com.amazonaws.Protocol getProxyProtocol() { + return this.proxyProtocol.equalsIgnoreCase("https") ? com.amazonaws.Protocol.HTTPS : com.amazonaws.Protocol.HTTP; + } + public HttpProtocol getProxyHttpProtocol() { return this.proxyProtocol.equalsIgnoreCase("https") ? HttpProtocol.HTTPS : HttpProtocol.HTTP; } diff --git a/src/main/java/net/snowflake/client/core/HttpUtil.java b/src/main/java/net/snowflake/client/core/HttpUtil.java index 3338169cf..482e29417 100644 --- a/src/main/java/net/snowflake/client/core/HttpUtil.java +++ b/src/main/java/net/snowflake/client/core/HttpUtil.java @@ -123,7 +123,7 @@ public static void closeExpiredAndIdleConnections() { */ public static void setProxyForS3(HttpClientSettingsKey key, ClientConfiguration clientConfig) { if (key != null && key.usesProxy()) { - clientConfig.setProxyProtocol(toAwsProtocol(key.getProxyProtocol())); + clientConfig.setProxyProtocol(key.getProxyProtocol()); clientConfig.setProxyHost(key.getProxyHost()); clientConfig.setProxyPort(key.getProxyPort()); clientConfig.setNonProxyHosts(key.getNonProxyHosts()); @@ -135,17 +135,6 @@ public static void setProxyForS3(HttpClientSettingsKey key, ClientConfiguration } } - private static Protocol toAwsProtocol(HttpProtocol protocol) { - switch (protocol) { - case HTTP: - return Protocol.HTTP; - case HTTPS: - return Protocol.HTTPS; - default: - throw new IllegalArgumentException("Unknown protocol: " + protocol); - } - } - /** * A static function to set S3 proxy params for sessionless connections using the proxy params * from the StageInfo @@ -307,7 +296,7 @@ public static CloseableHttpClient buildHttpClient( HttpHost proxy = (key != null && key.usesProxy()) ? new HttpHost( - key.getProxyHost(), key.getProxyPort(), key.getProxyProtocol().toString()) + key.getProxyHost(), key.getProxyPort(), key.getProxyHttpProtocol().toString()) : null; // If defaultrequestconfig is not initialized or its proxy settings do not match current proxy // settings, re-build it (current or old proxy settings could be null, so null check is @@ -390,7 +379,7 @@ public static CloseableHttpClient buildHttpClient( new SnowflakeMutableProxyRoutePlanner( key.getProxyHost(), key.getProxyPort(), - toAwsProtocol(key.getProxyProtocol()), + key.getProxyProtocol(), key.getNonProxyHosts())); httpClientBuilder = httpClientBuilder.setProxy(proxy).setRoutePlanner(sdkProxyRoutePlanner); if (!Strings.isNullOrEmpty(key.getProxyUser()) diff --git a/src/main/java/net/snowflake/client/core/SFSession.java b/src/main/java/net/snowflake/client/core/SFSession.java index fec471492..3db9c548a 100644 --- a/src/main/java/net/snowflake/client/core/SFSession.java +++ b/src/main/java/net/snowflake/client/core/SFSession.java @@ -524,7 +524,7 @@ public synchronized void open() throws SFException, SnowflakeSQLException { httpClientSettingsKey.getProxyUser(), !Strings.isNullOrEmpty(httpClientSettingsKey.getProxyPassword()) ? "***" : "(empty)", httpClientSettingsKey.getNonProxyHosts(), - httpClientSettingsKey.getProxyProtocol()); + httpClientSettingsKey.getProxyHttpProtocol()); // TODO: temporarily hardcode sessionParameter debug info. will be changed in the future SFLoginInput loginInput = new SFLoginInput(); diff --git a/src/test/java/net/snowflake/client/jdbc/CustomProxyLatestIT.java b/src/test/java/net/snowflake/client/jdbc/CustomProxyLatestIT.java index 54320beb1..ccff22067 100644 --- a/src/test/java/net/snowflake/client/jdbc/CustomProxyLatestIT.java +++ b/src/test/java/net/snowflake/client/jdbc/CustomProxyLatestIT.java @@ -596,7 +596,7 @@ public void testSetJVMProxyHttp() throws SQLException { "jdbc:snowflake://s3testaccount.us-east-1.snowflakecomputing.com", props); SFSession sfSession = con.unwrap(SnowflakeConnectionV1.class).getSfSession(); HttpClientSettingsKey clientSettingsKey = sfSession.getHttpClientKey(); - assertEquals(HttpProtocol.HTTP, clientSettingsKey.getProxyProtocol()); + assertEquals(HttpProtocol.HTTP, clientSettingsKey.getProxyHttpProtocol()); con.close(); } @@ -622,7 +622,7 @@ public void testSetJVMProxyHttps() throws SQLException { "jdbc:snowflake://s3testaccount.us-east-1.snowflakecomputing.com", props); SFSession sfSession = con.unwrap(SnowflakeConnectionV1.class).getSfSession(); HttpClientSettingsKey clientSettingsKey = sfSession.getHttpClientKey(); - assertEquals(HttpProtocol.HTTPS, clientSettingsKey.getProxyProtocol()); + assertEquals(HttpProtocol.HTTPS, clientSettingsKey.getProxyHttpProtocol()); con.close(); } @@ -647,7 +647,7 @@ public void testSetJVMProxyDefaultHttps() throws SQLException { "jdbc:snowflake://s3testaccount.us-east-1.snowflakecomputing.com", props); SFSession sfSession = con.unwrap(SnowflakeConnectionV1.class).getSfSession(); HttpClientSettingsKey clientSettingsKey = sfSession.getHttpClientKey(); - assertEquals(HttpProtocol.HTTPS, clientSettingsKey.getProxyProtocol()); + assertEquals(HttpProtocol.HTTPS, clientSettingsKey.getProxyHttpProtocol()); con.close(); } From 4db26fc87903bf6e140661ee31f1605ecd2b3a2a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Ferreira?= Date: Tue, 6 Feb 2024 18:55:00 +0000 Subject: [PATCH 03/18] copyright header --- src/main/java/net/snowflake/client/core/HttpProtocol.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/main/java/net/snowflake/client/core/HttpProtocol.java b/src/main/java/net/snowflake/client/core/HttpProtocol.java index 3975e4167..8e282bf0a 100644 --- a/src/main/java/net/snowflake/client/core/HttpProtocol.java +++ b/src/main/java/net/snowflake/client/core/HttpProtocol.java @@ -1,3 +1,7 @@ +/* + * Copyright (c) 2012-2024 Snowflake Computing Inc. All rights reserved. + */ + package net.snowflake.client.core; public enum HttpProtocol { From 7cfb93b0b02371d9e038ac9fca98f1982e19cbb5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Ferreira?= Date: Thu, 8 Feb 2024 08:31:43 +0000 Subject: [PATCH 04/18] fix copyright header --- src/main/java/net/snowflake/client/core/HttpProtocol.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/net/snowflake/client/core/HttpProtocol.java b/src/main/java/net/snowflake/client/core/HttpProtocol.java index 8e282bf0a..c0e625b8b 100644 --- a/src/main/java/net/snowflake/client/core/HttpProtocol.java +++ b/src/main/java/net/snowflake/client/core/HttpProtocol.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012-2024 Snowflake Computing Inc. All rights reserved. + * Copyright (c) 2024 Snowflake Computing Inc. All rights reserved. */ package net.snowflake.client.core; From f1b57bc39128e00ce6c1a519fa8b0ee1926bc079 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Ferreira?= Date: Thu, 8 Feb 2024 08:32:26 +0000 Subject: [PATCH 05/18] do not use getProxyHttpProtocol().toString(), use key.getProxyHttpProtocol().getScheme() instead --- .../java/net/snowflake/client/core/HttpProtocol.java | 9 ++++----- src/main/java/net/snowflake/client/core/HttpUtil.java | 2 +- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/src/main/java/net/snowflake/client/core/HttpProtocol.java b/src/main/java/net/snowflake/client/core/HttpProtocol.java index c0e625b8b..837f3b5fa 100644 --- a/src/main/java/net/snowflake/client/core/HttpProtocol.java +++ b/src/main/java/net/snowflake/client/core/HttpProtocol.java @@ -10,14 +10,13 @@ public enum HttpProtocol { HTTPS("https"); - private final String protocol; + private final String scheme; HttpProtocol(String protocol) { - this.protocol = protocol; + this.scheme = protocol; } - @Override - public String toString() { - return protocol; + public String getScheme() { + return scheme; } } diff --git a/src/main/java/net/snowflake/client/core/HttpUtil.java b/src/main/java/net/snowflake/client/core/HttpUtil.java index 482e29417..b510b7e09 100644 --- a/src/main/java/net/snowflake/client/core/HttpUtil.java +++ b/src/main/java/net/snowflake/client/core/HttpUtil.java @@ -296,7 +296,7 @@ public static CloseableHttpClient buildHttpClient( HttpHost proxy = (key != null && key.usesProxy()) ? new HttpHost( - key.getProxyHost(), key.getProxyPort(), key.getProxyHttpProtocol().toString()) + key.getProxyHost(), key.getProxyPort(), key.getProxyHttpProtocol().getScheme()) : null; // If defaultrequestconfig is not initialized or its proxy settings do not match current proxy // settings, re-build it (current or old proxy settings could be null, so null check is From 6cd37d8e20847c4879b231aa008b27501a763c77 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Ferreira?= Date: Thu, 8 Feb 2024 08:43:20 +0000 Subject: [PATCH 06/18] move setProxyForS3 to S3HttpUtil setSessionlessProxyForS3 was also moved because the methods are related --- .../client/core/HttpClientSettingsKey.java | 2 +- .../net/snowflake/client/core/HttpUtil.java | 59 ++----------- .../client/jdbc/cloud/storage/S3HttpUtil.java | 87 +++++++++++++++++++ .../jdbc/cloud/storage/SnowflakeS3Client.java | 4 +- .../core/CoreUtilsMiscellaneousTest.java | 9 +- 5 files changed, 100 insertions(+), 61 deletions(-) create mode 100644 src/main/java/net/snowflake/client/jdbc/cloud/storage/S3HttpUtil.java diff --git a/src/main/java/net/snowflake/client/core/HttpClientSettingsKey.java b/src/main/java/net/snowflake/client/core/HttpClientSettingsKey.java index 2e844195e..6cc20650c 100644 --- a/src/main/java/net/snowflake/client/core/HttpClientSettingsKey.java +++ b/src/main/java/net/snowflake/client/core/HttpClientSettingsKey.java @@ -123,7 +123,7 @@ public String getUserAgentSuffix() { } /** Be careful of using this! Should only be called when password is later masked. */ - String getProxyPassword() { + public String getProxyPassword() { return this.proxyPassword; } diff --git a/src/main/java/net/snowflake/client/core/HttpUtil.java b/src/main/java/net/snowflake/client/core/HttpUtil.java index b510b7e09..9fc26add7 100644 --- a/src/main/java/net/snowflake/client/core/HttpUtil.java +++ b/src/main/java/net/snowflake/client/core/HttpUtil.java @@ -9,7 +9,6 @@ import static org.apache.http.client.config.CookieSpecs.IGNORE_COOKIES; import com.amazonaws.ClientConfiguration; -import com.amazonaws.Protocol; import com.google.common.annotations.VisibleForTesting; import com.google.common.base.Strings; import com.microsoft.azure.storage.OperationContext; @@ -31,6 +30,7 @@ import net.snowflake.client.jdbc.RestRequest; import net.snowflake.client.jdbc.SnowflakeSQLException; import net.snowflake.client.jdbc.SnowflakeUtil; +import net.snowflake.client.jdbc.cloud.storage.S3HttpUtil; import net.snowflake.client.log.ArgSupplier; import net.snowflake.client.log.SFLogger; import net.snowflake.client.log.SFLoggerFactory; @@ -120,19 +120,10 @@ public static void closeExpiredAndIdleConnections() { * * @param key key to HttpClient map containing OCSP and proxy info * @param clientConfig the configuration needed by S3 to set the proxy + * @deprecated use S3HttpUtil.setProxyForS3(HttpClientSettingsKey, ClientConfiguration) instead */ public static void setProxyForS3(HttpClientSettingsKey key, ClientConfiguration clientConfig) { - if (key != null && key.usesProxy()) { - clientConfig.setProxyProtocol(key.getProxyProtocol()); - clientConfig.setProxyHost(key.getProxyHost()); - clientConfig.setProxyPort(key.getProxyPort()); - clientConfig.setNonProxyHosts(key.getNonProxyHosts()); - if (!Strings.isNullOrEmpty(key.getProxyUser()) - && !Strings.isNullOrEmpty(key.getProxyPassword())) { - clientConfig.setProxyUsername(key.getProxyUser()); - clientConfig.setProxyPassword(key.getProxyPassword()); - } - } + S3HttpUtil.setProxyForS3(key, clientConfig); } /** @@ -142,51 +133,11 @@ public static void setProxyForS3(HttpClientSettingsKey key, ClientConfiguration * @param proxyProperties proxy properties * @param clientConfig the configuration needed by S3 to set the proxy * @throws SnowflakeSQLException + * @deprecated use S3HttpUtil.setSessionlessProxyForS3(Properties, ClientConfiguration) instead */ public static void setSessionlessProxyForS3( Properties proxyProperties, ClientConfiguration clientConfig) throws SnowflakeSQLException { - // do nothing yet - if (proxyProperties != null - && proxyProperties.size() > 0 - && proxyProperties.getProperty(SFSessionProperty.USE_PROXY.getPropertyKey()) != null) { - Boolean useProxy = - Boolean.valueOf( - proxyProperties.getProperty(SFSessionProperty.USE_PROXY.getPropertyKey())); - if (useProxy) { - // set up other proxy related values. - String proxyHost = - proxyProperties.getProperty(SFSessionProperty.PROXY_HOST.getPropertyKey()); - int proxyPort; - try { - proxyPort = - Integer.parseInt( - proxyProperties.getProperty(SFSessionProperty.PROXY_PORT.getPropertyKey())); - } catch (NumberFormatException | NullPointerException e) { - throw new SnowflakeSQLException( - ErrorCode.INVALID_PROXY_PROPERTIES, "Could not parse port number"); - } - String proxyUser = - proxyProperties.getProperty(SFSessionProperty.PROXY_USER.getPropertyKey()); - String proxyPassword = - proxyProperties.getProperty(SFSessionProperty.PROXY_PASSWORD.getPropertyKey()); - String nonProxyHosts = - proxyProperties.getProperty(SFSessionProperty.NON_PROXY_HOSTS.getPropertyKey()); - String proxyProtocol = - proxyProperties.getProperty(SFSessionProperty.PROXY_PROTOCOL.getPropertyKey()); - Protocol protocolEnum = - (!Strings.isNullOrEmpty(proxyProtocol) && proxyProtocol.equalsIgnoreCase("https")) - ? Protocol.HTTPS - : Protocol.HTTP; - clientConfig.setProxyHost(proxyHost); - clientConfig.setProxyPort(proxyPort); - clientConfig.setNonProxyHosts(nonProxyHosts); - clientConfig.setProxyProtocol(protocolEnum); - if (!Strings.isNullOrEmpty(proxyUser) && !Strings.isNullOrEmpty(proxyPassword)) { - clientConfig.setProxyUsername(proxyUser); - clientConfig.setProxyPassword(proxyPassword); - } - } - } + S3HttpUtil.setSessionlessProxyForS3(proxyProperties, clientConfig); } /** diff --git a/src/main/java/net/snowflake/client/jdbc/cloud/storage/S3HttpUtil.java b/src/main/java/net/snowflake/client/jdbc/cloud/storage/S3HttpUtil.java new file mode 100644 index 000000000..a2161f26f --- /dev/null +++ b/src/main/java/net/snowflake/client/jdbc/cloud/storage/S3HttpUtil.java @@ -0,0 +1,87 @@ +package net.snowflake.client.jdbc.cloud.storage; + +import com.amazonaws.ClientConfiguration; +import com.amazonaws.Protocol; +import com.google.common.base.Strings; +import net.snowflake.client.core.HttpClientSettingsKey; +import net.snowflake.client.core.SFSessionProperty; +import net.snowflake.client.jdbc.ErrorCode; +import net.snowflake.client.jdbc.SnowflakeSQLException; + +import java.util.Properties; + +public class S3HttpUtil { + /** + * A static function to set S3 proxy params when there is a valid session + * + * @param key key to HttpClient map containing OCSP and proxy info + * @param clientConfig the configuration needed by S3 to set the proxy + */ + public static void setProxyForS3(HttpClientSettingsKey key, ClientConfiguration clientConfig) { + if (key != null && key.usesProxy()) { + clientConfig.setProxyProtocol(key.getProxyProtocol()); + clientConfig.setProxyHost(key.getProxyHost()); + clientConfig.setProxyPort(key.getProxyPort()); + clientConfig.setNonProxyHosts(key.getNonProxyHosts()); + if (!Strings.isNullOrEmpty(key.getProxyUser()) + && !Strings.isNullOrEmpty(key.getProxyPassword())) { + clientConfig.setProxyUsername(key.getProxyUser()); + clientConfig.setProxyPassword(key.getProxyPassword()); + } + } + } + + /** + * A static function to set S3 proxy params for sessionless connections using the proxy params + * from the StageInfo + * + * @param proxyProperties proxy properties + * @param clientConfig the configuration needed by S3 to set the proxy + * @throws SnowflakeSQLException + */ + public static void setSessionlessProxyForS3( + Properties proxyProperties, ClientConfiguration clientConfig) throws SnowflakeSQLException { + // do nothing yet + if (proxyProperties != null + && proxyProperties.size() > 0 + && proxyProperties.getProperty(SFSessionProperty.USE_PROXY.getPropertyKey()) != null) { + Boolean useProxy = + Boolean.valueOf( + proxyProperties.getProperty(SFSessionProperty.USE_PROXY.getPropertyKey())); + if (useProxy) { + // set up other proxy related values. + String proxyHost = + proxyProperties.getProperty(SFSessionProperty.PROXY_HOST.getPropertyKey()); + int proxyPort; + try { + proxyPort = + Integer.parseInt( + proxyProperties.getProperty(SFSessionProperty.PROXY_PORT.getPropertyKey())); + } catch (NumberFormatException | NullPointerException e) { + throw new SnowflakeSQLException( + ErrorCode.INVALID_PROXY_PROPERTIES, "Could not parse port number"); + } + String proxyUser = + proxyProperties.getProperty(SFSessionProperty.PROXY_USER.getPropertyKey()); + String proxyPassword = + proxyProperties.getProperty(SFSessionProperty.PROXY_PASSWORD.getPropertyKey()); + String nonProxyHosts = + proxyProperties.getProperty(SFSessionProperty.NON_PROXY_HOSTS.getPropertyKey()); + String proxyProtocol = + proxyProperties.getProperty(SFSessionProperty.PROXY_PROTOCOL.getPropertyKey()); + Protocol protocolEnum = + (!Strings.isNullOrEmpty(proxyProtocol) && proxyProtocol.equalsIgnoreCase("https")) + ? Protocol.HTTPS + : Protocol.HTTP; + clientConfig.setProxyHost(proxyHost); + clientConfig.setProxyPort(proxyPort); + clientConfig.setNonProxyHosts(nonProxyHosts); + clientConfig.setProxyProtocol(protocolEnum); + if (!Strings.isNullOrEmpty(proxyUser) && !Strings.isNullOrEmpty(proxyPassword)) { + clientConfig.setProxyUsername(proxyUser); + clientConfig.setProxyPassword(proxyPassword); + } + } + } + } +} diff --git a/src/main/java/net/snowflake/client/jdbc/cloud/storage/SnowflakeS3Client.java b/src/main/java/net/snowflake/client/jdbc/cloud/storage/SnowflakeS3Client.java index 86c571ee2..2315bd74c 100644 --- a/src/main/java/net/snowflake/client/jdbc/cloud/storage/SnowflakeS3Client.java +++ b/src/main/java/net/snowflake/client/jdbc/cloud/storage/SnowflakeS3Client.java @@ -144,9 +144,9 @@ private void setupSnowflakeS3Client( clientConfig.withSignerOverride("AWSS3V4SignerType"); clientConfig.getApacheHttpClientConfig().setSslSocketFactory(getSSLConnectionSocketFactory()); if (session != null) { - HttpUtil.setProxyForS3(session.getHttpClientKey(), clientConfig); + S3HttpUtil.setProxyForS3(session.getHttpClientKey(), clientConfig); } else { - HttpUtil.setSessionlessProxyForS3(proxyProperties, clientConfig); + S3HttpUtil.setSessionlessProxyForS3(proxyProperties, clientConfig); } AmazonS3Builder amazonS3Builder = AmazonS3Client.builder(); if (encMat != null) { diff --git a/src/test/java/net/snowflake/client/core/CoreUtilsMiscellaneousTest.java b/src/test/java/net/snowflake/client/core/CoreUtilsMiscellaneousTest.java index d89eb01ed..054f67bfa 100644 --- a/src/test/java/net/snowflake/client/core/CoreUtilsMiscellaneousTest.java +++ b/src/test/java/net/snowflake/client/core/CoreUtilsMiscellaneousTest.java @@ -18,6 +18,7 @@ import net.snowflake.client.jdbc.ErrorCode; import net.snowflake.client.jdbc.SnowflakeSQLException; import net.snowflake.client.jdbc.SnowflakeUtil; +import net.snowflake.client.jdbc.cloud.storage.S3HttpUtil; import org.junit.Test; public class CoreUtilsMiscellaneousTest { @@ -106,7 +107,7 @@ public void testSetProxyForS3() { "jdbc", false); ClientConfiguration clientConfig = new ClientConfiguration(); - HttpUtil.setProxyForS3(testKey, clientConfig); + S3HttpUtil.setProxyForS3(testKey, clientConfig); assertEquals(Protocol.HTTPS, clientConfig.getProxyProtocol()); assertEquals("snowflakecomputing.com", clientConfig.getProxyHost()); assertEquals(443, clientConfig.getProxyPort()); @@ -126,7 +127,7 @@ public void testSetSessionlessProxyForS3() throws SnowflakeSQLException { props.put("nonProxyHosts", "baz.com | foo.com"); props.put("proxyProtocol", "http"); ClientConfiguration clientConfig = new ClientConfiguration(); - HttpUtil.setSessionlessProxyForS3(props, clientConfig); + S3HttpUtil.setSessionlessProxyForS3(props, clientConfig); assertEquals(Protocol.HTTP, clientConfig.getProxyProtocol()); assertEquals("localhost", clientConfig.getProxyHost()); assertEquals(8084, clientConfig.getProxyPort()); @@ -136,7 +137,7 @@ public void testSetSessionlessProxyForS3() throws SnowflakeSQLException { // Test that exception is thrown when port number is invalid props.put("proxyPort", "invalidnumber"); try { - HttpUtil.setSessionlessProxyForS3(props, clientConfig); + S3HttpUtil.setSessionlessProxyForS3(props, clientConfig); } catch (SnowflakeSQLException e) { assertEquals((int) ErrorCode.INVALID_PROXY_PROPERTIES.getMessageCode(), e.getErrorCode()); } @@ -346,7 +347,7 @@ public void testNullAndEmptyProxySettingsForS3() { HttpClientSettingsKey testKey = new HttpClientSettingsKey(OCSPMode.FAIL_OPEN, null, 443, null, null, null, "", "", false); ClientConfiguration clientConfig = new ClientConfiguration(); - HttpUtil.setProxyForS3(testKey, clientConfig); + S3HttpUtil.setProxyForS3(testKey, clientConfig); assertEquals(Protocol.HTTP, clientConfig.getProxyProtocol()); assertEquals("", clientConfig.getProxyHost()); assertEquals(443, clientConfig.getProxyPort()); From 28ea19e0ed450418e7665f761424551e54acde45 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Ferreira?= Date: Thu, 8 Feb 2024 08:54:34 +0000 Subject: [PATCH 07/18] deprecate SnowflakeMutableProxyRoutePlanner constructor --- .../net/snowflake/client/core/HttpUtil.java | 2 +- .../SnowflakeMutableProxyRoutePlanner.java | 24 +++++++++++++++++-- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/src/main/java/net/snowflake/client/core/HttpUtil.java b/src/main/java/net/snowflake/client/core/HttpUtil.java index 9fc26add7..f0ed7bcab 100644 --- a/src/main/java/net/snowflake/client/core/HttpUtil.java +++ b/src/main/java/net/snowflake/client/core/HttpUtil.java @@ -330,7 +330,7 @@ public static CloseableHttpClient buildHttpClient( new SnowflakeMutableProxyRoutePlanner( key.getProxyHost(), key.getProxyPort(), - key.getProxyProtocol(), + key.getProxyHttpProtocol(), key.getNonProxyHosts())); httpClientBuilder = httpClientBuilder.setProxy(proxy).setRoutePlanner(sdkProxyRoutePlanner); if (!Strings.isNullOrEmpty(key.getProxyUser()) diff --git a/src/main/java/net/snowflake/client/core/SnowflakeMutableProxyRoutePlanner.java b/src/main/java/net/snowflake/client/core/SnowflakeMutableProxyRoutePlanner.java index e21e9d78c..e210a9d2a 100644 --- a/src/main/java/net/snowflake/client/core/SnowflakeMutableProxyRoutePlanner.java +++ b/src/main/java/net/snowflake/client/core/SnowflakeMutableProxyRoutePlanner.java @@ -24,20 +24,32 @@ public class SnowflakeMutableProxyRoutePlanner implements HttpRoutePlanner, Seri private String host; private int proxyPort; private String nonProxyHosts; - private Protocol protocol; + private HttpProtocol protocol; + /** + * @deprecated use SnowflakeMutableProxyRoutePlanner(String host, int proxyPort, HttpProtocol protocol, String nonProxyHosts) + */ public SnowflakeMutableProxyRoutePlanner( String host, int proxyPort, Protocol proxyProtocol, String nonProxyHosts) { proxyRoutePlanner = new SdkProxyRoutePlanner(host, proxyPort, proxyProtocol, nonProxyHosts); this.host = host; this.proxyPort = proxyPort; this.nonProxyHosts = nonProxyHosts; + this.protocol = toSnowflakeProtocol(proxyProtocol); + } + + public SnowflakeMutableProxyRoutePlanner( + String host, int proxyPort, HttpProtocol proxyProtocol, String nonProxyHosts) { + proxyRoutePlanner = new SdkProxyRoutePlanner(host, proxyPort, toAwsProtocol(proxyProtocol), nonProxyHosts); + this.host = host; + this.proxyPort = proxyPort; + this.nonProxyHosts = nonProxyHosts; this.protocol = proxyProtocol; } public void setNonProxyHosts(String nonProxyHosts) { this.nonProxyHosts = nonProxyHosts; - proxyRoutePlanner = new SdkProxyRoutePlanner(host, proxyPort, protocol, nonProxyHosts); + proxyRoutePlanner = new SdkProxyRoutePlanner(host, proxyPort, toAwsProtocol(protocol), nonProxyHosts); } public String getNonProxyHosts() { @@ -49,4 +61,12 @@ public HttpRoute determineRoute(HttpHost target, HttpRequest request, HttpContex throws HttpException { return proxyRoutePlanner.determineRoute(target, request, context); } + + private Protocol toAwsProtocol(HttpProtocol protocol) { + return protocol == HttpProtocol.HTTP ? Protocol.HTTP : Protocol.HTTPS; + } + + private HttpProtocol toSnowflakeProtocol(Protocol protocol) { + return protocol == Protocol.HTTP ? HttpProtocol.HTTP : HttpProtocol.HTTPS; + } } From 7dca1fcb1e67ac9716d249a464271347a2ce6d23 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Ferreira?= Date: Thu, 8 Feb 2024 08:59:25 +0000 Subject: [PATCH 08/18] remove last usage of deprecated getProxyProtocol --- .../net/snowflake/client/jdbc/cloud/storage/S3HttpUtil.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/net/snowflake/client/jdbc/cloud/storage/S3HttpUtil.java b/src/main/java/net/snowflake/client/jdbc/cloud/storage/S3HttpUtil.java index a2161f26f..c94ce9fcc 100644 --- a/src/main/java/net/snowflake/client/jdbc/cloud/storage/S3HttpUtil.java +++ b/src/main/java/net/snowflake/client/jdbc/cloud/storage/S3HttpUtil.java @@ -4,6 +4,7 @@ import com.amazonaws.Protocol; import com.google.common.base.Strings; import net.snowflake.client.core.HttpClientSettingsKey; +import net.snowflake.client.core.HttpProtocol; import net.snowflake.client.core.SFSessionProperty; import net.snowflake.client.jdbc.ErrorCode; import net.snowflake.client.jdbc.SnowflakeSQLException; @@ -19,7 +20,7 @@ public class S3HttpUtil { */ public static void setProxyForS3(HttpClientSettingsKey key, ClientConfiguration clientConfig) { if (key != null && key.usesProxy()) { - clientConfig.setProxyProtocol(key.getProxyProtocol()); + clientConfig.setProxyProtocol(key.getProxyHttpProtocol() == HttpProtocol.HTTPS ? Protocol.HTTPS : Protocol.HTTP); clientConfig.setProxyHost(key.getProxyHost()); clientConfig.setProxyPort(key.getProxyPort()); clientConfig.setNonProxyHosts(key.getNonProxyHosts()); From aaa5ca3ae9e4f279fb8f1b0505ee7a093713a550 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Ferreira?= Date: Thu, 8 Feb 2024 09:09:43 +0000 Subject: [PATCH 09/18] make a copy of com.amazonaws.http.apache.SdkProxyRoutePlanner but does not use com.amazonaws.Protocol --- .../SnowflakeMutableProxyRoutePlanner.java | 13 ++-- .../core/SnowflakeSdkProxyRoutePlanner.java | 69 +++++++++++++++++++ 2 files changed, 73 insertions(+), 9 deletions(-) create mode 100644 src/main/java/net/snowflake/client/core/SnowflakeSdkProxyRoutePlanner.java diff --git a/src/main/java/net/snowflake/client/core/SnowflakeMutableProxyRoutePlanner.java b/src/main/java/net/snowflake/client/core/SnowflakeMutableProxyRoutePlanner.java index e210a9d2a..41ea60f93 100644 --- a/src/main/java/net/snowflake/client/core/SnowflakeMutableProxyRoutePlanner.java +++ b/src/main/java/net/snowflake/client/core/SnowflakeMutableProxyRoutePlanner.java @@ -5,7 +5,6 @@ package net.snowflake.client.core; import com.amazonaws.Protocol; -import com.amazonaws.http.apache.SdkProxyRoutePlanner; import java.io.Serializable; import org.apache.http.HttpException; import org.apache.http.HttpHost; @@ -20,7 +19,7 @@ */ public class SnowflakeMutableProxyRoutePlanner implements HttpRoutePlanner, Serializable { - private SdkProxyRoutePlanner proxyRoutePlanner = null; + private SnowflakeSdkProxyRoutePlanner proxyRoutePlanner = null; private String host; private int proxyPort; private String nonProxyHosts; @@ -31,7 +30,7 @@ public class SnowflakeMutableProxyRoutePlanner implements HttpRoutePlanner, Seri */ public SnowflakeMutableProxyRoutePlanner( String host, int proxyPort, Protocol proxyProtocol, String nonProxyHosts) { - proxyRoutePlanner = new SdkProxyRoutePlanner(host, proxyPort, proxyProtocol, nonProxyHosts); + proxyRoutePlanner = new SnowflakeSdkProxyRoutePlanner(host, proxyPort, toSnowflakeProtocol(proxyProtocol), nonProxyHosts); this.host = host; this.proxyPort = proxyPort; this.nonProxyHosts = nonProxyHosts; @@ -40,7 +39,7 @@ public SnowflakeMutableProxyRoutePlanner( public SnowflakeMutableProxyRoutePlanner( String host, int proxyPort, HttpProtocol proxyProtocol, String nonProxyHosts) { - proxyRoutePlanner = new SdkProxyRoutePlanner(host, proxyPort, toAwsProtocol(proxyProtocol), nonProxyHosts); + proxyRoutePlanner = new SnowflakeSdkProxyRoutePlanner(host, proxyPort, proxyProtocol, nonProxyHosts); this.host = host; this.proxyPort = proxyPort; this.nonProxyHosts = nonProxyHosts; @@ -49,7 +48,7 @@ public SnowflakeMutableProxyRoutePlanner( public void setNonProxyHosts(String nonProxyHosts) { this.nonProxyHosts = nonProxyHosts; - proxyRoutePlanner = new SdkProxyRoutePlanner(host, proxyPort, toAwsProtocol(protocol), nonProxyHosts); + proxyRoutePlanner = new SnowflakeSdkProxyRoutePlanner(host, proxyPort, protocol, nonProxyHosts); } public String getNonProxyHosts() { @@ -62,10 +61,6 @@ public HttpRoute determineRoute(HttpHost target, HttpRequest request, HttpContex return proxyRoutePlanner.determineRoute(target, request, context); } - private Protocol toAwsProtocol(HttpProtocol protocol) { - return protocol == HttpProtocol.HTTP ? Protocol.HTTP : Protocol.HTTPS; - } - private HttpProtocol toSnowflakeProtocol(Protocol protocol) { return protocol == Protocol.HTTP ? HttpProtocol.HTTP : HttpProtocol.HTTPS; } diff --git a/src/main/java/net/snowflake/client/core/SnowflakeSdkProxyRoutePlanner.java b/src/main/java/net/snowflake/client/core/SnowflakeSdkProxyRoutePlanner.java new file mode 100644 index 000000000..75e489788 --- /dev/null +++ b/src/main/java/net/snowflake/client/core/SnowflakeSdkProxyRoutePlanner.java @@ -0,0 +1,69 @@ +/* + * Copyright 2016-2023 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"). + * You may not use this file except in compliance with the License. + * A copy of the License is located at + * + * http://aws.amazon.com/apache2.0 + * + * or in the "license" file accompanying this file. This file is distributed + * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either + * express or implied. See the License for the specific language governing + * permissions and limitations under the License. + */ +package net.snowflake.client.core; + +import com.google.common.base.Strings; +import org.apache.http.HttpException; +import org.apache.http.HttpHost; +import org.apache.http.HttpRequest; +import org.apache.http.impl.conn.DefaultRoutePlanner; +import org.apache.http.impl.conn.DefaultSchemePortResolver; +import org.apache.http.protocol.HttpContext; + +/** + * SdkProxyRoutePlanner delegates a Proxy Route Planner from the settings instead of the + * system properties. It will use the proxy created from proxyHost, proxyPort, and proxyProtocol and + * filter the hosts who matches nonProxyHosts pattern. + */ +public class SnowflakeSdkProxyRoutePlanner extends DefaultRoutePlanner { + private HttpHost proxy; + private String[] hostPatterns; + + public SnowflakeSdkProxyRoutePlanner(String proxyHost, int proxyPort, HttpProtocol proxyProtocol, String nonProxyHosts) { + super(DefaultSchemePortResolver.INSTANCE); + proxy = new HttpHost(proxyHost, proxyPort, proxyProtocol.getScheme()); + parseNonProxyHosts(nonProxyHosts); + } + + private void parseNonProxyHosts(String nonProxyHosts) { + if (!Strings.isNullOrEmpty(nonProxyHosts)) { + String[] hosts = nonProxyHosts.split("\\|"); + hostPatterns = new String[hosts.length]; + for (int i = 0; i < hosts.length; ++i) { + hostPatterns[i] = hosts[i].toLowerCase().replace("*", ".*?"); + } + } + } + + boolean doesTargetMatchNonProxyHosts(HttpHost target) { + if (hostPatterns == null) { + return false; + } + String targetHost = target.getHostName().toLowerCase(); + for (String pattern : hostPatterns) { + if (targetHost.matches(pattern)) return true; + } + return false; + } + + @Override + protected HttpHost determineProxy( + final HttpHost target, + final HttpRequest request, + final HttpContext context) throws HttpException { + + return doesTargetMatchNonProxyHosts(target) ? null : proxy; + } +} From 6e10f57bfb25ca7206378469798acf45929ddbe6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Ferreira?= Date: Fri, 9 Feb 2024 21:54:26 +0000 Subject: [PATCH 10/18] Revert "make a copy of com.amazonaws.http.apache.SdkProxyRoutePlanner but does not use com.amazonaws.Protocol" This reverts commit aaa5ca3ae9e4f279fb8f1b0505ee7a093713a550. --- .../SnowflakeMutableProxyRoutePlanner.java | 13 ++-- .../core/SnowflakeSdkProxyRoutePlanner.java | 69 ------------------- 2 files changed, 9 insertions(+), 73 deletions(-) delete mode 100644 src/main/java/net/snowflake/client/core/SnowflakeSdkProxyRoutePlanner.java diff --git a/src/main/java/net/snowflake/client/core/SnowflakeMutableProxyRoutePlanner.java b/src/main/java/net/snowflake/client/core/SnowflakeMutableProxyRoutePlanner.java index 41ea60f93..e210a9d2a 100644 --- a/src/main/java/net/snowflake/client/core/SnowflakeMutableProxyRoutePlanner.java +++ b/src/main/java/net/snowflake/client/core/SnowflakeMutableProxyRoutePlanner.java @@ -5,6 +5,7 @@ package net.snowflake.client.core; import com.amazonaws.Protocol; +import com.amazonaws.http.apache.SdkProxyRoutePlanner; import java.io.Serializable; import org.apache.http.HttpException; import org.apache.http.HttpHost; @@ -19,7 +20,7 @@ */ public class SnowflakeMutableProxyRoutePlanner implements HttpRoutePlanner, Serializable { - private SnowflakeSdkProxyRoutePlanner proxyRoutePlanner = null; + private SdkProxyRoutePlanner proxyRoutePlanner = null; private String host; private int proxyPort; private String nonProxyHosts; @@ -30,7 +31,7 @@ public class SnowflakeMutableProxyRoutePlanner implements HttpRoutePlanner, Seri */ public SnowflakeMutableProxyRoutePlanner( String host, int proxyPort, Protocol proxyProtocol, String nonProxyHosts) { - proxyRoutePlanner = new SnowflakeSdkProxyRoutePlanner(host, proxyPort, toSnowflakeProtocol(proxyProtocol), nonProxyHosts); + proxyRoutePlanner = new SdkProxyRoutePlanner(host, proxyPort, proxyProtocol, nonProxyHosts); this.host = host; this.proxyPort = proxyPort; this.nonProxyHosts = nonProxyHosts; @@ -39,7 +40,7 @@ public SnowflakeMutableProxyRoutePlanner( public SnowflakeMutableProxyRoutePlanner( String host, int proxyPort, HttpProtocol proxyProtocol, String nonProxyHosts) { - proxyRoutePlanner = new SnowflakeSdkProxyRoutePlanner(host, proxyPort, proxyProtocol, nonProxyHosts); + proxyRoutePlanner = new SdkProxyRoutePlanner(host, proxyPort, toAwsProtocol(proxyProtocol), nonProxyHosts); this.host = host; this.proxyPort = proxyPort; this.nonProxyHosts = nonProxyHosts; @@ -48,7 +49,7 @@ public SnowflakeMutableProxyRoutePlanner( public void setNonProxyHosts(String nonProxyHosts) { this.nonProxyHosts = nonProxyHosts; - proxyRoutePlanner = new SnowflakeSdkProxyRoutePlanner(host, proxyPort, protocol, nonProxyHosts); + proxyRoutePlanner = new SdkProxyRoutePlanner(host, proxyPort, toAwsProtocol(protocol), nonProxyHosts); } public String getNonProxyHosts() { @@ -61,6 +62,10 @@ public HttpRoute determineRoute(HttpHost target, HttpRequest request, HttpContex return proxyRoutePlanner.determineRoute(target, request, context); } + private Protocol toAwsProtocol(HttpProtocol protocol) { + return protocol == HttpProtocol.HTTP ? Protocol.HTTP : Protocol.HTTPS; + } + private HttpProtocol toSnowflakeProtocol(Protocol protocol) { return protocol == Protocol.HTTP ? HttpProtocol.HTTP : HttpProtocol.HTTPS; } diff --git a/src/main/java/net/snowflake/client/core/SnowflakeSdkProxyRoutePlanner.java b/src/main/java/net/snowflake/client/core/SnowflakeSdkProxyRoutePlanner.java deleted file mode 100644 index 75e489788..000000000 --- a/src/main/java/net/snowflake/client/core/SnowflakeSdkProxyRoutePlanner.java +++ /dev/null @@ -1,69 +0,0 @@ -/* - * Copyright 2016-2023 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. - */ -package net.snowflake.client.core; - -import com.google.common.base.Strings; -import org.apache.http.HttpException; -import org.apache.http.HttpHost; -import org.apache.http.HttpRequest; -import org.apache.http.impl.conn.DefaultRoutePlanner; -import org.apache.http.impl.conn.DefaultSchemePortResolver; -import org.apache.http.protocol.HttpContext; - -/** - * SdkProxyRoutePlanner delegates a Proxy Route Planner from the settings instead of the - * system properties. It will use the proxy created from proxyHost, proxyPort, and proxyProtocol and - * filter the hosts who matches nonProxyHosts pattern. - */ -public class SnowflakeSdkProxyRoutePlanner extends DefaultRoutePlanner { - private HttpHost proxy; - private String[] hostPatterns; - - public SnowflakeSdkProxyRoutePlanner(String proxyHost, int proxyPort, HttpProtocol proxyProtocol, String nonProxyHosts) { - super(DefaultSchemePortResolver.INSTANCE); - proxy = new HttpHost(proxyHost, proxyPort, proxyProtocol.getScheme()); - parseNonProxyHosts(nonProxyHosts); - } - - private void parseNonProxyHosts(String nonProxyHosts) { - if (!Strings.isNullOrEmpty(nonProxyHosts)) { - String[] hosts = nonProxyHosts.split("\\|"); - hostPatterns = new String[hosts.length]; - for (int i = 0; i < hosts.length; ++i) { - hostPatterns[i] = hosts[i].toLowerCase().replace("*", ".*?"); - } - } - } - - boolean doesTargetMatchNonProxyHosts(HttpHost target) { - if (hostPatterns == null) { - return false; - } - String targetHost = target.getHostName().toLowerCase(); - for (String pattern : hostPatterns) { - if (targetHost.matches(pattern)) return true; - } - return false; - } - - @Override - protected HttpHost determineProxy( - final HttpHost target, - final HttpRequest request, - final HttpContext context) throws HttpException { - - return doesTargetMatchNonProxyHosts(target) ? null : proxy; - } -} From 4c735cc8813e5cfbe98b9879f9f6458ad7c30421 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Ferreira?= Date: Fri, 9 Feb 2024 21:55:36 +0000 Subject: [PATCH 11/18] fix HttpProtocol constructor argument --- src/main/java/net/snowflake/client/core/HttpProtocol.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/net/snowflake/client/core/HttpProtocol.java b/src/main/java/net/snowflake/client/core/HttpProtocol.java index 837f3b5fa..6ee8cd34c 100644 --- a/src/main/java/net/snowflake/client/core/HttpProtocol.java +++ b/src/main/java/net/snowflake/client/core/HttpProtocol.java @@ -12,8 +12,8 @@ public enum HttpProtocol { private final String scheme; - HttpProtocol(String protocol) { - this.scheme = protocol; + HttpProtocol(String scheme) { + this.scheme = scheme; } public String getScheme() { From fce6bc58bc5cdb1fedcd22b8008458c8ed32d63d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Ferreira?= Date: Fri, 9 Feb 2024 22:05:20 +0000 Subject: [PATCH 12/18] add Deprecated annotations --- src/main/java/net/snowflake/client/core/HttpUtil.java | 4 +++- .../client/core/SnowflakeMutableProxyRoutePlanner.java | 1 + 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/main/java/net/snowflake/client/core/HttpUtil.java b/src/main/java/net/snowflake/client/core/HttpUtil.java index f0ed7bcab..1573a6a1b 100644 --- a/src/main/java/net/snowflake/client/core/HttpUtil.java +++ b/src/main/java/net/snowflake/client/core/HttpUtil.java @@ -120,8 +120,9 @@ public static void closeExpiredAndIdleConnections() { * * @param key key to HttpClient map containing OCSP and proxy info * @param clientConfig the configuration needed by S3 to set the proxy - * @deprecated use S3HttpUtil.setProxyForS3(HttpClientSettingsKey, ClientConfiguration) instead + * @deprecated use S3HttpUtil.setProxyForS3(HttpClientSettingsKey, ClientConfiguration) instead */ + @Deprecated public static void setProxyForS3(HttpClientSettingsKey key, ClientConfiguration clientConfig) { S3HttpUtil.setProxyForS3(key, clientConfig); } @@ -135,6 +136,7 @@ public static void setProxyForS3(HttpClientSettingsKey key, ClientConfiguration * @throws SnowflakeSQLException * @deprecated use S3HttpUtil.setSessionlessProxyForS3(Properties, ClientConfiguration) instead */ + @Deprecated public static void setSessionlessProxyForS3( Properties proxyProperties, ClientConfiguration clientConfig) throws SnowflakeSQLException { S3HttpUtil.setSessionlessProxyForS3(proxyProperties, clientConfig); diff --git a/src/main/java/net/snowflake/client/core/SnowflakeMutableProxyRoutePlanner.java b/src/main/java/net/snowflake/client/core/SnowflakeMutableProxyRoutePlanner.java index e210a9d2a..e06e8ef38 100644 --- a/src/main/java/net/snowflake/client/core/SnowflakeMutableProxyRoutePlanner.java +++ b/src/main/java/net/snowflake/client/core/SnowflakeMutableProxyRoutePlanner.java @@ -29,6 +29,7 @@ public class SnowflakeMutableProxyRoutePlanner implements HttpRoutePlanner, Seri /** * @deprecated use SnowflakeMutableProxyRoutePlanner(String host, int proxyPort, HttpProtocol protocol, String nonProxyHosts) */ + @Deprecated public SnowflakeMutableProxyRoutePlanner( String host, int proxyPort, Protocol proxyProtocol, String nonProxyHosts) { proxyRoutePlanner = new SdkProxyRoutePlanner(host, proxyPort, proxyProtocol, nonProxyHosts); From 92a67d6a626e7f0e8e77888a621eafbc0d4eb756 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Ferreira?= Date: Fri, 9 Feb 2024 22:05:54 +0000 Subject: [PATCH 13/18] remove duplicate code by calling the other constructor --- .../client/core/SnowflakeMutableProxyRoutePlanner.java | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/src/main/java/net/snowflake/client/core/SnowflakeMutableProxyRoutePlanner.java b/src/main/java/net/snowflake/client/core/SnowflakeMutableProxyRoutePlanner.java index e06e8ef38..f6a7de28b 100644 --- a/src/main/java/net/snowflake/client/core/SnowflakeMutableProxyRoutePlanner.java +++ b/src/main/java/net/snowflake/client/core/SnowflakeMutableProxyRoutePlanner.java @@ -41,11 +41,7 @@ public SnowflakeMutableProxyRoutePlanner( public SnowflakeMutableProxyRoutePlanner( String host, int proxyPort, HttpProtocol proxyProtocol, String nonProxyHosts) { - proxyRoutePlanner = new SdkProxyRoutePlanner(host, proxyPort, toAwsProtocol(proxyProtocol), nonProxyHosts); - this.host = host; - this.proxyPort = proxyPort; - this.nonProxyHosts = nonProxyHosts; - this.protocol = proxyProtocol; + this(host, proxyPort, toAwsProtocol(proxyProtocol), nonProxyHosts); } public void setNonProxyHosts(String nonProxyHosts) { @@ -63,11 +59,11 @@ public HttpRoute determineRoute(HttpHost target, HttpRequest request, HttpContex return proxyRoutePlanner.determineRoute(target, request, context); } - private Protocol toAwsProtocol(HttpProtocol protocol) { + private static Protocol toAwsProtocol(HttpProtocol protocol) { return protocol == HttpProtocol.HTTP ? Protocol.HTTP : Protocol.HTTPS; } - private HttpProtocol toSnowflakeProtocol(Protocol protocol) { + private static HttpProtocol toSnowflakeProtocol(Protocol protocol) { return protocol == Protocol.HTTP ? HttpProtocol.HTTP : HttpProtocol.HTTPS; } } From 7e7efab5a374e5d97bae79766565d9b789a4f5fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Ferreira?= Date: Fri, 9 Feb 2024 22:06:11 +0000 Subject: [PATCH 14/18] add copyright header --- .../net/snowflake/client/jdbc/cloud/storage/S3HttpUtil.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/main/java/net/snowflake/client/jdbc/cloud/storage/S3HttpUtil.java b/src/main/java/net/snowflake/client/jdbc/cloud/storage/S3HttpUtil.java index c94ce9fcc..32ec2b862 100644 --- a/src/main/java/net/snowflake/client/jdbc/cloud/storage/S3HttpUtil.java +++ b/src/main/java/net/snowflake/client/jdbc/cloud/storage/S3HttpUtil.java @@ -1,3 +1,7 @@ +/* + * Copyright (c) 2024 Snowflake Computing Inc. All rights reserved. + */ + package net.snowflake.client.jdbc.cloud.storage; import com.amazonaws.ClientConfiguration; From 12a8f929e4d0cf81f20a9138d7891415824439bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Ferreira?= Date: Fri, 9 Feb 2024 22:14:51 +0000 Subject: [PATCH 15/18] fmt --- .../client/core/HttpClientSettingsKey.java | 4 +- .../snowflake/client/core/HttpProtocol.java | 19 ++- .../SnowflakeMutableProxyRoutePlanner.java | 10 +- .../client/jdbc/cloud/storage/S3HttpUtil.java | 144 +++++++++--------- 4 files changed, 91 insertions(+), 86 deletions(-) diff --git a/src/main/java/net/snowflake/client/core/HttpClientSettingsKey.java b/src/main/java/net/snowflake/client/core/HttpClientSettingsKey.java index 6cc20650c..f9f1b5ca7 100644 --- a/src/main/java/net/snowflake/client/core/HttpClientSettingsKey.java +++ b/src/main/java/net/snowflake/client/core/HttpClientSettingsKey.java @@ -137,8 +137,10 @@ public String getNonProxyHosts() { */ @Deprecated public com.amazonaws.Protocol getProxyProtocol() { - return this.proxyProtocol.equalsIgnoreCase("https") ? com.amazonaws.Protocol.HTTPS : com.amazonaws.Protocol.HTTP; + return this.proxyProtocol.equalsIgnoreCase("https") + ? com.amazonaws.Protocol.HTTPS : com.amazonaws.Protocol.HTTP; } + public HttpProtocol getProxyHttpProtocol() { return this.proxyProtocol.equalsIgnoreCase("https") ? HttpProtocol.HTTPS : HttpProtocol.HTTP; } diff --git a/src/main/java/net/snowflake/client/core/HttpProtocol.java b/src/main/java/net/snowflake/client/core/HttpProtocol.java index 6ee8cd34c..76868b0eb 100644 --- a/src/main/java/net/snowflake/client/core/HttpProtocol.java +++ b/src/main/java/net/snowflake/client/core/HttpProtocol.java @@ -5,18 +5,17 @@ package net.snowflake.client.core; public enum HttpProtocol { + HTTP("http"), - HTTP("http"), + HTTPS("https"); - HTTPS("https"); + private final String scheme; - private final String scheme; + HttpProtocol(String scheme) { + this.scheme = scheme; + } - HttpProtocol(String scheme) { - this.scheme = scheme; - } - - public String getScheme() { - return scheme; - } + public String getScheme() { + return scheme; + } } diff --git a/src/main/java/net/snowflake/client/core/SnowflakeMutableProxyRoutePlanner.java b/src/main/java/net/snowflake/client/core/SnowflakeMutableProxyRoutePlanner.java index f6a7de28b..f41fb270a 100644 --- a/src/main/java/net/snowflake/client/core/SnowflakeMutableProxyRoutePlanner.java +++ b/src/main/java/net/snowflake/client/core/SnowflakeMutableProxyRoutePlanner.java @@ -27,7 +27,8 @@ public class SnowflakeMutableProxyRoutePlanner implements HttpRoutePlanner, Seri private HttpProtocol protocol; /** - * @deprecated use SnowflakeMutableProxyRoutePlanner(String host, int proxyPort, HttpProtocol protocol, String nonProxyHosts) + * @deprecated use SnowflakeMutableProxyRoutePlanner(String host, int proxyPort, HttpProtocol + * protocol, String nonProxyHosts) */ @Deprecated public SnowflakeMutableProxyRoutePlanner( @@ -40,13 +41,14 @@ public SnowflakeMutableProxyRoutePlanner( } public SnowflakeMutableProxyRoutePlanner( - String host, int proxyPort, HttpProtocol proxyProtocol, String nonProxyHosts) { + String host, int proxyPort, HttpProtocol proxyProtocol, String nonProxyHosts) { this(host, proxyPort, toAwsProtocol(proxyProtocol), nonProxyHosts); } public void setNonProxyHosts(String nonProxyHosts) { this.nonProxyHosts = nonProxyHosts; - proxyRoutePlanner = new SdkProxyRoutePlanner(host, proxyPort, toAwsProtocol(protocol), nonProxyHosts); + proxyRoutePlanner = + new SdkProxyRoutePlanner(host, proxyPort, toAwsProtocol(protocol), nonProxyHosts); } public String getNonProxyHosts() { @@ -64,6 +66,6 @@ private static Protocol toAwsProtocol(HttpProtocol protocol) { } private static HttpProtocol toSnowflakeProtocol(Protocol protocol) { - return protocol == Protocol.HTTP ? HttpProtocol.HTTP : HttpProtocol.HTTPS; + return protocol == Protocol.HTTP ? HttpProtocol.HTTP : HttpProtocol.HTTPS; } } diff --git a/src/main/java/net/snowflake/client/jdbc/cloud/storage/S3HttpUtil.java b/src/main/java/net/snowflake/client/jdbc/cloud/storage/S3HttpUtil.java index 32ec2b862..ec7f0c7ca 100644 --- a/src/main/java/net/snowflake/client/jdbc/cloud/storage/S3HttpUtil.java +++ b/src/main/java/net/snowflake/client/jdbc/cloud/storage/S3HttpUtil.java @@ -7,86 +7,88 @@ import com.amazonaws.ClientConfiguration; import com.amazonaws.Protocol; import com.google.common.base.Strings; +import java.util.Properties; import net.snowflake.client.core.HttpClientSettingsKey; import net.snowflake.client.core.HttpProtocol; import net.snowflake.client.core.SFSessionProperty; +import net.snowflake.client.core.SnowflakeJdbcInternalApi; import net.snowflake.client.jdbc.ErrorCode; import net.snowflake.client.jdbc.SnowflakeSQLException; -import java.util.Properties; - +@SnowflakeJdbcInternalApi public class S3HttpUtil { - /** - * A static function to set S3 proxy params when there is a valid session - * - * @param key key to HttpClient map containing OCSP and proxy info - * @param clientConfig the configuration needed by S3 to set the proxy - */ - public static void setProxyForS3(HttpClientSettingsKey key, ClientConfiguration clientConfig) { - if (key != null && key.usesProxy()) { - clientConfig.setProxyProtocol(key.getProxyHttpProtocol() == HttpProtocol.HTTPS ? Protocol.HTTPS : Protocol.HTTP); - clientConfig.setProxyHost(key.getProxyHost()); - clientConfig.setProxyPort(key.getProxyPort()); - clientConfig.setNonProxyHosts(key.getNonProxyHosts()); - if (!Strings.isNullOrEmpty(key.getProxyUser()) - && !Strings.isNullOrEmpty(key.getProxyPassword())) { - clientConfig.setProxyUsername(key.getProxyUser()); - clientConfig.setProxyPassword(key.getProxyPassword()); - } - } + /** + * A static function to set S3 proxy params when there is a valid session + * + * @param key key to HttpClient map containing OCSP and proxy info + * @param clientConfig the configuration needed by S3 to set the proxy + */ + public static void setProxyForS3(HttpClientSettingsKey key, ClientConfiguration clientConfig) { + if (key != null && key.usesProxy()) { + clientConfig.setProxyProtocol( + key.getProxyHttpProtocol() == HttpProtocol.HTTPS ? Protocol.HTTPS : Protocol.HTTP); + clientConfig.setProxyHost(key.getProxyHost()); + clientConfig.setProxyPort(key.getProxyPort()); + clientConfig.setNonProxyHosts(key.getNonProxyHosts()); + if (!Strings.isNullOrEmpty(key.getProxyUser()) + && !Strings.isNullOrEmpty(key.getProxyPassword())) { + clientConfig.setProxyUsername(key.getProxyUser()); + clientConfig.setProxyPassword(key.getProxyPassword()); + } } + } - /** - * A static function to set S3 proxy params for sessionless connections using the proxy params - * from the StageInfo - * - * @param proxyProperties proxy properties - * @param clientConfig the configuration needed by S3 to set the proxy - * @throws SnowflakeSQLException - */ - public static void setSessionlessProxyForS3( - Properties proxyProperties, ClientConfiguration clientConfig) throws SnowflakeSQLException { - // do nothing yet - if (proxyProperties != null - && proxyProperties.size() > 0 - && proxyProperties.getProperty(SFSessionProperty.USE_PROXY.getPropertyKey()) != null) { - Boolean useProxy = - Boolean.valueOf( - proxyProperties.getProperty(SFSessionProperty.USE_PROXY.getPropertyKey())); - if (useProxy) { - // set up other proxy related values. - String proxyHost = - proxyProperties.getProperty(SFSessionProperty.PROXY_HOST.getPropertyKey()); - int proxyPort; - try { - proxyPort = - Integer.parseInt( - proxyProperties.getProperty(SFSessionProperty.PROXY_PORT.getPropertyKey())); - } catch (NumberFormatException | NullPointerException e) { - throw new SnowflakeSQLException( - ErrorCode.INVALID_PROXY_PROPERTIES, "Could not parse port number"); - } - String proxyUser = - proxyProperties.getProperty(SFSessionProperty.PROXY_USER.getPropertyKey()); - String proxyPassword = - proxyProperties.getProperty(SFSessionProperty.PROXY_PASSWORD.getPropertyKey()); - String nonProxyHosts = - proxyProperties.getProperty(SFSessionProperty.NON_PROXY_HOSTS.getPropertyKey()); - String proxyProtocol = - proxyProperties.getProperty(SFSessionProperty.PROXY_PROTOCOL.getPropertyKey()); - Protocol protocolEnum = - (!Strings.isNullOrEmpty(proxyProtocol) && proxyProtocol.equalsIgnoreCase("https")) - ? Protocol.HTTPS - : Protocol.HTTP; - clientConfig.setProxyHost(proxyHost); - clientConfig.setProxyPort(proxyPort); - clientConfig.setNonProxyHosts(nonProxyHosts); - clientConfig.setProxyProtocol(protocolEnum); - if (!Strings.isNullOrEmpty(proxyUser) && !Strings.isNullOrEmpty(proxyPassword)) { - clientConfig.setProxyUsername(proxyUser); - clientConfig.setProxyPassword(proxyPassword); - } - } + /** + * A static function to set S3 proxy params for sessionless connections using the proxy params + * from the StageInfo + * + * @param proxyProperties proxy properties + * @param clientConfig the configuration needed by S3 to set the proxy + * @throws SnowflakeSQLException + */ + public static void setSessionlessProxyForS3( + Properties proxyProperties, ClientConfiguration clientConfig) throws SnowflakeSQLException { + // do nothing yet + if (proxyProperties != null + && proxyProperties.size() > 0 + && proxyProperties.getProperty(SFSessionProperty.USE_PROXY.getPropertyKey()) != null) { + Boolean useProxy = + Boolean.valueOf( + proxyProperties.getProperty(SFSessionProperty.USE_PROXY.getPropertyKey())); + if (useProxy) { + // set up other proxy related values. + String proxyHost = + proxyProperties.getProperty(SFSessionProperty.PROXY_HOST.getPropertyKey()); + int proxyPort; + try { + proxyPort = + Integer.parseInt( + proxyProperties.getProperty(SFSessionProperty.PROXY_PORT.getPropertyKey())); + } catch (NumberFormatException | NullPointerException e) { + throw new SnowflakeSQLException( + ErrorCode.INVALID_PROXY_PROPERTIES, "Could not parse port number"); + } + String proxyUser = + proxyProperties.getProperty(SFSessionProperty.PROXY_USER.getPropertyKey()); + String proxyPassword = + proxyProperties.getProperty(SFSessionProperty.PROXY_PASSWORD.getPropertyKey()); + String nonProxyHosts = + proxyProperties.getProperty(SFSessionProperty.NON_PROXY_HOSTS.getPropertyKey()); + String proxyProtocol = + proxyProperties.getProperty(SFSessionProperty.PROXY_PROTOCOL.getPropertyKey()); + Protocol protocolEnum = + (!Strings.isNullOrEmpty(proxyProtocol) && proxyProtocol.equalsIgnoreCase("https")) + ? Protocol.HTTPS + : Protocol.HTTP; + clientConfig.setProxyHost(proxyHost); + clientConfig.setProxyPort(proxyPort); + clientConfig.setNonProxyHosts(nonProxyHosts); + clientConfig.setProxyProtocol(protocolEnum); + if (!Strings.isNullOrEmpty(proxyUser) && !Strings.isNullOrEmpty(proxyPassword)) { + clientConfig.setProxyUsername(proxyUser); + clientConfig.setProxyPassword(proxyPassword); } + } } + } } From c4e2225aa4c3ea17f6a880a4774cb963686f8288 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Ferreira?= Date: Wed, 14 Feb 2024 10:20:58 +0000 Subject: [PATCH 16/18] change SnowflakeMutableProxyRoutePlanner constructor --- .../core/SnowflakeMutableProxyRoutePlanner.java | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/main/java/net/snowflake/client/core/SnowflakeMutableProxyRoutePlanner.java b/src/main/java/net/snowflake/client/core/SnowflakeMutableProxyRoutePlanner.java index f41fb270a..b0aae8d2f 100644 --- a/src/main/java/net/snowflake/client/core/SnowflakeMutableProxyRoutePlanner.java +++ b/src/main/java/net/snowflake/client/core/SnowflakeMutableProxyRoutePlanner.java @@ -33,16 +33,17 @@ public class SnowflakeMutableProxyRoutePlanner implements HttpRoutePlanner, Seri @Deprecated public SnowflakeMutableProxyRoutePlanner( String host, int proxyPort, Protocol proxyProtocol, String nonProxyHosts) { - proxyRoutePlanner = new SdkProxyRoutePlanner(host, proxyPort, proxyProtocol, nonProxyHosts); - this.host = host; - this.proxyPort = proxyPort; - this.nonProxyHosts = nonProxyHosts; - this.protocol = toSnowflakeProtocol(proxyProtocol); + this(host, proxyPort, toSnowflakeProtocol(proxyProtocol), nonProxyHosts); } public SnowflakeMutableProxyRoutePlanner( String host, int proxyPort, HttpProtocol proxyProtocol, String nonProxyHosts) { - this(host, proxyPort, toAwsProtocol(proxyProtocol), nonProxyHosts); + proxyRoutePlanner = + new SdkProxyRoutePlanner(host, proxyPort, toAwsProtocol(proxyProtocol), nonProxyHosts); + this.host = host; + this.proxyPort = proxyPort; + this.nonProxyHosts = nonProxyHosts; + this.protocol = proxyProtocol; } public void setNonProxyHosts(String nonProxyHosts) { From d326351d8073785a1af0549465137f631bc529f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Ferreira?= Date: Wed, 14 Feb 2024 10:23:02 +0000 Subject: [PATCH 17/18] reformat --- .../java/net/snowflake/client/core/HttpClientSettingsKey.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/net/snowflake/client/core/HttpClientSettingsKey.java b/src/main/java/net/snowflake/client/core/HttpClientSettingsKey.java index f9f1b5ca7..bb568eab2 100644 --- a/src/main/java/net/snowflake/client/core/HttpClientSettingsKey.java +++ b/src/main/java/net/snowflake/client/core/HttpClientSettingsKey.java @@ -138,7 +138,8 @@ public String getNonProxyHosts() { @Deprecated public com.amazonaws.Protocol getProxyProtocol() { return this.proxyProtocol.equalsIgnoreCase("https") - ? com.amazonaws.Protocol.HTTPS : com.amazonaws.Protocol.HTTP; + ? com.amazonaws.Protocol.HTTPS + : com.amazonaws.Protocol.HTTP; } public HttpProtocol getProxyHttpProtocol() { From ad9f4c1ff962b241ed88e30d8807f0534b74afc9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Ferreira?= Date: Wed, 14 Feb 2024 10:25:57 +0000 Subject: [PATCH 18/18] mark HttpClientSettingsKey.getProxyPassword as internal --- .../java/net/snowflake/client/core/HttpClientSettingsKey.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/net/snowflake/client/core/HttpClientSettingsKey.java b/src/main/java/net/snowflake/client/core/HttpClientSettingsKey.java index bb568eab2..0ca3df8b0 100644 --- a/src/main/java/net/snowflake/client/core/HttpClientSettingsKey.java +++ b/src/main/java/net/snowflake/client/core/HttpClientSettingsKey.java @@ -123,6 +123,7 @@ public String getUserAgentSuffix() { } /** Be careful of using this! Should only be called when password is later masked. */ + @SnowflakeJdbcInternalApi public String getProxyPassword() { return this.proxyPassword; }