summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/chef/config.rb22
-rw-r--r--spec/unit/config_spec.rb21
2 files changed, 43 insertions, 0 deletions
diff --git a/lib/chef/config.rb b/lib/chef/config.rb
index feb7e4ea94..c4a3fdaf48 100644
--- a/lib/chef/config.rb
+++ b/lib/chef/config.rb
@@ -507,5 +507,27 @@ class Chef
# created under ENV['TMP'] otherwise tempfiles will be created in
# the directory that files are going to reside.
default :file_staging_uses_destdir, false
+
+ # If installed via an omnibus installer, this gives the path to the
+ # "embedded" directory which contains all of the software packaged with
+ # omnibus. This is used to locate the cacert.pem file on windows.
+ def self.embedded_dir
+ find_embedded_dir_in(_this_file)
+ end
+
+ def self.find_embedded_dir_in(path)
+ if File.basename(path) == "embedded"
+ path
+ elsif File.basename(path) == path
+ nil
+ else
+ find_embedded_dir_in(File.dirname(path))
+ end
+ end
+
+ # Path to this file in the current install.
+ def self._this_file
+ File.expand_path(__FILE__)
+ end
end
end
diff --git a/spec/unit/config_spec.rb b/spec/unit/config_spec.rb
index cb48ab5bcc..e887c05202 100644
--- a/spec/unit/config_spec.rb
+++ b/spec/unit/config_spec.rb
@@ -266,6 +266,27 @@ describe Chef::Config do
end
end
+
+ describe "finding the windows embedded dir" do
+ let(:default_config_location) { "c:/opscode/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.6.0/lib/chef/config.rb" }
+ let(:alternate_install_location) { "c:/my/alternate/install/place/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.6.0/lib/chef/config.rb" }
+ let(:non_omnibus_location) { "c:/my/dev/stuff/lib/ruby/gems/1.9.1/gems/chef-11.6.0/lib/chef/config.rb" }
+
+ it "finds the embedded dir in the default location" do
+ Chef::Config.stub(:_this_file).and_return(default_config_location)
+ Chef::Config.embedded_dir.should == "c:/opscode/chef/embedded"
+ end
+
+ it "finds the embedded dir in a custom install location" do
+ Chef::Config.stub(:_this_file).and_return(alternate_install_location)
+ Chef::Config.embedded_dir.should == "c:/my/alternate/install/place/chef/embedded"
+ end
+
+ it "doesn't error when not in an omnibus install" do
+ Chef::Config.stub(:_this_file).and_return(non_omnibus_location)
+ Chef::Config.embedded_dir.should be_nil
+ end
+ end
end
describe "Chef::Config[:user_home]" do