summaryrefslogtreecommitdiff
path: root/lib/chef/application
diff options
context:
space:
mode:
authorThomas Heinen <theinen@tecracer.de>2021-08-26 16:03:43 +0200
committerThomas Heinen <theinen@tecracer.de>2021-09-06 11:10:03 +0200
commitd1d4f1b065c11242eaf9f16a66b3405d86b7d35a (patch)
tree82d5d4e8f61f7a6bd59be0372226489731859c1d /lib/chef/application
parentb91d99f16947b82d09217079f5423b5c7cd0962c (diff)
downloadchef-d1d4f1b065c11242eaf9f16a66b3405d86b7d35a.tar.gz
Enable directly using AWS S3 with --recipe-url parameter of Chef Client
Signed-off-by: Thomas Heinen <theinen@tecracer.de>
Diffstat (limited to 'lib/chef/application')
-rw-r--r--lib/chef/application/base.rb12
1 files changed, 11 insertions, 1 deletions
diff --git a/lib/chef/application/base.rb b/lib/chef/application/base.rb
index b2f98d5f2f..fc8511a04b 100644
--- a/lib/chef/application/base.rb
+++ b/lib/chef/application/base.rb
@@ -378,9 +378,19 @@ class Chef::Application::Base < Chef::Application
def fetch_recipe_tarball(url, path)
require "open-uri" unless defined?(OpenURI)
+ uri = URI.parse(url)
+
Chef::Log.trace("Download recipes tarball from #{url} to #{path}")
if File.exist?(url)
FileUtils.cp(url, path)
+ elsif uri.scheme == "s3"
+ require "aws-sdk-s3" unless defined?(Aws::S3)
+
+ s3 = Aws::S3::Client.new
+ object = s3.get_object(bucket: uri.hostname, key: uri.path[1..-1])
+ File.open(path, "wb") do |f|
+ f.write(object.body.read)
+ end
elsif URI::DEFAULT_PARSER.make_regexp.match?(url)
File.open(path, "wb") do |f|
URI.open(url) do |r|
@@ -388,7 +398,7 @@ class Chef::Application::Base < Chef::Application
end
end
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." +
+ Chef::Application.fatal! "You specified --recipe-url but the value is neither a valid URL, an S3 bucket nor a path to a file that exists on disk." +
"Please confirm the location of the tarball and try again."
end
end