aws-sdk-s3 1.21.0 → 1.117.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (99) hide show
  1. checksums.yaml +5 -5
  2. data/CHANGELOG.md +930 -0
  3. data/LICENSE.txt +202 -0
  4. data/VERSION +1 -0
  5. data/lib/aws-sdk-s3/bucket.rb +393 -75
  6. data/lib/aws-sdk-s3/bucket_acl.rb +57 -14
  7. data/lib/aws-sdk-s3/bucket_cors.rb +67 -13
  8. data/lib/aws-sdk-s3/bucket_lifecycle.rb +54 -15
  9. data/lib/aws-sdk-s3/bucket_lifecycle_configuration.rb +56 -15
  10. data/lib/aws-sdk-s3/bucket_logging.rb +52 -15
  11. data/lib/aws-sdk-s3/bucket_notification.rb +47 -17
  12. data/lib/aws-sdk-s3/bucket_policy.rb +51 -13
  13. data/lib/aws-sdk-s3/bucket_region_cache.rb +2 -0
  14. data/lib/aws-sdk-s3/bucket_request_payment.rb +51 -12
  15. data/lib/aws-sdk-s3/bucket_tagging.rb +59 -13
  16. data/lib/aws-sdk-s3/bucket_versioning.rb +118 -12
  17. data/lib/aws-sdk-s3/bucket_website.rb +66 -13
  18. data/lib/aws-sdk-s3/client.rb +11422 -2518
  19. data/lib/aws-sdk-s3/client_api.rb +1196 -155
  20. data/lib/aws-sdk-s3/customizations/bucket.rb +53 -36
  21. data/lib/aws-sdk-s3/customizations/multipart_upload.rb +2 -0
  22. data/lib/aws-sdk-s3/customizations/object.rb +200 -62
  23. data/lib/aws-sdk-s3/customizations/object_summary.rb +5 -0
  24. data/lib/aws-sdk-s3/customizations/types/list_object_versions_output.rb +2 -0
  25. data/lib/aws-sdk-s3/customizations.rb +4 -1
  26. data/lib/aws-sdk-s3/encryption/client.rb +23 -6
  27. data/lib/aws-sdk-s3/encryption/decrypt_handler.rb +71 -29
  28. data/lib/aws-sdk-s3/encryption/default_cipher_provider.rb +43 -5
  29. data/lib/aws-sdk-s3/encryption/default_key_provider.rb +2 -0
  30. data/lib/aws-sdk-s3/encryption/encrypt_handler.rb +13 -2
  31. data/lib/aws-sdk-s3/encryption/errors.rb +2 -0
  32. data/lib/aws-sdk-s3/encryption/io_auth_decrypter.rb +11 -3
  33. data/lib/aws-sdk-s3/encryption/io_decrypter.rb +11 -3
  34. data/lib/aws-sdk-s3/encryption/io_encrypter.rb +2 -0
  35. data/lib/aws-sdk-s3/encryption/key_provider.rb +2 -0
  36. data/lib/aws-sdk-s3/encryption/kms_cipher_provider.rb +34 -3
  37. data/lib/aws-sdk-s3/encryption/materials.rb +8 -6
  38. data/lib/aws-sdk-s3/encryption/utils.rb +25 -0
  39. data/lib/aws-sdk-s3/encryption.rb +4 -0
  40. data/lib/aws-sdk-s3/encryptionV2/client.rb +566 -0
  41. data/lib/aws-sdk-s3/encryptionV2/decrypt_handler.rb +222 -0
  42. data/lib/aws-sdk-s3/encryptionV2/default_cipher_provider.rb +170 -0
  43. data/lib/aws-sdk-s3/encryptionV2/default_key_provider.rb +40 -0
  44. data/lib/aws-sdk-s3/encryptionV2/encrypt_handler.rb +65 -0
  45. data/lib/aws-sdk-s3/encryptionV2/errors.rb +37 -0
  46. data/lib/aws-sdk-s3/encryptionV2/io_auth_decrypter.rb +58 -0
  47. data/lib/aws-sdk-s3/encryptionV2/io_decrypter.rb +37 -0
  48. data/lib/aws-sdk-s3/encryptionV2/io_encrypter.rb +73 -0
  49. data/lib/aws-sdk-s3/encryptionV2/key_provider.rb +31 -0
  50. data/lib/aws-sdk-s3/encryptionV2/kms_cipher_provider.rb +169 -0
  51. data/lib/aws-sdk-s3/encryptionV2/materials.rb +60 -0
  52. data/lib/aws-sdk-s3/encryptionV2/utils.rb +103 -0
  53. data/lib/aws-sdk-s3/encryption_v2.rb +23 -0
  54. data/lib/aws-sdk-s3/endpoint_parameters.rb +142 -0
  55. data/lib/aws-sdk-s3/endpoint_provider.rb +2020 -0
  56. data/lib/aws-sdk-s3/endpoints.rb +2149 -0
  57. data/lib/aws-sdk-s3/errors.rb +123 -1
  58. data/lib/aws-sdk-s3/event_streams.rb +20 -7
  59. data/lib/aws-sdk-s3/file_downloader.rb +17 -10
  60. data/lib/aws-sdk-s3/file_part.rb +11 -6
  61. data/lib/aws-sdk-s3/file_uploader.rb +33 -14
  62. data/lib/aws-sdk-s3/legacy_signer.rb +17 -25
  63. data/lib/aws-sdk-s3/multipart_file_uploader.rb +78 -19
  64. data/lib/aws-sdk-s3/multipart_stream_uploader.rb +54 -15
  65. data/lib/aws-sdk-s3/multipart_upload.rb +178 -28
  66. data/lib/aws-sdk-s3/multipart_upload_error.rb +2 -0
  67. data/lib/aws-sdk-s3/multipart_upload_part.rb +237 -44
  68. data/lib/aws-sdk-s3/object.rb +897 -154
  69. data/lib/aws-sdk-s3/object_acl.rb +81 -20
  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 +649 -139
  73. data/lib/aws-sdk-s3/object_version.rb +167 -65
  74. data/lib/aws-sdk-s3/plugins/accelerate.rb +17 -64
  75. data/lib/aws-sdk-s3/plugins/arn.rb +70 -0
  76. data/lib/aws-sdk-s3/plugins/bucket_dns.rb +7 -43
  77. data/lib/aws-sdk-s3/plugins/bucket_name_restrictions.rb +20 -3
  78. data/lib/aws-sdk-s3/plugins/dualstack.rb +7 -50
  79. data/lib/aws-sdk-s3/plugins/endpoints.rb +262 -0
  80. data/lib/aws-sdk-s3/plugins/expect_100_continue.rb +5 -4
  81. data/lib/aws-sdk-s3/plugins/get_bucket_location_fix.rb +3 -1
  82. data/lib/aws-sdk-s3/plugins/http_200_errors.rb +11 -3
  83. data/lib/aws-sdk-s3/plugins/iad_regional_endpoint.rb +44 -0
  84. data/lib/aws-sdk-s3/plugins/location_constraint.rb +2 -0
  85. data/lib/aws-sdk-s3/plugins/md5s.rb +34 -27
  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 +55 -92
  89. data/lib/aws-sdk-s3/plugins/skip_whole_multipart_get_checksums.rb +31 -0
  90. data/lib/aws-sdk-s3/plugins/sse_cpk.rb +3 -1
  91. data/lib/aws-sdk-s3/plugins/streaming_retry.rb +139 -0
  92. data/lib/aws-sdk-s3/plugins/url_encoded_keys.rb +2 -0
  93. data/lib/aws-sdk-s3/presigned_post.rb +108 -56
  94. data/lib/aws-sdk-s3/presigner.rb +169 -77
  95. data/lib/aws-sdk-s3/resource.rb +45 -5
  96. data/lib/aws-sdk-s3/types.rb +8564 -3891
  97. data/lib/aws-sdk-s3/waiters.rb +67 -1
  98. data/lib/aws-sdk-s3.rb +16 -6
  99. metadata +37 -13
@@ -1,9 +1,10 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'uri'
2
4
 
3
5
  module Aws
4
6
  module S3
5
7
  class Bucket
6
-
7
8
  # Deletes all objects and versioned objects from this bucket
8
9
  #
9
10
  # @example
@@ -31,10 +32,10 @@ module Aws
31
32
  # each attempt.
32
33
  #
33
34
  # @return [void]
34
- def delete! options = { }
35
+ def delete!(options = {})
35
36
  options = {
36
37
  initial_wait: 1.3,
37
- max_attempts: 3,
38
+ max_attempts: 3
38
39
  }.merge(options)
39
40
 
40
41
  attempts = 0
@@ -43,38 +44,72 @@ module Aws
43
44
  delete
44
45
  rescue Errors::BucketNotEmpty
45
46
  attempts += 1
46
- if attempts >= options[:max_attempts]
47
- raise
48
- else
49
- Kernel.sleep(options[:initial_wait] ** attempts)
50
- retry
51
- end
47
+ raise if attempts >= options[:max_attempts]
48
+
49
+ Kernel.sleep(options[:initial_wait]**attempts)
50
+ retry
52
51
  end
53
52
  end
54
53
 
55
54
  # Returns a public URL for this bucket.
56
55
  #
57
- # bucket = s3.bucket('bucket-name')
58
- # bucket.url
59
- # #=> "https://bucket-name.s3.amazonaws.com"
56
+ # @example
57
+ #
58
+ # bucket = s3.bucket('bucket-name')
59
+ # bucket.url
60
+ # #=> "https://bucket-name.s3.amazonaws.com"
61
+ #
62
+ # It will also work when provided an Access Point ARN.
63
+ #
64
+ # @example
65
+ #
66
+ # bucket = s3.bucket(
67
+ # 'arn:aws:s3:us-east-1:123456789012:accesspoint:myendpoint'
68
+ # )
69
+ # bucket.url
70
+ # #=> "https://myendpoint-123456789012.s3-accesspoint.us-west-2.amazonaws.com"
60
71
  #
61
72
  # You can pass `virtual_host: true` to use the bucket name as the
62
73
  # host name.
63
74
  #
64
- # bucket = s3.bucket('my.bucket.com')
75
+ # bucket = s3.bucket('my-bucket.com')
65
76
  # bucket.url(virtual_host: true)
66
- # #=> "http://my.bucket.com"
77
+ # #=> "http://my-bucket.com"
67
78
  #
68
79
  # @option options [Boolean] :virtual_host (false) When `true`,
69
80
  # the bucket name will be used as the host name. This is useful
70
81
  # when you have a CNAME configured for this bucket.
71
82
  #
83
+ # @option options [Boolean] :secure (true) When `false`, http
84
+ # will be used with virtual_host. This is required when
85
+ # the bucket name has a dot (.) in it.
86
+ #
72
87
  # @return [String] the URL for this bucket.
73
88
  def url(options = {})
74
89
  if options[:virtual_host]
75
- "http://#{name}"
90
+ scheme = options.fetch(:secure, true) ? 'https' : 'http'
91
+ "#{scheme}://#{name}"
76
92
  else
77
- s3_bucket_url
93
+ # Taken from Aws::S3::Endpoints module
94
+ unless client.config.regional_endpoint
95
+ endpoint = client.config.endpoint.to_s
96
+ end
97
+ params = Aws::S3::EndpointParameters.new(
98
+ bucket: name,
99
+ region: client.config.region,
100
+ use_fips: client.config.use_fips_endpoint,
101
+ use_dual_stack: client.config.use_dualstack_endpoint,
102
+ endpoint: endpoint,
103
+ force_path_style: client.config.force_path_style,
104
+ accelerate: client.config.use_accelerate_endpoint,
105
+ use_global_endpoint: client.config.s3_us_east_1_regional_endpoint == 'legacy',
106
+ use_object_lambda_endpoint: nil,
107
+ disable_access_points: nil,
108
+ disable_multi_region_access_points: client.config.s3_disable_multiregion_access_points,
109
+ use_arn_region: client.config.s3_use_arn_region,
110
+ )
111
+ endpoint = Aws::S3::EndpointProvider.new.resolve_endpoint(params)
112
+ endpoint.url
78
113
  end
79
114
  end
80
115
 
@@ -93,7 +128,7 @@ module Aws
93
128
  client.config.credentials,
94
129
  client.config.region,
95
130
  name,
96
- {url: url}.merge(options)
131
+ { url: url }.merge(options)
97
132
  )
98
133
  end
99
134
 
@@ -101,27 +136,9 @@ module Aws
101
136
  def load
102
137
  @data = client.list_buckets.buckets.find { |b| b.name == name }
103
138
  raise "unable to load bucket #{name}" if @data.nil?
104
- self
105
- end
106
-
107
- private
108
-
109
- def s3_bucket_url
110
- url = client.config.endpoint.dup
111
- if bucket_as_hostname?(url.scheme == 'https')
112
- url.host = "#{name}.#{url.host}"
113
- else
114
- url.path += '/' unless url.path[-1] == '/'
115
- url.path += Seahorse::Util.uri_escape(name)
116
- end
117
- url.to_s
118
- end
119
139
 
120
- def bucket_as_hostname?(https)
121
- Plugins::BucketDns.dns_compatible?(name, https) &&
122
- !client.config.force_path_style
140
+ self
123
141
  end
124
-
125
142
  end
126
143
  end
127
144
  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,90 @@ module Aws
184
202
  #
185
203
  # @return [String]
186
204
  #
187
- def presigned_url(http_method, params = {})
205
+ def presigned_url(method, params = {})
206
+ presigner = Presigner.new(client: client)
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
+ )
216
+ end
217
+
218
+ # Allows you to create presigned URL requests for S3 operations. This
219
+ # method returns a tuple containing the URL and the signed X-amz-* headers
220
+ # to be used with the presigned url.
221
+ #
222
+ # @example Pre-signed GET URL, valid for one hour
223
+ #
224
+ # obj.presigned_request(:get, expires_in: 3600)
225
+ # #=> ["https://bucket-name.s3.amazonaws.com/object-key?...", {}]
226
+ #
227
+ # @example Pre-signed PUT with a canned ACL
228
+ #
229
+ # # the object uploaded using this URL will be publicly accessible
230
+ # obj.presigned_request(:put, acl: 'public-read')
231
+ # #=> ["https://bucket-name.s3.amazonaws.com/object-key?...",
232
+ # {"x-amz-acl"=>"public-read"}]
233
+ #
234
+ # @param [Symbol] method
235
+ # The S3 operation to generate a presigned request for. Valid values
236
+ # are `:get`, `:put`, `:head`, `:delete`, `:create_multipart_upload`,
237
+ # `:list_multipart_uploads`, `:complete_multipart_upload`,
238
+ # `:abort_multipart_upload`, `:list_parts`, and `:upload_part`.
239
+ #
240
+ # @param [Hash] params
241
+ # Additional request parameters to use when generating the pre-signed
242
+ # request. See the related documentation in {Client} for accepted
243
+ # params.
244
+ #
245
+ # | Method | Client Method |
246
+ # |------------------------------|------------------------------------|
247
+ # | `:get` | {Client#get_object} |
248
+ # | `:put` | {Client#put_object} |
249
+ # | `:head` | {Client#head_object} |
250
+ # | `:delete` | {Client#delete_object} |
251
+ # | `:create_multipart_upload` | {Client#create_multipart_upload} |
252
+ # | `:list_multipart_uploads` | {Client#list_multipart_uploads} |
253
+ # | `:complete_multipart_upload` | {Client#complete_multipart_upload} |
254
+ # | `:abort_multipart_upload` | {Client#abort_multipart_upload} |
255
+ # | `:list_parts` | {Client#list_parts} |
256
+ # | `:upload_part` | {Client#upload_part} |
257
+ #
258
+ # @option params [Boolean] :virtual_host (false) When `true` the
259
+ # presigned URL will use the bucket name as a virtual host.
260
+ #
261
+ # bucket = Aws::S3::Bucket.new('my.bucket.com')
262
+ # bucket.object('key').presigned_request(virtual_host: true)
263
+ # #=> ["http://my.bucket.com/key?...", {}]
264
+ #
265
+ # @option params [Integer] :expires_in (900) Number of seconds before
266
+ # the pre-signed URL expires. This may not exceed one week (604800
267
+ # seconds). Note that the pre-signed URL is also only valid as long as
268
+ # credentials used to sign it are. For example, when using IAM roles,
269
+ # temporary tokens generated for signing also have a default expiration
270
+ # which will affect the effective expiration of the pre-signed URL.
271
+ #
272
+ # @raise [ArgumentError] Raised if `:expires_in` exceeds one week
273
+ # (604800 seconds).
274
+ #
275
+ # @return [String, Hash] A tuple with a presigned URL and headers that
276
+ # should be included with the request.
277
+ #
278
+ def presigned_request(method, params = {})
188
279
  presigner = Presigner.new(client: client)
189
- presigner.presigned_url("#{http_method.downcase}_object", params.merge(
190
- bucket: bucket_name,
191
- key: key,
192
- ))
280
+
281
+ if %w(delete head get put).include?(method.to_s)
282
+ method = "#{method}_object".to_sym
283
+ end
284
+
285
+ presigner.presigned_request(
286
+ method.downcase,
287
+ params.merge(bucket: bucket_name, key: key)
288
+ )
193
289
  end
194
290
 
195
291
  # Returns the public (un-signed) URL for this object.
@@ -197,15 +293,22 @@ module Aws
197
293
  # s3.bucket('bucket-name').object('obj-key').public_url
198
294
  # #=> "https://bucket-name.s3.amazonaws.com/obj-key"
199
295
  #
200
- # To use virtual hosted bucket url (disables https):
296
+ # To use virtual hosted bucket url.
297
+ # Uses https unless secure: false is set. If the bucket
298
+ # name contains dots (.) then you will need to set secure: false.
201
299
  #
202
- # s3.bucket('my.bucket.com').object('key').public_url(virtual_host: true)
203
- # #=> "http://my.bucket.com/key"
300
+ # s3.bucket('my-bucket.com').object('key')
301
+ # .public_url(virtual_host: true)
302
+ # #=> "https://my-bucket.com/key"
204
303
  #
205
304
  # @option options [Boolean] :virtual_host (false) When `true`, the bucket
206
305
  # name will be used as the host name. This is useful when you have
207
306
  # a CNAME configured for the bucket.
208
307
  #
308
+ # @option options [Boolean] :secure (true) When `false`, http
309
+ # will be used with virtual_host. This is required when
310
+ # the bucket name has a dot (.) in it.
311
+ #
209
312
  # @return [String]
210
313
  def public_url(options = {})
211
314
  url = URI.parse(bucket.url(options))
@@ -216,11 +319,12 @@ module Aws
216
319
 
217
320
  # Uploads a stream in a streaming fashion to the current object in S3.
218
321
  #
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.
322
+ # Passed chunks automatically split into multipart upload parts and the
323
+ # parts are uploaded in parallel. This allows for streaming uploads that
324
+ # never touch the disk.
222
325
  #
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.
326
+ # Note that this is known to have issues in JRuby until jruby-9.1.15.0,
327
+ # so avoid using this with older versions of JRuby.
224
328
  #
225
329
  # @example Streaming chunks of data
226
330
  # obj.upload_stream do |write_stream|
@@ -235,17 +339,15 @@ module Aws
235
339
  # IO.copy_stream(STDIN, write_stream)
236
340
  # end
237
341
  #
238
- # @option options [Integer] :thread_count
239
- # The number of parallel multipart uploads
240
- # Default `:thread_count` is `10`.
342
+ # @option options [Integer] :thread_count (10) The number of parallel
343
+ # multipart uploads
241
344
  #
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
345
+ # @option options [Boolean] :tempfile (false) Normally read data is stored
346
+ # in memory when building the parts in order to complete the underlying
347
+ # multipart upload. By passing `:tempfile => true` data read will be
245
348
  # temporarily stored on disk reducing the memory footprint vastly.
246
- # Default `:tempfile` is `false`.
247
349
  #
248
- # @option options [Integer] :part_size
350
+ # @option options [Integer] :part_size (5242880)
249
351
  # Define how big each part size but the last should be.
250
352
  # Default `:part_size` is `5 * 1024 * 1024`.
251
353
  #
@@ -264,9 +366,12 @@ module Aws
264
366
  client: client,
265
367
  thread_count: uploading_options.delete(:thread_count),
266
368
  tempfile: uploading_options.delete(:tempfile),
267
- part_size: uploading_options.delete(:part_size),
369
+ part_size: uploading_options.delete(:part_size)
370
+ )
371
+ uploader.upload(
372
+ uploading_options.merge(bucket: bucket_name, key: key),
373
+ &block
268
374
  )
269
- uploader.upload(uploading_options.merge(bucket: bucket_name, key: key), &block)
270
375
  true
271
376
  end
272
377
 
@@ -275,21 +380,48 @@ module Aws
275
380
  # # small files are uploaded in a single API call
276
381
  # obj.upload_file('/path/to/file')
277
382
  #
278
- # Files larger than `:multipart_threshold` are uploaded using the
279
- # Amazon S3 multipart upload APIs.
383
+ # Files larger than or equal to `:multipart_threshold` are uploaded
384
+ # using the Amazon S3 multipart upload APIs.
280
385
  #
281
386
  # # large files are automatically split into parts
282
387
  # # and the parts are uploaded in parallel
283
388
  # obj.upload_file('/path/to/very_large_file')
284
389
  #
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.
390
+ # The response of the S3 upload API is yielded if a block given.
391
+ #
392
+ # # API response will have etag value of the file
393
+ # obj.upload_file('/path/to/file') do |response|
394
+ # etag = response.etag
395
+ # end
396
+ #
397
+ # You can provide a callback to monitor progress of the upload:
398
+ #
399
+ # # bytes and totals are each an array with 1 entry per part
400
+ # progress = Proc.new do |bytes, totals|
401
+ # puts bytes.map.with_index { |b, i| "Part #{i+1}: #{b} / #{totals[i]}"}.join(' ') + "Total: #{100.0 * bytes.sum / totals.sum }%" }
402
+ # end
403
+ # obj.upload_file('/path/to/file', progress_callback: progress)
404
+ #
405
+ # @param [String, Pathname, File, Tempfile] source A file on the local
406
+ # file system that will be uploaded as this object. This can either be
407
+ # a String or Pathname to the file, an open File object, or an open
408
+ # Tempfile object. If you pass an open File or Tempfile object, then
409
+ # you are responsible for closing it after the upload completes. When
410
+ # using an open Tempfile, rewind it before uploading or else the object
411
+ # will be empty.
412
+ #
413
+ # @option options [Integer] :multipart_threshold (104857600) Files larger
414
+ # than or equal to `:multipart_threshold` are uploaded using the S3
415
+ # multipart APIs.
416
+ # Default threshold is 100MB.
289
417
  #
290
- # @option options [Integer] :multipart_threshold (15728640) Files larger
291
- # than `:multipart_threshold` are uploaded using the S3 multipart APIs.
292
- # Default threshold is 15MB.
418
+ # @option options [Integer] :thread_count (10) The number of parallel
419
+ # multipart uploads. This option is not used if the file is smaller than
420
+ # `:multipart_threshold`.
421
+ #
422
+ # @option options [Proc] :progress_callback
423
+ # A Proc that will be called when each chunk of the upload is sent.
424
+ # It will be invoked with [bytes_read], [total_sizes]
293
425
  #
294
426
  # @raise [MultipartUploadError] If an object is being uploaded in
295
427
  # parts, and the upload can not be completed, then the upload is
@@ -299,13 +431,17 @@ module Aws
299
431
  #
300
432
  # @return [Boolean] Returns `true` when the object is uploaded
301
433
  # without any errors.
302
- #
303
434
  def upload_file(source, options = {})
304
435
  uploading_options = options.dup
305
436
  uploader = FileUploader.new(
306
437
  multipart_threshold: uploading_options.delete(:multipart_threshold),
307
- client: client)
308
- uploader.upload(source, uploading_options.merge(bucket: bucket_name, key: key))
438
+ client: client
439
+ )
440
+ response = uploader.upload(
441
+ source,
442
+ uploading_options.merge(bucket: bucket_name, key: key)
443
+ )
444
+ yield response if block_given?
309
445
  true
310
446
  end
311
447
 
@@ -320,7 +456,7 @@ module Aws
320
456
  # # and the parts are downloaded in parallel
321
457
  # obj.download_file('/path/to/very_large_file')
322
458
  #
323
- # @param [String] destination Where to download the file to
459
+ # @param [String] destination Where to download the file to.
324
460
  #
325
461
  # @option options [String] mode `auto`, `single_request`, `get_range`
326
462
  # `single_request` mode forces only 1 GET request is made in download,
@@ -328,21 +464,23 @@ module Aws
328
464
  # customizing each range size in multipart_download,
329
465
  # By default, `auto` mode is enabled, which performs multipart_download
330
466
  #
331
- # @option options [String] chunk_size required in get_range mode
467
+ # @option options [Integer] chunk_size required in get_range mode.
332
468
  #
333
- # @option options [String] thread_count Customize threads used in multipart
334
- # download, if not provided, 10 is default value
469
+ # @option options [Integer] thread_count (10) Customize threads used in
470
+ # the multipart download.
335
471
  #
336
- # @option options [String] version_id The object version id used to retrieve
337
- # the object, to know more about object versioning, see:
472
+ # @option options [String] version_id The object version id used to
473
+ # retrieve the object. For more about object versioning, see:
338
474
  # https://docs.aws.amazon.com/AmazonS3/latest/dev/ObjectVersioning.html
339
475
  #
340
- # @return [Boolean] Returns `true` when the file is downloaded
341
- # without any errors.
476
+ # @return [Boolean] Returns `true` when the file is downloaded without
477
+ # any errors.
342
478
  def download_file(destination, options = {})
343
479
  downloader = FileDownloader.new(client: client)
344
480
  downloader.download(
345
- destination, options.merge(bucket: bucket_name, key: key))
481
+ destination,
482
+ options.merge(bucket: bucket_name, key: key)
483
+ )
346
484
  true
347
485
  end
348
486
  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
  #
@@ -112,7 +120,7 @@ module Aws
112
120
  # attr_reader :encryption_materials
113
121
  #
114
122
  # def key_for(matdesc)
115
- # key_name = JSON.load(matdesc)['key']
123
+ # key_name = JSON.parse(matdesc)['key']
116
124
  # if key = @keys[key_name]
117
125
  # key
118
126
  # else
@@ -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