aws-sdk-s3 1.53.0 → 1.146.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 +1126 -0
- data/LICENSE.txt +202 -0
- data/VERSION +1 -0
- data/lib/aws-sdk-s3/bucket.rb +778 -94
- 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 +12559 -877
- data/lib/aws-sdk-s3/client_api.rb +1078 -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 +231 -39
- 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 +25 -8
- 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 +2 -0
- data/lib/aws-sdk-s3/file_uploader.rb +28 -8
- data/lib/aws-sdk-s3/legacy_signer.rb +17 -25
- data/lib/aws-sdk-s3/multipart_file_uploader.rb +68 -12
- data/lib/aws-sdk-s3/multipart_stream_uploader.rb +59 -20
- 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 +32 -26
- 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 +136 -59
- data/lib/aws-sdk-s3/resource.rb +120 -8
- data/lib/aws-sdk-s3/types.rb +11349 -4242
- 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
@@ -1,9 +1,10 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'uri'
|
2
4
|
|
3
5
|
module Aws
|
4
6
|
module S3
|
5
7
|
class Bucket
|
6
|
-
|
7
8
|
# Deletes all objects and versioned objects from this bucket
|
8
9
|
#
|
9
10
|
# @example
|
@@ -31,10 +32,10 @@ module Aws
|
|
31
32
|
# each attempt.
|
32
33
|
#
|
33
34
|
# @return [void]
|
34
|
-
def delete!
|
35
|
+
def delete!(options = {})
|
35
36
|
options = {
|
36
37
|
initial_wait: 1.3,
|
37
|
-
max_attempts: 3
|
38
|
+
max_attempts: 3
|
38
39
|
}.merge(options)
|
39
40
|
|
40
41
|
attempts = 0
|
@@ -43,38 +44,72 @@ module Aws
|
|
43
44
|
delete
|
44
45
|
rescue Errors::BucketNotEmpty
|
45
46
|
attempts += 1
|
46
|
-
if attempts >= options[:max_attempts]
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
retry
|
51
|
-
end
|
47
|
+
raise if attempts >= options[:max_attempts]
|
48
|
+
|
49
|
+
Kernel.sleep(options[:initial_wait]**attempts)
|
50
|
+
retry
|
52
51
|
end
|
53
52
|
end
|
54
53
|
|
55
54
|
# Returns a public URL for this bucket.
|
56
55
|
#
|
57
|
-
#
|
58
|
-
#
|
59
|
-
#
|
56
|
+
# @example
|
57
|
+
#
|
58
|
+
# bucket = s3.bucket('bucket-name')
|
59
|
+
# bucket.url
|
60
|
+
# #=> "https://bucket-name.s3.amazonaws.com"
|
61
|
+
#
|
62
|
+
# It will also work when provided an Access Point ARN.
|
63
|
+
#
|
64
|
+
# @example
|
65
|
+
#
|
66
|
+
# bucket = s3.bucket(
|
67
|
+
# 'arn:aws:s3:us-east-1:123456789012:accesspoint:myendpoint'
|
68
|
+
# )
|
69
|
+
# bucket.url
|
70
|
+
# #=> "https://myendpoint-123456789012.s3-accesspoint.us-west-2.amazonaws.com"
|
60
71
|
#
|
61
72
|
# You can pass `virtual_host: true` to use the bucket name as the
|
62
73
|
# host name.
|
63
74
|
#
|
64
|
-
# bucket = s3.bucket('my
|
75
|
+
# bucket = s3.bucket('my-bucket.com')
|
65
76
|
# bucket.url(virtual_host: true)
|
66
|
-
# #=> "http://my
|
77
|
+
# #=> "http://my-bucket.com"
|
67
78
|
#
|
68
79
|
# @option options [Boolean] :virtual_host (false) When `true`,
|
69
80
|
# the bucket name will be used as the host name. This is useful
|
70
81
|
# when you have a CNAME configured for this bucket.
|
71
82
|
#
|
83
|
+
# @option options [Boolean] :secure (true) When `false`, http
|
84
|
+
# will be used with virtual_host. This is required when
|
85
|
+
# the bucket name has a dot (.) in it.
|
86
|
+
#
|
72
87
|
# @return [String] the URL for this bucket.
|
73
88
|
def url(options = {})
|
74
89
|
if options[:virtual_host]
|
75
|
-
|
90
|
+
scheme = options.fetch(:secure, true) ? 'https' : 'http'
|
91
|
+
"#{scheme}://#{name}"
|
76
92
|
else
|
77
|
-
|
93
|
+
# Taken from Aws::S3::Endpoints module
|
94
|
+
unless client.config.regional_endpoint
|
95
|
+
endpoint = client.config.endpoint.to_s
|
96
|
+
end
|
97
|
+
params = Aws::S3::EndpointParameters.new(
|
98
|
+
bucket: name,
|
99
|
+
region: client.config.region,
|
100
|
+
use_fips: client.config.use_fips_endpoint,
|
101
|
+
use_dual_stack: client.config.use_dualstack_endpoint,
|
102
|
+
endpoint: endpoint,
|
103
|
+
force_path_style: client.config.force_path_style,
|
104
|
+
accelerate: client.config.use_accelerate_endpoint,
|
105
|
+
use_global_endpoint: client.config.s3_us_east_1_regional_endpoint == 'legacy',
|
106
|
+
use_object_lambda_endpoint: nil,
|
107
|
+
disable_access_points: nil,
|
108
|
+
disable_multi_region_access_points: client.config.s3_disable_multiregion_access_points,
|
109
|
+
use_arn_region: client.config.s3_use_arn_region,
|
110
|
+
)
|
111
|
+
endpoint = Aws::S3::EndpointProvider.new.resolve_endpoint(params)
|
112
|
+
endpoint.url
|
78
113
|
end
|
79
114
|
end
|
80
115
|
|
@@ -93,35 +128,19 @@ module Aws
|
|
93
128
|
client.config.credentials,
|
94
129
|
client.config.region,
|
95
130
|
name,
|
96
|
-
{url: url}.merge(options)
|
131
|
+
{ url: url }.merge(options)
|
97
132
|
)
|
98
133
|
end
|
99
134
|
|
100
135
|
# @api private
|
101
136
|
def load
|
102
|
-
@data =
|
103
|
-
|
104
|
-
self
|
105
|
-
end
|
106
|
-
|
107
|
-
private
|
108
|
-
|
109
|
-
def s3_bucket_url
|
110
|
-
url = client.config.endpoint.dup
|
111
|
-
if bucket_as_hostname?(url.scheme == 'https')
|
112
|
-
url.host = "#{name}.#{url.host}"
|
113
|
-
else
|
114
|
-
url.path += '/' unless url.path[-1] == '/'
|
115
|
-
url.path += Seahorse::Util.uri_escape(name)
|
137
|
+
@data = Aws::Plugins::UserAgent.feature('resource') do
|
138
|
+
client.list_buckets.buckets.find { |b| b.name == name }
|
116
139
|
end
|
117
|
-
|
118
|
-
end
|
140
|
+
raise "unable to load bucket #{name}" if @data.nil?
|
119
141
|
|
120
|
-
|
121
|
-
Plugins::BucketDns.dns_compatible?(name, https) &&
|
122
|
-
!client.config.force_path_style
|
142
|
+
self
|
123
143
|
end
|
124
|
-
|
125
144
|
end
|
126
145
|
end
|
127
146
|
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Aws
|
4
|
+
module S3
|
5
|
+
module Errors
|
6
|
+
# Hijack PermanentRedirect dynamic error to also include endpoint
|
7
|
+
# and bucket.
|
8
|
+
class PermanentRedirect < ServiceError
|
9
|
+
# @param [Seahorse::Client::RequestContext] context
|
10
|
+
# @param [String] message
|
11
|
+
# @param [Aws::S3::Types::PermanentRedirect] _data
|
12
|
+
def initialize(context, message, _data = Aws::EmptyStructure.new)
|
13
|
+
data = Aws::S3::Types::PermanentRedirect.new(message: message)
|
14
|
+
body = context.http_response.body_contents
|
15
|
+
if (endpoint = body.match(/<Endpoint>(.+?)<\/Endpoint>/))
|
16
|
+
data.endpoint = endpoint[1]
|
17
|
+
end
|
18
|
+
if (bucket = body.match(/<Bucket>(.+?)<\/Bucket>/))
|
19
|
+
data.bucket = bucket[1]
|
20
|
+
end
|
21
|
+
data.region = context.http_response.headers['x-amz-bucket-region']
|
22
|
+
super(context, message, data)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -1,8 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Aws
|
2
4
|
module S3
|
3
5
|
class Object
|
4
6
|
alias size content_length
|
5
7
|
|
8
|
+
# Make the method redefinable
|
9
|
+
alias_method :copy_from, :copy_from
|
10
|
+
|
6
11
|
# Copies another object to this object. Use `multipart_copy: true`
|
7
12
|
# for large objects. This is required for objects that exceed 5GB.
|
8
13
|
#
|
@@ -22,10 +27,14 @@ module Aws
|
|
22
27
|
# necessary for objects larger than 5GB and can provide
|
23
28
|
# performance improvements on large objects. Amazon S3 does
|
24
29
|
# not accept multipart copies for objects smaller than 5MB.
|
30
|
+
# Object metadata such as Content-Type will be copied, however,
|
31
|
+
# Checksums are not copied.
|
25
32
|
#
|
26
33
|
# @option options [Integer] :content_length Only used when
|
27
34
|
# `:multipart_copy` is `true`. Passing this options avoids a HEAD
|
28
|
-
# request to query the source object size
|
35
|
+
# request to query the source object size but prevents object metadata
|
36
|
+
# from being copied. Raises an `ArgumentError` if
|
37
|
+
# this option is provided when `:multipart_copy` is `false` or not set.
|
29
38
|
#
|
30
39
|
# @option options [S3::Client] :copy_source_client Only used when
|
31
40
|
# `:multipart_copy` is `true` and the source object is in a
|
@@ -37,6 +46,14 @@ module Aws
|
|
37
46
|
# different region. You do not need to specify this option
|
38
47
|
# if you have provided a `:source_client` or a `:content_length`.
|
39
48
|
#
|
49
|
+
# @option options [Boolean] :use_source_parts (false) Only used when
|
50
|
+
# `:multipart_copy` is `true`. Use part sizes defined on the source
|
51
|
+
# object if any exist. If copying or moving an object that
|
52
|
+
# is already multipart, this does not re-part the object, instead
|
53
|
+
# re-using the part definitions on the original. That means the etag
|
54
|
+
# and any checksums will not change. This is especially useful if the
|
55
|
+
# source object has parts with varied sizes.
|
56
|
+
#
|
40
57
|
# @example Basic object copy
|
41
58
|
#
|
42
59
|
# bucket = Aws::S3::Bucket.new('target-bucket')
|
@@ -59,11 +76,13 @@ module Aws
|
|
59
76
|
# @see #copy_to
|
60
77
|
#
|
61
78
|
def copy_from(source, options = {})
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
79
|
+
Aws::Plugins::UserAgent.feature('resource') do
|
80
|
+
if Hash === source && source[:copy_source]
|
81
|
+
# for backwards compatibility
|
82
|
+
@client.copy_object(source.merge(bucket: bucket_name, key: key))
|
83
|
+
else
|
84
|
+
ObjectCopier.new(self, options).copy_from(source, options)
|
85
|
+
end
|
67
86
|
end
|
68
87
|
end
|
69
88
|
|
@@ -100,7 +119,9 @@ module Aws
|
|
100
119
|
# object.copy_to('src-bucket/src-key', multipart_copy: true)
|
101
120
|
#
|
102
121
|
def copy_to(target, options = {})
|
103
|
-
|
122
|
+
Aws::Plugins::UserAgent.feature('resource') do
|
123
|
+
ObjectCopier.new(self, options).copy_to(target, options)
|
124
|
+
end
|
104
125
|
end
|
105
126
|
|
106
127
|
# Copies and deletes the current object. The object will only be deleted
|
@@ -147,21 +168,35 @@ module Aws
|
|
147
168
|
# obj.presigned_url(:put, acl: 'public-read')
|
148
169
|
# #=> "https://bucket-name.s3.amazonaws.com/object-key?..."
|
149
170
|
#
|
150
|
-
# @
|
151
|
-
#
|
152
|
-
#
|
171
|
+
# @example Pre-signed UploadPart PUT
|
172
|
+
#
|
173
|
+
# # the object uploaded using this URL will be publicly accessible
|
174
|
+
# obj.presigned_url(:upload_part, part_number: 1, upload_id: 'uploadIdToken')
|
175
|
+
# #=> "https://bucket-name.s3.amazonaws.com/object-key?..."
|
176
|
+
#
|
177
|
+
# @param [Symbol] method
|
178
|
+
# The S3 operation to generate a presigned URL for. Valid values
|
179
|
+
# are `:get`, `:put`, `:head`, `:delete`, `:create_multipart_upload`,
|
180
|
+
# `:list_multipart_uploads`, `:complete_multipart_upload`,
|
181
|
+
# `:abort_multipart_upload`, `:list_parts`, and `:upload_part`.
|
153
182
|
#
|
154
183
|
# @param [Hash] params
|
155
184
|
# Additional request parameters to use when generating the pre-signed
|
156
185
|
# URL. See the related documentation in {Client} for accepted
|
157
186
|
# params.
|
158
187
|
#
|
159
|
-
# |
|
160
|
-
#
|
161
|
-
# | `:get`
|
162
|
-
# | `:put`
|
163
|
-
# | `:head`
|
164
|
-
# | `:delete`
|
188
|
+
# | Method | Client Method |
|
189
|
+
# |------------------------------|------------------------------------|
|
190
|
+
# | `:get` | {Client#get_object} |
|
191
|
+
# | `:put` | {Client#put_object} |
|
192
|
+
# | `:head` | {Client#head_object} |
|
193
|
+
# | `:delete` | {Client#delete_object} |
|
194
|
+
# | `:create_multipart_upload` | {Client#create_multipart_upload} |
|
195
|
+
# | `:list_multipart_uploads` | {Client#list_multipart_uploads} |
|
196
|
+
# | `:complete_multipart_upload` | {Client#complete_multipart_upload} |
|
197
|
+
# | `:abort_multipart_upload` | {Client#abort_multipart_upload} |
|
198
|
+
# | `:list_parts` | {Client#list_parts} |
|
199
|
+
# | `:upload_part` | {Client#upload_part} |
|
165
200
|
#
|
166
201
|
# @option params [Boolean] :virtual_host (false) When `true` the
|
167
202
|
# presigned URL will use the bucket name as a virtual host.
|
@@ -182,10 +217,88 @@ module Aws
|
|
182
217
|
#
|
183
218
|
# @return [String]
|
184
219
|
#
|
185
|
-
def presigned_url(
|
220
|
+
def presigned_url(method, params = {})
|
186
221
|
presigner = Presigner.new(client: client)
|
222
|
+
|
223
|
+
if %w(delete head get put).include?(method.to_s)
|
224
|
+
method = "#{method}_object".to_sym
|
225
|
+
end
|
226
|
+
|
187
227
|
presigner.presigned_url(
|
188
|
-
|
228
|
+
method.downcase,
|
229
|
+
params.merge(bucket: bucket_name, key: key)
|
230
|
+
)
|
231
|
+
end
|
232
|
+
|
233
|
+
# Allows you to create presigned URL requests for S3 operations. This
|
234
|
+
# method returns a tuple containing the URL and the signed X-amz-* headers
|
235
|
+
# to be used with the presigned url.
|
236
|
+
#
|
237
|
+
# @example Pre-signed GET URL, valid for one hour
|
238
|
+
#
|
239
|
+
# obj.presigned_request(:get, expires_in: 3600)
|
240
|
+
# #=> ["https://bucket-name.s3.amazonaws.com/object-key?...", {}]
|
241
|
+
#
|
242
|
+
# @example Pre-signed PUT with a canned ACL
|
243
|
+
#
|
244
|
+
# # the object uploaded using this URL will be publicly accessible
|
245
|
+
# obj.presigned_request(:put, acl: 'public-read')
|
246
|
+
# #=> ["https://bucket-name.s3.amazonaws.com/object-key?...",
|
247
|
+
# {"x-amz-acl"=>"public-read"}]
|
248
|
+
#
|
249
|
+
# @param [Symbol] method
|
250
|
+
# The S3 operation to generate a presigned request for. Valid values
|
251
|
+
# are `:get`, `:put`, `:head`, `:delete`, `:create_multipart_upload`,
|
252
|
+
# `:list_multipart_uploads`, `:complete_multipart_upload`,
|
253
|
+
# `:abort_multipart_upload`, `:list_parts`, and `:upload_part`.
|
254
|
+
#
|
255
|
+
# @param [Hash] params
|
256
|
+
# Additional request parameters to use when generating the pre-signed
|
257
|
+
# request. See the related documentation in {Client} for accepted
|
258
|
+
# params.
|
259
|
+
#
|
260
|
+
# | Method | Client Method |
|
261
|
+
# |------------------------------|------------------------------------|
|
262
|
+
# | `:get` | {Client#get_object} |
|
263
|
+
# | `:put` | {Client#put_object} |
|
264
|
+
# | `:head` | {Client#head_object} |
|
265
|
+
# | `:delete` | {Client#delete_object} |
|
266
|
+
# | `:create_multipart_upload` | {Client#create_multipart_upload} |
|
267
|
+
# | `:list_multipart_uploads` | {Client#list_multipart_uploads} |
|
268
|
+
# | `:complete_multipart_upload` | {Client#complete_multipart_upload} |
|
269
|
+
# | `:abort_multipart_upload` | {Client#abort_multipart_upload} |
|
270
|
+
# | `:list_parts` | {Client#list_parts} |
|
271
|
+
# | `:upload_part` | {Client#upload_part} |
|
272
|
+
#
|
273
|
+
# @option params [Boolean] :virtual_host (false) When `true` the
|
274
|
+
# presigned URL will use the bucket name as a virtual host.
|
275
|
+
#
|
276
|
+
# bucket = Aws::S3::Bucket.new('my.bucket.com')
|
277
|
+
# bucket.object('key').presigned_request(virtual_host: true)
|
278
|
+
# #=> ["http://my.bucket.com/key?...", {}]
|
279
|
+
#
|
280
|
+
# @option params [Integer] :expires_in (900) Number of seconds before
|
281
|
+
# the pre-signed URL expires. This may not exceed one week (604800
|
282
|
+
# seconds). Note that the pre-signed URL is also only valid as long as
|
283
|
+
# credentials used to sign it are. For example, when using IAM roles,
|
284
|
+
# temporary tokens generated for signing also have a default expiration
|
285
|
+
# which will affect the effective expiration of the pre-signed URL.
|
286
|
+
#
|
287
|
+
# @raise [ArgumentError] Raised if `:expires_in` exceeds one week
|
288
|
+
# (604800 seconds).
|
289
|
+
#
|
290
|
+
# @return [String, Hash] A tuple with a presigned URL and headers that
|
291
|
+
# should be included with the request.
|
292
|
+
#
|
293
|
+
def presigned_request(method, params = {})
|
294
|
+
presigner = Presigner.new(client: client)
|
295
|
+
|
296
|
+
if %w(delete head get put).include?(method.to_s)
|
297
|
+
method = "#{method}_object".to_sym
|
298
|
+
end
|
299
|
+
|
300
|
+
presigner.presigned_request(
|
301
|
+
method.downcase,
|
189
302
|
params.merge(bucket: bucket_name, key: key)
|
190
303
|
)
|
191
304
|
end
|
@@ -195,16 +308,22 @@ module Aws
|
|
195
308
|
# s3.bucket('bucket-name').object('obj-key').public_url
|
196
309
|
# #=> "https://bucket-name.s3.amazonaws.com/obj-key"
|
197
310
|
#
|
198
|
-
# To use virtual hosted bucket url
|
311
|
+
# To use virtual hosted bucket url.
|
312
|
+
# Uses https unless secure: false is set. If the bucket
|
313
|
+
# name contains dots (.) then you will need to set secure: false.
|
199
314
|
#
|
200
|
-
# s3.bucket('my
|
315
|
+
# s3.bucket('my-bucket.com').object('key')
|
201
316
|
# .public_url(virtual_host: true)
|
202
|
-
# #=> "
|
317
|
+
# #=> "https://my-bucket.com/key"
|
203
318
|
#
|
204
319
|
# @option options [Boolean] :virtual_host (false) When `true`, the bucket
|
205
320
|
# name will be used as the host name. This is useful when you have
|
206
321
|
# a CNAME configured for the bucket.
|
207
322
|
#
|
323
|
+
# @option options [Boolean] :secure (true) When `false`, http
|
324
|
+
# will be used with virtual_host. This is required when
|
325
|
+
# the bucket name has a dot (.) in it.
|
326
|
+
#
|
208
327
|
# @return [String]
|
209
328
|
def public_url(options = {})
|
210
329
|
url = URI.parse(bucket.url(options))
|
@@ -234,6 +353,10 @@ module Aws
|
|
234
353
|
# obj.upload_stream do |write_stream|
|
235
354
|
# IO.copy_stream(STDIN, write_stream)
|
236
355
|
# end
|
356
|
+
# @param [Hash] options
|
357
|
+
# Additional options for {Client#create_multipart_upload},
|
358
|
+
# {Client#complete_multipart_upload},
|
359
|
+
# and {Client#upload_part} can be provided.
|
237
360
|
#
|
238
361
|
# @option options [Integer] :thread_count (10) The number of parallel
|
239
362
|
# multipart uploads
|
@@ -256,6 +379,9 @@ module Aws
|
|
256
379
|
# @return [Boolean] Returns `true` when the object is uploaded
|
257
380
|
# without any errors.
|
258
381
|
#
|
382
|
+
# @see Client#create_multipart_upload
|
383
|
+
# @see Client#complete_multipart_upload
|
384
|
+
# @see Client#upload_part
|
259
385
|
def upload_stream(options = {}, &block)
|
260
386
|
uploading_options = options.dup
|
261
387
|
uploader = MultipartStreamUploader.new(
|
@@ -264,10 +390,12 @@ module Aws
|
|
264
390
|
tempfile: uploading_options.delete(:tempfile),
|
265
391
|
part_size: uploading_options.delete(:part_size)
|
266
392
|
)
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
393
|
+
Aws::Plugins::UserAgent.feature('resource') do
|
394
|
+
uploader.upload(
|
395
|
+
uploading_options.merge(bucket: bucket_name, key: key),
|
396
|
+
&block
|
397
|
+
)
|
398
|
+
end
|
271
399
|
true
|
272
400
|
end
|
273
401
|
|
@@ -276,8 +404,8 @@ module Aws
|
|
276
404
|
# # small files are uploaded in a single API call
|
277
405
|
# obj.upload_file('/path/to/file')
|
278
406
|
#
|
279
|
-
# Files larger than `:multipart_threshold` are uploaded
|
280
|
-
# Amazon S3 multipart upload APIs.
|
407
|
+
# Files larger than or equal to `:multipart_threshold` are uploaded
|
408
|
+
# using the Amazon S3 multipart upload APIs.
|
281
409
|
#
|
282
410
|
# # large files are automatically split into parts
|
283
411
|
# # and the parts are uploaded in parallel
|
@@ -290,6 +418,14 @@ module Aws
|
|
290
418
|
# etag = response.etag
|
291
419
|
# end
|
292
420
|
#
|
421
|
+
# You can provide a callback to monitor progress of the upload:
|
422
|
+
#
|
423
|
+
# # bytes and totals are each an array with 1 entry per part
|
424
|
+
# progress = Proc.new do |bytes, totals|
|
425
|
+
# puts bytes.map.with_index { |b, i| "Part #{i+1}: #{b} / #{totals[i]}"}.join(' ') + "Total: #{100.0 * bytes.sum / totals.sum }%" }
|
426
|
+
# end
|
427
|
+
# obj.upload_file('/path/to/file', progress_callback: progress)
|
428
|
+
#
|
293
429
|
# @param [String, Pathname, File, Tempfile] source A file on the local
|
294
430
|
# file system that will be uploaded as this object. This can either be
|
295
431
|
# a String or Pathname to the file, an open File object, or an open
|
@@ -298,14 +434,26 @@ module Aws
|
|
298
434
|
# using an open Tempfile, rewind it before uploading or else the object
|
299
435
|
# will be empty.
|
300
436
|
#
|
301
|
-
# @
|
302
|
-
#
|
303
|
-
#
|
437
|
+
# @param [Hash] options
|
438
|
+
# Additional options for {Client#put_object}
|
439
|
+
# when file sizes below the multipart threshold. For files larger than
|
440
|
+
# the multipart threshold, options for {Client#create_multipart_upload},
|
441
|
+
# {Client#complete_multipart_upload},
|
442
|
+
# and {Client#upload_part} can be provided.
|
443
|
+
#
|
444
|
+
# @option options [Integer] :multipart_threshold (104857600) Files larger
|
445
|
+
# than or equal to `:multipart_threshold` are uploaded using the S3
|
446
|
+
# multipart APIs.
|
447
|
+
# Default threshold is 100MB.
|
304
448
|
#
|
305
449
|
# @option options [Integer] :thread_count (10) The number of parallel
|
306
450
|
# multipart uploads. This option is not used if the file is smaller than
|
307
451
|
# `:multipart_threshold`.
|
308
452
|
#
|
453
|
+
# @option options [Proc] :progress_callback
|
454
|
+
# A Proc that will be called when each chunk of the upload is sent.
|
455
|
+
# It will be invoked with [bytes_read], [total_sizes]
|
456
|
+
#
|
309
457
|
# @raise [MultipartUploadError] If an object is being uploaded in
|
310
458
|
# parts, and the upload can not be completed, then the upload is
|
311
459
|
# aborted and this error is raised. The raised error has a `#errors`
|
@@ -315,16 +463,22 @@ module Aws
|
|
315
463
|
# @return [Boolean] Returns `true` when the object is uploaded
|
316
464
|
# without any errors.
|
317
465
|
#
|
466
|
+
# @see Client#put_object
|
467
|
+
# @see Client#create_multipart_upload
|
468
|
+
# @see Client#complete_multipart_upload
|
469
|
+
# @see Client#upload_part
|
318
470
|
def upload_file(source, options = {})
|
319
471
|
uploading_options = options.dup
|
320
472
|
uploader = FileUploader.new(
|
321
473
|
multipart_threshold: uploading_options.delete(:multipart_threshold),
|
322
474
|
client: client
|
323
475
|
)
|
324
|
-
response =
|
325
|
-
|
326
|
-
|
327
|
-
|
476
|
+
response = Aws::Plugins::UserAgent.feature('resource') do
|
477
|
+
uploader.upload(
|
478
|
+
source,
|
479
|
+
uploading_options.merge(bucket: bucket_name, key: key)
|
480
|
+
)
|
481
|
+
end
|
328
482
|
yield response if block_given?
|
329
483
|
true
|
330
484
|
end
|
@@ -340,15 +494,28 @@ module Aws
|
|
340
494
|
# # and the parts are downloaded in parallel
|
341
495
|
# obj.download_file('/path/to/very_large_file')
|
342
496
|
#
|
497
|
+
# You can provide a callback to monitor progress of the download:
|
498
|
+
#
|
499
|
+
# # bytes and part_sizes are each an array with 1 entry per part
|
500
|
+
# # part_sizes may not be known until the first bytes are retrieved
|
501
|
+
# progress = Proc.new do |bytes, part_sizes, file_size|
|
502
|
+
# puts bytes.map.with_index { |b, i| "Part #{i+1}: #{b} / #{part_sizes[i]}"}.join(' ') + "Total: #{100.0 * bytes.sum / file_size}%" }
|
503
|
+
# end
|
504
|
+
# obj.download_file('/path/to/file', progress_callback: progress)
|
505
|
+
#
|
343
506
|
# @param [String] destination Where to download the file to.
|
344
507
|
#
|
508
|
+
# @param [Hash] options
|
509
|
+
# Additional options for {Client#get_object} and #{Client#head_object}
|
510
|
+
# may be provided.
|
511
|
+
#
|
345
512
|
# @option options [String] mode `auto`, `single_request`, `get_range`
|
346
513
|
# `single_request` mode forces only 1 GET request is made in download,
|
347
514
|
# `get_range` mode allows `chunk_size` parameter to configured in
|
348
515
|
# customizing each range size in multipart_download,
|
349
516
|
# By default, `auto` mode is enabled, which performs multipart_download
|
350
517
|
#
|
351
|
-
# @option options [
|
518
|
+
# @option options [Integer] chunk_size required in get_range mode.
|
352
519
|
#
|
353
520
|
# @option options [Integer] thread_count (10) Customize threads used in
|
354
521
|
# the multipart download.
|
@@ -357,14 +524,39 @@ module Aws
|
|
357
524
|
# retrieve the object. For more about object versioning, see:
|
358
525
|
# https://docs.aws.amazon.com/AmazonS3/latest/dev/ObjectVersioning.html
|
359
526
|
#
|
527
|
+
# @option options [String] checksum_mode (ENABLED) When `ENABLED` and
|
528
|
+
# the object has a stored checksum, it will be used to validate the
|
529
|
+
# download and will raise an `Aws::Errors::ChecksumError` if
|
530
|
+
# checksum validation fails. You may provide a `on_checksum_validated`
|
531
|
+
# callback if you need to verify that validation occurred and which
|
532
|
+
# algorithm was used. To disable checksum validation, set
|
533
|
+
# `checksum_mode` to "DISABLED".
|
534
|
+
#
|
535
|
+
# @option options [Callable] on_checksum_validated Called each time a
|
536
|
+
# request's checksum is validated with the checksum algorithm and the
|
537
|
+
# response. For multipart downloads, this will be called for each
|
538
|
+
# part that is downloaded and validated.
|
539
|
+
#
|
540
|
+
# @option options [Proc] :progress_callback
|
541
|
+
# A Proc that will be called when each chunk of the download is received.
|
542
|
+
# It will be invoked with [bytes_read], [part_sizes], file_size.
|
543
|
+
# When the object is downloaded as parts (rather than by ranges), the
|
544
|
+
# part_sizes will not be known ahead of time and will be nil in the
|
545
|
+
# callback until the first bytes in the part are received.
|
546
|
+
#
|
360
547
|
# @return [Boolean] Returns `true` when the file is downloaded without
|
361
548
|
# any errors.
|
549
|
+
#
|
550
|
+
# @see Client#get_object
|
551
|
+
# @see Client#head_object
|
362
552
|
def download_file(destination, options = {})
|
363
553
|
downloader = FileDownloader.new(client: client)
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
554
|
+
Aws::Plugins::UserAgent.feature('resource') do
|
555
|
+
downloader.download(
|
556
|
+
destination,
|
557
|
+
options.merge(bucket: bucket_name, key: key)
|
558
|
+
)
|
559
|
+
end
|
368
560
|
true
|
369
561
|
end
|
370
562
|
end
|
@@ -1,9 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Aws
|
2
4
|
module S3
|
3
5
|
class ObjectSummary
|
4
6
|
|
5
7
|
alias content_length size
|
6
8
|
|
9
|
+
# Make the method redefinable
|
10
|
+
alias_method :copy_from, :copy_from
|
11
|
+
|
7
12
|
# @param (see Object#copy_from)
|
8
13
|
# @options (see Object#copy_from)
|
9
14
|
# @return (see Object#copy_from)
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Aws
|
4
|
+
module S3
|
5
|
+
module Types
|
6
|
+
# This error is not modeled.
|
7
|
+
#
|
8
|
+
# The bucket you are attempting to access must be addressed using the
|
9
|
+
# specified endpoint. Please send all future requests to this endpoint.
|
10
|
+
#
|
11
|
+
# @!attribute [rw] endpoint
|
12
|
+
# @return [String]
|
13
|
+
#
|
14
|
+
# @!attribute [rw] bucket
|
15
|
+
# @return [String]
|
16
|
+
#
|
17
|
+
# @!attribute [rw] message
|
18
|
+
# @return [String]
|
19
|
+
#
|
20
|
+
class PermanentRedirect < Struct.new(:endpoint, :bucket, :region, :message)
|
21
|
+
SENSITIVE = []
|
22
|
+
include Aws::Structure
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|