aws-sdk-s3 1.109.0 → 1.156.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 (100) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +352 -0
  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 +241 -0
  6. data/lib/aws-sdk-s3/bucket.rb +585 -110
  7. data/lib/aws-sdk-s3/bucket_acl.rb +28 -6
  8. data/lib/aws-sdk-s3/bucket_cors.rb +34 -10
  9. data/lib/aws-sdk-s3/bucket_lifecycle.rb +34 -10
  10. data/lib/aws-sdk-s3/bucket_lifecycle_configuration.rb +34 -10
  11. data/lib/aws-sdk-s3/bucket_logging.rb +35 -6
  12. data/lib/aws-sdk-s3/bucket_notification.rb +12 -6
  13. data/lib/aws-sdk-s3/bucket_policy.rb +78 -10
  14. data/lib/aws-sdk-s3/bucket_region_cache.rb +9 -5
  15. data/lib/aws-sdk-s3/bucket_request_payment.rb +28 -6
  16. data/lib/aws-sdk-s3/bucket_tagging.rb +34 -10
  17. data/lib/aws-sdk-s3/bucket_versioning.rb +72 -14
  18. data/lib/aws-sdk-s3/bucket_website.rb +34 -10
  19. data/lib/aws-sdk-s3/client.rb +7900 -3252
  20. data/lib/aws-sdk-s3/client_api.rb +706 -228
  21. data/lib/aws-sdk-s3/customizations/bucket.rb +23 -47
  22. data/lib/aws-sdk-s3/customizations/errors.rb +40 -0
  23. data/lib/aws-sdk-s3/customizations/object.rb +97 -21
  24. data/lib/aws-sdk-s3/customizations/types/permanent_redirect.rb +26 -0
  25. data/lib/aws-sdk-s3/customizations.rb +10 -0
  26. data/lib/aws-sdk-s3/encryption/client.rb +6 -2
  27. data/lib/aws-sdk-s3/encryption/kms_cipher_provider.rb +13 -9
  28. data/lib/aws-sdk-s3/encryptionV2/client.rb +6 -2
  29. data/lib/aws-sdk-s3/encryptionV2/decrypt_handler.rb +1 -0
  30. data/lib/aws-sdk-s3/encryptionV2/kms_cipher_provider.rb +10 -6
  31. data/lib/aws-sdk-s3/endpoint_parameters.rb +186 -0
  32. data/lib/aws-sdk-s3/endpoint_provider.rb +592 -0
  33. data/lib/aws-sdk-s3/endpoints.rb +2689 -0
  34. data/lib/aws-sdk-s3/express_credentials.rb +55 -0
  35. data/lib/aws-sdk-s3/express_credentials_provider.rb +59 -0
  36. data/lib/aws-sdk-s3/file_downloader.rb +170 -45
  37. data/lib/aws-sdk-s3/file_uploader.rb +11 -4
  38. data/lib/aws-sdk-s3/multipart_file_uploader.rb +30 -11
  39. data/lib/aws-sdk-s3/multipart_stream_uploader.rb +46 -17
  40. data/lib/aws-sdk-s3/multipart_upload.rb +194 -19
  41. data/lib/aws-sdk-s3/multipart_upload_part.rb +280 -30
  42. data/lib/aws-sdk-s3/object.rb +1753 -266
  43. data/lib/aws-sdk-s3/object_acl.rb +49 -13
  44. data/lib/aws-sdk-s3/object_copier.rb +7 -5
  45. data/lib/aws-sdk-s3/object_multipart_copier.rb +46 -22
  46. data/lib/aws-sdk-s3/object_summary.rb +1497 -221
  47. data/lib/aws-sdk-s3/object_version.rb +383 -58
  48. data/lib/aws-sdk-s3/plugins/accelerate.rb +3 -50
  49. data/lib/aws-sdk-s3/plugins/access_grants.rb +114 -0
  50. data/lib/aws-sdk-s3/plugins/arn.rb +0 -184
  51. data/lib/aws-sdk-s3/plugins/bucket_dns.rb +3 -39
  52. data/lib/aws-sdk-s3/plugins/bucket_name_restrictions.rb +1 -6
  53. data/lib/aws-sdk-s3/plugins/dualstack.rb +1 -49
  54. data/lib/aws-sdk-s3/plugins/endpoints.rb +274 -0
  55. data/lib/aws-sdk-s3/plugins/expect_100_continue.rb +2 -1
  56. data/lib/aws-sdk-s3/plugins/express_session_auth.rb +97 -0
  57. data/lib/aws-sdk-s3/plugins/http_200_errors.rb +53 -16
  58. data/lib/aws-sdk-s3/plugins/iad_regional_endpoint.rb +6 -29
  59. data/lib/aws-sdk-s3/plugins/location_constraint.rb +3 -1
  60. data/lib/aws-sdk-s3/plugins/md5s.rb +6 -3
  61. data/lib/aws-sdk-s3/plugins/s3_signer.rb +42 -126
  62. data/lib/aws-sdk-s3/plugins/skip_whole_multipart_get_checksums.rb +31 -0
  63. data/lib/aws-sdk-s3/plugins/streaming_retry.rb +23 -2
  64. data/lib/aws-sdk-s3/presigned_post.rb +99 -78
  65. data/lib/aws-sdk-s3/presigner.rb +28 -37
  66. data/lib/aws-sdk-s3/resource.rb +89 -13
  67. data/lib/aws-sdk-s3/types.rb +6544 -4909
  68. data/lib/aws-sdk-s3.rb +5 -1
  69. data/sig/bucket.rbs +212 -0
  70. data/sig/bucket_acl.rbs +78 -0
  71. data/sig/bucket_cors.rbs +69 -0
  72. data/sig/bucket_lifecycle.rbs +88 -0
  73. data/sig/bucket_lifecycle_configuration.rbs +111 -0
  74. data/sig/bucket_logging.rbs +76 -0
  75. data/sig/bucket_notification.rbs +114 -0
  76. data/sig/bucket_policy.rbs +59 -0
  77. data/sig/bucket_request_payment.rbs +54 -0
  78. data/sig/bucket_tagging.rbs +65 -0
  79. data/sig/bucket_versioning.rbs +77 -0
  80. data/sig/bucket_website.rbs +93 -0
  81. data/sig/client.rbs +2381 -0
  82. data/sig/customizations/bucket.rbs +19 -0
  83. data/sig/customizations/object.rbs +38 -0
  84. data/sig/customizations/object_summary.rbs +35 -0
  85. data/sig/errors.rbs +34 -0
  86. data/sig/multipart_upload.rbs +110 -0
  87. data/sig/multipart_upload_part.rbs +105 -0
  88. data/sig/object.rbs +442 -0
  89. data/sig/object_acl.rbs +86 -0
  90. data/sig/object_summary.rbs +334 -0
  91. data/sig/object_version.rbs +137 -0
  92. data/sig/resource.rbs +127 -0
  93. data/sig/types.rbs +2568 -0
  94. data/sig/waiters.rbs +95 -0
  95. metadata +50 -16
  96. data/lib/aws-sdk-s3/arn/access_point_arn.rb +0 -69
  97. data/lib/aws-sdk-s3/arn/multi_region_access_point_arn.rb +0 -68
  98. data/lib/aws-sdk-s3/arn/object_lambda_arn.rb +0 -69
  99. data/lib/aws-sdk-s3/arn/outpost_access_point_arn.rb +0 -74
  100. data/lib/aws-sdk-s3/plugins/object_lambda_endpoint.rb +0 -25
@@ -4,29 +4,19 @@ require 'aws-sigv4'
4
4
 
5
5
  module Aws
6
6
  module S3
7
+ # @api private
8
+ def self.bucket_region_cache
9
+ @bucket_region_cache ||= BucketRegionCache.new
10
+ end
11
+
7
12
  module Plugins
8
- # This plugin is an implementation detail and may be modified.
13
+ # This plugin used to have a V4 signer but it was removed in favor of
14
+ # generic Sign plugin that uses endpoint auth scheme.
15
+ #
9
16
  # @api private
10
17
  class S3Signer < Seahorse::Client::Plugin
11
18
  option(:signature_version, 'v4')
12
19
 
13
- option(:sigv4_signer) do |cfg|
14
- S3Signer.build_v4_signer(
15
- service: 's3',
16
- region: cfg.sigv4_region,
17
- credentials: cfg.credentials
18
- )
19
- end
20
-
21
- option(:sigv4_region) do |cfg|
22
- # S3 removes core's signature_v4 plugin that checks for this
23
- raise Aws::Errors::MissingRegionError if cfg.region.nil?
24
-
25
- Aws::Partitions::EndpointProvider.signing_region(
26
- cfg.region, 's3'
27
- )
28
- end
29
-
30
20
  def add_handlers(handlers, cfg)
31
21
  case cfg.signature_version
32
22
  when 'v4' then add_v4_handlers(handlers)
@@ -39,11 +29,11 @@ module Aws
39
29
 
40
30
  def add_v4_handlers(handlers)
41
31
  handlers.add(CachedBucketRegionHandler, step: :sign, priority: 60)
42
- handlers.add(V4Handler, step: :sign)
43
32
  handlers.add(BucketRegionErrorHandler, step: :sign, priority: 40)
44
33
  end
45
34
 
46
35
  def add_legacy_handler(handlers)
36
+ # generic Sign plugin will be skipped if it sees sigv2
47
37
  handlers.add(LegacyHandler, step: :sign)
48
38
  end
49
39
 
@@ -54,53 +44,6 @@ module Aws
54
44
  end
55
45
  end
56
46
 
57
- class V4Handler < Seahorse::Client::Handler
58
- def call(context)
59
- Aws::Plugins::SignatureV4.apply_signature(
60
- context: context,
61
- signer: sigv4_signer(context)
62
- )
63
- @handler.call(context)
64
- end
65
-
66
- private
67
-
68
- def sigv4_signer(context)
69
- # If the client was configured with the wrong region,
70
- # we have to build a new signer.
71
- if context[:cached_sigv4_region] &&
72
- context[:cached_sigv4_region] != context.config.sigv4_signer.region
73
- S3Signer.build_v4_signer(
74
- service: 's3',
75
- region: context[:cached_sigv4_region],
76
- credentials: context.config.credentials
77
- )
78
- elsif (arn = context.metadata[:s3_arn])
79
- if arn[:arn].is_a?(MultiRegionAccessPointARN)
80
- signing_region = '*'
81
- signing_algorithm = :sigv4a
82
- else
83
- signing_region = arn[:resolved_region]
84
- signing_algorithm = :sigv4
85
- end
86
- S3Signer.build_v4_signer(
87
- service: arn[:arn].service,
88
- signing_algorithm: signing_algorithm,
89
- region: signing_region,
90
- credentials: context.config.credentials
91
- )
92
- elsif context.operation.name == 'WriteGetObjectResponse'
93
- S3Signer.build_v4_signer(
94
- service: 's3-object-lambda',
95
- region: context.config.sigv4_region,
96
- credentials: context.config.credentials
97
- )
98
- else
99
- context.config.sigv4_signer
100
- end
101
- end
102
- end
103
-
104
47
  # This handler will update the http endpoint when the bucket region
105
48
  # is known/cached.
106
49
  class CachedBucketRegionHandler < Seahorse::Client::Handler
@@ -113,12 +56,14 @@ module Aws
113
56
  private
114
57
 
115
58
  def check_for_cached_region(context, bucket)
116
- cached_region = S3::BUCKET_REGIONS[bucket]
117
- if cached_region && cached_region != context.config.region
59
+ cached_region = Aws::S3.bucket_region_cache[bucket]
60
+ if cached_region &&
61
+ cached_region != context.config.region &&
62
+ !S3Signer.custom_endpoint?(context)
118
63
  context.http_request.endpoint.host = S3Signer.new_hostname(
119
64
  context, cached_region
120
65
  )
121
- context[:cached_sigv4_region] = cached_region
66
+ context[:sigv4_region] = cached_region # Sign plugin will use this
122
67
  end
123
68
  end
124
69
  end
@@ -126,7 +71,8 @@ module Aws
126
71
  # This handler detects when a request fails because of a mismatched bucket
127
72
  # region. It follows up by making a request to determine the correct
128
73
  # region, then finally a version 4 signed request against the correct
129
- # regional endpoint.
74
+ # regional endpoint. This is intended for s3's global endpoint which
75
+ # will return 400 if the bucket is not in region.
130
76
  class BucketRegionErrorHandler < Seahorse::Client::Handler
131
77
  def call(context)
132
78
  response = @handler.call(context)
@@ -138,7 +84,8 @@ module Aws
138
84
  def handle_region_errors(response)
139
85
  if wrong_sigv4_region?(response) &&
140
86
  !fips_region?(response) &&
141
- !custom_endpoint?(response)
87
+ !S3Signer.custom_endpoint?(response.context) &&
88
+ !expired_credentials?(response)
142
89
  get_region_and_retry(response.context)
143
90
  else
144
91
  response
@@ -155,23 +102,15 @@ module Aws
155
102
  end
156
103
 
157
104
  def update_bucket_cache(context, actual_region)
158
- S3::BUCKET_REGIONS[context.params[:bucket]] = actual_region
105
+ Aws::S3.bucket_region_cache[context.params[:bucket]] = actual_region
159
106
  end
160
107
 
161
108
  def fips_region?(resp)
162
- resp.context.http_request.endpoint.host.include?('fips')
109
+ resp.context.http_request.endpoint.host.include?('s3-fips.')
163
110
  end
164
111
 
165
- def custom_endpoint?(resp)
166
- resolved_suffix = Aws::Partitions::EndpointProvider.dns_suffix_for(
167
- resp.context.config.region,
168
- 's3',
169
- {
170
- dualstack: resp.context[:use_dualstack_endpoint],
171
- fips: resp.context.config.use_fips_endpoint
172
- }
173
- )
174
- !resp.context.http_request.endpoint.hostname.include?(resolved_suffix)
112
+ def expired_credentials?(resp)
113
+ resp.context.http_response.body_contents.match(/<Code>ExpiredToken<\/Code>/)
175
114
  end
176
115
 
177
116
  def wrong_sigv4_region?(resp)
@@ -186,18 +125,14 @@ module Aws
186
125
  context, actual_region
187
126
  )
188
127
  context.metadata[:redirect_region] = actual_region
189
- # if it's an ARN, use the service in the ARN
190
- if (arn = context.metadata[:s3_arn])
191
- service = arn[:arn].service
192
- end
193
- Aws::Plugins::SignatureV4.apply_signature(
194
- context: context,
195
- signer: S3Signer.build_v4_signer(
196
- service: service || 's3',
197
- region: actual_region,
198
- credentials: context.config.credentials
199
- )
128
+
129
+ signer = Aws::Plugins::Sign.signer_for(
130
+ context[:auth_scheme],
131
+ context.config,
132
+ actual_region
200
133
  )
134
+
135
+ signer.sign(context)
201
136
  end
202
137
 
203
138
  def region_from_body(body)
@@ -223,41 +158,22 @@ module Aws
223
158
  end
224
159
 
225
160
  class << self
226
- # @option options [required, String] :region
227
- # @option options [required, #credentials] :credentials
228
- # @api private
229
- def build_v4_signer(options = {})
230
- Aws::Sigv4::Signer.new(
231
- service: options[:service],
232
- region: options[:region],
233
- credentials_provider: options[:credentials],
234
- signing_algorithm: options.fetch(:signing_algorithm, :sigv4),
235
- uri_escape_path: false,
236
- unsigned_headers: ['content-length', 'x-amzn-trace-id']
237
- )
161
+ def new_hostname(context, region)
162
+ endpoint_params = context[:endpoint_params].dup
163
+ endpoint_params.region = region
164
+ endpoint_params.endpoint = nil
165
+ endpoint =
166
+ context.config.endpoint_provider.resolve_endpoint(endpoint_params)
167
+ URI(endpoint.url).host
238
168
  end
239
169
 
240
- # Check to see if the bucket is actually an ARN
241
- # Otherwise it will retry with the ARN as the bucket name.
242
- def new_hostname(context, region)
243
- uri = URI.parse(
244
- Aws::Partitions::EndpointProvider.resolve(
245
- region, 's3', 'regional',
246
- {
247
- dualstack: context[:use_dualstack_endpoint],
248
- fips: context.config.use_fips_endpoint
249
- }
250
- )
251
- )
170
+ def custom_endpoint?(context)
171
+ region = context.config.region
172
+ partition = Aws::Endpoints::Matchers.aws_partition(region)
173
+ endpoint = context.http_request.endpoint
252
174
 
253
- if (arn = context.metadata[:s3_arn])
254
- # Retry with the response region and not the ARN resolved one
255
- ARN.resolve_url!(
256
- uri, arn[:arn], region, arn[:fips], arn[:dualstack]
257
- ).host
258
- else
259
- "#{context.params[:bucket]}.#{uri.host}"
260
- end
175
+ !endpoint.hostname.include?(partition['dnsSuffix']) &&
176
+ !endpoint.hostname.include?(partition['dualStackDnsSuffix'])
261
177
  end
262
178
  end
263
179
  end
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Aws
4
+ module S3
5
+ module Plugins
6
+
7
+ # S3 GetObject results for whole Multipart Objects contain a checksum
8
+ # that cannot be validated. These should be skipped by the
9
+ # ChecksumAlgorithm plugin.
10
+ class SkipWholeMultipartGetChecksums < Seahorse::Client::Plugin
11
+
12
+ class Handler < Seahorse::Client::Handler
13
+
14
+ def call(context)
15
+ context[:http_checksum] ||= {}
16
+ context[:http_checksum][:skip_on_suffix] = true
17
+
18
+ @handler.call(context)
19
+ end
20
+
21
+ end
22
+
23
+ handler(
24
+ Handler,
25
+ step: :initialize,
26
+ operations: [:get_object]
27
+ )
28
+ end
29
+ end
30
+ end
31
+ end
@@ -36,6 +36,17 @@ module Aws
36
36
  def rewind; end
37
37
  end
38
38
 
39
+ class NonRetryableStreamingError < StandardError
40
+
41
+ def initialize(error)
42
+ super('Unable to retry request - retry could result in processing duplicated chunks.')
43
+ set_backtrace(error.backtrace)
44
+ @original_error = error
45
+ end
46
+
47
+ attr_reader :original_error
48
+ end
49
+
39
50
  # This handler works with the ResponseTarget plugin to provide smart
40
51
  # retries of S3 streaming operations that support the range parameter
41
52
  # (currently only: get_object). When a 200 OK with a TruncatedBodyError
@@ -84,8 +95,18 @@ module Aws
84
95
  end
85
96
 
86
97
  context.http_response.on_error do |error|
87
- if retryable_body?(context) && truncated_body?(error)
88
- context.http_request.headers[:range] = "bytes=#{context.http_response.body.size}-"
98
+ if retryable_body?(context)
99
+ if truncated_body?(error)
100
+ context.http_request.headers[:range] = "bytes=#{context.http_response.body.size}-"
101
+ else
102
+ case context.http_response.body
103
+ when RetryableManagedFile
104
+ # call rewind on the underlying file
105
+ context.http_response.body.instance_variable_get(:@file).rewind
106
+ else
107
+ raise NonRetryableStreamingError, error
108
+ end
109
+ end
89
110
  end
90
111
  end
91
112
  end
@@ -98,7 +98,7 @@ module Aws
98
98
  # or call the associated method.
99
99
  #
100
100
  # ```ruby
101
- # post = Aws::S3::PresignedPost.new(creds, region, bucket).
101
+ # post = Aws::S3::PresignedPost.new(creds, region, bucket)
102
102
  # post.content_type('text/plain')
103
103
  # ```
104
104
  #
@@ -176,11 +176,17 @@ module Aws
176
176
  # ```
177
177
  #
178
178
  class PresignedPost
179
+ @@allowed_fields = []
179
180
 
180
181
  # @param [Credentials] credentials Security credentials for signing
181
182
  # the post policy.
182
183
  # @param [String] bucket_region Region of the target bucket.
183
184
  # @param [String] bucket_name Name of the target bucket.
185
+ # @option options [Boolean] :use_accelerate_endpoint (false) When `true`,
186
+ # PresignedPost will attempt to use accelerated endpoint.
187
+ # @option options [String] :url See {PresignedPost#url}.
188
+ # @option options [Sting, Array<String>] :allow_any
189
+ # See {PresignedPost#allow_any}.
184
190
  # @option options [Time] :signature_expiration Specify when the signature on
185
191
  # the post will expire. Defaults to one hour from creation of the
186
192
  # presigned post. May not exceed one week from creation time.
@@ -205,7 +211,7 @@ module Aws
205
211
  # See {PresignedPost#content_encoding}.
206
212
  # @option options [String] :content_encoding_starts_with
207
213
  # See {PresignedPost#content_encoding_starts_with}.
208
- # @option options [String] :expires See {PresignedPost#expires}.
214
+ # @option options [Time] :expires See {PresignedPost#expires}.
209
215
  # @option options [String] :expires_starts_with
210
216
  # See {PresignedPost#expires_starts_with}.
211
217
  # @option options [Range<Integer>] :content_length_range
@@ -232,6 +238,8 @@ module Aws
232
238
  # See {PresignedPost#server_side_encryption_customer_algorithm}.
233
239
  # @option options [String] :server_side_encryption_customer_key
234
240
  # See {PresignedPost#server_side_encryption_customer_key}.
241
+ # @option options [String] :server_side_encryption_customer_key_starts_with
242
+ # See {PresignedPost#server_side_encryption_customer_key_starts_with}.
235
243
  def initialize(credentials, bucket_region, bucket_name, options = {})
236
244
  @credentials = credentials.credentials
237
245
  @bucket_region = bucket_region
@@ -247,7 +255,12 @@ module Aws
247
255
  case option_name
248
256
  when :allow_any then allow_any(option_value)
249
257
  when :signature_expiration then @signature_expiration = option_value
250
- else send("#{option_name}", option_value)
258
+ else
259
+ if @@allowed_fields.include?(option_name)
260
+ send("#{option_name}", option_value)
261
+ else
262
+ raise ArgumentError, "Unsupported option: #{option_name}"
263
+ end
251
264
  end
252
265
  end
253
266
  end
@@ -279,44 +292,52 @@ module Aws
279
292
  end
280
293
 
281
294
  # @api private
282
- def self.define_field(field, *args)
295
+ def self.define_field(field, *args, &block)
296
+ @@allowed_fields << field
283
297
  options = args.last.is_a?(Hash) ? args.pop : {}
284
298
  field_name = args.last || field.to_s
285
299
 
286
- define_method("#{field}") do |value|
287
- with(field_name, value)
288
- end
300
+ if block_given?
301
+ define_method("#{field}", block)
302
+ else
303
+ define_method("#{field}") do |value|
304
+ with(field_name, value)
305
+ end
289
306
 
290
- if options[:starts_with]
291
- define_method("#{field}_starts_with") do |value|
292
- starts_with(field_name, value)
307
+ if options[:starts_with]
308
+ @@allowed_fields << "#{field}_starts_with".to_sym
309
+ define_method("#{field}_starts_with") do |value|
310
+ starts_with(field_name, value)
311
+ end
293
312
  end
294
313
  end
295
314
  end
296
315
 
297
316
  # @!group Fields
298
317
 
299
- # The key to use for the uploaded object. You can use `${filename}`
300
- # as a variable in the key. This will be replaced with the name
301
- # of the file as provided by the user.
318
+ # @!method key(key)
319
+ # The key to use for the uploaded object. You can use `${filename}`
320
+ # as a variable in the key. This will be replaced with the name
321
+ # of the file as provided by the user.
302
322
  #
303
- # For example, if the key is given as `/user/betty/${filename}` and
304
- # the file uploaded is named `lolcatz.jpg`, the resultant key will
305
- # be `/user/betty/lolcatz.jpg`.
323
+ # For example, if the key is given as `/user/betty/${filename}` and
324
+ # the file uploaded is named `lolcatz.jpg`, the resultant key will
325
+ # be `/user/betty/lolcatz.jpg`.
306
326
  #
307
- # @param [String] key
308
- # @see http://docs.aws.amazon.com/AmazonS3/latest/dev/UsingMetadata.html)
309
- # @return [self]
310
- def key(key)
327
+ # @param [String] key
328
+ # @see http://docs.aws.amazon.com/AmazonS3/latest/dev/UsingMetadata.html)
329
+ # @return [self]
330
+ define_field(:key) do |key|
311
331
  @key_set = true
312
332
  with('key', key)
313
333
  end
314
334
 
315
- # Specify a prefix the uploaded
316
- # @param [String] prefix
317
- # @see #key
318
- # @return [self]
319
- def key_starts_with(prefix)
335
+ # @!method key_starts_with(prefix)
336
+ # Specify a prefix the uploaded
337
+ # @param [String] prefix
338
+ # @see #key
339
+ # @return [self]
340
+ define_field(:key_starts_with) do |prefix|
320
341
  @key_set = true
321
342
  starts_with('key', prefix)
322
343
  end
@@ -393,27 +414,30 @@ module Aws
393
414
  # @return [self]
394
415
  define_field(:content_encoding, 'Content-Encoding', starts_with: true)
395
416
 
396
- # The date and time at which the object is no longer cacheable.
397
- # @note This does not affect the expiration of the presigned post
398
- # signature.
399
- # @param [Time] time
400
- # @see http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.21
401
- # @return [self]
402
- def expires(time)
417
+ # @!method expires(time)
418
+ # The date and time at which the object is no longer cacheable.
419
+ # @note This does not affect the expiration of the presigned post
420
+ # signature.
421
+ # @param [Time] time
422
+ # @see http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.21
423
+ # @return [self]
424
+ define_field(:expires) do |time|
403
425
  with('Expires', time.httpdate)
404
426
  end
405
427
 
406
- # @param [String] prefix
407
- # @see #expires
408
- # @return [self]
409
- def expires_starts_with(prefix)
428
+ # @!method expires_starts_with(prefix)
429
+ # @param [String] prefix
430
+ # @see #expires
431
+ # @return [self]
432
+ define_field(:expires_starts_with) do |prefix|
410
433
  starts_with('Expires', prefix)
411
434
  end
412
435
 
413
- # The minimum and maximum allowable size for the uploaded content.
414
- # @param [Range<Integer>] byte_range
415
- # @return [self]
416
- def content_length_range(byte_range)
436
+ # @!method content_length_range(byte_range)
437
+ # The minimum and maximum allowable size for the uploaded content.
438
+ # @param [Range<Integer>] byte_range
439
+ # @return [self]
440
+ define_field(:content_length_range) do |byte_range|
417
441
  min = byte_range.begin
418
442
  max = byte_range.end
419
443
  max -= 1 if byte_range.exclude_end?
@@ -488,22 +512,24 @@ module Aws
488
512
  # @return [self]
489
513
  define_field(:website_redirect_location, 'x-amz-website-redirect-location')
490
514
 
491
- # Metadata hash to store with the uploaded object. Hash keys will be
492
- # prefixed with "x-amz-meta-".
493
- # @param [Hash<String,String>] hash
494
- # @return [self]
495
- def metadata(hash)
515
+ # @!method metadata(hash)
516
+ # Metadata hash to store with the uploaded object. Hash keys will be
517
+ # prefixed with "x-amz-meta-".
518
+ # @param [Hash<String,String>] hash
519
+ # @return [self]
520
+ define_field(:metadata) do |hash|
496
521
  hash.each do |key, value|
497
522
  with("x-amz-meta-#{key}", value)
498
523
  end
499
524
  self
500
525
  end
501
526
 
502
- # Specify allowable prefix for each key in the metadata hash.
503
- # @param [Hash<String,String>] hash
504
- # @see #metadata
505
- # @return [self]
506
- def metadata_starts_with(hash)
527
+ # @!method metadata_starts_with(hash)
528
+ # Specify allowable prefix for each key in the metadata hash.
529
+ # @param [Hash<String,String>] hash
530
+ # @see #metadata
531
+ # @return [self]
532
+ define_field(:metadata_starts_with) do |hash|
507
533
  hash.each do |key, value|
508
534
  starts_with("x-amz-meta-#{key}", value)
509
535
  end
@@ -552,25 +578,27 @@ module Aws
552
578
  'x-amz-server-side-encryption-customer-algorithm'
553
579
  )
554
580
 
555
- # Specifies the customer-provided encryption key for Amazon S3 to use
556
- # in encrypting data. This value is used to store the object and then
557
- # it is discarded; Amazon does not store the encryption key.
581
+ # @!method server_side_encryption_customer_key(value)
582
+ # Specifies the customer-provided encryption key for Amazon S3 to use
583
+ # in encrypting data. This value is used to store the object and then
584
+ # it is discarded; Amazon does not store the encryption key.
558
585
  #
559
- # You must also call {#server_side_encryption_customer_algorithm}.
586
+ # You must also call {#server_side_encryption_customer_algorithm}.
560
587
  #
561
- # @param [String] value
562
- # @see #server_side_encryption_customer_algorithm
563
- # @return [self]
564
- def server_side_encryption_customer_key(value)
588
+ # @param [String] value
589
+ # @see #server_side_encryption_customer_algorithm
590
+ # @return [self]
591
+ define_field(:server_side_encryption_customer_key) do |value|
565
592
  field_name = 'x-amz-server-side-encryption-customer-key'
566
593
  with(field_name, base64(value))
567
594
  with(field_name + '-MD5', base64(OpenSSL::Digest::MD5.digest(value)))
568
595
  end
569
596
 
570
- # @param [String] prefix
571
- # @see #server_side_encryption_customer_key
572
- # @return [self]
573
- def server_side_encryption_customer_key_starts_with(prefix)
597
+ # @!method server_side_encryption_customer_key_starts_with(prefix)
598
+ # @param [String] prefix
599
+ # @see #server_side_encryption_customer_key
600
+ # @return [self]
601
+ define_field(:server_side_encryption_customer_key_starts_with) do |prefix|
574
602
  field_name = 'x-amz-server-side-encryption-customer-key'
575
603
  starts_with(field_name, prefix)
576
604
  end
@@ -610,22 +638,15 @@ module Aws
610
638
  end
611
639
 
612
640
  def bucket_url
613
- url = Aws::Partitions::EndpointProvider.resolve(@bucket_region, 's3')
614
- url = URI.parse(url)
615
- if Plugins::BucketDns.dns_compatible?(@bucket_name, _ssl = true)
616
- if @accelerate
617
- url.host = "#{@bucket_name}.s3-accelerate.amazonaws.com"
618
- else
619
- url.host = "#{@bucket_name}.#{url.host}"
620
- end
621
- else
622
- url.path = "/#{@bucket_name}"
623
- end
624
- if @bucket_region == 'us-east-1'
625
- # keep legacy behavior by default
626
- url.host = Plugins::IADRegionalEndpoint.legacy_host(url.host)
627
- end
628
- url.to_s
641
+ # Taken from Aws::S3::Endpoints module
642
+ params = Aws::S3::EndpointParameters.new(
643
+ bucket: @bucket_name,
644
+ region: @bucket_region,
645
+ accelerate: @accelerate,
646
+ use_global_endpoint: true
647
+ )
648
+ endpoint = Aws::S3::EndpointProvider.new.resolve_endpoint(params)
649
+ endpoint.url
629
650
  end
630
651
 
631
652
  # @return [Hash]