aws-sdk-s3 1.10.0 → 1.208.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.
- checksums.yaml +5 -5
- data/CHANGELOG.md +1517 -0
- data/LICENSE.txt +202 -0
- data/VERSION +1 -0
- data/lib/aws-sdk-s3/access_grants_credentials.rb +57 -0
- data/lib/aws-sdk-s3/access_grants_credentials_provider.rb +250 -0
- data/lib/aws-sdk-s3/bucket.rb +1062 -99
- data/lib/aws-sdk-s3/bucket_acl.rb +67 -17
- data/lib/aws-sdk-s3/bucket_cors.rb +80 -17
- data/lib/aws-sdk-s3/bucket_lifecycle.rb +71 -19
- data/lib/aws-sdk-s3/bucket_lifecycle_configuration.rb +126 -20
- data/lib/aws-sdk-s3/bucket_logging.rb +68 -18
- data/lib/aws-sdk-s3/bucket_notification.rb +56 -20
- data/lib/aws-sdk-s3/bucket_policy.rb +108 -17
- data/lib/aws-sdk-s3/bucket_region_cache.rb +11 -5
- data/lib/aws-sdk-s3/bucket_request_payment.rb +60 -15
- data/lib/aws-sdk-s3/bucket_tagging.rb +71 -17
- data/lib/aws-sdk-s3/bucket_versioning.rb +166 -17
- data/lib/aws-sdk-s3/bucket_website.rb +78 -17
- data/lib/aws-sdk-s3/client.rb +20068 -3879
- data/lib/aws-sdk-s3/client_api.rb +1957 -209
- data/lib/aws-sdk-s3/customizations/bucket.rb +57 -38
- data/lib/aws-sdk-s3/customizations/errors.rb +40 -0
- data/lib/aws-sdk-s3/customizations/multipart_upload.rb +2 -0
- data/lib/aws-sdk-s3/customizations/object.rb +338 -68
- data/lib/aws-sdk-s3/customizations/object_summary.rb +17 -0
- data/lib/aws-sdk-s3/customizations/object_version.rb +13 -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 +30 -27
- data/lib/aws-sdk-s3/default_executor.rb +103 -0
- data/lib/aws-sdk-s3/encryption/client.rb +29 -8
- data/lib/aws-sdk-s3/encryption/decrypt_handler.rb +71 -29
- data/lib/aws-sdk-s3/encryption/default_cipher_provider.rb +45 -5
- data/lib/aws-sdk-s3/encryption/default_key_provider.rb +2 -0
- data/lib/aws-sdk-s3/encryption/encrypt_handler.rb +15 -2
- data/lib/aws-sdk-s3/encryption/errors.rb +2 -0
- data/lib/aws-sdk-s3/encryption/io_auth_decrypter.rb +11 -3
- 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 +48 -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 +645 -0
- data/lib/aws-sdk-s3/encryptionV2/decrypt_handler.rb +68 -0
- data/lib/aws-sdk-s3/encryptionV2/decryption.rb +205 -0
- data/lib/aws-sdk-s3/encryptionV2/default_cipher_provider.rb +187 -0
- data/lib/aws-sdk-s3/encryptionV2/default_key_provider.rb +40 -0
- data/lib/aws-sdk-s3/encryptionV2/encrypt_handler.rb +67 -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 +75 -0
- data/lib/aws-sdk-s3/encryptionV2/key_provider.rb +31 -0
- data/lib/aws-sdk-s3/encryptionV2/kms_cipher_provider.rb +181 -0
- data/lib/aws-sdk-s3/encryptionV2/materials.rb +60 -0
- data/lib/aws-sdk-s3/encryptionV2/utils.rb +108 -0
- data/lib/aws-sdk-s3/encryptionV3/client.rb +885 -0
- data/lib/aws-sdk-s3/encryptionV3/decrypt_handler.rb +98 -0
- data/lib/aws-sdk-s3/encryptionV3/decryption.rb +244 -0
- data/lib/aws-sdk-s3/encryptionV3/default_cipher_provider.rb +159 -0
- data/lib/aws-sdk-s3/encryptionV3/default_key_provider.rb +35 -0
- data/lib/aws-sdk-s3/encryptionV3/encrypt_handler.rb +98 -0
- data/lib/aws-sdk-s3/encryptionV3/errors.rb +47 -0
- data/lib/aws-sdk-s3/encryptionV3/io_auth_decrypter.rb +60 -0
- data/lib/aws-sdk-s3/encryptionV3/io_decrypter.rb +35 -0
- data/lib/aws-sdk-s3/encryptionV3/io_encrypter.rb +84 -0
- data/lib/aws-sdk-s3/encryptionV3/key_provider.rb +28 -0
- data/lib/aws-sdk-s3/encryptionV3/kms_cipher_provider.rb +159 -0
- data/lib/aws-sdk-s3/encryptionV3/materials.rb +58 -0
- data/lib/aws-sdk-s3/encryptionV3/utils.rb +321 -0
- data/lib/aws-sdk-s3/encryption_v2.rb +24 -0
- data/lib/aws-sdk-s3/encryption_v3.rb +24 -0
- data/lib/aws-sdk-s3/endpoint_parameters.rb +181 -0
- data/lib/aws-sdk-s3/endpoint_provider.rb +886 -0
- data/lib/aws-sdk-s3/endpoints.rb +1544 -0
- data/lib/aws-sdk-s3/errors.rb +181 -1
- data/lib/aws-sdk-s3/event_streams.rb +69 -0
- data/lib/aws-sdk-s3/express_credentials.rb +55 -0
- data/lib/aws-sdk-s3/express_credentials_provider.rb +59 -0
- data/lib/aws-sdk-s3/file_downloader.rb +261 -82
- data/lib/aws-sdk-s3/file_part.rb +16 -13
- data/lib/aws-sdk-s3/file_uploader.rb +37 -22
- data/lib/aws-sdk-s3/legacy_signer.rb +19 -26
- data/lib/aws-sdk-s3/multipart_download_error.rb +8 -0
- data/lib/aws-sdk-s3/multipart_file_uploader.rb +142 -80
- data/lib/aws-sdk-s3/multipart_stream_uploader.rb +191 -0
- data/lib/aws-sdk-s3/multipart_upload.rb +342 -31
- data/lib/aws-sdk-s3/multipart_upload_error.rb +5 -4
- data/lib/aws-sdk-s3/multipart_upload_part.rb +387 -47
- data/lib/aws-sdk-s3/object.rb +2733 -204
- data/lib/aws-sdk-s3/object_acl.rb +112 -25
- data/lib/aws-sdk-s3/object_copier.rb +9 -5
- data/lib/aws-sdk-s3/object_multipart_copier.rb +50 -23
- data/lib/aws-sdk-s3/object_summary.rb +2265 -181
- data/lib/aws-sdk-s3/object_version.rb +542 -74
- data/lib/aws-sdk-s3/plugins/accelerate.rb +17 -64
- data/lib/aws-sdk-s3/plugins/access_grants.rb +178 -0
- 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/checksum_algorithm.rb +31 -0
- data/lib/aws-sdk-s3/plugins/dualstack.rb +7 -50
- data/lib/aws-sdk-s3/plugins/endpoints.rb +86 -0
- data/lib/aws-sdk-s3/plugins/expect_100_continue.rb +5 -4
- data/lib/aws-sdk-s3/plugins/express_session_auth.rb +88 -0
- data/lib/aws-sdk-s3/plugins/get_bucket_location_fix.rb +3 -1
- data/lib/aws-sdk-s3/plugins/http_200_errors.rb +62 -17
- 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 +14 -67
- data/lib/aws-sdk-s3/plugins/redirects.rb +5 -1
- data/lib/aws-sdk-s3/plugins/s3_host_id.rb +2 -0
- data/lib/aws-sdk-s3/plugins/s3_signer.rb +67 -93
- data/lib/aws-sdk-s3/plugins/sse_cpk.rb +3 -1
- data/lib/aws-sdk-s3/plugins/streaming_retry.rb +137 -0
- data/lib/aws-sdk-s3/plugins/url_encoded_keys.rb +4 -1
- data/lib/aws-sdk-s3/presigned_post.rb +160 -99
- data/lib/aws-sdk-s3/presigner.rb +178 -81
- data/lib/aws-sdk-s3/resource.rb +164 -15
- data/lib/aws-sdk-s3/transfer_manager.rb +303 -0
- data/lib/aws-sdk-s3/types.rb +15981 -4168
- data/lib/aws-sdk-s3/waiters.rb +67 -1
- data/lib/aws-sdk-s3.rb +46 -31
- data/sig/bucket.rbs +231 -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 +115 -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 +2612 -0
- data/sig/customizations/bucket.rbs +19 -0
- data/sig/customizations/object.rbs +38 -0
- data/sig/customizations/object_summary.rbs +35 -0
- data/sig/errors.rbs +44 -0
- data/sig/multipart_upload.rbs +120 -0
- data/sig/multipart_upload_part.rbs +109 -0
- data/sig/object.rbs +464 -0
- data/sig/object_acl.rbs +86 -0
- data/sig/object_summary.rbs +347 -0
- data/sig/object_version.rbs +143 -0
- data/sig/resource.rbs +141 -0
- data/sig/types.rbs +2899 -0
- data/sig/waiters.rbs +95 -0
- metadata +97 -14
data/lib/aws-sdk-s3/presigner.rb
CHANGED
|
@@ -1,27 +1,95 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
module Aws
|
|
2
4
|
module S3
|
|
3
|
-
|
|
4
|
-
# Allows you to create presigned URLs for S3 operations.
|
|
5
|
-
#
|
|
6
|
-
# Example Use:
|
|
7
|
-
#
|
|
8
|
-
# signer = Aws::S3::Presigner.new
|
|
9
|
-
# url = signer.presigned_url(:get_object, bucket: "bucket", key: "key")
|
|
10
|
-
#
|
|
11
5
|
class Presigner
|
|
12
|
-
|
|
13
6
|
# @api private
|
|
14
7
|
ONE_WEEK = 60 * 60 * 24 * 7
|
|
15
8
|
|
|
16
9
|
# @api private
|
|
17
10
|
FIFTEEN_MINUTES = 60 * 15
|
|
18
11
|
|
|
12
|
+
# @api private
|
|
13
|
+
BLACKLISTED_HEADERS = [
|
|
14
|
+
'accept',
|
|
15
|
+
'amz-sdk-request',
|
|
16
|
+
'cache-control',
|
|
17
|
+
'content-length', # due to a ELB bug
|
|
18
|
+
'expect',
|
|
19
|
+
'from',
|
|
20
|
+
'if-match',
|
|
21
|
+
'if-none-match',
|
|
22
|
+
'if-modified-since',
|
|
23
|
+
'if-unmodified-since',
|
|
24
|
+
'if-range',
|
|
25
|
+
'max-forwards',
|
|
26
|
+
'pragma',
|
|
27
|
+
'proxy-authorization',
|
|
28
|
+
'referer',
|
|
29
|
+
'te',
|
|
30
|
+
'user-agent'
|
|
31
|
+
].freeze
|
|
32
|
+
|
|
19
33
|
# @option options [Client] :client Optionally provide an existing
|
|
20
34
|
# S3 client
|
|
21
35
|
def initialize(options = {})
|
|
22
36
|
@client = options[:client] || Aws::S3::Client.new
|
|
23
37
|
end
|
|
24
38
|
|
|
39
|
+
# Create presigned URLs for S3 operations.
|
|
40
|
+
#
|
|
41
|
+
# @example
|
|
42
|
+
# signer = Aws::S3::Presigner.new
|
|
43
|
+
# url = signer.presigned_url(:get_object, bucket: "bucket", key: "key")
|
|
44
|
+
#
|
|
45
|
+
# @param [Symbol] method Symbolized method name of the operation you want
|
|
46
|
+
# to presign.
|
|
47
|
+
#
|
|
48
|
+
# @option params [Integer] :expires_in (900) The number of seconds
|
|
49
|
+
# before the presigned URL expires. Defaults to 15 minutes. As signature
|
|
50
|
+
# version 4 has a maximum expiry time of one week for presigned URLs,
|
|
51
|
+
# attempts to set this value to greater than one week (604800) will
|
|
52
|
+
# raise an exception. The min value of this option and the credentials
|
|
53
|
+
# expiration time is used in the presigned URL.
|
|
54
|
+
#
|
|
55
|
+
# @option params [Time] :time (Time.now) The starting time for when the
|
|
56
|
+
# presigned url becomes active.
|
|
57
|
+
#
|
|
58
|
+
# @option params [Boolean] :secure (true) When `false`, a HTTP URL
|
|
59
|
+
# is returned instead of the default HTTPS URL.
|
|
60
|
+
#
|
|
61
|
+
# @option params [Boolean] :virtual_host (false) When `true`, the
|
|
62
|
+
# bucket name will be used as the hostname.
|
|
63
|
+
#
|
|
64
|
+
# @option params [Boolean] :use_accelerate_endpoint (false) When `true`,
|
|
65
|
+
# Presigner will attempt to use accelerated endpoint.
|
|
66
|
+
#
|
|
67
|
+
# @option params [Array<String>] :whitelist_headers ([]) Additional
|
|
68
|
+
# headers to be included for the signed request. Certain headers beyond
|
|
69
|
+
# the authorization header could, in theory, be changed for various
|
|
70
|
+
# reasons (including but not limited to proxies) while in transit and
|
|
71
|
+
# after signing. This would lead to signature errors being returned,
|
|
72
|
+
# despite no actual problems with signing. (see BLACKLISTED_HEADERS)
|
|
73
|
+
#
|
|
74
|
+
# @raise [ArgumentError] Raises an ArgumentError if `:expires_in`
|
|
75
|
+
# exceeds one week.
|
|
76
|
+
#
|
|
77
|
+
# @return [String] a presigned url
|
|
78
|
+
def presigned_url(method, params = {})
|
|
79
|
+
url, _headers = _presigned_request(method, params)
|
|
80
|
+
url
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
# Allows you to create presigned URL requests for S3 operations. This
|
|
84
|
+
# method returns a tuple containing the URL and the signed X-amz-* headers
|
|
85
|
+
# to be used with the presigned url.
|
|
86
|
+
#
|
|
87
|
+
# @example
|
|
88
|
+
# signer = Aws::S3::Presigner.new
|
|
89
|
+
# url, headers = signer.presigned_request(
|
|
90
|
+
# :get_object, bucket: "bucket", key: "key"
|
|
91
|
+
# )
|
|
92
|
+
#
|
|
25
93
|
# @param [Symbol] method Symbolized method name of the operation you want
|
|
26
94
|
# to presign.
|
|
27
95
|
#
|
|
@@ -29,7 +97,11 @@ module Aws
|
|
|
29
97
|
# before the presigned URL expires. Defaults to 15 minutes. As signature
|
|
30
98
|
# version 4 has a maximum expiry time of one week for presigned URLs,
|
|
31
99
|
# attempts to set this value to greater than one week (604800) will
|
|
32
|
-
# raise an exception.
|
|
100
|
+
# raise an exception. The min value of this option and the credentials
|
|
101
|
+
# expiration time is used in the presigned URL.
|
|
102
|
+
#
|
|
103
|
+
# @option params [Time] :time (Time.now) The starting time for when the
|
|
104
|
+
# presigned url becomes active.
|
|
33
105
|
#
|
|
34
106
|
# @option params [Boolean] :secure (true) When `false`, a HTTP URL
|
|
35
107
|
# is returned instead of the default HTTPS URL.
|
|
@@ -38,37 +110,57 @@ module Aws
|
|
|
38
110
|
# bucket name will be used as the hostname. This will cause
|
|
39
111
|
# the returned URL to be 'http' and not 'https'.
|
|
40
112
|
#
|
|
113
|
+
# @option params [Boolean] :use_accelerate_endpoint (false) When `true`,
|
|
114
|
+
# Presigner will attempt to use accelerated endpoint.
|
|
115
|
+
#
|
|
116
|
+
# @option params [Array<String>] :whitelist_headers ([]) Additional
|
|
117
|
+
# headers to be included for the signed request. Certain headers beyond
|
|
118
|
+
# the authorization header could, in theory, be changed for various
|
|
119
|
+
# reasons (including but not limited to proxies) while in transit and
|
|
120
|
+
# after signing. This would lead to signature errors being returned,
|
|
121
|
+
# despite no actual problems with signing. (see BLACKLISTED_HEADERS)
|
|
122
|
+
#
|
|
41
123
|
# @raise [ArgumentError] Raises an ArgumentError if `:expires_in`
|
|
42
124
|
# exceeds one week.
|
|
43
125
|
#
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
126
|
+
# @return [String, Hash] A tuple with a presigned URL and headers that
|
|
127
|
+
# should be included with the request.
|
|
128
|
+
def presigned_request(method, params = {})
|
|
129
|
+
_presigned_request(method, params, false)
|
|
130
|
+
end
|
|
131
|
+
|
|
132
|
+
private
|
|
133
|
+
|
|
134
|
+
def _presigned_request(method, params, hoist = true)
|
|
135
|
+
virtual_host = params.delete(:virtual_host)
|
|
136
|
+
time = params.delete(:time)
|
|
137
|
+
unsigned_headers = unsigned_headers(params)
|
|
138
|
+
secure = params.delete(:secure) != false
|
|
139
|
+
expires_in = expires_in(params)
|
|
50
140
|
|
|
51
141
|
req = @client.build_request(method, params)
|
|
52
142
|
use_bucket_as_hostname(req) if virtual_host
|
|
53
|
-
|
|
54
|
-
req.send_request.data
|
|
55
|
-
end
|
|
143
|
+
handle_presigned_url_context(req)
|
|
56
144
|
|
|
57
|
-
|
|
145
|
+
x_amz_headers = sign_but_dont_send(
|
|
146
|
+
req, expires_in, secure, time, unsigned_headers, hoist
|
|
147
|
+
)
|
|
148
|
+
[req.send_request.data, x_amz_headers]
|
|
149
|
+
end
|
|
58
150
|
|
|
59
|
-
def
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
else
|
|
63
|
-
@client.config.endpoint.scheme
|
|
64
|
-
end
|
|
151
|
+
def unsigned_headers(params)
|
|
152
|
+
whitelist_headers = params.delete(:whitelist_headers) || []
|
|
153
|
+
BLACKLISTED_HEADERS - whitelist_headers
|
|
65
154
|
end
|
|
66
155
|
|
|
67
156
|
def expires_in(params)
|
|
68
|
-
if expires_in = params.delete(:expires_in)
|
|
157
|
+
if (expires_in = params.delete(:expires_in))
|
|
69
158
|
if expires_in > ONE_WEEK
|
|
70
|
-
|
|
71
|
-
|
|
159
|
+
raise ArgumentError,
|
|
160
|
+
"expires_in value of #{expires_in} exceeds one-week maximum."
|
|
161
|
+
elsif expires_in <= 0
|
|
162
|
+
raise ArgumentError,
|
|
163
|
+
"expires_in value of #{expires_in} cannot be 0 or less."
|
|
72
164
|
end
|
|
73
165
|
expires_in
|
|
74
166
|
else
|
|
@@ -77,88 +169,93 @@ module Aws
|
|
|
77
169
|
end
|
|
78
170
|
|
|
79
171
|
def use_bucket_as_hostname(req)
|
|
80
|
-
req.
|
|
81
|
-
req.handle do |context|
|
|
172
|
+
req.handle(priority: 35) do |context|
|
|
82
173
|
uri = context.http_request.endpoint
|
|
83
174
|
uri.host = context.params[:bucket]
|
|
84
175
|
uri.path.sub!("/#{context.params[:bucket]}", '')
|
|
85
|
-
uri.scheme = 'http'
|
|
86
|
-
uri.port = 80
|
|
87
176
|
@handler.call(context)
|
|
88
177
|
end
|
|
89
178
|
end
|
|
90
179
|
|
|
91
|
-
#
|
|
92
|
-
|
|
180
|
+
# Used for excluding presigned_urls from API request count.
|
|
181
|
+
#
|
|
182
|
+
# Store context information as early as possible, to allow
|
|
183
|
+
# handlers to perform decisions based on this flag if need.
|
|
184
|
+
def handle_presigned_url_context(req)
|
|
185
|
+
req.handle(step: :initialize, priority: 98) do |context|
|
|
186
|
+
context[:presigned_url] = true
|
|
187
|
+
@handler.call(context)
|
|
188
|
+
end
|
|
189
|
+
end
|
|
93
190
|
|
|
191
|
+
# @param [Seahorse::Client::Request] req
|
|
192
|
+
def sign_but_dont_send(
|
|
193
|
+
req, expires_in, secure, time, unsigned_headers, hoist = true
|
|
194
|
+
)
|
|
195
|
+
x_amz_headers = {}
|
|
94
196
|
http_req = req.context.http_request
|
|
95
|
-
|
|
96
|
-
req.handlers.remove(Aws::S3::Plugins::S3Signer::LegacyHandler)
|
|
97
|
-
req.handlers.remove(Aws::S3::Plugins::S3Signer::V4Handler)
|
|
98
197
|
req.handlers.remove(Seahorse::Client::Plugins::ContentLength::Handler)
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
198
|
+
req.handlers.remove(Aws::Rest::ContentTypeHandler)
|
|
199
|
+
req.handlers.remove(Aws::Plugins::ChecksumAlgorithm::OptionHandler)
|
|
200
|
+
req.handlers.remove(Aws::Plugins::ChecksumAlgorithm::ChecksumHandler)
|
|
201
|
+
req.handlers.remove(Aws::Plugins::InvocationId::Handler)
|
|
202
|
+
req.handlers.remove(Aws::Plugins::Sign::Handler)
|
|
203
|
+
req.handlers.remove(Aws::S3::Plugins::S3Signer::LegacyHandler)
|
|
102
204
|
req.handle(step: :send) do |context|
|
|
103
|
-
|
|
104
|
-
if
|
|
105
|
-
endpoint =
|
|
106
|
-
endpoint.
|
|
107
|
-
endpoint.port = (scheme == 'http' ? 80 : 443)
|
|
108
|
-
http_req.endpoint = URI.parse(endpoint.to_s)
|
|
205
|
+
# if an endpoint was not provided, force secure or insecure
|
|
206
|
+
if context.config.regional_endpoint
|
|
207
|
+
http_req.endpoint.scheme = secure ? 'https' : 'http'
|
|
208
|
+
http_req.endpoint.port = secure ? 443 : 80
|
|
109
209
|
end
|
|
110
210
|
|
|
111
|
-
# hoist x-amz-* headers to the querystring
|
|
112
211
|
query = http_req.endpoint.query ? http_req.endpoint.query.split('&') : []
|
|
113
|
-
http_req.headers.
|
|
114
|
-
|
|
115
|
-
|
|
212
|
+
http_req.headers.each do |key, value|
|
|
213
|
+
next unless key =~ /^x-amz/i
|
|
214
|
+
|
|
215
|
+
if hoist
|
|
216
|
+
value = Aws::Sigv4::Signer.uri_escape(value)
|
|
116
217
|
key = Aws::Sigv4::Signer.uri_escape(key)
|
|
218
|
+
# hoist x-amz-* headers to the querystring
|
|
219
|
+
http_req.headers.delete(key)
|
|
117
220
|
query << "#{key}=#{value}"
|
|
221
|
+
else
|
|
222
|
+
x_amz_headers[key] = value
|
|
118
223
|
end
|
|
119
224
|
end
|
|
120
225
|
http_req.endpoint.query = query.join('&') unless query.empty?
|
|
121
226
|
|
|
227
|
+
auth_scheme = context[:auth_scheme]
|
|
228
|
+
scheme_name = auth_scheme['name']
|
|
229
|
+
region = if scheme_name == 'sigv4a'
|
|
230
|
+
auth_scheme['signingRegionSet'].first
|
|
231
|
+
else
|
|
232
|
+
auth_scheme['signingRegion']
|
|
233
|
+
end
|
|
234
|
+
signer = Aws::Sigv4::Signer.new(
|
|
235
|
+
service: auth_scheme['signingName'] || 's3',
|
|
236
|
+
region: context[:sigv4_region] || region || context.config.region,
|
|
237
|
+
credentials_provider: context[:sigv4_credentials] || context.config.credentials,
|
|
238
|
+
signing_algorithm: scheme_name.to_sym,
|
|
239
|
+
uri_escape_path: !!!auth_scheme['disableDoubleEncoding'],
|
|
240
|
+
normalize_path: !!!auth_scheme['disableNormalizePath'],
|
|
241
|
+
unsigned_headers: unsigned_headers,
|
|
242
|
+
apply_checksum_header: false
|
|
243
|
+
)
|
|
244
|
+
|
|
122
245
|
url = signer.presign_url(
|
|
123
246
|
http_method: http_req.http_method,
|
|
124
247
|
url: http_req.endpoint,
|
|
125
248
|
headers: http_req.headers,
|
|
126
249
|
body_digest: 'UNSIGNED-PAYLOAD',
|
|
127
|
-
expires_in: expires_in
|
|
250
|
+
expires_in: expires_in,
|
|
251
|
+
time: time
|
|
128
252
|
).to_s
|
|
129
253
|
|
|
130
254
|
Seahorse::Client::Response.new(context: context, data: url)
|
|
131
255
|
end
|
|
256
|
+
# Return the headers
|
|
257
|
+
x_amz_headers
|
|
132
258
|
end
|
|
133
|
-
|
|
134
|
-
def build_signer(cfg)
|
|
135
|
-
Aws::Sigv4::Signer.new(
|
|
136
|
-
service: 's3',
|
|
137
|
-
region: cfg.region,
|
|
138
|
-
credentials_provider: cfg.credentials,
|
|
139
|
-
unsigned_headers: [
|
|
140
|
-
'cache-control',
|
|
141
|
-
'content-length', # due to a ELB bug
|
|
142
|
-
'expect',
|
|
143
|
-
'max-forwards',
|
|
144
|
-
'pragma',
|
|
145
|
-
'te',
|
|
146
|
-
'if-match',
|
|
147
|
-
'if-none-match',
|
|
148
|
-
'if-modified-since',
|
|
149
|
-
'if-unmodified-since',
|
|
150
|
-
'if-range',
|
|
151
|
-
'accept',
|
|
152
|
-
'proxy-authorization',
|
|
153
|
-
'from',
|
|
154
|
-
'referer',
|
|
155
|
-
'user-agent',
|
|
156
|
-
'x-amzn-trace-id'
|
|
157
|
-
],
|
|
158
|
-
uri_escape_path: false
|
|
159
|
-
)
|
|
160
|
-
end
|
|
161
|
-
|
|
162
259
|
end
|
|
163
260
|
end
|
|
164
261
|
end
|
data/lib/aws-sdk-s3/resource.rb
CHANGED
|
@@ -1,11 +1,25 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
# WARNING ABOUT GENERATED CODE
|
|
2
4
|
#
|
|
3
5
|
# This file is generated. See the contributing guide for more information:
|
|
4
|
-
# https://github.com/aws/aws-sdk-ruby/blob/
|
|
6
|
+
# https://github.com/aws/aws-sdk-ruby/blob/version-3/CONTRIBUTING.md
|
|
5
7
|
#
|
|
6
8
|
# WARNING ABOUT GENERATED CODE
|
|
7
9
|
|
|
8
10
|
module Aws::S3
|
|
11
|
+
|
|
12
|
+
# This class provides a resource oriented interface for S3.
|
|
13
|
+
# To create a resource object:
|
|
14
|
+
#
|
|
15
|
+
# resource = Aws::S3::Resource.new(region: 'us-west-2')
|
|
16
|
+
#
|
|
17
|
+
# You can supply a client object with custom configuration that will be used for all resource operations.
|
|
18
|
+
# If you do not pass `:client`, a default client will be constructed.
|
|
19
|
+
#
|
|
20
|
+
# client = Aws::S3::Client.new(region: 'us-west-2')
|
|
21
|
+
# resource = Aws::S3::Resource.new(client: client)
|
|
22
|
+
#
|
|
9
23
|
class Resource
|
|
10
24
|
|
|
11
25
|
# @param options ({})
|
|
@@ -27,34 +41,141 @@ module Aws::S3
|
|
|
27
41
|
# acl: "private", # accepts private, public-read, public-read-write, authenticated-read
|
|
28
42
|
# bucket: "BucketName", # required
|
|
29
43
|
# create_bucket_configuration: {
|
|
30
|
-
# location_constraint: "
|
|
44
|
+
# location_constraint: "af-south-1", # accepts af-south-1, ap-east-1, ap-northeast-1, ap-northeast-2, ap-northeast-3, ap-south-1, ap-south-2, ap-southeast-1, ap-southeast-2, ap-southeast-3, ap-southeast-4, ap-southeast-5, ca-central-1, cn-north-1, cn-northwest-1, EU, eu-central-1, eu-central-2, eu-north-1, eu-south-1, eu-south-2, eu-west-1, eu-west-2, eu-west-3, il-central-1, me-central-1, me-south-1, sa-east-1, us-east-2, us-gov-east-1, us-gov-west-1, us-west-1, us-west-2
|
|
45
|
+
# location: {
|
|
46
|
+
# type: "AvailabilityZone", # accepts AvailabilityZone, LocalZone
|
|
47
|
+
# name: "LocationNameAsString",
|
|
48
|
+
# },
|
|
49
|
+
# bucket: {
|
|
50
|
+
# data_redundancy: "SingleAvailabilityZone", # accepts SingleAvailabilityZone, SingleLocalZone
|
|
51
|
+
# type: "Directory", # accepts Directory
|
|
52
|
+
# },
|
|
53
|
+
# tags: [
|
|
54
|
+
# {
|
|
55
|
+
# key: "ObjectKey", # required
|
|
56
|
+
# value: "Value", # required
|
|
57
|
+
# },
|
|
58
|
+
# ],
|
|
31
59
|
# },
|
|
32
60
|
# grant_full_control: "GrantFullControl",
|
|
33
61
|
# grant_read: "GrantRead",
|
|
34
62
|
# grant_read_acp: "GrantReadACP",
|
|
35
63
|
# grant_write: "GrantWrite",
|
|
36
64
|
# grant_write_acp: "GrantWriteACP",
|
|
65
|
+
# object_lock_enabled_for_bucket: false,
|
|
66
|
+
# object_ownership: "BucketOwnerPreferred", # accepts BucketOwnerPreferred, ObjectWriter, BucketOwnerEnforced
|
|
37
67
|
# })
|
|
38
68
|
# @param [Hash] options ({})
|
|
39
69
|
# @option options [String] :acl
|
|
40
70
|
# The canned ACL to apply to the bucket.
|
|
71
|
+
#
|
|
72
|
+
# <note markdown="1"> This functionality is not supported for directory buckets.
|
|
73
|
+
#
|
|
74
|
+
# </note>
|
|
41
75
|
# @option options [required, String] :bucket
|
|
76
|
+
# The name of the bucket to create.
|
|
77
|
+
#
|
|
78
|
+
# **General purpose buckets** - For information about bucket naming
|
|
79
|
+
# restrictions, see [Bucket naming rules][1] in the *Amazon S3 User
|
|
80
|
+
# Guide*.
|
|
81
|
+
#
|
|
82
|
+
# <b>Directory buckets </b> - When you use this operation with a
|
|
83
|
+
# directory bucket, you must use path-style requests in the format
|
|
84
|
+
# `https://s3express-control.region-code.amazonaws.com/bucket-name `.
|
|
85
|
+
# Virtual-hosted-style requests aren't supported. Directory bucket
|
|
86
|
+
# names must be unique in the chosen Zone (Availability Zone or Local
|
|
87
|
+
# Zone). Bucket names must also follow the format `
|
|
88
|
+
# bucket-base-name--zone-id--x-s3` (for example, `
|
|
89
|
+
# DOC-EXAMPLE-BUCKET--usw2-az1--x-s3`). For information about bucket
|
|
90
|
+
# naming restrictions, see [Directory bucket naming rules][2] in the
|
|
91
|
+
# *Amazon S3 User Guide*
|
|
92
|
+
#
|
|
93
|
+
#
|
|
94
|
+
#
|
|
95
|
+
# [1]: https://docs.aws.amazon.com/AmazonS3/latest/userguide/bucketnamingrules.html
|
|
96
|
+
# [2]: https://docs.aws.amazon.com/AmazonS3/latest/userguide/directory-bucket-naming-rules.html
|
|
42
97
|
# @option options [Types::CreateBucketConfiguration] :create_bucket_configuration
|
|
98
|
+
# The configuration information for the bucket.
|
|
43
99
|
# @option options [String] :grant_full_control
|
|
44
100
|
# Allows grantee the read, write, read ACP, and write ACP permissions on
|
|
45
101
|
# the bucket.
|
|
102
|
+
#
|
|
103
|
+
# <note markdown="1"> This functionality is not supported for directory buckets.
|
|
104
|
+
#
|
|
105
|
+
# </note>
|
|
46
106
|
# @option options [String] :grant_read
|
|
47
107
|
# Allows grantee to list the objects in the bucket.
|
|
108
|
+
#
|
|
109
|
+
# <note markdown="1"> This functionality is not supported for directory buckets.
|
|
110
|
+
#
|
|
111
|
+
# </note>
|
|
48
112
|
# @option options [String] :grant_read_acp
|
|
49
113
|
# Allows grantee to read the bucket ACL.
|
|
114
|
+
#
|
|
115
|
+
# <note markdown="1"> This functionality is not supported for directory buckets.
|
|
116
|
+
#
|
|
117
|
+
# </note>
|
|
50
118
|
# @option options [String] :grant_write
|
|
51
|
-
# Allows grantee to create
|
|
52
|
-
#
|
|
119
|
+
# Allows grantee to create new objects in the bucket.
|
|
120
|
+
#
|
|
121
|
+
# For the bucket and object owners of existing objects, also allows
|
|
122
|
+
# deletions and overwrites of those objects.
|
|
123
|
+
#
|
|
124
|
+
# <note markdown="1"> This functionality is not supported for directory buckets.
|
|
125
|
+
#
|
|
126
|
+
# </note>
|
|
53
127
|
# @option options [String] :grant_write_acp
|
|
54
128
|
# Allows grantee to write the ACL for the applicable bucket.
|
|
129
|
+
#
|
|
130
|
+
# <note markdown="1"> This functionality is not supported for directory buckets.
|
|
131
|
+
#
|
|
132
|
+
# </note>
|
|
133
|
+
# @option options [Boolean] :object_lock_enabled_for_bucket
|
|
134
|
+
# Specifies whether you want S3 Object Lock to be enabled for the new
|
|
135
|
+
# bucket.
|
|
136
|
+
#
|
|
137
|
+
# <note markdown="1"> This functionality is not supported for directory buckets.
|
|
138
|
+
#
|
|
139
|
+
# </note>
|
|
140
|
+
# @option options [String] :object_ownership
|
|
141
|
+
# The container element for object ownership for a bucket's ownership
|
|
142
|
+
# controls.
|
|
143
|
+
#
|
|
144
|
+
# `BucketOwnerPreferred` - Objects uploaded to the bucket change
|
|
145
|
+
# ownership to the bucket owner if the objects are uploaded with the
|
|
146
|
+
# `bucket-owner-full-control` canned ACL.
|
|
147
|
+
#
|
|
148
|
+
# `ObjectWriter` - The uploading account will own the object if the
|
|
149
|
+
# object is uploaded with the `bucket-owner-full-control` canned ACL.
|
|
150
|
+
#
|
|
151
|
+
# `BucketOwnerEnforced` - Access control lists (ACLs) are disabled and
|
|
152
|
+
# no longer affect permissions. The bucket owner automatically owns and
|
|
153
|
+
# has full control over every object in the bucket. The bucket only
|
|
154
|
+
# accepts PUT requests that don't specify an ACL or specify bucket
|
|
155
|
+
# owner full control ACLs (such as the predefined
|
|
156
|
+
# `bucket-owner-full-control` canned ACL or a custom ACL in XML format
|
|
157
|
+
# that grants the same permissions).
|
|
158
|
+
#
|
|
159
|
+
# By default, `ObjectOwnership` is set to `BucketOwnerEnforced` and ACLs
|
|
160
|
+
# are disabled. We recommend keeping ACLs disabled, except in uncommon
|
|
161
|
+
# use cases where you must control access for each object individually.
|
|
162
|
+
# For more information about S3 Object Ownership, see [Controlling
|
|
163
|
+
# ownership of objects and disabling ACLs for your bucket][1] in the
|
|
164
|
+
# *Amazon S3 User Guide*.
|
|
165
|
+
#
|
|
166
|
+
# <note markdown="1"> This functionality is not supported for directory buckets. Directory
|
|
167
|
+
# buckets use the bucket owner enforced setting for S3 Object Ownership.
|
|
168
|
+
#
|
|
169
|
+
# </note>
|
|
170
|
+
#
|
|
171
|
+
#
|
|
172
|
+
#
|
|
173
|
+
# [1]: https://docs.aws.amazon.com/AmazonS3/latest/userguide/about-object-ownership.html
|
|
55
174
|
# @return [Bucket]
|
|
56
175
|
def create_bucket(options = {})
|
|
57
|
-
|
|
176
|
+
Aws::Plugins::UserAgent.metric('RESOURCE_MODEL') do
|
|
177
|
+
@client.create_bucket(options)
|
|
178
|
+
end
|
|
58
179
|
Bucket.new(
|
|
59
180
|
name: options[:bucket],
|
|
60
181
|
client: @client
|
|
@@ -74,21 +195,49 @@ module Aws::S3
|
|
|
74
195
|
|
|
75
196
|
# @example Request syntax with placeholder values
|
|
76
197
|
#
|
|
77
|
-
# s3.buckets(
|
|
198
|
+
# buckets = s3.buckets({
|
|
199
|
+
# prefix: "Prefix",
|
|
200
|
+
# bucket_region: "BucketRegion",
|
|
201
|
+
# })
|
|
78
202
|
# @param [Hash] options ({})
|
|
203
|
+
# @option options [String] :prefix
|
|
204
|
+
# Limits the response to bucket names that begin with the specified
|
|
205
|
+
# bucket name prefix.
|
|
206
|
+
# @option options [String] :bucket_region
|
|
207
|
+
# Limits the response to buckets that are located in the specified
|
|
208
|
+
# Amazon Web Services Region. The Amazon Web Services Region must be
|
|
209
|
+
# expressed according to the Amazon Web Services Region code, such as
|
|
210
|
+
# `us-west-2` for the US West (Oregon) Region. For a list of the valid
|
|
211
|
+
# values for all of the Amazon Web Services Regions, see [Regions and
|
|
212
|
+
# Endpoints][1].
|
|
213
|
+
#
|
|
214
|
+
# <note markdown="1"> Requests made to a Regional endpoint that is different from the
|
|
215
|
+
# `bucket-region` parameter are not supported. For example, if you want
|
|
216
|
+
# to limit the response to your buckets in Region `us-west-2`, the
|
|
217
|
+
# request must be made to an endpoint in Region `us-west-2`.
|
|
218
|
+
#
|
|
219
|
+
# </note>
|
|
220
|
+
#
|
|
221
|
+
#
|
|
222
|
+
#
|
|
223
|
+
# [1]: https://docs.aws.amazon.com/general/latest/gr/rande.html#s3_region
|
|
79
224
|
# @return [Bucket::Collection]
|
|
80
225
|
def buckets(options = {})
|
|
81
226
|
batches = Enumerator.new do |y|
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
227
|
+
resp = Aws::Plugins::UserAgent.metric('RESOURCE_MODEL') do
|
|
228
|
+
@client.list_buckets(options)
|
|
229
|
+
end
|
|
230
|
+
resp.each_page do |page|
|
|
231
|
+
batch = []
|
|
232
|
+
page.data.buckets.each do |b|
|
|
233
|
+
batch << Bucket.new(
|
|
234
|
+
name: b.name,
|
|
235
|
+
data: b,
|
|
236
|
+
client: @client
|
|
237
|
+
)
|
|
238
|
+
end
|
|
239
|
+
y.yield(batch)
|
|
90
240
|
end
|
|
91
|
-
y.yield(batch)
|
|
92
241
|
end
|
|
93
242
|
Bucket::Collection.new(batches)
|
|
94
243
|
end
|