aws-sdk-s3 1.48.0 → 1.114.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 +903 -0
- data/LICENSE.txt +202 -0
- data/VERSION +1 -0
- data/lib/aws-sdk-s3/arn/access_point_arn.rb +69 -0
- data/lib/aws-sdk-s3/arn/multi_region_access_point_arn.rb +68 -0
- data/lib/aws-sdk-s3/arn/object_lambda_arn.rb +69 -0
- data/lib/aws-sdk-s3/arn/outpost_access_point_arn.rb +74 -0
- data/lib/aws-sdk-s3/bucket.rb +375 -82
- data/lib/aws-sdk-s3/bucket_acl.rb +55 -15
- data/lib/aws-sdk-s3/bucket_cors.rb +67 -14
- data/lib/aws-sdk-s3/bucket_lifecycle.rb +54 -16
- data/lib/aws-sdk-s3/bucket_lifecycle_configuration.rb +56 -16
- data/lib/aws-sdk-s3/bucket_logging.rb +52 -13
- data/lib/aws-sdk-s3/bucket_notification.rb +43 -17
- data/lib/aws-sdk-s3/bucket_policy.rb +51 -13
- data/lib/aws-sdk-s3/bucket_region_cache.rb +2 -0
- data/lib/aws-sdk-s3/bucket_request_payment.rb +51 -12
- data/lib/aws-sdk-s3/bucket_tagging.rb +59 -14
- data/lib/aws-sdk-s3/bucket_versioning.rb +118 -12
- data/lib/aws-sdk-s3/bucket_website.rb +66 -17
- data/lib/aws-sdk-s3/client.rb +8996 -758
- data/lib/aws-sdk-s3/client_api.rb +778 -2
- data/lib/aws-sdk-s3/customizations/bucket.rb +59 -16
- data/lib/aws-sdk-s3/customizations/multipart_upload.rb +2 -0
- data/lib/aws-sdk-s3/customizations/object.rb +200 -62
- 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.rb +4 -1
- data/lib/aws-sdk-s3/encryption/client.rb +22 -5
- 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 +34 -3
- 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 +566 -0
- data/lib/aws-sdk-s3/encryptionV2/decrypt_handler.rb +222 -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 +169 -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/errors.rb +123 -1
- data/lib/aws-sdk-s3/event_streams.rb +8 -1
- data/lib/aws-sdk-s3/file_downloader.rb +17 -10
- data/lib/aws-sdk-s3/file_part.rb +11 -6
- data/lib/aws-sdk-s3/file_uploader.rb +33 -14
- data/lib/aws-sdk-s3/legacy_signer.rb +17 -25
- data/lib/aws-sdk-s3/multipart_file_uploader.rb +78 -19
- data/lib/aws-sdk-s3/multipart_stream_uploader.rb +18 -7
- data/lib/aws-sdk-s3/multipart_upload.rb +178 -29
- data/lib/aws-sdk-s3/multipart_upload_error.rb +2 -0
- data/lib/aws-sdk-s3/multipart_upload_part.rb +233 -42
- data/lib/aws-sdk-s3/object.rb +846 -179
- data/lib/aws-sdk-s3/object_acl.rb +79 -21
- data/lib/aws-sdk-s3/object_copier.rb +2 -0
- data/lib/aws-sdk-s3/object_multipart_copier.rb +2 -0
- data/lib/aws-sdk-s3/object_summary.rb +613 -162
- data/lib/aws-sdk-s3/object_version.rb +162 -71
- data/lib/aws-sdk-s3/plugins/accelerate.rb +38 -38
- data/lib/aws-sdk-s3/plugins/arn.rb +254 -0
- data/lib/aws-sdk-s3/plugins/bucket_dns.rb +8 -8
- data/lib/aws-sdk-s3/plugins/bucket_name_restrictions.rb +25 -3
- data/lib/aws-sdk-s3/plugins/dualstack.rb +38 -33
- data/lib/aws-sdk-s3/plugins/expect_100_continue.rb +4 -4
- 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 +73 -0
- data/lib/aws-sdk-s3/plugins/location_constraint.rb +2 -0
- data/lib/aws-sdk-s3/plugins/md5s.rb +34 -30
- data/lib/aws-sdk-s3/plugins/object_lambda_endpoint.rb +25 -0
- 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 +94 -36
- 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 +110 -51
- data/lib/aws-sdk-s3/presigner.rb +133 -45
- data/lib/aws-sdk-s3/resource.rb +43 -7
- data/lib/aws-sdk-s3/types.rb +8445 -1136
- data/lib/aws-sdk-s3/waiters.rb +67 -1
- data/lib/aws-sdk-s3.rb +12 -6
- metadata +37 -12
@@ -1,21 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'openssl'
|
2
|
-
require 'base64'
|
3
4
|
|
4
5
|
module Aws
|
5
6
|
module S3
|
6
7
|
module Plugins
|
8
|
+
# @api private
|
9
|
+
# This plugin is effectively deprecated in favor of modeled
|
10
|
+
# httpChecksumRequired traits.
|
7
11
|
class Md5s < Seahorse::Client::Plugin
|
8
|
-
|
9
|
-
#
|
10
|
-
|
11
|
-
:
|
12
|
-
:
|
13
|
-
:put_bucket_lifecycle,
|
14
|
-
:put_bucket_policy,
|
15
|
-
:put_bucket_tagging,
|
16
|
-
:put_object_legal_hold,
|
17
|
-
:put_object_lock_configuration,
|
18
|
-
:put_object_retention
|
12
|
+
# These operations allow Content MD5 but are not required by
|
13
|
+
# httpChecksumRequired. This list should not grow.
|
14
|
+
OPTIONAL_OPERATIONS = [
|
15
|
+
:put_object,
|
16
|
+
:upload_part
|
19
17
|
]
|
20
18
|
|
21
19
|
# @api private
|
@@ -24,9 +22,11 @@ module Aws
|
|
24
22
|
CHUNK_SIZE = 1 * 1024 * 1024 # one MB
|
25
23
|
|
26
24
|
def call(context)
|
27
|
-
|
28
|
-
|
29
|
-
|
25
|
+
if !context[:checksum_algorithms] # skip in favor of flexible checksum
|
26
|
+
body = context.http_request.body
|
27
|
+
if body.respond_to?(:size) && body.size > 0
|
28
|
+
context.http_request.headers['Content-Md5'] ||= md5(body)
|
29
|
+
end
|
30
30
|
end
|
31
31
|
@handler.call(context)
|
32
32
|
end
|
@@ -37,18 +37,20 @@ module Aws
|
|
37
37
|
# @return [String<MD5>]
|
38
38
|
def md5(value)
|
39
39
|
if (File === value || Tempfile === value) && !value.path.nil? && File.exist?(value.path)
|
40
|
-
|
40
|
+
OpenSSL::Digest::MD5.file(value).base64digest
|
41
41
|
elsif value.respond_to?(:read)
|
42
42
|
md5 = OpenSSL::Digest::MD5.new
|
43
43
|
update_in_chunks(md5, value)
|
44
|
-
|
44
|
+
md5.base64digest
|
45
45
|
else
|
46
|
-
|
46
|
+
OpenSSL::Digest::MD5.digest(value).base64digest
|
47
47
|
end
|
48
48
|
end
|
49
49
|
|
50
50
|
def update_in_chunks(digest, io)
|
51
|
-
|
51
|
+
loop do
|
52
|
+
chunk = io.read(CHUNK_SIZE)
|
53
|
+
break unless chunk
|
52
54
|
digest.update(chunk)
|
53
55
|
end
|
54
56
|
io.rewind
|
@@ -60,20 +62,22 @@ module Aws
|
|
60
62
|
default: true,
|
61
63
|
doc_type: 'Boolean',
|
62
64
|
docstring: <<-DOCS)
|
63
|
-
When `true` a MD5 checksum will be computed
|
64
|
-
|
65
|
-
|
66
|
-
|
65
|
+
When `true` a MD5 checksum will be computed and sent in the Content Md5
|
66
|
+
header for :put_object and :upload_part. When `false`, MD5 checksums
|
67
|
+
will not be computed for these operations. Checksums are still computed
|
68
|
+
for operations requiring them. Checksum errors returned by Amazon S3 are
|
69
|
+
automatically retried up to `:retry_limit` times.
|
67
70
|
DOCS
|
68
71
|
|
69
72
|
def add_handlers(handlers, config)
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
73
|
+
if config.compute_checksums
|
74
|
+
# priority set low to ensure md5 is computed AFTER the request is
|
75
|
+
# built but before it is signed
|
76
|
+
handlers.add(
|
77
|
+
Handler,
|
78
|
+
priority: 10, step: :build, operations: OPTIONAL_OPERATIONS
|
79
|
+
)
|
80
|
+
end
|
77
81
|
end
|
78
82
|
|
79
83
|
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Aws
|
4
|
+
module S3
|
5
|
+
module Plugins
|
6
|
+
# WriteGetObjectResponse is called from Lambda after a data transform.
|
7
|
+
# If there is no custom endpoint, we change the endpoint from s3 to
|
8
|
+
# s3-object-lambda just for this operation.
|
9
|
+
class ObjectLambdaEndpoint < Seahorse::Client::Plugin
|
10
|
+
class Handler < Seahorse::Client::Handler
|
11
|
+
def call(context)
|
12
|
+
if context.config.regional_endpoint
|
13
|
+
host = context.http_request.endpoint.host
|
14
|
+
host = host.sub('s3.', 's3-object-lambda.')
|
15
|
+
context.http_request.endpoint.host = host
|
16
|
+
end
|
17
|
+
@handler.call(context)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
handler(Handler, operations: [:write_get_object_response])
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'aws-sigv4'
|
2
4
|
|
3
5
|
module Aws
|
@@ -6,18 +8,23 @@ module Aws
|
|
6
8
|
# This plugin is an implementation detail and may be modified.
|
7
9
|
# @api private
|
8
10
|
class S3Signer < Seahorse::Client::Plugin
|
9
|
-
|
10
11
|
option(:signature_version, 'v4')
|
11
12
|
|
12
13
|
option(:sigv4_signer) do |cfg|
|
13
14
|
S3Signer.build_v4_signer(
|
15
|
+
service: 's3',
|
14
16
|
region: cfg.sigv4_region,
|
15
17
|
credentials: cfg.credentials
|
16
18
|
)
|
17
19
|
end
|
18
20
|
|
19
21
|
option(:sigv4_region) do |cfg|
|
20
|
-
|
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
|
+
)
|
21
28
|
end
|
22
29
|
|
23
30
|
def add_handlers(handlers, cfg)
|
@@ -48,7 +55,6 @@ module Aws
|
|
48
55
|
end
|
49
56
|
|
50
57
|
class V4Handler < Seahorse::Client::Handler
|
51
|
-
|
52
58
|
def call(context)
|
53
59
|
Aws::Plugins::SignatureV4.apply_signature(
|
54
60
|
context: context,
|
@@ -62,25 +68,42 @@ module Aws
|
|
62
68
|
def sigv4_signer(context)
|
63
69
|
# If the client was configured with the wrong region,
|
64
70
|
# we have to build a new signer.
|
65
|
-
if
|
66
|
-
|
67
|
-
context[:cached_sigv4_region] != context.config.sigv4_signer.region
|
68
|
-
then
|
71
|
+
if context[:cached_sigv4_region] &&
|
72
|
+
context[:cached_sigv4_region] != context.config.sigv4_signer.region
|
69
73
|
S3Signer.build_v4_signer(
|
74
|
+
service: 's3',
|
70
75
|
region: context[:cached_sigv4_region],
|
71
76
|
credentials: context.config.credentials
|
72
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
|
+
)
|
73
98
|
else
|
74
99
|
context.config.sigv4_signer
|
75
100
|
end
|
76
101
|
end
|
77
|
-
|
78
102
|
end
|
79
103
|
|
80
104
|
# This handler will update the http endpoint when the bucket region
|
81
105
|
# is known/cached.
|
82
106
|
class CachedBucketRegionHandler < Seahorse::Client::Handler
|
83
|
-
|
84
107
|
def call(context)
|
85
108
|
bucket = context.params[:bucket]
|
86
109
|
check_for_cached_region(context, bucket) if bucket
|
@@ -92,11 +115,12 @@ module Aws
|
|
92
115
|
def check_for_cached_region(context, bucket)
|
93
116
|
cached_region = S3::BUCKET_REGIONS[bucket]
|
94
117
|
if cached_region && cached_region != context.config.region
|
95
|
-
context.http_request.endpoint.host = S3Signer.new_hostname(
|
118
|
+
context.http_request.endpoint.host = S3Signer.new_hostname(
|
119
|
+
context, cached_region
|
120
|
+
)
|
96
121
|
context[:cached_sigv4_region] = cached_region
|
97
122
|
end
|
98
123
|
end
|
99
|
-
|
100
124
|
end
|
101
125
|
|
102
126
|
# This handler detects when a request fails because of a mismatched bucket
|
@@ -104,7 +128,6 @@ module Aws
|
|
104
128
|
# region, then finally a version 4 signed request against the correct
|
105
129
|
# regional endpoint.
|
106
130
|
class BucketRegionErrorHandler < Seahorse::Client::Handler
|
107
|
-
|
108
131
|
def call(context)
|
109
132
|
response = @handler.call(context)
|
110
133
|
handle_region_errors(response)
|
@@ -113,7 +136,10 @@ module Aws
|
|
113
136
|
private
|
114
137
|
|
115
138
|
def handle_region_errors(response)
|
116
|
-
if wrong_sigv4_region?(response) &&
|
139
|
+
if wrong_sigv4_region?(response) &&
|
140
|
+
!fips_region?(response) &&
|
141
|
+
!custom_endpoint?(response) &&
|
142
|
+
!expired_credentials?(response)
|
117
143
|
get_region_and_retry(response.context)
|
118
144
|
else
|
119
145
|
response
|
@@ -137,21 +163,42 @@ module Aws
|
|
137
163
|
resp.context.http_request.endpoint.host.include?('fips')
|
138
164
|
end
|
139
165
|
|
166
|
+
def expired_credentials?(resp)
|
167
|
+
resp.context.http_response.body_contents.match(/<Code>ExpiredToken<\/Code>/)
|
168
|
+
end
|
169
|
+
|
170
|
+
def custom_endpoint?(resp)
|
171
|
+
resolved_suffix = Aws::Partitions::EndpointProvider.dns_suffix_for(
|
172
|
+
resp.context.config.region,
|
173
|
+
's3',
|
174
|
+
{
|
175
|
+
dualstack: resp.context[:use_dualstack_endpoint],
|
176
|
+
fips: resp.context.config.use_fips_endpoint
|
177
|
+
}
|
178
|
+
)
|
179
|
+
!resp.context.http_request.endpoint.hostname.include?(resolved_suffix)
|
180
|
+
end
|
181
|
+
|
140
182
|
def wrong_sigv4_region?(resp)
|
141
183
|
resp.context.http_response.status_code == 400 &&
|
142
|
-
|
143
|
-
|
144
|
-
resp.context.http_response.body_contents.match(/<Region>.+?<\/Region>/)
|
145
|
-
)
|
184
|
+
(resp.context.http_response.headers['x-amz-bucket-region'] ||
|
185
|
+
resp.context.http_response.body_contents.match(/<Region>.+?<\/Region>/))
|
146
186
|
end
|
147
187
|
|
148
188
|
def resign_with_new_region(context, actual_region)
|
149
189
|
context.http_response.body.truncate(0)
|
150
|
-
context.http_request.endpoint.host = S3Signer.new_hostname(
|
190
|
+
context.http_request.endpoint.host = S3Signer.new_hostname(
|
191
|
+
context, actual_region
|
192
|
+
)
|
151
193
|
context.metadata[:redirect_region] = actual_region
|
194
|
+
# if it's an ARN, use the service in the ARN
|
195
|
+
if (arn = context.metadata[:s3_arn])
|
196
|
+
service = arn[:arn].service
|
197
|
+
end
|
152
198
|
Aws::Plugins::SignatureV4.apply_signature(
|
153
199
|
context: context,
|
154
200
|
signer: S3Signer.build_v4_signer(
|
201
|
+
service: service || 's3',
|
155
202
|
region: actual_region,
|
156
203
|
credentials: context.config.credentials
|
157
204
|
)
|
@@ -160,7 +207,7 @@ module Aws
|
|
160
207
|
|
161
208
|
def region_from_body(body)
|
162
209
|
region = body.match(/<Region>(.+?)<\/Region>/)[1]
|
163
|
-
if region.nil? || region ==
|
210
|
+
if region.nil? || region == ''
|
164
211
|
raise "couldn't get region from body: #{body}"
|
165
212
|
else
|
166
213
|
region
|
@@ -168,44 +215,55 @@ module Aws
|
|
168
215
|
end
|
169
216
|
|
170
217
|
def log_warning(context, actual_region)
|
171
|
-
msg = "S3 client configured for #{context.config.region.inspect} "
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
if logger = context.config.logger
|
218
|
+
msg = "S3 client configured for #{context.config.region.inspect} " \
|
219
|
+
"but the bucket #{context.params[:bucket].inspect} is in " \
|
220
|
+
"#{actual_region.inspect}; Please configure the proper region " \
|
221
|
+
"to avoid multiple unnecessary redirects and signing attempts\n"
|
222
|
+
if (logger = context.config.logger)
|
176
223
|
logger.warn(msg)
|
177
224
|
else
|
178
225
|
warn(msg)
|
179
226
|
end
|
180
227
|
end
|
181
|
-
|
182
228
|
end
|
183
229
|
|
184
230
|
class << self
|
185
|
-
|
186
231
|
# @option options [required, String] :region
|
187
232
|
# @option options [required, #credentials] :credentials
|
188
233
|
# @api private
|
189
234
|
def build_v4_signer(options = {})
|
190
|
-
Aws::Sigv4::Signer.new(
|
191
|
-
service:
|
235
|
+
Aws::Sigv4::Signer.new(
|
236
|
+
service: options[:service],
|
192
237
|
region: options[:region],
|
193
238
|
credentials_provider: options[:credentials],
|
239
|
+
signing_algorithm: options.fetch(:signing_algorithm, :sigv4),
|
194
240
|
uri_escape_path: false,
|
195
|
-
unsigned_headers: ['content-length', 'x-amzn-trace-id']
|
196
|
-
|
241
|
+
unsigned_headers: ['content-length', 'x-amzn-trace-id']
|
242
|
+
)
|
197
243
|
end
|
198
244
|
|
245
|
+
# Check to see if the bucket is actually an ARN
|
246
|
+
# Otherwise it will retry with the ARN as the bucket name.
|
199
247
|
def new_hostname(context, region)
|
200
|
-
|
201
|
-
|
202
|
-
|
248
|
+
uri = URI.parse(
|
249
|
+
Aws::Partitions::EndpointProvider.resolve(
|
250
|
+
region, 's3', 'regional',
|
251
|
+
{
|
252
|
+
dualstack: context[:use_dualstack_endpoint],
|
253
|
+
fips: context.config.use_fips_endpoint
|
254
|
+
}
|
255
|
+
)
|
256
|
+
)
|
257
|
+
|
258
|
+
if (arn = context.metadata[:s3_arn])
|
259
|
+
# Retry with the response region and not the ARN resolved one
|
260
|
+
ARN.resolve_url!(
|
261
|
+
uri, arn[:arn], region, arn[:fips], arn[:dualstack]
|
262
|
+
).host
|
203
263
|
else
|
204
|
-
|
205
|
-
bucket + '.' + URI.parse(endpoint).host
|
264
|
+
"#{context.params[:bucket]}.#{uri.host}"
|
206
265
|
end
|
207
266
|
end
|
208
|
-
|
209
267
|
end
|
210
268
|
end
|
211
269
|
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
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'uri'
|
2
4
|
require 'openssl'
|
3
5
|
|
@@ -18,7 +20,7 @@ This should only be disabled for local testing.
|
|
18
20
|
class Handler < Seahorse::Client::Handler
|
19
21
|
|
20
22
|
def call(context)
|
21
|
-
compute_key_md5(context)
|
23
|
+
compute_key_md5(context) if context.params.is_a?(Hash)
|
22
24
|
@handler.call(context)
|
23
25
|
end
|
24
26
|
|
@@ -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
|