aws-sdk-s3 1.142.0 → 1.208.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (118) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +417 -1
  3. data/VERSION +1 -1
  4. data/lib/aws-sdk-s3/access_grants_credentials.rb +57 -0
  5. data/lib/aws-sdk-s3/access_grants_credentials_provider.rb +250 -0
  6. data/lib/aws-sdk-s3/bucket.rb +358 -106
  7. data/lib/aws-sdk-s3/bucket_acl.rb +10 -9
  8. data/lib/aws-sdk-s3/bucket_cors.rb +10 -9
  9. data/lib/aws-sdk-s3/bucket_lifecycle.rb +11 -6
  10. data/lib/aws-sdk-s3/bucket_lifecycle_configuration.rb +64 -7
  11. data/lib/aws-sdk-s3/bucket_logging.rb +5 -5
  12. data/lib/aws-sdk-s3/bucket_notification.rb +3 -3
  13. data/lib/aws-sdk-s3/bucket_policy.rb +14 -13
  14. data/lib/aws-sdk-s3/bucket_region_cache.rb +9 -5
  15. data/lib/aws-sdk-s3/bucket_request_payment.rb +6 -6
  16. data/lib/aws-sdk-s3/bucket_tagging.rb +7 -7
  17. data/lib/aws-sdk-s3/bucket_versioning.rb +47 -14
  18. data/lib/aws-sdk-s3/bucket_website.rb +7 -7
  19. data/lib/aws-sdk-s3/client.rb +5671 -2195
  20. data/lib/aws-sdk-s3/client_api.rb +665 -166
  21. data/lib/aws-sdk-s3/customizations/bucket.rb +1 -1
  22. data/lib/aws-sdk-s3/customizations/errors.rb +15 -2
  23. data/lib/aws-sdk-s3/customizations/object.rb +87 -91
  24. data/lib/aws-sdk-s3/customizations/object_summary.rb +5 -0
  25. data/lib/aws-sdk-s3/customizations/object_version.rb +13 -0
  26. data/lib/aws-sdk-s3/customizations.rb +28 -36
  27. data/lib/aws-sdk-s3/default_executor.rb +103 -0
  28. data/lib/aws-sdk-s3/encryption/client.rb +4 -4
  29. data/lib/aws-sdk-s3/encryption/default_cipher_provider.rb +2 -0
  30. data/lib/aws-sdk-s3/encryption/encrypt_handler.rb +2 -0
  31. data/lib/aws-sdk-s3/encryption/kms_cipher_provider.rb +4 -2
  32. data/lib/aws-sdk-s3/encryptionV2/client.rb +100 -25
  33. data/lib/aws-sdk-s3/encryptionV2/decrypt_handler.rb +7 -162
  34. data/lib/aws-sdk-s3/encryptionV2/decryption.rb +205 -0
  35. data/lib/aws-sdk-s3/encryptionV2/default_cipher_provider.rb +17 -0
  36. data/lib/aws-sdk-s3/encryptionV2/encrypt_handler.rb +2 -0
  37. data/lib/aws-sdk-s3/encryptionV2/io_encrypter.rb +2 -0
  38. data/lib/aws-sdk-s3/encryptionV2/kms_cipher_provider.rb +10 -2
  39. data/lib/aws-sdk-s3/encryptionV2/utils.rb +5 -0
  40. data/lib/aws-sdk-s3/encryptionV3/client.rb +885 -0
  41. data/lib/aws-sdk-s3/encryptionV3/decrypt_handler.rb +98 -0
  42. data/lib/aws-sdk-s3/encryptionV3/decryption.rb +244 -0
  43. data/lib/aws-sdk-s3/encryptionV3/default_cipher_provider.rb +159 -0
  44. data/lib/aws-sdk-s3/encryptionV3/default_key_provider.rb +35 -0
  45. data/lib/aws-sdk-s3/encryptionV3/encrypt_handler.rb +98 -0
  46. data/lib/aws-sdk-s3/encryptionV3/errors.rb +47 -0
  47. data/lib/aws-sdk-s3/encryptionV3/io_auth_decrypter.rb +60 -0
  48. data/lib/aws-sdk-s3/encryptionV3/io_decrypter.rb +35 -0
  49. data/lib/aws-sdk-s3/encryptionV3/io_encrypter.rb +84 -0
  50. data/lib/aws-sdk-s3/encryptionV3/key_provider.rb +28 -0
  51. data/lib/aws-sdk-s3/encryptionV3/kms_cipher_provider.rb +159 -0
  52. data/lib/aws-sdk-s3/encryptionV3/materials.rb +58 -0
  53. data/lib/aws-sdk-s3/encryptionV3/utils.rb +321 -0
  54. data/lib/aws-sdk-s3/encryption_v2.rb +1 -0
  55. data/lib/aws-sdk-s3/encryption_v3.rb +24 -0
  56. data/lib/aws-sdk-s3/endpoint_parameters.rb +37 -34
  57. data/lib/aws-sdk-s3/endpoint_provider.rb +572 -277
  58. data/lib/aws-sdk-s3/endpoints.rb +566 -1612
  59. data/lib/aws-sdk-s3/errors.rb +58 -0
  60. data/lib/aws-sdk-s3/express_credentials_provider.rb +27 -4
  61. data/lib/aws-sdk-s3/file_downloader.rb +192 -146
  62. data/lib/aws-sdk-s3/file_uploader.rb +10 -14
  63. data/lib/aws-sdk-s3/legacy_signer.rb +2 -1
  64. data/lib/aws-sdk-s3/multipart_download_error.rb +8 -0
  65. data/lib/aws-sdk-s3/multipart_file_uploader.rb +106 -102
  66. data/lib/aws-sdk-s3/multipart_stream_uploader.rb +99 -108
  67. data/lib/aws-sdk-s3/multipart_upload.rb +112 -12
  68. data/lib/aws-sdk-s3/multipart_upload_error.rb +3 -4
  69. data/lib/aws-sdk-s3/multipart_upload_part.rb +55 -39
  70. data/lib/aws-sdk-s3/object.rb +713 -227
  71. data/lib/aws-sdk-s3/object_acl.rb +15 -9
  72. data/lib/aws-sdk-s3/object_copier.rb +1 -1
  73. data/lib/aws-sdk-s3/object_multipart_copier.rb +12 -9
  74. data/lib/aws-sdk-s3/object_summary.rb +592 -173
  75. data/lib/aws-sdk-s3/object_version.rb +102 -17
  76. data/lib/aws-sdk-s3/plugins/access_grants.rb +178 -0
  77. data/lib/aws-sdk-s3/plugins/checksum_algorithm.rb +31 -0
  78. data/lib/aws-sdk-s3/plugins/endpoints.rb +26 -213
  79. data/lib/aws-sdk-s3/plugins/express_session_auth.rb +19 -21
  80. data/lib/aws-sdk-s3/plugins/http_200_errors.rb +55 -18
  81. data/lib/aws-sdk-s3/plugins/md5s.rb +10 -71
  82. data/lib/aws-sdk-s3/plugins/s3_signer.rb +7 -2
  83. data/lib/aws-sdk-s3/plugins/streaming_retry.rb +5 -7
  84. data/lib/aws-sdk-s3/plugins/url_encoded_keys.rb +2 -1
  85. data/lib/aws-sdk-s3/presigner.rb +7 -5
  86. data/lib/aws-sdk-s3/resource.rb +53 -20
  87. data/lib/aws-sdk-s3/transfer_manager.rb +303 -0
  88. data/lib/aws-sdk-s3/types.rb +4738 -1542
  89. data/lib/aws-sdk-s3.rb +35 -31
  90. data/sig/bucket.rbs +231 -0
  91. data/sig/bucket_acl.rbs +78 -0
  92. data/sig/bucket_cors.rbs +69 -0
  93. data/sig/bucket_lifecycle.rbs +88 -0
  94. data/sig/bucket_lifecycle_configuration.rbs +115 -0
  95. data/sig/bucket_logging.rbs +76 -0
  96. data/sig/bucket_notification.rbs +114 -0
  97. data/sig/bucket_policy.rbs +59 -0
  98. data/sig/bucket_request_payment.rbs +54 -0
  99. data/sig/bucket_tagging.rbs +65 -0
  100. data/sig/bucket_versioning.rbs +77 -0
  101. data/sig/bucket_website.rbs +93 -0
  102. data/sig/client.rbs +2612 -0
  103. data/sig/customizations/bucket.rbs +19 -0
  104. data/sig/customizations/object.rbs +38 -0
  105. data/sig/customizations/object_summary.rbs +35 -0
  106. data/sig/errors.rbs +44 -0
  107. data/sig/multipart_upload.rbs +120 -0
  108. data/sig/multipart_upload_part.rbs +109 -0
  109. data/sig/object.rbs +464 -0
  110. data/sig/object_acl.rbs +86 -0
  111. data/sig/object_summary.rbs +347 -0
  112. data/sig/object_version.rbs +143 -0
  113. data/sig/resource.rbs +141 -0
  114. data/sig/types.rbs +2899 -0
  115. data/sig/waiters.rbs +95 -0
  116. metadata +58 -13
  117. data/lib/aws-sdk-s3/express_credentials_cache.rb +0 -30
  118. data/lib/aws-sdk-s3/plugins/skip_whole_multipart_get_checksums.rb +0 -31
@@ -134,7 +134,7 @@ module Aws
134
134
 
135
135
  # @api private
136
136
  def load
137
- @data = Aws::Plugins::UserAgent.feature('resource') do
137
+ @data = Aws::Plugins::UserAgent.metric('RESOURCE_MODEL') do
138
138
  client.list_buckets.buckets.find { |b| b.name == name }
139
139
  end
140
140
  raise "unable to load bucket #{name}" if @data.nil?
@@ -3,8 +3,8 @@
3
3
  module Aws
4
4
  module S3
5
5
  module Errors
6
- # Hijack PermanentRedirect dynamic error to also include endpoint
7
- # and bucket.
6
+ # Hijack PermanentRedirect dynamic error to include the bucket, region,
7
+ # and endpoint.
8
8
  class PermanentRedirect < ServiceError
9
9
  # @param [Seahorse::Client::RequestContext] context
10
10
  # @param [String] message
@@ -22,6 +22,19 @@ module Aws
22
22
  super(context, message, data)
23
23
  end
24
24
  end
25
+
26
+ # Hijack PermanentRedirect (HeadBucket case - no body) dynamic error to
27
+ # include the region.
28
+ class Http301Error < ServiceError
29
+ # @param [Seahorse::Client::RequestContext] context
30
+ # @param [String] message
31
+ # @param [Aws::S3::Types::PermanentRedirect] _data
32
+ def initialize(context, message, _data = Aws::EmptyStructure.new)
33
+ data = Aws::S3::Types::PermanentRedirect.new(message: message)
34
+ data.region = context.http_response.headers['x-amz-bucket-region']
35
+ super(context, message, data)
36
+ end
37
+ end
25
38
  end
26
39
  end
27
40
  end
@@ -76,7 +76,7 @@ module Aws
76
76
  # @see #copy_to
77
77
  #
78
78
  def copy_from(source, options = {})
79
- Aws::Plugins::UserAgent.feature('resource') do
79
+ Aws::Plugins::UserAgent.metric('RESOURCE_MODEL') do
80
80
  if Hash === source && source[:copy_source]
81
81
  # for backwards compatibility
82
82
  @client.copy_object(source.merge(bucket: bucket_name, key: key))
@@ -119,7 +119,7 @@ module Aws
119
119
  # object.copy_to('src-bucket/src-key', multipart_copy: true)
120
120
  #
121
121
  def copy_to(target, options = {})
122
- Aws::Plugins::UserAgent.feature('resource') do
122
+ Aws::Plugins::UserAgent.metric('RESOURCE_MODEL') do
123
123
  ObjectCopier.new(self, options).copy_to(target, options)
124
124
  end
125
125
  end
@@ -358,8 +358,8 @@ module Aws
358
358
  # {Client#complete_multipart_upload},
359
359
  # and {Client#upload_part} can be provided.
360
360
  #
361
- # @option options [Integer] :thread_count (10) The number of parallel
362
- # multipart uploads
361
+ # @option options [Integer] :thread_count (10) The number of parallel multipart uploads.
362
+ # An additional thread is used internally for task coordination.
363
363
  #
364
364
  # @option options [Boolean] :tempfile (false) Normally read data is stored
365
365
  # in memory when building the parts in order to complete the underlying
@@ -383,29 +383,28 @@ module Aws
383
383
  # @see Client#complete_multipart_upload
384
384
  # @see Client#upload_part
385
385
  def upload_stream(options = {}, &block)
386
- uploading_options = options.dup
386
+ upload_opts = options.merge(bucket: bucket_name, key: key)
387
+ executor = DefaultExecutor.new(max_threads: upload_opts.delete(:thread_count))
387
388
  uploader = MultipartStreamUploader.new(
388
389
  client: client,
389
- thread_count: uploading_options.delete(:thread_count),
390
- tempfile: uploading_options.delete(:tempfile),
391
- part_size: uploading_options.delete(:part_size)
390
+ executor: executor,
391
+ tempfile: upload_opts.delete(:tempfile),
392
+ part_size: upload_opts.delete(:part_size)
392
393
  )
393
- Aws::Plugins::UserAgent.feature('resource') do
394
- uploader.upload(
395
- uploading_options.merge(bucket: bucket_name, key: key),
396
- &block
397
- )
394
+ Aws::Plugins::UserAgent.metric('RESOURCE_MODEL') do
395
+ uploader.upload(upload_opts, &block)
398
396
  end
397
+ executor.shutdown
399
398
  true
400
399
  end
400
+ deprecated(:upload_stream, use: 'Aws::S3::TransferManager#upload_stream', version: 'next major version')
401
401
 
402
402
  # Uploads a file from disk to the current object in S3.
403
403
  #
404
404
  # # small files are uploaded in a single API call
405
405
  # obj.upload_file('/path/to/file')
406
406
  #
407
- # Files larger than or equal to `:multipart_threshold` are uploaded
408
- # using the Amazon S3 multipart upload APIs.
407
+ # Files larger than or equal to `:multipart_threshold` are uploaded using the Amazon S3 multipart upload APIs.
409
408
  #
410
409
  # # large files are automatically split into parts
411
410
  # # and the parts are uploaded in parallel
@@ -421,74 +420,65 @@ module Aws
421
420
  # You can provide a callback to monitor progress of the upload:
422
421
  #
423
422
  # # bytes and totals are each an array with 1 entry per part
424
- # progress = Proc.new do |bytes, totals|
425
- # puts bytes.map.with_index { |b, i| "Part #{i+1}: #{b} / #{totals[i]}"}.join(' ') + "Total: #{100.0 * bytes.sum / totals.sum }%" }
423
+ # progress = proc do |bytes, totals|
424
+ # puts bytes.map.with_index { |b, i| "Part #{i+1}: #{b} / #{totals[i]}"}.join(' ') + "Total: #{100.0 * bytes.sum / totals.sum }%"
426
425
  # end
427
426
  # obj.upload_file('/path/to/file', progress_callback: progress)
428
427
  #
429
- # @param [String, Pathname, File, Tempfile] source A file on the local
430
- # file system that will be uploaded as this object. This can either be
431
- # a String or Pathname to the file, an open File object, or an open
432
- # Tempfile object. If you pass an open File or Tempfile object, then
433
- # you are responsible for closing it after the upload completes. When
434
- # using an open Tempfile, rewind it before uploading or else the object
428
+ # @param [String, Pathname, File, Tempfile] source A file on the local file system that will be uploaded as
429
+ # this object. This can either be a String or Pathname to the file, an open File object, or an open
430
+ # Tempfile object. If you pass an open File or Tempfile object, then you are responsible for closing it
431
+ # after the upload completes. When using an open Tempfile, rewind it before uploading or else the object
435
432
  # will be empty.
436
433
  #
437
434
  # @param [Hash] options
438
- # Additional options for {Client#put_object}
439
- # when file sizes below the multipart threshold. For files larger than
440
- # the multipart threshold, options for {Client#create_multipart_upload},
441
- # {Client#complete_multipart_upload},
442
- # and {Client#upload_part} can be provided.
435
+ # Additional options for {Client#put_object} when file sizes below the multipart threshold.
436
+ # For files larger than the multipart threshold, options for {Client#create_multipart_upload},
437
+ # {Client#complete_multipart_upload}, and {Client#upload_part} can be provided.
443
438
  #
444
- # @option options [Integer] :multipart_threshold (104857600) Files larger
445
- # than or equal to `:multipart_threshold` are uploaded using the S3
446
- # multipart APIs.
447
- # Default threshold is 100MB.
439
+ # @option options [Integer] :multipart_threshold (104857600) Files larger han or equal to
440
+ # `:multipart_threshold` are uploaded using the S3 multipart APIs. Default threshold is 100MB.
448
441
  #
449
- # @option options [Integer] :thread_count (10) The number of parallel
450
- # multipart uploads. This option is not used if the file is smaller than
451
- # `:multipart_threshold`.
442
+ # @option options [Integer] :thread_count (10) The number of parallel multipart uploads.
443
+ # This option is not used if the file is smaller than `:multipart_threshold`.
452
444
  #
453
445
  # @option options [Proc] :progress_callback
454
446
  # A Proc that will be called when each chunk of the upload is sent.
455
447
  # It will be invoked with [bytes_read], [total_sizes]
456
448
  #
457
- # @raise [MultipartUploadError] If an object is being uploaded in
458
- # parts, and the upload can not be completed, then the upload is
459
- # aborted and this error is raised. The raised error has a `#errors`
460
- # method that returns the failures that caused the upload to be
461
- # aborted.
449
+ # @raise [MultipartUploadError] If an object is being uploaded in parts, and the upload can not be completed,
450
+ # then the upload is aborted and this error is raised. The raised error has a `#errors` method that
451
+ # returns the failures that caused the upload to be aborted.
462
452
  #
463
- # @return [Boolean] Returns `true` when the object is uploaded
464
- # without any errors.
453
+ # @return [Boolean] Returns `true` when the object is uploaded without any errors.
465
454
  #
466
455
  # @see Client#put_object
467
456
  # @see Client#create_multipart_upload
468
457
  # @see Client#complete_multipart_upload
469
458
  # @see Client#upload_part
470
459
  def upload_file(source, options = {})
471
- uploading_options = options.dup
460
+ upload_opts = options.merge(bucket: bucket_name, key: key)
461
+ executor = DefaultExecutor.new(max_threads: upload_opts.delete(:thread_count))
472
462
  uploader = FileUploader.new(
473
- multipart_threshold: uploading_options.delete(:multipart_threshold),
474
- client: client
463
+ client: client,
464
+ executor: executor,
465
+ multipart_threshold: upload_opts.delete(:multipart_threshold)
475
466
  )
476
- response = Aws::Plugins::UserAgent.feature('resource') do
477
- uploader.upload(
478
- source,
479
- uploading_options.merge(bucket: bucket_name, key: key)
480
- )
467
+ response = Aws::Plugins::UserAgent.metric('RESOURCE_MODEL') do
468
+ uploader.upload(source, upload_opts)
481
469
  end
482
470
  yield response if block_given?
471
+ executor.shutdown
483
472
  true
484
473
  end
474
+ deprecated(:upload_file, use: 'Aws::S3::TransferManager#upload_file', version: 'next major version')
485
475
 
486
476
  # Downloads a file in S3 to a path on disk.
487
477
  #
488
478
  # # small files (< 5MB) are downloaded in a single API call
489
479
  # obj.download_file('/path/to/file')
490
480
  #
491
- # Files larger than 5MB are downloaded using multipart method
481
+ # Files larger than 5MB are downloaded using multipart method:
492
482
  #
493
483
  # # large files are split into parts
494
484
  # # and the parts are downloaded in parallel
@@ -498,67 +488,73 @@ module Aws
498
488
  #
499
489
  # # bytes and part_sizes are each an array with 1 entry per part
500
490
  # # part_sizes may not be known until the first bytes are retrieved
501
- # progress = Proc.new do |bytes, part_sizes, file_size|
502
- # puts bytes.map.with_index { |b, i| "Part #{i+1}: #{b} / #{part_sizes[i]}"}.join(' ') + "Total: #{100.0 * bytes.sum / file_size}%" }
491
+ # progress = proc do |bytes, part_sizes, file_size|
492
+ # puts bytes.map.with_index { |b, i| "Part #{i + 1}: #{b} / #{part_sizes[i]}" }.join(' ') + "Total: #{100.0 * bytes.sum / file_size}%"
503
493
  # end
504
494
  # obj.download_file('/path/to/file', progress_callback: progress)
505
495
  #
506
- # @param [String] destination Where to download the file to.
496
+ # @param [String, Pathname, File, Tempfile] destination
497
+ # Where to download the file to. This can either be a String or Pathname to the file, an open File object,
498
+ # or an open Tempfile object. If you pass an open File or Tempfile object, then you are responsible for
499
+ # closing it after the download completes. Download behavior varies by destination type:
500
+ #
501
+ # * **String/Pathname paths**: Downloads to a temporary file first, then atomically moves to the final
502
+ # destination. This prevents corruption of any existing file if the download fails.
503
+ # * **File/Tempfile objects**: Downloads directly to the file object without using temporary files.
504
+ # You are responsible for managing the file object's state and closing it after the download completes.
505
+ # If the download fails, the file object may contain partial data.
507
506
  #
508
507
  # @param [Hash] options
509
- # Additional options for {Client#get_object} and #{Client#head_object}
510
- # may be provided.
508
+ # Additional options for {Client#get_object} and #{Client#head_object} may be provided.
511
509
  #
512
- # @option options [String] mode `auto`, `single_request`, `get_range`
513
- # `single_request` mode forces only 1 GET request is made in download,
514
- # `get_range` mode allows `chunk_size` parameter to configured in
515
- # customizing each range size in multipart_download,
516
- # By default, `auto` mode is enabled, which performs multipart_download
510
+ # @option options [String] :mode ("auto") `"auto"`, `"single_request"` or `"get_range"`
517
511
  #
518
- # @option options [Integer] chunk_size required in get_range mode.
512
+ # * `auto` mode is enabled by default, which performs `multipart_download`
513
+ # * `"single_request`" mode forces only 1 GET request is made in download
514
+ # * `"get_range"` mode requires `:chunk_size` parameter to configured in customizing each range size
519
515
  #
520
- # @option options [Integer] thread_count (10) Customize threads used in
521
- # the multipart download.
516
+ # @option options [Integer] :chunk_size required in `"get_range"` mode.
522
517
  #
523
- # @option options [String] version_id The object version id used to
524
- # retrieve the object. For more about object versioning, see:
525
- # https://docs.aws.amazon.com/AmazonS3/latest/dev/ObjectVersioning.html
518
+ # @option options [Integer] :thread_count (10) Customize threads used in the multipart download.
526
519
  #
527
- # @option options [String] checksum_mode (ENABLED) When `ENABLED` and
528
- # the object has a stored checksum, it will be used to validate the
529
- # download and will raise an `Aws::Errors::ChecksumError` if
530
- # checksum validation fails. You may provide a `on_checksum_validated`
531
- # callback if you need to verify that validation occurred and which
532
- # algorithm was used. To disable checksum validation, set
533
- # `checksum_mode` to "DISABLED".
520
+ # @option options [String] :checksum_mode ("ENABLED")
521
+ # This option is deprecated. Use `:response_checksum_validation` on your S3 client instead.
522
+ # To disable checksum validation, set `response_checksum_validation: 'when_required'`
523
+ # when creating your S3 client.
534
524
  #
535
- # @option options [Callable] on_checksum_validated Called each time a
536
- # request's checksum is validated with the checksum algorithm and the
537
- # response. For multipart downloads, this will be called for each
538
- # part that is downloaded and validated.
525
+ # @option options [Callable] :on_checksum_validated
526
+ # Called each time a request's checksum is validated with the checksum algorithm and the
527
+ # response. For multipart downloads, this will be called for each part that is downloaded and validated.
539
528
  #
540
529
  # @option options [Proc] :progress_callback
541
- # A Proc that will be called when each chunk of the download is received.
542
- # It will be invoked with [bytes_read], [part_sizes], file_size.
543
- # When the object is downloaded as parts (rather than by ranges), the
544
- # part_sizes will not be known ahead of time and will be nil in the
545
- # callback until the first bytes in the part are received.
530
+ # A Proc that will be called when each chunk of the download is received. It will be invoked with
531
+ # `bytes_read`, `part_sizes`, `file_size`. When the object is downloaded as parts (rather than by ranges),
532
+ # the `part_sizes` will not be known ahead of time and will be `nil` in the callback until the first bytes
533
+ # in the part are received.
546
534
  #
547
- # @return [Boolean] Returns `true` when the file is downloaded without
548
- # any errors.
535
+ # @raise [MultipartDownloadError] Raised when an object validation fails outside of service errors.
536
+ #
537
+ # @return [Boolean] Returns `true` when the file is downloaded without any errors.
549
538
  #
550
539
  # @see Client#get_object
551
540
  # @see Client#head_object
552
541
  def download_file(destination, options = {})
553
- downloader = FileDownloader.new(client: client)
554
- Aws::Plugins::UserAgent.feature('resource') do
555
- downloader.download(
556
- destination,
557
- options.merge(bucket: bucket_name, key: key)
558
- )
542
+ download_opts = options.merge(bucket: bucket_name, key: key)
543
+ executor = DefaultExecutor.new(max_threads: download_opts.delete([:thread_count]))
544
+ downloader = FileDownloader.new(client: client, executor: executor)
545
+ Aws::Plugins::UserAgent.metric('RESOURCE_MODEL') do
546
+ downloader.download(destination, download_opts)
559
547
  end
548
+ executor.shutdown
560
549
  true
561
550
  end
551
+ deprecated(:download_file, use: 'Aws::S3::TransferManager#download_file', version: 'next major version')
552
+
553
+ class Collection < Aws::Resources::Collection
554
+ alias_method :delete, :batch_delete!
555
+ extend Aws::Deprecations
556
+ deprecated :delete, use: :batch_delete!
557
+ end
562
558
  end
563
559
  end
564
560
  end
@@ -80,6 +80,11 @@ module Aws
80
80
  object.download_file(destination, options)
81
81
  end
82
82
 
83
+ class Collection < Aws::Resources::Collection
84
+ alias_method :delete, :batch_delete!
85
+ extend Aws::Deprecations
86
+ deprecated :delete, use: :batch_delete!
87
+ end
83
88
  end
84
89
  end
85
90
  end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Aws
4
+ module S3
5
+ class ObjectVersion
6
+ class Collection < Aws::Resources::Collection
7
+ alias_method :delete, :batch_delete!
8
+ extend Aws::Deprecations
9
+ deprecated :delete, use: :batch_delete!
10
+ end
11
+ end
12
+ end
13
+ end
@@ -1,41 +1,33 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # utility classes
4
- require 'aws-sdk-s3/bucket_region_cache'
5
- require 'aws-sdk-s3/encryption'
6
- require 'aws-sdk-s3/encryption_v2'
7
- require 'aws-sdk-s3/file_part'
8
- require 'aws-sdk-s3/file_uploader'
9
- require 'aws-sdk-s3/file_downloader'
10
- require 'aws-sdk-s3/legacy_signer'
11
- require 'aws-sdk-s3/multipart_file_uploader'
12
- require 'aws-sdk-s3/multipart_stream_uploader'
13
- require 'aws-sdk-s3/multipart_upload_error'
14
- require 'aws-sdk-s3/object_copier'
15
- require 'aws-sdk-s3/object_multipart_copier'
16
- require 'aws-sdk-s3/presigned_post'
17
- require 'aws-sdk-s3/presigner'
3
+ module Aws
4
+ module S3
5
+ # utility classes
6
+ autoload :BucketRegionCache, 'aws-sdk-s3/bucket_region_cache'
7
+ autoload :Encryption, 'aws-sdk-s3/encryption'
8
+ autoload :EncryptionV2, 'aws-sdk-s3/encryption_v2'
9
+ autoload :EncryptionV3, 'aws-sdk-s3/encryption_v3'
10
+ autoload :FilePart, 'aws-sdk-s3/file_part'
11
+ autoload :DefaultExecutor, 'aws-sdk-s3/default_executor'
12
+ autoload :FileUploader, 'aws-sdk-s3/file_uploader'
13
+ autoload :FileDownloader, 'aws-sdk-s3/file_downloader'
14
+ autoload :LegacySigner, 'aws-sdk-s3/legacy_signer'
15
+ autoload :MultipartDownloadError, 'aws-sdk-s3/multipart_download_error'
16
+ autoload :MultipartFileUploader, 'aws-sdk-s3/multipart_file_uploader'
17
+ autoload :MultipartStreamUploader, 'aws-sdk-s3/multipart_stream_uploader'
18
+ autoload :MultipartUploadError, 'aws-sdk-s3/multipart_upload_error'
19
+ autoload :ObjectCopier, 'aws-sdk-s3/object_copier'
20
+ autoload :ObjectMultipartCopier, 'aws-sdk-s3/object_multipart_copier'
21
+ autoload :PresignedPost, 'aws-sdk-s3/presigned_post'
22
+ autoload :Presigner, 'aws-sdk-s3/presigner'
23
+ autoload :TransferManager, 'aws-sdk-s3/transfer_manager'
18
24
 
19
- # s3 express session auth
20
- require 'aws-sdk-s3/express_credentials'
21
- require 'aws-sdk-s3/express_credentials_cache'
22
- require 'aws-sdk-s3/express_credentials_provider'
25
+ # s3 express session auth
26
+ autoload :ExpressCredentials, 'aws-sdk-s3/express_credentials'
27
+ autoload :ExpressCredentialsProvider, 'aws-sdk-s3/express_credentials_provider'
23
28
 
24
- # customizations to generated classes
25
- require 'aws-sdk-s3/customizations/bucket'
26
- require 'aws-sdk-s3/customizations/errors'
27
- require 'aws-sdk-s3/customizations/object'
28
- require 'aws-sdk-s3/customizations/object_summary'
29
- require 'aws-sdk-s3/customizations/multipart_upload'
30
- require 'aws-sdk-s3/customizations/types/list_object_versions_output'
31
- require 'aws-sdk-s3/customizations/types/permanent_redirect'
32
-
33
- [
34
- Aws::S3::Object::Collection,
35
- Aws::S3::ObjectSummary::Collection,
36
- Aws::S3::ObjectVersion::Collection,
37
- ].each do |klass|
38
- klass.send(:alias_method, :delete, :batch_delete!)
39
- klass.extend Aws::Deprecations
40
- klass.send(:deprecated, :delete, use: :batch_delete!)
29
+ # s3 access grants auth
30
+ autoload :AccessGrantsCredentials, 'aws-sdk-s3/access_grants_credentials'
31
+ autoload :AccessGrantsCredentialsProvider, 'aws-sdk-s3/access_grants_credentials_provider'
32
+ end
41
33
  end
@@ -0,0 +1,103 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Aws
4
+ module S3
5
+ # @api private
6
+ class DefaultExecutor
7
+ DEFAULT_MAX_THREADS = 10
8
+ RUNNING = :running
9
+ SHUTTING_DOWN = :shutting_down
10
+ SHUTDOWN = :shutdown
11
+
12
+ def initialize(options = {})
13
+ @max_threads = options[:max_threads] || DEFAULT_MAX_THREADS
14
+ @state = RUNNING
15
+ @queue = Queue.new
16
+ @pool = []
17
+ @mutex = Mutex.new
18
+ end
19
+
20
+ # Submits a task for execution.
21
+ # @param [Object] args Variable number of arguments to pass to the block
22
+ # @param [Proc] block The block to be executed
23
+ # @return [Boolean] Returns true if the task was submitted successfully
24
+ def post(*args, &block)
25
+ @mutex.synchronize do
26
+ raise 'Executor has been shutdown and is no longer accepting tasks' unless @state == RUNNING
27
+
28
+ @queue << [args, block]
29
+ ensure_worker_available
30
+ end
31
+ true
32
+ end
33
+
34
+ # Immediately terminates all worker threads and clears pending tasks.
35
+ # This is a forceful shutdown that doesn't wait for running tasks to complete.
36
+ #
37
+ # @return [Boolean] true when termination is complete
38
+ def kill
39
+ @mutex.synchronize do
40
+ @state = SHUTDOWN
41
+ @pool.each(&:kill)
42
+ @pool.clear
43
+ @queue.clear
44
+ end
45
+ true
46
+ end
47
+
48
+ # Gracefully shuts down the executor, optionally with a timeout.
49
+ # Stops accepting new tasks and waits for running tasks to complete.
50
+ #
51
+ # @param timeout [Numeric, nil] Maximum time in seconds to wait for shutdown.
52
+ # If nil, waits indefinitely. If timeout expires, remaining threads are killed.
53
+ # @return [Boolean] true when shutdown is complete
54
+ def shutdown(timeout = nil)
55
+ @mutex.synchronize do
56
+ return true if @state == SHUTDOWN
57
+
58
+ @state = SHUTTING_DOWN
59
+ @pool.size.times { @queue << :shutdown }
60
+ end
61
+
62
+ if timeout
63
+ deadline = Time.now + timeout
64
+ @pool.each do |thread|
65
+ remaining = deadline - Time.now
66
+ break if remaining <= 0
67
+
68
+ thread.join([remaining, 0].max)
69
+ end
70
+ @pool.select(&:alive?).each(&:kill)
71
+ else
72
+ @pool.each(&:join)
73
+ end
74
+
75
+ @mutex.synchronize do
76
+ @pool.clear
77
+ @state = SHUTDOWN
78
+ end
79
+ true
80
+ end
81
+
82
+ private
83
+
84
+ def ensure_worker_available
85
+ return unless @state == RUNNING
86
+
87
+ @pool.select!(&:alive?)
88
+ @pool << spawn_worker if @pool.size < @max_threads
89
+ end
90
+
91
+ def spawn_worker
92
+ Thread.new do
93
+ while (job = @queue.shift)
94
+ break if job == :shutdown
95
+
96
+ args, block = job
97
+ block.call(*args)
98
+ end
99
+ end
100
+ end
101
+ end
102
+ end
103
+ end
@@ -6,9 +6,9 @@ module Aws
6
6
  module S3
7
7
 
8
8
  # [MAINTENANCE MODE] There is a new version of the Encryption Client.
9
- # AWS strongly recommends upgrading to the {Aws::S3::EncryptionV2::Client},
9
+ # AWS strongly recommends upgrading to the {Aws::S3::EncryptionV3::Client},
10
10
  # which provides updated data security best practices.
11
- # See documentation for {Aws::S3::EncryptionV2::Client}.
11
+ # See documentation for {Aws::S3::EncryptionV3::Client}.
12
12
  # Provides an encryption client that encrypts and decrypts data client-side,
13
13
  # storing the encrypted data in Amazon S3.
14
14
  #
@@ -270,7 +270,7 @@ module Aws
270
270
  envelope_location: @envelope_location,
271
271
  instruction_file_suffix: @instruction_file_suffix,
272
272
  }
273
- Aws::Plugins::UserAgent.feature('S3CryptoV1n') do
273
+ Aws::Plugins::UserAgent.metric('S3_CRYPTO_V1N') do
274
274
  req.send_request
275
275
  end
276
276
  end
@@ -300,7 +300,7 @@ module Aws
300
300
  envelope_location: envelope_location,
301
301
  instruction_file_suffix: instruction_file_suffix,
302
302
  }
303
- Aws::Plugins::UserAgent.feature('S3CryptoV1n') do
303
+ Aws::Plugins::UserAgent.metric('S3_CRYPTO_V1N') do
304
304
  req.send_request(target: block)
305
305
  end
306
306
  end
@@ -16,6 +16,8 @@ module Aws
16
16
  # envelope and encryption cipher.
17
17
  def encryption_cipher
18
18
  cipher = Utils.aes_encryption_cipher(:CBC)
19
+ ##= ../specification/s3-encryption/data-format/content-metadata.md#algorithm-suite-and-message-format-version-compatibility
20
+ ##% Objects encrypted with ALG_AES_256_CBC_IV16_NO_KDF MAY use either the V1 or V2 message format version.
19
21
  envelope = {
20
22
  'x-amz-key' => encode64(encrypt(envelope_key(cipher))),
21
23
  'x-amz-iv' => encode64(envelope_iv(cipher)),
@@ -38,6 +38,8 @@ module Aws
38
38
  io = StringIO.new(io) if String === io
39
39
  context.params[:body] = IOEncrypter.new(cipher, io)
40
40
  context.params[:metadata] ||= {}
41
+ ##= ../specification/s3-encryption/data-format/content-metadata.md#content-metadata-mapkeys
42
+ ##% - The mapkey "x-amz-unencrypted-content-length" SHOULD be present for V1 format objects.
41
43
  context.params[:metadata]['x-amz-unencrypted-content-length'] = io.size
42
44
  if context.params.delete(:content_md5)
43
45
  warn('Setting content_md5 on client side encrypted objects is deprecated')
@@ -17,7 +17,7 @@ module Aws
17
17
  # envelope and encryption cipher.
18
18
  def encryption_cipher
19
19
  encryption_context = { "kms_cmk_id" => @kms_key_id }
20
- key_data = Aws::Plugins::UserAgent.feature('S3CryptoV1n') do
20
+ key_data = Aws::Plugins::UserAgent.metric('S3_CRYPTO_V1N') do
21
21
  @kms_client.generate_data_key(
22
22
  key_id: @kms_key_id,
23
23
  encryption_context: encryption_context,
@@ -26,6 +26,8 @@ module Aws
26
26
  end
27
27
  cipher = Utils.aes_encryption_cipher(:CBC)
28
28
  cipher.key = key_data.plaintext
29
+ ##= ../specification/s3-encryption/data-format/content-metadata.md#algorithm-suite-and-message-format-version-compatibility
30
+ ##% Objects encrypted with ALG_AES_256_CBC_IV16_NO_KDF MAY use either the V1 or V2 message format version.
29
31
  envelope = {
30
32
  'x-amz-key-v2' => encode64(key_data.ciphertext_blob),
31
33
  'x-amz-iv' => encode64(cipher.iv = cipher.random_iv),
@@ -60,7 +62,7 @@ module Aws
60
62
  "#{envelope['x-amz-wrap-alg']}"
61
63
  end
62
64
 
63
- key = Aws::Plugins::UserAgent.feature('S3CryptoV1n') do
65
+ key = Aws::Plugins::UserAgent.metric('S3_CRYPTO_V1N') do
64
66
  @kms_client.decrypt(
65
67
  ciphertext_blob: decode64(envelope['x-amz-key-v2']),
66
68
  encryption_context: encryption_context