aws-sdk-core 3.191.0 → 3.199.0

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 (101) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +153 -1
  3. data/VERSION +1 -1
  4. data/lib/aws-sdk-core/binary/decode_handler.rb +3 -9
  5. data/lib/aws-sdk-core/binary/encode_handler.rb +1 -1
  6. data/lib/aws-sdk-core/binary/event_builder.rb +34 -37
  7. data/lib/aws-sdk-core/binary/event_stream_decoder.rb +1 -0
  8. data/lib/aws-sdk-core/binary/event_stream_encoder.rb +4 -3
  9. data/lib/aws-sdk-core/cbor/cbor_engine.rb +19 -0
  10. data/lib/aws-sdk-core/cbor/decoder.rb +310 -0
  11. data/lib/aws-sdk-core/cbor/encoder.rb +243 -0
  12. data/lib/aws-sdk-core/cbor.rb +106 -0
  13. data/lib/aws-sdk-core/client_stubs.rb +3 -2
  14. data/lib/aws-sdk-core/credential_provider.rb +1 -1
  15. data/lib/aws-sdk-core/ec2_metadata.rb +1 -1
  16. data/lib/aws-sdk-core/ecs_credentials.rb +2 -1
  17. data/lib/aws-sdk-core/endpoints/matchers.rb +5 -1
  18. data/lib/aws-sdk-core/error_handler.rb +41 -0
  19. data/lib/aws-sdk-core/event_emitter.rb +0 -16
  20. data/lib/aws-sdk-core/instance_profile_credentials.rb +3 -2
  21. data/lib/aws-sdk-core/json/builder.rb +8 -1
  22. data/lib/aws-sdk-core/json/error_handler.rb +15 -10
  23. data/lib/aws-sdk-core/json/handler.rb +5 -6
  24. data/lib/aws-sdk-core/json/json_engine.rb +3 -1
  25. data/lib/aws-sdk-core/json/oj_engine.rb +7 -1
  26. data/lib/aws-sdk-core/json/parser.rb +6 -1
  27. data/lib/aws-sdk-core/json.rb +43 -14
  28. data/lib/aws-sdk-core/lru_cache.rb +75 -0
  29. data/lib/aws-sdk-core/pageable_response.rb +1 -1
  30. data/lib/aws-sdk-core/param_validator.rb +7 -2
  31. data/lib/aws-sdk-core/plugins/client_metrics_send_plugin.rb +14 -2
  32. data/lib/aws-sdk-core/plugins/global_configuration.rb +8 -9
  33. data/lib/aws-sdk-core/plugins/invocation_id.rb +1 -11
  34. data/lib/aws-sdk-core/plugins/protocols/api_gateway.rb +3 -1
  35. data/lib/aws-sdk-core/plugins/protocols/ec2.rb +2 -24
  36. data/lib/aws-sdk-core/plugins/protocols/json_rpc.rb +6 -8
  37. data/lib/aws-sdk-core/plugins/protocols/query.rb +4 -2
  38. data/lib/aws-sdk-core/plugins/protocols/rest_json.rb +3 -15
  39. data/lib/aws-sdk-core/plugins/protocols/rest_xml.rb +3 -0
  40. data/lib/aws-sdk-core/plugins/protocols/rpc_v2.rb +17 -0
  41. data/lib/aws-sdk-core/plugins/request_compression.rb +11 -2
  42. data/lib/aws-sdk-core/plugins/retry_errors.rb +10 -3
  43. data/lib/aws-sdk-core/plugins/sign.rb +8 -3
  44. data/lib/aws-sdk-core/plugins/user_agent.rb +61 -26
  45. data/lib/aws-sdk-core/process_credentials.rb +45 -27
  46. data/lib/aws-sdk-core/query/ec2_handler.rb +27 -0
  47. data/lib/aws-sdk-core/query/ec2_param_builder.rb +5 -7
  48. data/lib/aws-sdk-core/query/handler.rb +4 -4
  49. data/lib/aws-sdk-core/query/param_builder.rb +2 -2
  50. data/lib/aws-sdk-core/query.rb +2 -1
  51. data/lib/aws-sdk-core/rest/content_type_handler.rb +60 -0
  52. data/lib/aws-sdk-core/rest/handler.rb +3 -4
  53. data/lib/aws-sdk-core/rest/request/body.rb +32 -5
  54. data/lib/aws-sdk-core/rest/request/endpoint.rb +24 -4
  55. data/lib/aws-sdk-core/rest/request/headers.rb +15 -7
  56. data/lib/aws-sdk-core/rest/request/querystring_builder.rb +23 -11
  57. data/lib/aws-sdk-core/rest/response/body.rb +15 -1
  58. data/lib/aws-sdk-core/rest/response/header_list_parser.rb +79 -0
  59. data/lib/aws-sdk-core/rest/response/headers.rb +8 -3
  60. data/lib/aws-sdk-core/rest.rb +1 -0
  61. data/lib/aws-sdk-core/rpc_v2/builder.rb +62 -0
  62. data/lib/aws-sdk-core/rpc_v2/content_type_handler.rb +45 -0
  63. data/lib/aws-sdk-core/rpc_v2/error_handler.rb +84 -0
  64. data/lib/aws-sdk-core/rpc_v2/handler.rb +74 -0
  65. data/lib/aws-sdk-core/rpc_v2/parser.rb +90 -0
  66. data/lib/aws-sdk-core/rpc_v2.rb +6 -0
  67. data/lib/aws-sdk-core/stubbing/protocols/rpc_v2.rb +41 -0
  68. data/lib/aws-sdk-core/util.rb +39 -0
  69. data/lib/aws-sdk-core/waiters/poller.rb +1 -1
  70. data/lib/aws-sdk-core/xml/builder.rb +17 -9
  71. data/lib/aws-sdk-core/xml/error_handler.rb +32 -42
  72. data/lib/aws-sdk-core/xml/parser/frame.rb +4 -20
  73. data/lib/aws-sdk-core/xml/parser/stack.rb +2 -0
  74. data/lib/aws-sdk-core/xml/parser.rb +2 -6
  75. data/lib/aws-sdk-core.rb +7 -2
  76. data/lib/aws-sdk-sso/client.rb +77 -49
  77. data/lib/aws-sdk-sso.rb +1 -1
  78. data/lib/aws-sdk-ssooidc/client.rb +127 -51
  79. data/lib/aws-sdk-ssooidc/client_api.rb +22 -0
  80. data/lib/aws-sdk-ssooidc/errors.rb +21 -0
  81. data/lib/aws-sdk-ssooidc/types.rb +77 -9
  82. data/lib/aws-sdk-ssooidc.rb +1 -1
  83. data/lib/aws-sdk-sts/client.rb +77 -49
  84. data/lib/aws-sdk-sts/client_api.rb +8 -8
  85. data/lib/aws-sdk-sts.rb +1 -1
  86. data/lib/seahorse/client/async_base.rb +1 -1
  87. data/lib/seahorse/client/async_response.rb +19 -0
  88. data/lib/seahorse/client/base.rb +18 -7
  89. data/lib/seahorse/client/h2/handler.rb +1 -0
  90. data/lib/seahorse/client/handler.rb +1 -1
  91. data/lib/seahorse/client/net_http/connection_pool.rb +3 -9
  92. data/lib/seahorse/client/plugin.rb +8 -0
  93. data/lib/seahorse/client/plugins/endpoint.rb +0 -1
  94. data/lib/seahorse/client/plugins/net_http.rb +48 -16
  95. data/lib/seahorse/model/shapes.rb +2 -2
  96. metadata +24 -7
  97. /data/lib/aws-sdk-core/xml/parser/{engines/libxml.rb → libxml_engine.rb} +0 -0
  98. /data/lib/aws-sdk-core/xml/parser/{engines/nokogiri.rb → nokogiri_engine.rb} +0 -0
  99. /data/lib/aws-sdk-core/xml/parser/{engines/oga.rb → oga_engine.rb} +0 -0
  100. /data/lib/aws-sdk-core/xml/parser/{engines/ox.rb → ox_engine.rb} +0 -0
  101. /data/lib/aws-sdk-core/xml/parser/{engines/rexml.rb → rexml_engine.rb} +0 -0
@@ -0,0 +1,243 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bigdecimal'
4
+
5
+ module Aws
6
+ module Cbor
7
+ # Pure ruby implementation of CBOR encoder.
8
+ class Encoder
9
+ def initialize
10
+ @buffer = String.new
11
+ end
12
+
13
+ # @return the encoded bytes in CBOR format for all added data
14
+ def bytes
15
+ @buffer
16
+ end
17
+
18
+ # generic method for adding generic Ruby data based on its type
19
+ def add(value)
20
+ case value
21
+ when BigDecimal then add_big_decimal(value)
22
+ when Integer then add_auto_integer(value)
23
+ when Numeric then add_auto_float(value)
24
+ when Symbol then add_string(value.to_s)
25
+ when true, false then add_boolean(value)
26
+ when nil then add_nil
27
+ when Tagged
28
+ add_tag(value.tag)
29
+ add(value.value)
30
+ when String
31
+ if value.encoding == Encoding::BINARY
32
+ add_byte_string(value)
33
+ else
34
+ add_string(value)
35
+ end
36
+ when Array
37
+ start_array(value.size)
38
+ value.each { |di| add(di) }
39
+ when Hash
40
+ start_map(value.size)
41
+ value.each do |k, v|
42
+ add(k)
43
+ add(v)
44
+ end
45
+ when Time
46
+ add_time(value)
47
+ else
48
+ raise UnknownTypeError, value
49
+ end
50
+ self
51
+ end
52
+
53
+ private
54
+
55
+ MAJOR_TYPE_UNSIGNED_INT = 0x00 # 000_00000 - Major Type 0 - unsigned int
56
+ MAJOR_TYPE_NEGATIVE_INT = 0x20 # 001_00000 - Major Type 1 - negative int
57
+ MAJOR_TYPE_BYTE_STR = 0x40 # 010_00000 - Major Type 2 (Byte String)
58
+ MAJOR_TYPE_STR = 0x60 # 011_00000 - Major Type 3 (Text String)
59
+ MAJOR_TYPE_ARRAY = 0x80 # 100_00000 - Major Type 4 (Array)
60
+ MAJOR_TYPE_MAP = 0xa0 # 101_00000 - Major Type 5 (Map)
61
+ MAJOR_TYPE_TAG = 0xc0 # 110_00000 - Major type 6 (Tag)
62
+ MAJOR_TYPE_SIMPLE = 0xe0 # 111_00000 - Major type 7 (111) + 5 bit 0
63
+
64
+ FLOAT_BYTES = 0xfa # 111_11010 - Major type 7 (Float) + value: 26
65
+ DOUBLE_BYTES = 0xfb # 111_ 11011 - Major type 7 (Float) + value: 26
66
+
67
+ # https://www.rfc-editor.org/rfc/rfc8949.html#tags
68
+ TAG_TYPE_EPOCH = 1
69
+ TAG_BIGNUM_BASE = 2
70
+ TAG_TYPE_BIGDEC = 4
71
+
72
+ MAX_INTEGER = 18_446_744_073_709_551_616 # 2^64
73
+
74
+ def head(major_type, value)
75
+ @buffer <<
76
+ case value
77
+ when 0...24
78
+ [major_type + value].pack('C') # 8-bit unsigned
79
+ when 0...256
80
+ [major_type + 24, value].pack('CC')
81
+ when 0...65_536
82
+ [major_type + 25, value].pack('Cn')
83
+ when 0...4_294_967_296
84
+ [major_type + 26, value].pack('CN')
85
+ when 0...MAX_INTEGER
86
+ [major_type + 27, value].pack('CQ>')
87
+ else
88
+ raise Error, "Value is too large to encode: #{value}"
89
+ end
90
+ end
91
+
92
+ # streaming style, lower level interface
93
+ def add_integer(value)
94
+ major_type =
95
+ if value.negative?
96
+ value = -1 - value
97
+ MAJOR_TYPE_NEGATIVE_INT
98
+ else
99
+ MAJOR_TYPE_UNSIGNED_INT
100
+ end
101
+ head(major_type, value)
102
+ end
103
+
104
+ def add_bignum(value)
105
+ major_type =
106
+ if value.negative?
107
+ value = -1 - value
108
+ MAJOR_TYPE_NEGATIVE_INT
109
+ else
110
+ MAJOR_TYPE_UNSIGNED_INT
111
+ end
112
+ s = bignum_to_bytes(value)
113
+ head(MAJOR_TYPE_TAG, TAG_BIGNUM_BASE + (major_type >> 5))
114
+ head(MAJOR_TYPE_BYTE_STR, s.bytesize)
115
+ @buffer << s
116
+ end
117
+
118
+ # A decimal fraction or a bigfloat is represented as a tagged array
119
+ # that contains exactly two integer numbers:
120
+ # an exponent e and a mantissa m
121
+ # decimal fractions are always represented with a base of 10
122
+ # See: https://www.rfc-editor.org/rfc/rfc8949.html#name-decimal-fractions-and-bigfl
123
+ def add_big_decimal(value)
124
+ if value.infinite? == 1
125
+ return add_float(value.infinite? * Float::INFINITY)
126
+ elsif value.nan?
127
+ return add_float(Float::NAN)
128
+ end
129
+
130
+ head(MAJOR_TYPE_TAG, TAG_TYPE_BIGDEC)
131
+ sign, digits, base, exp = value.split
132
+ # Ruby BigDecimal digits of XXX are used as 0.XXX, convert
133
+ exp = exp - digits.size
134
+ digits = sign * digits.to_i
135
+ start_array(2)
136
+ add_auto_integer(exp)
137
+ add_auto_integer(digits)
138
+ end
139
+
140
+ def add_auto_integer(value)
141
+ major_type =
142
+ if value.negative?
143
+ value = -1 - value
144
+ MAJOR_TYPE_NEGATIVE_INT
145
+ else
146
+ MAJOR_TYPE_UNSIGNED_INT
147
+ end
148
+
149
+ if value >= MAX_INTEGER
150
+ s = bignum_to_bytes(value)
151
+ head(MAJOR_TYPE_TAG, TAG_BIGNUM_BASE + (major_type >> 5))
152
+ head(MAJOR_TYPE_BYTE_STR, s.bytesize)
153
+ @buffer << s
154
+ else
155
+ head(major_type, value)
156
+ end
157
+ end
158
+
159
+ def add_float(value)
160
+ @buffer << [FLOAT_BYTES, value].pack('Cg') # single-precision
161
+ end
162
+
163
+ def add_double(value)
164
+ @buffer << [DOUBLE_BYTES, value].pack('CG') # double-precision
165
+ end
166
+
167
+ def add_auto_float(value)
168
+ if value.nan?
169
+ @buffer << FLOAT_BYTES << [value].pack('g')
170
+ else
171
+ ss = [value].pack('g') # single-precision
172
+ if ss.unpack1('g') == value
173
+ @buffer << FLOAT_BYTES << ss
174
+ else
175
+ @buffer << [DOUBLE_BYTES, value].pack('CG') # double-precision
176
+ end
177
+ end
178
+ end
179
+
180
+ def add_nil
181
+ head(MAJOR_TYPE_SIMPLE, 22)
182
+ end
183
+
184
+ def add_boolean(value)
185
+ value ? head(MAJOR_TYPE_SIMPLE, 21) : head(MAJOR_TYPE_SIMPLE, 20)
186
+ end
187
+
188
+ # Encoding MUST already be Encoding::BINARY
189
+ def add_byte_string(value)
190
+ head(MAJOR_TYPE_BYTE_STR, value.bytesize)
191
+ @buffer << value
192
+ end
193
+
194
+ def add_string(value)
195
+ value = value.encode(Encoding::UTF_8).force_encoding(Encoding::BINARY)
196
+ head(MAJOR_TYPE_STR, value.bytesize)
197
+ @buffer << value
198
+ end
199
+
200
+ # caller is responsible for adding length values
201
+ def start_array(length)
202
+ head(MAJOR_TYPE_ARRAY, length)
203
+ end
204
+
205
+ def start_indefinite_array
206
+ head(MAJOR_TYPE_ARRAY + 31, 0)
207
+ end
208
+
209
+ # caller is responsible for adding length key/value pairs
210
+ def start_map(length)
211
+ head(MAJOR_TYPE_MAP, length)
212
+ end
213
+
214
+ def start_indefinite_map
215
+ head(MAJOR_TYPE_MAP + 31, 0)
216
+ end
217
+
218
+ def end_indefinite_collection
219
+ # write the stop sequence
220
+ head(MAJOR_TYPE_SIMPLE + 31, 0)
221
+ end
222
+
223
+ def add_tag(tag)
224
+ head(MAJOR_TYPE_TAG, tag)
225
+ end
226
+
227
+ def add_time(value)
228
+ head(MAJOR_TYPE_TAG, TAG_TYPE_EPOCH)
229
+ epoch_ms = (value.to_f * 1000).to_i
230
+ add_integer(epoch_ms)
231
+ end
232
+
233
+ def bignum_to_bytes(value)
234
+ s = String.new
235
+ while value != 0
236
+ s << (value & 0xFF)
237
+ value >>= 8
238
+ end
239
+ s.reverse!
240
+ end
241
+ end
242
+ end
243
+ end
@@ -0,0 +1,106 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Aws
4
+ # @api private
5
+ module Cbor
6
+
7
+ # CBOR Tagged data (Major type 6).
8
+ # A Tag consists of a tag number and a value.
9
+ # In the extended generic data model, a tag number's definition
10
+ # describes the additional semantics conveyed with the tag number.
11
+ # # @!method initialize(*args)
12
+ # @option args [Integer] :tag The tag number.
13
+ # @option args [Object] :value The tag's content.
14
+ # @!attribute tag
15
+ # The tag number.
16
+ # @return [Integer]
17
+ # @!attribute value
18
+ # The tag's content.
19
+ # @return [Object]
20
+ Tagged = Struct.new(:tag, :value)
21
+
22
+ class Error < StandardError; end
23
+
24
+ class OutOfBytesError < Error
25
+ def initialize(n, left)
26
+ super("Out of bytes. Trying to read #{n} bytes but buffer contains only #{left}")
27
+ end
28
+ end
29
+
30
+ class UnknownTypeError < Error
31
+ def initialize(type)
32
+ super("Unable to encode #{type}")
33
+ end
34
+ end
35
+
36
+ class ExtraBytesError < Error
37
+ def initialize(pos, size)
38
+ super("Extra bytes follow after decoding item. Read #{pos} / #{size} bytes")
39
+ end
40
+ end
41
+
42
+ class UnexpectedBreakCodeError < Error; end
43
+
44
+ class UnexpectedAdditionalInformationError < Error
45
+ def initialize(add_info)
46
+ super("Unexpected additional information: #{add_info}")
47
+ end
48
+ end
49
+
50
+ class << self
51
+ # @param [Symbol,Class] engine
52
+ # Must be one of the following values:
53
+ #
54
+ # * :cbor
55
+ #
56
+ def engine=(engine)
57
+ @engine = Class === engine ? engine : load_engine(engine)
58
+ end
59
+
60
+ # @return [Class] Returns the default engine.
61
+ # One of:
62
+ #
63
+ # * {CborEngine}
64
+ #
65
+ def engine
66
+ set_default_engine unless @engine
67
+ @engine
68
+ end
69
+
70
+ def encode(data)
71
+ @engine.encode(data)
72
+ end
73
+
74
+ def decode(bytes)
75
+ bytes.force_encoding(Encoding::BINARY)
76
+ @engine.decode(bytes)
77
+ end
78
+
79
+ def set_default_engine
80
+ [:cbor].each do |name|
81
+ @engine ||= try_load_engine(name)
82
+ end
83
+
84
+ unless @engine
85
+ raise 'Unable to find a compatible cbor library.'
86
+ end
87
+ end
88
+
89
+ private
90
+
91
+ def load_engine(name)
92
+ require "aws-sdk-core/cbor/#{name}_engine"
93
+ const_name = name[0].upcase + name[1..-1] + 'Engine'
94
+ const_get(const_name)
95
+ end
96
+
97
+ def try_load_engine(name)
98
+ load_engine(name)
99
+ rescue LoadError
100
+ false
101
+ end
102
+ end
103
+
104
+ set_default_engine
105
+ end
106
+ end
@@ -308,10 +308,11 @@ module Aws
308
308
  def protocol_helper
309
309
  case config.api.metadata['protocol']
310
310
  when 'json' then Stubbing::Protocols::Json
311
- when 'query' then Stubbing::Protocols::Query
312
- when 'ec2' then Stubbing::Protocols::EC2
313
311
  when 'rest-json' then Stubbing::Protocols::RestJson
314
312
  when 'rest-xml' then Stubbing::Protocols::RestXml
313
+ when 'query' then Stubbing::Protocols::Query
314
+ when 'ec2' then Stubbing::Protocols::EC2
315
+ when 'smithy-rpc-v2-cbor' then Stubbing::Protocols::RpcV2
315
316
  when 'api-gateway' then Stubbing::Protocols::ApiGateway
316
317
  else raise "unsupported protocol"
317
318
  end.new
@@ -11,7 +11,7 @@ module Aws
11
11
 
12
12
  # @return [Boolean]
13
13
  def set?
14
- !!credentials && credentials.set?
14
+ !!@credentials && @credentials.set?
15
15
  end
16
16
 
17
17
  end
@@ -183,7 +183,7 @@ module Aws
183
183
 
184
184
  def open_connection
185
185
  uri = URI.parse(@endpoint)
186
- http = Net::HTTP.new(uri.hostname || @endpoint, @port || uri.port)
186
+ http = Net::HTTP.new(uri.hostname || @endpoint, uri.port || @port)
187
187
  http.open_timeout = @http_open_timeout
188
188
  http.read_timeout = @http_read_timeout
189
189
  http.set_debug_output(@http_debug_output) if @http_debug_output
@@ -207,7 +207,8 @@ module Aws
207
207
  end
208
208
  rescue TokenFileReadError, InvalidTokenError
209
209
  raise
210
- rescue StandardError
210
+ rescue StandardError => e
211
+ warn("Error retrieving ECS Credentials: #{e.message}")
211
212
  '{}'
212
213
  end
213
214
 
@@ -28,7 +28,11 @@ module Aws
28
28
 
29
29
  val = if (index = parts.first[BRACKET_REGEX, 1])
30
30
  # remove brackets and index from part before indexing
31
- value[parts.first.gsub(BRACKET_REGEX, '')][index.to_i]
31
+ if (base = parts.first.gsub(BRACKET_REGEX, '')) && !base.empty?
32
+ value[base][index.to_i]
33
+ else
34
+ value[index.to_i]
35
+ end
32
36
  else
33
37
  value[parts.first]
34
38
  end
@@ -0,0 +1,41 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Aws
4
+ class ErrorHandler < Seahorse::Client::Handler
5
+
6
+ private
7
+
8
+ def error(context)
9
+ body = context.http_response.body_contents
10
+ if body.empty?
11
+ code, message, data = http_status_error(context)
12
+ else
13
+ code, message, data = extract_error(body, context)
14
+ end
15
+ build_error(context, code, message, data)
16
+ end
17
+
18
+ def build_error(context, code, message, data)
19
+ errors_module = context.client.class.errors_module
20
+ errors_module.error_class(code).new(context, message, data)
21
+ end
22
+
23
+ def http_status_error(context)
24
+ [http_status_error_code(context), '', EmptyStructure.new]
25
+ end
26
+
27
+ def http_status_error_code(context)
28
+ status_code = context.http_response.status_code
29
+ {
30
+ 302 => 'MovedTemporarily',
31
+ 304 => 'NotModified',
32
+ 400 => 'BadRequest',
33
+ 403 => 'Forbidden',
34
+ 404 => 'NotFound',
35
+ 412 => 'PreconditionFailed',
36
+ 413 => 'RequestEntityTooLarge',
37
+ }[status_code] || "Http#{status_code}Error"
38
+ end
39
+
40
+ end
41
+ end
@@ -6,7 +6,6 @@ module Aws
6
6
  def initialize
7
7
  @listeners = {}
8
8
  @validate_event = true
9
- @status = :sleep
10
9
  @signal_queue = Queue.new
11
10
  end
12
11
 
@@ -40,25 +39,10 @@ module Aws
40
39
  Aws::ParamValidator.validate!(
41
40
  @encoder.rules.shape.member(type), params)
42
41
  end
43
- _ready_for_events?
44
42
  @stream.data(
45
43
  @encoder.encode(type, params),
46
44
  end_stream: type == :end_stream
47
45
  )
48
46
  end
49
-
50
- private
51
-
52
- def _ready_for_events?
53
- return true if @status == :ready
54
-
55
- # blocked until once initial 200 response is received
56
- # signal will be available in @signal_queue
57
- # and this check will no longer be blocked
58
- @signal_queue.pop
59
- @status = :ready
60
- true
61
- end
62
-
63
47
  end
64
48
  end
@@ -215,7 +215,8 @@ module Aws
215
215
  _get_credentials(conn, token)
216
216
  end
217
217
  end
218
- rescue
218
+ rescue => e
219
+ warn("Error retrieving instance profile credentials: #{e}")
219
220
  '{}'
220
221
  end
221
222
  end
@@ -261,7 +262,7 @@ module Aws
261
262
 
262
263
  def open_connection
263
264
  uri = URI.parse(@endpoint)
264
- http = Net::HTTP.new(uri.hostname || @endpoint, @port || uri.port)
265
+ http = Net::HTTP.new(uri.hostname || @endpoint, uri.port || @port)
265
266
  http.open_timeout = @http_open_timeout
266
267
  http.read_timeout = @http_read_timeout
267
268
  http.set_debug_output(@http_debug_output) if @http_debug_output
@@ -8,7 +8,7 @@ module Aws
8
8
 
9
9
  include Seahorse::Model::Shapes
10
10
 
11
- def initialize(rules)
11
+ def initialize(rules, _options = {})
12
12
  @rules = rules
13
13
  end
14
14
 
@@ -20,6 +20,8 @@ module Aws
20
20
  private
21
21
 
22
22
  def structure(ref, values)
23
+ return nil if values.nil?
24
+
23
25
  shape = ref.shape
24
26
  values.each_pair.with_object({}) do |(key, value), data|
25
27
  if shape.member?(key) && !value.nil?
@@ -31,11 +33,15 @@ module Aws
31
33
  end
32
34
 
33
35
  def list(ref, values)
36
+ return nil if values.nil?
37
+
34
38
  member_ref = ref.shape.member
35
39
  values.collect { |value| format(member_ref, value) }
36
40
  end
37
41
 
38
42
  def map(ref, values)
43
+ return nil if values.nil?
44
+
39
45
  value_ref = ref.shape.value
40
46
  values.each.with_object({}) do |(key, value), data|
41
47
  data[key] = format(value_ref, value)
@@ -49,6 +55,7 @@ module Aws
49
55
  when MapShape then map(ref, value)
50
56
  when TimestampShape then timestamp(ref, value)
51
57
  when BlobShape then encode(value)
58
+ when FloatShape then Util.serialize_number(value)
52
59
  else value
53
60
  end
54
61
  end
@@ -2,10 +2,8 @@
2
2
 
3
3
  module Aws
4
4
  module Json
5
- class ErrorHandler < Xml::ErrorHandler
5
+ class ErrorHandler < Aws::ErrorHandler
6
6
 
7
- # @param [Seahorse::Client::RequestContext] context
8
- # @return [Seahorse::Client::Response]
9
7
  def call(context)
10
8
  @handler.call(context).on(300..599) do |response|
11
9
  response.error = error(context)
@@ -19,7 +17,7 @@ module Aws
19
17
  json = Json.load(body)
20
18
  code = error_code(json, context)
21
19
  message = error_message(code, json)
22
- data = parse_error_data(context, code)
20
+ data = parse_error_data(context, body, code)
23
21
  [code, message, data]
24
22
  rescue Json::ParseError
25
23
  [http_status_error_code(context), '', EmptyStructure.new]
@@ -48,7 +46,7 @@ module Aws
48
46
  end
49
47
 
50
48
  def remove_prefix(error_code, context)
51
- if prefix = context.config.api.metadata['errorPrefix']
49
+ if (prefix = context.config.api.metadata['errorPrefix'])
52
50
  error_code.sub(/^#{prefix}/, '')
53
51
  else
54
52
  error_code
@@ -63,22 +61,29 @@ module Aws
63
61
  end
64
62
  end
65
63
 
66
- def parse_error_data(context, code)
64
+ def parse_error_data(context, body, code)
67
65
  data = EmptyStructure.new
68
- if error_rules = context.operation.errors
66
+ if (error_rules = context.operation.errors)
69
67
  error_rules.each do |rule|
70
68
  # match modeled shape name with the type(code) only
71
69
  # some type(code) might contains invalid characters
72
70
  # such as ':' (efs) etc
73
71
  match = rule.shape.name == code.gsub(/[^^a-zA-Z0-9]/, '')
74
- if match && rule.shape.members.any?
75
- data = Parser.new(rule).parse(context.http_response.body_contents)
76
- end
72
+ next unless match && rule.shape.members.any?
73
+
74
+ data = Parser.new(rule).parse(body)
75
+ # errors support HTTP bindings
76
+ apply_error_headers(rule, context, data)
77
77
  end
78
78
  end
79
79
  data
80
80
  end
81
81
 
82
+ def apply_error_headers(rule, context, data)
83
+ headers = Aws::Rest::Response::Headers.new(rule)
84
+ headers.apply(context.http_response, data)
85
+ end
86
+
82
87
  end
83
88
  end
84
89
  end
@@ -12,8 +12,7 @@ module Aws
12
12
  build_request(context)
13
13
  response = @handler.call(context)
14
14
  response.on(200..299) { |resp| parse_response(resp) }
15
- response.on(200..599) { |resp| apply_request_id(context) }
16
- response
15
+ response.on(200..599) { |_resp| apply_request_id(context) }
17
16
  end
18
17
 
19
18
  private
@@ -38,10 +37,10 @@ module Aws
38
37
  end
39
38
 
40
39
  def parse_body(context)
40
+ json = context.http_response.body_contents
41
41
  if simple_json?(context)
42
- Json.load(context.http_response.body_contents)
43
- elsif rules = context.operation.output
44
- json = context.http_response.body_contents
42
+ Json.load(json)
43
+ elsif (rules = context.operation.output)
45
44
  if json.is_a?(Array)
46
45
  # an array of emitted events
47
46
  if json[0].respond_to?(:response)
@@ -62,7 +61,7 @@ module Aws
62
61
  Parser.new(
63
62
  rules,
64
63
  query_compatible: query_compatible?(context)
65
- ).parse(json == '' ? '{}' : json)
64
+ ).parse(json)
66
65
  end
67
66
  else
68
67
  EmptyStructure.new
@@ -1,8 +1,10 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'json'
4
+
3
5
  module Aws
4
6
  module Json
5
- module JSONEngine
7
+ module JsonEngine
6
8
  class << self
7
9
  def load(json)
8
10
  JSON.parse(json)
@@ -1,10 +1,16 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'oj'
4
+
3
5
  module Aws
4
6
  module Json
5
7
  module OjEngine
6
8
  # @api private
7
- LOAD_OPTIONS = { mode: :compat, symbol_keys: false, empty_string: false }.freeze
9
+ LOAD_OPTIONS = {
10
+ mode: :compat,
11
+ symbol_keys: false,
12
+ empty_string: false
13
+ }.freeze
8
14
 
9
15
  # @api private
10
16
  DUMP_OPTIONS = { mode: :compat }.freeze