aws-sdk-core 3.117.0 → 3.197.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (163) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +836 -0
  3. data/VERSION +1 -1
  4. data/lib/aws-defaults/default_configuration.rb +153 -0
  5. data/lib/aws-defaults/defaults_mode_config_resolver.rb +107 -0
  6. data/lib/aws-defaults.rb +3 -0
  7. data/lib/aws-sdk-core/arn.rb +13 -0
  8. data/lib/aws-sdk-core/assume_role_credentials.rb +21 -7
  9. data/lib/aws-sdk-core/assume_role_web_identity_credentials.rb +14 -10
  10. data/lib/aws-sdk-core/binary/decode_handler.rb +0 -5
  11. data/lib/aws-sdk-core/binary/encode_handler.rb +12 -1
  12. data/lib/aws-sdk-core/binary/event_builder.rb +34 -37
  13. data/lib/aws-sdk-core/client_stubs.rb +20 -13
  14. data/lib/aws-sdk-core/credential_provider.rb +4 -1
  15. data/lib/aws-sdk-core/credential_provider_chain.rb +8 -5
  16. data/lib/aws-sdk-core/ec2_metadata.rb +4 -3
  17. data/lib/aws-sdk-core/ecs_credentials.rb +187 -52
  18. data/lib/aws-sdk-core/endpoints/condition.rb +41 -0
  19. data/lib/aws-sdk-core/endpoints/endpoint.rb +17 -0
  20. data/lib/aws-sdk-core/endpoints/endpoint_rule.rb +75 -0
  21. data/lib/aws-sdk-core/endpoints/error_rule.rb +42 -0
  22. data/lib/aws-sdk-core/endpoints/function.rb +80 -0
  23. data/lib/aws-sdk-core/endpoints/matchers.rb +135 -0
  24. data/lib/aws-sdk-core/endpoints/reference.rb +31 -0
  25. data/lib/aws-sdk-core/endpoints/rule.rb +25 -0
  26. data/lib/aws-sdk-core/endpoints/rule_set.rb +52 -0
  27. data/lib/aws-sdk-core/endpoints/rules_provider.rb +37 -0
  28. data/lib/aws-sdk-core/endpoints/templater.rb +58 -0
  29. data/lib/aws-sdk-core/endpoints/tree_rule.rb +45 -0
  30. data/lib/aws-sdk-core/endpoints/url.rb +60 -0
  31. data/lib/aws-sdk-core/endpoints.rb +78 -0
  32. data/lib/aws-sdk-core/errors.rb +17 -4
  33. data/lib/aws-sdk-core/event_emitter.rb +0 -16
  34. data/lib/aws-sdk-core/ini_parser.rb +7 -0
  35. data/lib/aws-sdk-core/instance_profile_credentials.rb +127 -33
  36. data/lib/aws-sdk-core/json/builder.rb +8 -1
  37. data/lib/aws-sdk-core/json/error_handler.rb +30 -4
  38. data/lib/aws-sdk-core/json/handler.rb +8 -1
  39. data/lib/aws-sdk-core/json/json_engine.rb +10 -8
  40. data/lib/aws-sdk-core/json/oj_engine.rb +33 -6
  41. data/lib/aws-sdk-core/json/parser.rb +38 -2
  42. data/lib/aws-sdk-core/json.rb +8 -26
  43. data/lib/aws-sdk-core/log/formatter.rb +6 -0
  44. data/lib/aws-sdk-core/log/param_filter.rb +9 -1
  45. data/lib/aws-sdk-core/lru_cache.rb +75 -0
  46. data/lib/aws-sdk-core/pageable_response.rb +81 -32
  47. data/lib/aws-sdk-core/param_validator.rb +36 -2
  48. data/lib/aws-sdk-core/plugins/bearer_authorization.rb +67 -0
  49. data/lib/aws-sdk-core/plugins/checksum_algorithm.rb +342 -0
  50. data/lib/aws-sdk-core/plugins/client_metrics_plugin.rb +1 -0
  51. data/lib/aws-sdk-core/plugins/client_metrics_send_plugin.rb +14 -2
  52. data/lib/aws-sdk-core/plugins/credentials_configuration.rb +29 -1
  53. data/lib/aws-sdk-core/plugins/defaults_mode.rb +40 -0
  54. data/lib/aws-sdk-core/plugins/endpoint_discovery.rb +6 -2
  55. data/lib/aws-sdk-core/plugins/http_checksum.rb +9 -1
  56. data/lib/aws-sdk-core/plugins/invocation_id.rb +1 -11
  57. data/lib/aws-sdk-core/plugins/jsonvalue_converter.rb +34 -6
  58. data/lib/aws-sdk-core/plugins/logging.rb +2 -0
  59. data/lib/aws-sdk-core/plugins/protocols/api_gateway.rb +17 -0
  60. data/lib/aws-sdk-core/plugins/protocols/rest_json.rb +4 -2
  61. data/lib/aws-sdk-core/plugins/protocols/rest_xml.rb +1 -2
  62. data/lib/aws-sdk-core/plugins/recursion_detection.rb +38 -0
  63. data/lib/aws-sdk-core/plugins/regional_endpoint.rb +144 -17
  64. data/lib/aws-sdk-core/plugins/request_compression.rb +226 -0
  65. data/lib/aws-sdk-core/plugins/response_paging.rb +1 -1
  66. data/lib/aws-sdk-core/plugins/retries/error_inspector.rb +7 -4
  67. data/lib/aws-sdk-core/plugins/retry_errors.rb +33 -7
  68. data/lib/aws-sdk-core/plugins/sign.rb +211 -0
  69. data/lib/aws-sdk-core/plugins/signature_v2.rb +1 -0
  70. data/lib/aws-sdk-core/plugins/signature_v4.rb +28 -31
  71. data/lib/aws-sdk-core/plugins/stub_responses.rb +6 -1
  72. data/lib/aws-sdk-core/plugins/user_agent.rb +152 -14
  73. data/lib/aws-sdk-core/process_credentials.rb +50 -34
  74. data/lib/aws-sdk-core/query/ec2_param_builder.rb +5 -7
  75. data/lib/aws-sdk-core/query/param_builder.rb +2 -2
  76. data/lib/aws-sdk-core/refreshing_credentials.rb +49 -18
  77. data/lib/aws-sdk-core/refreshing_token.rb +71 -0
  78. data/lib/aws-sdk-core/rest/handler.rb +1 -1
  79. data/lib/aws-sdk-core/rest/request/body.rb +49 -4
  80. data/lib/aws-sdk-core/rest/request/content_type.rb +60 -0
  81. data/lib/aws-sdk-core/rest/request/endpoint.rb +24 -4
  82. data/lib/aws-sdk-core/rest/request/headers.rb +23 -7
  83. data/lib/aws-sdk-core/rest/request/querystring_builder.rb +62 -36
  84. data/lib/aws-sdk-core/rest/response/body.rb +15 -1
  85. data/lib/aws-sdk-core/rest/response/header_list_parser.rb +79 -0
  86. data/lib/aws-sdk-core/rest/response/headers.rb +10 -3
  87. data/lib/aws-sdk-core/rest.rb +1 -0
  88. data/lib/aws-sdk-core/shared_config.rb +112 -12
  89. data/lib/aws-sdk-core/sso_credentials.rb +92 -51
  90. data/lib/aws-sdk-core/sso_token_provider.rb +135 -0
  91. data/lib/aws-sdk-core/static_token_provider.rb +14 -0
  92. data/lib/aws-sdk-core/structure.rb +16 -5
  93. data/lib/aws-sdk-core/stubbing/stub_data.rb +11 -0
  94. data/lib/aws-sdk-core/token.rb +31 -0
  95. data/lib/aws-sdk-core/token_provider.rb +15 -0
  96. data/lib/aws-sdk-core/token_provider_chain.rb +51 -0
  97. data/lib/aws-sdk-core/util.rb +39 -0
  98. data/lib/aws-sdk-core/waiters/poller.rb +4 -2
  99. data/lib/aws-sdk-core/xml/builder.rb +17 -9
  100. data/lib/aws-sdk-core/xml/error_handler.rb +31 -8
  101. data/lib/aws-sdk-core/xml/parser/engines/oga.rb +2 -0
  102. data/lib/aws-sdk-core/xml/parser/engines/ox.rb +1 -1
  103. data/lib/aws-sdk-core/xml/parser/engines/rexml.rb +0 -8
  104. data/lib/aws-sdk-core/xml/parser/frame.rb +27 -20
  105. data/lib/aws-sdk-core/xml/parser/stack.rb +2 -0
  106. data/lib/aws-sdk-core.rb +21 -0
  107. data/lib/aws-sdk-sso/client.rb +157 -50
  108. data/lib/aws-sdk-sso/endpoint_parameters.rb +66 -0
  109. data/lib/aws-sdk-sso/endpoint_provider.rb +57 -0
  110. data/lib/aws-sdk-sso/endpoints.rb +72 -0
  111. data/lib/aws-sdk-sso/plugins/endpoints.rb +78 -0
  112. data/lib/aws-sdk-sso/types.rb +8 -43
  113. data/lib/aws-sdk-sso.rb +5 -1
  114. data/lib/aws-sdk-ssooidc/client.rb +1008 -0
  115. data/lib/aws-sdk-ssooidc/client_api.rb +293 -0
  116. data/lib/aws-sdk-ssooidc/customizations.rb +1 -0
  117. data/lib/aws-sdk-ssooidc/endpoint_parameters.rb +66 -0
  118. data/lib/aws-sdk-ssooidc/endpoint_provider.rb +57 -0
  119. data/lib/aws-sdk-ssooidc/endpoints.rb +72 -0
  120. data/lib/aws-sdk-ssooidc/errors.rb +342 -0
  121. data/lib/aws-sdk-ssooidc/plugins/endpoints.rb +78 -0
  122. data/lib/aws-sdk-ssooidc/resource.rb +26 -0
  123. data/lib/aws-sdk-ssooidc/types.rb +823 -0
  124. data/lib/aws-sdk-ssooidc.rb +59 -0
  125. data/lib/aws-sdk-sts/client.rb +472 -398
  126. data/lib/aws-sdk-sts/client_api.rb +20 -9
  127. data/lib/aws-sdk-sts/endpoint_parameters.rb +78 -0
  128. data/lib/aws-sdk-sts/endpoint_provider.rb +112 -0
  129. data/lib/aws-sdk-sts/endpoints.rb +136 -0
  130. data/lib/aws-sdk-sts/plugins/endpoints.rb +86 -0
  131. data/lib/aws-sdk-sts/plugins/sts_regional_endpoints.rb +5 -1
  132. data/lib/aws-sdk-sts/presigner.rb +14 -10
  133. data/lib/aws-sdk-sts/types.rb +168 -227
  134. data/lib/aws-sdk-sts.rb +5 -1
  135. data/lib/seahorse/client/async_base.rb +1 -2
  136. data/lib/seahorse/client/async_response.rb +19 -0
  137. data/lib/seahorse/client/base.rb +1 -0
  138. data/lib/seahorse/client/configuration.rb +5 -5
  139. data/lib/seahorse/client/h2/connection.rb +15 -16
  140. data/lib/seahorse/client/h2/handler.rb +5 -5
  141. data/lib/seahorse/client/net_http/connection_pool.rb +10 -9
  142. data/lib/seahorse/client/net_http/handler.rb +15 -7
  143. data/lib/seahorse/client/net_http/patches.rb +12 -86
  144. data/lib/seahorse/client/plugin.rb +9 -0
  145. data/lib/seahorse/client/plugins/content_length.rb +11 -5
  146. data/lib/seahorse/client/plugins/h2.rb +3 -3
  147. data/lib/seahorse/client/plugins/net_http.rb +73 -10
  148. data/lib/seahorse/client/plugins/request_callback.rb +40 -9
  149. data/lib/seahorse/client/response.rb +6 -0
  150. data/lib/seahorse/model/operation.rb +6 -0
  151. data/lib/seahorse/model/shapes.rb +27 -2
  152. data/lib/seahorse/util.rb +4 -0
  153. data/sig/aws-sdk-core/client_stubs.rbs +10 -0
  154. data/sig/aws-sdk-core/errors.rbs +22 -0
  155. data/sig/aws-sdk-core/resources/collection.rbs +21 -0
  156. data/sig/aws-sdk-core/structure.rbs +4 -0
  157. data/sig/aws-sdk-core/waiters/errors.rbs +20 -0
  158. data/sig/aws-sdk-core.rbs +7 -0
  159. data/sig/seahorse/client/base.rbs +25 -0
  160. data/sig/seahorse/client/handler_builder.rbs +16 -0
  161. data/sig/seahorse/client/response.rbs +61 -0
  162. metadata +82 -17
  163. data/lib/aws-sdk-sso/plugins/content_type.rb +0 -25
data/lib/aws-sdk-sts.rb CHANGED
@@ -15,9 +15,13 @@ end
15
15
 
16
16
  require_relative 'aws-sdk-sts/types'
17
17
  require_relative 'aws-sdk-sts/client_api'
18
+ require_relative 'aws-sdk-sts/plugins/endpoints.rb'
18
19
  require_relative 'aws-sdk-sts/client'
19
20
  require_relative 'aws-sdk-sts/errors'
20
21
  require_relative 'aws-sdk-sts/resource'
22
+ require_relative 'aws-sdk-sts/endpoint_parameters'
23
+ require_relative 'aws-sdk-sts/endpoint_provider'
24
+ require_relative 'aws-sdk-sts/endpoints'
21
25
  require_relative 'aws-sdk-sts/customizations'
22
26
 
23
27
  # This module provides support for AWS Security Token Service. This module is available in the
@@ -50,6 +54,6 @@ require_relative 'aws-sdk-sts/customizations'
50
54
  # @!group service
51
55
  module Aws::STS
52
56
 
53
- GEM_VERSION = '3.117.0'
57
+ GEM_VERSION = '3.197.2'
54
58
 
55
59
  end
@@ -5,12 +5,12 @@ module Seahorse
5
5
  class AsyncBase < Seahorse::Client::Base
6
6
 
7
7
  # default H2 plugins
8
+ # @api private
8
9
  @plugins = PluginList.new([
9
10
  Plugins::Endpoint,
10
11
  Plugins::H2,
11
12
  Plugins::ResponseTarget
12
13
  ])
13
-
14
14
  def initialize(plugins, options)
15
15
  super
16
16
  @connection = H2::Connection.new(options)
@@ -49,4 +49,3 @@ module Seahorse
49
49
  end
50
50
  end
51
51
  end
52
-
@@ -12,24 +12,43 @@ module Seahorse
12
12
  @sync_queue = options[:sync_queue]
13
13
  end
14
14
 
15
+ # @return [RequestContext]
15
16
  def context
16
17
  @response.context
17
18
  end
18
19
 
20
+ # @return [StandardError, nil]
19
21
  def error
20
22
  @response.error
21
23
  end
22
24
 
25
+ # @overload on(status_code, &block)
26
+ # @param [Integer] status_code The block will be
27
+ # triggered only for responses with the given status code.
28
+ #
29
+ # @overload on(status_code_range, &block)
30
+ # @param [Range<Integer>] status_code_range The block will be
31
+ # triggered only for responses with a status code that falls
32
+ # witin the given range.
33
+ #
34
+ # @return [self]
23
35
  def on(range, &block)
24
36
  @response.on(range, &block)
25
37
  self
26
38
  end
27
39
 
40
+ # @api private
28
41
  def on_complete(&block)
29
42
  @response.on_complete(&block)
30
43
  self
31
44
  end
32
45
 
46
+ # @return [Boolean] Returns `true` if the response is complete with
47
+ # no error.
48
+ def successful?
49
+ @response.error.nil?
50
+ end
51
+
33
52
  def wait
34
53
  if error && context.config.raise_response_errors
35
54
  raise error
@@ -9,6 +9,7 @@ module Seahorse
9
9
  include HandlerBuilder
10
10
 
11
11
  # default plugins
12
+ # @api private
12
13
  @plugins = PluginList.new([
13
14
  Plugins::Endpoint,
14
15
  Plugins::NetHttp,
@@ -68,7 +68,7 @@ module Seahorse
68
68
  @block = block
69
69
  end
70
70
 
71
- def call(*args)
71
+ def call(*args)
72
72
  @block.call(*args)
73
73
  end
74
74
  end
@@ -195,15 +195,15 @@ module Seahorse
195
195
  @members.include?(method_name) or super
196
196
  end
197
197
 
198
+ def override_config(k, v)
199
+ @struct[k] = v
200
+ end
201
+
198
202
  private
199
203
 
200
204
  def value_at(opt_name)
201
205
  value = @struct[opt_name]
202
206
  if value.is_a?(Defaults)
203
- # this config value is used by endpoint discovery
204
- if opt_name == :endpoint && @struct.members.include?(:regional_endpoint)
205
- @struct[:regional_endpoint] = true
206
- end
207
207
  resolve_defaults(opt_name, value)
208
208
  else
209
209
  value
@@ -1,10 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- if RUBY_VERSION >= '2.1'
4
- begin
5
- require 'http/2'
6
- rescue LoadError; end
7
- end
3
+ begin
4
+ require 'http/2'
5
+ rescue LoadError; end
8
6
  require 'openssl'
9
7
  require 'socket'
10
8
 
@@ -45,7 +43,9 @@ module Seahorse
45
43
  @h2_client = HTTP2::Client.new(
46
44
  settings_max_concurrent_streams: max_concurrent_streams
47
45
  )
48
- @logger = options[:logger] || Logger.new($stdout) if @http_wire_trace
46
+ @logger = if @http_wire_trace
47
+ options[:logger] || Logger.new($stdout)
48
+ end
49
49
  @chunk_size = options[:read_chunk_size] || CHUNKSIZE
50
50
  @errors = []
51
51
  @status = :ready
@@ -106,7 +106,7 @@ module Seahorse
106
106
  @mutex.synchronize {
107
107
  return if @socket_thread
108
108
  @socket_thread = Thread.new do
109
- while !@socket.closed?
109
+ while @socket && !@socket.closed?
110
110
  begin
111
111
  data = @socket.read_nonblock(@chunk_size)
112
112
  @h2_client << data
@@ -132,6 +132,7 @@ module Seahorse
132
132
  self.close!
133
133
  end
134
134
  end
135
+ @socket_thread = nil
135
136
  end
136
137
  @socket_thread.abort_on_exception = true
137
138
  }
@@ -144,10 +145,6 @@ module Seahorse
144
145
  @socket.close
145
146
  @socket = nil
146
147
  end
147
- if @socket_thread
148
- Thread.kill(@socket_thread)
149
- @socket_thread = nil
150
- end
151
148
  @status = :closed
152
149
  }
153
150
  end
@@ -185,11 +182,13 @@ module Seahorse
185
182
  @socket.flush
186
183
  end
187
184
  end
188
- @h2_client.on(:frame_sent) do |frame|
189
- debug_output("frame: #{frame.inspect}", :send)
190
- end
191
- @h2_client.on(:frame_received) do |frame|
192
- debug_output("frame: #{frame.inspect}", :receive)
185
+ if @http_wire_trace
186
+ @h2_client.on(:frame_sent) do |frame|
187
+ debug_output("frame: #{frame.inspect}", :send)
188
+ end
189
+ @h2_client.on(:frame_received) do |frame|
190
+ debug_output("frame: #{frame.inspect}", :receive)
191
+ end
193
192
  end
194
193
  end
195
194
 
@@ -1,10 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- if RUBY_VERSION >= '2.1'
4
- begin
5
- require 'http/2'
6
- rescue LoadError; end
7
- end
3
+ begin
4
+ require 'http/2'
5
+ rescue LoadError; end
6
+
8
7
  require 'securerandom'
9
8
 
10
9
  module Seahorse
@@ -127,6 +126,7 @@ module Seahorse
127
126
  # https://http2.github.io/http2-spec/#rfc.section.8.1.2.3
128
127
  def _h2_headers(req)
129
128
  headers = {}
129
+ headers[':authority'] = req.endpoint.host
130
130
  headers[':method'] = req.http_method.upcase
131
131
  headers[':scheme'] = req.endpoint.scheme
132
132
  headers[':path'] = req.endpoint.path.empty? ? '/' : req.endpoint.path
@@ -34,6 +34,7 @@ module Seahorse
34
34
  ssl_ca_bundle: nil,
35
35
  ssl_ca_directory: nil,
36
36
  ssl_ca_store: nil,
37
+ ssl_timeout: nil
37
38
  }
38
39
 
39
40
  # @api private
@@ -118,11 +119,7 @@ module Seahorse
118
119
  # pool, not counting those currently in use.
119
120
  def size
120
121
  @pool_mutex.synchronize do
121
- size = 0
122
- @pool.each_pair do |endpoint,sessions|
123
- size += sessions.size
124
- end
125
- size
122
+ @pool.values.flatten.size
126
123
  end
127
124
  end
128
125
 
@@ -141,9 +138,7 @@ module Seahorse
141
138
  # @return [nil]
142
139
  def empty!
143
140
  @pool_mutex.synchronize do
144
- @pool.each_pair do |endpoint,sessions|
145
- sessions.each(&:finish)
146
- end
141
+ @pool.values.flatten.map(&:finish)
147
142
  @pool.clear
148
143
  end
149
144
  nil
@@ -187,6 +182,9 @@ module Seahorse
187
182
  # disables this behaviour. This value can safely be set per
188
183
  # request on the session yielded by {#session_for}.
189
184
  #
185
+ # @option options [Float] :ssl_timeout (nil) Sets the SSL timeout
186
+ # in seconds.
187
+ #
190
188
  # @option options [Boolean] :http_wire_trace (false) When `true`,
191
189
  # HTTP debug output will be sent to the `:logger`.
192
190
  #
@@ -248,6 +246,7 @@ module Seahorse
248
246
  :ssl_ca_bundle => options[:ssl_ca_bundle],
249
247
  :ssl_ca_directory => options[:ssl_ca_directory],
250
248
  :ssl_ca_store => options[:ssl_ca_store],
249
+ :ssl_timeout => options[:ssl_timeout]
251
250
  }
252
251
  end
253
252
 
@@ -285,6 +284,8 @@ module Seahorse
285
284
 
286
285
  if endpoint.scheme == 'https'
287
286
  http.use_ssl = true
287
+ http.ssl_timeout = ssl_timeout
288
+
288
289
  if ssl_verify_peer?
289
290
  http.verify_mode = OpenSSL::SSL::VERIFY_PEER
290
291
  http.ca_file = ssl_ca_bundle if ssl_ca_bundle
@@ -305,7 +306,7 @@ module Seahorse
305
306
  # @note **Must** be called behind a `@pool_mutex` synchronize block.
306
307
  def _clean
307
308
  now = Aws::Util.monotonic_milliseconds
308
- @pool.each_pair do |endpoint,sessions|
309
+ @pool.values.each do |sessions|
309
310
  sessions.delete_if do |session|
310
311
  if session.last_used.nil? or now - session.last_used > http_idle_timeout * 1000
311
312
  session.finish
@@ -74,8 +74,9 @@ module Seahorse
74
74
  # @return [void]
75
75
  def transmit(config, req, resp)
76
76
  session(config, req) do |http|
77
+ # Monkey patch default content-type set by Net::HTTP
78
+ Thread.current[:net_http_skip_default_content_type] = true
77
79
  http.request(build_net_request(req)) do |net_resp|
78
-
79
80
  status_code = net_resp.code.to_i
80
81
  headers = extract_headers(net_resp)
81
82
 
@@ -96,6 +97,9 @@ module Seahorse
96
97
  rescue => error
97
98
  # not retryable
98
99
  resp.signal_error(error)
100
+ ensure
101
+ # ensure we turn off monkey patch in case of error
102
+ Thread.current[:net_http_skip_default_content_type] = nil
99
103
  end
100
104
 
101
105
  def complete_response(req, resp, bytes_received)
@@ -147,7 +151,12 @@ module Seahorse
147
151
  def build_net_request(request)
148
152
  request_class = net_http_request_class(request)
149
153
  req = request_class.new(request.endpoint.request_uri, headers(request))
150
- req.body_stream = request.body
154
+ # Net::HTTP adds a default Content-Type when a body is present.
155
+ # Set the body stream when it has an unknown size or when it is > 0.
156
+ if !request.body.respond_to?(:size) ||
157
+ (request.body.respond_to?(:size) && request.body.size > 0)
158
+ req.body_stream = request.body
159
+ end
151
160
  req
152
161
  end
153
162
 
@@ -166,14 +175,13 @@ module Seahorse
166
175
  # @return [Hash] Returns a vanilla hash of headers to send with the
167
176
  # HTTP request.
168
177
  def headers(request)
169
- # Net::HTTP adds default headers for content-type to POSTs (1.8.7+)
170
- # and accept-encoding (2.0.0+). Setting a default empty value defeats
171
- # this.
178
+ # Net::HTTP adds a default header for accept-encoding (2.0.0+).
179
+ # Setting a default empty value defeats this.
172
180
  #
173
- # Removing these are necessary for most services to not break request
181
+ # Removing this is necessary for most services to not break request
174
182
  # signatures as well as dynamodb crc32 checks (these fail if the
175
183
  # response is gzipped).
176
- headers = { 'content-type' => '', 'accept-encoding' => '' }
184
+ headers = { 'accept-encoding' => '' }
177
185
  request.headers.each_pair do |key, value|
178
186
  headers[key] = value
179
187
  end
@@ -11,97 +11,23 @@ module Seahorse
11
11
  module Patches
12
12
 
13
13
  def self.apply!
14
- return unless RUBY_VERSION < '2.5'
15
- if RUBY_VERSION >= '2.3'
16
- Net::HTTP::IDEMPOTENT_METHODS_.clear
17
- return
18
- end
19
- # no further patches needed for above versions
20
-
21
- if RUBY_VERSION >= '2.0'
22
- Net::HTTP.send(:include, Ruby_2)
23
- Net::HTTP::IDEMPOTENT_METHODS_.clear
24
- elsif RUBY_VERSION >= '1.9.3'
25
- Net::HTTP.send(:include, Ruby_1_9_3)
26
- end
27
- Net::HTTP.send(:alias_method, :old_transport_request, :transport_request)
28
- Net::HTTP.send(:alias_method, :transport_request, :new_transport_request)
14
+ Net::HTTPGenericRequest.prepend(PatchDefaultContentType)
29
15
  end
30
16
 
31
- module Ruby_2
32
- def new_transport_request(req)
33
- count = 0
34
- begin
35
- begin_transport req
36
- res = catch(:response) {
37
- req.exec @socket, @curr_http_version, edit_path(req.path)
38
- begin
39
- res = Net::HTTPResponse.read_new(@socket)
40
- res.decode_content = req.decode_content
41
- end while res.kind_of?(Net::HTTPInformation)
42
-
43
- res.uri = req.uri
44
-
45
- res
46
- }
47
- res.reading_body(@socket, req.response_body_permitted?) {
48
- yield res if block_given?
49
- }
50
- rescue Net::OpenTimeout
51
- raise
52
- rescue Net::ReadTimeout, IOError, EOFError,
53
- Errno::ECONNRESET, Errno::ECONNABORTED, Errno::EPIPE,
54
- # avoid a dependency on OpenSSL
55
- defined?(OpenSSL::SSL) ? OpenSSL::SSL::SSLError : IOError,
56
- Timeout::Error => exception
57
- if count == 0 && Net::HTTP::IDEMPOTENT_METHODS_.include?(req.method)
58
- count += 1
59
- @socket.close if @socket and not @socket.closed?
60
- D "Conn close because of error #{exception}, and retry"
61
- if req.body_stream
62
- if req.body_stream.respond_to?(:rewind)
63
- req.body_stream.rewind
64
- else
65
- raise
66
- end
67
- end
68
- retry
69
- end
70
- D "Conn close because of error #{exception}"
71
- @socket.close if @socket and not @socket.closed?
72
- raise
73
- end
74
-
75
- end_transport req, res
76
- res
77
- rescue => exception
78
- D "Conn close because of error #{exception}"
79
- @socket.close if @socket and not @socket.closed?
80
- raise exception
17
+ # For requests with bodies, Net::HTTP sets a default content type of:
18
+ # 'application/x-www-form-urlencoded'
19
+ # There are cases where we should not send content type at all.
20
+ # Even when no body is supplied, Net::HTTP uses a default empty body
21
+ # and sets it anyway. This patch disables the behavior when a Thread
22
+ # local variable is set.
23
+ module PatchDefaultContentType
24
+ def supply_default_content_type
25
+ return if Thread.current[:net_http_skip_default_content_type]
26
+
27
+ super
81
28
  end
82
29
  end
83
30
 
84
- module Ruby_1_9_3
85
- def new_transport_request(req)
86
- begin_transport req
87
- res = catch(:response) {
88
- req.exec @socket, @curr_http_version, edit_path(req.path)
89
- begin
90
- res = Net::HTTPResponse.read_new(@socket)
91
- end while res.kind_of?(Net::HTTPContinue)
92
- res
93
- }
94
- res.reading_body(@socket, req.response_body_permitted?) {
95
- yield res if block_given?
96
- }
97
- end_transport req, res
98
- res
99
- rescue => exception
100
- D "Conn close because of error #{exception}"
101
- @socket.close if @socket and not @socket.closed?
102
- raise exception
103
- end
104
- end
105
31
  end
106
32
  end
107
33
  end
@@ -111,7 +111,15 @@ module Seahorse
111
111
 
112
112
  def initialize(name, options = {})
113
113
  @name = name
114
+ # prevent unstable object shapes by ensuring
115
+ # order and presence of instance variables
116
+ @default = nil
117
+ @default_block = nil
118
+ @required = nil
119
+ @doc_type = nil
114
120
  @doc_default = nil
121
+ @docstring = nil
122
+ @rbs_type = nil
115
123
  options.each_pair do |opt_name, opt_value|
116
124
  self.send("#{opt_name}=", opt_value)
117
125
  end
@@ -124,6 +132,7 @@ module Seahorse
124
132
  attr_accessor :doc_type
125
133
  attr_writer :doc_default
126
134
  attr_accessor :docstring
135
+ attr_accessor :rbs_type
127
136
 
128
137
  def doc_default(options)
129
138
  if @doc_default.nil? && !default.is_a?(Proc)
@@ -7,16 +7,22 @@ module Seahorse
7
7
 
8
8
  # @api private
9
9
  class Handler < Client::Handler
10
+ # https://github.com/ruby/net-http/blob/master/lib/net/http/requests.rb
11
+ # Methods without body are forwards compatible, because content-length
12
+ # may be set for requests without body but is technically incorrect.
13
+ METHODS_WITHOUT_BODY = Set.new(
14
+ %w[GET HEAD DELETE OPTIONS TRACE COPY MOVE]
15
+ )
10
16
 
11
17
  def call(context)
12
- # If it's an IO object and not a File / String / String IO
13
- if context.http_request.body.respond_to?(:size)
14
- length = context.http_request.body.size
15
- context.http_request.headers['Content-Length'] = length
18
+ body = context.http_request.body
19
+ method = context.http_request.http_method
20
+ # We use Net::HTTP with body_stream which doesn't do this by default
21
+ if body.respond_to?(:size) && !METHODS_WITHOUT_BODY.include?(method)
22
+ context.http_request.headers['Content-Length'] = body.size
16
23
  end
17
24
  @handler.call(context)
18
25
  end
19
-
20
26
  end
21
27
 
22
28
  handler(Handler, step: :sign, priority: 0)
@@ -54,9 +54,9 @@ When `true`, HTTP2 debug output will be sent to the `:logger`.
54
54
  DOCS
55
55
 
56
56
  option(:enable_alpn, default: false, doc_type: 'Boolean', docstring: <<-DOCS)
57
- Setting to `true` to enable ALPN in HTTP2 over TLS, requires Ruby version >= 2.3 and
58
- Openssl version >= 1.0.2. Defaults to false. Note: not all service HTTP2 operations
59
- supports ALPN on server side, please refer to service documentation.
57
+ Set to `true` to enable ALPN in HTTP2 over TLS. Requires Openssl version >= 1.0.2.
58
+ Defaults to false. Note: not all service HTTP2 operations supports ALPN on server
59
+ side, please refer to service documentation.
60
60
  DOCS
61
61
 
62
62
  option(:logger)
@@ -7,33 +7,96 @@ module Seahorse
7
7
  module Plugins
8
8
  class NetHttp < Plugin
9
9
 
10
- option(:http_proxy, default: nil, doc_type: String, docstring: '')
10
+ option(:http_proxy, default: nil, doc_type: "URI::HTTP,String", docstring: <<-DOCS)
11
+ A proxy to send requests through. Formatted like 'http://proxy.com:123'.
12
+ DOCS
11
13
 
12
- option(:http_open_timeout, default: 15, doc_type: Integer, docstring: '')
14
+ option(:http_open_timeout, default: 15, doc_type: Float, docstring: <<-DOCS) do |cfg|
15
+ The default number of seconds to wait for response data.
16
+ This value can safely be set per-request on the session.
17
+ DOCS
18
+ resolve_http_open_timeout(cfg)
19
+ end
13
20
 
14
- option(:http_read_timeout, default: 60, doc_type: Integer, docstring: '')
21
+ option(:http_read_timeout, default: 60, doc_type: Float, docstring: <<-DOCS) do |cfg|
22
+ The default number of seconds to wait for response data.
23
+ This value can safely be set per-request on the session.
24
+ DOCS
25
+ resolve_http_read_timeout(cfg)
26
+ end
15
27
 
16
- option(:http_idle_timeout, default: 5, doc_type: Integer, docstring: '')
28
+ option(:http_idle_timeout, default: 5, doc_type: Float, docstring: <<-DOCS)
29
+ The number of seconds a connection is allowed to sit idle before it
30
+ is considered stale. Stale connections are closed and removed from the
31
+ pool before making a request.
32
+ DOCS
17
33
 
18
- option(:http_continue_timeout, default: 1, doc_type: Integer, docstring: '')
34
+ option(:http_continue_timeout, default: 1, doc_type: Float, docstring: <<-DOCS)
35
+ The number of seconds to wait for a 100-continue response before sending the
36
+ request body. This option has no effect unless the request has "Expect"
37
+ header set to "100-continue". Defaults to `nil` which disables this
38
+ behaviour. This value can safely be set per request on the session.
39
+ DOCS
19
40
 
20
- option(:http_wire_trace, default: false, doc_type: 'Boolean', docstring: '')
41
+ option(:http_wire_trace, default: false, doc_type: 'Boolean', docstring: <<-DOCS)
42
+ When `true`, HTTP debug output will be sent to the `:logger`.
43
+ DOCS
21
44
 
22
- option(:ssl_verify_peer, default: true, doc_type: 'Boolean', docstring: '')
45
+ option(:ssl_verify_peer, default: true, doc_type: 'Boolean', docstring: <<-DOCS)
46
+ When `true`, SSL peer certificates are verified when establishing a connection.
47
+ DOCS
23
48
 
24
- option(:ssl_ca_bundle, doc_type: String, docstring: '') do |cfg|
49
+ option(:ssl_ca_bundle, doc_type: String, docstring: <<-DOCS) do |cfg|
50
+ Full path to the SSL certificate authority bundle file that should be used when
51
+ verifying peer certificates. If you do not pass `:ssl_ca_bundle` or
52
+ `:ssl_ca_directory` the the system default will be used if available.
53
+ DOCS
25
54
  ENV['AWS_CA_BUNDLE'] ||
26
55
  Aws.shared_config.ca_bundle(profile: cfg.profile) if cfg.respond_to?(:profile)
27
56
  end
28
57
 
29
- option(:ssl_ca_directory, default: nil, doc_type: String, docstring: '')
58
+ option(:ssl_ca_directory, default: nil, doc_type: String, docstring: <<-DOCS)
59
+ Full path of the directory that contains the unbundled SSL certificate
60
+ authority files for verifying peer certificates. If you do
61
+ not pass `:ssl_ca_bundle` or `:ssl_ca_directory` the the system
62
+ default will be used if available.
63
+ DOCS
30
64
 
31
- option(:ssl_ca_store, default: nil, doc_type: String, docstring: '')
65
+ option(:ssl_ca_store, default: nil, doc_type: String, docstring: <<-DOCS)
66
+ Sets the X509::Store to verify peer certificate.
67
+ DOCS
68
+
69
+ option(:ssl_timeout, default: nil, doc_type: Float, docstring: 'Sets the SSL timeout in seconds') do |cfg|
70
+ resolve_ssl_timeout(cfg)
71
+ end
32
72
 
33
73
  option(:logger) # for backwards compat
34
74
 
35
75
  handler(Client::NetHttp::Handler, step: :send)
36
76
 
77
+ def self.resolve_http_open_timeout(cfg)
78
+ default_mode_value =
79
+ if cfg.respond_to?(:defaults_mode_config_resolver)
80
+ cfg.defaults_mode_config_resolver.resolve(:http_open_timeout)
81
+ end
82
+ default_mode_value || 15
83
+ end
84
+
85
+ def self.resolve_http_read_timeout(cfg)
86
+ default_mode_value =
87
+ if cfg.respond_to?(:defaults_mode_config_resolver)
88
+ cfg.defaults_mode_config_resolver.resolve(:http_read_timeout)
89
+ end
90
+ default_mode_value || 60
91
+ end
92
+
93
+ def self.resolve_ssl_timeout(cfg)
94
+ default_mode_value =
95
+ if cfg.respond_to?(:defaults_mode_config_resolver)
96
+ cfg.defaults_mode_config_resolver.resolve(:ssl_timeout)
97
+ end
98
+ default_mode_value || nil
99
+ end
37
100
  end
38
101
  end
39
102
  end