diff options
author | danielsdeleo <dan@opscode.com> | 2013-10-14 09:50:18 -0700 |
---|---|---|
committer | danielsdeleo <dan@opscode.com> | 2013-10-16 13:53:37 -0700 |
commit | 939e4fe1f8d27dba77ef8208ad792860d9766b9e (patch) | |
tree | 113aef75aecc539af9078d7468ccb80d1a7ab574 /lib/chef/shell.rb | |
parent | b14c9f6e9892ab2398de4035b8d6840d3da375e3 (diff) | |
download | chef-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/shell.rb')
-rw-r--r-- | lib/chef/shell.rb | 22 |
1 files changed, 3 insertions, 19 deletions
diff --git a/lib/chef/shell.rb b/lib/chef/shell.rb index 4c86f96616..0788962e62 100644 --- a/lib/chef/shell.rb +++ b/lib/chef/shell.rb @@ -24,6 +24,7 @@ require 'chef' require 'chef/version' require 'chef/client' require 'chef/config' +require 'chef/config_fetcher' require 'chef/shell/shell_session' require 'chef/shell/ext' @@ -151,26 +152,9 @@ module Shell end def self.parse_json - # HACK: copied verbatim from chef/application/client, because it's not - # reusable as written there :( if Chef::Config[:json_attribs] - begin - json_io = open(Chef::Config[:json_attribs]) - rescue SocketError => error - fatal!("I cannot connect to #{Chef::Config[:json_attribs]}", 2) - rescue Errno::ENOENT => error - fatal!("I cannot find #{Chef::Config[:json_attribs]}", 2) - rescue Errno::EACCES => error - fatal!("Permissions are incorrect on #{Chef::Config[:json_attribs]}. Please chmod a+r #{Chef::Config[:json_attribs]}", 2) - rescue Exception => error - fatal!("Got an unexpected error reading #{Chef::Config[:json_attribs]}: #{error.message}", 2) - end - - begin - @json_attribs = Chef::JSONCompat.from_json(json_io.read) - rescue JSON::ParserError => error - 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]) + @json_attribs = config_fetcher.fetch_json end end |