lib/chef/knife/s3_source.rb in knife-ec2-0.19.16 vs lib/chef/knife/s3_source.rb in knife-ec2-1.0.1

- old
+ new

@@ -24,17 +24,20 @@ source.url = url source.body end def body - bucket_obj.files.get(path).body + bucket_obj.body.string end private def bucket_obj - @bucket_obj ||= fog.directories.get(bucket) + s3_connection.get_object({ + bucket: bucket, + key: path, + }) end # @return [URI] def bucket uri = URI(@url) @@ -53,16 +56,31 @@ else URI(@url).path.split(bucket).last.sub(/^\//, "") end end - # @return [Fog::Storage::AWS] - def fog - require "fog/aws" # lazy load the fog library to speed up the knife run - @fog ||= Fog::Storage::AWS.new( - aws_access_key_id: Chef::Config[:knife][:aws_access_key_id], - aws_secret_access_key: Chef::Config[:knife][:aws_secret_access_key] - ) + def connection_string + conn = {} + conn[:region] = Chef::Config[:knife][:region] + conn[:credentials] = + if Chef::Config[:knife][:use_iam_profile] + Aws::InstanceProfileCredentials.new + else + Aws::Credentials.new( + Chef::Config[:knife][:aws_access_key_id], + Chef::Config[:knife][:aws_secret_access_key], + Chef::Config[:knife][:aws_session_token] + ) + end + conn + end + + # @return [Aws::S3::Client] + def s3_connection + @s3_connection ||= begin + require "aws-sdk-s3" # lazy load the aws sdk to speed up the knife run + Aws::S3::Client.new(connection_string) + end end end end end