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,11 +1,14 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # WARNING ABOUT GENERATED CODE
2
4
  #
3
5
  # This file is generated. See the contributing guide for more information:
4
- # https://github.com/aws/aws-sdk-ruby/blob/master/CONTRIBUTING.md
6
+ # https://github.com/aws/aws-sdk-ruby/blob/version-3/CONTRIBUTING.md
5
7
  #
6
8
  # WARNING ABOUT GENERATED CODE
7
9
 
8
10
  module Aws::S3
11
+
9
12
  class ObjectVersion
10
13
 
11
14
  extend Aws::Deprecations
@@ -27,6 +30,7 @@ module Aws::S3
27
30
  @id = extract_id(args, options)
28
31
  @data = options.delete(:data)
29
32
  @client = options.delete(:client) || Client.new(options)
33
+ @waiter_block_warned = false
30
34
  end
31
35
 
32
36
  # @!group Read-Only Attributes
@@ -46,7 +50,7 @@ module Aws::S3
46
50
  @id
47
51
  end
48
52
 
49
-
53
+ # The entity tag is an MD5 hash of that version of the object.
50
54
  # @return [String]
51
55
  def etag
52
56
  data[:etag]
@@ -89,7 +93,7 @@ module Aws::S3
89
93
  data[:last_modified]
90
94
  end
91
95
 
92
-
96
+ # Specifies the owner of the object.
93
97
  # @return [Types::Owner]
94
98
  def owner
95
99
  data[:owner]
@@ -130,7 +134,8 @@ module Aws::S3
130
134
  # Waiter polls an API operation until a resource enters a desired
131
135
  # state.
132
136
  #
133
- # @note The waiting operation is performed on a copy. The original resource remains unchanged
137
+ # @note The waiting operation is performed on a copy. The original resource
138
+ # remains unchanged.
134
139
  #
135
140
  # ## Basic Usage
136
141
  #
@@ -143,13 +148,15 @@ module Aws::S3
143
148
  #
144
149
  # ## Example
145
150
  #
146
- # instance.wait_until(max_attempts:10, delay:5) {|instance| instance.state.name == 'running' }
151
+ # instance.wait_until(max_attempts:10, delay:5) do |instance|
152
+ # instance.state.name == 'running'
153
+ # end
147
154
  #
148
155
  # ## Configuration
149
156
  #
150
157
  # You can configure the maximum number of polling attempts, and the
151
- # delay (in seconds) between each polling attempt. The waiting condition is set
152
- # by passing a block to {#wait_until}:
158
+ # delay (in seconds) between each polling attempt. The waiting condition is
159
+ # set by passing a block to {#wait_until}:
153
160
  #
154
161
  # # poll for ~25 seconds
155
162
  # resource.wait_until(max_attempts:5,delay:5) {|resource|...}
@@ -180,17 +187,16 @@ module Aws::S3
180
187
  # # resource did not enter the desired state in time
181
188
  # end
182
189
  #
190
+ # @yieldparam [Resource] resource to be used in the waiting condition.
183
191
  #
184
- # @yield param [Resource] resource to be used in the waiting condition
185
- #
186
- # @raise [Aws::Waiters::Errors::FailureStateError] Raised when the waiter terminates
187
- # because the waiter has entered a state that it will not transition
188
- # out of, preventing success.
192
+ # @raise [Aws::Waiters::Errors::FailureStateError] Raised when the waiter
193
+ # terminates because the waiter has entered a state that it will not
194
+ # transition out of, preventing success.
189
195
  #
190
196
  # yet successful.
191
197
  #
192
- # @raise [Aws::Waiters::Errors::UnexpectedError] Raised when an error is encountered
193
- # while polling for a resource that is not expected.
198
+ # @raise [Aws::Waiters::Errors::UnexpectedError] Raised when an error is
199
+ # encountered while polling for a resource that is not expected.
194
200
  #
195
201
  # @raise [NotImplementedError] Raised when the resource does not
196
202
  #
@@ -228,20 +234,31 @@ module Aws::S3
228
234
  # mfa: "MFA",
229
235
  # request_payer: "requester", # accepts requester
230
236
  # bypass_governance_retention: false,
237
+ # expected_bucket_owner: "AccountId",
231
238
  # })
232
239
  # @param [Hash] options ({})
233
240
  # @option options [String] :mfa
234
241
  # The concatenation of the authentication device's serial number, a
235
242
  # space, and the value that is displayed on your authentication device.
243
+ # Required to permanently delete a versioned object if versioning is
244
+ # configured with MFA delete enabled.
236
245
  # @option options [String] :request_payer
237
- # Confirms that the requester knows that she or he will be charged for
238
- # the request. Bucket owners need not specify this parameter in their
239
- # requests. Documentation on downloading objects from requester pays
240
- # buckets can be found at
241
- # http://docs.aws.amazon.com/AmazonS3/latest/dev/ObjectsinRequesterPaysBuckets.html
246
+ # Confirms that the requester knows that they will be charged for the
247
+ # request. Bucket owners need not specify this parameter in their
248
+ # requests. For information about downloading objects from requester
249
+ # pays buckets, see [Downloading Objects in Requestor Pays Buckets][1]
250
+ # in the *Amazon S3 User Guide*.
251
+ #
252
+ #
253
+ #
254
+ # [1]: https://docs.aws.amazon.com/AmazonS3/latest/dev/ObjectsinRequesterPaysBuckets.html
242
255
  # @option options [Boolean] :bypass_governance_retention
243
256
  # Indicates whether S3 Object Lock should bypass Governance-mode
244
257
  # restrictions to process this operation.
258
+ # @option options [String] :expected_bucket_owner
259
+ # The account ID of the expected bucket owner. If the bucket is owned by
260
+ # a different account, the request will fail with an HTTP `403 (Access
261
+ # Denied)` error.
245
262
  # @return [Types::DeleteObjectOutput]
246
263
  def delete(options = {})
247
264
  options = options.merge(
@@ -272,6 +289,7 @@ module Aws::S3
272
289
  # sse_customer_key_md5: "SSECustomerKeyMD5",
273
290
  # request_payer: "requester", # accepts requester
274
291
  # part_number: 1,
292
+ # expected_bucket_owner: "AccountId",
275
293
  # })
276
294
  # @param [Hash] options ({})
277
295
  # @option options [String] :if_match
@@ -288,44 +306,61 @@ module Aws::S3
288
306
  # time, otherwise return a 412 (precondition failed).
289
307
  # @option options [String] :range
290
308
  # Downloads the specified range bytes of an object. For more information
291
- # about the HTTP Range header, go to
292
- # http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.35.
309
+ # about the HTTP Range header, see
310
+ # [https://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.35][1].
311
+ #
312
+ # <note markdown="1"> Amazon S3 doesn't support retrieving multiple ranges of data per
313
+ # `GET` request.
314
+ #
315
+ # </note>
316
+ #
317
+ #
318
+ #
319
+ # [1]: https://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.35
293
320
  # @option options [String] :response_cache_control
294
- # Sets the Cache-Control header of the response.
321
+ # Sets the `Cache-Control` header of the response.
295
322
  # @option options [String] :response_content_disposition
296
- # Sets the Content-Disposition header of the response
323
+ # Sets the `Content-Disposition` header of the response
297
324
  # @option options [String] :response_content_encoding
298
- # Sets the Content-Encoding header of the response.
325
+ # Sets the `Content-Encoding` header of the response.
299
326
  # @option options [String] :response_content_language
300
- # Sets the Content-Language header of the response.
327
+ # Sets the `Content-Language` header of the response.
301
328
  # @option options [String] :response_content_type
302
- # Sets the Content-Type header of the response.
329
+ # Sets the `Content-Type` header of the response.
303
330
  # @option options [Time,DateTime,Date,Integer,String] :response_expires
304
- # Sets the Expires header of the response.
331
+ # Sets the `Expires` header of the response.
305
332
  # @option options [String] :sse_customer_algorithm
306
- # Specifies the algorithm to use to when encrypting the object (e.g.,
307
- # AES256).
333
+ # Specifies the algorithm to use to when decrypting the object (for
334
+ # example, AES256).
308
335
  # @option options [String] :sse_customer_key
309
- # Specifies the customer-provided encryption key for Amazon S3 to use in
310
- # encrypting data. This value is used to store the object and then it is
311
- # discarded; Amazon does not store the encryption key. The key must be
312
- # appropriate for use with the algorithm specified in the
313
- # x-amz-server-side​-encryption​-customer-algorithm header.
336
+ # Specifies the customer-provided encryption key for Amazon S3 used to
337
+ # encrypt the data. This value is used to decrypt the object when
338
+ # recovering it and must match the one used when storing the data. The
339
+ # key must be appropriate for use with the algorithm specified in the
340
+ # `x-amz-server-side-encryption-customer-algorithm` header.
314
341
  # @option options [String] :sse_customer_key_md5
315
342
  # Specifies the 128-bit MD5 digest of the encryption key according to
316
343
  # RFC 1321. Amazon S3 uses this header for a message integrity check to
317
- # ensure the encryption key was transmitted without error.
344
+ # ensure that the encryption key was transmitted without error.
318
345
  # @option options [String] :request_payer
319
- # Confirms that the requester knows that she or he will be charged for
320
- # the request. Bucket owners need not specify this parameter in their
321
- # requests. Documentation on downloading objects from requester pays
322
- # buckets can be found at
323
- # http://docs.aws.amazon.com/AmazonS3/latest/dev/ObjectsinRequesterPaysBuckets.html
346
+ # Confirms that the requester knows that they will be charged for the
347
+ # request. Bucket owners need not specify this parameter in their
348
+ # requests. For information about downloading objects from requester
349
+ # pays buckets, see [Downloading Objects in Requestor Pays Buckets][1]
350
+ # in the *Amazon S3 User Guide*.
351
+ #
352
+ #
353
+ #
354
+ # [1]: https://docs.aws.amazon.com/AmazonS3/latest/dev/ObjectsinRequesterPaysBuckets.html
324
355
  # @option options [Integer] :part_number
325
356
  # Part number of the object being read. This is a positive integer
326
357
  # between 1 and 10,000. Effectively performs a 'ranged' GET request
327
358
  # for the part specified. Useful for downloading just a part of an
328
359
  # object.
360
+ # @option options [String] :expected_bucket_owner
361
+ # The account ID of the expected bucket owner. If the bucket is owned by
362
+ # a different account, the request will fail with an HTTP `403 (Access
363
+ # Denied)` error.
329
364
  # @return [Types::GetObjectOutput]
330
365
  def get(options = {}, &block)
331
366
  options = options.merge(
@@ -350,6 +385,7 @@ module Aws::S3
350
385
  # sse_customer_key_md5: "SSECustomerKeyMD5",
351
386
  # request_payer: "requester", # accepts requester
352
387
  # part_number: 1,
388
+ # expected_bucket_owner: "AccountId",
353
389
  # })
354
390
  # @param [Hash] options ({})
355
391
  # @option options [String] :if_match
@@ -366,32 +402,49 @@ module Aws::S3
366
402
  # time, otherwise return a 412 (precondition failed).
367
403
  # @option options [String] :range
368
404
  # Downloads the specified range bytes of an object. For more information
369
- # about the HTTP Range header, go to
370
- # http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.35.
405
+ # about the HTTP Range header, see
406
+ # [http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.35][1].
407
+ #
408
+ # <note markdown="1"> Amazon S3 doesn't support retrieving multiple ranges of data per
409
+ # `GET` request.
410
+ #
411
+ # </note>
412
+ #
413
+ #
414
+ #
415
+ # [1]: http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.35
371
416
  # @option options [String] :sse_customer_algorithm
372
- # Specifies the algorithm to use to when encrypting the object (e.g.,
373
- # AES256).
417
+ # Specifies the algorithm to use to when encrypting the object (for
418
+ # example, AES256).
374
419
  # @option options [String] :sse_customer_key
375
420
  # Specifies the customer-provided encryption key for Amazon S3 to use in
376
421
  # encrypting data. This value is used to store the object and then it is
377
- # discarded; Amazon does not store the encryption key. The key must be
378
- # appropriate for use with the algorithm specified in the
379
- # x-amz-server-side​-encryption​-customer-algorithm header.
422
+ # discarded; Amazon S3 does not store the encryption key. The key must
423
+ # be appropriate for use with the algorithm specified in the
424
+ # `x-amz-server-side-encryption-customer-algorithm` header.
380
425
  # @option options [String] :sse_customer_key_md5
381
426
  # Specifies the 128-bit MD5 digest of the encryption key according to
382
427
  # RFC 1321. Amazon S3 uses this header for a message integrity check to
383
- # ensure the encryption key was transmitted without error.
428
+ # ensure that the encryption key was transmitted without error.
384
429
  # @option options [String] :request_payer
385
- # Confirms that the requester knows that she or he will be charged for
386
- # the request. Bucket owners need not specify this parameter in their
387
- # requests. Documentation on downloading objects from requester pays
388
- # buckets can be found at
389
- # http://docs.aws.amazon.com/AmazonS3/latest/dev/ObjectsinRequesterPaysBuckets.html
430
+ # Confirms that the requester knows that they will be charged for the
431
+ # request. Bucket owners need not specify this parameter in their
432
+ # requests. For information about downloading objects from requester
433
+ # pays buckets, see [Downloading Objects in Requestor Pays Buckets][1]
434
+ # in the *Amazon S3 User Guide*.
435
+ #
436
+ #
437
+ #
438
+ # [1]: https://docs.aws.amazon.com/AmazonS3/latest/dev/ObjectsinRequesterPaysBuckets.html
390
439
  # @option options [Integer] :part_number
391
440
  # Part number of the object being read. This is a positive integer
392
441
  # between 1 and 10,000. Effectively performs a 'ranged' HEAD request
393
442
  # for the part specified. Useful querying about the size of the part and
394
443
  # the number of parts in this object.
444
+ # @option options [String] :expected_bucket_owner
445
+ # The account ID of the expected bucket owner. If the bucket is owned by
446
+ # a different account, the request will fail with an HTTP `403 (Access
447
+ # Denied)` error.
395
448
  # @return [Types::HeadObjectOutput]
396
449
  def head(options = {})
397
450
  options = options.merge(
@@ -470,21 +523,32 @@ module Aws::S3
470
523
  # mfa: "MFA",
471
524
  # request_payer: "requester", # accepts requester
472
525
  # bypass_governance_retention: false,
526
+ # expected_bucket_owner: "AccountId",
473
527
  # })
474
528
  # @param options ({})
475
529
  # @option options [String] :mfa
476
530
  # The concatenation of the authentication device's serial number, a
477
531
  # space, and the value that is displayed on your authentication device.
532
+ # Required to permanently delete a versioned object if versioning is
533
+ # configured with MFA delete enabled.
478
534
  # @option options [String] :request_payer
479
- # Confirms that the requester knows that she or he will be charged for
480
- # the request. Bucket owners need not specify this parameter in their
481
- # requests. Documentation on downloading objects from requester pays
482
- # buckets can be found at
483
- # http://docs.aws.amazon.com/AmazonS3/latest/dev/ObjectsinRequesterPaysBuckets.html
535
+ # Confirms that the requester knows that they will be charged for the
536
+ # request. Bucket owners need not specify this parameter in their
537
+ # requests. For information about downloading objects from requester
538
+ # pays buckets, see [Downloading Objects in Requestor Pays Buckets][1]
539
+ # in the *Amazon S3 User Guide*.
540
+ #
541
+ #
542
+ #
543
+ # [1]: https://docs.aws.amazon.com/AmazonS3/latest/dev/ObjectsinRequesterPaysBuckets.html
484
544
  # @option options [Boolean] :bypass_governance_retention
485
545
  # Specifies whether you want to delete this object even if it has a
486
546
  # Governance-type Object Lock in place. You must have sufficient
487
547
  # permissions to perform this operation.
548
+ # @option options [String] :expected_bucket_owner
549
+ # The account ID of the expected bucket owner. If the bucket is owned by
550
+ # a different account, the request will fail with an HTTP `403 (Access
551
+ # Denied)` error.
488
552
  # @return [void]
489
553
  def batch_delete!(options = {})
490
554
  batch_enum.each do |batch|
@@ -1,36 +1,51 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Aws
2
4
  module S3
3
5
  module Plugins
4
-
5
6
  # Provides support for using `Aws::S3::Client` with Amazon S3 Transfer
6
7
  # Acceleration.
7
8
  #
8
9
  # Go here for more information about transfer acceleration:
9
10
  # [http://docs.aws.amazon.com/AmazonS3/latest/dev/transfer-acceleration.html](http://docs.aws.amazon.com/AmazonS3/latest/dev/transfer-acceleration.html)
10
11
  class Accelerate < Seahorse::Client::Plugin
11
-
12
- option(:use_accelerate_endpoint,
12
+ option(
13
+ :use_accelerate_endpoint,
13
14
  default: false,
14
15
  doc_type: 'Boolean',
15
16
  docstring: <<-DOCS)
16
17
  When set to `true`, accelerated bucket endpoints will be used
17
18
  for all object operations. You must first enable accelerate for
18
- each bucket. [Go here for more information](http://docs.aws.amazon.com/AmazonS3/latest/dev/transfer-acceleration.html).
19
+ each bucket. [Go here for more information](http://docs.aws.amazon.com/AmazonS3/latest/dev/transfer-acceleration.html).
19
20
  DOCS
20
21
 
21
22
  def add_handlers(handlers, config)
22
23
  operations = config.api.operation_names - [
23
- :create_bucket, :list_buckets, :delete_bucket,
24
+ :create_bucket, :list_buckets, :delete_bucket
24
25
  ]
25
- handlers.add(OptionHandler, step: :initialize, operations: operations)
26
- handlers.add(AccelerateHandler, step: :build, priority: 0, operations: operations)
26
+ # Need 2 handlers so that the context can be set for other plugins
27
+ # and to remove :use_accelerate_endpoint from the params.
28
+ handlers.add(
29
+ OptionHandler, step: :initialize, operations: operations
30
+ )
31
+ handlers.add(
32
+ AccelerateHandler, step: :build, priority: 11, operations: operations
33
+ )
27
34
  end
28
35
 
29
36
  # @api private
30
37
  class OptionHandler < Seahorse::Client::Handler
31
38
  def call(context)
32
- accelerate = context.params.delete(:use_accelerate_endpoint)
39
+ # Support client configuration and per-operation configuration
40
+ if context.params.is_a?(Hash)
41
+ accelerate = context.params.delete(:use_accelerate_endpoint)
42
+ end
33
43
  accelerate = context.config.use_accelerate_endpoint if accelerate.nil?
44
+ # Raise if :endpoint and dualstack are both provided
45
+ if accelerate && !context.config.regional_endpoint
46
+ raise ArgumentError,
47
+ 'Cannot use both :use_accelerate_endpoint and :endpoint'
48
+ end
34
49
  context[:use_accelerate_endpoint] = accelerate
35
50
  @handler.call(context)
36
51
  end
@@ -38,39 +53,24 @@ each bucket. [Go here for more information](http://docs.aws.amazon.com/AmazonS3
38
53
 
39
54
  # @api private
40
55
  class AccelerateHandler < Seahorse::Client::Handler
41
-
42
56
  def call(context)
43
- if context[:use_accelerate_endpoint]
44
- if context[:use_dualstack_endpoint]
45
- use_combined_accelerate_dualstack_endpoint(context)
46
- else
47
- use_accelerate_endpoint(context)
48
- end
57
+ if context.config.regional_endpoint && context[:use_accelerate_endpoint]
58
+ dualstack = !!context[:use_dualstack_endpoint]
59
+ use_accelerate_endpoint(context, dualstack)
49
60
  end
50
61
  @handler.call(context)
51
62
  end
52
63
 
53
64
  private
54
65
 
55
- def use_accelerate_endpoint(context)
56
- bucket_name = context.params[:bucket]
57
- validate_bucket_name!(bucket_name)
58
- endpoint = URI.parse(context.http_request.endpoint.to_s)
59
- endpoint.scheme = 'https'
60
- endpoint.port = 443
61
- endpoint.host = "#{bucket_name}.s3-accelerate.amazonaws.com"
62
- context.http_request.endpoint = endpoint.to_s
63
- # s3 accelerate endpoint doesn't work with 'expect' header
64
- context.http_request.headers.delete('expect')
65
- end
66
-
67
- def use_combined_accelerate_dualstack_endpoint(context)
66
+ def use_accelerate_endpoint(context, dualstack)
68
67
  bucket_name = context.params[:bucket]
69
68
  validate_bucket_name!(bucket_name)
70
69
  endpoint = URI.parse(context.http_request.endpoint.to_s)
71
70
  endpoint.scheme = 'https'
72
71
  endpoint.port = 443
73
- endpoint.host = "#{bucket_name}.s3-accelerate.dualstack.amazonaws.com"
72
+ endpoint.host = "#{bucket_name}.s3-accelerate"\
73
+ "#{'.dualstack' if dualstack}.amazonaws.com"
74
74
  context.http_request.endpoint = endpoint.to_s
75
75
  # s3 accelerate endpoint doesn't work with 'expect' header
76
76
  context.http_request.headers.delete('expect')
@@ -78,17 +78,11 @@ each bucket. [Go here for more information](http://docs.aws.amazon.com/AmazonS3
78
78
 
79
79
  def validate_bucket_name!(bucket_name)
80
80
  unless BucketDns.dns_compatible?(bucket_name, _ssl = true)
81
- msg = "unable to use `accelerate: true` on buckets with "
82
- msg << "non-DNS compatible names"
83
- raise ArgumentError, msg
84
- end
85
- if bucket_name.include?('.')
86
- msg = "unable to use `accelerate: true` on buckets with dots"
87
- msg << "in their name: #{bucket_name.inspect}"
88
- raise ArgumentError, msg
81
+ raise ArgumentError,
82
+ 'Unable to use `use_accelerate_endpoint: true` on buckets '\
83
+ 'with non-DNS compatible names.'
89
84
  end
90
85
  end
91
-
92
86
  end
93
87
  end
94
88
  end