aws-sdk-s3 1.45.0 → 1.143.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/CHANGELOG.md +1106 -0
- data/LICENSE.txt +202 -0
- data/VERSION +1 -0
- data/lib/aws-sdk-s3/bucket.rb +784 -98
- data/lib/aws-sdk-s3/bucket_acl.rb +64 -18
- data/lib/aws-sdk-s3/bucket_cors.rb +79 -18
- data/lib/aws-sdk-s3/bucket_lifecycle.rb +66 -20
- data/lib/aws-sdk-s3/bucket_lifecycle_configuration.rb +68 -20
- data/lib/aws-sdk-s3/bucket_logging.rb +68 -16
- data/lib/aws-sdk-s3/bucket_notification.rb +52 -20
- data/lib/aws-sdk-s3/bucket_policy.rb +107 -17
- data/lib/aws-sdk-s3/bucket_region_cache.rb +2 -0
- data/lib/aws-sdk-s3/bucket_request_payment.rb +60 -15
- data/lib/aws-sdk-s3/bucket_tagging.rb +71 -18
- data/lib/aws-sdk-s3/bucket_versioning.rb +133 -17
- data/lib/aws-sdk-s3/bucket_website.rb +78 -21
- data/lib/aws-sdk-s3/client.rb +12610 -902
- data/lib/aws-sdk-s3/client_api.rb +1086 -191
- data/lib/aws-sdk-s3/customizations/bucket.rb +56 -37
- data/lib/aws-sdk-s3/customizations/errors.rb +27 -0
- data/lib/aws-sdk-s3/customizations/multipart_upload.rb +2 -0
- data/lib/aws-sdk-s3/customizations/object.rb +282 -68
- data/lib/aws-sdk-s3/customizations/object_summary.rb +5 -0
- data/lib/aws-sdk-s3/customizations/types/list_object_versions_output.rb +2 -0
- data/lib/aws-sdk-s3/customizations/types/permanent_redirect.rb +26 -0
- data/lib/aws-sdk-s3/customizations.rb +11 -1
- data/lib/aws-sdk-s3/encryption/client.rb +28 -7
- data/lib/aws-sdk-s3/encryption/decrypt_handler.rb +71 -29
- data/lib/aws-sdk-s3/encryption/default_cipher_provider.rb +43 -5
- data/lib/aws-sdk-s3/encryption/default_key_provider.rb +2 -0
- data/lib/aws-sdk-s3/encryption/encrypt_handler.rb +13 -2
- data/lib/aws-sdk-s3/encryption/errors.rb +2 -0
- data/lib/aws-sdk-s3/encryption/io_auth_decrypter.rb +2 -0
- data/lib/aws-sdk-s3/encryption/io_decrypter.rb +11 -3
- data/lib/aws-sdk-s3/encryption/io_encrypter.rb +2 -0
- data/lib/aws-sdk-s3/encryption/key_provider.rb +2 -0
- data/lib/aws-sdk-s3/encryption/kms_cipher_provider.rb +46 -11
- data/lib/aws-sdk-s3/encryption/materials.rb +8 -6
- data/lib/aws-sdk-s3/encryption/utils.rb +25 -0
- data/lib/aws-sdk-s3/encryption.rb +4 -0
- data/lib/aws-sdk-s3/encryptionV2/client.rb +570 -0
- data/lib/aws-sdk-s3/encryptionV2/decrypt_handler.rb +223 -0
- data/lib/aws-sdk-s3/encryptionV2/default_cipher_provider.rb +170 -0
- data/lib/aws-sdk-s3/encryptionV2/default_key_provider.rb +40 -0
- data/lib/aws-sdk-s3/encryptionV2/encrypt_handler.rb +65 -0
- data/lib/aws-sdk-s3/encryptionV2/errors.rb +37 -0
- data/lib/aws-sdk-s3/encryptionV2/io_auth_decrypter.rb +58 -0
- data/lib/aws-sdk-s3/encryptionV2/io_decrypter.rb +37 -0
- data/lib/aws-sdk-s3/encryptionV2/io_encrypter.rb +73 -0
- data/lib/aws-sdk-s3/encryptionV2/key_provider.rb +31 -0
- data/lib/aws-sdk-s3/encryptionV2/kms_cipher_provider.rb +173 -0
- data/lib/aws-sdk-s3/encryptionV2/materials.rb +60 -0
- data/lib/aws-sdk-s3/encryptionV2/utils.rb +103 -0
- data/lib/aws-sdk-s3/encryption_v2.rb +23 -0
- data/lib/aws-sdk-s3/endpoint_parameters.rb +178 -0
- data/lib/aws-sdk-s3/endpoint_provider.rb +591 -0
- data/lib/aws-sdk-s3/endpoints.rb +2590 -0
- data/lib/aws-sdk-s3/errors.rb +123 -1
- data/lib/aws-sdk-s3/event_streams.rb +8 -1
- data/lib/aws-sdk-s3/express_credentials.rb +55 -0
- data/lib/aws-sdk-s3/express_credentials_cache.rb +30 -0
- data/lib/aws-sdk-s3/express_credentials_provider.rb +36 -0
- data/lib/aws-sdk-s3/file_downloader.rb +176 -44
- data/lib/aws-sdk-s3/file_part.rb +11 -6
- data/lib/aws-sdk-s3/file_uploader.rb +39 -18
- data/lib/aws-sdk-s3/legacy_signer.rb +17 -25
- data/lib/aws-sdk-s3/multipart_file_uploader.rb +78 -20
- data/lib/aws-sdk-s3/multipart_stream_uploader.rb +56 -18
- data/lib/aws-sdk-s3/multipart_upload.rb +242 -32
- data/lib/aws-sdk-s3/multipart_upload_error.rb +2 -0
- data/lib/aws-sdk-s3/multipart_upload_part.rb +367 -45
- data/lib/aws-sdk-s3/object.rb +2191 -227
- data/lib/aws-sdk-s3/object_acl.rb +103 -25
- data/lib/aws-sdk-s3/object_copier.rb +9 -5
- data/lib/aws-sdk-s3/object_multipart_copier.rb +43 -19
- data/lib/aws-sdk-s3/object_summary.rb +1811 -208
- data/lib/aws-sdk-s3/object_version.rb +452 -80
- data/lib/aws-sdk-s3/plugins/accelerate.rb +17 -64
- data/lib/aws-sdk-s3/plugins/arn.rb +70 -0
- data/lib/aws-sdk-s3/plugins/bucket_dns.rb +7 -43
- data/lib/aws-sdk-s3/plugins/bucket_name_restrictions.rb +20 -3
- data/lib/aws-sdk-s3/plugins/dualstack.rb +7 -50
- data/lib/aws-sdk-s3/plugins/endpoints.rb +274 -0
- data/lib/aws-sdk-s3/plugins/expect_100_continue.rb +5 -4
- data/lib/aws-sdk-s3/plugins/express_session_auth.rb +91 -0
- data/lib/aws-sdk-s3/plugins/get_bucket_location_fix.rb +3 -1
- data/lib/aws-sdk-s3/plugins/http_200_errors.rb +11 -3
- data/lib/aws-sdk-s3/plugins/iad_regional_endpoint.rb +44 -0
- data/lib/aws-sdk-s3/plugins/location_constraint.rb +5 -1
- data/lib/aws-sdk-s3/plugins/md5s.rb +35 -30
- data/lib/aws-sdk-s3/plugins/redirects.rb +2 -0
- data/lib/aws-sdk-s3/plugins/s3_host_id.rb +2 -0
- data/lib/aws-sdk-s3/plugins/s3_signer.rb +56 -92
- data/lib/aws-sdk-s3/plugins/skip_whole_multipart_get_checksums.rb +31 -0
- data/lib/aws-sdk-s3/plugins/sse_cpk.rb +3 -1
- data/lib/aws-sdk-s3/plugins/streaming_retry.rb +139 -0
- data/lib/aws-sdk-s3/plugins/url_encoded_keys.rb +2 -0
- data/lib/aws-sdk-s3/presigned_post.rb +160 -99
- data/lib/aws-sdk-s3/presigner.rb +171 -80
- data/lib/aws-sdk-s3/resource.rb +120 -8
- data/lib/aws-sdk-s3/types.rb +11353 -4225
- data/lib/aws-sdk-s3/waiters.rb +67 -1
- data/lib/aws-sdk-s3.rb +16 -6
- data/sig/bucket.rbs +212 -0
- data/sig/bucket_acl.rbs +78 -0
- data/sig/bucket_cors.rbs +69 -0
- data/sig/bucket_lifecycle.rbs +88 -0
- data/sig/bucket_lifecycle_configuration.rbs +111 -0
- data/sig/bucket_logging.rbs +76 -0
- data/sig/bucket_notification.rbs +114 -0
- data/sig/bucket_policy.rbs +59 -0
- data/sig/bucket_request_payment.rbs +54 -0
- data/sig/bucket_tagging.rbs +65 -0
- data/sig/bucket_versioning.rbs +77 -0
- data/sig/bucket_website.rbs +93 -0
- data/sig/client.rbs +2360 -0
- data/sig/errors.rbs +34 -0
- data/sig/multipart_upload.rbs +110 -0
- data/sig/multipart_upload_part.rbs +105 -0
- data/sig/object.rbs +436 -0
- data/sig/object_acl.rbs +86 -0
- data/sig/object_summary.rbs +334 -0
- data/sig/object_version.rbs +131 -0
- data/sig/resource.rbs +124 -0
- data/sig/types.rbs +2562 -0
- data/sig/waiters.rbs +83 -0
- metadata +68 -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 '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
|
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
|
189
|
-
#
|
190
|
-
# @option options [String] :
|
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
|
193
|
-
#
|
194
|
-
# @option options [String] :
|
195
|
-
#
|
196
|
-
# @option options [String] :
|
197
|
-
#
|
198
|
-
# @option options [String] :
|
199
|
-
#
|
200
|
-
# @option options [String] :
|
201
|
-
#
|
202
|
-
# @option options [
|
203
|
-
# @option options [String] :
|
204
|
-
#
|
205
|
-
# @option options [
|
206
|
-
#
|
207
|
-
# @option options [String] :
|
208
|
-
#
|
209
|
-
# @option options [String] :
|
210
|
-
#
|
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
|
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(
|
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
|
-
|
261
|
-
|
262
|
-
|
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
|
-
|
265
|
-
|
266
|
-
|
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
|
-
#
|
274
|
-
#
|
275
|
-
#
|
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
|
-
#
|
278
|
-
#
|
279
|
-
#
|
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
|
-
#
|
282
|
-
#
|
283
|
-
#
|
284
|
-
|
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
|
-
#
|
290
|
-
#
|
291
|
-
#
|
292
|
-
#
|
293
|
-
|
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
|
-
#
|
371
|
-
#
|
372
|
-
#
|
373
|
-
#
|
374
|
-
#
|
375
|
-
#
|
376
|
-
|
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
|
-
#
|
381
|
-
#
|
382
|
-
#
|
383
|
-
|
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
|
-
#
|
388
|
-
#
|
389
|
-
#
|
390
|
-
|
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
|
-
#
|
466
|
-
#
|
467
|
-
#
|
468
|
-
#
|
469
|
-
|
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
|
-
#
|
477
|
-
#
|
478
|
-
#
|
479
|
-
#
|
480
|
-
|
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(
|
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(
|
522
|
-
|
523
|
-
|
524
|
-
|
525
|
-
|
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
|
-
#
|
586
|
+
# You must also call {#server_side_encryption_customer_algorithm}.
|
528
587
|
#
|
529
|
-
#
|
530
|
-
#
|
531
|
-
#
|
532
|
-
|
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
|
-
#
|
539
|
-
#
|
540
|
-
#
|
541
|
-
|
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 =
|
575
|
-
|
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
|
-
|
582
|
-
|
583
|
-
|
584
|
-
|
585
|
-
|
586
|
-
|
587
|
-
|
588
|
-
|
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(
|
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')
|