aws-sdk-s3 1.143.0 → 1.156.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (63) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +100 -1
  3. data/VERSION +1 -1
  4. data/lib/aws-sdk-s3/access_grants_credentials.rb +57 -0
  5. data/lib/aws-sdk-s3/access_grants_credentials_provider.rb +241 -0
  6. data/lib/aws-sdk-s3/bucket.rb +13 -10
  7. data/lib/aws-sdk-s3/bucket_acl.rb +3 -3
  8. data/lib/aws-sdk-s3/bucket_cors.rb +4 -4
  9. data/lib/aws-sdk-s3/bucket_lifecycle.rb +4 -4
  10. data/lib/aws-sdk-s3/bucket_lifecycle_configuration.rb +4 -4
  11. data/lib/aws-sdk-s3/bucket_logging.rb +3 -3
  12. data/lib/aws-sdk-s3/bucket_notification.rb +3 -3
  13. data/lib/aws-sdk-s3/bucket_policy.rb +4 -4
  14. data/lib/aws-sdk-s3/bucket_region_cache.rb +9 -5
  15. data/lib/aws-sdk-s3/bucket_request_payment.rb +3 -3
  16. data/lib/aws-sdk-s3/bucket_tagging.rb +4 -4
  17. data/lib/aws-sdk-s3/bucket_versioning.rb +5 -5
  18. data/lib/aws-sdk-s3/bucket_website.rb +4 -4
  19. data/lib/aws-sdk-s3/client.rb +370 -314
  20. data/lib/aws-sdk-s3/client_api.rb +15 -6
  21. data/lib/aws-sdk-s3/customizations/bucket.rb +1 -1
  22. data/lib/aws-sdk-s3/customizations/errors.rb +15 -2
  23. data/lib/aws-sdk-s3/customizations/object.rb +5 -5
  24. data/lib/aws-sdk-s3/customizations.rb +4 -1
  25. data/lib/aws-sdk-s3/encryption/client.rb +2 -2
  26. data/lib/aws-sdk-s3/encryption/kms_cipher_provider.rb +2 -2
  27. data/lib/aws-sdk-s3/encryptionV2/client.rb +2 -2
  28. data/lib/aws-sdk-s3/encryptionV2/kms_cipher_provider.rb +2 -2
  29. data/lib/aws-sdk-s3/endpoint_parameters.rb +8 -0
  30. data/lib/aws-sdk-s3/endpoint_provider.rb +7 -6
  31. data/lib/aws-sdk-s3/endpoints.rb +100 -1
  32. data/lib/aws-sdk-s3/express_credentials_provider.rb +27 -4
  33. data/lib/aws-sdk-s3/file_downloader.rb +1 -1
  34. data/lib/aws-sdk-s3/file_uploader.rb +1 -1
  35. data/lib/aws-sdk-s3/multipart_file_uploader.rb +4 -3
  36. data/lib/aws-sdk-s3/multipart_stream_uploader.rb +6 -4
  37. data/lib/aws-sdk-s3/multipart_upload.rb +4 -4
  38. data/lib/aws-sdk-s3/multipart_upload_part.rb +3 -3
  39. data/lib/aws-sdk-s3/object.rb +30 -12
  40. data/lib/aws-sdk-s3/object_acl.rb +3 -3
  41. data/lib/aws-sdk-s3/object_copier.rb +1 -1
  42. data/lib/aws-sdk-s3/object_multipart_copier.rb +10 -8
  43. data/lib/aws-sdk-s3/object_summary.rb +10 -10
  44. data/lib/aws-sdk-s3/object_version.rb +23 -5
  45. data/lib/aws-sdk-s3/plugins/access_grants.rb +114 -0
  46. data/lib/aws-sdk-s3/plugins/express_session_auth.rb +8 -2
  47. data/lib/aws-sdk-s3/plugins/http_200_errors.rb +53 -16
  48. data/lib/aws-sdk-s3/plugins/s3_signer.rb +7 -2
  49. data/lib/aws-sdk-s3/presigner.rb +2 -0
  50. data/lib/aws-sdk-s3/resource.rb +3 -3
  51. data/lib/aws-sdk-s3/types.rb +101 -51
  52. data/lib/aws-sdk-s3.rb +1 -1
  53. data/sig/client.rbs +21 -0
  54. data/sig/customizations/bucket.rbs +19 -0
  55. data/sig/customizations/object.rbs +38 -0
  56. data/sig/customizations/object_summary.rbs +35 -0
  57. data/sig/object.rbs +6 -0
  58. data/sig/object_version.rbs +6 -0
  59. data/sig/resource.rbs +3 -0
  60. data/sig/types.rbs +6 -0
  61. data/sig/waiters.rbs +12 -0
  62. metadata +12 -7
  63. data/lib/aws-sdk-s3/express_credentials_cache.rb +0 -30
@@ -0,0 +1,114 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Aws
4
+ module S3
5
+ module Plugins
6
+ # @api private
7
+ class AccessGrants < Seahorse::Client::Plugin
8
+ @s3control =
9
+ begin
10
+ require 'aws-sdk-s3control'
11
+ true
12
+ rescue LoadError
13
+ false
14
+ end
15
+
16
+ option(
17
+ :access_grants,
18
+ default: false,
19
+ doc_type: 'Boolean',
20
+ docstring: <<-DOCS)
21
+ When `true`, the S3 client will use the S3 Access Grants feature to
22
+ authenticate requests. Bucket credentials will be fetched from S3
23
+ Control using the `get_data_access` API.
24
+ DOCS
25
+
26
+ option(:access_grants_credentials_provider,
27
+ doc_type: 'Aws::S3::AccessGrantsCredentialsProvider',
28
+ rbs_type: 'untyped',
29
+ docstring: <<-DOCS) do |_cfg|
30
+ When `access_grants` is `true`, this option can be used to provide
31
+ additional options to the credentials provider, including a privilege
32
+ setting, caching, and fallback behavior.
33
+ DOCS
34
+ Aws::S3::AccessGrantsCredentialsProvider.new
35
+ end
36
+
37
+ # @api private
38
+ class Handler < Seahorse::Client::Handler
39
+ PERMISSION_MAP = {
40
+ head_object: 'READ',
41
+ get_object: 'READ',
42
+ get_object_acl: 'READ',
43
+ list_multipart_uploads: 'READ',
44
+ list_objects_v2: 'READ',
45
+ list_object_versions: 'READ',
46
+ list_parts: 'READ',
47
+ put_object: 'WRITE',
48
+ put_object_acl: 'WRITE',
49
+ delete_object: 'WRITE',
50
+ abort_multipart_upload: 'WRITE',
51
+ create_multipart_upload: 'WRITE',
52
+ upload_part: 'WRITE',
53
+ complete_multipart_upload: 'WRITE'
54
+ }.freeze
55
+
56
+ def call(context)
57
+ if access_grants_operation?(context) &&
58
+ !s3_express_endpoint?(context)
59
+ params = context[:endpoint_params]
60
+ permission = PERMISSION_MAP[context.operation_name]
61
+
62
+ provider = context.config.access_grants_credentials_provider
63
+ credentials = provider.access_grants_credentials_for(
64
+ bucket: params[:bucket],
65
+ key: params[:key],
66
+ prefix: params[:prefix],
67
+ permission: permission
68
+ )
69
+ context[:sigv4_credentials] = credentials # Sign will use this
70
+ end
71
+
72
+ with_metric(credentials) { @handler.call(context) }
73
+ end
74
+
75
+ private
76
+
77
+ def with_metric(credentials, &block)
78
+ return block.call unless credentials
79
+
80
+ Aws::Plugins::UserAgent.metric('S3_ACCESS_GRANTS', &block)
81
+ end
82
+
83
+ def access_grants_operation?(context)
84
+ params = context[:endpoint_params]
85
+ params[:bucket] && PERMISSION_MAP[context.operation_name]
86
+ end
87
+
88
+ def s3_express_endpoint?(context)
89
+ context[:endpoint_properties]['backend'] == 'S3Express'
90
+ end
91
+ end
92
+
93
+ def add_handlers(handlers, config)
94
+ return unless AccessGrants.s3control? && config.access_grants
95
+
96
+ handlers.add(Handler)
97
+ end
98
+
99
+ def after_initialize(client)
100
+ return unless AccessGrants.s3control? && client.config.access_grants
101
+
102
+ provider = client.config.access_grants_credentials_provider
103
+ provider.s3_client = client unless provider.s3_client
104
+ end
105
+
106
+ class << self
107
+ def s3control?
108
+ @s3control
109
+ end
110
+ end
111
+ end
112
+ end
113
+ end
114
+ end
@@ -31,7 +31,7 @@ for different buckets.
31
31
  def call(context)
32
32
  if (props = context[:endpoint_properties])
33
33
  # S3 Express endpoint - turn off md5 and enable crc32 default
34
- if (backend = props['backend']) && backend == 'S3Express'
34
+ if props['backend'] == 'S3Express'
35
35
  if context.operation_name == :put_object || checksum_required?(context)
36
36
  context[:default_request_checksum_algorithm] = 'CRC32'
37
37
  end
@@ -47,11 +47,17 @@ for different buckets.
47
47
  context[:sigv4_credentials] = credentials # Sign will use this
48
48
  end
49
49
  end
50
- @handler.call(context)
50
+ with_metric(credentials) { @handler.call(context) }
51
51
  end
52
52
 
53
53
  private
54
54
 
55
+ def with_metric(credentials, &block)
56
+ return block.call unless credentials
57
+
58
+ Aws::Plugins::UserAgent.metric('S3_EXPRESS_BUCKET', &block)
59
+ end
60
+
55
61
  def checksum_required?(context)
56
62
  context.operation.http_checksum_required ||
57
63
  (context.operation.http_checksum &&
@@ -15,22 +15,67 @@ module Aws
15
15
 
16
16
  def call(context)
17
17
  @handler.call(context).on(200) do |response|
18
- if error = check_for_error(context)
19
- context.http_response.status_code = 500
20
- response.data = nil
21
- response.error = error
18
+ return response if streaming_output?(context.operation.output)
19
+
20
+ error = check_for_error(context)
21
+ return response unless error
22
+
23
+ context.http_response.status_code = 500
24
+ response.data = nil
25
+ response.error = error
26
+ end
27
+ end
28
+
29
+ private
30
+
31
+ # Streaming outputs are not subject to 200 errors.
32
+ def streaming_output?(output)
33
+ if (payload = output[:payload_member])
34
+ # checking ref and shape
35
+ payload['streaming'] || payload.shape['streaming'] ||
36
+ payload.eventstream
37
+ else
38
+ false
39
+ end
40
+ end
41
+
42
+ # Checks if the output shape is a structure shape and has members that
43
+ # are in the body for the case of a payload and a normal structure. A
44
+ # non-structure shape will not have members in the body. In the case
45
+ # of a string or blob, the body contents would have been checked first
46
+ # before this method is called in incomplete_xml_body?.
47
+ def members_in_body?(output)
48
+ shape =
49
+ if output[:payload_member]
50
+ output[:payload_member].shape
51
+ else
52
+ output.shape
22
53
  end
54
+
55
+ if structure_shape?(shape)
56
+ shape.members.any? { |_, k| k.location.nil? }
57
+ else
58
+ false
23
59
  end
24
60
  end
25
61
 
62
+ def structure_shape?(shape)
63
+ shape.is_a?(Seahorse::Model::Shapes::StructureShape)
64
+ end
65
+
66
+ # Must have a member in the body and have the start of an XML Tag.
67
+ # Other incomplete xml bodies will result in an XML ParsingError.
68
+ def incomplete_xml_body?(xml, output)
69
+ members_in_body?(output) && !xml.match(/<\w/)
70
+ end
71
+
26
72
  def check_for_error(context)
27
73
  xml = context.http_response.body_contents
28
- if xml.match(/<Error>/)
74
+ if xml.match(/\?>\s*<Error>/)
29
75
  error_code = xml.match(/<Code>(.+?)<\/Code>/)[1]
30
76
  error_message = xml.match(/<Message>(.+?)<\/Message>/)[1]
31
77
  S3::Errors.error_class(error_code).new(context, error_message)
32
- elsif !xml.match(/<\w/) # Must have the start of an XML Tag
33
- # Other incomplete xml bodies will result in XML ParsingError
78
+ elsif incomplete_xml_body?(xml, context.operation.output)
34
79
  Seahorse::Client::NetworkingError.new(
35
80
  S3::Errors
36
81
  .error_class('InternalError')
@@ -40,15 +85,7 @@ module Aws
40
85
  end
41
86
  end
42
87
 
43
- handler(
44
- Handler,
45
- step: :sign,
46
- operations: [
47
- :complete_multipart_upload,
48
- :copy_object,
49
- :upload_part_copy,
50
- ]
51
- )
88
+ handler(Handler, step: :sign)
52
89
  end
53
90
  end
54
91
  end
@@ -4,6 +4,11 @@ require 'aws-sigv4'
4
4
 
5
5
  module Aws
6
6
  module S3
7
+ # @api private
8
+ def self.bucket_region_cache
9
+ @bucket_region_cache ||= BucketRegionCache.new
10
+ end
11
+
7
12
  module Plugins
8
13
  # This plugin used to have a V4 signer but it was removed in favor of
9
14
  # generic Sign plugin that uses endpoint auth scheme.
@@ -51,7 +56,7 @@ module Aws
51
56
  private
52
57
 
53
58
  def check_for_cached_region(context, bucket)
54
- cached_region = S3::BUCKET_REGIONS[bucket]
59
+ cached_region = Aws::S3.bucket_region_cache[bucket]
55
60
  if cached_region &&
56
61
  cached_region != context.config.region &&
57
62
  !S3Signer.custom_endpoint?(context)
@@ -97,7 +102,7 @@ module Aws
97
102
  end
98
103
 
99
104
  def update_bucket_cache(context, actual_region)
100
- S3::BUCKET_REGIONS[context.params[:bucket]] = actual_region
105
+ Aws::S3.bucket_region_cache[context.params[:bucket]] = actual_region
101
106
  end
102
107
 
103
108
  def fips_region?(resp)
@@ -199,6 +199,8 @@ module Aws
199
199
  req.handlers.remove(Aws::S3::Plugins::S3Signer::LegacyHandler)
200
200
  req.handlers.remove(Aws::Plugins::Sign::Handler)
201
201
  req.handlers.remove(Seahorse::Client::Plugins::ContentLength::Handler)
202
+ req.handlers.remove(Aws::Rest::ContentTypeHandler)
203
+ req.handlers.remove(Aws::Plugins::InvocationId::Handler)
202
204
 
203
205
  req.handle(step: :send) do |context|
204
206
  # if an endpoint was not provided, force secure or insecure
@@ -79,7 +79,7 @@ module Aws::S3
79
79
  # Virtual-hosted-style requests aren't supported. Directory bucket
80
80
  # names must be unique in the chosen Availability Zone. Bucket names
81
81
  # must also follow the format ` bucket_base_name--az_id--x-s3` (for
82
- # example, ` DOC-EXAMPLE-BUCKET--usw2-az2--x-s3`). For information about
82
+ # example, ` DOC-EXAMPLE-BUCKET--usw2-az1--x-s3`). For information about
83
83
  # bucket naming restrictions, see [Directory bucket naming rules][2] in
84
84
  # the *Amazon S3 User Guide*
85
85
  #
@@ -166,7 +166,7 @@ module Aws::S3
166
166
  # [1]: https://docs.aws.amazon.com/AmazonS3/latest/userguide/about-object-ownership.html
167
167
  # @return [Bucket]
168
168
  def create_bucket(options = {})
169
- Aws::Plugins::UserAgent.feature('resource') do
169
+ Aws::Plugins::UserAgent.metric('RESOURCE_MODEL') do
170
170
  @client.create_bucket(options)
171
171
  end
172
172
  Bucket.new(
@@ -194,7 +194,7 @@ module Aws::S3
194
194
  def buckets(options = {})
195
195
  batches = Enumerator.new do |y|
196
196
  batch = []
197
- resp = Aws::Plugins::UserAgent.feature('resource') do
197
+ resp = Aws::Plugins::UserAgent.metric('RESOURCE_MODEL') do
198
198
  @client.list_buckets(options)
199
199
  end
200
200
  resp.data.buckets.each do |b|