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.
Files changed (128) hide show
  1. checksums.yaml +5 -5
  2. data/CHANGELOG.md +1126 -0
  3. data/LICENSE.txt +202 -0
  4. data/VERSION +1 -0
  5. data/lib/aws-sdk-s3/bucket.rb +778 -94
  6. data/lib/aws-sdk-s3/bucket_acl.rb +64 -18
  7. data/lib/aws-sdk-s3/bucket_cors.rb +79 -18
  8. data/lib/aws-sdk-s3/bucket_lifecycle.rb +66 -20
  9. data/lib/aws-sdk-s3/bucket_lifecycle_configuration.rb +68 -20
  10. data/lib/aws-sdk-s3/bucket_logging.rb +68 -16
  11. data/lib/aws-sdk-s3/bucket_notification.rb +52 -20
  12. data/lib/aws-sdk-s3/bucket_policy.rb +107 -17
  13. data/lib/aws-sdk-s3/bucket_region_cache.rb +2 -0
  14. data/lib/aws-sdk-s3/bucket_request_payment.rb +60 -15
  15. data/lib/aws-sdk-s3/bucket_tagging.rb +71 -18
  16. data/lib/aws-sdk-s3/bucket_versioning.rb +133 -17
  17. data/lib/aws-sdk-s3/bucket_website.rb +78 -21
  18. data/lib/aws-sdk-s3/client.rb +12559 -877
  19. data/lib/aws-sdk-s3/client_api.rb +1078 -191
  20. data/lib/aws-sdk-s3/customizations/bucket.rb +56 -37
  21. data/lib/aws-sdk-s3/customizations/errors.rb +27 -0
  22. data/lib/aws-sdk-s3/customizations/multipart_upload.rb +2 -0
  23. data/lib/aws-sdk-s3/customizations/object.rb +231 -39
  24. data/lib/aws-sdk-s3/customizations/object_summary.rb +5 -0
  25. data/lib/aws-sdk-s3/customizations/types/list_object_versions_output.rb +2 -0
  26. data/lib/aws-sdk-s3/customizations/types/permanent_redirect.rb +26 -0
  27. data/lib/aws-sdk-s3/customizations.rb +11 -1
  28. data/lib/aws-sdk-s3/encryption/client.rb +25 -8
  29. data/lib/aws-sdk-s3/encryption/decrypt_handler.rb +71 -29
  30. data/lib/aws-sdk-s3/encryption/default_cipher_provider.rb +43 -5
  31. data/lib/aws-sdk-s3/encryption/default_key_provider.rb +2 -0
  32. data/lib/aws-sdk-s3/encryption/encrypt_handler.rb +13 -2
  33. data/lib/aws-sdk-s3/encryption/errors.rb +2 -0
  34. data/lib/aws-sdk-s3/encryption/io_auth_decrypter.rb +2 -0
  35. data/lib/aws-sdk-s3/encryption/io_decrypter.rb +11 -3
  36. data/lib/aws-sdk-s3/encryption/io_encrypter.rb +2 -0
  37. data/lib/aws-sdk-s3/encryption/key_provider.rb +2 -0
  38. data/lib/aws-sdk-s3/encryption/kms_cipher_provider.rb +46 -11
  39. data/lib/aws-sdk-s3/encryption/materials.rb +8 -6
  40. data/lib/aws-sdk-s3/encryption/utils.rb +25 -0
  41. data/lib/aws-sdk-s3/encryption.rb +4 -0
  42. data/lib/aws-sdk-s3/encryptionV2/client.rb +570 -0
  43. data/lib/aws-sdk-s3/encryptionV2/decrypt_handler.rb +223 -0
  44. data/lib/aws-sdk-s3/encryptionV2/default_cipher_provider.rb +170 -0
  45. data/lib/aws-sdk-s3/encryptionV2/default_key_provider.rb +40 -0
  46. data/lib/aws-sdk-s3/encryptionV2/encrypt_handler.rb +65 -0
  47. data/lib/aws-sdk-s3/encryptionV2/errors.rb +37 -0
  48. data/lib/aws-sdk-s3/encryptionV2/io_auth_decrypter.rb +58 -0
  49. data/lib/aws-sdk-s3/encryptionV2/io_decrypter.rb +37 -0
  50. data/lib/aws-sdk-s3/encryptionV2/io_encrypter.rb +73 -0
  51. data/lib/aws-sdk-s3/encryptionV2/key_provider.rb +31 -0
  52. data/lib/aws-sdk-s3/encryptionV2/kms_cipher_provider.rb +173 -0
  53. data/lib/aws-sdk-s3/encryptionV2/materials.rb +60 -0
  54. data/lib/aws-sdk-s3/encryptionV2/utils.rb +103 -0
  55. data/lib/aws-sdk-s3/encryption_v2.rb +23 -0
  56. data/lib/aws-sdk-s3/endpoint_parameters.rb +178 -0
  57. data/lib/aws-sdk-s3/endpoint_provider.rb +591 -0
  58. data/lib/aws-sdk-s3/endpoints.rb +2590 -0
  59. data/lib/aws-sdk-s3/errors.rb +123 -1
  60. data/lib/aws-sdk-s3/event_streams.rb +8 -1
  61. data/lib/aws-sdk-s3/express_credentials.rb +55 -0
  62. data/lib/aws-sdk-s3/express_credentials_cache.rb +30 -0
  63. data/lib/aws-sdk-s3/express_credentials_provider.rb +36 -0
  64. data/lib/aws-sdk-s3/file_downloader.rb +176 -44
  65. data/lib/aws-sdk-s3/file_part.rb +2 -0
  66. data/lib/aws-sdk-s3/file_uploader.rb +28 -8
  67. data/lib/aws-sdk-s3/legacy_signer.rb +17 -25
  68. data/lib/aws-sdk-s3/multipart_file_uploader.rb +68 -12
  69. data/lib/aws-sdk-s3/multipart_stream_uploader.rb +59 -20
  70. data/lib/aws-sdk-s3/multipart_upload.rb +242 -32
  71. data/lib/aws-sdk-s3/multipart_upload_error.rb +2 -0
  72. data/lib/aws-sdk-s3/multipart_upload_part.rb +367 -45
  73. data/lib/aws-sdk-s3/object.rb +2191 -227
  74. data/lib/aws-sdk-s3/object_acl.rb +103 -25
  75. data/lib/aws-sdk-s3/object_copier.rb +9 -5
  76. data/lib/aws-sdk-s3/object_multipart_copier.rb +43 -19
  77. data/lib/aws-sdk-s3/object_summary.rb +1811 -208
  78. data/lib/aws-sdk-s3/object_version.rb +452 -80
  79. data/lib/aws-sdk-s3/plugins/accelerate.rb +17 -64
  80. data/lib/aws-sdk-s3/plugins/arn.rb +70 -0
  81. data/lib/aws-sdk-s3/plugins/bucket_dns.rb +7 -43
  82. data/lib/aws-sdk-s3/plugins/bucket_name_restrictions.rb +20 -3
  83. data/lib/aws-sdk-s3/plugins/dualstack.rb +7 -50
  84. data/lib/aws-sdk-s3/plugins/endpoints.rb +274 -0
  85. data/lib/aws-sdk-s3/plugins/expect_100_continue.rb +5 -4
  86. data/lib/aws-sdk-s3/plugins/express_session_auth.rb +91 -0
  87. data/lib/aws-sdk-s3/plugins/get_bucket_location_fix.rb +3 -1
  88. data/lib/aws-sdk-s3/plugins/http_200_errors.rb +11 -3
  89. data/lib/aws-sdk-s3/plugins/iad_regional_endpoint.rb +44 -0
  90. data/lib/aws-sdk-s3/plugins/location_constraint.rb +5 -1
  91. data/lib/aws-sdk-s3/plugins/md5s.rb +32 -26
  92. data/lib/aws-sdk-s3/plugins/redirects.rb +2 -0
  93. data/lib/aws-sdk-s3/plugins/s3_host_id.rb +2 -0
  94. data/lib/aws-sdk-s3/plugins/s3_signer.rb +56 -92
  95. data/lib/aws-sdk-s3/plugins/skip_whole_multipart_get_checksums.rb +31 -0
  96. data/lib/aws-sdk-s3/plugins/sse_cpk.rb +3 -1
  97. data/lib/aws-sdk-s3/plugins/streaming_retry.rb +139 -0
  98. data/lib/aws-sdk-s3/plugins/url_encoded_keys.rb +2 -0
  99. data/lib/aws-sdk-s3/presigned_post.rb +160 -99
  100. data/lib/aws-sdk-s3/presigner.rb +136 -59
  101. data/lib/aws-sdk-s3/resource.rb +120 -8
  102. data/lib/aws-sdk-s3/types.rb +11349 -4242
  103. data/lib/aws-sdk-s3/waiters.rb +67 -1
  104. data/lib/aws-sdk-s3.rb +16 -6
  105. data/sig/bucket.rbs +212 -0
  106. data/sig/bucket_acl.rbs +78 -0
  107. data/sig/bucket_cors.rbs +69 -0
  108. data/sig/bucket_lifecycle.rbs +88 -0
  109. data/sig/bucket_lifecycle_configuration.rbs +111 -0
  110. data/sig/bucket_logging.rbs +76 -0
  111. data/sig/bucket_notification.rbs +114 -0
  112. data/sig/bucket_policy.rbs +59 -0
  113. data/sig/bucket_request_payment.rbs +54 -0
  114. data/sig/bucket_tagging.rbs +65 -0
  115. data/sig/bucket_versioning.rbs +77 -0
  116. data/sig/bucket_website.rbs +93 -0
  117. data/sig/client.rbs +2360 -0
  118. data/sig/errors.rbs +34 -0
  119. data/sig/multipart_upload.rbs +110 -0
  120. data/sig/multipart_upload_part.rbs +105 -0
  121. data/sig/object.rbs +436 -0
  122. data/sig/object_acl.rbs +86 -0
  123. data/sig/object_summary.rbs +334 -0
  124. data/sig/object_version.rbs +131 -0
  125. data/sig/resource.rbs +124 -0
  126. data/sig/types.rbs +2562 -0
  127. data/sig/waiters.rbs +83 -0
  128. metadata +68 -15
@@ -0,0 +1,91 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Aws
4
+ module S3
5
+ module Plugins
6
+ # @api private
7
+ class ExpressSessionAuth < Seahorse::Client::Plugin
8
+ # This should be s3_disable_express_auth instead
9
+ # But this is not a built in. We're overwriting the generated value
10
+ option(:disable_s3_express_session_auth,
11
+ default: false,
12
+ doc_type: 'Boolean',
13
+ docstring: <<-DOCS) do |cfg|
14
+ When `true`, S3 Express session authentication is disabled.
15
+ DOCS
16
+ resolve_disable_s3_express_session_auth(cfg)
17
+ end
18
+
19
+ option(:express_credentials_provider,
20
+ doc_type: 'Aws::S3::ExpressCredentialsProvider',
21
+ rbs_type: 'untyped',
22
+ docstring: <<-DOCS) do |_cfg|
23
+ Credential Provider for S3 Express endpoints. Manages credentials
24
+ for different buckets.
25
+ DOCS
26
+ Aws::S3::ExpressCredentialsProvider.new
27
+ end
28
+
29
+ # @api private
30
+ class Handler < Seahorse::Client::Handler
31
+ def call(context)
32
+ if (props = context[:endpoint_properties])
33
+ # S3 Express endpoint - turn off md5 and enable crc32 default
34
+ if (backend = props['backend']) && backend == 'S3Express'
35
+ if context.operation_name == :put_object || checksum_required?(context)
36
+ context[:default_request_checksum_algorithm] = 'CRC32'
37
+ end
38
+ context[:s3_express_endpoint] = true
39
+ end
40
+
41
+ # if s3 express auth, use new credentials and sign additional header
42
+ if context[:auth_scheme]['name'] == 'sigv4-s3express' &&
43
+ !context.config.disable_s3_express_session_auth
44
+ bucket = context.params[:bucket]
45
+ credentials_provider = context.config.express_credentials_provider
46
+ credentials = credentials_provider.express_credentials_for(bucket)
47
+ context[:sigv4_credentials] = credentials # Sign will use this
48
+ end
49
+ end
50
+ @handler.call(context)
51
+ end
52
+
53
+ private
54
+
55
+ def checksum_required?(context)
56
+ context.operation.http_checksum_required ||
57
+ (context.operation.http_checksum &&
58
+ context.operation.http_checksum['requestChecksumRequired'])
59
+ end
60
+ end
61
+
62
+ handler(Handler)
63
+
64
+ # Optimization - sets this client as the client to create sessions.
65
+ def after_initialize(client)
66
+ provider = client.config.express_credentials_provider
67
+ provider.client = client unless provider.client
68
+ end
69
+
70
+ class << self
71
+ private
72
+
73
+ def resolve_disable_s3_express_session_auth(cfg)
74
+ value = ENV['AWS_S3_DISABLE_EXPRESS_SESSION_AUTH'] ||
75
+ Aws.shared_config.s3_disable_express_session_auth(profile: cfg.profile) ||
76
+ 'false'
77
+ value = Aws::Util.str_2_bool(value)
78
+ # Raise if provided value is not true or false
79
+ if value.nil?
80
+ raise ArgumentError,
81
+ 'Must provide either `true` or `false` for the '\
82
+ '`s3_disable_express_session_auth` profile option or for '\
83
+ "ENV['AWS_S3_DISABLE_EXPRESS_SESSION_AUTH']."
84
+ end
85
+ value
86
+ end
87
+ end
88
+ end
89
+ end
90
+ end
91
+ end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Aws
2
4
  module S3
3
5
  module Plugins
@@ -9,7 +11,7 @@ module Aws
9
11
  @handler.call(context).on(200) do |response|
10
12
  response.data = S3::Types::GetBucketLocationOutput.new
11
13
  xml = context.http_response.body_contents
12
- matches = xml.match(/>(.+?)<\/LocationConstraint>/)
14
+ matches = xml.match(/<LocationConstraint.*?>(.+?)<\/LocationConstraint>/)
13
15
  response.data[:location_constraint] = matches ? matches[1] : ''
14
16
  end
15
17
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Aws
2
4
  module S3
3
5
  module Plugins
@@ -27,12 +29,19 @@ module Aws
27
29
  error_code = xml.match(/<Code>(.+?)<\/Code>/)[1]
28
30
  error_message = xml.match(/<Message>(.+?)<\/Message>/)[1]
29
31
  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
34
+ Seahorse::Client::NetworkingError.new(
35
+ S3::Errors
36
+ .error_class('InternalError')
37
+ .new(context, 'Empty or incomplete response body')
38
+ )
30
39
  end
31
40
  end
32
-
33
41
  end
34
42
 
35
- handler(Handler,
43
+ handler(
44
+ Handler,
36
45
  step: :sign,
37
46
  operations: [
38
47
  :complete_multipart_upload,
@@ -40,7 +49,6 @@ module Aws
40
49
  :upload_part_copy,
41
50
  ]
42
51
  )
43
-
44
52
  end
45
53
  end
46
54
  end
@@ -0,0 +1,44 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Aws
4
+ module S3
5
+ module Plugins
6
+
7
+ class IADRegionalEndpoint < Seahorse::Client::Plugin
8
+
9
+ option(:s3_us_east_1_regional_endpoint,
10
+ default: 'legacy',
11
+ doc_type: String,
12
+ docstring: <<-DOCS) do |cfg|
13
+ Pass in `regional` to enable the `us-east-1` regional endpoint.
14
+ Defaults to `legacy` mode which uses the global endpoint.
15
+ DOCS
16
+ resolve_iad_regional_endpoint(cfg)
17
+ end
18
+
19
+ private
20
+
21
+ def self.resolve_iad_regional_endpoint(cfg)
22
+ default_mode_value =
23
+ if cfg.respond_to?(:defaults_mode_config_resolver)
24
+ cfg.defaults_mode_config_resolver.resolve(:s3_us_east_1_regional_endpoint)
25
+ end
26
+
27
+ mode = ENV['AWS_S3_US_EAST_1_REGIONAL_ENDPOINT'] ||
28
+ Aws.shared_config.s3_us_east_1_regional_endpoint(profile: cfg.profile) ||
29
+ default_mode_value ||
30
+ 'legacy'
31
+ mode = mode.downcase
32
+ unless %w(legacy regional).include?(mode)
33
+ raise ArgumentError, "expected :s3_us_east_1_regional_endpoint or"\
34
+ " ENV['AWS_S3_US_EAST_1_REGIONAL_ENDPOINT'] to be `legacy` or"\
35
+ " `regional`."
36
+ end
37
+ mode
38
+ end
39
+
40
+ end
41
+
42
+ end
43
+ end
44
+ end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Aws
2
4
  module S3
3
5
  module Plugins
@@ -20,7 +22,9 @@ module Aws
20
22
 
21
23
  def populate_location_constraint(params, region)
22
24
  params[:create_bucket_configuration] ||= {}
23
- params[:create_bucket_configuration][:location_constraint] ||= region
25
+ unless params[:create_bucket_configuration][:location]
26
+ params[:create_bucket_configuration][:location_constraint] ||= region
27
+ end
24
28
  end
25
29
 
26
30
  end
@@ -1,20 +1,19 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'openssl'
2
4
 
3
5
  module Aws
4
6
  module S3
5
7
  module Plugins
8
+ # @api private
9
+ # This plugin is effectively deprecated in favor of modeled
10
+ # httpChecksumRequired traits.
6
11
  class Md5s < Seahorse::Client::Plugin
7
-
8
- # Amazon S3 requires these operations to have an MD5 checksum
9
- REQUIRED_OPERATIONS = [
10
- :delete_objects,
11
- :put_bucket_cors,
12
- :put_bucket_lifecycle,
13
- :put_bucket_policy,
14
- :put_bucket_tagging,
15
- :put_object_legal_hold,
16
- :put_object_lock_configuration,
17
- :put_object_retention
12
+ # These operations allow Content MD5 but are not required by
13
+ # httpChecksumRequired. This list should not grow.
14
+ OPTIONAL_OPERATIONS = [
15
+ :put_object,
16
+ :upload_part
18
17
  ]
19
18
 
20
19
  # @api private
@@ -23,9 +22,12 @@ module Aws
23
22
  CHUNK_SIZE = 1 * 1024 * 1024 # one MB
24
23
 
25
24
  def call(context)
26
- body = context.http_request.body
27
- if body.size > 0
28
- context.http_request.headers['Content-Md5'] ||= md5(body)
25
+ if !context[:checksum_algorithms] && # skip in favor of flexible checksum
26
+ !context[:s3_express_endpoint] # s3 express endpoints do not support md5
27
+ body = context.http_request.body
28
+ if body.respond_to?(:size) && body.size > 0
29
+ context.http_request.headers['Content-Md5'] ||= md5(body)
30
+ end
29
31
  end
30
32
  @handler.call(context)
31
33
  end
@@ -47,7 +49,9 @@ module Aws
47
49
  end
48
50
 
49
51
  def update_in_chunks(digest, io)
50
- while chunk = io.read(CHUNK_SIZE, buffer ||= "")
52
+ loop do
53
+ chunk = io.read(CHUNK_SIZE)
54
+ break unless chunk
51
55
  digest.update(chunk)
52
56
  end
53
57
  io.rewind
@@ -59,20 +63,22 @@ module Aws
59
63
  default: true,
60
64
  doc_type: 'Boolean',
61
65
  docstring: <<-DOCS)
62
- When `true` a MD5 checksum will be computed for every request that
63
- sends a body. When `false`, MD5 checksums will only be computed
64
- for operations that require them. Checksum errors returned by Amazon
65
- S3 are automatically retried up to `:retry_limit` times.
66
+ When `true` a MD5 checksum will be computed and sent in the Content Md5
67
+ header for :put_object and :upload_part. When `false`, MD5 checksums
68
+ will not be computed for these operations. Checksums are still computed
69
+ for operations requiring them. Checksum errors returned by Amazon S3 are
70
+ automatically retried up to `:retry_limit` times.
66
71
  DOCS
67
72
 
68
73
  def add_handlers(handlers, config)
69
- # priority set low to ensure md5 is computed AFTER the request is
70
- # built but before it is signed
71
- handlers.add(Handler, {
72
- priority: 10,
73
- step: :build,
74
- operations: config.compute_checksums ? nil : REQUIRED_OPERATIONS,
75
- })
74
+ if config.compute_checksums
75
+ # priority set low to ensure md5 is computed AFTER the request is
76
+ # built but before it is signed
77
+ handlers.add(
78
+ Handler,
79
+ priority: 10, step: :build, operations: OPTIONAL_OPERATIONS
80
+ )
81
+ end
76
82
  end
77
83
 
78
84
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Aws
2
4
  module S3
3
5
  module Plugins
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Aws
2
4
  module S3
3
5
  module Plugins
@@ -1,25 +1,17 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'aws-sigv4'
2
4
 
3
5
  module Aws
4
6
  module S3
5
7
  module Plugins
6
- # This plugin is an implementation detail and may be modified.
8
+ # This plugin used to have a V4 signer but it was removed in favor of
9
+ # generic Sign plugin that uses endpoint auth scheme.
10
+ #
7
11
  # @api private
8
12
  class S3Signer < Seahorse::Client::Plugin
9
-
10
13
  option(:signature_version, 'v4')
11
14
 
12
- option(:sigv4_signer) do |cfg|
13
- S3Signer.build_v4_signer(
14
- region: cfg.sigv4_region,
15
- credentials: cfg.credentials
16
- )
17
- end
18
-
19
- option(:sigv4_region) do |cfg|
20
- Aws::Partitions::EndpointProvider.signing_region(cfg.region, 's3')
21
- end
22
-
23
15
  def add_handlers(handlers, cfg)
24
16
  case cfg.signature_version
25
17
  when 'v4' then add_v4_handlers(handlers)
@@ -32,11 +24,11 @@ module Aws
32
24
 
33
25
  def add_v4_handlers(handlers)
34
26
  handlers.add(CachedBucketRegionHandler, step: :sign, priority: 60)
35
- handlers.add(V4Handler, step: :sign)
36
27
  handlers.add(BucketRegionErrorHandler, step: :sign, priority: 40)
37
28
  end
38
29
 
39
30
  def add_legacy_handler(handlers)
31
+ # generic Sign plugin will be skipped if it sees sigv2
40
32
  handlers.add(LegacyHandler, step: :sign)
41
33
  end
42
34
 
@@ -47,40 +39,9 @@ module Aws
47
39
  end
48
40
  end
49
41
 
50
- class V4Handler < Seahorse::Client::Handler
51
-
52
- def call(context)
53
- Aws::Plugins::SignatureV4.apply_signature(
54
- context: context,
55
- signer: sigv4_signer(context)
56
- )
57
- @handler.call(context)
58
- end
59
-
60
- private
61
-
62
- def sigv4_signer(context)
63
- # If the client was configured with the wrong region,
64
- # we have to build a new signer.
65
- if
66
- context[:cached_sigv4_region] &&
67
- context[:cached_sigv4_region] != context.config.sigv4_signer.region
68
- then
69
- S3Signer.build_v4_signer(
70
- region: context[:cached_sigv4_region],
71
- credentials: context.config.credentials
72
- )
73
- else
74
- context.config.sigv4_signer
75
- end
76
- end
77
-
78
- end
79
-
80
42
  # This handler will update the http endpoint when the bucket region
81
43
  # is known/cached.
82
44
  class CachedBucketRegionHandler < Seahorse::Client::Handler
83
-
84
45
  def call(context)
85
46
  bucket = context.params[:bucket]
86
47
  check_for_cached_region(context, bucket) if bucket
@@ -91,20 +52,23 @@ module Aws
91
52
 
92
53
  def check_for_cached_region(context, bucket)
93
54
  cached_region = S3::BUCKET_REGIONS[bucket]
94
- if cached_region && cached_region != context.config.region
95
- context.http_request.endpoint.host = S3Signer.new_hostname(context, cached_region)
96
- context[:cached_sigv4_region] = cached_region
55
+ if cached_region &&
56
+ cached_region != context.config.region &&
57
+ !S3Signer.custom_endpoint?(context)
58
+ context.http_request.endpoint.host = S3Signer.new_hostname(
59
+ context, cached_region
60
+ )
61
+ context[:sigv4_region] = cached_region # Sign plugin will use this
97
62
  end
98
63
  end
99
-
100
64
  end
101
65
 
102
66
  # This handler detects when a request fails because of a mismatched bucket
103
67
  # region. It follows up by making a request to determine the correct
104
68
  # region, then finally a version 4 signed request against the correct
105
- # regional endpoint.
69
+ # regional endpoint. This is intended for s3's global endpoint which
70
+ # will return 400 if the bucket is not in region.
106
71
  class BucketRegionErrorHandler < Seahorse::Client::Handler
107
-
108
72
  def call(context)
109
73
  response = @handler.call(context)
110
74
  handle_region_errors(response)
@@ -113,7 +77,10 @@ module Aws
113
77
  private
114
78
 
115
79
  def handle_region_errors(response)
116
- if wrong_sigv4_region?(response) && !fips_region?(response)
80
+ if wrong_sigv4_region?(response) &&
81
+ !fips_region?(response) &&
82
+ !S3Signer.custom_endpoint?(response.context) &&
83
+ !expired_credentials?(response)
117
84
  get_region_and_retry(response.context)
118
85
  else
119
86
  response
@@ -134,33 +101,38 @@ module Aws
134
101
  end
135
102
 
136
103
  def fips_region?(resp)
137
- resp.context.http_request.endpoint.host.include?('fips')
104
+ resp.context.http_request.endpoint.host.include?('s3-fips.')
105
+ end
106
+
107
+ def expired_credentials?(resp)
108
+ resp.context.http_response.body_contents.match(/<Code>ExpiredToken<\/Code>/)
138
109
  end
139
110
 
140
111
  def wrong_sigv4_region?(resp)
141
112
  resp.context.http_response.status_code == 400 &&
142
- (
143
- resp.context.http_response.headers['x-amz-bucket-region'] ||
144
- resp.context.http_response.body_contents.match(/<Region>.+?<\/Region>/)
145
- )
113
+ (resp.context.http_response.headers['x-amz-bucket-region'] ||
114
+ resp.context.http_response.body_contents.match(/<Region>.+?<\/Region>/))
146
115
  end
147
116
 
148
117
  def resign_with_new_region(context, actual_region)
149
118
  context.http_response.body.truncate(0)
150
- context.http_request.endpoint.host = S3Signer.new_hostname(context, actual_region)
119
+ context.http_request.endpoint.host = S3Signer.new_hostname(
120
+ context, actual_region
121
+ )
151
122
  context.metadata[:redirect_region] = actual_region
152
- Aws::Plugins::SignatureV4.apply_signature(
153
- context: context,
154
- signer: S3Signer.build_v4_signer(
155
- region: actual_region,
156
- credentials: context.config.credentials
157
- )
123
+
124
+ signer = Aws::Plugins::Sign.signer_for(
125
+ context[:auth_scheme],
126
+ context.config,
127
+ actual_region
158
128
  )
129
+
130
+ signer.sign(context)
159
131
  end
160
132
 
161
133
  def region_from_body(body)
162
134
  region = body.match(/<Region>(.+?)<\/Region>/)[1]
163
- if region.nil? || region == ""
135
+ if region.nil? || region == ''
164
136
  raise "couldn't get region from body: #{body}"
165
137
  else
166
138
  region
@@ -168,44 +140,36 @@ module Aws
168
140
  end
169
141
 
170
142
  def log_warning(context, actual_region)
171
- msg = "S3 client configured for #{context.config.region.inspect} " +
172
- "but the bucket #{context.params[:bucket].inspect} is in " +
173
- "#{actual_region.inspect}; Please configure the proper region " +
174
- "to avoid multiple unnecessary redirects and signing attempts\n"
175
- if logger = context.config.logger
143
+ msg = "S3 client configured for #{context.config.region.inspect} " \
144
+ "but the bucket #{context.params[:bucket].inspect} is in " \
145
+ "#{actual_region.inspect}; Please configure the proper region " \
146
+ "to avoid multiple unnecessary redirects and signing attempts\n"
147
+ if (logger = context.config.logger)
176
148
  logger.warn(msg)
177
149
  else
178
150
  warn(msg)
179
151
  end
180
152
  end
181
-
182
153
  end
183
154
 
184
155
  class << self
185
-
186
- # @option options [required, String] :region
187
- # @option options [required, #credentials] :credentials
188
- # @api private
189
- def build_v4_signer(options = {})
190
- Aws::Sigv4::Signer.new({
191
- service: 's3',
192
- region: options[:region],
193
- credentials_provider: options[:credentials],
194
- uri_escape_path: false,
195
- unsigned_headers: ['content-length', 'x-amzn-trace-id'],
196
- })
197
- end
198
-
199
156
  def new_hostname(context, region)
200
- bucket = context.params[:bucket]
201
- if region == 'us-east-1'
202
- "#{bucket}.s3.amazonaws.com"
203
- else
204
- endpoint = Aws::Partitions::EndpointProvider.resolve(region, 's3')
205
- bucket + '.' + URI.parse(endpoint).host
206
- end
157
+ endpoint_params = context[:endpoint_params].dup
158
+ endpoint_params.region = region
159
+ endpoint_params.endpoint = nil
160
+ endpoint =
161
+ context.config.endpoint_provider.resolve_endpoint(endpoint_params)
162
+ URI(endpoint.url).host
207
163
  end
208
164
 
165
+ def custom_endpoint?(context)
166
+ region = context.config.region
167
+ partition = Aws::Endpoints::Matchers.aws_partition(region)
168
+ endpoint = context.http_request.endpoint
169
+
170
+ !endpoint.hostname.include?(partition['dnsSuffix']) &&
171
+ !endpoint.hostname.include?(partition['dualStackDnsSuffix'])
172
+ end
209
173
  end
210
174
  end
211
175
  end
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Aws
4
+ module S3
5
+ module Plugins
6
+
7
+ # S3 GetObject results for whole Multipart Objects contain a checksum
8
+ # that cannot be validated. These should be skipped by the
9
+ # ChecksumAlgorithm plugin.
10
+ class SkipWholeMultipartGetChecksums < Seahorse::Client::Plugin
11
+
12
+ class Handler < Seahorse::Client::Handler
13
+
14
+ def call(context)
15
+ context[:http_checksum] ||= {}
16
+ context[:http_checksum][:skip_on_suffix] = true
17
+
18
+ @handler.call(context)
19
+ end
20
+
21
+ end
22
+
23
+ handler(
24
+ Handler,
25
+ step: :initialize,
26
+ operations: [:get_object]
27
+ )
28
+ end
29
+ end
30
+ end
31
+ end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'uri'
2
4
  require 'openssl'
3
5
 
@@ -18,7 +20,7 @@ This should only be disabled for local testing.
18
20
  class Handler < Seahorse::Client::Handler
19
21
 
20
22
  def call(context)
21
- compute_key_md5(context)
23
+ compute_key_md5(context) if context.params.is_a?(Hash)
22
24
  @handler.call(context)
23
25
  end
24
26