From 3ca1eb9726f73bb6be8fca41cb7de7134529000f Mon Sep 17 00:00:00 2001 From: danielsdeleo Date: Fri, 28 Oct 2016 14:38:14 -0700 Subject: Extract data collector http config to a private method Signed-off-by: Daniel DeLeo --- lib/chef/data_collector.rb | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) (limited to 'lib/chef/data_collector.rb') diff --git a/lib/chef/data_collector.rb b/lib/chef/data_collector.rb index 4365497bab..f544a4b044 100644 --- a/lib/chef/data_collector.rb +++ b/lib/chef/data_collector.rb @@ -113,12 +113,7 @@ class Chef @deprecations = Set.new @enabled = true - @http = - if data_collector_token.nil? - Chef::ServerAPI.new(data_collector_server_url) - else - Chef::HTTP::SimpleJSON.new(data_collector_server_url) - end + @http = setup_http_client end # see EventDispatch::Base#run_started @@ -285,6 +280,19 @@ class Chef private + # Selects the type of HTTP client to use based on whether we are using + # token-based or signed header authentication. Token authentication is + # intended to be used primarily for Chef Solo in which case no signing + # key will be available (in which case `Chef::ServerAPI.new()` would + # raise an exception. + def setup_http_client + if data_collector_token.nil? + Chef::ServerAPI.new(data_collector_server_url) + else + Chef::HTTP::SimpleJSON.new(data_collector_server_url) + end + end + # # Yields to the passed-in block (which is expected to be some interaction # with the DataCollector endpoint). If some communication failure occurs, -- cgit v1.2.1