diff options
author | Justin Seely <justin.seely@gmail.com> | 2017-07-31 14:19:13 -0700 |
---|---|---|
committer | Justin Seely <justin.seely@gmail.com> | 2017-09-29 16:53:13 +0000 |
commit | ea68edc855e43f2c6c07eab046b81d273111f72e (patch) | |
tree | d1c8fc3b590063c6176002d3abd221f2ae29e83f | |
parent | 97dee8d4dc0c0f618ec6427b84246a5a439b3d23 (diff) | |
download | chef-ea68edc855e43f2c6c07eab046b81d273111f72e.tar.gz |
Fix issue #2351, chef-client doesn't make /etc/chef if the directory doesn't exist
Signed-off-by: Justin Seely <justin.seely@gmail.com>
-rw-r--r-- | lib/chef/api_client/registration.rb | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/lib/chef/api_client/registration.rb b/lib/chef/api_client/registration.rb index e8ab0149e8..e61ef4a160 100644 --- a/lib/chef/api_client/registration.rb +++ b/lib/chef/api_client/registration.rb @@ -19,6 +19,7 @@ require "chef/config" require "chef/server_api" require "chef/exceptions" +require "fileutils" class Chef class ApiClient @@ -69,6 +70,13 @@ class Chef end def assert_destination_writable! + if !File.exists?(File.dirname(destination)) + begin + FileUtils.mkdir_p(File.dirname(destination)) + rescue Errno::EACCES + raise Chef::Exceptions::CannotWritePrivateKey, "I can't write your private key to #{abs_path} - check permissions?" + end + end if (File.exists?(destination) && !File.writable?(destination)) || !File.writable?(File.dirname(destination)) abs_path = File.expand_path(destination) raise Chef::Exceptions::CannotWritePrivateKey, "I can't write your private key to #{abs_path} - check permissions?" |