diff --git a/cli/src/main/java/denominator/cli/Denominator.java b/cli/src/main/java/denominator/cli/Denominator.java index c0eaf6aa..2dde81f5 100644 --- a/cli/src/main/java/denominator/cli/Denominator.java +++ b/cli/src/main/java/denominator/cli/Denominator.java @@ -23,31 +23,6 @@ import com.google.gson.reflect.TypeToken; import com.google.gson.stream.JsonReader; import com.google.gson.stream.JsonWriter; - -import org.bouncycastle.asn1.pkcs.PrivateKeyInfo; -import org.bouncycastle.jce.provider.BouncyCastleProvider; -import org.bouncycastle.jce.provider.X509CertParser; -import org.bouncycastle.openssl.PEMKeyPair; -import org.bouncycastle.openssl.PEMParser; -import org.yaml.snakeyaml.Yaml; - -import java.io.ByteArrayInputStream; -import java.io.File; -import java.io.IOException; -import java.io.StringReader; -import java.lang.reflect.Type; -import java.security.KeyFactory; -import java.security.spec.PKCS8EncodedKeySpec; -import java.util.Collection; -import java.util.Collections; -import java.util.Iterator; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Map; -import java.util.Map.Entry; - -import javax.inject.Singleton; - import dagger.ObjectGraph; import dagger.Provides; import denominator.Credentials; @@ -86,6 +61,30 @@ import io.airlift.airline.Help; import io.airlift.airline.Option; import io.airlift.airline.OptionType; +import org.bouncycastle.asn1.pkcs.PrivateKeyInfo; +import org.bouncycastle.jce.provider.BouncyCastleProvider; +import org.bouncycastle.jce.provider.X509CertParser; +import org.bouncycastle.openssl.PEMKeyPair; +import org.bouncycastle.openssl.PEMParser; +import org.yaml.snakeyaml.Yaml; + +import javax.inject.Singleton; +import java.io.ByteArrayInputStream; +import java.io.File; +import java.io.IOException; +import java.io.StringReader; +import java.lang.reflect.Type; +import java.net.MalformedURLException; +import java.net.URL; +import java.security.KeyFactory; +import java.security.spec.PKCS8EncodedKeySpec; +import java.util.Collection; +import java.util.Collections; +import java.util.Iterator; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; import static com.google.common.base.Preconditions.checkArgument; import static denominator.CredentialsConfiguration.credentials; @@ -274,6 +273,8 @@ public static abstract class DenominatorCommand implements Runnable { @SuppressWarnings("unchecked") public void run() { + setProxyFromEnv(); + if (providerName != null && credentialArgs != null) { credentials = ListCredentials.from(Lists.transform(credentialArgs, decodeAnyPems)); } else if (providerConfigurationName != null) { @@ -426,6 +427,44 @@ void overrideFromEnv(Map env) { } } + static void setProxyFromEnv() { + String envHttpProxy = System.getenv("HTTP_PROXY"); + if (envHttpProxy != null && !envHttpProxy.isEmpty()) { + try { + URL httpProxyUrl = new URL(envHttpProxy); + + String httpProxyHost = System.getProperty("http.proxyHost"); + if ((httpProxyHost == null || httpProxyHost.isEmpty())) { + System.setProperty("http.proxyHost", httpProxyUrl.getHost()); + System.setProperty("http.proxyPort", + Integer.toString( + httpProxyUrl.getPort() == -1 ? httpProxyUrl.getDefaultPort() : httpProxyUrl.getPort())); + } + } catch (MalformedURLException e) { + System.err.println("invalid http proxy configuration: " + e.getMessage()); + System.exit(1); + } + } + + String envHttpsProxy = System.getenv("HTTPS_PROXY"); + if (envHttpsProxy != null && !envHttpsProxy.isEmpty()) { + try { + URL httpsProxyUrl = new URL(envHttpsProxy); + + String httpsProxyHost = System.getProperty("https.proxyHost"); + if ((httpsProxyHost == null || httpsProxyHost.isEmpty())) { + System.setProperty("https.proxyHost", httpsProxyUrl.getHost()); + System.setProperty("https.proxyPort", + Integer.toString( + httpsProxyUrl.getPort() == -1 ? httpsProxyUrl.getDefaultPort() : httpsProxyUrl.getPort())); + } + } catch (MalformedURLException e) { + System.err.println("invalid https proxy configuration: " + e.getMessage()); + System.exit(1); + } + } + } + /** * return a lazy iterator where possible to improve the perceived responsiveness of the cli */