aws-sdk-s3 1.79.1 → 1.212.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 (133) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +1548 -0
  3. data/LICENSE.txt +202 -0
  4. data/VERSION +1 -0
  5. data/lib/aws-sdk-s3/access_grants_credentials.rb +57 -0
  6. data/lib/aws-sdk-s3/access_grants_credentials_provider.rb +250 -0
  7. data/lib/aws-sdk-s3/bucket.rb +900 -98
  8. data/lib/aws-sdk-s3/bucket_acl.rb +44 -10
  9. data/lib/aws-sdk-s3/bucket_cors.rb +51 -11
  10. data/lib/aws-sdk-s3/bucket_lifecycle.rb +53 -8
  11. data/lib/aws-sdk-s3/bucket_lifecycle_configuration.rb +107 -9
  12. data/lib/aws-sdk-s3/bucket_logging.rb +43 -6
  13. data/lib/aws-sdk-s3/bucket_notification.rb +32 -9
  14. data/lib/aws-sdk-s3/bucket_policy.rb +90 -6
  15. data/lib/aws-sdk-s3/bucket_region_cache.rb +9 -5
  16. data/lib/aws-sdk-s3/bucket_request_payment.rb +38 -8
  17. data/lib/aws-sdk-s3/bucket_tagging.rb +46 -7
  18. data/lib/aws-sdk-s3/bucket_versioning.rb +127 -9
  19. data/lib/aws-sdk-s3/bucket_website.rb +46 -7
  20. data/lib/aws-sdk-s3/client.rb +13729 -3146
  21. data/lib/aws-sdk-s3/client_api.rb +1604 -277
  22. data/lib/aws-sdk-s3/customizations/bucket.rb +31 -47
  23. data/lib/aws-sdk-s3/customizations/errors.rb +40 -0
  24. data/lib/aws-sdk-s3/customizations/object.rb +253 -82
  25. data/lib/aws-sdk-s3/customizations/object_summary.rb +5 -0
  26. data/lib/aws-sdk-s3/customizations/object_version.rb +13 -0
  27. data/lib/aws-sdk-s3/customizations/types/permanent_redirect.rb +26 -0
  28. data/lib/aws-sdk-s3/customizations.rb +28 -29
  29. data/lib/aws-sdk-s3/default_executor.rb +103 -0
  30. data/lib/aws-sdk-s3/encryption/client.rb +9 -5
  31. data/lib/aws-sdk-s3/encryption/decrypt_handler.rb +0 -4
  32. data/lib/aws-sdk-s3/encryption/default_cipher_provider.rb +2 -0
  33. data/lib/aws-sdk-s3/encryption/encrypt_handler.rb +2 -0
  34. data/lib/aws-sdk-s3/encryption/kms_cipher_provider.rb +15 -9
  35. data/lib/aws-sdk-s3/encryptionV2/client.rb +105 -26
  36. data/lib/aws-sdk-s3/encryptionV2/decrypt_handler.rb +7 -165
  37. data/lib/aws-sdk-s3/encryptionV2/decryption.rb +205 -0
  38. data/lib/aws-sdk-s3/encryptionV2/default_cipher_provider.rb +20 -3
  39. data/lib/aws-sdk-s3/encryptionV2/encrypt_handler.rb +2 -4
  40. data/lib/aws-sdk-s3/encryptionV2/io_encrypter.rb +2 -0
  41. data/lib/aws-sdk-s3/encryptionV2/kms_cipher_provider.rb +18 -6
  42. data/lib/aws-sdk-s3/encryptionV2/utils.rb +5 -0
  43. data/lib/aws-sdk-s3/encryptionV3/client.rb +885 -0
  44. data/lib/aws-sdk-s3/encryptionV3/decrypt_handler.rb +98 -0
  45. data/lib/aws-sdk-s3/encryptionV3/decryption.rb +244 -0
  46. data/lib/aws-sdk-s3/encryptionV3/default_cipher_provider.rb +159 -0
  47. data/lib/aws-sdk-s3/encryptionV3/default_key_provider.rb +35 -0
  48. data/lib/aws-sdk-s3/encryptionV3/encrypt_handler.rb +98 -0
  49. data/lib/aws-sdk-s3/encryptionV3/errors.rb +47 -0
  50. data/lib/aws-sdk-s3/encryptionV3/io_auth_decrypter.rb +60 -0
  51. data/lib/aws-sdk-s3/encryptionV3/io_decrypter.rb +35 -0
  52. data/lib/aws-sdk-s3/encryptionV3/io_encrypter.rb +84 -0
  53. data/lib/aws-sdk-s3/encryptionV3/key_provider.rb +28 -0
  54. data/lib/aws-sdk-s3/encryptionV3/kms_cipher_provider.rb +159 -0
  55. data/lib/aws-sdk-s3/encryptionV3/materials.rb +58 -0
  56. data/lib/aws-sdk-s3/encryptionV3/utils.rb +321 -0
  57. data/lib/aws-sdk-s3/encryption_v2.rb +1 -0
  58. data/lib/aws-sdk-s3/encryption_v3.rb +24 -0
  59. data/lib/aws-sdk-s3/endpoint_parameters.rb +181 -0
  60. data/lib/aws-sdk-s3/endpoint_provider.rb +889 -0
  61. data/lib/aws-sdk-s3/endpoints.rb +1544 -0
  62. data/lib/aws-sdk-s3/errors.rb +80 -1
  63. data/lib/aws-sdk-s3/event_streams.rb +1 -1
  64. data/lib/aws-sdk-s3/express_credentials.rb +55 -0
  65. data/lib/aws-sdk-s3/express_credentials_provider.rb +59 -0
  66. data/lib/aws-sdk-s3/file_downloader.rb +258 -82
  67. data/lib/aws-sdk-s3/file_uploader.rb +25 -14
  68. data/lib/aws-sdk-s3/legacy_signer.rb +17 -26
  69. data/lib/aws-sdk-s3/multipart_download_error.rb +8 -0
  70. data/lib/aws-sdk-s3/multipart_file_uploader.rb +111 -86
  71. data/lib/aws-sdk-s3/multipart_stream_uploader.rb +110 -92
  72. data/lib/aws-sdk-s3/multipart_upload.rb +304 -14
  73. data/lib/aws-sdk-s3/multipart_upload_error.rb +3 -4
  74. data/lib/aws-sdk-s3/multipart_upload_part.rb +344 -20
  75. data/lib/aws-sdk-s3/object.rb +2457 -225
  76. data/lib/aws-sdk-s3/object_acl.rb +76 -15
  77. data/lib/aws-sdk-s3/object_copier.rb +7 -5
  78. data/lib/aws-sdk-s3/object_multipart_copier.rb +48 -23
  79. data/lib/aws-sdk-s3/object_summary.rb +2033 -169
  80. data/lib/aws-sdk-s3/object_version.rb +470 -53
  81. data/lib/aws-sdk-s3/plugins/accelerate.rb +1 -39
  82. data/lib/aws-sdk-s3/plugins/access_grants.rb +178 -0
  83. data/lib/aws-sdk-s3/plugins/arn.rb +70 -0
  84. data/lib/aws-sdk-s3/plugins/bucket_dns.rb +3 -41
  85. data/lib/aws-sdk-s3/plugins/bucket_name_restrictions.rb +1 -6
  86. data/lib/aws-sdk-s3/plugins/checksum_algorithm.rb +44 -0
  87. data/lib/aws-sdk-s3/plugins/dualstack.rb +2 -49
  88. data/lib/aws-sdk-s3/plugins/endpoints.rb +86 -0
  89. data/lib/aws-sdk-s3/plugins/expect_100_continue.rb +3 -1
  90. data/lib/aws-sdk-s3/plugins/express_session_auth.rb +88 -0
  91. data/lib/aws-sdk-s3/plugins/get_bucket_location_fix.rb +1 -1
  92. data/lib/aws-sdk-s3/plugins/http_200_errors.rb +87 -26
  93. data/lib/aws-sdk-s3/plugins/iad_regional_endpoint.rb +8 -26
  94. data/lib/aws-sdk-s3/plugins/location_constraint.rb +3 -1
  95. data/lib/aws-sdk-s3/plugins/md5s.rb +10 -68
  96. data/lib/aws-sdk-s3/plugins/s3_signer.rb +48 -88
  97. data/lib/aws-sdk-s3/plugins/streaming_retry.rb +28 -9
  98. data/lib/aws-sdk-s3/plugins/url_encoded_keys.rb +2 -1
  99. data/lib/aws-sdk-s3/presigned_post.rb +99 -78
  100. data/lib/aws-sdk-s3/presigner.rb +50 -42
  101. data/lib/aws-sdk-s3/resource.rb +144 -15
  102. data/lib/aws-sdk-s3/transfer_manager.rb +321 -0
  103. data/lib/aws-sdk-s3/types.rb +12223 -4723
  104. data/lib/aws-sdk-s3/waiters.rb +1 -1
  105. data/lib/aws-sdk-s3.rb +37 -28
  106. data/sig/bucket.rbs +231 -0
  107. data/sig/bucket_acl.rbs +78 -0
  108. data/sig/bucket_cors.rbs +69 -0
  109. data/sig/bucket_lifecycle.rbs +88 -0
  110. data/sig/bucket_lifecycle_configuration.rbs +115 -0
  111. data/sig/bucket_logging.rbs +76 -0
  112. data/sig/bucket_notification.rbs +114 -0
  113. data/sig/bucket_policy.rbs +59 -0
  114. data/sig/bucket_request_payment.rbs +54 -0
  115. data/sig/bucket_tagging.rbs +65 -0
  116. data/sig/bucket_versioning.rbs +77 -0
  117. data/sig/bucket_website.rbs +93 -0
  118. data/sig/client.rbs +2612 -0
  119. data/sig/customizations/bucket.rbs +19 -0
  120. data/sig/customizations/object.rbs +38 -0
  121. data/sig/customizations/object_summary.rbs +35 -0
  122. data/sig/errors.rbs +44 -0
  123. data/sig/multipart_upload.rbs +120 -0
  124. data/sig/multipart_upload_part.rbs +109 -0
  125. data/sig/object.rbs +464 -0
  126. data/sig/object_acl.rbs +86 -0
  127. data/sig/object_summary.rbs +347 -0
  128. data/sig/object_version.rbs +143 -0
  129. data/sig/resource.rbs +141 -0
  130. data/sig/types.rbs +2899 -0
  131. data/sig/waiters.rbs +95 -0
  132. metadata +74 -16
  133. data/lib/aws-sdk-s3/plugins/bucket_arn.rb +0 -212
@@ -5,23 +5,6 @@ require 'uri'
5
5
  module Aws
6
6
  module S3
7
7
  class Bucket
8
- # Save the old initialize method so that we can call 'super'.
9
- old_initialize = instance_method(:initialize)
10
- # Make the method redefinable
11
- alias_method :initialize, :initialize
12
- # Define a new initialize method that extracts out a bucket ARN.
13
- define_method(:initialize) do |*args|
14
- old_initialize.bind(self).call(*args)
15
- bucket_name, region, arn = Plugins::BucketARN.resolve_arn!(
16
- name,
17
- client.config.region,
18
- client.config.s3_use_arn_region
19
- )
20
- @name = bucket_name
21
- @client.config.region = region
22
- @arn = arn
23
- end
24
-
25
8
  # Deletes all objects and versioned objects from this bucket
26
9
  #
27
10
  # @example
@@ -89,22 +72,44 @@ module Aws
89
72
  # You can pass `virtual_host: true` to use the bucket name as the
90
73
  # host name.
91
74
  #
92
- # bucket = s3.bucket('my.bucket.com')
75
+ # bucket = s3.bucket('my-bucket.com')
93
76
  # bucket.url(virtual_host: true)
94
- # #=> "http://my.bucket.com"
77
+ # #=> "http://my-bucket.com"
95
78
  #
96
79
  # @option options [Boolean] :virtual_host (false) When `true`,
97
80
  # the bucket name will be used as the host name. This is useful
98
81
  # when you have a CNAME configured for this bucket.
99
82
  #
83
+ # @option options [Boolean] :secure (true) When `false`, http
84
+ # will be used with virtual_host. This is required when
85
+ # the bucket name has a dot (.) in it.
86
+ #
100
87
  # @return [String] the URL for this bucket.
101
88
  def url(options = {})
102
89
  if options[:virtual_host]
103
- "http://#{name}"
104
- elsif @arn
105
- Plugins::BucketARN.resolve_url!(URI.parse(s3_bucket_url), @arn).to_s
90
+ scheme = options.fetch(:secure, true) ? 'https' : 'http'
91
+ "#{scheme}://#{name}"
106
92
  else
107
- s3_bucket_url
93
+ # Taken from Aws::S3::Endpoints module
94
+ unless client.config.regional_endpoint
95
+ endpoint = client.config.endpoint.to_s
96
+ end
97
+ params = Aws::S3::EndpointParameters.new(
98
+ bucket: name,
99
+ region: client.config.region,
100
+ use_fips: client.config.use_fips_endpoint,
101
+ use_dual_stack: client.config.use_dualstack_endpoint,
102
+ endpoint: endpoint,
103
+ force_path_style: client.config.force_path_style,
104
+ accelerate: client.config.use_accelerate_endpoint,
105
+ use_global_endpoint: client.config.s3_us_east_1_regional_endpoint == 'legacy',
106
+ use_object_lambda_endpoint: nil,
107
+ disable_access_points: nil,
108
+ disable_multi_region_access_points: client.config.s3_disable_multiregion_access_points,
109
+ use_arn_region: client.config.s3_use_arn_region,
110
+ )
111
+ endpoint = Aws::S3::EndpointProvider.new.resolve_endpoint(params)
112
+ endpoint.url
108
113
  end
109
114
  end
110
115
 
@@ -129,34 +134,13 @@ module Aws
129
134
 
130
135
  # @api private
131
136
  def load
132
- @data = client.list_buckets.buckets.find { |b| b.name == name }
137
+ @data = Aws::Plugins::UserAgent.metric('RESOURCE_MODEL') do
138
+ client.list_buckets.buckets.find { |b| b.name == name }
139
+ end
133
140
  raise "unable to load bucket #{name}" if @data.nil?
134
141
 
135
142
  self
136
143
  end
137
-
138
- private
139
-
140
- def s3_bucket_url
141
- url = client.config.endpoint.dup
142
- if bucket_as_hostname?(url.scheme == 'https')
143
- url.host = "#{name}.#{url.host}"
144
- else
145
- url.path += '/' unless url.path[-1] == '/'
146
- url.path += Seahorse::Util.uri_escape(name)
147
- end
148
- if (client.config.region == 'us-east-1') &&
149
- (client.config.s3_us_east_1_regional_endpoint == 'legacy')
150
- url.host = Plugins::IADRegionalEndpoint.legacy_host(url.host)
151
- end
152
- url.to_s
153
- end
154
-
155
- def bucket_as_hostname?(https)
156
- Plugins::BucketDns.dns_compatible?(name, https) &&
157
- !client.config.force_path_style
158
- end
159
-
160
144
  end
161
145
  end
162
146
  end
@@ -0,0 +1,40 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Aws
4
+ module S3
5
+ module Errors
6
+ # Hijack PermanentRedirect dynamic error to include the bucket, region,
7
+ # and endpoint.
8
+ class PermanentRedirect < ServiceError
9
+ # @param [Seahorse::Client::RequestContext] context
10
+ # @param [String] message
11
+ # @param [Aws::S3::Types::PermanentRedirect] _data
12
+ def initialize(context, message, _data = Aws::EmptyStructure.new)
13
+ data = Aws::S3::Types::PermanentRedirect.new(message: message)
14
+ body = context.http_response.body_contents
15
+ if (endpoint = body.match(/<Endpoint>(.+?)<\/Endpoint>/))
16
+ data.endpoint = endpoint[1]
17
+ end
18
+ if (bucket = body.match(/<Bucket>(.+?)<\/Bucket>/))
19
+ data.bucket = bucket[1]
20
+ end
21
+ data.region = context.http_response.headers['x-amz-bucket-region']
22
+ super(context, message, data)
23
+ end
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
38
+ end
39
+ end
40
+ end
@@ -27,10 +27,13 @@ module Aws
27
27
  # necessary for objects larger than 5GB and can provide
28
28
  # performance improvements on large objects. Amazon S3 does
29
29
  # not accept multipart copies for objects smaller than 5MB.
30
+ # Object metadata such as Content-Type will be copied, however,
31
+ # Checksums are not copied.
30
32
  #
31
33
  # @option options [Integer] :content_length Only used when
32
34
  # `:multipart_copy` is `true`. Passing this options avoids a HEAD
33
- # request to query the source object size. Raises an `ArgumentError` if
35
+ # request to query the source object size but prevents object metadata
36
+ # from being copied. Raises an `ArgumentError` if
34
37
  # this option is provided when `:multipart_copy` is `false` or not set.
35
38
  #
36
39
  # @option options [S3::Client] :copy_source_client Only used when
@@ -43,6 +46,14 @@ module Aws
43
46
  # different region. You do not need to specify this option
44
47
  # if you have provided a `:source_client` or a `:content_length`.
45
48
  #
49
+ # @option options [Boolean] :use_source_parts (false) Only used when
50
+ # `:multipart_copy` is `true`. Use part sizes defined on the source
51
+ # object if any exist. If copying or moving an object that
52
+ # is already multipart, this does not re-part the object, instead
53
+ # re-using the part definitions on the original. That means the etag
54
+ # and any checksums will not change. This is especially useful if the
55
+ # source object has parts with varied sizes.
56
+ #
46
57
  # @example Basic object copy
47
58
  #
48
59
  # bucket = Aws::S3::Bucket.new('target-bucket')
@@ -65,11 +76,13 @@ module Aws
65
76
  # @see #copy_to
66
77
  #
67
78
  def copy_from(source, options = {})
68
- if Hash === source && source[:copy_source]
69
- # for backwards compatibility
70
- @client.copy_object(source.merge(bucket: bucket_name, key: key))
71
- else
72
- ObjectCopier.new(self, options).copy_from(source, options)
79
+ Aws::Plugins::UserAgent.metric('RESOURCE_MODEL') do
80
+ if Hash === source && source[:copy_source]
81
+ # for backwards compatibility
82
+ @client.copy_object(source.merge(bucket: bucket_name, key: key))
83
+ else
84
+ ObjectCopier.new(self, options).copy_from(source, options)
85
+ end
73
86
  end
74
87
  end
75
88
 
@@ -106,7 +119,9 @@ module Aws
106
119
  # object.copy_to('src-bucket/src-key', multipart_copy: true)
107
120
  #
108
121
  def copy_to(target, options = {})
109
- ObjectCopier.new(self, options).copy_to(target, options)
122
+ Aws::Plugins::UserAgent.metric('RESOURCE_MODEL') do
123
+ ObjectCopier.new(self, options).copy_to(target, options)
124
+ end
110
125
  end
111
126
 
112
127
  # Copies and deletes the current object. The object will only be deleted
@@ -153,21 +168,35 @@ module Aws
153
168
  # obj.presigned_url(:put, acl: 'public-read')
154
169
  # #=> "https://bucket-name.s3.amazonaws.com/object-key?..."
155
170
  #
156
- # @param [Symbol] http_method
157
- # The HTTP method to generate a presigned URL for. Valid values
158
- # are `:get`, `:put`, `:head`, and `:delete`.
171
+ # @example Pre-signed UploadPart PUT
172
+ #
173
+ # # the object uploaded using this URL will be publicly accessible
174
+ # obj.presigned_url(:upload_part, part_number: 1, upload_id: 'uploadIdToken')
175
+ # #=> "https://bucket-name.s3.amazonaws.com/object-key?..."
176
+ #
177
+ # @param [Symbol] method
178
+ # The S3 operation to generate a presigned URL for. Valid values
179
+ # are `:get`, `:put`, `:head`, `:delete`, `:create_multipart_upload`,
180
+ # `:list_multipart_uploads`, `:complete_multipart_upload`,
181
+ # `:abort_multipart_upload`, `:list_parts`, and `:upload_part`.
159
182
  #
160
183
  # @param [Hash] params
161
184
  # Additional request parameters to use when generating the pre-signed
162
185
  # URL. See the related documentation in {Client} for accepted
163
186
  # params.
164
187
  #
165
- # | HTTP Method | Client Method |
166
- # |---------------|------------------------|
167
- # | `:get` | {Client#get_object} |
168
- # | `:put` | {Client#put_object} |
169
- # | `:head` | {Client#head_object} |
170
- # | `:delete` | {Client#delete_object} |
188
+ # | Method | Client Method |
189
+ # |------------------------------|------------------------------------|
190
+ # | `:get` | {Client#get_object} |
191
+ # | `:put` | {Client#put_object} |
192
+ # | `:head` | {Client#head_object} |
193
+ # | `:delete` | {Client#delete_object} |
194
+ # | `:create_multipart_upload` | {Client#create_multipart_upload} |
195
+ # | `:list_multipart_uploads` | {Client#list_multipart_uploads} |
196
+ # | `:complete_multipart_upload` | {Client#complete_multipart_upload} |
197
+ # | `:abort_multipart_upload` | {Client#abort_multipart_upload} |
198
+ # | `:list_parts` | {Client#list_parts} |
199
+ # | `:upload_part` | {Client#upload_part} |
171
200
  #
172
201
  # @option params [Boolean] :virtual_host (false) When `true` the
173
202
  # presigned URL will use the bucket name as a virtual host.
@@ -188,10 +217,88 @@ module Aws
188
217
  #
189
218
  # @return [String]
190
219
  #
191
- def presigned_url(http_method, params = {})
220
+ def presigned_url(method, params = {})
192
221
  presigner = Presigner.new(client: client)
222
+
223
+ if %w(delete head get put).include?(method.to_s)
224
+ method = "#{method}_object".to_sym
225
+ end
226
+
193
227
  presigner.presigned_url(
194
- "#{http_method.downcase}_object",
228
+ method.downcase,
229
+ params.merge(bucket: bucket_name, key: key)
230
+ )
231
+ end
232
+
233
+ # Allows you to create presigned URL requests for S3 operations. This
234
+ # method returns a tuple containing the URL and the signed X-amz-* headers
235
+ # to be used with the presigned url.
236
+ #
237
+ # @example Pre-signed GET URL, valid for one hour
238
+ #
239
+ # obj.presigned_request(:get, expires_in: 3600)
240
+ # #=> ["https://bucket-name.s3.amazonaws.com/object-key?...", {}]
241
+ #
242
+ # @example Pre-signed PUT with a canned ACL
243
+ #
244
+ # # the object uploaded using this URL will be publicly accessible
245
+ # obj.presigned_request(:put, acl: 'public-read')
246
+ # #=> ["https://bucket-name.s3.amazonaws.com/object-key?...",
247
+ # {"x-amz-acl"=>"public-read"}]
248
+ #
249
+ # @param [Symbol] method
250
+ # The S3 operation to generate a presigned request for. Valid values
251
+ # are `:get`, `:put`, `:head`, `:delete`, `:create_multipart_upload`,
252
+ # `:list_multipart_uploads`, `:complete_multipart_upload`,
253
+ # `:abort_multipart_upload`, `:list_parts`, and `:upload_part`.
254
+ #
255
+ # @param [Hash] params
256
+ # Additional request parameters to use when generating the pre-signed
257
+ # request. See the related documentation in {Client} for accepted
258
+ # params.
259
+ #
260
+ # | Method | Client Method |
261
+ # |------------------------------|------------------------------------|
262
+ # | `:get` | {Client#get_object} |
263
+ # | `:put` | {Client#put_object} |
264
+ # | `:head` | {Client#head_object} |
265
+ # | `:delete` | {Client#delete_object} |
266
+ # | `:create_multipart_upload` | {Client#create_multipart_upload} |
267
+ # | `:list_multipart_uploads` | {Client#list_multipart_uploads} |
268
+ # | `:complete_multipart_upload` | {Client#complete_multipart_upload} |
269
+ # | `:abort_multipart_upload` | {Client#abort_multipart_upload} |
270
+ # | `:list_parts` | {Client#list_parts} |
271
+ # | `:upload_part` | {Client#upload_part} |
272
+ #
273
+ # @option params [Boolean] :virtual_host (false) When `true` the
274
+ # presigned URL will use the bucket name as a virtual host.
275
+ #
276
+ # bucket = Aws::S3::Bucket.new('my.bucket.com')
277
+ # bucket.object('key').presigned_request(virtual_host: true)
278
+ # #=> ["http://my.bucket.com/key?...", {}]
279
+ #
280
+ # @option params [Integer] :expires_in (900) Number of seconds before
281
+ # the pre-signed URL expires. This may not exceed one week (604800
282
+ # seconds). Note that the pre-signed URL is also only valid as long as
283
+ # credentials used to sign it are. For example, when using IAM roles,
284
+ # temporary tokens generated for signing also have a default expiration
285
+ # which will affect the effective expiration of the pre-signed URL.
286
+ #
287
+ # @raise [ArgumentError] Raised if `:expires_in` exceeds one week
288
+ # (604800 seconds).
289
+ #
290
+ # @return [String, Hash] A tuple with a presigned URL and headers that
291
+ # should be included with the request.
292
+ #
293
+ def presigned_request(method, params = {})
294
+ presigner = Presigner.new(client: client)
295
+
296
+ if %w(delete head get put).include?(method.to_s)
297
+ method = "#{method}_object".to_sym
298
+ end
299
+
300
+ presigner.presigned_request(
301
+ method.downcase,
195
302
  params.merge(bucket: bucket_name, key: key)
196
303
  )
197
304
  end
@@ -201,16 +308,22 @@ module Aws
201
308
  # s3.bucket('bucket-name').object('obj-key').public_url
202
309
  # #=> "https://bucket-name.s3.amazonaws.com/obj-key"
203
310
  #
204
- # To use virtual hosted bucket url (disables https):
311
+ # To use virtual hosted bucket url.
312
+ # Uses https unless secure: false is set. If the bucket
313
+ # name contains dots (.) then you will need to set secure: false.
205
314
  #
206
- # s3.bucket('my.bucket.com').object('key')
315
+ # s3.bucket('my-bucket.com').object('key')
207
316
  # .public_url(virtual_host: true)
208
- # #=> "http://my.bucket.com/key"
317
+ # #=> "https://my-bucket.com/key"
209
318
  #
210
319
  # @option options [Boolean] :virtual_host (false) When `true`, the bucket
211
320
  # name will be used as the host name. This is useful when you have
212
321
  # a CNAME configured for the bucket.
213
322
  #
323
+ # @option options [Boolean] :secure (true) When `false`, http
324
+ # will be used with virtual_host. This is required when
325
+ # the bucket name has a dot (.) in it.
326
+ #
214
327
  # @return [String]
215
328
  def public_url(options = {})
216
329
  url = URI.parse(bucket.url(options))
@@ -240,9 +353,13 @@ module Aws
240
353
  # obj.upload_stream do |write_stream|
241
354
  # IO.copy_stream(STDIN, write_stream)
242
355
  # end
356
+ # @param [Hash] options
357
+ # Additional options for {Client#create_multipart_upload},
358
+ # {Client#complete_multipart_upload},
359
+ # and {Client#upload_part} can be provided.
243
360
  #
244
- # @option options [Integer] :thread_count (10) The number of parallel
245
- # 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.
246
363
  #
247
364
  # @option options [Boolean] :tempfile (false) Normally read data is stored
248
365
  # in memory when building the parts in order to complete the underlying
@@ -262,28 +379,32 @@ module Aws
262
379
  # @return [Boolean] Returns `true` when the object is uploaded
263
380
  # without any errors.
264
381
  #
382
+ # @see Client#create_multipart_upload
383
+ # @see Client#complete_multipart_upload
384
+ # @see Client#upload_part
265
385
  def upload_stream(options = {}, &block)
266
- 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))
267
388
  uploader = MultipartStreamUploader.new(
268
389
  client: client,
269
- thread_count: uploading_options.delete(:thread_count),
270
- tempfile: uploading_options.delete(:tempfile),
271
- part_size: uploading_options.delete(:part_size)
272
- )
273
- uploader.upload(
274
- uploading_options.merge(bucket: bucket_name, key: key),
275
- &block
390
+ executor: executor,
391
+ tempfile: upload_opts.delete(:tempfile),
392
+ part_size: upload_opts.delete(:part_size)
276
393
  )
394
+ Aws::Plugins::UserAgent.metric('RESOURCE_MODEL') do
395
+ uploader.upload(upload_opts, &block)
396
+ end
397
+ executor.shutdown
277
398
  true
278
399
  end
400
+ deprecated(:upload_stream, use: 'Aws::S3::TransferManager#upload_stream', version: 'next major version')
279
401
 
280
402
  # Uploads a file from disk to the current object in S3.
281
403
  #
282
404
  # # small files are uploaded in a single API call
283
405
  # obj.upload_file('/path/to/file')
284
406
  #
285
- # Files larger than `:multipart_threshold` are uploaded using the
286
- # Amazon S3 multipart upload APIs.
407
+ # Files larger than or equal to `:multipart_threshold` are uploaded using the Amazon S3 multipart upload APIs.
287
408
  #
288
409
  # # large files are automatically split into parts
289
410
  # # and the parts are uploaded in parallel
@@ -299,91 +420,141 @@ module Aws
299
420
  # You can provide a callback to monitor progress of the upload:
300
421
  #
301
422
  # # bytes and totals are each an array with 1 entry per part
302
- # progress = Proc.new do |bytes, totals|
303
- # 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 }%"
304
425
  # end
305
- # obj.upload_file('/path/to/file')
426
+ # obj.upload_file('/path/to/file', progress_callback: progress)
306
427
  #
307
- # @param [String, Pathname, File, Tempfile] source A file on the local
308
- # file system that will be uploaded as this object. This can either be
309
- # a String or Pathname to the file, an open File object, or an open
310
- # Tempfile object. If you pass an open File or Tempfile object, then
311
- # you are responsible for closing it after the upload completes. When
312
- # 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
313
432
  # will be empty.
314
433
  #
315
- # @option options [Integer] :multipart_threshold (15728640) Files larger
316
- # than `:multipart_threshold` are uploaded using the S3 multipart APIs.
317
- # Default threshold is 15MB.
434
+ # @param [Hash] options
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.
438
+ #
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.
318
441
  #
319
- # @option options [Integer] :thread_count (10) The number of parallel
320
- # multipart uploads. This option is not used if the file is smaller than
321
- # `: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`.
322
444
  #
323
445
  # @option options [Proc] :progress_callback
324
446
  # A Proc that will be called when each chunk of the upload is sent.
325
447
  # It will be invoked with [bytes_read], [total_sizes]
326
448
  #
327
- # @raise [MultipartUploadError] If an object is being uploaded in
328
- # parts, and the upload can not be completed, then the upload is
329
- # aborted and this error is raised. The raised error has a `#errors`
330
- # method that returns the failures that caused the upload to be
331
- # 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.
332
452
  #
333
- # @return [Boolean] Returns `true` when the object is uploaded
334
- # without any errors.
453
+ # @return [Boolean] Returns `true` when the object is uploaded without any errors.
454
+ #
455
+ # @see Client#put_object
456
+ # @see Client#create_multipart_upload
457
+ # @see Client#complete_multipart_upload
458
+ # @see Client#upload_part
335
459
  def upload_file(source, options = {})
336
- 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))
337
462
  uploader = FileUploader.new(
338
- multipart_threshold: uploading_options.delete(:multipart_threshold),
339
- client: client
340
- )
341
- response = uploader.upload(
342
- source,
343
- uploading_options.merge(bucket: bucket_name, key: key)
463
+ client: client,
464
+ executor: executor,
465
+ multipart_threshold: upload_opts.delete(:multipart_threshold)
344
466
  )
467
+ response = Aws::Plugins::UserAgent.metric('RESOURCE_MODEL') do
468
+ uploader.upload(source, upload_opts)
469
+ end
345
470
  yield response if block_given?
471
+ executor.shutdown
346
472
  true
347
473
  end
474
+ deprecated(:upload_file, use: 'Aws::S3::TransferManager#upload_file', version: 'next major version')
348
475
 
349
476
  # Downloads a file in S3 to a path on disk.
350
477
  #
351
478
  # # small files (< 5MB) are downloaded in a single API call
352
479
  # obj.download_file('/path/to/file')
353
480
  #
354
- # Files larger than 5MB are downloaded using multipart method
481
+ # Files larger than 5MB are downloaded using multipart method:
355
482
  #
356
483
  # # large files are split into parts
357
484
  # # and the parts are downloaded in parallel
358
485
  # obj.download_file('/path/to/very_large_file')
359
486
  #
360
- # @param [String] destination Where to download the file to.
487
+ # You can provide a callback to monitor progress of the download:
488
+ #
489
+ # # bytes and part_sizes are each an array with 1 entry per part
490
+ # # part_sizes may not be known until the first bytes are retrieved
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}%"
493
+ # end
494
+ # obj.download_file('/path/to/file', progress_callback: progress)
495
+ #
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.
506
+ #
507
+ # @param [Hash] options
508
+ # Additional options for {Client#get_object} and #{Client#head_object} may be provided.
509
+ #
510
+ # @option options [String] :mode ("auto") `"auto"`, `"single_request"` or `"get_range"`
361
511
  #
362
- # @option options [String] mode `auto`, `single_request`, `get_range`
363
- # `single_request` mode forces only 1 GET request is made in download,
364
- # `get_range` mode allows `chunk_size` parameter to configured in
365
- # customizing each range size in multipart_download,
366
- # By default, `auto` mode is enabled, which performs multipart_download
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
367
515
  #
368
- # @option options [String] chunk_size required in get_range mode.
516
+ # @option options [Integer] :chunk_size required in `"get_range"` mode.
369
517
  #
370
- # @option options [Integer] thread_count (10) Customize threads used in
371
- # the multipart download.
518
+ # @option options [Integer] :thread_count (10) Customize threads used in the multipart download.
372
519
  #
373
- # @option options [String] version_id The object version id used to
374
- # retrieve the object. For more about object versioning, see:
375
- # https://docs.aws.amazon.com/AmazonS3/latest/dev/ObjectVersioning.html
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.
376
524
  #
377
- # @return [Boolean] Returns `true` when the file is downloaded without
378
- # any errors.
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.
528
+ #
529
+ # @option options [Proc] :progress_callback
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.
536
+ #
537
+ # @return [Boolean] Returns `true` when the file is downloaded without any errors.
538
+ #
539
+ # @see Client#get_object
540
+ # @see Client#head_object
379
541
  def download_file(destination, options = {})
380
- downloader = FileDownloader.new(client: client)
381
- downloader.download(
382
- destination,
383
- options.merge(bucket: bucket_name, key: key)
384
- )
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)
547
+ end
548
+ executor.shutdown
385
549
  true
386
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
387
558
  end
388
559
  end
389
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