aws-sdk-s3 1.48.0 → 1.183.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 (134) hide show
  1. checksums.yaml +5 -5
  2. data/CHANGELOG.md +1352 -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 +1005 -106
  8. data/lib/aws-sdk-s3/bucket_acl.rb +65 -18
  9. data/lib/aws-sdk-s3/bucket_cors.rb +80 -18
  10. data/lib/aws-sdk-s3/bucket_lifecycle.rb +71 -20
  11. data/lib/aws-sdk-s3/bucket_lifecycle_configuration.rb +126 -21
  12. data/lib/aws-sdk-s3/bucket_logging.rb +68 -16
  13. data/lib/aws-sdk-s3/bucket_notification.rb +52 -20
  14. data/lib/aws-sdk-s3/bucket_policy.rb +108 -17
  15. data/lib/aws-sdk-s3/bucket_region_cache.rb +11 -5
  16. data/lib/aws-sdk-s3/bucket_request_payment.rb +60 -15
  17. data/lib/aws-sdk-s3/bucket_tagging.rb +71 -18
  18. data/lib/aws-sdk-s3/bucket_versioning.rb +133 -17
  19. data/lib/aws-sdk-s3/bucket_website.rb +78 -21
  20. data/lib/aws-sdk-s3/client.rb +14517 -941
  21. data/lib/aws-sdk-s3/client_api.rb +1296 -197
  22. data/lib/aws-sdk-s3/customizations/bucket.rb +56 -37
  23. data/lib/aws-sdk-s3/customizations/errors.rb +40 -0
  24. data/lib/aws-sdk-s3/customizations/multipart_upload.rb +2 -0
  25. data/lib/aws-sdk-s3/customizations/object.rb +288 -68
  26. data/lib/aws-sdk-s3/customizations/object_summary.rb +10 -0
  27. data/lib/aws-sdk-s3/customizations/object_version.rb +13 -0
  28. data/lib/aws-sdk-s3/customizations/types/list_object_versions_output.rb +2 -0
  29. data/lib/aws-sdk-s3/customizations/types/permanent_redirect.rb +26 -0
  30. data/lib/aws-sdk-s3/customizations.rb +27 -28
  31. data/lib/aws-sdk-s3/encryption/client.rb +28 -7
  32. data/lib/aws-sdk-s3/encryption/decrypt_handler.rb +71 -29
  33. data/lib/aws-sdk-s3/encryption/default_cipher_provider.rb +43 -5
  34. data/lib/aws-sdk-s3/encryption/default_key_provider.rb +2 -0
  35. data/lib/aws-sdk-s3/encryption/encrypt_handler.rb +13 -2
  36. data/lib/aws-sdk-s3/encryption/errors.rb +2 -0
  37. data/lib/aws-sdk-s3/encryption/io_auth_decrypter.rb +2 -0
  38. data/lib/aws-sdk-s3/encryption/io_decrypter.rb +11 -3
  39. data/lib/aws-sdk-s3/encryption/io_encrypter.rb +2 -0
  40. data/lib/aws-sdk-s3/encryption/key_provider.rb +2 -0
  41. data/lib/aws-sdk-s3/encryption/kms_cipher_provider.rb +46 -11
  42. data/lib/aws-sdk-s3/encryption/materials.rb +8 -6
  43. data/lib/aws-sdk-s3/encryption/utils.rb +25 -0
  44. data/lib/aws-sdk-s3/encryption.rb +4 -0
  45. data/lib/aws-sdk-s3/encryptionV2/client.rb +570 -0
  46. data/lib/aws-sdk-s3/encryptionV2/decrypt_handler.rb +223 -0
  47. data/lib/aws-sdk-s3/encryptionV2/default_cipher_provider.rb +170 -0
  48. data/lib/aws-sdk-s3/encryptionV2/default_key_provider.rb +40 -0
  49. data/lib/aws-sdk-s3/encryptionV2/encrypt_handler.rb +65 -0
  50. data/lib/aws-sdk-s3/encryptionV2/errors.rb +37 -0
  51. data/lib/aws-sdk-s3/encryptionV2/io_auth_decrypter.rb +58 -0
  52. data/lib/aws-sdk-s3/encryptionV2/io_decrypter.rb +37 -0
  53. data/lib/aws-sdk-s3/encryptionV2/io_encrypter.rb +73 -0
  54. data/lib/aws-sdk-s3/encryptionV2/key_provider.rb +31 -0
  55. data/lib/aws-sdk-s3/encryptionV2/kms_cipher_provider.rb +173 -0
  56. data/lib/aws-sdk-s3/encryptionV2/materials.rb +60 -0
  57. data/lib/aws-sdk-s3/encryptionV2/utils.rb +103 -0
  58. data/lib/aws-sdk-s3/encryption_v2.rb +23 -0
  59. data/lib/aws-sdk-s3/endpoint_parameters.rb +181 -0
  60. data/lib/aws-sdk-s3/endpoint_provider.rb +716 -0
  61. data/lib/aws-sdk-s3/endpoints.rb +1434 -0
  62. data/lib/aws-sdk-s3/errors.rb +170 -1
  63. data/lib/aws-sdk-s3/event_streams.rb +8 -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 +161 -46
  67. data/lib/aws-sdk-s3/file_part.rb +11 -6
  68. data/lib/aws-sdk-s3/file_uploader.rb +39 -18
  69. data/lib/aws-sdk-s3/legacy_signer.rb +17 -25
  70. data/lib/aws-sdk-s3/multipart_file_uploader.rb +104 -27
  71. data/lib/aws-sdk-s3/multipart_stream_uploader.rb +61 -21
  72. data/lib/aws-sdk-s3/multipart_upload.rb +342 -32
  73. data/lib/aws-sdk-s3/multipart_upload_error.rb +2 -0
  74. data/lib/aws-sdk-s3/multipart_upload_part.rb +384 -46
  75. data/lib/aws-sdk-s3/object.rb +2600 -231
  76. data/lib/aws-sdk-s3/object_acl.rb +103 -25
  77. data/lib/aws-sdk-s3/object_copier.rb +9 -5
  78. data/lib/aws-sdk-s3/object_multipart_copier.rb +48 -22
  79. data/lib/aws-sdk-s3/object_summary.rb +2174 -204
  80. data/lib/aws-sdk-s3/object_version.rb +539 -80
  81. data/lib/aws-sdk-s3/plugins/accelerate.rb +17 -64
  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 +7 -43
  85. data/lib/aws-sdk-s3/plugins/bucket_name_restrictions.rb +20 -3
  86. data/lib/aws-sdk-s3/plugins/checksum_algorithm.rb +31 -0
  87. data/lib/aws-sdk-s3/plugins/dualstack.rb +7 -50
  88. data/lib/aws-sdk-s3/plugins/endpoints.rb +86 -0
  89. data/lib/aws-sdk-s3/plugins/expect_100_continue.rb +5 -4
  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 +3 -1
  92. data/lib/aws-sdk-s3/plugins/http_200_errors.rb +62 -17
  93. data/lib/aws-sdk-s3/plugins/iad_regional_endpoint.rb +44 -0
  94. data/lib/aws-sdk-s3/plugins/location_constraint.rb +5 -1
  95. data/lib/aws-sdk-s3/plugins/md5s.rb +14 -70
  96. data/lib/aws-sdk-s3/plugins/redirects.rb +2 -0
  97. data/lib/aws-sdk-s3/plugins/s3_host_id.rb +2 -0
  98. data/lib/aws-sdk-s3/plugins/s3_signer.rb +63 -94
  99. data/lib/aws-sdk-s3/plugins/sse_cpk.rb +3 -1
  100. data/lib/aws-sdk-s3/plugins/streaming_retry.rb +139 -0
  101. data/lib/aws-sdk-s3/plugins/url_encoded_keys.rb +2 -0
  102. data/lib/aws-sdk-s3/presigned_post.rb +160 -99
  103. data/lib/aws-sdk-s3/presigner.rb +141 -62
  104. data/lib/aws-sdk-s3/resource.rb +156 -17
  105. data/lib/aws-sdk-s3/types.rb +13021 -4106
  106. data/lib/aws-sdk-s3/waiters.rb +67 -1
  107. data/lib/aws-sdk-s3.rb +46 -32
  108. data/sig/bucket.rbs +222 -0
  109. data/sig/bucket_acl.rbs +78 -0
  110. data/sig/bucket_cors.rbs +69 -0
  111. data/sig/bucket_lifecycle.rbs +88 -0
  112. data/sig/bucket_lifecycle_configuration.rbs +115 -0
  113. data/sig/bucket_logging.rbs +76 -0
  114. data/sig/bucket_notification.rbs +114 -0
  115. data/sig/bucket_policy.rbs +59 -0
  116. data/sig/bucket_request_payment.rbs +54 -0
  117. data/sig/bucket_tagging.rbs +65 -0
  118. data/sig/bucket_versioning.rbs +77 -0
  119. data/sig/bucket_website.rbs +93 -0
  120. data/sig/client.rbs +2472 -0
  121. data/sig/customizations/bucket.rbs +19 -0
  122. data/sig/customizations/object.rbs +38 -0
  123. data/sig/customizations/object_summary.rbs +35 -0
  124. data/sig/errors.rbs +42 -0
  125. data/sig/multipart_upload.rbs +120 -0
  126. data/sig/multipart_upload_part.rbs +109 -0
  127. data/sig/object.rbs +459 -0
  128. data/sig/object_acl.rbs +86 -0
  129. data/sig/object_summary.rbs +345 -0
  130. data/sig/object_version.rbs +143 -0
  131. data/sig/resource.rbs +134 -0
  132. data/sig/types.rbs +2712 -0
  133. data/sig/waiters.rbs +95 -0
  134. metadata +74 -15
@@ -0,0 +1,139 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'forwardable'
4
+
5
+ module Aws
6
+ module S3
7
+ module Plugins
8
+
9
+ # A wrapper around BlockIO that adds no-ops for truncate and rewind
10
+ # @api private
11
+ class RetryableBlockIO
12
+ extend Forwardable
13
+ def_delegators :@block_io, :write, :read, :size
14
+
15
+ def initialize(block_io)
16
+ @block_io = block_io
17
+ end
18
+
19
+ def truncate(_integer); end
20
+
21
+ def rewind; end
22
+ end
23
+
24
+ # A wrapper around ManagedFile that adds no-ops for truncate and rewind
25
+ # @api private
26
+ class RetryableManagedFile
27
+ extend Forwardable
28
+ def_delegators :@file, :write, :read, :size, :open?, :close
29
+
30
+ def initialize(managed_file)
31
+ @file = managed_file
32
+ end
33
+
34
+ def truncate(_integer); end
35
+
36
+ def rewind; end
37
+ end
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
+
50
+ # This handler works with the ResponseTarget plugin to provide smart
51
+ # retries of S3 streaming operations that support the range parameter
52
+ # (currently only: get_object). When a 200 OK with a TruncatedBodyError
53
+ # is received this handler will add a range header that excludes the
54
+ # data that has already been processed (written to file or sent to
55
+ # the target Proc).
56
+ # It is important to not write data to the custom target in the case of
57
+ # a non-success response. We do not want to write an XML error
58
+ # message to someone's file or pass it to a user's Proc.
59
+ # @api private
60
+ class StreamingRetry < Seahorse::Client::Plugin
61
+
62
+ class Handler < Seahorse::Client::Handler
63
+
64
+ def call(context)
65
+ target = context.params[:response_target] || context[:response_target]
66
+
67
+ # retry is only supported when range is NOT set on the initial request
68
+ if supported_target?(target) && !context.params[:range]
69
+ add_event_listeners(context, target)
70
+ end
71
+ @handler.call(context)
72
+ end
73
+
74
+ private
75
+
76
+ def add_event_listeners(context, target)
77
+ context.http_response.on_headers(200..299) do
78
+ case context.http_response.body
79
+ when Seahorse::Client::BlockIO then
80
+ context.http_response.body = RetryableBlockIO.new(context.http_response.body)
81
+ when Seahorse::Client::ManagedFile then
82
+ context.http_response.body = RetryableManagedFile.new(context.http_response.body)
83
+ end
84
+ end
85
+
86
+ context.http_response.on_headers(400..599) do
87
+ context.http_response.body = StringIO.new # something to write the error to
88
+ end
89
+
90
+ context.http_response.on_success(200..299) do
91
+ body = context.http_response.body
92
+ if body.is_a?(RetryableManagedFile) && body.open?
93
+ body.close
94
+ end
95
+ end
96
+
97
+ context.http_response.on_error do |error|
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
110
+ end
111
+ end
112
+ end
113
+
114
+ def truncated_body?(error)
115
+ error.is_a?(Seahorse::Client::NetworkingError) &&
116
+ error.original_error.is_a?(
117
+ Seahorse::Client::NetHttp::Handler::TruncatedBodyError
118
+ )
119
+ end
120
+
121
+ def retryable_body?(context)
122
+ context.http_response.body.is_a?(RetryableBlockIO) ||
123
+ context.http_response.body.is_a?(RetryableManagedFile)
124
+ end
125
+
126
+ def supported_target?(target)
127
+ case target
128
+ when Proc, String, Pathname then true
129
+ else false
130
+ end
131
+ end
132
+ end
133
+
134
+ handler(Handler, step: :sign, operations: [:get_object], priority: 10)
135
+
136
+ end
137
+ end
138
+ end
139
+ end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'uri'
2
4
  require 'cgi'
3
5
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'openssl'
2
4
  require 'base64'
3
5
 
@@ -96,7 +98,7 @@ module Aws
96
98
  # or call the associated method.
97
99
  #
98
100
  # ```ruby
99
- # post = Aws::S3::PresignedPost.new(creds, region, bucket).
101
+ # post = Aws::S3::PresignedPost.new(creds, region, bucket)
100
102
  # post.content_type('text/plain')
101
103
  # ```
102
104
  #
@@ -174,44 +176,76 @@ module Aws
174
176
  # ```
175
177
  #
176
178
  class PresignedPost
179
+ @@allowed_fields = []
177
180
 
178
181
  # @param [Credentials] credentials Security credentials for signing
179
182
  # the post policy.
180
183
  # @param [String] bucket_region Region of the target bucket.
181
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}.
182
190
  # @option options [Time] :signature_expiration Specify when the signature on
183
191
  # the post will expire. Defaults to one hour from creation of the
184
192
  # presigned post. May not exceed one week from creation time.
185
193
  # @option options [String] :key See {PresignedPost#key}.
186
- # @option options [String] :key_starts_with See {PresignedPost#key_starts_with}.
194
+ # @option options [String] :key_starts_with
195
+ # See {PresignedPost#key_starts_with}.
187
196
  # @option options [String] :acl See {PresignedPost#acl}.
188
- # @option options [String] :acl_starts_with See {PresignedPost#acl_starts_with}.
189
- # @option options [String] :cache_control See {PresignedPost#cache_control}.
190
- # @option options [String] :cache_control_starts_with See {PresignedPost#cache_control_starts_with}.
197
+ # @option options [String] :acl_starts_with
198
+ # See {PresignedPost#acl_starts_with}.
199
+ # @option options [String] :cache_control
200
+ # See {PresignedPost#cache_control}.
201
+ # @option options [String] :cache_control_starts_with
202
+ # See {PresignedPost#cache_control_starts_with}.
191
203
  # @option options [String] :content_type See {PresignedPost#content_type}.
192
- # @option options [String] :content_type_starts_with See {PresignedPost#content_type_starts_with}.
193
- # @option options [String] :content_disposition See {PresignedPost#content_disposition}.
194
- # @option options [String] :content_disposition_starts_with See {PresignedPost#content_disposition_starts_with}.
195
- # @option options [String] :content_encoding See {PresignedPost#content_encoding}.
196
- # @option options [String] :content_encoding_starts_with See {PresignedPost#content_encoding_starts_with}.
197
- # @option options [String] :expires See {PresignedPost#expires}.
198
- # @option options [String] :expires_starts_with See {PresignedPost#expires_starts_with}.
199
- # @option options [Range<Integer>] :content_length_range See {PresignedPost#content_length_range}.
200
- # @option options [String] :success_action_redirect See {PresignedPost#success_action_redirect}.
201
- # @option options [String] :success_action_redirect_starts_with See {PresignedPost#success_action_redirect_starts_with}.
202
- # @option options [String] :success_action_status See {PresignedPost#success_action_status}.
203
- # @option options [String] :storage_class See {PresignedPost#storage_class}.
204
- # @option options [String] :website_redirect_location See {PresignedPost#website_redirect_location}.
205
- # @option options [Hash<String,String>] :metadata See {PresignedPost#metadata}.
206
- # @option options [Hash<String,String>] :metadata_starts_with See {PresignedPost#metadata_starts_with}.
207
- # @option options [String] :server_side_encryption See {PresignedPost#server_side_encryption}.
208
- # @option options [String] :server_side_encryption_aws_kms_key_id See {PresignedPost#server_side_encryption_aws_kms_key_id}.
209
- # @option options [String] :server_side_encryption_customer_algorithm See {PresignedPost#server_side_encryption_customer_algorithm}.
210
- # @option options [String] :server_side_encryption_customer_key See {PresignedPost#server_side_encryption_customer_key}.
204
+ # @option options [String] :content_type_starts_with
205
+ # See {PresignedPost#content_type_starts_with}.
206
+ # @option options [String] :content_disposition
207
+ # See {PresignedPost#content_disposition}.
208
+ # @option options [String] :content_disposition_starts_with
209
+ # See {PresignedPost#content_disposition_starts_with}.
210
+ # @option options [String] :content_encoding
211
+ # See {PresignedPost#content_encoding}.
212
+ # @option options [String] :content_encoding_starts_with
213
+ # See {PresignedPost#content_encoding_starts_with}.
214
+ # @option options [Time] :expires See {PresignedPost#expires}.
215
+ # @option options [String] :expires_starts_with
216
+ # See {PresignedPost#expires_starts_with}.
217
+ # @option options [Range<Integer>] :content_length_range
218
+ # See {PresignedPost#content_length_range}.
219
+ # @option options [String] :success_action_redirect
220
+ # See {PresignedPost#success_action_redirect}.
221
+ # @option options [String] :success_action_redirect_starts_with
222
+ # See {PresignedPost#success_action_redirect_starts_with}.
223
+ # @option options [String] :success_action_status
224
+ # See {PresignedPost#success_action_status}.
225
+ # @option options [String] :storage_class
226
+ # See {PresignedPost#storage_class}.
227
+ # @option options [String] :website_redirect_location
228
+ # See {PresignedPost#website_redirect_location}.
229
+ # @option options [Hash<String,String>] :metadata
230
+ # See {PresignedPost#metadata}.
231
+ # @option options [Hash<String,String>] :metadata_starts_with
232
+ # See {PresignedPost#metadata_starts_with}.
233
+ # @option options [String] :server_side_encryption
234
+ # See {PresignedPost#server_side_encryption}.
235
+ # @option options [String] :server_side_encryption_aws_kms_key_id
236
+ # See {PresignedPost#server_side_encryption_aws_kms_key_id}.
237
+ # @option options [String] :server_side_encryption_customer_algorithm
238
+ # See {PresignedPost#server_side_encryption_customer_algorithm}.
239
+ # @option options [String] :server_side_encryption_customer_key
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}.
211
243
  def initialize(credentials, bucket_region, bucket_name, options = {})
212
244
  @credentials = credentials.credentials
213
245
  @bucket_region = bucket_region
214
246
  @bucket_name = bucket_name
247
+ @accelerate = !!options.delete(:use_accelerate_endpoint)
248
+ options.delete(:url) if @accelerate # resource methods pass url
215
249
  @url = options.delete(:url) || bucket_url
216
250
  @fields = {}
217
251
  @key_set = false
@@ -221,7 +255,12 @@ module Aws
221
255
  case option_name
222
256
  when :allow_any then allow_any(option_value)
223
257
  when :signature_expiration then @signature_expiration = option_value
224
- 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
225
264
  end
226
265
  end
227
266
  end
@@ -234,7 +273,7 @@ module Aws
234
273
  # as hidden input fields.
235
274
  def fields
236
275
  check_required_values!
237
- datetime = Time.now.utc.strftime("%Y%m%dT%H%M%SZ")
276
+ datetime = Time.now.utc.strftime('%Y%m%dT%H%M%SZ')
238
277
  fields = @fields.dup
239
278
  fields.update('policy' => policy(datetime))
240
279
  fields.update(signature_fields(datetime))
@@ -253,44 +292,52 @@ module Aws
253
292
  end
254
293
 
255
294
  # @api private
256
- def self.define_field(field, *args)
295
+ def self.define_field(field, *args, &block)
296
+ @@allowed_fields << field
257
297
  options = args.last.is_a?(Hash) ? args.pop : {}
258
298
  field_name = args.last || field.to_s
259
299
 
260
- define_method("#{field}") do |value|
261
- with(field_name, value)
262
- 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
263
306
 
264
- if options[:starts_with]
265
- define_method("#{field}_starts_with") do |value|
266
- 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
267
312
  end
268
313
  end
269
314
  end
270
315
 
271
316
  # @!group Fields
272
317
 
273
- # The key to use for the uploaded object. Use can use `${filename}`
274
- # as a variable in the key. This will be replaced with the name
275
- # 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.
276
322
  #
277
- # For example, if the key is given as `/user/betty/${filename}` and
278
- # the file uploaded is named `lolcatz.jpg`, the resultant key will
279
- # 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`.
280
326
  #
281
- # @param [String] key
282
- # @see http://docs.aws.amazon.com/AmazonS3/latest/dev/UsingMetadata.html)
283
- # @return [self]
284
- 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|
285
331
  @key_set = true
286
332
  with('key', key)
287
333
  end
288
334
 
289
- # Specify a prefix the uploaded
290
- # @param [String] prefix
291
- # @see #key
292
- # @return [self]
293
- 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|
294
341
  @key_set = true
295
342
  starts_with('key', prefix)
296
343
  end
@@ -367,27 +414,30 @@ module Aws
367
414
  # @return [self]
368
415
  define_field(:content_encoding, 'Content-Encoding', starts_with: true)
369
416
 
370
- # The date and time at which the object is no longer cacheable.
371
- # @note This does not affect the expiration of the presigned post
372
- # signature.
373
- # @param [Time] time
374
- # @see http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.21
375
- # @return [self]
376
- 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|
377
425
  with('Expires', time.httpdate)
378
426
  end
379
427
 
380
- # @param [String] prefix
381
- # @see #expires
382
- # @return [self]
383
- 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|
384
433
  starts_with('Expires', prefix)
385
434
  end
386
435
 
387
- # The minimum and maximum allowable size for the uploaded content.
388
- # @param [Range<Integer>] byte_range
389
- # @return [self]
390
- 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|
391
441
  min = byte_range.begin
392
442
  max = byte_range.end
393
443
  max -= 1 if byte_range.exclude_end?
@@ -462,22 +512,24 @@ module Aws
462
512
  # @return [self]
463
513
  define_field(:website_redirect_location, 'x-amz-website-redirect-location')
464
514
 
465
- # Metadata hash to store with the uploaded object. Hash keys will be
466
- # prefixed with "x-amz-meta-".
467
- # @param [Hash<String,String>] hash
468
- # @return [self]
469
- 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|
470
521
  hash.each do |key, value|
471
522
  with("x-amz-meta-#{key}", value)
472
523
  end
473
524
  self
474
525
  end
475
526
 
476
- # Specify allowable prefix for each key in the metadata hash.
477
- # @param [Hash<String,String>] hash
478
- # @see #metadata
479
- # @return [self]
480
- 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|
481
533
  hash.each do |key, value|
482
534
  starts_with("x-amz-meta-#{key}", value)
483
535
  end
@@ -505,7 +557,10 @@ module Aws
505
557
  # (KMS) master encryption key to use for the object.
506
558
  # @param [String] value
507
559
  # @return [self]
508
- define_field(:server_side_encryption_aws_kms_key_id, 'x-amz-server-side-encryption-aws-kms-key-id')
560
+ define_field(
561
+ :server_side_encryption_aws_kms_key_id,
562
+ 'x-amz-server-side-encryption-aws-kms-key-id'
563
+ )
509
564
 
510
565
  # @!endgroup
511
566
 
@@ -518,27 +573,32 @@ module Aws
518
573
  # @param [String] value
519
574
  # @see #server_side_encryption_customer_key
520
575
  # @return [self]
521
- define_field(:server_side_encryption_customer_algorithm, 'x-amz-server-side-encryption-customer-algorithm')
522
-
523
- # Specifies the customer-provided encryption key for Amazon S3 to use
524
- # in encrypting data. This value is used to store the object and then
525
- # it is discarded; Amazon does not store the encryption key.
576
+ define_field(
577
+ :server_side_encryption_customer_algorithm,
578
+ 'x-amz-server-side-encryption-customer-algorithm'
579
+ )
580
+
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.
526
585
  #
527
- # You must also call {#server_side_encryption_customer_algorithm}.
586
+ # You must also call {#server_side_encryption_customer_algorithm}.
528
587
  #
529
- # @param [String] value
530
- # @see #server_side_encryption_customer_algorithm
531
- # @return [self]
532
- 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|
533
592
  field_name = 'x-amz-server-side-encryption-customer-key'
534
593
  with(field_name, base64(value))
535
594
  with(field_name + '-MD5', base64(OpenSSL::Digest::MD5.digest(value)))
536
595
  end
537
596
 
538
- # @param [String] prefix
539
- # @see #server_side_encryption_customer_key
540
- # @return [self]
541
- 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|
542
602
  field_name = 'x-amz-server-side-encryption-customer-key'
543
603
  starts_with(field_name, prefix)
544
604
  end
@@ -571,21 +631,22 @@ module Aws
571
631
 
572
632
  def check_required_values!
573
633
  unless @key_set
574
- msg = "key required; you must provide a key via :key, "
575
- msg << ":key_starts_with, or :allow_any => ['key']"
634
+ msg = 'key required; you must provide a key via :key, '\
635
+ ":key_starts_with, or :allow_any => ['key']"
576
636
  raise msg
577
637
  end
578
638
  end
579
639
 
580
640
  def bucket_url
581
- url = Aws::Partitions::EndpointProvider.resolve(@bucket_region, 's3')
582
- url = URI.parse(url)
583
- if Plugins::BucketDns.dns_compatible?(@bucket_name, true)
584
- url.host = @bucket_name + '.' + url.host
585
- else
586
- url.path = '/' + @bucket_name
587
- end
588
- 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
589
650
  end
590
651
 
591
652
  # @return [Hash]
@@ -613,7 +674,7 @@ module Aws
613
674
 
614
675
  def signature(datetime, string_to_sign)
615
676
  k_secret = @credentials.secret_access_key
616
- k_date = hmac("AWS4" + k_secret, datetime[0,8])
677
+ k_date = hmac('AWS4' + k_secret, datetime[0,8])
617
678
  k_region = hmac(k_date, @bucket_region)
618
679
  k_service = hmac(k_region, 's3')
619
680
  k_credentials = hmac(k_service, 'aws4_request')