Skip to content

Commit

Permalink
Allow setting connection proxy for ADL connection
Browse files Browse the repository at this point in the history
  • Loading branch information
wendigo authored and losipiuk committed Apr 20, 2021
1 parent 8942fdd commit 5ed22be
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
*/
package io.trino.plugin.hive.azure;

import com.google.common.net.HostAndPort;
import io.airlift.configuration.Config;
import io.airlift.configuration.ConfigSecuritySensitive;

Expand All @@ -27,6 +28,7 @@ public class HiveAzureConfig
private String adlClientId;
private String adlCredential;
private String adlRefreshUrl;
private HostAndPort adlProxyHost;
private String abfsOAuthClientEndpoint;
private String abfsOAuthClientId;
private String abfsOAuthClientSecret;
Expand Down Expand Up @@ -122,6 +124,18 @@ public HiveAzureConfig setAdlRefreshUrl(String adlRefreshUrl)
return this;
}

@Config("hive.azure.adl-proxy-host")
public HiveAzureConfig setAdlProxyHost(HostAndPort adlProxyHost)
{
this.adlProxyHost = adlProxyHost;
return this;
}

public Optional<HostAndPort> getAdlProxyHost()
{
return Optional.ofNullable(adlProxyHost);
}

@ConfigSecuritySensitive
@Config("hive.azure.abfs.oauth.endpoint")
public HiveAzureConfig setAbfsOAuthClientEndpoint(String endpoint)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,17 @@
*/
package io.trino.plugin.hive.azure;

import com.google.common.net.HostAndPort;
import io.trino.plugin.hive.ConfigurationInitializer;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.adl.AdlFileSystem;
import org.apache.hadoop.fs.azurebfs.AzureBlobFileSystem;

import javax.inject.Inject;

import java.net.InetSocketAddress;
import java.net.Proxy;
import java.net.Proxy.Type;
import java.util.Optional;

import static com.google.common.base.Preconditions.checkArgument;
Expand Down Expand Up @@ -79,6 +83,9 @@ public TrinoAzureConfigurationInitializer(HiveAzureConfig config)
checkArgument(
!(abfsAccessKey.isPresent() && abfsOAuthClientSecret.isPresent()),
"Multiple ABFS authentication methods configured: access key and OAuth2");

config.getAdlProxyHost().ifPresent(proxyHost ->
io.trino.hadoop.$internal.com.microsoft.azure.datalake.store.HttpTransport.setConnectionProxy(proxyForHost(proxyHost)));
}

@Override
Expand Down Expand Up @@ -116,4 +123,9 @@ private static Optional<String> dropEmpty(Optional<String> optional)
{
return optional.filter(value -> !value.isEmpty());
}

private static Proxy proxyForHost(HostAndPort address)
{
return new Proxy(Type.HTTP, new InetSocketAddress(address.getHost(), address.getPort()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
package io.trino.plugin.hive.azure;

import com.google.common.collect.ImmutableMap;
import com.google.common.net.HostAndPort;
import org.testng.annotations.Test;

import java.util.Map;
Expand All @@ -34,6 +35,7 @@ public void testDefaults()
.setAbfsAccessKey(null)
.setAdlClientId(null)
.setAdlCredential(null)
.setAdlProxyHost(null)
.setAdlRefreshUrl(null)
.setAbfsOAuthClientEndpoint(null)
.setAbfsOAuthClientId(null)
Expand All @@ -51,6 +53,7 @@ public void testExplicitPropertyMappings()
.put("hive.azure.adl-client-id", "adlclientid")
.put("hive.azure.adl-credential", "adlcredential")
.put("hive.azure.adl-refresh-url", "adlrefreshurl")
.put("hive.azure.adl-proxy-host", "proxy-host:9800")
.put("hive.azure.abfs.oauth.endpoint", "abfsoauthendpoint")
.put("hive.azure.abfs.oauth.client-id", "abfsoauthclientid")
.put("hive.azure.abfs.oauth.secret", "abfsoauthsecret")
Expand All @@ -64,6 +67,7 @@ public void testExplicitPropertyMappings()
.setAdlClientId("adlclientid")
.setAdlCredential("adlcredential")
.setAdlRefreshUrl("adlrefreshurl")
.setAdlProxyHost(HostAndPort.fromParts("proxy-host", 9800))
.setAbfsOAuthClientEndpoint("abfsoauthendpoint")
.setAbfsOAuthClientId("abfsoauthclientid")
.setAbfsOAuthClientSecret("abfsoauthsecret");
Expand Down

0 comments on commit 5ed22be

Please sign in to comment.