diff options
author | Thomas Heinen <theinen@tecracer.de> | 2021-08-26 16:03:43 +0200 |
---|---|---|
committer | Thomas Heinen <theinen@tecracer.de> | 2021-09-06 11:10:03 +0200 |
commit | d1d4f1b065c11242eaf9f16a66b3405d86b7d35a (patch) | |
tree | 82d5d4e8f61f7a6bd59be0372226489731859c1d | |
parent | b91d99f16947b82d09217079f5423b5c7cd0962c (diff) | |
download | chef-d1d4f1b065c11242eaf9f16a66b3405d86b7d35a.tar.gz |
Enable directly using AWS S3 with --recipe-url parameter of Chef Client
Signed-off-by: Thomas Heinen <theinen@tecracer.de>
-rw-r--r-- | chef.gemspec | 1 | ||||
-rw-r--r-- | lib/chef/application/base.rb | 12 |
2 files changed, 12 insertions, 1 deletions
diff --git a/chef.gemspec b/chef.gemspec index 936a9dfd91..1c735d3e88 100644 --- a/chef.gemspec +++ b/chef.gemspec @@ -55,6 +55,7 @@ Gem::Specification.new do |s| s.add_dependency "proxifier", "~> 1.0" + s.add_dependency "aws-sdk-s3", "~> 1.99" s.add_dependency "aws-sdk-secretsmanager", "~> 1.46" s.add_dependency "vault", "~> 0.16" # hashi vault official client gem s.bindir = "bin" 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 |