aws-sdk-core 3.46.2 → 3.126.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (206) hide show
  1. checksums.yaml +5 -5
  2. data/CHANGELOG.md +1258 -0
  3. data/LICENSE.txt +202 -0
  4. data/VERSION +1 -1
  5. data/lib/aws-defaults/default_configuration.rb +153 -0
  6. data/lib/aws-defaults/defaults_mode_config_resolver.rb +107 -0
  7. data/lib/aws-defaults.rb +3 -0
  8. data/lib/aws-sdk-core/arn.rb +92 -0
  9. data/lib/aws-sdk-core/arn_parser.rb +40 -0
  10. data/lib/aws-sdk-core/assume_role_credentials.rb +20 -0
  11. data/lib/aws-sdk-core/assume_role_web_identity_credentials.rb +109 -0
  12. data/lib/aws-sdk-core/async_client_stubs.rb +82 -0
  13. data/lib/aws-sdk-core/binary/decode_handler.rb +11 -1
  14. data/lib/aws-sdk-core/binary/encode_handler.rb +34 -0
  15. data/lib/aws-sdk-core/binary/event_builder.rb +124 -0
  16. data/lib/aws-sdk-core/binary/event_parser.rb +50 -18
  17. data/lib/aws-sdk-core/binary/event_stream_decoder.rb +7 -2
  18. data/lib/aws-sdk-core/binary/event_stream_encoder.rb +55 -0
  19. data/lib/aws-sdk-core/binary.rb +5 -0
  20. data/lib/aws-sdk-core/client_side_monitoring/publisher.rb +11 -1
  21. data/lib/aws-sdk-core/client_side_monitoring/request_metrics.rb +2 -0
  22. data/lib/aws-sdk-core/client_stubs.rb +16 -13
  23. data/lib/aws-sdk-core/credential_provider.rb +1 -30
  24. data/lib/aws-sdk-core/credential_provider_chain.rb +102 -40
  25. data/lib/aws-sdk-core/credentials.rb +2 -0
  26. data/lib/aws-sdk-core/deprecations.rb +17 -11
  27. data/lib/aws-sdk-core/eager_loader.rb +2 -0
  28. data/lib/aws-sdk-core/ec2_metadata.rb +238 -0
  29. data/lib/aws-sdk-core/ecs_credentials.rb +18 -9
  30. data/lib/aws-sdk-core/endpoint_cache.rb +16 -11
  31. data/lib/aws-sdk-core/errors.rb +138 -15
  32. data/lib/aws-sdk-core/event_emitter.rb +44 -0
  33. data/lib/aws-sdk-core/ini_parser.rb +2 -0
  34. data/lib/aws-sdk-core/instance_profile_credentials.rb +179 -42
  35. data/lib/aws-sdk-core/json/builder.rb +2 -0
  36. data/lib/aws-sdk-core/json/error_handler.rb +21 -2
  37. data/lib/aws-sdk-core/json/handler.rb +21 -1
  38. data/lib/aws-sdk-core/json/json_engine.rb +12 -8
  39. data/lib/aws-sdk-core/json/oj_engine.rb +35 -6
  40. data/lib/aws-sdk-core/json/parser.rb +10 -0
  41. data/lib/aws-sdk-core/json.rb +11 -28
  42. data/lib/aws-sdk-core/log/formatter.rb +16 -4
  43. data/lib/aws-sdk-core/log/handler.rb +2 -0
  44. data/lib/aws-sdk-core/log/param_filter.rb +38 -13
  45. data/lib/aws-sdk-core/log/param_formatter.rb +2 -0
  46. data/lib/aws-sdk-core/pageable_response.rb +48 -24
  47. data/lib/aws-sdk-core/pager.rb +5 -0
  48. data/lib/aws-sdk-core/param_converter.rb +2 -0
  49. data/lib/aws-sdk-core/param_validator.rb +63 -7
  50. data/lib/aws-sdk-core/plugins/api_key.rb +5 -1
  51. data/lib/aws-sdk-core/plugins/apig_authorizer_token.rb +2 -0
  52. data/lib/aws-sdk-core/plugins/apig_credentials_configuration.rb +2 -0
  53. data/lib/aws-sdk-core/plugins/apig_user_agent.rb +2 -0
  54. data/lib/aws-sdk-core/plugins/client_metrics_plugin.rb +28 -1
  55. data/lib/aws-sdk-core/plugins/client_metrics_send_plugin.rb +2 -0
  56. data/lib/aws-sdk-core/plugins/credentials_configuration.rb +26 -7
  57. data/lib/aws-sdk-core/plugins/defaults_mode.rb +40 -0
  58. data/lib/aws-sdk-core/plugins/endpoint_discovery.rb +12 -4
  59. data/lib/aws-sdk-core/plugins/endpoint_pattern.rb +8 -6
  60. data/lib/aws-sdk-core/plugins/event_stream_configuration.rb +16 -0
  61. data/lib/aws-sdk-core/plugins/global_configuration.rb +2 -0
  62. data/lib/aws-sdk-core/plugins/helpful_socket_errors.rb +2 -0
  63. data/lib/aws-sdk-core/plugins/http_checksum.rb +57 -0
  64. data/lib/aws-sdk-core/plugins/idempotency_token.rb +2 -0
  65. data/lib/aws-sdk-core/plugins/invocation_id.rb +35 -0
  66. data/lib/aws-sdk-core/plugins/jsonvalue_converter.rb +2 -0
  67. data/lib/aws-sdk-core/plugins/logging.rb +2 -0
  68. data/lib/aws-sdk-core/plugins/param_converter.rb +2 -0
  69. data/lib/aws-sdk-core/plugins/param_validator.rb +2 -0
  70. data/lib/aws-sdk-core/plugins/protocols/api_gateway.rb +19 -0
  71. data/lib/aws-sdk-core/plugins/protocols/ec2.rb +2 -0
  72. data/lib/aws-sdk-core/plugins/protocols/json_rpc.rb +2 -0
  73. data/lib/aws-sdk-core/plugins/protocols/query.rb +2 -0
  74. data/lib/aws-sdk-core/plugins/protocols/rest_json.rb +18 -1
  75. data/lib/aws-sdk-core/plugins/protocols/rest_xml.rb +2 -0
  76. data/lib/aws-sdk-core/plugins/recursion_detection.rb +27 -0
  77. data/lib/aws-sdk-core/plugins/regional_endpoint.rb +74 -16
  78. data/lib/aws-sdk-core/plugins/response_paging.rb +2 -0
  79. data/lib/aws-sdk-core/plugins/retries/client_rate_limiter.rb +139 -0
  80. data/lib/aws-sdk-core/plugins/retries/clock_skew.rb +100 -0
  81. data/lib/aws-sdk-core/plugins/retries/error_inspector.rb +146 -0
  82. data/lib/aws-sdk-core/plugins/retries/retry_quota.rb +59 -0
  83. data/lib/aws-sdk-core/plugins/retry_errors.rb +295 -107
  84. data/lib/aws-sdk-core/plugins/signature_v2.rb +2 -0
  85. data/lib/aws-sdk-core/plugins/signature_v4.rb +28 -25
  86. data/lib/aws-sdk-core/plugins/stub_responses.rb +24 -7
  87. data/lib/aws-sdk-core/plugins/transfer_encoding.rb +53 -0
  88. data/lib/aws-sdk-core/plugins/user_agent.rb +6 -8
  89. data/lib/aws-sdk-core/process_credentials.rb +12 -5
  90. data/lib/aws-sdk-core/query/ec2_param_builder.rb +2 -0
  91. data/lib/aws-sdk-core/query/handler.rb +2 -0
  92. data/lib/aws-sdk-core/query/param.rb +2 -0
  93. data/lib/aws-sdk-core/query/param_builder.rb +2 -0
  94. data/lib/aws-sdk-core/query/param_list.rb +2 -0
  95. data/lib/aws-sdk-core/query.rb +2 -0
  96. data/lib/aws-sdk-core/refreshing_credentials.rb +15 -2
  97. data/lib/aws-sdk-core/resources/collection.rb +2 -0
  98. data/lib/aws-sdk-core/rest/handler.rb +2 -0
  99. data/lib/aws-sdk-core/rest/request/body.rb +21 -1
  100. data/lib/aws-sdk-core/rest/request/builder.rb +2 -0
  101. data/lib/aws-sdk-core/rest/request/endpoint.rb +10 -3
  102. data/lib/aws-sdk-core/rest/request/headers.rb +20 -6
  103. data/lib/aws-sdk-core/rest/request/querystring_builder.rb +4 -2
  104. data/lib/aws-sdk-core/rest/response/body.rb +2 -0
  105. data/lib/aws-sdk-core/rest/response/headers.rb +6 -3
  106. data/lib/aws-sdk-core/rest/response/parser.rb +2 -0
  107. data/lib/aws-sdk-core/rest/response/status_code.rb +2 -0
  108. data/lib/aws-sdk-core/rest.rb +2 -0
  109. data/lib/aws-sdk-core/shared_config.rb +153 -127
  110. data/lib/aws-sdk-core/shared_credentials.rb +9 -1
  111. data/lib/aws-sdk-core/sso_credentials.rb +136 -0
  112. data/lib/aws-sdk-core/structure.rb +14 -4
  113. data/lib/aws-sdk-core/stubbing/data_applicator.rb +2 -0
  114. data/lib/aws-sdk-core/stubbing/empty_stub.rb +2 -0
  115. data/lib/aws-sdk-core/stubbing/protocols/api_gateway.rb +2 -0
  116. data/lib/aws-sdk-core/stubbing/protocols/ec2.rb +2 -0
  117. data/lib/aws-sdk-core/stubbing/protocols/json.rb +3 -1
  118. data/lib/aws-sdk-core/stubbing/protocols/query.rb +4 -2
  119. data/lib/aws-sdk-core/stubbing/protocols/rest.rb +52 -7
  120. data/lib/aws-sdk-core/stubbing/protocols/rest_json.rb +3 -1
  121. data/lib/aws-sdk-core/stubbing/protocols/rest_xml.rb +2 -2
  122. data/lib/aws-sdk-core/stubbing/stub_data.rb +15 -4
  123. data/lib/aws-sdk-core/stubbing/xml_error.rb +2 -0
  124. data/lib/aws-sdk-core/type_builder.rb +2 -0
  125. data/lib/aws-sdk-core/util.rb +6 -0
  126. data/lib/aws-sdk-core/waiters/errors.rb +2 -0
  127. data/lib/aws-sdk-core/waiters/poller.rb +2 -0
  128. data/lib/aws-sdk-core/waiters/waiter.rb +4 -2
  129. data/lib/aws-sdk-core/waiters.rb +2 -0
  130. data/lib/aws-sdk-core/xml/builder.rb +5 -3
  131. data/lib/aws-sdk-core/xml/default_list.rb +2 -0
  132. data/lib/aws-sdk-core/xml/default_map.rb +2 -0
  133. data/lib/aws-sdk-core/xml/doc_builder.rb +15 -4
  134. data/lib/aws-sdk-core/xml/error_handler.rb +29 -4
  135. data/lib/aws-sdk-core/xml/parser/engines/libxml.rb +2 -0
  136. data/lib/aws-sdk-core/xml/parser/engines/nokogiri.rb +2 -0
  137. data/lib/aws-sdk-core/xml/parser/engines/oga.rb +2 -0
  138. data/lib/aws-sdk-core/xml/parser/engines/ox.rb +3 -1
  139. data/lib/aws-sdk-core/xml/parser/engines/rexml.rb +4 -1
  140. data/lib/aws-sdk-core/xml/parser/frame.rb +25 -0
  141. data/lib/aws-sdk-core/xml/parser/parsing_error.rb +2 -0
  142. data/lib/aws-sdk-core/xml/parser/stack.rb +2 -0
  143. data/lib/aws-sdk-core/xml/parser.rb +7 -0
  144. data/lib/aws-sdk-core/xml.rb +2 -0
  145. data/lib/aws-sdk-core.rb +23 -4
  146. data/lib/aws-sdk-sso/client.rb +568 -0
  147. data/lib/aws-sdk-sso/client_api.rb +190 -0
  148. data/lib/aws-sdk-sso/customizations.rb +1 -0
  149. data/lib/aws-sdk-sso/errors.rb +102 -0
  150. data/lib/aws-sdk-sso/resource.rb +26 -0
  151. data/lib/aws-sdk-sso/types.rb +352 -0
  152. data/lib/aws-sdk-sso.rb +55 -0
  153. data/lib/aws-sdk-sts/client.rb +1282 -531
  154. data/lib/aws-sdk-sts/client_api.rb +76 -1
  155. data/lib/aws-sdk-sts/customizations.rb +4 -0
  156. data/lib/aws-sdk-sts/errors.rb +153 -1
  157. data/lib/aws-sdk-sts/plugins/sts_regional_endpoints.rb +38 -0
  158. data/lib/aws-sdk-sts/presigner.rb +75 -0
  159. data/lib/aws-sdk-sts/resource.rb +4 -1
  160. data/lib/aws-sdk-sts/types.rb +958 -229
  161. data/lib/aws-sdk-sts.rb +16 -6
  162. data/lib/seahorse/client/async_base.rb +52 -0
  163. data/lib/seahorse/client/async_response.rb +64 -0
  164. data/lib/seahorse/client/base.rb +7 -2
  165. data/lib/seahorse/client/block_io.rb +6 -2
  166. data/lib/seahorse/client/configuration.rb +7 -1
  167. data/lib/seahorse/client/events.rb +3 -1
  168. data/lib/seahorse/client/h2/connection.rb +250 -0
  169. data/lib/seahorse/client/h2/handler.rb +152 -0
  170. data/lib/seahorse/client/handler.rb +2 -0
  171. data/lib/seahorse/client/handler_builder.rb +2 -0
  172. data/lib/seahorse/client/handler_list.rb +2 -0
  173. data/lib/seahorse/client/handler_list_entry.rb +6 -4
  174. data/lib/seahorse/client/http/async_response.rb +44 -0
  175. data/lib/seahorse/client/http/headers.rb +2 -0
  176. data/lib/seahorse/client/http/request.rb +5 -3
  177. data/lib/seahorse/client/http/response.rb +18 -11
  178. data/lib/seahorse/client/logging/formatter.rb +6 -2
  179. data/lib/seahorse/client/logging/handler.rb +2 -0
  180. data/lib/seahorse/client/managed_file.rb +2 -0
  181. data/lib/seahorse/client/net_http/connection_pool.rb +30 -23
  182. data/lib/seahorse/client/net_http/handler.rb +24 -7
  183. data/lib/seahorse/client/net_http/patches.rb +15 -84
  184. data/lib/seahorse/client/networking_error.rb +30 -0
  185. data/lib/seahorse/client/plugin.rb +10 -7
  186. data/lib/seahorse/client/plugin_list.rb +2 -0
  187. data/lib/seahorse/client/plugins/content_length.rb +14 -3
  188. data/lib/seahorse/client/plugins/endpoint.rb +4 -2
  189. data/lib/seahorse/client/plugins/h2.rb +69 -0
  190. data/lib/seahorse/client/plugins/logging.rb +2 -0
  191. data/lib/seahorse/client/plugins/net_http.rb +39 -3
  192. data/lib/seahorse/client/plugins/operation_methods.rb +2 -0
  193. data/lib/seahorse/client/plugins/raise_response_errors.rb +2 -0
  194. data/lib/seahorse/client/plugins/request_callback.rb +110 -0
  195. data/lib/seahorse/client/plugins/response_target.rb +23 -14
  196. data/lib/seahorse/client/request.rb +2 -0
  197. data/lib/seahorse/client/request_context.rb +2 -0
  198. data/lib/seahorse/client/response.rb +5 -5
  199. data/lib/seahorse/model/api.rb +10 -0
  200. data/lib/seahorse/model/authorizer.rb +2 -0
  201. data/lib/seahorse/model/operation.rb +9 -0
  202. data/lib/seahorse/model/shapes.rb +29 -2
  203. data/lib/seahorse/util.rb +8 -1
  204. data/lib/seahorse/version.rb +2 -0
  205. data/lib/seahorse.rb +12 -0
  206. metadata +64 -14
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Seahorse
2
4
  module Client
3
5
 
@@ -77,8 +79,8 @@ module Seahorse
77
79
  if options.key?(name)
78
80
  options[name]
79
81
  else
80
- msg = "invalid :priority `%s', must be between 0 and 99"
81
- raise ArgumentError, msg % priority.inspect
82
+ msg = "missing option: `%s'"
83
+ raise ArgumentError, msg % name.inspect
82
84
  end
83
85
  end
84
86
 
@@ -86,8 +88,8 @@ module Seahorse
86
88
  if STEPS.key?(step)
87
89
  @step = step
88
90
  else
89
- msg = "invalid :step `%s', must be one of :initialize, :validate, "
90
- msg << ":build, :sign or :send"
91
+ msg = "invalid :step `%s', must be one of :initialize, :validate, "\
92
+ ':build, :sign or :send'
91
93
  raise ArgumentError, msg % step.inspect
92
94
  end
93
95
  end
@@ -0,0 +1,44 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Seahorse
4
+ module Client
5
+ module Http
6
+ class AsyncResponse < Seahorse::Client::Http::Response
7
+
8
+ def initialize(options = {})
9
+ super
10
+ end
11
+
12
+ def signal_headers(headers)
13
+ # H2 headers arrive as array of pair
14
+ hash = headers.inject({}) do |h, pair|
15
+ key, value = pair
16
+ h[key] = value
17
+ h
18
+ end
19
+ @status_code = hash[":status"].to_i
20
+ @headers = Headers.new(hash)
21
+ emit(:headers, @status_code, @headers)
22
+ end
23
+
24
+ def signal_done(options = {})
25
+ # H2 only has header and body
26
+ # ':status' header will be sent back
27
+ if options.keys.sort == [:body, :headers]
28
+ signal_headers(options[:headers])
29
+ signal_data(options[:body])
30
+ signal_done
31
+ elsif options.empty?
32
+ @body.rewind if @body.respond_to?(:rewind)
33
+ @done = true
34
+ emit(:done)
35
+ else
36
+ msg = "options must be empty or must contain :headers and :body"
37
+ raise ArgumentError, msg
38
+ end
39
+ end
40
+
41
+ end
42
+ end
43
+ end
44
+ end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Seahorse
2
4
  module Client
3
5
  module Http
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'stringio'
2
4
  require 'uri'
3
5
 
@@ -34,8 +36,8 @@ module Seahorse
34
36
  if endpoint.nil? or URI::HTTP === endpoint or URI::HTTPS === endpoint
35
37
  @endpoint = endpoint
36
38
  else
37
- msg = "invalid endpoint, expected URI::HTTP, URI::HTTPS, or nil, "
38
- msg << "got #{endpoint.inspect}"
39
+ msg = 'invalid endpoint, expected URI::HTTP, URI::HTTPS, or nil, '\
40
+ "got #{endpoint.inspect}"
39
41
  raise ArgumentError, msg
40
42
  end
41
43
  end
@@ -55,7 +57,7 @@ module Seahorse
55
57
 
56
58
  # @param [#read, #size, #rewind] io
57
59
  def body=(io)
58
- @body =case io
60
+ @body = case io
59
61
  when nil then StringIO.new('')
60
62
  when String then StringIO.new(io)
61
63
  else io
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Seahorse
2
4
  module Client
3
5
  module Http
@@ -40,12 +42,17 @@ module Seahorse
40
42
  end
41
43
  end
42
44
 
43
- # @return [String]
45
+ # @return [String|Array]
44
46
  def body_contents
45
- body.rewind
46
- contents = body.read
47
- body.rewind
48
- contents
47
+ if body.is_a?(Array)
48
+ # an array of parsed events
49
+ body
50
+ else
51
+ body.rewind
52
+ contents = body.read
53
+ body.rewind
54
+ contents
55
+ end
49
56
  end
50
57
 
51
58
  # @param [Integer] status_code
@@ -66,7 +73,7 @@ module Seahorse
66
73
 
67
74
  # Completes the http response.
68
75
  #
69
- # @example Completing the response in a singal call
76
+ # @example Completing the response in a single call
70
77
  #
71
78
  # http_response.signal_done(
72
79
  # status_code: 200,
@@ -104,8 +111,8 @@ module Seahorse
104
111
  @done = true
105
112
  emit(:done)
106
113
  else
107
- msg = "options must be empty or must contain :status_code, :headers, "
108
- msg << "and :body"
114
+ msg = 'options must be empty or must contain :status_code, :headers, '\
115
+ 'and :body'
109
116
  raise ArgumentError, msg
110
117
  end
111
118
  end
@@ -117,15 +124,15 @@ module Seahorse
117
124
  end
118
125
 
119
126
  def on_headers(status_code_range = nil, &block)
120
- @listeners[:headers] << listener(status_code_range, Proc.new)
127
+ @listeners[:headers] << listener(status_code_range, block)
121
128
  end
122
129
 
123
130
  def on_data(&callback)
124
- @listeners[:data] << Proc.new
131
+ @listeners[:data] << callback
125
132
  end
126
133
 
127
134
  def on_done(status_code_range = nil, &callback)
128
- listener = listener(status_code_range, Proc.new)
135
+ listener = listener(status_code_range, callback)
129
136
  if @done
130
137
  listener.call
131
138
  else
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'pathname'
2
4
 
3
5
  module Seahorse
@@ -173,9 +175,11 @@ module Seahorse
173
175
  end
174
176
 
175
177
  def _http_response_body(response)
176
- response.context.http_response.body.respond_to?(:rewind) ?
177
- summarize_value(response.context.http_response.body_contents) :
178
+ if response.context.http_response.body.respond_to?(:rewind)
179
+ summarize_value(response.context.http_response.body_contents)
180
+ else
178
181
  ''
182
+ end
179
183
  end
180
184
 
181
185
  def _error_class(response)
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Seahorse
2
4
  module Client
3
5
  # @deprecated Use Aws::Logging instead.
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Seahorse
2
4
  module Client
3
5
  # This utility class is used to track files opened by Seahorse.
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'cgi'
2
4
  require 'net/http'
3
5
  require 'net/https'
@@ -18,6 +20,7 @@ module Seahorse
18
20
 
19
21
  @pools_mutex = Mutex.new
20
22
  @pools = {}
23
+ @default_logger = Logger.new($stdout)
21
24
 
22
25
  OPTIONS = {
23
26
  http_proxy: nil,
@@ -31,6 +34,7 @@ module Seahorse
31
34
  ssl_ca_bundle: nil,
32
35
  ssl_ca_directory: nil,
33
36
  ssl_ca_store: nil,
37
+ ssl_timeout: nil
34
38
  }
35
39
 
36
40
  # @api private
@@ -52,14 +56,14 @@ module Seahorse
52
56
 
53
57
  # Makes an HTTP request, yielding a Net::HTTPResponse object.
54
58
  #
55
- # pool.request('http://domain', Net::HTTP::Get.new('/')) do |resp|
59
+ # pool.request(URI.parse('http://domain'), Net::HTTP::Get.new('/')) do |resp|
56
60
  # puts resp.code # status code
57
61
  # puts resp.to_h.inspect # dump the headers
58
62
  # puts resp.body
59
63
  # end
60
64
  #
61
- # @param [String] endpoint The HTTP(S) endpoint to
62
- # connect to (e.g. 'https://domain.com').
65
+ # @param [URI::HTTP, URI::HTTPS] endpoint The HTTP(S) endpoint
66
+ # to connect to (e.g. 'https://domain.com').
63
67
  #
64
68
  # @param [Net::HTTPRequest] request The request to make. This can be
65
69
  # any request object from Net::HTTP (e.g. Net::HTTP::Get,
@@ -131,7 +135,7 @@ module Seahorse
131
135
  nil
132
136
  end
133
137
 
134
- # Closes and removes removes all sessions from the pool.
138
+ # Closes and removes all sessions from the pool.
135
139
  # If empty! is called while there are outstanding requests they may
136
140
  # get checked back into the pool, leaving the pool in a non-empty
137
141
  # state.
@@ -165,16 +169,15 @@ module Seahorse
165
169
  # requests through. Formatted like 'http://proxy.com:123'.
166
170
  #
167
171
  # @option options [Float] :http_open_timeout (15) The number of
168
- # seconds to wait when opening a HTTP session before rasing a
172
+ # seconds to wait when opening an HTTP session before raising a
169
173
  # `Timeout::Error`.
170
174
  #
171
- # @option options [Integer] :http_read_timeout (60) The default
172
- # number of seconds to wait for response data. This value can
173
- # safely be set
174
- # per-request on the session yeidled by {#session_for}.
175
+ # @option options [Float] :http_read_timeout (60) The default
176
+ # number of seconds to wait for response data. This value can be
177
+ # safely set per-request on the session yielded by {#session_for}.
175
178
  #
176
179
  # @option options [Float] :http_idle_timeout (5) The number of
177
- # seconds a connection is allowed to sit idble before it is
180
+ # seconds a connection is allowed to sit idle before it is
178
181
  # considered stale. Stale connections are closed and removed
179
182
  # from the pool before making a request.
180
183
  #
@@ -183,7 +186,10 @@ module Seahorse
183
186
  # request body. This option has no effect unless the request has
184
187
  # "Expect" header set to "100-continue". Defaults to `nil` which
185
188
  # disables this behaviour. This value can safely be set per
186
- # request on the session yeidled by {#session_for}.
189
+ # request on the session yielded by {#session_for}.
190
+ #
191
+ # @option options [Float] :ssl_timeout (nil) Sets the SSL timeout
192
+ # in seconds.
187
193
  #
188
194
  # @option options [Boolean] :http_wire_trace (false) When `true`,
189
195
  # HTTP debug output will be sent to the `:logger`.
@@ -200,13 +206,13 @@ module Seahorse
200
206
  # @option options [String] :ssl_ca_bundle Full path to the SSL
201
207
  # certificate authority bundle file that should be used when
202
208
  # verifying peer certificates. If you do not pass
203
- # `:ssl_ca_bundle` or `:ssl_ca_directory` the the system default
209
+ # `:ssl_ca_bundle` or `:ssl_ca_directory` the system default
204
210
  # will be used if available.
205
211
  #
206
212
  # @option options [String] :ssl_ca_directory Full path of the
207
213
  # directory that contains the unbundled SSL certificate
208
214
  # authority files for verifying peer certificates. If you do
209
- # not pass `:ssl_ca_bundle` or `:ssl_ca_directory` the the
215
+ # not pass `:ssl_ca_bundle` or `:ssl_ca_directory` the
210
216
  # system default will be used if available.
211
217
  #
212
218
  # @return [ConnectionPool]
@@ -217,7 +223,7 @@ module Seahorse
217
223
  end
218
224
  end
219
225
 
220
- # @return [Array<ConnectionPool>] Returns a list of of the
226
+ # @return [Array<ConnectionPool>] Returns a list of the
221
227
  # constructed connection pools.
222
228
  def pools
223
229
  @pools_mutex.synchronize do
@@ -231,7 +237,7 @@ module Seahorse
231
237
  # @return [Hash]
232
238
  def pool_options options
233
239
  wire_trace = !!options[:http_wire_trace]
234
- logger = options[:logger] || Logger.new($stdout) if wire_trace
240
+ logger = options[:logger] || @default_logger if wire_trace
235
241
  verify_peer = options.key?(:ssl_verify_peer) ?
236
242
  !!options[:ssl_verify_peer] : true
237
243
  {
@@ -246,6 +252,7 @@ module Seahorse
246
252
  :ssl_ca_bundle => options[:ssl_ca_bundle],
247
253
  :ssl_ca_directory => options[:ssl_ca_directory],
248
254
  :ssl_ca_store => options[:ssl_ca_store],
255
+ :ssl_timeout => options[:ssl_timeout]
249
256
  }
250
257
  end
251
258
 
@@ -279,9 +286,12 @@ module Seahorse
279
286
  http = ExtendedSession.new(Net::HTTP.new(*args.compact))
280
287
  http.set_debug_output(logger) if http_wire_trace?
281
288
  http.open_timeout = http_open_timeout
289
+ http.keep_alive_timeout = http_idle_timeout if http.respond_to?(:keep_alive_timeout=)
282
290
 
283
291
  if endpoint.scheme == 'https'
284
292
  http.use_ssl = true
293
+ http.ssl_timeout = ssl_timeout
294
+
285
295
  if ssl_verify_peer?
286
296
  http.verify_mode = OpenSSL::SSL::VERIFY_PEER
287
297
  http.ca_file = ssl_ca_bundle if ssl_ca_bundle
@@ -301,13 +311,10 @@ module Seahorse
301
311
  # Removes stale sessions from the pool. This method *must* be called
302
312
  # @note **Must** be called behind a `@pool_mutex` synchronize block.
303
313
  def _clean
304
- now = Time.now
314
+ now = Aws::Util.monotonic_milliseconds
305
315
  @pool.each_pair do |endpoint,sessions|
306
316
  sessions.delete_if do |session|
307
- if
308
- session.last_used.nil? or
309
- now - session.last_used > http_idle_timeout
310
- then
317
+ if session.last_used.nil? or now - session.last_used > http_idle_timeout * 1000
311
318
  session.finish
312
319
  true
313
320
  end
@@ -315,7 +322,7 @@ module Seahorse
315
322
  end
316
323
  end
317
324
 
318
- # Helper methods extended onto Net::HTTPSession objects opend by the
325
+ # Helper methods extended onto Net::HTTPSession objects opened by the
319
326
  # connection pool.
320
327
  # @api private
321
328
  class ExtendedSession < Delegator
@@ -325,7 +332,7 @@ module Seahorse
325
332
  @http = http
326
333
  end
327
334
 
328
- # @return [Time,nil]
335
+ # @return [Integer,nil]
329
336
  attr_reader :last_used
330
337
 
331
338
  def __getobj__
@@ -338,8 +345,8 @@ module Seahorse
338
345
 
339
346
  # Sends the request and tracks that this session has been used.
340
347
  def request(*args, &block)
341
- @last_used = Time.now
342
348
  @http.request(*args, &block)
349
+ @last_used = Aws::Util.monotonic_milliseconds
343
350
  end
344
351
 
345
352
  # Attempts to close/finish the session without raising an error.
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'net/https'
2
4
  require 'openssl'
3
5
 
@@ -13,8 +15,8 @@ module Seahorse
13
15
  # @api private
14
16
  class TruncatedBodyError < IOError
15
17
  def initialize(bytes_expected, bytes_received)
16
- msg = "http response body truncated, expected #{bytes_expected} "
17
- msg << "bytes, received #{bytes_received} bytes"
18
+ msg = "http response body truncated, expected #{bytes_expected} "\
19
+ "bytes, received #{bytes_received} bytes"
18
20
  super(msg)
19
21
  end
20
22
  end
@@ -23,7 +25,8 @@ module Seahorse
23
25
  SocketError, EOFError, IOError, Timeout::Error,
24
26
  Errno::ECONNABORTED, Errno::ECONNRESET, Errno::EPIPE,
25
27
  Errno::EINVAL, Errno::ETIMEDOUT, OpenSSL::SSL::SSLError,
26
- Errno::EHOSTUNREACH, Errno::ECONNREFUSED
28
+ Errno::EHOSTUNREACH, Errno::ECONNREFUSED,
29
+ Net::HTTPFatalError # for proxy connection failures
27
30
  ]
28
31
 
29
32
  # does not exist in Ruby 1.9.3
@@ -71,8 +74,9 @@ module Seahorse
71
74
  # @return [void]
72
75
  def transmit(config, req, resp)
73
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
74
79
  http.request(build_net_request(req)) do |net_resp|
75
-
76
80
  status_code = net_resp.code.to_i
77
81
  headers = extract_headers(net_resp)
78
82
 
@@ -93,6 +97,9 @@ module Seahorse
93
97
  rescue => error
94
98
  # not retryable
95
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
96
103
  end
97
104
 
98
105
  def complete_response(req, resp, bytes_received)
@@ -144,7 +151,12 @@ module Seahorse
144
151
  def build_net_request(request)
145
152
  request_class = net_http_request_class(request)
146
153
  req = request_class.new(request.endpoint.request_uri, headers(request))
147
- 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
148
160
  req
149
161
  end
150
162
 
@@ -163,8 +175,13 @@ module Seahorse
163
175
  # @return [Hash] Returns a vanilla hash of headers to send with the
164
176
  # HTTP request.
165
177
  def headers(request)
166
- # setting these to stop net/http from providing defaults
167
- headers = { 'content-type' => '', 'accept-encoding' => '' }
178
+ # Net::HTTP adds a default header for accept-encoding (2.0.0+).
179
+ # Setting a default empty value defeats this.
180
+ #
181
+ # Removing this is necessary for most services to not break request
182
+ # signatures as well as dynamodb crc32 checks (these fail if the
183
+ # response is gzipped).
184
+ headers = { 'accept-encoding' => '' }
168
185
  request.headers.each_pair do |key, value|
169
186
  headers[key] = value
170
187
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'net/http'
2
4
 
3
5
  module Seahorse
@@ -9,97 +11,26 @@ module Seahorse
9
11
  module Patches
10
12
 
11
13
  def self.apply!
14
+ Net::HTTPGenericRequest.prepend(PatchDefaultContentType)
12
15
  return unless RUBY_VERSION < '2.5'
13
- if RUBY_VERSION >= '2.3'
14
- Net::HTTP::IDEMPOTENT_METHODS_.clear
15
- return
16
- end
17
- # no further patches needed for above versions
18
16
 
19
- if RUBY_VERSION >= '2.0'
20
- Net::HTTP.send(:include, Ruby_2)
21
- Net::HTTP::IDEMPOTENT_METHODS_.clear
22
- elsif RUBY_VERSION >= '1.9.3'
23
- Net::HTTP.send(:include, Ruby_1_9_3)
24
- end
25
- Net::HTTP.send(:alias_method, :old_transport_request, :transport_request)
26
- Net::HTTP.send(:alias_method, :transport_request, :new_transport_request)
17
+ Net::HTTP::IDEMPOTENT_METHODS_.clear
27
18
  end
28
19
 
29
- module Ruby_2
30
- def new_transport_request(req)
31
- count = 0
32
- begin
33
- begin_transport req
34
- res = catch(:response) {
35
- req.exec @socket, @curr_http_version, edit_path(req.path)
36
- begin
37
- res = Net::HTTPResponse.read_new(@socket)
38
- res.decode_content = req.decode_content
39
- end while res.kind_of?(Net::HTTPInformation)
40
-
41
- res.uri = req.uri
42
-
43
- res
44
- }
45
- res.reading_body(@socket, req.response_body_permitted?) {
46
- yield res if block_given?
47
- }
48
- rescue Net::OpenTimeout
49
- raise
50
- rescue Net::ReadTimeout, IOError, EOFError,
51
- Errno::ECONNRESET, Errno::ECONNABORTED, Errno::EPIPE,
52
- # avoid a dependency on OpenSSL
53
- defined?(OpenSSL::SSL) ? OpenSSL::SSL::SSLError : IOError,
54
- Timeout::Error => exception
55
- if count == 0 && Net::HTTP::IDEMPOTENT_METHODS_.include?(req.method)
56
- count += 1
57
- @socket.close if @socket and not @socket.closed?
58
- D "Conn close because of error #{exception}, and retry"
59
- if req.body_stream
60
- if req.body_stream.respond_to?(:rewind)
61
- req.body_stream.rewind
62
- else
63
- raise
64
- end
65
- end
66
- retry
67
- end
68
- D "Conn close because of error #{exception}"
69
- @socket.close if @socket and not @socket.closed?
70
- raise
71
- end
72
-
73
- end_transport req, res
74
- res
75
- rescue => exception
76
- D "Conn close because of error #{exception}"
77
- @socket.close if @socket and not @socket.closed?
78
- raise exception
20
+ # For requests with bodys, Net::HTTP sets a default content type of:
21
+ # 'application/x-www-form-urlencoded'
22
+ # There are cases where we should not send content type at all.
23
+ # Even when no body is supplied, Net::HTTP uses a default empty body
24
+ # and sets it anyway. This patch disables the behavior when a Thread
25
+ # local variable is set.
26
+ module PatchDefaultContentType
27
+ def supply_default_content_type
28
+ return if Thread.current[:net_http_skip_default_content_type]
29
+
30
+ super
79
31
  end
80
32
  end
81
33
 
82
- module Ruby_1_9_3
83
- def new_transport_request(req)
84
- begin_transport req
85
- res = catch(:response) {
86
- req.exec @socket, @curr_http_version, edit_path(req.path)
87
- begin
88
- res = Net::HTTPResponse.read_new(@socket)
89
- end while res.kind_of?(Net::HTTPContinue)
90
- res
91
- }
92
- res.reading_body(@socket, req.response_body_permitted?) {
93
- yield res if block_given?
94
- }
95
- end_transport req, res
96
- res
97
- rescue => exception
98
- D "Conn close because of error #{exception}"
99
- @socket.close if @socket and not @socket.closed?
100
- raise exception
101
- end
102
- end
103
34
  end
104
35
  end
105
36
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Seahorse
2
4
  module Client
3
5
  class NetworkingError < StandardError
@@ -11,5 +13,33 @@ module Seahorse
11
13
  attr_reader :original_error
12
14
 
13
15
  end
16
+
17
+ # Raised when sending initial headers and data failed
18
+ # for event stream requests over Http2
19
+ class Http2InitialRequestError < StandardError
20
+
21
+ def initialize(error)
22
+ @original_error = error
23
+ end
24
+
25
+ # @return [HTTP2::Error]
26
+ attr_reader :original_error
27
+
28
+ end
29
+
30
+ # Raised when connection failed to initialize a new stream
31
+ class Http2StreamInitializeError < StandardError
32
+
33
+ def initialize(error)
34
+ @original_error = error
35
+ end
36
+
37
+ # @return [HTTP2::Error]
38
+ attr_reader :original_error
39
+
40
+ end
41
+
42
+ # Rasied when trying to use an closed connection
43
+ class Http2ConnectionClosedError < StandardError; end
14
44
  end
15
45
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Seahorse
2
4
  module Client
3
5
  class Plugin
@@ -53,12 +55,12 @@ module Seahorse
53
55
  # For backwards-compat reasons, the default value can be passed as 2nd
54
56
  # positional argument (before the options hash) or as the `:default` option
55
57
  # in the options hash.
56
- if Hash === default
58
+ if default.is_a? Hash
57
59
  options = default
58
60
  else
59
61
  options[:default] = default
60
62
  end
61
- options[:default_block] = Proc.new if block_given?
63
+ options[:default_block] = block if block_given?
62
64
  self.options << PluginOption.new(name, options)
63
65
  end
64
66
 
@@ -109,6 +111,7 @@ module Seahorse
109
111
 
110
112
  def initialize(name, options = {})
111
113
  @name = name
114
+ @doc_default = nil
112
115
  options.each_pair do |opt_name, opt_value|
113
116
  self.send("#{opt_name}=", opt_value)
114
117
  end
@@ -119,14 +122,14 @@ module Seahorse
119
122
  attr_accessor :default_block
120
123
  attr_accessor :required
121
124
  attr_accessor :doc_type
122
- attr_accessor :doc_default
125
+ attr_writer :doc_default
123
126
  attr_accessor :docstring
124
127
 
125
- def doc_default
126
- if @doc_default.nil?
127
- Proc === default ? nil : default
128
+ def doc_default(options)
129
+ if @doc_default.nil? && !default.is_a?(Proc)
130
+ default
128
131
  else
129
- @doc_default
132
+ @doc_default.respond_to?(:call) ? @doc_default.call(options) : @doc_default
130
133
  end
131
134
  end
132
135
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'set'
2
4
  require 'thread'
3
5