Skip to content

Commit 0d0d10d

Browse files
author
Brian Goad
committed
Add estimation for the expires time for transferring large files
1 parent cc7c1a0 commit 0d0d10d

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

providers/s3_file.rb

+10-1
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,19 @@ def whyrun_supported?
2222
do_s3_file(:touch)
2323
end
2424

25+
def estimate_expires_time(size)
26+
# Assumes 8MB can be transferred between S3 per second
27+
# (conservative estimate based on http://cache.nasuni.com/Resources/Nasuni_Cloud_Storage_Benchmark_Report.pdf)
28+
return [300, (size / (1024 * 1024) / 8).ceil].max
29+
end
30+
2531
def do_s3_file(resource_action)
2632
md5s_match = false
2733

28-
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
34+
raise Chef::Exception::FileNotFound.new("File #{remote_path} does not exist on S3 bucket #{new_resource.bucket}!") unless s3_obj.exists?
35+
36+
# Estimate a reasonable expiration time given the possibility of transferring a really large file
37+
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
2938
Chef::Log.debug("Using S3 URL #{s3url}")
3039

3140
if resource_action == :create

resources/s3_file.rb

+2
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@
3535
attribute :force_unlink, kind_of: [TrueClass, FalseClass], default: false
3636
attribute :manage_symlink_source, kind_of: [TrueClass, FalseClass]
3737
attribute :sensitive, kind_of: [TrueClass, FalseClass], default: false
38+
attribute :expires, kind_of: Integer
39+
3840
if node['platform_family'] == 'windows'
3941
attribute :inherits, kind_of: [TrueClass, FalseClass], default: true
4042
attribute :rights, kind_of: Hash

0 commit comments

Comments
 (0)