Skip to content

Commit

Permalink
(GH-605) Ensure environment proxy settings available
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
ferventcoder committed Feb 28, 2017
1 parent 70a6120 commit bf5f78b
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 7 deletions.
15 changes: 15 additions & 0 deletions src/chocolatey/infrastructure.app/builders/ConfigurationBuilder.cs
Expand Up @@ -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)
Expand Down
Expand Up @@ -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;
Expand All @@ -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");
}

Expand Down

0 comments on commit bf5f78b

Please sign in to comment.