aws-sdk-s3 1.87.0 → 1.143.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (98) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +1106 -0
  3. data/LICENSE.txt +202 -0
  4. data/VERSION +1 -0
  5. data/lib/aws-sdk-s3/bucket.rb +605 -114
  6. data/lib/aws-sdk-s3/bucket_acl.rb +36 -11
  7. data/lib/aws-sdk-s3/bucket_cors.rb +40 -15
  8. data/lib/aws-sdk-s3/bucket_lifecycle.rb +42 -15
  9. data/lib/aws-sdk-s3/bucket_lifecycle_configuration.rb +43 -13
  10. data/lib/aws-sdk-s3/bucket_logging.rb +40 -11
  11. data/lib/aws-sdk-s3/bucket_notification.rb +30 -12
  12. data/lib/aws-sdk-s3/bucket_policy.rb +82 -13
  13. data/lib/aws-sdk-s3/bucket_request_payment.rb +35 -13
  14. data/lib/aws-sdk-s3/bucket_tagging.rb +38 -13
  15. data/lib/aws-sdk-s3/bucket_versioning.rb +82 -21
  16. data/lib/aws-sdk-s3/bucket_website.rb +38 -13
  17. data/lib/aws-sdk-s3/client.rb +8666 -3425
  18. data/lib/aws-sdk-s3/client_api.rb +774 -225
  19. data/lib/aws-sdk-s3/customizations/bucket.rb +31 -50
  20. data/lib/aws-sdk-s3/customizations/errors.rb +27 -0
  21. data/lib/aws-sdk-s3/customizations/object.rb +211 -37
  22. data/lib/aws-sdk-s3/customizations/types/permanent_redirect.rb +26 -0
  23. data/lib/aws-sdk-s3/customizations.rb +7 -0
  24. data/lib/aws-sdk-s3/encryption/client.rb +7 -3
  25. data/lib/aws-sdk-s3/encryption/decrypt_handler.rb +0 -4
  26. data/lib/aws-sdk-s3/encryption/kms_cipher_provider.rb +13 -9
  27. data/lib/aws-sdk-s3/encryptionV2/client.rb +7 -3
  28. data/lib/aws-sdk-s3/encryptionV2/decrypt_handler.rb +1 -4
  29. data/lib/aws-sdk-s3/encryptionV2/default_cipher_provider.rb +3 -3
  30. data/lib/aws-sdk-s3/encryptionV2/encrypt_handler.rb +0 -4
  31. data/lib/aws-sdk-s3/encryptionV2/kms_cipher_provider.rb +10 -6
  32. data/lib/aws-sdk-s3/endpoint_parameters.rb +178 -0
  33. data/lib/aws-sdk-s3/endpoint_provider.rb +591 -0
  34. data/lib/aws-sdk-s3/endpoints.rb +2590 -0
  35. data/lib/aws-sdk-s3/errors.rb +1 -1
  36. data/lib/aws-sdk-s3/event_streams.rb +1 -1
  37. data/lib/aws-sdk-s3/express_credentials.rb +55 -0
  38. data/lib/aws-sdk-s3/express_credentials_cache.rb +30 -0
  39. data/lib/aws-sdk-s3/express_credentials_provider.rb +36 -0
  40. data/lib/aws-sdk-s3/file_downloader.rb +171 -41
  41. data/lib/aws-sdk-s3/file_uploader.rb +14 -7
  42. data/lib/aws-sdk-s3/multipart_file_uploader.rb +26 -8
  43. data/lib/aws-sdk-s3/multipart_stream_uploader.rb +41 -14
  44. data/lib/aws-sdk-s3/multipart_upload.rb +198 -23
  45. data/lib/aws-sdk-s3/multipart_upload_part.rb +285 -34
  46. data/lib/aws-sdk-s3/object.rb +1824 -266
  47. data/lib/aws-sdk-s3/object_acl.rb +58 -19
  48. data/lib/aws-sdk-s3/object_copier.rb +7 -5
  49. data/lib/aws-sdk-s3/object_multipart_copier.rb +41 -19
  50. data/lib/aws-sdk-s3/object_summary.rb +1579 -299
  51. data/lib/aws-sdk-s3/object_version.rb +372 -64
  52. data/lib/aws-sdk-s3/plugins/accelerate.rb +1 -39
  53. data/lib/aws-sdk-s3/plugins/arn.rb +25 -142
  54. data/lib/aws-sdk-s3/plugins/bucket_dns.rb +3 -39
  55. data/lib/aws-sdk-s3/plugins/bucket_name_restrictions.rb +1 -6
  56. data/lib/aws-sdk-s3/plugins/dualstack.rb +2 -49
  57. data/lib/aws-sdk-s3/plugins/endpoints.rb +274 -0
  58. data/lib/aws-sdk-s3/plugins/expect_100_continue.rb +3 -1
  59. data/lib/aws-sdk-s3/plugins/express_session_auth.rb +91 -0
  60. data/lib/aws-sdk-s3/plugins/get_bucket_location_fix.rb +1 -1
  61. data/lib/aws-sdk-s3/plugins/iad_regional_endpoint.rb +8 -31
  62. data/lib/aws-sdk-s3/plugins/location_constraint.rb +3 -1
  63. data/lib/aws-sdk-s3/plugins/md5s.rb +6 -3
  64. data/lib/aws-sdk-s3/plugins/s3_signer.rb +35 -102
  65. data/lib/aws-sdk-s3/plugins/skip_whole_multipart_get_checksums.rb +31 -0
  66. data/lib/aws-sdk-s3/plugins/streaming_retry.rb +23 -2
  67. data/lib/aws-sdk-s3/presigned_post.rb +99 -78
  68. data/lib/aws-sdk-s3/presigner.rb +43 -51
  69. data/lib/aws-sdk-s3/resource.rb +102 -6
  70. data/lib/aws-sdk-s3/types.rb +7404 -5114
  71. data/lib/aws-sdk-s3/waiters.rb +1 -1
  72. data/lib/aws-sdk-s3.rb +6 -2
  73. data/sig/bucket.rbs +212 -0
  74. data/sig/bucket_acl.rbs +78 -0
  75. data/sig/bucket_cors.rbs +69 -0
  76. data/sig/bucket_lifecycle.rbs +88 -0
  77. data/sig/bucket_lifecycle_configuration.rbs +111 -0
  78. data/sig/bucket_logging.rbs +76 -0
  79. data/sig/bucket_notification.rbs +114 -0
  80. data/sig/bucket_policy.rbs +59 -0
  81. data/sig/bucket_request_payment.rbs +54 -0
  82. data/sig/bucket_tagging.rbs +65 -0
  83. data/sig/bucket_versioning.rbs +77 -0
  84. data/sig/bucket_website.rbs +93 -0
  85. data/sig/client.rbs +2360 -0
  86. data/sig/errors.rbs +34 -0
  87. data/sig/multipart_upload.rbs +110 -0
  88. data/sig/multipart_upload_part.rbs +105 -0
  89. data/sig/object.rbs +436 -0
  90. data/sig/object_acl.rbs +86 -0
  91. data/sig/object_summary.rbs +334 -0
  92. data/sig/object_version.rbs +131 -0
  93. data/sig/resource.rbs +124 -0
  94. data/sig/types.rbs +2562 -0
  95. data/sig/waiters.rbs +83 -0
  96. metadata +51 -17
  97. data/lib/aws-sdk-s3/arn/access_point_arn.rb +0 -62
  98. data/lib/aws-sdk-s3/arn/outpost_access_point_arn.rb +0 -71
@@ -3,7 +3,7 @@
3
3
  # WARNING ABOUT GENERATED CODE
4
4
  #
5
5
  # This file is generated. See the contributing guide for more information:
6
- # https://github.com/aws/aws-sdk-ruby/blob/master/CONTRIBUTING.md
6
+ # https://github.com/aws/aws-sdk-ruby/blob/version-3/CONTRIBUTING.md
7
7
  #
8
8
  # WARNING ABOUT GENERATED CODE
9
9
 
@@ -3,7 +3,7 @@
3
3
  # WARNING ABOUT GENERATED CODE
4
4
  #
5
5
  # This file is generated. See the contributing guide for more information:
6
- # https://github.com/aws/aws-sdk-ruby/blob/master/CONTRIBUTING.md
6
+ # https://github.com/aws/aws-sdk-ruby/blob/version-3/CONTRIBUTING.md
7
7
  #
8
8
  # WARNING ABOUT GENERATED CODE
9
9
 
@@ -0,0 +1,55 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'set'
4
+
5
+ module Aws
6
+ module S3
7
+ # @api private
8
+ class ExpressCredentials
9
+ include CredentialProvider
10
+ include RefreshingCredentials
11
+
12
+ SYNC_EXPIRATION_LENGTH = 60 # 1 minute
13
+ ASYNC_EXPIRATION_LENGTH = 120 # 2 minutes
14
+
15
+ def initialize(options = {})
16
+ @client = options[:client]
17
+ @create_session_params = {}
18
+ options.each_pair do |key, value|
19
+ if self.class.create_session_options.include?(key)
20
+ @create_session_params[key] = value
21
+ end
22
+ end
23
+ @async_refresh = true
24
+ super
25
+ end
26
+
27
+ # @return [S3::Client]
28
+ attr_reader :client
29
+
30
+ private
31
+
32
+ def refresh
33
+ c = @client.create_session(@create_session_params).credentials
34
+ @credentials = Credentials.new(
35
+ c.access_key_id,
36
+ c.secret_access_key,
37
+ c.session_token
38
+ )
39
+ @expiration = c.expiration
40
+ end
41
+
42
+ class << self
43
+
44
+ # @api private
45
+ def create_session_options
46
+ @cso ||= begin
47
+ input = S3::Client.api.operation(:create_session).input
48
+ Set.new(input.shape.member_names)
49
+ end
50
+ end
51
+
52
+ end
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Aws
4
+ module S3
5
+ # @api private
6
+ class ExpressCredentialsCache
7
+ def initialize
8
+ @credentials = {}
9
+ @mutex = Mutex.new
10
+ end
11
+
12
+ def [](bucket_name)
13
+ @mutex.synchronize { @credentials[bucket_name] }
14
+ end
15
+
16
+ def []=(bucket_name, credential_provider)
17
+ @mutex.synchronize do
18
+ @credentials[bucket_name] = credential_provider
19
+ end
20
+ end
21
+
22
+ def clear
23
+ @mutex.synchronize { @credentials = {} }
24
+ end
25
+ end
26
+
27
+ # @api private
28
+ EXPRESS_CREDENTIALS_CACHE = ExpressCredentialsCache.new
29
+ end
30
+ end
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Aws
4
+ module S3
5
+ # Returns Credentials class for S3 Express. Accepts CreateSession
6
+ # params as options. See {Client#create_session} for details.
7
+ class ExpressCredentialsProvider
8
+ # @param [Hash] options
9
+ # @option options [Client] :client The S3 client used to create the session.
10
+ # @option options [String] :session_mode (see: {Client#create_session})
11
+ # @option options [Callable] :before_refresh Proc called before
12
+ # credentials are refreshed.
13
+ def initialize(options = {})
14
+ @client = options.delete(:client)
15
+ @options = options
16
+ @cache = EXPRESS_CREDENTIALS_CACHE
17
+ end
18
+
19
+ def express_credentials_for(bucket)
20
+ @cache[bucket] || new_credentials_for(bucket)
21
+ end
22
+
23
+ attr_accessor :client
24
+
25
+ private
26
+
27
+ def new_credentials_for(bucket)
28
+ @cache[bucket] = ExpressCredentials.new(
29
+ bucket: bucket,
30
+ client: @client,
31
+ **@options
32
+ )
33
+ end
34
+ end
35
+ end
36
+ end
@@ -32,39 +32,68 @@ module Aws
32
32
  }
33
33
  @params[:version_id] = options[:version_id] if options[:version_id]
34
34
 
35
- case @mode
36
- when 'auto' then multipart_download
37
- when 'single_request' then single_request
38
- when 'get_range'
39
- if @chunk_size
40
- resp = @client.head_object(@params)
41
- multithreaded_get_by_ranges(construct_chunks(resp.content_length))
35
+ # checksum_mode only supports the value "ENABLED"
36
+ # falsey values (false/nil) or "DISABLED" should be considered
37
+ # disabled and the api parameter should be unset.
38
+ if (checksum_mode = options.fetch(:checksum_mode, 'ENABLED'))
39
+ @params[:checksum_mode] = checksum_mode unless checksum_mode.upcase == 'DISABLED'
40
+ end
41
+ @on_checksum_validated = options[:on_checksum_validated]
42
+
43
+ @progress_callback = options[:progress_callback]
44
+
45
+ validate!
46
+
47
+ Aws::Plugins::UserAgent.feature('s3-transfer') do
48
+ case @mode
49
+ when 'auto' then multipart_download
50
+ when 'single_request' then single_request
51
+ when 'get_range'
52
+ if @chunk_size
53
+ resp = @client.head_object(@params)
54
+ multithreaded_get_by_ranges(resp.content_length)
55
+ else
56
+ msg = 'In :get_range mode, :chunk_size must be provided'
57
+ raise ArgumentError, msg
58
+ end
42
59
  else
43
- msg = 'In :get_range mode, :chunk_size must be provided'
60
+ msg = "Invalid mode #{@mode} provided, "\
61
+ 'mode should be :single_request, :get_range or :auto'
44
62
  raise ArgumentError, msg
45
63
  end
46
- else
47
- msg = "Invalid mode #{@mode} provided, "\
48
- 'mode should be :single_request, :get_range or :auto'
49
- raise ArgumentError, msg
50
64
  end
51
65
  end
52
66
 
53
67
  private
54
68
 
69
+ def validate!
70
+ if @on_checksum_validated && @params[:checksum_mode] != 'ENABLED'
71
+ raise ArgumentError, "You must set checksum_mode: 'ENABLED' " +
72
+ "when providing a on_checksum_validated callback"
73
+ end
74
+
75
+ if @on_checksum_validated && !@on_checksum_validated.respond_to?(:call)
76
+ raise ArgumentError, 'on_checksum_validated must be callable'
77
+ end
78
+ end
79
+
55
80
  def multipart_download
56
81
  resp = @client.head_object(@params.merge(part_number: 1))
57
82
  count = resp.parts_count
58
83
  if count.nil? || count <= 1
59
- resp.content_length < MIN_CHUNK_SIZE ?
60
- single_request :
61
- multithreaded_get_by_ranges(construct_chunks(resp.content_length))
84
+ if resp.content_length <= MIN_CHUNK_SIZE
85
+ single_request
86
+ else
87
+ multithreaded_get_by_ranges(resp.content_length)
88
+ end
62
89
  else
63
90
  # partNumber is an option
64
91
  resp = @client.head_object(@params)
65
- resp.content_length < MIN_CHUNK_SIZE ?
66
- single_request :
92
+ if resp.content_length <= MIN_CHUNK_SIZE
93
+ single_request
94
+ else
67
95
  compute_mode(resp.content_length, count)
96
+ end
68
97
  end
69
98
  end
70
99
 
@@ -72,9 +101,9 @@ module Aws
72
101
  chunk_size = compute_chunk(file_size)
73
102
  part_size = (file_size.to_f / count.to_f).ceil
74
103
  if chunk_size < part_size
75
- multithreaded_get_by_ranges(construct_chunks(file_size))
104
+ multithreaded_get_by_ranges(file_size)
76
105
  else
77
- multithreaded_get_by_parts(count)
106
+ multithreaded_get_by_parts(count, file_size)
78
107
  end
79
108
  end
80
109
 
@@ -82,10 +111,11 @@ module Aws
82
111
  offset = 0
83
112
  default_chunk_size = compute_chunk(file_size)
84
113
  chunks = []
85
- while offset <= file_size
114
+ while offset < file_size
86
115
  progress = offset + default_chunk_size
87
- chunks << "bytes=#{offset}-#{progress < file_size ? progress : file_size}"
88
- offset = progress + 1
116
+ progress = file_size if progress > file_size
117
+ chunks << "bytes=#{offset}-#{progress - 1}"
118
+ offset = progress
89
119
  end
90
120
  chunks
91
121
  end
@@ -94,7 +124,9 @@ module Aws
94
124
  if @chunk_size && @chunk_size > file_size
95
125
  raise ArgumentError, ":chunk_size shouldn't exceed total file size."
96
126
  else
97
- @chunk_size || [(file_size.to_f / MAX_PARTS).ceil, MIN_CHUNK_SIZE].max.to_i
127
+ @chunk_size || [
128
+ (file_size.to_f / MAX_PARTS).ceil, MIN_CHUNK_SIZE
129
+ ].max.to_i
98
130
  end
99
131
  end
100
132
 
@@ -103,39 +135,137 @@ module Aws
103
135
  chunks.each_slice(@thread_count).to_a
104
136
  end
105
137
 
106
- def multithreaded_get_by_ranges(chunks)
107
- thread_batches(chunks, 'range')
138
+ def multithreaded_get_by_ranges(file_size)
139
+ offset = 0
140
+ default_chunk_size = compute_chunk(file_size)
141
+ chunks = []
142
+ part_number = 1 # parts start at 1
143
+ while offset < file_size
144
+ progress = offset + default_chunk_size
145
+ progress = file_size if progress > file_size
146
+ range = "bytes=#{offset}-#{progress - 1}"
147
+ chunks << Part.new(
148
+ part_number: part_number,
149
+ size: (progress-offset),
150
+ params: @params.merge(range: range)
151
+ )
152
+ part_number += 1
153
+ offset = progress
154
+ end
155
+ download_in_threads(PartList.new(chunks), file_size)
108
156
  end
109
157
 
110
- def multithreaded_get_by_parts(parts)
111
- thread_batches(parts, 'part_number')
158
+ def multithreaded_get_by_parts(n_parts, total_size)
159
+ parts = (1..n_parts).map do |part|
160
+ Part.new(part_number: part, params: @params.merge(part_number: part))
161
+ end
162
+ download_in_threads(PartList.new(parts), total_size)
112
163
  end
113
164
 
114
- def thread_batches(chunks, param)
115
- batches(chunks, param).each do |batch|
116
- threads = []
117
- batch.each do |chunk|
118
- threads << Thread.new do
119
- resp = @client.get_object(
120
- @params.merge(param.to_sym => chunk)
121
- )
122
- write(resp)
165
+ def download_in_threads(pending, total_size)
166
+ threads = []
167
+ if @progress_callback
168
+ progress = MultipartProgress.new(pending, total_size, @progress_callback)
169
+ end
170
+ @thread_count.times do
171
+ thread = Thread.new do
172
+ begin
173
+ while part = pending.shift
174
+ if progress
175
+ part.params[:on_chunk_received] =
176
+ proc do |_chunk, bytes, total|
177
+ progress.call(part.part_number, bytes, total)
178
+ end
179
+ end
180
+ resp = @client.get_object(part.params)
181
+ write(resp)
182
+ if @on_checksum_validated && resp.checksum_validated
183
+ @on_checksum_validated.call(resp.checksum_validated, resp)
184
+ end
185
+ end
186
+ nil
187
+ rescue => error
188
+ # keep other threads from downloading other parts
189
+ pending.clear!
190
+ raise error
123
191
  end
124
192
  end
125
- threads.each(&:join)
193
+ threads << thread
126
194
  end
195
+ threads.map(&:value).compact
127
196
  end
128
197
 
129
198
  def write(resp)
130
199
  range, _ = resp.content_range.split(' ').last.split('/')
131
200
  head, _ = range.split('-').map {|s| s.to_i}
132
- IO.write(@path, resp.body.read, head)
201
+ File.write(@path, resp.body.read, head)
133
202
  end
134
203
 
135
204
  def single_request
136
- @client.get_object(
137
- @params.merge(response_target: @path)
138
- )
205
+ params = @params.merge(response_target: @path)
206
+ params[:on_chunk_received] = single_part_progress if @progress_callback
207
+ resp = @client.get_object(params)
208
+
209
+ return resp unless @on_checksum_validated
210
+
211
+ if resp.checksum_validated
212
+ @on_checksum_validated.call(resp.checksum_validated, resp)
213
+ end
214
+
215
+ resp
216
+ end
217
+
218
+ def single_part_progress
219
+ proc do |_chunk, bytes_read, total_size|
220
+ @progress_callback.call([bytes_read], [total_size], total_size)
221
+ end
222
+ end
223
+
224
+ class Part < Struct.new(:part_number, :size, :params)
225
+ include Aws::Structure
226
+ end
227
+
228
+ # @api private
229
+ class PartList
230
+ include Enumerable
231
+ def initialize(parts = [])
232
+ @parts = parts
233
+ @mutex = Mutex.new
234
+ end
235
+
236
+ def shift
237
+ @mutex.synchronize { @parts.shift }
238
+ end
239
+
240
+ def size
241
+ @mutex.synchronize { @parts.size }
242
+ end
243
+
244
+ def clear!
245
+ @mutex.synchronize { @parts.clear }
246
+ end
247
+
248
+ def each(&block)
249
+ @mutex.synchronize { @parts.each(&block) }
250
+ end
251
+ end
252
+
253
+ # @api private
254
+ class MultipartProgress
255
+ def initialize(parts, total_size, progress_callback)
256
+ @bytes_received = Array.new(parts.size, 0)
257
+ @part_sizes = parts.map(&:size)
258
+ @total_size = total_size
259
+ @progress_callback = progress_callback
260
+ end
261
+
262
+ def call(part_number, bytes_received, total)
263
+ # part numbers start at 1
264
+ @bytes_received[part_number - 1] = bytes_received
265
+ # part size may not be known until we get the first response
266
+ @part_sizes[part_number - 1] ||= total
267
+ @progress_callback.call(@bytes_received, @part_sizes, @total_size)
268
+ end
139
269
  end
140
270
  end
141
271
  end
@@ -7,16 +7,16 @@ module Aws
7
7
  # @api private
8
8
  class FileUploader
9
9
 
10
- FIFTEEN_MEGABYTES = 15 * 1024 * 1024
10
+ ONE_HUNDRED_MEGABYTES = 100 * 1024 * 1024
11
11
 
12
12
  # @param [Hash] options
13
13
  # @option options [Client] :client
14
- # @option options [Integer] :multipart_threshold (15728640)
14
+ # @option options [Integer] :multipart_threshold (104857600)
15
15
  def initialize(options = {})
16
16
  @options = options
17
17
  @client = options[:client] || Client.new
18
18
  @multipart_threshold = options[:multipart_threshold] ||
19
- FIFTEEN_MEGABYTES
19
+ ONE_HUNDRED_MEGABYTES
20
20
  end
21
21
 
22
22
  # @return [Client]
@@ -32,12 +32,19 @@ module Aws
32
32
  # @option options [Proc] :progress_callback
33
33
  # A Proc that will be called when each chunk of the upload is sent.
34
34
  # It will be invoked with [bytes_read], [total_sizes]
35
+ # @option options [Integer] :thread_count
36
+ # The thread count to use for multipart uploads. Ignored for
37
+ # objects smaller than the multipart threshold.
35
38
  # @return [void]
36
39
  def upload(source, options = {})
37
- if File.size(source) >= multipart_threshold
38
- MultipartFileUploader.new(@options).upload(source, options)
39
- else
40
- put_object(source, options)
40
+ Aws::Plugins::UserAgent.feature('s3-transfer') do
41
+ if File.size(source) >= multipart_threshold
42
+ MultipartFileUploader.new(@options).upload(source, options)
43
+ else
44
+ # remove multipart parameters not supported by put_object
45
+ options.delete(:thread_count)
46
+ put_object(source, options)
47
+ end
41
48
  end
42
49
  end
43
50
 
@@ -21,6 +21,10 @@ module Aws
21
21
  Client.api.operation(:create_multipart_upload).input.shape.member_names
22
22
  )
23
23
 
24
+ COMPLETE_OPTIONS = Set.new(
25
+ Client.api.operation(:complete_multipart_upload).input.shape.member_names
26
+ )
27
+
24
28
  # @api private
25
29
  UPLOAD_PART_OPTIONS = Set.new(
26
30
  Client.api.operation(:upload_part).input.shape.member_names
@@ -42,7 +46,7 @@ module Aws
42
46
  # @option options [Proc] :progress_callback
43
47
  # A Proc that will be called when each chunk of the upload is sent.
44
48
  # It will be invoked with [bytes_read], [total_sizes]
45
- # @return [void]
49
+ # @return [Seahorse::Client::Response] - the CompleteMultipartUploadResponse
46
50
  def upload(source, options = {})
47
51
  if File.size(source) < MIN_PART_SIZE
48
52
  raise ArgumentError, FILE_TOO_SMALL
@@ -61,10 +65,10 @@ module Aws
61
65
 
62
66
  def complete_upload(upload_id, parts, options)
63
67
  @client.complete_multipart_upload(
64
- bucket: options[:bucket],
65
- key: options[:key],
66
- upload_id: upload_id,
67
- multipart_upload: { parts: parts }
68
+ **complete_opts(options).merge(
69
+ upload_id: upload_id,
70
+ multipart_upload: { parts: parts }
71
+ )
68
72
  )
69
73
  end
70
74
 
@@ -123,6 +127,13 @@ module Aws
123
127
  end
124
128
  end
125
129
 
130
+ def complete_opts(options)
131
+ COMPLETE_OPTIONS.inject({}) do |hash, key|
132
+ hash[key] = options[key] if options.key?(key)
133
+ hash
134
+ end
135
+ end
136
+
126
137
  def upload_part_opts(options)
127
138
  UPLOAD_PART_OPTIONS.inject({}) do |hash, key|
128
139
  hash[key] = options[key] if options.key?(key)
@@ -147,7 +158,15 @@ module Aws
147
158
  end
148
159
  resp = @client.upload_part(part)
149
160
  part[:body].close
150
- completed.push(etag: resp.etag, part_number: part[:part_number])
161
+ completed_part = {etag: resp.etag, part_number: part[:part_number]}
162
+
163
+ # get the requested checksum from the response
164
+ if part[:checksum_algorithm]
165
+ k = "checksum_#{part[:checksum_algorithm].downcase}".to_sym
166
+ completed_part[k] = resp[k]
167
+ end
168
+
169
+ completed.push(completed_part)
151
170
  end
152
171
  nil
153
172
  rescue => error
@@ -156,7 +175,6 @@ module Aws
156
175
  error
157
176
  end
158
177
  end
159
- thread.abort_on_exception = true
160
178
  threads << thread
161
179
  end
162
180
  threads.map(&:value).compact
@@ -224,4 +242,4 @@ module Aws
224
242
  end
225
243
  end
226
244
  end
227
- end
245
+ end
@@ -26,6 +26,10 @@ module Aws
26
26
  UPLOAD_PART_OPTIONS =
27
27
  Set.new(Client.api.operation(:upload_part).input.shape.member_names)
28
28
 
29
+ # @api private
30
+ COMPLETE_UPLOAD_OPTIONS =
31
+ Set.new(Client.api.operation(:complete_multipart_upload).input.shape.member_names)
32
+
29
33
  # @option options [Client] :client
30
34
  def initialize(options = {})
31
35
  @client = options[:client] || Client.new
@@ -39,11 +43,13 @@ module Aws
39
43
 
40
44
  # @option options [required,String] :bucket
41
45
  # @option options [required,String] :key
42
- # @return [void]
46
+ # @return [Seahorse::Client::Response] - the CompleteMultipartUploadResponse
43
47
  def upload(options = {}, &block)
44
- upload_id = initiate_upload(options)
45
- parts = upload_parts(upload_id, options, &block)
46
- complete_upload(upload_id, parts, options)
48
+ Aws::Plugins::UserAgent.feature('s3-transfer') do
49
+ upload_id = initiate_upload(options)
50
+ parts = upload_parts(upload_id, options, &block)
51
+ complete_upload(upload_id, parts, options)
52
+ end
47
53
  end
48
54
 
49
55
  private
@@ -54,17 +60,22 @@ module Aws
54
60
 
55
61
  def complete_upload(upload_id, parts, options)
56
62
  @client.complete_multipart_upload(
57
- bucket: options[:bucket],
58
- key: options[:key],
59
- upload_id: upload_id,
60
- multipart_upload: { parts: parts })
63
+ **complete_opts(options).merge(
64
+ upload_id: upload_id,
65
+ multipart_upload: { parts: parts }
66
+ )
67
+ )
61
68
  end
62
69
 
63
70
  def upload_parts(upload_id, options, &block)
64
71
  completed = Queue.new
72
+ thread_errors = []
65
73
  errors = begin
66
74
  IO.pipe do |read_pipe, write_pipe|
67
- threads = upload_in_threads(read_pipe, completed, upload_part_opts(options).merge(upload_id: upload_id))
75
+ threads = upload_in_threads(
76
+ read_pipe, completed,
77
+ upload_part_opts(options).merge(upload_id: upload_id),
78
+ thread_errors)
68
79
  begin
69
80
  block.call(write_pipe)
70
81
  ensure
@@ -74,7 +85,7 @@ module Aws
74
85
  threads.map(&:value).compact
75
86
  end
76
87
  rescue => e
77
- [e]
88
+ thread_errors + [e]
78
89
  end
79
90
 
80
91
  if errors.empty?
@@ -113,6 +124,13 @@ module Aws
113
124
  end
114
125
  end
115
126
 
127
+ def complete_opts(options)
128
+ COMPLETE_UPLOAD_OPTIONS.inject({}) do |hash, key|
129
+ hash[key] = options[key] if options.key?(key)
130
+ hash
131
+ end
132
+ end
133
+
116
134
  def read_to_part_body(read_pipe)
117
135
  return if read_pipe.closed?
118
136
  temp_io = @tempfile ? Tempfile.new(TEMPFILE_PREIX) : StringIO.new(String.new)
@@ -130,7 +148,7 @@ module Aws
130
148
  end
131
149
  end
132
150
 
133
- def upload_in_threads(read_pipe, completed, options)
151
+ def upload_in_threads(read_pipe, completed, options, thread_errors)
134
152
  mutex = Mutex.new
135
153
  part_number = 0
136
154
  @thread_count.times.map do
@@ -147,7 +165,14 @@ module Aws
147
165
  part_number: thread_part_number,
148
166
  )
149
167
  resp = @client.upload_part(part)
150
- completed << {etag: resp.etag, part_number: part[:part_number]}
168
+ completed_part = {etag: resp.etag, part_number: part[:part_number]}
169
+
170
+ # get the requested checksum from the response
171
+ if part[:checksum_algorithm]
172
+ k = "checksum_#{part[:checksum_algorithm].downcase}".to_sym
173
+ completed_part[k] = resp[k]
174
+ end
175
+ completed.push(completed_part)
151
176
  ensure
152
177
  if Tempfile === body
153
178
  body.close
@@ -160,11 +185,13 @@ module Aws
160
185
  nil
161
186
  rescue => error
162
187
  # keep other threads from uploading other parts
163
- mutex.synchronize { read_pipe.close_read unless read_pipe.closed? }
188
+ mutex.synchronize do
189
+ thread_errors.push(error)
190
+ read_pipe.close_read unless read_pipe.closed?
191
+ end
164
192
  error
165
193
  end
166
194
  end
167
- thread.abort_on_exception = true
168
195
  thread
169
196
  end
170
197
  end