From bf5f78bffe4fb07029bcee119a6d9b3694746dca Mon Sep 17 00:00:00 2001 From: Rob Reynolds Date: Tue, 28 Feb 2017 13:33:22 -0600 Subject: [PATCH] (GH-605) Ensure environment proxy settings available When proxy settings are determined from the environment, ensure they are available for use with all areas of Chocolatey and not just the PowerShell scripts. --- .../builders/ConfigurationBuilder.cs | 15 +++++++++++++++ .../configuration/EnvironmentSettings.cs | 15 ++++++++------- 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/src/chocolatey/infrastructure.app/builders/ConfigurationBuilder.cs b/src/chocolatey/infrastructure.app/builders/ConfigurationBuilder.cs index f29e9691e8..27c0f54dd8 100644 --- a/src/chocolatey/infrastructure.app/builders/ConfigurationBuilder.cs +++ b/src/chocolatey/infrastructure.app/builders/ConfigurationBuilder.cs @@ -474,6 +474,21 @@ private static void set_environment_options(ChocolateyConfiguration config) config.Information.IsInteractive = Environment.UserInteractive; config.Information.IsUserAdministrator = ProcessInformation.user_is_administrator(); config.Information.IsProcessElevated = ProcessInformation.process_is_elevated(); + + if (!string.IsNullOrWhiteSpace(Environment.GetEnvironmentVariable("https_proxy")) && string.IsNullOrWhiteSpace(config.Proxy.Location)) + { + config.Proxy.Location = Environment.GetEnvironmentVariable("https_proxy"); + } + + if (!string.IsNullOrWhiteSpace(Environment.GetEnvironmentVariable("http_proxy")) && string.IsNullOrWhiteSpace(config.Proxy.Location)) + { + config.Proxy.Location = Environment.GetEnvironmentVariable("http_proxy"); + } + + if (!string.IsNullOrWhiteSpace(Environment.GetEnvironmentVariable("no_proxy")) && string.IsNullOrWhiteSpace(config.Proxy.BypassList)) + { + config.Proxy.BypassList = Environment.GetEnvironmentVariable("no_proxy"); + } } private static void set_licensed_options(ChocolateyConfiguration config, ChocolateyLicense license, ConfigFileSettings configFileSettings) diff --git a/src/chocolatey/infrastructure.app/configuration/EnvironmentSettings.cs b/src/chocolatey/infrastructure.app/configuration/EnvironmentSettings.cs index 9e63a81442..08bea315b2 100644 --- a/src/chocolatey/infrastructure.app/configuration/EnvironmentSettings.cs +++ b/src/chocolatey/infrastructure.app/configuration/EnvironmentSettings.cs @@ -86,12 +86,7 @@ public static void set_environment_variables(ChocolateyConfiguration config) if (config.Features.ScriptsCheckLastExitCode) Environment.SetEnvironmentVariable(ApplicationParameters.Environment.ChocolateyCheckLastExitCode, "true"); Environment.SetEnvironmentVariable("chocolateyRequestTimeout", config.WebRequestTimeoutSeconds.to_string() + "000"); Environment.SetEnvironmentVariable("chocolateyResponseTimeout", config.CommandExecutionTimeoutSeconds.to_string() + "000"); - - - if (!string.IsNullOrWhiteSpace(Environment.GetEnvironmentVariable("https_proxy"))) Environment.SetEnvironmentVariable("chocolateyProxyLocation", Environment.GetEnvironmentVariable("https_proxy")); - if (!string.IsNullOrWhiteSpace(Environment.GetEnvironmentVariable("http_proxy")) && string.IsNullOrWhiteSpace(Environment.GetEnvironmentVariable("chocolateyProxyLocation"))) Environment.SetEnvironmentVariable("chocolateyProxyLocation", Environment.GetEnvironmentVariable("http_proxy")); - if (!string.IsNullOrWhiteSpace(Environment.GetEnvironmentVariable("no_proxy"))) Environment.SetEnvironmentVariable("chocolateyProxyBypassList", Environment.GetEnvironmentVariable("no_proxy")); - + if (!string.IsNullOrWhiteSpace(config.Proxy.Location)) { var proxyCreds = string.Empty; @@ -109,7 +104,13 @@ public static void set_environment_variables(ChocolateyConfiguration config) Environment.SetEnvironmentVariable("https_proxy", "{0}{1}".format_with(proxyCreds, config.Proxy.Location)); Environment.SetEnvironmentVariable("chocolateyProxyLocation", config.Proxy.Location); - if (!string.IsNullOrWhiteSpace(config.Proxy.BypassList)) Environment.SetEnvironmentVariable("chocolateyProxyBypassList", config.Proxy.BypassList); + if (!string.IsNullOrWhiteSpace(config.Proxy.BypassList)) + { + Environment.SetEnvironmentVariable("chocolateyProxyBypassList", config.Proxy.BypassList); + Environment.SetEnvironmentVariable("no_proxy", config.Proxy.BypassList); + + } + if (config.Proxy.BypassOnLocal) Environment.SetEnvironmentVariable("chocolateyProxyBypassOnLocal", "true"); }