summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLamont Granquist <lamont@scriptkiddie.org>2015-06-09 13:54:56 -0700
committerLamont Granquist <lamont@scriptkiddie.org>2015-06-09 13:54:56 -0700
commita80f3e29856f9920638405bc6bd1cfb3d45dc754 (patch)
treec0f4f3a1620b3611567525796ad52bac55ee294b
parent58c6fef2890fca55a5bff36842654a4e151ad6af (diff)
downloadchef-lcg/tight-coupling1.tar.gz
moar loosernesslcg/tight-coupling1
-rw-r--r--lib/chef/http.rb18
-rw-r--r--lib/chef/http/auth_credentials.rb13
-rw-r--r--lib/chef/http/authenticator.rb2
-rw-r--r--lib/chef/http/basic_client.rb25
-rw-r--r--lib/chef/http/http_request.rb9
-rw-r--r--lib/chef/http/ssl_policies.rb13
6 files changed, 54 insertions, 26 deletions
diff --git a/lib/chef/http.rb b/lib/chef/http.rb
index f5281639f2..398ca6c5bf 100644
--- a/lib/chef/http.rb
+++ b/lib/chef/http.rb
@@ -332,30 +332,34 @@ class Chef
end
end
+ attr_writer :http_retry_delay
def http_retry_delay
@http_retry_delay ||= config[:http_retry_delay]
end
- attr_writer :http_retry_delay
+ attr_writer :http_retry_count
def http_retry_count
@http_retry_count ||= config[:http_retry_count]
end
- attr_writer :http_retry_count
+ attr_writer :local_mode
def local_mode
@local_mode ||= config[:local_mode]
end
- attr_writer :local_mode
+ attr_writer :custom_http_headers
def custom_http_headers
@custom_http_headers ||= config[:custom_http_headers]
end
- attr_writer :custom_http_headers
+ attr_writer :config
def config
- @config ||= Chef::Config
+ @config ||=
+ begin
+ Thread.exclusive { require 'chef/config' unless defined?(Chef::Config) }
+ Chef::Config
+ end
end
- attr_writer :config
def follow_redirect
raise Chef::Exceptions::RedirectLimitExceeded if @redirects_followed >= redirect_limit
@@ -425,5 +429,3 @@ class Chef
end
end
-
-require 'chef/config'
diff --git a/lib/chef/http/auth_credentials.rb b/lib/chef/http/auth_credentials.rb
index bd73524b1f..dcc2d946c8 100644
--- a/lib/chef/http/auth_credentials.rb
+++ b/lib/chef/http/auth_credentials.rb
@@ -28,8 +28,9 @@ class Chef
class AuthCredentials
attr_reader :client_name, :key
- def initialize(client_name=nil, key=nil)
+ def initialize(client_name=nil, key=nil, opts={})
@client_name, @key = client_name, key
+ @config = opts[:config] if opts.key?(:config)
end
def sign_requests?
@@ -44,7 +45,7 @@ class Chef
request_params = request_params.dup
request_params[:timestamp] = Time.now.utc.iso8601
request_params[:user_id] = client_name
- request_params[:proto_version] = Chef::Config[:authentication_protocol_version]
+ request_params[:proto_version] = config[:authentication_protocol_version]
host = request_params.delete(:host) || "localhost"
sign_obj = Mixlib::Authentication::SignedHeaderAuth.signing_object(request_params)
@@ -52,6 +53,14 @@ class Chef
signed.inject({}){|memo, kv| memo["#{kv[0].to_s.upcase}"] = kv[1];memo}
end
+ def config
+ @config ||=
+ begin
+ Thread.exclusive { require 'chef/config' unless defined?(Chef::Config) }
+ Chef::Config
+ end
+ end
+
end
end
end
diff --git a/lib/chef/http/authenticator.rb b/lib/chef/http/authenticator.rb
index bffa9c4b3a..3c5e49b9e0 100644
--- a/lib/chef/http/authenticator.rb
+++ b/lib/chef/http/authenticator.rb
@@ -38,7 +38,7 @@ class Chef
@sign_request = true
@signing_key_filename = opts[:signing_key_filename]
@key = load_signing_key(opts[:signing_key_filename], opts[:raw_key])
- @auth_credentials = AuthCredentials.new(opts[:client_name], @key)
+ @auth_credentials = AuthCredentials.new(opts[:client_name], @key, opts)
if opts[:api_version]
@api_version = opts[:api_version]
else
diff --git a/lib/chef/http/basic_client.rb b/lib/chef/http/basic_client.rb
index de5e7c03a8..d2564b394b 100644
--- a/lib/chef/http/basic_client.rb
+++ b/lib/chef/http/basic_client.rb
@@ -34,6 +34,7 @@ class Chef
attr_reader :url
attr_reader :http_client
attr_reader :ssl_policy
+ attr_reader :opts
# Instantiate a BasicClient.
# === Arguments:
@@ -44,6 +45,8 @@ class Chef
@url = url
@ssl_policy = opts[:ssl_policy] || DefaultSSLPolicy
@http_client = build_http_client
+ @opts = opts
+ @config = opts[:config] if opts.key?(:config)
end
def host
@@ -55,7 +58,7 @@ class Chef
end
def request(method, url, req_body, base_headers={})
- http_request = HTTPRequest.new(method, url, req_body, base_headers).http_request
+ http_request = HTTPRequest.new(method, url, req_body, base_headers, opts).http_request
Chef::Log.debug("Initiating #{method} to #{url}")
Chef::Log.debug("---- HTTP Request Header Data: ----")
base_headers.each do |name, value|
@@ -97,7 +100,7 @@ class Chef
#adapted from buildr/lib/buildr/core/transports.rb
def proxy_uri
- proxy = Chef::Config["#{url.scheme}_proxy"] ||
+ proxy = config["#{url.scheme}_proxy"] ||
env["#{url.scheme.upcase}_PROXY"] || env["#{url.scheme}_proxy"]
# Check if the proxy string contains a scheme. If not, add the url's scheme to the
@@ -108,10 +111,10 @@ class Chef
proxy = URI.parse(proxy.strip)
else
proxy = URI.parse("#{url.scheme}://#{proxy.strip}")
- end
+ end
end
-
- no_proxy = Chef::Config[:no_proxy] || env['NO_PROXY'] || env['no_proxy']
+
+ no_proxy = config[:no_proxy] || env['NO_PROXY'] || env['no_proxy']
excludes = 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}") }
@@ -130,7 +133,11 @@ class Chef
end
def config
- Chef::Config
+ @config ||=
+ begin
+ Thread.exclusive { require 'chef/config' unless defined?(Chef::Config) }
+ Chef::Config
+ end
end
def env
@@ -150,18 +157,18 @@ class Chef
end
def http_proxy_user(http_proxy)
- http_proxy.user || Chef::Config["#{url.scheme}_proxy_user"] ||
+ http_proxy.user || config["#{url.scheme}_proxy_user"] ||
env["#{url.scheme.upcase}_PROXY_USER"] || env["#{url.scheme}_proxy_user"]
end
def http_proxy_pass(http_proxy)
- http_proxy.password || Chef::Config["#{url.scheme}_proxy_pass"] ||
+ http_proxy.password || config["#{url.scheme}_proxy_pass"] ||
env["#{url.scheme.upcase}_PROXY_PASS"] || env["#{url.scheme}_proxy_pass"]
end
def configure_ssl(http_client)
http_client.use_ssl = true
- ssl_policy.apply_to(http_client)
+ ssl_policy.apply_to(http_client, opts)
end
end
diff --git a/lib/chef/http/http_request.rb b/lib/chef/http/http_request.rb
index 7582f4458f..4a6c316dce 100644
--- a/lib/chef/http/http_request.rb
+++ b/lib/chef/http/http_request.rb
@@ -72,9 +72,10 @@ class Chef
attr_reader :method, :url, :headers, :http_client, :http_request
- def initialize(method, url, req_body, base_headers={})
+ def initialize(method, url, req_body, base_headers={}, opts = {})
@method, @url = method, url
@request_body = nil
+ @config = opts[:config] if opts.key?(:config)
build_headers(base_headers)
configure_http_request(req_body)
end
@@ -110,7 +111,11 @@ class Chef
end
def config
- Chef::Config
+ @config ||=
+ begin
+ Thread.exclusive { require 'chef/config' unless defined?(Chef::Config) }
+ Chef::Config
+ end
end
# DEPRECATED. Call request on an HTTP client object instead.
diff --git a/lib/chef/http/ssl_policies.rb b/lib/chef/http/ssl_policies.rb
index 9c180c154e..aaed6f3e83 100644
--- a/lib/chef/http/ssl_policies.rb
+++ b/lib/chef/http/ssl_policies.rb
@@ -31,15 +31,16 @@ class Chef
# Configures SSL behavior on an HTTP object via visitor pattern.
class DefaultSSLPolicy
- def self.apply_to(http_client)
- new(http_client).apply
+ def self.apply_to(http_client, opts = {})
+ new(http_client, opts).apply
http_client
end
attr_reader :http_client
- def initialize(http_client)
+ def initialize(http_client, opts = {})
@http_client = http_client
+ @config = opts[:config] if opts.key?(:config)
end
def apply
@@ -102,7 +103,11 @@ class Chef
end
def config
- Chef::Config
+ @config ||=
+ begin
+ Thread.exclusive { require 'chef/config' unless defined?(Chef::Config) }
+ Chef::Config
+ end
end
private