summaryrefslogtreecommitdiff
path: root/lib/chef/application/solo.rb
diff options
context:
space:
mode:
authordanielsdeleo <dan@opscode.com>2013-10-14 09:50:18 -0700
committerdanielsdeleo <dan@opscode.com>2013-10-16 13:53:37 -0700
commit939e4fe1f8d27dba77ef8208ad792860d9766b9e (patch)
tree113aef75aecc539af9078d7468ccb80d1a7ab574 /lib/chef/application/solo.rb
parentb14c9f6e9892ab2398de4035b8d6840d3da375e3 (diff)
downloadchef-939e4fe1f8d27dba77ef8208ad792860d9766b9e.tar.gz
Move json attribs fetching to a class
* Extract duplicated code for fetching/reading JSON attributes to a shared class * Use HTTP::Simple instead of Chef::REST
Diffstat (limited to 'lib/chef/application/solo.rb')
-rw-r--r--lib/chef/application/solo.rb29
1 files changed, 3 insertions, 26 deletions
diff --git a/lib/chef/application/solo.rb b/lib/chef/application/solo.rb
index 960c917c66..ba563ce3a8 100644
--- a/lib/chef/application/solo.rb
+++ b/lib/chef/application/solo.rb
@@ -23,7 +23,7 @@ require 'chef/config'
require 'chef/daemon'
require 'chef/log'
require 'chef/rest'
-require 'open-uri'
+require 'chef/config_fetcher'
require 'fileutils'
class Chef::Application::Solo < Chef::Application
@@ -181,36 +181,13 @@ class Chef::Application::Solo < Chef::Application
end
if Chef::Config[:json_attribs]
- begin
- json_io = case Chef::Config[:json_attribs]
- when /^(http|https):\/\//
- @rest = Chef::REST.new(Chef::Config[:json_attribs], nil, nil)
- @rest.get_rest(Chef::Config[:json_attribs], true).open
- else
- open(Chef::Config[:json_attribs])
- end
- rescue SocketError => error
- Chef::Application.fatal!("I cannot connect to #{Chef::Config[:json_attribs]}", 2)
- rescue Errno::ENOENT => error
- Chef::Application.fatal!("I cannot find #{Chef::Config[:json_attribs]}", 2)
- rescue Errno::EACCES => error
- Chef::Application.fatal!("Permissions are incorrect on #{Chef::Config[:json_attribs]}. Please chmod a+r #{Chef::Config[:json_attribs]}", 2)
- rescue Exception => error
- Chef::Application.fatal!("Got an unexpected error reading #{Chef::Config[:json_attribs]}: #{error.message}", 2)
- end
-
- begin
- @chef_client_json = Chef::JSONCompat.from_json(json_io.read)
- json_io.close unless json_io.closed?
- rescue JSON::ParserError => error
- Chef::Application.fatal!("Could not parse the provided JSON file (#{Chef::Config[:json_attribs]})!: " + error.message, 2)
- end
+ config_fetcher = Chef::ConfigFetcher.new(Chef::Config[:json_attribs])
+ @chef_solo_json = config_fetcher.fetch_json
end
if Chef::Config[:recipe_url]
cookbooks_path = Array(Chef::Config[:cookbook_path]).detect{|e| e =~ /\/cookbooks\/*$/ }
recipes_path = File.expand_path(File.join(cookbooks_path, '..'))
- target_file = File.join(recipes_path, 'recipes.tgz')
Chef::Log.debug "Creating path #{recipes_path} to extract recipes into"
FileUtils.mkdir_p recipes_path