Skip to content

Commit

Permalink
(chocolateyGH-262) Sources Explicitly Bypass Proxy
Browse files Browse the repository at this point in the history
Configure a source to explicitly bypass any configured or system
proxies by specifically providing `bypassProxy` as a parameter for
sources to configure. Without this a source could be subject to a proxy
if one is configured, even if it should not be. This allows a user to
explicitly configure a source to not use a proxy.
  • Loading branch information
ferventcoder committed Feb 18, 2017
1 parent 8377b82 commit 4cac92b
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,8 @@ private static void add_or_remove_licensed_source(ChocolateyLicense license, Con
Value = ApplicationParameters.ChocolateyLicensedFeedSource,
UserName = "customer",
Password = NugetEncryptionUtility.EncryptString(license.Id),
Priority = 10
Priority = 10,
BypassProxy = false,
};

if (addOrUpdate && !sources.Any(s =>
Expand Down Expand Up @@ -180,7 +181,8 @@ private static void set_machine_sources(ChocolateyConfiguration config, ConfigFi
EncryptedPassword = source.Password,
Certificate = source.Certificate,
EncryptedCertificatePassword = source.CertificatePassword,
Priority = source.Priority
Priority = source.Priority,
BypassProxy = source.BypassProxy,
});
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,10 @@ public virtual void configure_argument_parser(OptionSet optionSet, ChocolateyCon
option => configuration.SourceCommand.CertificatePassword = option.remove_surrounding_quotes())
.Add("priority=",
"Priority - The priority order of this source as compared to other sources, lower is better. Defaults to 0 (no priority). All priorities above 0 will be evaluated first, then zero-based values will be evaluated in config file order. Available in 0.9.9.9+.",
option => configuration.SourceCommand.Priority = int.Parse(option.remove_surrounding_quotes()))
option => configuration.SourceCommand.Priority = int.Parse(option.remove_surrounding_quotes()))
.Add("bypassProxy",
"BypassProxy - Should this source explicitly bypass any explicitly or system configured proxies? Defaults to false. Available in 0.10.4+.",
option => configuration.SourceCommand.BypassProxy = option != null)
;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,7 @@ public sealed class SourcesCommandConfiguration
public int Priority { get; set; }
public string Certificate { get; set; }
public string CertificatePassword { get; set; }
public bool BypassProxy { get; set; }
}

[Serializable]
Expand All @@ -427,6 +428,7 @@ public sealed class MachineSourceConfiguration
public int Priority { get; set; }
public string Certificate { get; set; }
public string EncryptedCertificatePassword { get; set; }
public bool BypassProxy { get; set; }
}

[Serializable]
Expand Down Expand Up @@ -470,5 +472,6 @@ public sealed class ProxyConfiguration
public string Location { get; set; }
public string User { get; set; }
public string EncryptedPassword { get; set; }
public string BypassList { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ public class ChocolateySource

public bool Disabled { get; set; }

public bool Authenticated { get; set; }
public bool Authenticated { get; set; }

public bool BypassProxy { get; set; }

public int Priority { get; set; }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ public sealed class ConfigFileSourceSetting
[XmlAttribute(AttributeName = "disabled")]
public bool Disabled { get; set; }

[XmlAttribute(AttributeName = "bypassProxy")]
public bool BypassProxy { get; set; }

[XmlAttribute(AttributeName = "user")]
public string UserName { get; set; }

Expand Down
17 changes: 13 additions & 4 deletions src/chocolatey/infrastructure.app/nuget/NugetCommon.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,21 @@ public static IPackageRepository GetRemoteRepository(ChocolateyConfiguration con
{

var source = sourceValue;
if (configuration.MachineSources.Any(m => m.Name.is_equal_to(source)))
var bypassProxy = false;
if (configuration.MachineSources.Any(m => m.Name.is_equal_to(source) || m.Key.is_equal_to(source)))
{
"chocolatey".Log().Debug("Switching source name {0} to actual source value.".format_with(sourceValue));

try
{
source = configuration.MachineSources.FirstOrDefault(m => m.Name.is_equal_to(source)).Key;
var machineSource = configuration.MachineSources.FirstOrDefault(m => m.Key.is_equal_to(source));
if (machineSource == null)
{
machineSource = configuration.MachineSources.FirstOrDefault(m => m.Name.is_equal_to(source));
"chocolatey".Log().Debug("Switching source name {0} to actual source value '{1}'.".format_with(sourceValue, machineSource.Key.to_string()));
source = machineSource.Key;
}

if (machineSource != null) bypassProxy = machineSource.BypassProxy;
}
catch (Exception ex)
{
Expand All @@ -104,7 +113,7 @@ public static IPackageRepository GetRemoteRepository(ChocolateyConfiguration con
}
else
{
repositories.Add(new DataServicePackageRepository(new RedirectedHttpClient(uri)));
repositories.Add(new DataServicePackageRepository(new RedirectedHttpClient(uri, bypassProxy)));
}
}
catch (Exception)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,19 +52,21 @@ public IEnumerable<ChocolateySource> source_list(ChocolateyConfiguration configu
foreach (var source in configFileSettings.Sources)
{
if (!configuration.QuietOutput) {
this.Log().Info(() => "{0}{1} - {2} {3}| Priority {4}.".format_with(
this.Log().Info(() => "{0}{1} - {2} {3}| Priority {4}|Bypass Proxy - {5}.".format_with(
source.Id,
source.Disabled ? " [Disabled]" : string.Empty,
source.Value,
(string.IsNullOrWhiteSpace(source.UserName) && string.IsNullOrWhiteSpace(source.Certificate)) ? string.Empty : "(Authenticated)",
source.Priority));
source.Priority,
source.BypassProxy.to_string()));
}
list.Add(new ChocolateySource {
Id = source.Id,
Value = source.Value,
Disabled = source.Disabled,
Authenticated = !(string.IsNullOrWhiteSpace(source.UserName) && string.IsNullOrWhiteSpace(source.Certificate)),
Priority = source.Priority
Priority = source.Priority,
BypassProxy = source.BypassProxy,
});
}
return list;
Expand All @@ -83,7 +85,8 @@ public void source_add(ChocolateyConfiguration configuration)
Password = NugetEncryptionUtility.EncryptString(configuration.SourceCommand.Password),
Certificate = configuration.SourceCommand.Certificate,
CertificatePassword = NugetEncryptionUtility.EncryptString(configuration.SourceCommand.CertificatePassword),
Priority = configuration.SourceCommand.Priority
Priority = configuration.SourceCommand.Priority,
BypassProxy = configuration.SourceCommand.BypassProxy,
};
configFileSettings.Sources.Add(source);

Expand All @@ -99,7 +102,8 @@ public void source_add(ChocolateyConfiguration configuration)
configuration.SourceCommand.Username.is_equal_to(source.UserName) &&
configuration.SourceCommand.Password.is_equal_to(currentPassword) &&
configuration.SourceCommand.CertificatePassword.is_equal_to(currentCertificatePassword) &&
configuration.SourceCommand.Certificate.is_equal_to(source.Certificate)
configuration.SourceCommand.Certificate.is_equal_to(source.Certificate) &&
configuration.SourceCommand.BypassProxy == source.BypassProxy
)
{
if (!configuration.QuietOutput) this.Log().Warn(NO_CHANGE_MESSAGE);
Expand All @@ -112,6 +116,7 @@ public void source_add(ChocolateyConfiguration configuration)
source.Password = NugetEncryptionUtility.EncryptString(configuration.SourceCommand.Password);
source.CertificatePassword = NugetEncryptionUtility.EncryptString(configuration.SourceCommand.CertificatePassword);
source.Certificate = configuration.SourceCommand.Certificate;
source.BypassProxy = configuration.SourceCommand.BypassProxy;

_xmlService.serialize(configFileSettings, ApplicationParameters.GlobalConfigFileLocation);
if (!configuration.QuietOutput) this.Log().Warn(() => "Updated {0} - {1} (Priority {2})".format_with(source.Id, source.Value, source.Priority));
Expand Down

0 comments on commit 4cac92b

Please sign in to comment.