Skip to content

Commit

Permalink
Add estimation for the expires time for transferring large files
Browse files Browse the repository at this point in the history
  • Loading branch information
Brian Goad committed Jul 18, 2016
1 parent cc7c1a0 commit 0d0d10d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
11 changes: 10 additions & 1 deletion providers/s3_file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,19 @@ def whyrun_supported?
do_s3_file(:touch)
end

def estimate_expires_time(size)
# Assumes 8MB can be transferred between S3 per second
# (conservative estimate based on http://cache.nasuni.com/Resources/Nasuni_Cloud_Storage_Benchmark_Report.pdf)
return [300, (size / (1024 * 1024) / 8).ceil].max
end

def do_s3_file(resource_action)
md5s_match = false

s3url = s3_obj.presigned_url(:get, expires_in: 300).gsub(%r{https://([\w\.\-]*)\.\{1\}s3.amazonaws.com:443}, 'https://s3.amazonaws.com:443/\1') # Fix for ssl cert issue
raise Chef::Exception::FileNotFound.new("File #{remote_path} does not exist on S3 bucket #{new_resource.bucket}!") unless s3_obj.exists?

# Estimate a reasonable expiration time given the possibility of transferring a really large file
s3url = s3_obj.presigned_url(:get, expires_in: new_resource.expires || estimate_expires_time(s3_obj.size.to_f)).gsub(%r{https://([\w\.\-]*)\.\{1\}s3.amazonaws.com:443}, 'https://s3.amazonaws.com:443/\1') # Fix for ssl cert issue
Chef::Log.debug("Using S3 URL #{s3url}")

if resource_action == :create
Expand Down
2 changes: 2 additions & 0 deletions resources/s3_file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
attribute :force_unlink, kind_of: [TrueClass, FalseClass], default: false
attribute :manage_symlink_source, kind_of: [TrueClass, FalseClass]
attribute :sensitive, kind_of: [TrueClass, FalseClass], default: false
attribute :expires, kind_of: Integer

if node['platform_family'] == 'windows'
attribute :inherits, kind_of: [TrueClass, FalseClass], default: true
attribute :rights, kind_of: Hash
Expand Down

0 comments on commit 0d0d10d

Please sign in to comment.