summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordanielsdeleo <dan@getchef.com>2015-03-27 15:37:41 -0700
committerdanielsdeleo <dan@getchef.com>2015-04-01 13:35:01 -0700
commitbb882960a984fc7b80dec12c33cef09cdba9f65f (patch)
tree0806bbccd7a89e5c0203b93223ebfdca5d04da1a
parent110f3b77d46d4c58c00e1badeaec92875fb4e1ef (diff)
downloadchef-bb882960a984fc7b80dec12c33cef09cdba9f65f.tar.gz
Hoist socketless chef-zero support into Chef::HTTP
Was hoping to avoid this, but there are multiple subclasses of Chef::HTTP that interact with the server, which all must support socketless mode.
-rw-r--r--lib/chef/http.rb13
-rw-r--r--lib/chef/local_mode.rb2
-rw-r--r--lib/chef/rest.rb34
-rw-r--r--lib/chef/server_api.rb1
4 files changed, 15 insertions, 35 deletions
diff --git a/lib/chef/http.rb b/lib/chef/http.rb
index 5e52337aff..0e0bc2988e 100644
--- a/lib/chef/http.rb
+++ b/lib/chef/http.rb
@@ -196,14 +196,18 @@ class Chef
def http_client(base_url=nil)
base_url ||= url
- BasicClient.new(base_url)
+ if chef_zero_uri?(base_url)
+ SocketlessChefZeroClient.new(base_url)
+ else
+ BasicClient.new(base_url, :ssl_policy => Chef::HTTP::APISSLPolicy)
+ end
end
protected
def create_url(path)
return path if path.is_a?(URI)
- if path =~ /^(http|https):\/\//i
+ if path =~ /^(http|https|chefzero):\/\//i
URI.parse(path)
elsif path.nil? or path.empty?
URI.parse(@url)
@@ -351,6 +355,11 @@ class Chef
private
+ def chef_zero_uri?(uri)
+ uri = URI.parse(uri) unless uri.respond_to?(:scheme)
+ uri.scheme == "chefzero"
+ end
+
def redirected_to(response)
return nil unless response.kind_of?(Net::HTTPRedirection)
# Net::HTTPNotModified is undesired subclass of Net::HTTPRedirection so test for this
diff --git a/lib/chef/local_mode.rb b/lib/chef/local_mode.rb
index c814301b4b..13782ce3d8 100644
--- a/lib/chef/local_mode.rb
+++ b/lib/chef/local_mode.rb
@@ -62,6 +62,8 @@ class Chef
server_options = {}
server_options[:data_store] = data_store
server_options[:log_level] = Chef::Log.level
+
+ # TODO: there needs to be an option to force Chef Zero to operate in socket-ful mode
# server_options[:host] = Chef::Config.chef_zero.host
# server_options[:port] = parse_port(Chef::Config.chef_zero.port)
# @chef_zero_server = ChefZero::Server.new(server_options)
diff --git a/lib/chef/rest.rb b/lib/chef/rest.rb
index 8ff01e78da..2b1f2044c4 100644
--- a/lib/chef/rest.rb
+++ b/lib/chef/rest.rb
@@ -165,16 +165,11 @@ class Chef
r["SERVER_PORT"] = ""
r["rack.url_scheme"] = "chefzero"
r["rack.input"] = StringIO.new(body_str)
- pp rack_req: r
res = ChefZero::Socketless.instance.request(r)
- pp raw_rack_response: res
-
net_http_response = to_net_http(res[0], res[1], res[2])
- #pp net_http_response: net_http_response
-
yield net_http_response if block_given?
[self, net_http_response]
@@ -231,13 +226,7 @@ class Chef
# HTTP GET request to http://localhost:4000/nodes
def initialize(url, client_name=Chef::Config[:node_name], signing_key_filename=Chef::Config[:client_key], options={})
- url_as_uri = url.respond_to?(:scheme) ? url : URI.parse(url)
-
- # TODO: NEW STUFF ADD TESTS
- scheme = url_as_uri.scheme
- @socketless = (scheme == "chefzero")
- signing_key_filename = nil if @socketless
-
+ signing_key_filename = nil if chef_zero_uri?(url)
options = options.dup
options[:client_name] = client_name
@@ -370,27 +359,6 @@ class Chef
public :create_url
- def create_url(path)
- return path if path.is_a?(URI)
- if path =~ /^(chefzero):\/\//i
- URI.parse(path)
- else
- super
- end
- end
-
- def http_client(base_url=nil)
- base_url ||= url
- pp url_class: base_url.class, value: base_url
- base_url = URI.parse(base_url) if base_url.kind_of?(String)
- if base_url.scheme == "chefzero"
- pp using_zero_client: base_url
- SocketlessChefZeroClient.new(base_url)
- else
- BasicClient.new(base_url, :ssl_policy => Chef::HTTP::APISSLPolicy)
- end
- end
-
############################################################################
# DEPRECATED
############################################################################
diff --git a/lib/chef/server_api.rb b/lib/chef/server_api.rb
index 8cdcd7a09d..ec4a864cb3 100644
--- a/lib/chef/server_api.rb
+++ b/lib/chef/server_api.rb
@@ -30,6 +30,7 @@ class Chef
def initialize(url = Chef::Config[:chef_server_url], options = {})
options[:client_name] ||= Chef::Config[:node_name]
options[:signing_key_filename] ||= Chef::Config[:client_key]
+ options[:signing_key_filename] = nil if chef_zero_uri?(url)
super(url, options)
end