diff options
author | danielsdeleo <dan@opscode.com> | 2013-10-14 15:20:46 -0700 |
---|---|---|
committer | danielsdeleo <dan@opscode.com> | 2013-10-16 13:53:37 -0700 |
commit | dd998f23aa904011fa3aeef40e2fae31273ad4e5 (patch) | |
tree | 0f42bd77f794f7ab91733a2d89ccccfbcfa96114 /lib/chef/config_fetcher.rb | |
parent | 3b877d8956531eb18ca5b398e2b2c8b4e33b71ce (diff) | |
download | chef-dd998f23aa904011fa3aeef40e2fae31273ad4e5.tar.gz |
Load client/solo config via ConfigFetcher
* Uses Chef::HTTP::Simple rather than Chef::REST to fetch files
* Re-use error handling logic in ConfigFetcher
Diffstat (limited to 'lib/chef/config_fetcher.rb')
-rw-r--r-- | lib/chef/config_fetcher.rb | 33 |
1 files changed, 31 insertions, 2 deletions
diff --git a/lib/chef/config_fetcher.rb b/lib/chef/config_fetcher.rb index 129d8bed62..2400dc6897 100644 --- a/lib/chef/config_fetcher.rb +++ b/lib/chef/config_fetcher.rb @@ -1,11 +1,17 @@ +require 'chef/application' +require 'chef/chef_fs/path_utils' require 'chef/http/simple' +require 'chef/json_compat' + class Chef class ConfigFetcher attr_reader :config_location + attr_reader :config_file_jail - def initialize(config_location) + def initialize(config_location, config_file_jail) @config_location = config_location + @config_file_jail = config_file_jail end def fetch_json @@ -27,7 +33,7 @@ class Chef def fetch_remote_config http.get("") - rescue SocketError, SystemCallError => error + rescue SocketError, SystemCallError, Net::HTTPServerException => error Chef::Application.fatal!("Cannot fetch config '#{config_location}': '#{error.class}: #{error.message}", 2) end @@ -39,6 +45,29 @@ class Chef Chef::Application.fatal!("Permissions are incorrect on #{config_location}. Please chmod a+r #{config_location}", 2) end + def config_missing? + return true if remote_config? + + # Check if the config file exists, and check if it is underneath the config file jail + begin + real_config_file = Pathname.new(config_file).realpath.to_s + rescue Errno::ENOENT + return false + end + + # If realpath succeeded, the file exists + return true if !config_file_jail + + begin + real_jail = Pathname.new(config_file_jail).realpath.to_s + rescue Errno::ENOENT + Chef::Log.warn("Config file jail #{config_file_jail} does not exist: will not load any config file.") + return false + end + + Chef::ChefFS::PathUtils.descendant_of?(real_config_file, real_jail) + end + def http Chef::HTTP::Simple.new(config_location) end |