diff options
author | Thom May <thom@chef.io> | 2018-05-04 12:08:27 +0100 |
---|---|---|
committer | Thom May <thom@chef.io> | 2018-05-04 12:08:27 +0100 |
commit | 34a66ec9ab64d740c0d371f7284b8c266b147e3b (patch) | |
tree | 6db945e18010472471e9e73eb9720c6bcdab4fad | |
parent | 06a00403026b06548671adb6239ab44cab4981c2 (diff) | |
download | chef-windows-open-uri.tar.gz |
check the path to --recipe-urlwindows-open-uri
Provide the user with feedback if it's invalid or missing.
Signed-off-by: Thom May <thom@chef.io>
-rw-r--r-- | lib/chef/application/client.rb | 10 | ||||
-rw-r--r-- | spec/integration/client/client_spec.rb | 6 |
2 files changed, 13 insertions, 3 deletions
diff --git a/lib/chef/application/client.rb b/lib/chef/application/client.rb index b5ce2decb3..ffb997f187 100644 --- a/lib/chef/application/client.rb +++ b/lib/chef/application/client.rb @@ -28,6 +28,7 @@ require "chef/workstation_config_loader" require "chef/mixin/shell_out" require "chef-config/mixin/dot_d" require "mixlib/archive" +require "uri" class Chef::Application::Client < Chef::Application include Chef::Mixin::ShellOut @@ -534,14 +535,17 @@ class Chef::Application::Client < Chef::Application def fetch_recipe_tarball(url, path) Chef::Log.trace("Download recipes tarball from #{url} to #{path}") - if File.exist?(url) - FileUtils.cp(url, path) - else + if url =~ URI.regexp File.open(path, "wb") do |f| open(url) do |r| f.write(r.read) end end + elsif File.exist?(url) + FileUtils.cp(url, path) + else + Chef::Application.fatal! "You specified --recipe-url but the value is neither a valid URL nor a path to a file that exists on disk." + + "Please confirm the location of the tarball and try again." end end end diff --git a/spec/integration/client/client_spec.rb b/spec/integration/client/client_spec.rb index 201815ef01..8f2364d99a 100644 --- a/spec/integration/client/client_spec.rb +++ b/spec/integration/client/client_spec.rb @@ -553,6 +553,12 @@ EOM result = shell_out("#{chef_client} --recipe-url=http://localhost:9000/recipes.tgz", :cwd => tmp_dir) expect(result.exitstatus).not_to eq(0) end + + it "should fail when passed --recipe-url with a file that doesn't exist" do + broken_path = File.join(CHEF_SPEC_DATA, "recipes_dont_exist.tgz") + result = shell_out("#{chef_client} --recipe-url=#{broken_path}", :cwd => tmp_dir) + expect(result.exitstatus).not_to eq(0) + end end when_the_repository "has a cookbook with broken metadata.rb, but has metadata.json" do |