aws-sdk-s3 1.36.0 → 1.95.1

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 +5 -5
  2. data/CHANGELOG.md +768 -0
  3. data/LICENSE.txt +202 -0
  4. data/VERSION +1 -0
  5. data/lib/aws-sdk-s3/arn/access_point_arn.rb +69 -0
  6. data/lib/aws-sdk-s3/arn/object_lambda_arn.rb +69 -0
  7. data/lib/aws-sdk-s3/arn/outpost_access_point_arn.rb +73 -0
  8. data/lib/aws-sdk-s3/bucket.rb +277 -76
  9. data/lib/aws-sdk-s3/bucket_acl.rb +40 -15
  10. data/lib/aws-sdk-s3/bucket_cors.rb +50 -14
  11. data/lib/aws-sdk-s3/bucket_lifecycle.rb +33 -14
  12. data/lib/aws-sdk-s3/bucket_lifecycle_configuration.rb +32 -14
  13. data/lib/aws-sdk-s3/bucket_logging.rb +35 -15
  14. data/lib/aws-sdk-s3/bucket_notification.rb +32 -18
  15. data/lib/aws-sdk-s3/bucket_policy.rb +34 -13
  16. data/lib/aws-sdk-s3/bucket_region_cache.rb +2 -0
  17. data/lib/aws-sdk-s3/bucket_request_payment.rb +34 -12
  18. data/lib/aws-sdk-s3/bucket_tagging.rb +42 -14
  19. data/lib/aws-sdk-s3/bucket_versioning.rb +67 -12
  20. data/lib/aws-sdk-s3/bucket_website.rb +49 -17
  21. data/lib/aws-sdk-s3/client.rb +7494 -618
  22. data/lib/aws-sdk-s3/client_api.rb +417 -2
  23. data/lib/aws-sdk-s3/customizations/bucket.rb +59 -16
  24. data/lib/aws-sdk-s3/customizations/multipart_upload.rb +2 -0
  25. data/lib/aws-sdk-s3/customizations/object.rb +125 -60
  26. data/lib/aws-sdk-s3/customizations/object_summary.rb +5 -0
  27. data/lib/aws-sdk-s3/customizations/types/list_object_versions_output.rb +2 -0
  28. data/lib/aws-sdk-s3/customizations.rb +4 -1
  29. data/lib/aws-sdk-s3/encryption/client.rb +22 -5
  30. data/lib/aws-sdk-s3/encryption/decrypt_handler.rb +72 -26
  31. data/lib/aws-sdk-s3/encryption/default_cipher_provider.rb +43 -5
  32. data/lib/aws-sdk-s3/encryption/default_key_provider.rb +2 -0
  33. data/lib/aws-sdk-s3/encryption/encrypt_handler.rb +13 -2
  34. data/lib/aws-sdk-s3/encryption/errors.rb +2 -0
  35. data/lib/aws-sdk-s3/encryption/io_auth_decrypter.rb +2 -0
  36. data/lib/aws-sdk-s3/encryption/io_decrypter.rb +11 -3
  37. data/lib/aws-sdk-s3/encryption/io_encrypter.rb +2 -0
  38. data/lib/aws-sdk-s3/encryption/key_provider.rb +2 -0
  39. data/lib/aws-sdk-s3/encryption/kms_cipher_provider.rb +34 -3
  40. data/lib/aws-sdk-s3/encryption/materials.rb +8 -6
  41. data/lib/aws-sdk-s3/encryption/utils.rb +25 -0
  42. data/lib/aws-sdk-s3/encryption.rb +4 -0
  43. data/lib/aws-sdk-s3/encryptionV2/client.rb +566 -0
  44. data/lib/aws-sdk-s3/encryptionV2/decrypt_handler.rb +226 -0
  45. data/lib/aws-sdk-s3/encryptionV2/default_cipher_provider.rb +170 -0
  46. data/lib/aws-sdk-s3/encryptionV2/default_key_provider.rb +40 -0
  47. data/lib/aws-sdk-s3/encryptionV2/encrypt_handler.rb +69 -0
  48. data/lib/aws-sdk-s3/encryptionV2/errors.rb +37 -0
  49. data/lib/aws-sdk-s3/encryptionV2/io_auth_decrypter.rb +58 -0
  50. data/lib/aws-sdk-s3/encryptionV2/io_decrypter.rb +37 -0
  51. data/lib/aws-sdk-s3/encryptionV2/io_encrypter.rb +73 -0
  52. data/lib/aws-sdk-s3/encryptionV2/key_provider.rb +31 -0
  53. data/lib/aws-sdk-s3/encryptionV2/kms_cipher_provider.rb +169 -0
  54. data/lib/aws-sdk-s3/encryptionV2/materials.rb +60 -0
  55. data/lib/aws-sdk-s3/encryptionV2/utils.rb +103 -0
  56. data/lib/aws-sdk-s3/encryption_v2.rb +23 -0
  57. data/lib/aws-sdk-s3/errors.rb +123 -1
  58. data/lib/aws-sdk-s3/event_streams.rb +15 -8
  59. data/lib/aws-sdk-s3/file_downloader.rb +10 -8
  60. data/lib/aws-sdk-s3/file_part.rb +11 -6
  61. data/lib/aws-sdk-s3/file_uploader.rb +28 -14
  62. data/lib/aws-sdk-s3/legacy_signer.rb +17 -25
  63. data/lib/aws-sdk-s3/multipart_file_uploader.rb +53 -13
  64. data/lib/aws-sdk-s3/multipart_stream_uploader.rb +20 -7
  65. data/lib/aws-sdk-s3/multipart_upload.rb +64 -29
  66. data/lib/aws-sdk-s3/multipart_upload_error.rb +2 -0
  67. data/lib/aws-sdk-s3/multipart_upload_part.rb +115 -42
  68. data/lib/aws-sdk-s3/object.rb +656 -151
  69. data/lib/aws-sdk-s3/object_acl.rb +64 -21
  70. data/lib/aws-sdk-s3/object_copier.rb +2 -0
  71. data/lib/aws-sdk-s3/object_multipart_copier.rb +2 -0
  72. data/lib/aws-sdk-s3/object_summary.rb +474 -138
  73. data/lib/aws-sdk-s3/object_version.rb +122 -58
  74. data/lib/aws-sdk-s3/plugins/accelerate.rb +32 -38
  75. data/lib/aws-sdk-s3/plugins/arn.rb +228 -0
  76. data/lib/aws-sdk-s3/plugins/bucket_dns.rb +7 -7
  77. data/lib/aws-sdk-s3/plugins/bucket_name_restrictions.rb +25 -3
  78. data/lib/aws-sdk-s3/plugins/dualstack.rb +15 -4
  79. data/lib/aws-sdk-s3/plugins/expect_100_continue.rb +4 -4
  80. data/lib/aws-sdk-s3/plugins/get_bucket_location_fix.rb +2 -0
  81. data/lib/aws-sdk-s3/plugins/http_200_errors.rb +11 -3
  82. data/lib/aws-sdk-s3/plugins/iad_regional_endpoint.rb +67 -0
  83. data/lib/aws-sdk-s3/plugins/location_constraint.rb +2 -0
  84. data/lib/aws-sdk-s3/plugins/md5s.rb +30 -28
  85. data/lib/aws-sdk-s3/plugins/object_lambda_endpoint.rb +25 -0
  86. data/lib/aws-sdk-s3/plugins/redirects.rb +2 -0
  87. data/lib/aws-sdk-s3/plugins/s3_host_id.rb +2 -0
  88. data/lib/aws-sdk-s3/plugins/s3_signer.rb +64 -35
  89. data/lib/aws-sdk-s3/plugins/sse_cpk.rb +3 -1
  90. data/lib/aws-sdk-s3/plugins/streaming_retry.rb +118 -0
  91. data/lib/aws-sdk-s3/plugins/url_encoded_keys.rb +2 -0
  92. data/lib/aws-sdk-s3/presigned_post.rb +72 -32
  93. data/lib/aws-sdk-s3/presigner.rb +162 -66
  94. data/lib/aws-sdk-s3/resource.rb +23 -5
  95. data/lib/aws-sdk-s3/types.rb +6441 -952
  96. data/lib/aws-sdk-s3/waiters.rb +67 -1
  97. data/lib/aws-sdk-s3.rb +12 -6
  98. metadata +35 -12
@@ -1,8 +1,25 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'uri'
2
4
 
3
5
  module Aws
4
6
  module S3
5
7
  class Bucket
8
+ # Save the old initialize method so that we can call 'super'.
9
+ old_initialize = instance_method(:initialize)
10
+ # Make the method redefinable
11
+ alias_method :initialize, :initialize
12
+ # Define a new initialize method that extracts out a bucket ARN.
13
+ define_method(:initialize) do |*args|
14
+ old_initialize.bind(self).call(*args)
15
+ resolved_region, arn = Plugins::ARN.resolve_arn!(
16
+ name,
17
+ client.config.region,
18
+ client.config.s3_use_arn_region
19
+ )
20
+ @resolved_region = resolved_region
21
+ @arn = arn
22
+ end
6
23
 
7
24
  # Deletes all objects and versioned objects from this bucket
8
25
  #
@@ -31,10 +48,10 @@ module Aws
31
48
  # each attempt.
32
49
  #
33
50
  # @return [void]
34
- def delete! options = { }
51
+ def delete!(options = {})
35
52
  options = {
36
53
  initial_wait: 1.3,
37
- max_attempts: 3,
54
+ max_attempts: 3
38
55
  }.merge(options)
39
56
 
40
57
  attempts = 0
@@ -43,36 +60,57 @@ module Aws
43
60
  delete
44
61
  rescue Errors::BucketNotEmpty
45
62
  attempts += 1
46
- if attempts >= options[:max_attempts]
47
- raise
48
- else
49
- Kernel.sleep(options[:initial_wait] ** attempts)
50
- retry
51
- end
63
+ raise if attempts >= options[:max_attempts]
64
+
65
+ Kernel.sleep(options[:initial_wait]**attempts)
66
+ retry
52
67
  end
53
68
  end
54
69
 
55
70
  # Returns a public URL for this bucket.
56
71
  #
57
- # bucket = s3.bucket('bucket-name')
58
- # bucket.url
59
- # #=> "https://bucket-name.s3.amazonaws.com"
72
+ # @example
73
+ #
74
+ # bucket = s3.bucket('bucket-name')
75
+ # bucket.url
76
+ # #=> "https://bucket-name.s3.amazonaws.com"
77
+ #
78
+ # It will also work when provided an Access Point ARN.
79
+ #
80
+ # @example
81
+ #
82
+ # bucket = s3.bucket(
83
+ # 'arn:aws:s3:us-east-1:123456789012:accesspoint:myendpoint'
84
+ # )
85
+ # bucket.url
86
+ # #=> "https://myendpoint-123456789012.s3-accesspoint.us-west-2.amazonaws.com"
60
87
  #
61
88
  # You can pass `virtual_host: true` to use the bucket name as the
62
89
  # host name.
63
90
  #
64
- # bucket = s3.bucket('my.bucket.com')
91
+ # bucket = s3.bucket('my-bucket.com')
65
92
  # bucket.url(virtual_host: true)
66
- # #=> "http://my.bucket.com"
93
+ # #=> "http://my-bucket.com"
67
94
  #
68
95
  # @option options [Boolean] :virtual_host (false) When `true`,
69
96
  # the bucket name will be used as the host name. This is useful
70
97
  # when you have a CNAME configured for this bucket.
71
98
  #
99
+ # @option options [Boolean] :secure (true) When `false`, http
100
+ # will be used with virtual_host. This is required when
101
+ # the bucket name has a dot (.) in it.
102
+ #
72
103
  # @return [String] the URL for this bucket.
73
104
  def url(options = {})
74
105
  if options[:virtual_host]
75
- "http://#{name}"
106
+ scheme = options.fetch(:secure, true) ? 'https' : 'http'
107
+ "#{scheme}://#{name}"
108
+ elsif @arn
109
+ Plugins::ARN.resolve_url!(
110
+ client.config.endpoint.dup,
111
+ @arn,
112
+ @resolved_region
113
+ ).to_s
76
114
  else
77
115
  s3_bucket_url
78
116
  end
@@ -93,7 +131,7 @@ module Aws
93
131
  client.config.credentials,
94
132
  client.config.region,
95
133
  name,
96
- {url: url}.merge(options)
134
+ { url: url }.merge(options)
97
135
  )
98
136
  end
99
137
 
@@ -101,6 +139,7 @@ module Aws
101
139
  def load
102
140
  @data = client.list_buckets.buckets.find { |b| b.name == name }
103
141
  raise "unable to load bucket #{name}" if @data.nil?
142
+
104
143
  self
105
144
  end
106
145
 
@@ -114,12 +153,16 @@ module Aws
114
153
  url.path += '/' unless url.path[-1] == '/'
115
154
  url.path += Seahorse::Util.uri_escape(name)
116
155
  end
156
+ if (client.config.region == 'us-east-1') &&
157
+ (client.config.s3_us_east_1_regional_endpoint == 'legacy')
158
+ url.host = Plugins::IADRegionalEndpoint.legacy_host(url.host)
159
+ end
117
160
  url.to_s
118
161
  end
119
162
 
120
163
  def bucket_as_hostname?(https)
121
164
  Plugins::BucketDns.dns_compatible?(name, https) &&
122
- !client.config.force_path_style
165
+ !client.config.force_path_style
123
166
  end
124
167
 
125
168
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Aws
2
4
  module S3
3
5
  class MultipartUpload
@@ -1,14 +1,19 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Aws
2
4
  module S3
3
5
  class Object
4
-
5
6
  alias size content_length
6
7
 
8
+ # Make the method redefinable
9
+ alias_method :copy_from, :copy_from
10
+
7
11
  # Copies another object to this object. Use `multipart_copy: true`
8
12
  # for large objects. This is required for objects that exceed 5GB.
9
13
  #
10
- # @param [S3::Object, S3::ObjectVersion, S3::ObjectSummary, String, Hash] source
11
- # Where to copy object data from. `source` must be one of the following:
14
+ # @param [S3::Object, S3::ObjectVersion, S3::ObjectSummary, String, Hash]
15
+ # source Where to copy object data from. `source` must be one of the
16
+ # following:
12
17
  #
13
18
  # * {Aws::S3::Object}
14
19
  # * {Aws::S3::ObjectSummary}
@@ -25,7 +30,8 @@ module Aws
25
30
  #
26
31
  # @option options [Integer] :content_length Only used when
27
32
  # `:multipart_copy` is `true`. Passing this options avoids a HEAD
28
- # request to query the source object size.
33
+ # request to query the source object size. Raises an `ArgumentError` if
34
+ # this option is provided when `:multipart_copy` is `false` or not set.
29
35
  #
30
36
  # @option options [S3::Client] :copy_source_client Only used when
31
37
  # `:multipart_copy` is `true` and the source object is in a
@@ -103,8 +109,9 @@ module Aws
103
109
  ObjectCopier.new(self, options).copy_to(target, options)
104
110
  end
105
111
 
106
- # Copies and deletes the current object. The object will only be
107
- # deleted if the copy operation succeeds.
112
+ # Copies and deletes the current object. The object will only be deleted
113
+ # if the copy operation succeeds.
114
+ #
108
115
  # @param (see Object#copy_to)
109
116
  # @option (see Object#copy_to)
110
117
  # @return [void]
@@ -129,10 +136,7 @@ module Aws
129
136
  client.config.credentials,
130
137
  client.config.region,
131
138
  bucket_name,
132
- {
133
- key: key,
134
- url: bucket.url,
135
- }.merge(options)
139
+ { key: key, url: bucket.url }.merge(options)
136
140
  )
137
141
  end
138
142
 
@@ -149,21 +153,35 @@ module Aws
149
153
  # obj.presigned_url(:put, acl: 'public-read')
150
154
  # #=> "https://bucket-name.s3.amazonaws.com/object-key?..."
151
155
  #
152
- # @param [Symbol] http_method
153
- # The HTTP method to generate a presigned URL for. Valid values
154
- # are `:get`, `:put`, `:head`, and `:delete`.
156
+ # @example Pre-signed UploadPart PUT
157
+ #
158
+ # # the object uploaded using this URL will be publicly accessible
159
+ # obj.presigned_url(:upload_part, part_number: 1, upload_id: 'uploadIdToken')
160
+ # #=> "https://bucket-name.s3.amazonaws.com/object-key?..."
161
+ #
162
+ # @param [Symbol] method
163
+ # The S3 operation to generate a presigned URL for. Valid values
164
+ # are `:get`, `:put`, `:head`, `:delete`, `:create_multipart_upload`,
165
+ # `:list_multipart_uploads`, `:complete_multipart_upload`,
166
+ # `:abort_multipart_upload`, `:list_parts`, and `:upload_part`.
155
167
  #
156
168
  # @param [Hash] params
157
169
  # Additional request parameters to use when generating the pre-signed
158
170
  # URL. See the related documentation in {Client} for accepted
159
171
  # params.
160
172
  #
161
- # | HTTP Method | Client Method |
162
- # |---------------|------------------------|
163
- # | `:get` | {Client#get_object} |
164
- # | `:put` | {Client#put_object} |
165
- # | `:head` | {Client#head_object} |
166
- # | `:delete` | {Client#delete_object} |
173
+ # | Method | Client Method |
174
+ # |------------------------------|------------------------------------|
175
+ # | `:get` | {Client#get_object} |
176
+ # | `:put` | {Client#put_object} |
177
+ # | `:head` | {Client#head_object} |
178
+ # | `:delete` | {Client#delete_object} |
179
+ # | `:create_multipart_upload` | {Client#create_multipart_upload} |
180
+ # | `:list_multipart_uploads` | {Client#list_multipart_uploads} |
181
+ # | `:complete_multipart_upload` | {Client#complete_multipart_upload} |
182
+ # | `:abort_multipart_upload` | {Client#abort_multipart_upload} |
183
+ # | `:list_parts` | {Client#list_parts} |
184
+ # | `:upload_part` | {Client#upload_part} |
167
185
  #
168
186
  # @option params [Boolean] :virtual_host (false) When `true` the
169
187
  # presigned URL will use the bucket name as a virtual host.
@@ -184,12 +202,17 @@ module Aws
184
202
  #
185
203
  # @return [String]
186
204
  #
187
- def presigned_url(http_method, params = {})
205
+ def presigned_url(method, params = {})
188
206
  presigner = Presigner.new(client: client)
189
- presigner.presigned_url("#{http_method.downcase}_object", params.merge(
190
- bucket: bucket_name,
191
- key: key,
192
- ))
207
+
208
+ if %w(delete head get put).include?(method.to_s)
209
+ method = "#{method}_object".to_sym
210
+ end
211
+
212
+ presigner.presigned_url(
213
+ method.downcase,
214
+ params.merge(bucket: bucket_name, key: key)
215
+ )
193
216
  end
194
217
 
195
218
  # Returns the public (un-signed) URL for this object.
@@ -197,15 +220,22 @@ module Aws
197
220
  # s3.bucket('bucket-name').object('obj-key').public_url
198
221
  # #=> "https://bucket-name.s3.amazonaws.com/obj-key"
199
222
  #
200
- # To use virtual hosted bucket url (disables https):
223
+ # To use virtual hosted bucket url.
224
+ # Uses https unless secure: false is set. If the bucket
225
+ # name contains dots (.) then you will need to set secure: false.
201
226
  #
202
- # s3.bucket('my.bucket.com').object('key').public_url(virtual_host: true)
203
- # #=> "http://my.bucket.com/key"
227
+ # s3.bucket('my-bucket.com').object('key')
228
+ # .public_url(virtual_host: true)
229
+ # #=> "https://my-bucket.com/key"
204
230
  #
205
231
  # @option options [Boolean] :virtual_host (false) When `true`, the bucket
206
232
  # name will be used as the host name. This is useful when you have
207
233
  # a CNAME configured for the bucket.
208
234
  #
235
+ # @option options [Boolean] :secure (true) When `false`, http
236
+ # will be used with virtual_host. This is required when
237
+ # the bucket name has a dot (.) in it.
238
+ #
209
239
  # @return [String]
210
240
  def public_url(options = {})
211
241
  url = URI.parse(bucket.url(options))
@@ -216,11 +246,12 @@ module Aws
216
246
 
217
247
  # Uploads a stream in a streaming fashion to the current object in S3.
218
248
  #
219
- # # Passed chunks automatically split into multipart upload parts
220
- # # and the parts are uploaded in parallel. This allows for streaming uploads
221
- # # that never touch the disk.
249
+ # Passed chunks automatically split into multipart upload parts and the
250
+ # parts are uploaded in parallel. This allows for streaming uploads that
251
+ # never touch the disk.
222
252
  #
223
- # Note that this is known to have issues in JRuby until jruby-9.1.15.0, so avoid using this with older versions of JRuby.
253
+ # Note that this is known to have issues in JRuby until jruby-9.1.15.0,
254
+ # so avoid using this with older versions of JRuby.
224
255
  #
225
256
  # @example Streaming chunks of data
226
257
  # obj.upload_stream do |write_stream|
@@ -235,17 +266,15 @@ module Aws
235
266
  # IO.copy_stream(STDIN, write_stream)
236
267
  # end
237
268
  #
238
- # @option options [Integer] :thread_count
239
- # The number of parallel multipart uploads
240
- # Default `:thread_count` is `10`.
269
+ # @option options [Integer] :thread_count (10) The number of parallel
270
+ # multipart uploads
241
271
  #
242
- # @option options [Boolean] :tempfile
243
- # Normally read data is stored in memory when building the parts in order to complete
244
- # the underlying multipart upload. By passing `:tempfile => true` data read will be
272
+ # @option options [Boolean] :tempfile (false) Normally read data is stored
273
+ # in memory when building the parts in order to complete the underlying
274
+ # multipart upload. By passing `:tempfile => true` data read will be
245
275
  # temporarily stored on disk reducing the memory footprint vastly.
246
- # Default `:tempfile` is `false`.
247
276
  #
248
- # @option options [Integer] :part_size
277
+ # @option options [Integer] :part_size (5242880)
249
278
  # Define how big each part size but the last should be.
250
279
  # Default `:part_size` is `5 * 1024 * 1024`.
251
280
  #
@@ -264,9 +293,12 @@ module Aws
264
293
  client: client,
265
294
  thread_count: uploading_options.delete(:thread_count),
266
295
  tempfile: uploading_options.delete(:tempfile),
267
- part_size: uploading_options.delete(:part_size),
296
+ part_size: uploading_options.delete(:part_size)
297
+ )
298
+ uploader.upload(
299
+ uploading_options.merge(bucket: bucket_name, key: key),
300
+ &block
268
301
  )
269
- uploader.upload(uploading_options.merge(bucket: bucket_name, key: key), &block)
270
302
  true
271
303
  end
272
304
 
@@ -275,22 +307,49 @@ module Aws
275
307
  # # small files are uploaded in a single API call
276
308
  # obj.upload_file('/path/to/file')
277
309
  #
278
- # Files larger than `:multipart_threshold` are uploaded using the
279
- # Amazon S3 multipart upload APIs.
310
+ # Files larger than or equal to `:multipart_threshold` are uploaded
311
+ # using the Amazon S3 multipart upload APIs.
280
312
  #
281
313
  # # large files are automatically split into parts
282
314
  # # and the parts are uploaded in parallel
283
315
  # obj.upload_file('/path/to/very_large_file')
284
316
  #
285
- # @param [String,Pathname,File,Tempfile] source A file or path to a file
286
- # on the local file system that should be uploaded to this object.
287
- # If you pass an open file object, then it is your responsibility
288
- # to close the file object once the upload completes.
317
+ # The response of the S3 upload API is yielded if a block given.
318
+ #
319
+ # # API response will have etag value of the file
320
+ # obj.upload_file('/path/to/file') do |response|
321
+ # etag = response.etag
322
+ # end
323
+ #
324
+ # You can provide a callback to monitor progress of the upload:
325
+ #
326
+ # # bytes and totals are each an array with 1 entry per part
327
+ # progress = Proc.new do |bytes, totals|
328
+ # puts bytes.map.with_index { |b, i| "Part #{i+1}: #{b} / #{totals[i]}"}.join(' ') + "Total: #{100.0 * bytes.sum / totals.sum }%" }
329
+ # end
330
+ # obj.upload_file('/path/to/file')
331
+ #
332
+ # @param [String, Pathname, File, Tempfile] source A file on the local
333
+ # file system that will be uploaded as this object. This can either be
334
+ # a String or Pathname to the file, an open File object, or an open
335
+ # Tempfile object. If you pass an open File or Tempfile object, then
336
+ # you are responsible for closing it after the upload completes. When
337
+ # using an open Tempfile, rewind it before uploading or else the object
338
+ # will be empty.
289
339
  #
290
340
  # @option options [Integer] :multipart_threshold (15728640) Files larger
291
- # than `:multipart_threshold` are uploaded using the S3 multipart APIs.
341
+ # than or equal to `:multipart_threshold` are uploaded using the S3
342
+ # multipart APIs.
292
343
  # Default threshold is 15MB.
293
344
  #
345
+ # @option options [Integer] :thread_count (10) The number of parallel
346
+ # multipart uploads. This option is not used if the file is smaller than
347
+ # `:multipart_threshold`.
348
+ #
349
+ # @option options [Proc] :progress_callback
350
+ # A Proc that will be called when each chunk of the upload is sent.
351
+ # It will be invoked with [bytes_read], [total_sizes]
352
+ #
294
353
  # @raise [MultipartUploadError] If an object is being uploaded in
295
354
  # parts, and the upload can not be completed, then the upload is
296
355
  # aborted and this error is raised. The raised error has a `#errors`
@@ -299,13 +358,17 @@ module Aws
299
358
  #
300
359
  # @return [Boolean] Returns `true` when the object is uploaded
301
360
  # without any errors.
302
- #
303
361
  def upload_file(source, options = {})
304
362
  uploading_options = options.dup
305
363
  uploader = FileUploader.new(
306
364
  multipart_threshold: uploading_options.delete(:multipart_threshold),
307
- client: client)
308
- uploader.upload(source, uploading_options.merge(bucket: bucket_name, key: key))
365
+ client: client
366
+ )
367
+ response = uploader.upload(
368
+ source,
369
+ uploading_options.merge(bucket: bucket_name, key: key)
370
+ )
371
+ yield response if block_given?
309
372
  true
310
373
  end
311
374
 
@@ -320,7 +383,7 @@ module Aws
320
383
  # # and the parts are downloaded in parallel
321
384
  # obj.download_file('/path/to/very_large_file')
322
385
  #
323
- # @param [String] destination Where to download the file to
386
+ # @param [String] destination Where to download the file to.
324
387
  #
325
388
  # @option options [String] mode `auto`, `single_request`, `get_range`
326
389
  # `single_request` mode forces only 1 GET request is made in download,
@@ -328,21 +391,23 @@ module Aws
328
391
  # customizing each range size in multipart_download,
329
392
  # By default, `auto` mode is enabled, which performs multipart_download
330
393
  #
331
- # @option options [String] chunk_size required in get_range mode
394
+ # @option options [String] chunk_size required in get_range mode.
332
395
  #
333
- # @option options [String] thread_count Customize threads used in multipart
334
- # download, if not provided, 10 is default value
396
+ # @option options [Integer] thread_count (10) Customize threads used in
397
+ # the multipart download.
335
398
  #
336
- # @option options [String] version_id The object version id used to retrieve
337
- # the object, to know more about object versioning, see:
399
+ # @option options [String] version_id The object version id used to
400
+ # retrieve the object. For more about object versioning, see:
338
401
  # https://docs.aws.amazon.com/AmazonS3/latest/dev/ObjectVersioning.html
339
402
  #
340
- # @return [Boolean] Returns `true` when the file is downloaded
341
- # without any errors.
403
+ # @return [Boolean] Returns `true` when the file is downloaded without
404
+ # any errors.
342
405
  def download_file(destination, options = {})
343
406
  downloader = FileDownloader.new(client: client)
344
407
  downloader.download(
345
- destination, options.merge(bucket: bucket_name, key: key))
408
+ destination,
409
+ options.merge(bucket: bucket_name, key: key)
410
+ )
346
411
  true
347
412
  end
348
413
  end
@@ -1,9 +1,14 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Aws
2
4
  module S3
3
5
  class ObjectSummary
4
6
 
5
7
  alias content_length size
6
8
 
9
+ # Make the method redefinable
10
+ alias_method :copy_from, :copy_from
11
+
7
12
  # @param (see Object#copy_from)
8
13
  # @options (see Object#copy_from)
9
14
  # @return (see Object#copy_from)
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class Aws::S3::Types::ListObjectVersionsOutput
2
4
 
3
5
  # TODO : Remove this customization once the resource code
@@ -1,6 +1,9 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # utility classes
2
4
  require 'aws-sdk-s3/bucket_region_cache'
3
5
  require 'aws-sdk-s3/encryption'
6
+ require 'aws-sdk-s3/encryption_v2'
4
7
  require 'aws-sdk-s3/file_part'
5
8
  require 'aws-sdk-s3/file_uploader'
6
9
  require 'aws-sdk-s3/file_downloader'
@@ -26,6 +29,6 @@ require 'aws-sdk-s3/customizations/types/list_object_versions_output'
26
29
  Aws::S3::ObjectVersion::Collection,
27
30
  ].each do |klass|
28
31
  klass.send(:alias_method, :delete, :batch_delete!)
29
- klass.send(:extend, Aws::Deprecations)
32
+ klass.extend Aws::Deprecations
30
33
  klass.send(:deprecated, :delete, use: :batch_delete!)
31
34
  end
@@ -1,6 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'forwardable'
4
+
1
5
  module Aws
2
6
  module S3
3
7
 
8
+ # [MAINTENANCE MODE] There is a new version of the Encryption Client.
9
+ # AWS strongly recommends upgrading to the {Aws::S3::EncryptionV2::Client},
10
+ # which provides updated data security best practices.
11
+ # See documentation for {Aws::S3::EncryptionV2::Client}.
4
12
  # Provides an encryption client that encrypts and decrypts data client-side,
5
13
  # storing the encrypted data in Amazon S3.
6
14
  #
@@ -178,8 +186,10 @@ module Aws
178
186
  class Client
179
187
 
180
188
  extend Deprecations
189
+ extend Forwardable
190
+ def_delegators :@client, :config, :delete_object, :head_object, :build_request
181
191
 
182
- # Creates a new encryption client. You must provide on of the following
192
+ # Creates a new encryption client. You must provide one of the following
183
193
  # options:
184
194
  #
185
195
  # * `:encryption_key`
@@ -223,6 +233,13 @@ module Aws
223
233
  @envelope_location = extract_location(options)
224
234
  @instruction_file_suffix = extract_suffix(options)
225
235
  end
236
+ deprecated :initialize,
237
+ message:
238
+ '[MAINTENANCE MODE] This version of the S3 Encryption client is currently in maintenance mode. ' \
239
+ 'AWS strongly recommends upgrading to the Aws::S3::EncryptionV2::Client, ' \
240
+ 'which provides updated data security best practices. ' \
241
+ 'See documentation for Aws::S3::EncryptionV2::Client.'
242
+
226
243
 
227
244
  # @return [S3::Client]
228
245
  attr_reader :client
@@ -327,7 +344,7 @@ module Aws
327
344
  elsif options[:encryption_key]
328
345
  DefaultKeyProvider.new(options)
329
346
  else
330
- msg = "you must pass a :kms_key_id, :key_provider, or :encryption_key"
347
+ msg = 'you must pass a :kms_key_id, :key_provider, or :encryption_key'
331
348
  raise ArgumentError, msg
332
349
  end
333
350
  end
@@ -347,8 +364,8 @@ module Aws
347
364
  if [:metadata, :instruction_file].include?(location)
348
365
  location
349
366
  else
350
- msg = ":envelope_location must be :metadata or :instruction_file "
351
- msg << "got #{location.inspect}"
367
+ msg = ':envelope_location must be :metadata or :instruction_file '\
368
+ "got #{location.inspect}"
352
369
  raise ArgumentError, msg
353
370
  end
354
371
  end
@@ -358,7 +375,7 @@ module Aws
358
375
  if String === suffix
359
376
  suffix
360
377
  else
361
- msg = ":instruction_file_suffix must be a String"
378
+ msg = ':instruction_file_suffix must be a String'
362
379
  raise ArgumentError, msg
363
380
  end
364
381
  end