diff options
author | Salim Alam <salam@chef.io> | 2016-03-17 14:04:53 -0700 |
---|---|---|
committer | Salim Alam <salam@chef.io> | 2016-03-21 21:23:08 -0700 |
commit | 88e05318bc4409b24e9e5ac45403cfde21ad7006 (patch) | |
tree | f72e23329332cee559e3cd1484a7700735bddefc | |
parent | b22d5d03a3d26e274f8f33aacea3666681f02116 (diff) | |
download | chef-88e05318bc4409b24e9e5ac45403cfde21ad7006.tar.gz |
Override no_proxy with internal matcher
-rw-r--r-- | chef-config/lib/chef-config/config.rb | 10 | ||||
-rw-r--r-- | chef.gemspec | 1 | ||||
-rw-r--r-- | lib/chef/http/basic_client.rb | 7 |
3 files changed, 15 insertions, 3 deletions
diff --git a/chef-config/lib/chef-config/config.rb b/chef-config/lib/chef-config/config.rb index 9da69a1867..53799e9ee1 100644 --- a/chef-config/lib/chef-config/config.rb +++ b/chef-config/lib/chef-config/config.rb @@ -27,6 +27,7 @@ require "chef-config/windows" require "chef-config/path_helper" require "mixlib/shellout" require "uri" +require "fuzzyurl" require "openssl" module ChefConfig @@ -864,8 +865,13 @@ module ChefConfig end excludes = ENV["no_proxy"].to_s.split(/\s*,\s*/).compact - excludes = excludes.map { |exclude| exclude =~ /:\d+$/ ? exclude : "#{exclude}:*" } - return proxy unless excludes.any? { |exclude| File.fnmatch(exclude, "#{host}:#{port}") } + return proxy unless excludes.any? { |exclude| fuzzy_hostname_match?(exclude, host) } + end + + def self.fuzzy_hostname_match?(match, hostname) + # Do greedy matching by adding wildcard if it is not specified + match = "*" + match if !match.start_with?("*") + Fuzzyurl.matches?(Fuzzyurl.mask(hostname: match), hostname) end # Chef requires an English-language UTF-8 locale to function properly. We attempt diff --git a/chef.gemspec b/chef.gemspec index 5b9805827a..dfff59d166 100644 --- a/chef.gemspec +++ b/chef.gemspec @@ -31,6 +31,7 @@ Gem::Specification.new do |s| s.add_dependency "diff-lcs", "~> 1.2", ">= 1.2.4" s.add_dependency "chef-zero", "~> 4.5" + s.add_dependency "fuzzyurl", '~> 0.8.0' s.add_dependency "plist", "~> 3.2" diff --git a/lib/chef/http/basic_client.rb b/lib/chef/http/basic_client.rb index 190635f798..4253701510 100644 --- a/lib/chef/http/basic_client.rb +++ b/lib/chef/http/basic_client.rb @@ -100,7 +100,12 @@ class Chef end def build_http_client - http_client = http_client_builder.new(host, port) + # Note: the last nil in the new below forces Net::HTTP to ignore the + # no_proxy environment variable. This is a workaround for limitations + # in Net::HTTP use of the no_proxy environment variable. We internally + # match no_proxy with a fuzzy matcher, rather than letting Net::HTTP + # do it. + http_client = http_client_builder.new(host, port, nil) if url.scheme == HTTPS configure_ssl(http_client) |