aws-sdk-s3 1.176.1 → 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 (99) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +202 -0
  3. data/VERSION +1 -1
  4. data/lib/aws-sdk-s3/bucket.rb +86 -35
  5. data/lib/aws-sdk-s3/bucket_acl.rb +7 -6
  6. data/lib/aws-sdk-s3/bucket_cors.rb +6 -5
  7. data/lib/aws-sdk-s3/bucket_lifecycle.rb +2 -2
  8. data/lib/aws-sdk-s3/bucket_lifecycle_configuration.rb +3 -3
  9. data/lib/aws-sdk-s3/bucket_logging.rb +2 -2
  10. data/lib/aws-sdk-s3/bucket_policy.rb +6 -5
  11. data/lib/aws-sdk-s3/bucket_request_payment.rb +3 -3
  12. data/lib/aws-sdk-s3/bucket_tagging.rb +3 -3
  13. data/lib/aws-sdk-s3/bucket_versioning.rb +42 -9
  14. data/lib/aws-sdk-s3/bucket_website.rb +3 -3
  15. data/lib/aws-sdk-s3/client.rb +3038 -1226
  16. data/lib/aws-sdk-s3/client_api.rb +492 -164
  17. data/lib/aws-sdk-s3/customizations/object.rb +76 -86
  18. data/lib/aws-sdk-s3/customizations.rb +4 -1
  19. data/lib/aws-sdk-s3/default_executor.rb +103 -0
  20. data/lib/aws-sdk-s3/encryption/client.rb +2 -2
  21. data/lib/aws-sdk-s3/encryption/default_cipher_provider.rb +2 -0
  22. data/lib/aws-sdk-s3/encryption/encrypt_handler.rb +2 -0
  23. data/lib/aws-sdk-s3/encryption/kms_cipher_provider.rb +2 -0
  24. data/lib/aws-sdk-s3/encryptionV2/client.rb +98 -23
  25. data/lib/aws-sdk-s3/encryptionV2/decrypt_handler.rb +7 -162
  26. data/lib/aws-sdk-s3/encryptionV2/decryption.rb +205 -0
  27. data/lib/aws-sdk-s3/encryptionV2/default_cipher_provider.rb +17 -0
  28. data/lib/aws-sdk-s3/encryptionV2/encrypt_handler.rb +2 -0
  29. data/lib/aws-sdk-s3/encryptionV2/io_encrypter.rb +2 -0
  30. data/lib/aws-sdk-s3/encryptionV2/kms_cipher_provider.rb +8 -0
  31. data/lib/aws-sdk-s3/encryptionV2/utils.rb +5 -0
  32. data/lib/aws-sdk-s3/encryptionV3/client.rb +885 -0
  33. data/lib/aws-sdk-s3/encryptionV3/decrypt_handler.rb +98 -0
  34. data/lib/aws-sdk-s3/encryptionV3/decryption.rb +244 -0
  35. data/lib/aws-sdk-s3/encryptionV3/default_cipher_provider.rb +159 -0
  36. data/lib/aws-sdk-s3/encryptionV3/default_key_provider.rb +35 -0
  37. data/lib/aws-sdk-s3/encryptionV3/encrypt_handler.rb +98 -0
  38. data/lib/aws-sdk-s3/encryptionV3/errors.rb +47 -0
  39. data/lib/aws-sdk-s3/encryptionV3/io_auth_decrypter.rb +60 -0
  40. data/lib/aws-sdk-s3/encryptionV3/io_decrypter.rb +35 -0
  41. data/lib/aws-sdk-s3/encryptionV3/io_encrypter.rb +84 -0
  42. data/lib/aws-sdk-s3/encryptionV3/key_provider.rb +28 -0
  43. data/lib/aws-sdk-s3/encryptionV3/kms_cipher_provider.rb +159 -0
  44. data/lib/aws-sdk-s3/encryptionV3/materials.rb +58 -0
  45. data/lib/aws-sdk-s3/encryptionV3/utils.rb +321 -0
  46. data/lib/aws-sdk-s3/encryption_v2.rb +1 -0
  47. data/lib/aws-sdk-s3/encryption_v3.rb +24 -0
  48. data/lib/aws-sdk-s3/endpoint_parameters.rb +17 -17
  49. data/lib/aws-sdk-s3/endpoint_provider.rb +562 -304
  50. data/lib/aws-sdk-s3/endpoints.rb +110 -0
  51. data/lib/aws-sdk-s3/errors.rb +11 -0
  52. data/lib/aws-sdk-s3/file_downloader.rb +189 -143
  53. data/lib/aws-sdk-s3/file_uploader.rb +9 -13
  54. data/lib/aws-sdk-s3/legacy_signer.rb +2 -1
  55. data/lib/aws-sdk-s3/multipart_download_error.rb +8 -0
  56. data/lib/aws-sdk-s3/multipart_file_uploader.rb +105 -102
  57. data/lib/aws-sdk-s3/multipart_stream_uploader.rb +96 -107
  58. data/lib/aws-sdk-s3/multipart_upload.rb +50 -6
  59. data/lib/aws-sdk-s3/multipart_upload_error.rb +3 -4
  60. data/lib/aws-sdk-s3/multipart_upload_part.rb +50 -34
  61. data/lib/aws-sdk-s3/object.rb +264 -137
  62. data/lib/aws-sdk-s3/object_acl.rb +12 -6
  63. data/lib/aws-sdk-s3/object_multipart_copier.rb +2 -1
  64. data/lib/aws-sdk-s3/object_summary.rb +179 -103
  65. data/lib/aws-sdk-s3/object_version.rb +25 -23
  66. data/lib/aws-sdk-s3/plugins/checksum_algorithm.rb +31 -0
  67. data/lib/aws-sdk-s3/plugins/endpoints.rb +1 -1
  68. data/lib/aws-sdk-s3/plugins/express_session_auth.rb +11 -20
  69. data/lib/aws-sdk-s3/plugins/md5s.rb +10 -71
  70. data/lib/aws-sdk-s3/plugins/streaming_retry.rb +5 -7
  71. data/lib/aws-sdk-s3/plugins/url_encoded_keys.rb +2 -1
  72. data/lib/aws-sdk-s3/presigner.rb +4 -5
  73. data/lib/aws-sdk-s3/resource.rb +7 -1
  74. data/lib/aws-sdk-s3/transfer_manager.rb +303 -0
  75. data/lib/aws-sdk-s3/types.rb +2907 -1059
  76. data/lib/aws-sdk-s3.rb +1 -1
  77. data/sig/bucket.rbs +16 -6
  78. data/sig/bucket_acl.rbs +1 -1
  79. data/sig/bucket_cors.rbs +1 -1
  80. data/sig/bucket_lifecycle.rbs +1 -1
  81. data/sig/bucket_lifecycle_configuration.rbs +1 -1
  82. data/sig/bucket_logging.rbs +1 -1
  83. data/sig/bucket_policy.rbs +1 -1
  84. data/sig/bucket_request_payment.rbs +1 -1
  85. data/sig/bucket_tagging.rbs +1 -1
  86. data/sig/bucket_versioning.rbs +3 -3
  87. data/sig/bucket_website.rbs +1 -1
  88. data/sig/client.rbs +226 -64
  89. data/sig/errors.rbs +2 -0
  90. data/sig/multipart_upload.rbs +9 -2
  91. data/sig/multipart_upload_part.rbs +5 -1
  92. data/sig/object.rbs +31 -15
  93. data/sig/object_acl.rbs +1 -1
  94. data/sig/object_summary.rbs +22 -15
  95. data/sig/object_version.rbs +5 -2
  96. data/sig/resource.rbs +11 -2
  97. data/sig/types.rbs +281 -64
  98. metadata +26 -10
  99. data/lib/aws-sdk-s3/plugins/skip_whole_multipart_get_checksums.rb +0 -31
@@ -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
394
  Aws::Plugins::UserAgent.metric('RESOURCE_MODEL') do
394
- uploader.upload(
395
- uploading_options.merge(bucket: bucket_name, key: key),
396
- &block
397
- )
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
467
  response = Aws::Plugins::UserAgent.metric('RESOURCE_MODEL') do
477
- uploader.upload(
478
- source,
479
- uploading_options.merge(bucket: bucket_name, key: key)
480
- )
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,67 @@ 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.
534
+ #
535
+ # @raise [MultipartDownloadError] Raised when an object validation fails outside of service errors.
546
536
  #
547
- # @return [Boolean] Returns `true` when the file is downloaded without
548
- # any errors.
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)
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)
554
545
  Aws::Plugins::UserAgent.metric('RESOURCE_MODEL') do
555
- downloader.download(
556
- destination,
557
- options.merge(bucket: bucket_name, key: key)
558
- )
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')
562
552
 
563
553
  class Collection < Aws::Resources::Collection
564
554
  alias_method :delete, :batch_delete!
@@ -6,10 +6,13 @@ module Aws
6
6
  autoload :BucketRegionCache, 'aws-sdk-s3/bucket_region_cache'
7
7
  autoload :Encryption, 'aws-sdk-s3/encryption'
8
8
  autoload :EncryptionV2, 'aws-sdk-s3/encryption_v2'
9
+ autoload :EncryptionV3, 'aws-sdk-s3/encryption_v3'
9
10
  autoload :FilePart, 'aws-sdk-s3/file_part'
11
+ autoload :DefaultExecutor, 'aws-sdk-s3/default_executor'
10
12
  autoload :FileUploader, 'aws-sdk-s3/file_uploader'
11
13
  autoload :FileDownloader, 'aws-sdk-s3/file_downloader'
12
14
  autoload :LegacySigner, 'aws-sdk-s3/legacy_signer'
15
+ autoload :MultipartDownloadError, 'aws-sdk-s3/multipart_download_error'
13
16
  autoload :MultipartFileUploader, 'aws-sdk-s3/multipart_file_uploader'
14
17
  autoload :MultipartStreamUploader, 'aws-sdk-s3/multipart_stream_uploader'
15
18
  autoload :MultipartUploadError, 'aws-sdk-s3/multipart_upload_error'
@@ -17,13 +20,13 @@ module Aws
17
20
  autoload :ObjectMultipartCopier, 'aws-sdk-s3/object_multipart_copier'
18
21
  autoload :PresignedPost, 'aws-sdk-s3/presigned_post'
19
22
  autoload :Presigner, 'aws-sdk-s3/presigner'
23
+ autoload :TransferManager, 'aws-sdk-s3/transfer_manager'
20
24
 
21
25
  # s3 express session auth
22
26
  autoload :ExpressCredentials, 'aws-sdk-s3/express_credentials'
23
27
  autoload :ExpressCredentialsProvider, 'aws-sdk-s3/express_credentials_provider'
24
28
 
25
29
  # s3 access grants auth
26
-
27
30
  autoload :AccessGrantsCredentials, 'aws-sdk-s3/access_grants_credentials'
28
31
  autoload :AccessGrantsCredentialsProvider, 'aws-sdk-s3/access_grants_credentials_provider'
29
32
  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
  #
@@ -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')
@@ -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),
@@ -5,9 +5,17 @@ require 'forwardable'
5
5
  module Aws
6
6
  module S3
7
7
 
8
- REQUIRED_PARAMS = [:key_wrap_schema, :content_encryption_schema, :security_profile]
9
- SUPPORTED_SECURITY_PROFILES = [:v2, :v2_and_legacy]
8
+ REQUIRED_PARAMS = [:key_wrap_schema, :content_encryption_schema, :security_profile].freeze
9
+ SUPPORTED_SECURITY_PROFILES = [:v2, :v2_and_legacy].freeze
10
+ SUPPORTED_COMMITMENT_POLICIES = [:forbid_encrypt_allow_decrypt].freeze
10
11
 
12
+ # [MAINTENANCE MODE] There is a new version of the Encryption Client.
13
+ # AWS strongly recommends upgrading to the {Aws::S3::EncryptionV3::Client},
14
+ # which provides updated data security best practices.
15
+ # For migration guidance, see: https://docs.aws.amazon.com/sdk-for-ruby/v3/developer-guide/s3-encryption-migration-v2-v3.html
16
+ # Provides an encryption client that encrypts and decrypts data client-side,
17
+ # storing the encrypted data in Amazon S3.
18
+ #
11
19
  # Provides an encryption client that encrypts and decrypts data client-side,
12
20
  # storing the encrypted data in Amazon S3. The `EncryptionV2::Client` (V2 Client)
13
21
  # provides improved security over the `Encryption::Client` (V1 Client)
@@ -307,15 +315,29 @@ module Aws
307
315
  # @option options [KMS::Client] :kms_client A default {KMS::Client}
308
316
  # is constructed when using KMS to manage encryption keys.
309
317
  #
318
+ # @option options [Symbol] :commitment_policy (nil)
319
+ # Optional parameter for migration from V2 to V3. When set to
320
+ # :forbid_encrypt_allow_decrypt, this explicitly indicates you are
321
+ # maintaining V2 encryption behavior while preparing for migration.
322
+ # This allows the V2 client to decrypt V3-encrypted objects while
323
+ # continuing to encrypt new objects using V2 algorithms.
324
+ # Only :forbid_encrypt_allow_decrypt is supported.
325
+ # For migration guidance, see: https://docs.aws.amazon.com/sdk-for-ruby/v3/developer-guide/s3-encryption-migration-v2-v3.html
326
+ #
310
327
  def initialize(options = {})
311
328
  validate_params(options)
312
329
  @client = extract_client(options)
313
- @cipher_provider = cipher_provider(options)
330
+ @cipher_provider = build_cipher_provider(options)
331
+ @key_provider = @cipher_provider.key_provider if @cipher_provider.is_a?(DefaultCipherProvider)
314
332
  @envelope_location = extract_location(options)
315
333
  @instruction_file_suffix = extract_suffix(options)
316
334
  @kms_allow_decrypt_with_any_cmk =
317
335
  options[:kms_key_id] == :kms_allow_decrypt_with_any_cmk
318
336
  @security_profile = extract_security_profile(options)
337
+ @commitment_policy = extract_commitment_policy(options)
338
+ # The v3 cipher is only used for decrypt.
339
+ # Therefore any configured v2 `content_encryption_schema` is going to be incorrect.
340
+ @v3_cipher_provider = build_v3_cipher_provider_for_decrypt(options.reject { |k, _| k == :content_encryption_schema })
319
341
  end
320
342
 
321
343
  # @return [S3::Client]
@@ -341,6 +363,11 @@ module Aws
341
363
  # by this string.
342
364
  attr_reader :instruction_file_suffix
343
365
 
366
+ # @return [Symbol, nil] Optional commitment policy for V2 to V3 migration.
367
+ # When set to :forbid_encrypt_allow_decrypt, explicitly indicates
368
+ # maintaining V2 encryption behavior while preparing for migration.
369
+ attr_reader :commitment_policy
370
+
344
371
  # Uploads an object to Amazon S3, encrypting data client-side.
345
372
  # See {S3::Client#put_object} for documentation on accepted
346
373
  # request parameters.
@@ -410,6 +437,7 @@ module Aws
410
437
  req.handlers.add(DecryptHandler)
411
438
  req.context[:encryption] = {
412
439
  cipher_provider: @cipher_provider,
440
+ v3_cipher_provider: @v3_cipher_provider,
413
441
  envelope_location: envelope_location,
414
442
  instruction_file_suffix: instruction_file_suffix,
415
443
  kms_encryption_context: kms_encryption_context,
@@ -423,6 +451,50 @@ module Aws
423
451
 
424
452
  private
425
453
 
454
+ def build_cipher_provider(options)
455
+ if options[:kms_key_id]
456
+ KmsCipherProvider.new(
457
+ kms_key_id: options[:kms_key_id],
458
+ kms_client: kms_client(options),
459
+ key_wrap_schema: options[:key_wrap_schema],
460
+ content_encryption_schema: options[:content_encryption_schema]
461
+ )
462
+ else
463
+ key_provider = extract_key_provider(options)
464
+ DefaultCipherProvider.new(
465
+ key_provider: key_provider,
466
+ key_wrap_schema: options[:key_wrap_schema],
467
+ content_encryption_schema: options[:content_encryption_schema]
468
+ )
469
+ end
470
+ end
471
+
472
+ def build_v3_cipher_provider_for_decrypt(options)
473
+ if options[:kms_key_id]
474
+ Aws::S3::EncryptionV3::KmsCipherProvider.new(
475
+ kms_key_id: options[:kms_key_id],
476
+ kms_client: kms_client(options),
477
+ key_wrap_schema: options[:key_wrap_schema],
478
+ content_encryption_schema: options[:content_encryption_schema]
479
+ )
480
+ else
481
+ # Create V3 key provider explicitly for proper namespace consistency
482
+ key_provider = if options[:key_provider]
483
+ options[:key_provider]
484
+ elsif options[:encryption_key]
485
+ Aws::S3::EncryptionV3::DefaultKeyProvider.new(options)
486
+ else
487
+ msg = 'you must pass a :kms_key_id, :key_provider, or :encryption_key'
488
+ raise ArgumentError, msg
489
+ end
490
+ Aws::S3::EncryptionV3::DefaultCipherProvider.new(
491
+ key_provider: key_provider,
492
+ key_wrap_schema: options[:key_wrap_schema],
493
+ content_encryption_schema: options[:content_encryption_schema]
494
+ )
495
+ end
496
+ end
497
+
426
498
  # Validate required parameters exist and don't conflict.
427
499
  # The cek_alg and wrap_alg are passed on to the CipherProviders
428
500
  # and further validated there
@@ -452,36 +524,19 @@ module Aws
452
524
  options.delete(:encryption_key)
453
525
  options.delete(:envelope_location)
454
526
  options.delete(:instruction_file_suffix)
527
+ options.delete(:commitment_policy)
455
528
  REQUIRED_PARAMS.each { |p| options.delete(p) }
456
529
  S3::Client.new(options)
457
530
  end
458
531
  end
459
532
 
460
533
  def kms_client(options)
461
- options[:kms_client] || begin
534
+ options[:kms_client] || (@kms_client ||=
462
535
  KMS::Client.new(
463
536
  region: @client.config.region,
464
537
  credentials: @client.config.credentials,
465
538
  )
466
- end
467
- end
468
-
469
- def cipher_provider(options)
470
- if options[:kms_key_id]
471
- KmsCipherProvider.new(
472
- kms_key_id: options[:kms_key_id],
473
- kms_client: kms_client(options),
474
- key_wrap_schema: options[:key_wrap_schema],
475
- content_encryption_schema: options[:content_encryption_schema]
476
- )
477
- else
478
- @key_provider = extract_key_provider(options)
479
- DefaultCipherProvider.new(
480
- key_provider: @key_provider,
481
- key_wrap_schema: options[:key_wrap_schema],
482
- content_encryption_schema: options[:content_encryption_schema]
483
- )
484
- end
539
+ )
485
540
  end
486
541
 
487
542
  def extract_key_provider(options)
@@ -564,7 +619,27 @@ module Aws
564
619
  end
565
620
  security_profile
566
621
  end
622
+
623
+ def extract_commitment_policy(options)
624
+ validate_commitment_policy(options[:commitment_policy])
625
+ end
626
+
627
+ def validate_commitment_policy(commitment_policy)
628
+ return nil if commitment_policy.nil?
629
+
630
+ unless SUPPORTED_COMMITMENT_POLICIES.include? commitment_policy
631
+ raise ArgumentError, "Unsupported commitment policy: :#{commitment_policy}. " \
632
+ "The V2 client only supports :forbid_encrypt_allow_decrypt for migration purposes. " \
633
+ "For migration guidance, see: https://docs.aws.amazon.com/sdk-for-ruby/v3/developer-guide/s3-encryption-migration-v2-v3.html"
634
+ end
635
+ commitment_policy
636
+ end
567
637
  end
568
638
  end
569
639
  end
570
640
  end
641
+
642
+ ##= ../specification/s3-encryption/data-format/content-metadata.md#v1-v2-shared
643
+ ##= type=exception
644
+ ##= reason=This has never been supported in Ruby
645
+ ##% This string MAY be encoded by the esoteric double-encoding scheme used by the S3 web server.