summaryrefslogtreecommitdiff
path: root/lib/chef/application.rb
diff options
context:
space:
mode:
authorJohn Keiser <jkeiser@opscode.com>2013-10-15 20:53:52 -0700
committerJohn Keiser <jkeiser@opscode.com>2013-10-15 20:53:52 -0700
commitc3115f323ef6c7cc588af2c0845bfecac9184019 (patch)
treea3850b059204351c98db79d48a3c1a3cb412c3a2 /lib/chef/application.rb
parentcb8845818e9a130d1a85793675aa1216b936d168 (diff)
parente1c6bef68597f5c4f418107ef9e3638e44cc8cf7 (diff)
downloadchef-c3115f323ef6c7cc588af2c0845bfecac9184019.tar.gz
Merge branch 'jk/local_multi_cache_path'
Diffstat (limited to 'lib/chef/application.rb')
-rw-r--r--lib/chef/application.rb51
1 files changed, 44 insertions, 7 deletions
diff --git a/lib/chef/application.rb b/lib/chef/application.rb
index 8bd8506749..04b8a0f9d8 100644
--- a/lib/chef/application.rb
+++ b/lib/chef/application.rb
@@ -25,6 +25,8 @@ require 'chef/platform'
require 'mixlib/cli'
require 'tmpdir'
require 'rbconfig'
+require 'pathname'
+require 'chef/chef_fs/path_utils'
class Chef::Application
include Mixlib::CLI
@@ -75,7 +77,21 @@ class Chef::Application
# Parse the config file
def load_config_file
if !config[:config_file]
- Chef::Log.warn("No config file found or specified on command line, not loading.")
+ Chef::Log.warn("No config file found or specified on command line, using command line options.")
+ Chef::Config.merge!(config)
+ return
+ end
+
+ if !Chef::Application.config_file_exists?(config[:config_file])
+ Chef::Log.warn("*****************************************")
+ if !File.exists?(config[:config_file])
+ Chef::Log.warn("Did not find config file: #{config[:config_file]}, using command line options.")
+ else
+ Chef::Log.warn("Config file #{config[:config_file]} not inside the jail #{Chef::Config.config_file_jail}, using command line options.", 2)
+ end
+ Chef::Log.warn("*****************************************")
+
+ Chef::Config.merge!(config)
return
end
@@ -86,12 +102,6 @@ class Chef::Application
else
::File::open(config[:config_file]) { |f| apply_config(f.path) }
end
- rescue Errno::ENOENT => error
- Chef::Log.warn("*****************************************")
- Chef::Log.warn("Did not find config file: #{config[:config_file]}, using command line options.")
- Chef::Log.warn("*****************************************")
-
- Chef::Config.merge!(config)
rescue SocketError => error
Chef::Application.fatal!("Error getting config file #{config[:config_file]}", 2)
rescue Chef::Exceptions::ConfigurationError => error
@@ -101,6 +111,33 @@ class Chef::Application
end
end
+ # Determines whether a config file exists, taking into account file existence
+ # as well as Chef::Config.config_file_jail (if they are not under the jail,
+ # this method will return false). Takes symlinks and relative paths into
+ # account.
+ def self.config_file_exists?(config_file)
+ if config_file =~ /^(http|https):\/\//
+ return true
+ end
+
+ begin
+ real_config_file = Pathname.new(config_file).realpath.to_s
+ rescue Errno::ENOENT
+ return false
+ end
+
+ return true if !Chef::Config.config_file_jail
+
+ begin
+ jail = Pathname.new(Chef::Config.config_file_jail).realpath.to_s
+ rescue Errno::ENOENT
+ Chef::Log.warn("Config file jail #{Chef::Config.config_file_jail} does not exist: will not load any config file.")
+ return false
+ end
+
+ Chef::ChefFS::PathUtils.descendant_of?(real_config_file, jail)
+ end
+
# Initialize and configure the logger.
# === Loggers and Formatters
# In Chef 10.x and previous, the Logger was the primary/only way that Chef