Skip to content

Commit

Permalink
remove dependency on com.amazonaws.Protocol from HttpClientSettingsKey
Browse files Browse the repository at this point in the history
  • Loading branch information
jtjeferreira committed Feb 5, 2024
1 parent 455ba17 commit 7ca3a88
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

package net.snowflake.client.core;

import com.amazonaws.Protocol;
import com.google.common.base.Strings;
import java.io.Serializable;

Expand Down Expand Up @@ -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() {
Expand Down
19 changes: 19 additions & 0 deletions src/main/java/net/snowflake/client/core/HttpProtocol.java
Original file line number Diff line number Diff line change
@@ -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;
}
}
15 changes: 13 additions & 2 deletions src/main/java/net/snowflake/client/core/HttpUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand All @@ -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
Expand Down Expand Up @@ -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())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@
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;
import java.sql.*;
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;
Expand Down Expand Up @@ -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();
}

Expand All @@ -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();
}

Expand All @@ -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();
}

Expand Down

0 comments on commit 7ca3a88

Please sign in to comment.