aws-sdk-s3 1.103.0 → 1.120.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (59) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +139 -0
  3. data/VERSION +1 -1
  4. data/lib/aws-sdk-s3/bucket.rb +134 -34
  5. data/lib/aws-sdk-s3/bucket_acl.rb +18 -2
  6. data/lib/aws-sdk-s3/bucket_cors.rb +20 -4
  7. data/lib/aws-sdk-s3/bucket_lifecycle.rb +24 -6
  8. data/lib/aws-sdk-s3/bucket_lifecycle_configuration.rb +28 -6
  9. data/lib/aws-sdk-s3/bucket_logging.rb +18 -2
  10. data/lib/aws-sdk-s3/bucket_notification.rb +17 -5
  11. data/lib/aws-sdk-s3/bucket_policy.rb +20 -4
  12. data/lib/aws-sdk-s3/bucket_request_payment.rb +18 -2
  13. data/lib/aws-sdk-s3/bucket_tagging.rb +20 -4
  14. data/lib/aws-sdk-s3/bucket_versioning.rb +54 -6
  15. data/lib/aws-sdk-s3/bucket_website.rb +20 -4
  16. data/lib/aws-sdk-s3/client.rb +2574 -1199
  17. data/lib/aws-sdk-s3/client_api.rb +574 -208
  18. data/lib/aws-sdk-s3/customizations/bucket.rb +20 -46
  19. data/lib/aws-sdk-s3/customizations/errors.rb +27 -0
  20. data/lib/aws-sdk-s3/customizations/object.rb +80 -4
  21. data/lib/aws-sdk-s3/customizations/types/permanent_redirect.rb +26 -0
  22. data/lib/aws-sdk-s3/customizations.rb +2 -0
  23. data/lib/aws-sdk-s3/endpoint_parameters.rb +142 -0
  24. data/lib/aws-sdk-s3/endpoint_provider.rb +733 -0
  25. data/lib/aws-sdk-s3/endpoints.rb +2149 -0
  26. data/lib/aws-sdk-s3/file_downloader.rb +1 -1
  27. data/lib/aws-sdk-s3/file_uploader.rb +5 -0
  28. data/lib/aws-sdk-s3/multipart_file_uploader.rb +26 -7
  29. data/lib/aws-sdk-s3/multipart_stream_uploader.rb +36 -10
  30. data/lib/aws-sdk-s3/multipart_upload.rb +126 -12
  31. data/lib/aws-sdk-s3/multipart_upload_part.rb +133 -14
  32. data/lib/aws-sdk-s3/object.rb +289 -112
  33. data/lib/aws-sdk-s3/object_acl.rb +20 -4
  34. data/lib/aws-sdk-s3/object_multipart_copier.rb +11 -5
  35. data/lib/aws-sdk-s3/object_summary.rb +204 -74
  36. data/lib/aws-sdk-s3/object_version.rb +68 -40
  37. data/lib/aws-sdk-s3/plugins/accelerate.rb +3 -44
  38. data/lib/aws-sdk-s3/plugins/arn.rb +0 -197
  39. data/lib/aws-sdk-s3/plugins/bucket_dns.rb +3 -39
  40. data/lib/aws-sdk-s3/plugins/bucket_name_restrictions.rb +1 -6
  41. data/lib/aws-sdk-s3/plugins/dualstack.rb +1 -55
  42. data/lib/aws-sdk-s3/plugins/endpoints.rb +262 -0
  43. data/lib/aws-sdk-s3/plugins/expect_100_continue.rb +2 -1
  44. data/lib/aws-sdk-s3/plugins/iad_regional_endpoint.rb +6 -29
  45. data/lib/aws-sdk-s3/plugins/md5s.rb +5 -3
  46. data/lib/aws-sdk-s3/plugins/s3_signer.rb +33 -109
  47. data/lib/aws-sdk-s3/plugins/skip_whole_multipart_get_checksums.rb +31 -0
  48. data/lib/aws-sdk-s3/plugins/streaming_retry.rb +23 -2
  49. data/lib/aws-sdk-s3/presigned_post.rb +47 -35
  50. data/lib/aws-sdk-s3/presigner.rb +20 -33
  51. data/lib/aws-sdk-s3/resource.rb +19 -1
  52. data/lib/aws-sdk-s3/types.rb +2519 -4175
  53. data/lib/aws-sdk-s3.rb +5 -1
  54. metadata +11 -9
  55. data/lib/aws-sdk-s3/arn/access_point_arn.rb +0 -69
  56. data/lib/aws-sdk-s3/arn/multi_region_access_point_arn.rb +0 -69
  57. data/lib/aws-sdk-s3/arn/object_lambda_arn.rb +0 -69
  58. data/lib/aws-sdk-s3/arn/outpost_access_point_arn.rb +0 -73
  59. data/lib/aws-sdk-s3/plugins/object_lambda_endpoint.rb +0 -25
@@ -5,22 +5,6 @@ require 'uri'
5
5
  module Aws
6
6
  module S3
7
7
  class Bucket
8
- # Save the old initialize method so that we can call 'super'.
9
- old_initialize = instance_method(:initialize)
10
- # Make the method redefinable
11
- alias_method :initialize, :initialize
12
- # Define a new initialize method that extracts out a bucket ARN.
13
- define_method(:initialize) do |*args|
14
- old_initialize.bind(self).call(*args)
15
- resolved_region, arn = Plugins::ARN.resolve_arn!(
16
- name,
17
- client.config.region,
18
- client.config.s3_use_arn_region
19
- )
20
- @resolved_region = resolved_region
21
- @arn = arn
22
- end
23
-
24
8
  # Deletes all objects and versioned objects from this bucket
25
9
  #
26
10
  # @example
@@ -105,14 +89,27 @@ module Aws
105
89
  if options[:virtual_host]
106
90
  scheme = options.fetch(:secure, true) ? 'https' : 'http'
107
91
  "#{scheme}://#{name}"
108
- elsif @arn
109
- Plugins::ARN.resolve_url!(
110
- client.config.endpoint.dup,
111
- @arn,
112
- @resolved_region
113
- ).to_s
114
92
  else
115
- s3_bucket_url
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
116
113
  end
117
114
  end
118
115
 
@@ -142,29 +139,6 @@ module Aws
142
139
 
143
140
  self
144
141
  end
145
-
146
- private
147
-
148
- def s3_bucket_url
149
- url = client.config.endpoint.dup
150
- if bucket_as_hostname?(url.scheme == 'https')
151
- url.host = "#{name}.#{url.host}"
152
- else
153
- url.path += '/' unless url.path[-1] == '/'
154
- url.path += Seahorse::Util.uri_escape(name)
155
- end
156
- if (client.config.region == 'us-east-1') &&
157
- (client.config.s3_us_east_1_regional_endpoint == 'legacy')
158
- url.host = Plugins::IADRegionalEndpoint.legacy_host(url.host)
159
- end
160
- url.to_s
161
- end
162
-
163
- def bucket_as_hostname?(https)
164
- Plugins::BucketDns.dns_compatible?(name, https) &&
165
- !client.config.force_path_style
166
- end
167
-
168
142
  end
169
143
  end
170
144
  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
@@ -27,10 +27,13 @@ module Aws
27
27
  # necessary for objects larger than 5GB and can provide
28
28
  # performance improvements on large objects. Amazon S3 does
29
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.
30
32
  #
31
33
  # @option options [Integer] :content_length Only used when
32
34
  # `:multipart_copy` is `true`. Passing this options avoids a HEAD
33
- # request to query the source object size. Raises an `ArgumentError` if
35
+ # request to query the source object size but prevents object metadata
36
+ # from being copied. Raises an `ArgumentError` if
34
37
  # this option is provided when `:multipart_copy` is `false` or not set.
35
38
  #
36
39
  # @option options [S3::Client] :copy_source_client Only used when
@@ -161,7 +164,7 @@ module Aws
161
164
  #
162
165
  # @param [Symbol] method
163
166
  # The S3 operation to generate a presigned URL for. Valid values
164
- # are `:get`, `:put`, `:head`, `:delete`, `:create_multipart_upload`,
167
+ # are `:get`, `:put`, `:head`, `:delete`, `:create_multipart_upload`,
165
168
  # `:list_multipart_uploads`, `:complete_multipart_upload`,
166
169
  # `:abort_multipart_upload`, `:list_parts`, and `:upload_part`.
167
170
  #
@@ -215,6 +218,79 @@ module Aws
215
218
  )
216
219
  end
217
220
 
221
+ # Allows you to create presigned URL requests for S3 operations. This
222
+ # method returns a tuple containing the URL and the signed X-amz-* headers
223
+ # to be used with the presigned url.
224
+ #
225
+ # @example Pre-signed GET URL, valid for one hour
226
+ #
227
+ # obj.presigned_request(:get, expires_in: 3600)
228
+ # #=> ["https://bucket-name.s3.amazonaws.com/object-key?...", {}]
229
+ #
230
+ # @example Pre-signed PUT with a canned ACL
231
+ #
232
+ # # the object uploaded using this URL will be publicly accessible
233
+ # obj.presigned_request(:put, acl: 'public-read')
234
+ # #=> ["https://bucket-name.s3.amazonaws.com/object-key?...",
235
+ # {"x-amz-acl"=>"public-read"}]
236
+ #
237
+ # @param [Symbol] method
238
+ # The S3 operation to generate a presigned request for. Valid values
239
+ # are `:get`, `:put`, `:head`, `:delete`, `:create_multipart_upload`,
240
+ # `:list_multipart_uploads`, `:complete_multipart_upload`,
241
+ # `:abort_multipart_upload`, `:list_parts`, and `:upload_part`.
242
+ #
243
+ # @param [Hash] params
244
+ # Additional request parameters to use when generating the pre-signed
245
+ # request. See the related documentation in {Client} for accepted
246
+ # params.
247
+ #
248
+ # | Method | Client Method |
249
+ # |------------------------------|------------------------------------|
250
+ # | `:get` | {Client#get_object} |
251
+ # | `:put` | {Client#put_object} |
252
+ # | `:head` | {Client#head_object} |
253
+ # | `:delete` | {Client#delete_object} |
254
+ # | `:create_multipart_upload` | {Client#create_multipart_upload} |
255
+ # | `:list_multipart_uploads` | {Client#list_multipart_uploads} |
256
+ # | `:complete_multipart_upload` | {Client#complete_multipart_upload} |
257
+ # | `:abort_multipart_upload` | {Client#abort_multipart_upload} |
258
+ # | `:list_parts` | {Client#list_parts} |
259
+ # | `:upload_part` | {Client#upload_part} |
260
+ #
261
+ # @option params [Boolean] :virtual_host (false) When `true` the
262
+ # presigned URL will use the bucket name as a virtual host.
263
+ #
264
+ # bucket = Aws::S3::Bucket.new('my.bucket.com')
265
+ # bucket.object('key').presigned_request(virtual_host: true)
266
+ # #=> ["http://my.bucket.com/key?...", {}]
267
+ #
268
+ # @option params [Integer] :expires_in (900) Number of seconds before
269
+ # the pre-signed URL expires. This may not exceed one week (604800
270
+ # seconds). Note that the pre-signed URL is also only valid as long as
271
+ # credentials used to sign it are. For example, when using IAM roles,
272
+ # temporary tokens generated for signing also have a default expiration
273
+ # which will affect the effective expiration of the pre-signed URL.
274
+ #
275
+ # @raise [ArgumentError] Raised if `:expires_in` exceeds one week
276
+ # (604800 seconds).
277
+ #
278
+ # @return [String, Hash] A tuple with a presigned URL and headers that
279
+ # should be included with the request.
280
+ #
281
+ def presigned_request(method, params = {})
282
+ presigner = Presigner.new(client: client)
283
+
284
+ if %w(delete head get put).include?(method.to_s)
285
+ method = "#{method}_object".to_sym
286
+ end
287
+
288
+ presigner.presigned_request(
289
+ method.downcase,
290
+ params.merge(bucket: bucket_name, key: key)
291
+ )
292
+ end
293
+
218
294
  # Returns the public (un-signed) URL for this object.
219
295
  #
220
296
  # s3.bucket('bucket-name').object('obj-key').public_url
@@ -327,7 +403,7 @@ module Aws
327
403
  # progress = Proc.new do |bytes, totals|
328
404
  # puts bytes.map.with_index { |b, i| "Part #{i+1}: #{b} / #{totals[i]}"}.join(' ') + "Total: #{100.0 * bytes.sum / totals.sum }%" }
329
405
  # end
330
- # obj.upload_file('/path/to/file')
406
+ # obj.upload_file('/path/to/file', progress_callback: progress)
331
407
  #
332
408
  # @param [String, Pathname, File, Tempfile] source A file on the local
333
409
  # file system that will be uploaded as this object. This can either be
@@ -391,7 +467,7 @@ module Aws
391
467
  # customizing each range size in multipart_download,
392
468
  # By default, `auto` mode is enabled, which performs multipart_download
393
469
  #
394
- # @option options [String] chunk_size required in get_range mode.
470
+ # @option options [Integer] chunk_size required in get_range mode.
395
471
  #
396
472
  # @option options [Integer] thread_count (10) Customize threads used in
397
473
  # the multipart download.
@@ -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
@@ -18,10 +18,12 @@ require 'aws-sdk-s3/presigner'
18
18
 
19
19
  # customizations to generated classes
20
20
  require 'aws-sdk-s3/customizations/bucket'
21
+ require 'aws-sdk-s3/customizations/errors'
21
22
  require 'aws-sdk-s3/customizations/object'
22
23
  require 'aws-sdk-s3/customizations/object_summary'
23
24
  require 'aws-sdk-s3/customizations/multipart_upload'
24
25
  require 'aws-sdk-s3/customizations/types/list_object_versions_output'
26
+ require 'aws-sdk-s3/customizations/types/permanent_redirect'
25
27
 
26
28
  [
27
29
  Aws::S3::Object::Collection,
@@ -0,0 +1,142 @@
1
+ # frozen_string_literal: true
2
+
3
+ # WARNING ABOUT GENERATED CODE
4
+ #
5
+ # This file is generated. See the contributing guide for more information:
6
+ # https://github.com/aws/aws-sdk-ruby/blob/version-3/CONTRIBUTING.md
7
+ #
8
+ # WARNING ABOUT GENERATED CODE
9
+
10
+ module Aws::S3
11
+ # Endpoint parameters used to influence endpoints per request.
12
+ #
13
+ # @!attribute bucket
14
+ # The S3 bucket used to send the request. This is an optional parameter that will be set automatically for operations that are scoped to an S3 bucket.
15
+ #
16
+ # @return [String]
17
+ #
18
+ # @!attribute region
19
+ # The AWS region used to dispatch the request.
20
+ #
21
+ # @return [String]
22
+ #
23
+ # @!attribute use_fips
24
+ # When true, send this request to the FIPS-compliant regional endpoint. If the configured endpoint does not have a FIPS compliant endpoint, dispatching the request will return an error.
25
+ #
26
+ # @return [Boolean]
27
+ #
28
+ # @!attribute use_dual_stack
29
+ # When true, use the dual-stack endpoint. If the configured endpoint does not support dual-stack, dispatching the request MAY return an error.
30
+ #
31
+ # @return [Boolean]
32
+ #
33
+ # @!attribute endpoint
34
+ # Override the endpoint used to send this request
35
+ #
36
+ # @return [String]
37
+ #
38
+ # @!attribute force_path_style
39
+ # When true, force a path-style endpoint to be used where the bucket name is part of the path.
40
+ #
41
+ # @return [Boolean]
42
+ #
43
+ # @!attribute accelerate
44
+ # When true, use S3 Accelerate. NOTE: Not all regions support S3 accelerate.
45
+ #
46
+ # @return [Boolean]
47
+ #
48
+ # @!attribute use_global_endpoint
49
+ # Whether the global endpoint should be used, rather then the regional endpoint for us-east-1.
50
+ #
51
+ # @return [Boolean]
52
+ #
53
+ # @!attribute use_object_lambda_endpoint
54
+ # Internal parameter to use object lambda endpoint for an operation (eg: WriteGetObjectResponse)
55
+ #
56
+ # @return [Boolean]
57
+ #
58
+ # @!attribute disable_access_points
59
+ # Internal parameter to disable Access Point Buckets
60
+ #
61
+ # @return [Boolean]
62
+ #
63
+ # @!attribute disable_multi_region_access_points
64
+ # Whether multi-region access points (MRAP) should be disabled.
65
+ #
66
+ # @return [Boolean]
67
+ #
68
+ # @!attribute use_arn_region
69
+ # When an Access Point ARN is provided and this flag is enabled, the SDK MUST use the ARN&#39;s region when constructing the endpoint instead of the client&#39;s configured region.
70
+ #
71
+ # @return [Boolean]
72
+ #
73
+ EndpointParameters = Struct.new(
74
+ :bucket,
75
+ :region,
76
+ :use_fips,
77
+ :use_dual_stack,
78
+ :endpoint,
79
+ :force_path_style,
80
+ :accelerate,
81
+ :use_global_endpoint,
82
+ :use_object_lambda_endpoint,
83
+ :disable_access_points,
84
+ :disable_multi_region_access_points,
85
+ :use_arn_region,
86
+ ) do
87
+ include Aws::Structure
88
+
89
+ # @api private
90
+ class << self
91
+ PARAM_MAP = {
92
+ 'Bucket' => :bucket,
93
+ 'Region' => :region,
94
+ 'UseFIPS' => :use_fips,
95
+ 'UseDualStack' => :use_dual_stack,
96
+ 'Endpoint' => :endpoint,
97
+ 'ForcePathStyle' => :force_path_style,
98
+ 'Accelerate' => :accelerate,
99
+ 'UseGlobalEndpoint' => :use_global_endpoint,
100
+ 'UseObjectLambdaEndpoint' => :use_object_lambda_endpoint,
101
+ 'DisableAccessPoints' => :disable_access_points,
102
+ 'DisableMultiRegionAccessPoints' => :disable_multi_region_access_points,
103
+ 'UseArnRegion' => :use_arn_region,
104
+ }.freeze
105
+ end
106
+
107
+ def initialize(options = {})
108
+ self[:bucket] = options[:bucket]
109
+ self[:region] = options[:region]
110
+ self[:use_fips] = options[:use_fips]
111
+ self[:use_fips] = false if self[:use_fips].nil?
112
+ if self[:use_fips].nil?
113
+ raise ArgumentError, "Missing required EndpointParameter: :use_fips"
114
+ end
115
+ self[:use_dual_stack] = options[:use_dual_stack]
116
+ self[:use_dual_stack] = false if self[:use_dual_stack].nil?
117
+ if self[:use_dual_stack].nil?
118
+ raise ArgumentError, "Missing required EndpointParameter: :use_dual_stack"
119
+ end
120
+ self[:endpoint] = options[:endpoint]
121
+ self[:force_path_style] = options[:force_path_style]
122
+ self[:accelerate] = options[:accelerate]
123
+ self[:accelerate] = false if self[:accelerate].nil?
124
+ if self[:accelerate].nil?
125
+ raise ArgumentError, "Missing required EndpointParameter: :accelerate"
126
+ end
127
+ self[:use_global_endpoint] = options[:use_global_endpoint]
128
+ self[:use_global_endpoint] = false if self[:use_global_endpoint].nil?
129
+ if self[:use_global_endpoint].nil?
130
+ raise ArgumentError, "Missing required EndpointParameter: :use_global_endpoint"
131
+ end
132
+ self[:use_object_lambda_endpoint] = options[:use_object_lambda_endpoint]
133
+ self[:disable_access_points] = options[:disable_access_points]
134
+ self[:disable_multi_region_access_points] = options[:disable_multi_region_access_points]
135
+ self[:disable_multi_region_access_points] = false if self[:disable_multi_region_access_points].nil?
136
+ if self[:disable_multi_region_access_points].nil?
137
+ raise ArgumentError, "Missing required EndpointParameter: :disable_multi_region_access_points"
138
+ end
139
+ self[:use_arn_region] = options[:use_arn_region]
140
+ end
141
+ end
142
+ end