aws-sdk-core 3.185.1 → 3.214.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (177) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +409 -0
  3. data/VERSION +1 -1
  4. data/lib/aws-defaults/default_configuration.rb +1 -2
  5. data/lib/aws-defaults.rb +4 -1
  6. data/lib/aws-sdk-core/assume_role_credentials.rb +12 -5
  7. data/lib/aws-sdk-core/assume_role_web_identity_credentials.rb +13 -7
  8. data/lib/aws-sdk-core/binary/decode_handler.rb +3 -9
  9. data/lib/aws-sdk-core/binary/encode_handler.rb +1 -1
  10. data/lib/aws-sdk-core/binary/event_builder.rb +34 -37
  11. data/lib/aws-sdk-core/binary/event_stream_decoder.rb +1 -0
  12. data/lib/aws-sdk-core/binary/event_stream_encoder.rb +4 -3
  13. data/lib/aws-sdk-core/cbor/decoder.rb +310 -0
  14. data/lib/aws-sdk-core/cbor/encoder.rb +243 -0
  15. data/lib/aws-sdk-core/cbor.rb +53 -0
  16. data/lib/aws-sdk-core/client_side_monitoring.rb +9 -0
  17. data/lib/aws-sdk-core/client_stubs.rb +23 -19
  18. data/lib/aws-sdk-core/credential_provider.rb +1 -1
  19. data/lib/aws-sdk-core/credential_provider_chain.rb +13 -6
  20. data/lib/aws-sdk-core/credentials.rb +13 -6
  21. data/lib/aws-sdk-core/ec2_metadata.rb +1 -1
  22. data/lib/aws-sdk-core/ecs_credentials.rb +78 -11
  23. data/lib/aws-sdk-core/endpoints/endpoint.rb +3 -1
  24. data/lib/aws-sdk-core/endpoints/matchers.rb +6 -9
  25. data/lib/aws-sdk-core/endpoints.rb +74 -18
  26. data/lib/aws-sdk-core/error_handler.rb +41 -0
  27. data/lib/aws-sdk-core/errors.rb +11 -2
  28. data/lib/aws-sdk-core/event_emitter.rb +0 -16
  29. data/lib/aws-sdk-core/instance_profile_credentials.rb +55 -32
  30. data/lib/aws-sdk-core/json/builder.rb +8 -1
  31. data/lib/aws-sdk-core/json/error_handler.rb +17 -11
  32. data/lib/aws-sdk-core/json/handler.rb +13 -6
  33. data/lib/aws-sdk-core/json/json_engine.rb +3 -1
  34. data/lib/aws-sdk-core/json/oj_engine.rb +7 -1
  35. data/lib/aws-sdk-core/json/parser.rb +32 -2
  36. data/lib/aws-sdk-core/json.rb +43 -14
  37. data/lib/aws-sdk-core/log/param_filter.rb +2 -2
  38. data/lib/aws-sdk-core/log.rb +10 -0
  39. data/lib/aws-sdk-core/lru_cache.rb +75 -0
  40. data/lib/aws-sdk-core/pageable_response.rb +1 -1
  41. data/lib/aws-sdk-core/param_validator.rb +7 -2
  42. data/lib/aws-sdk-core/plugins/bearer_authorization.rb +2 -0
  43. data/lib/aws-sdk-core/plugins/checksum_algorithm.rb +6 -3
  44. data/lib/aws-sdk-core/plugins/client_metrics_plugin.rb +1 -0
  45. data/lib/aws-sdk-core/plugins/client_metrics_send_plugin.rb +14 -2
  46. data/lib/aws-sdk-core/plugins/credentials_configuration.rb +9 -3
  47. data/lib/aws-sdk-core/plugins/global_configuration.rb +8 -9
  48. data/lib/aws-sdk-core/plugins/http_checksum.rb +2 -1
  49. data/lib/aws-sdk-core/plugins/invocation_id.rb +1 -11
  50. data/lib/aws-sdk-core/plugins/logging.rb +2 -0
  51. data/lib/aws-sdk-core/plugins/protocols/api_gateway.rb +3 -1
  52. data/lib/aws-sdk-core/plugins/protocols/ec2.rb +2 -24
  53. data/lib/aws-sdk-core/plugins/protocols/json_rpc.rb +6 -8
  54. data/lib/aws-sdk-core/plugins/protocols/query.rb +4 -2
  55. data/lib/aws-sdk-core/plugins/protocols/rest_json.rb +3 -15
  56. data/lib/aws-sdk-core/plugins/protocols/rest_xml.rb +3 -0
  57. data/lib/aws-sdk-core/plugins/protocols/rpc_v2.rb +17 -0
  58. data/lib/aws-sdk-core/plugins/regional_endpoint.rb +74 -25
  59. data/lib/aws-sdk-core/plugins/request_compression.rb +11 -2
  60. data/lib/aws-sdk-core/plugins/retry_errors.rb +12 -3
  61. data/lib/aws-sdk-core/plugins/sign.rb +27 -15
  62. data/lib/aws-sdk-core/plugins/signature_v2.rb +2 -1
  63. data/lib/aws-sdk-core/plugins/signature_v4.rb +2 -1
  64. data/lib/aws-sdk-core/plugins/stub_responses.rb +30 -2
  65. data/lib/aws-sdk-core/plugins/telemetry.rb +75 -0
  66. data/lib/aws-sdk-core/plugins/transfer_encoding.rb +16 -9
  67. data/lib/aws-sdk-core/plugins/user_agent.rb +70 -26
  68. data/lib/aws-sdk-core/plugins.rb +39 -0
  69. data/lib/aws-sdk-core/process_credentials.rb +47 -28
  70. data/lib/aws-sdk-core/query/ec2_handler.rb +27 -0
  71. data/lib/aws-sdk-core/query/ec2_param_builder.rb +5 -7
  72. data/lib/aws-sdk-core/query/handler.rb +4 -4
  73. data/lib/aws-sdk-core/query/param_builder.rb +2 -2
  74. data/lib/aws-sdk-core/query.rb +2 -1
  75. data/lib/aws-sdk-core/refreshing_credentials.rb +12 -6
  76. data/lib/aws-sdk-core/resources.rb +8 -0
  77. data/lib/aws-sdk-core/rest/content_type_handler.rb +60 -0
  78. data/lib/aws-sdk-core/rest/handler.rb +3 -4
  79. data/lib/aws-sdk-core/rest/request/body.rb +32 -5
  80. data/lib/aws-sdk-core/rest/request/endpoint.rb +24 -4
  81. data/lib/aws-sdk-core/rest/request/headers.rb +14 -6
  82. data/lib/aws-sdk-core/rest/request/querystring_builder.rb +62 -36
  83. data/lib/aws-sdk-core/rest/response/body.rb +15 -1
  84. data/lib/aws-sdk-core/rest/response/header_list_parser.rb +79 -0
  85. data/lib/aws-sdk-core/rest/response/headers.rb +8 -3
  86. data/lib/aws-sdk-core/rest.rb +1 -0
  87. data/lib/aws-sdk-core/rpc_v2/builder.rb +62 -0
  88. data/lib/aws-sdk-core/rpc_v2/cbor_engine.rb +18 -0
  89. data/lib/aws-sdk-core/rpc_v2/content_type_handler.rb +47 -0
  90. data/lib/aws-sdk-core/rpc_v2/error_handler.rb +85 -0
  91. data/lib/aws-sdk-core/rpc_v2/handler.rb +79 -0
  92. data/lib/aws-sdk-core/rpc_v2/parser.rb +90 -0
  93. data/lib/aws-sdk-core/rpc_v2.rb +69 -0
  94. data/lib/aws-sdk-core/shared_config.rb +7 -2
  95. data/lib/aws-sdk-core/shared_credentials.rb +0 -7
  96. data/lib/aws-sdk-core/sso_credentials.rb +2 -1
  97. data/lib/aws-sdk-core/stubbing/protocols/ec2.rb +12 -11
  98. data/lib/aws-sdk-core/stubbing/protocols/json.rb +11 -10
  99. data/lib/aws-sdk-core/stubbing/protocols/query.rb +7 -6
  100. data/lib/aws-sdk-core/stubbing/protocols/rest.rb +2 -1
  101. data/lib/aws-sdk-core/stubbing/protocols/rest_json.rb +9 -8
  102. data/lib/aws-sdk-core/stubbing/protocols/rest_xml.rb +6 -5
  103. data/lib/aws-sdk-core/stubbing/protocols/rpc_v2.rb +39 -0
  104. data/lib/aws-sdk-core/stubbing.rb +22 -0
  105. data/lib/aws-sdk-core/telemetry/base.rb +177 -0
  106. data/lib/aws-sdk-core/telemetry/no_op.rb +70 -0
  107. data/lib/aws-sdk-core/telemetry/otel.rb +235 -0
  108. data/lib/aws-sdk-core/telemetry/span_kind.rb +22 -0
  109. data/lib/aws-sdk-core/telemetry/span_status.rb +59 -0
  110. data/lib/aws-sdk-core/telemetry.rb +78 -0
  111. data/lib/aws-sdk-core/util.rb +39 -0
  112. data/lib/aws-sdk-core/waiters/poller.rb +10 -5
  113. data/lib/aws-sdk-core/xml/builder.rb +17 -9
  114. data/lib/aws-sdk-core/xml/error_handler.rb +32 -42
  115. data/lib/aws-sdk-core/xml/parser/frame.rb +4 -20
  116. data/lib/aws-sdk-core/xml/parser/stack.rb +2 -0
  117. data/lib/aws-sdk-core/xml/parser.rb +2 -6
  118. data/lib/aws-sdk-core.rb +82 -107
  119. data/lib/aws-sdk-sso/client.rb +119 -55
  120. data/lib/aws-sdk-sso/client_api.rb +7 -0
  121. data/lib/aws-sdk-sso/endpoint_parameters.rb +9 -6
  122. data/lib/aws-sdk-sso/endpoints.rb +2 -54
  123. data/lib/aws-sdk-sso/plugins/endpoints.rb +23 -22
  124. data/lib/aws-sdk-sso/types.rb +1 -0
  125. data/lib/aws-sdk-sso.rb +15 -11
  126. data/lib/aws-sdk-ssooidc/client.rb +504 -83
  127. data/lib/aws-sdk-ssooidc/client_api.rb +83 -1
  128. data/lib/aws-sdk-ssooidc/endpoint_parameters.rb +9 -6
  129. data/lib/aws-sdk-ssooidc/endpoint_provider.rb +2 -2
  130. data/lib/aws-sdk-ssooidc/endpoints.rb +2 -40
  131. data/lib/aws-sdk-ssooidc/errors.rb +52 -0
  132. data/lib/aws-sdk-ssooidc/plugins/endpoints.rb +23 -20
  133. data/lib/aws-sdk-ssooidc/types.rb +373 -51
  134. data/lib/aws-sdk-ssooidc.rb +15 -11
  135. data/lib/aws-sdk-sts/client.rb +334 -105
  136. data/lib/aws-sdk-sts/client_api.rb +36 -10
  137. data/lib/aws-sdk-sts/customizations.rb +5 -1
  138. data/lib/aws-sdk-sts/endpoint_parameters.rb +10 -9
  139. data/lib/aws-sdk-sts/endpoint_provider.rb +2 -2
  140. data/lib/aws-sdk-sts/endpoints.rb +2 -118
  141. data/lib/aws-sdk-sts/plugins/endpoints.rb +23 -30
  142. data/lib/aws-sdk-sts/presigner.rb +1 -1
  143. data/lib/aws-sdk-sts/types.rb +188 -30
  144. data/lib/aws-sdk-sts.rb +15 -11
  145. data/lib/seahorse/client/async_base.rb +1 -1
  146. data/lib/seahorse/client/async_response.rb +19 -0
  147. data/lib/seahorse/client/base.rb +18 -7
  148. data/lib/seahorse/client/h2/handler.rb +14 -3
  149. data/lib/seahorse/client/handler.rb +1 -1
  150. data/lib/seahorse/client/net_http/connection_pool.rb +11 -11
  151. data/lib/seahorse/client/net_http/handler.rb +21 -9
  152. data/lib/seahorse/client/net_http/patches.rb +1 -4
  153. data/lib/seahorse/client/plugin.rb +9 -0
  154. data/lib/seahorse/client/plugins/endpoint.rb +0 -1
  155. data/lib/seahorse/client/plugins/h2.rb +3 -3
  156. data/lib/seahorse/client/plugins/net_http.rb +57 -16
  157. data/lib/seahorse/client/request_context.rb +8 -1
  158. data/lib/seahorse/model/shapes.rb +2 -2
  159. data/sig/aws-sdk-core/client_stubs.rbs +10 -0
  160. data/sig/aws-sdk-core/errors.rbs +22 -0
  161. data/sig/aws-sdk-core/resources/collection.rbs +21 -0
  162. data/sig/aws-sdk-core/structure.rbs +4 -0
  163. data/sig/aws-sdk-core/telemetry/base.rbs +46 -0
  164. data/sig/aws-sdk-core/telemetry/otel.rbs +22 -0
  165. data/sig/aws-sdk-core/telemetry/span_kind.rbs +15 -0
  166. data/sig/aws-sdk-core/telemetry/span_status.rbs +24 -0
  167. data/sig/aws-sdk-core/waiters/errors.rbs +20 -0
  168. data/sig/aws-sdk-core.rbs +7 -0
  169. data/sig/seahorse/client/base.rbs +25 -0
  170. data/sig/seahorse/client/handler_builder.rbs +16 -0
  171. data/sig/seahorse/client/response.rbs +61 -0
  172. metadata +61 -19
  173. /data/lib/aws-sdk-core/xml/parser/{engines/libxml.rb → libxml_engine.rb} +0 -0
  174. /data/lib/aws-sdk-core/xml/parser/{engines/nokogiri.rb → nokogiri_engine.rb} +0 -0
  175. /data/lib/aws-sdk-core/xml/parser/{engines/oga.rb → oga_engine.rb} +0 -0
  176. /data/lib/aws-sdk-core/xml/parser/{engines/ox.rb → ox_engine.rb} +0 -0
  177. /data/lib/aws-sdk-core/xml/parser/{engines/rexml.rb → rexml_engine.rb} +0 -0
@@ -0,0 +1,310 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Aws
4
+ module Cbor
5
+ # Pure Ruby implementation of CBOR Decoder
6
+ class Decoder
7
+ def initialize(bytes)
8
+ @buffer = bytes
9
+ @pos = 0
10
+ end
11
+
12
+ def decode
13
+ return nil if @buffer.nil? || @buffer.empty?
14
+
15
+ val = decode_item
16
+ return val unless @pos != @buffer.size
17
+
18
+ raise ExtraBytesError.new(@pos, @buffer.size)
19
+ end
20
+
21
+ private
22
+
23
+ FIVE_BIT_MASK = 0x1F
24
+ TAG_TYPE_EPOCH = 1
25
+ TAG_TYPE_BIGNUM = 2
26
+ TAG_TYPE_NEG_BIGNUM = 3
27
+ TAG_TYPE_BIGDEC = 4
28
+
29
+ # high level, generic decode. Based on the next type. Consumes and returns
30
+ # the next item as a ruby object.
31
+ def decode_item
32
+ case (next_type = peek_type)
33
+ when :array
34
+ read_array.times.map { decode_item }
35
+ when :map
36
+ read_map.times.map { [read_string, decode_item] }.to_h
37
+ when :indefinite_array
38
+ read_start_indefinite_array
39
+ value = []
40
+ value << decode_item until peek_type == :break_stop_code
41
+ read_end_indefinite_collection
42
+ value
43
+ when :indefinite_map
44
+ read_start_indefinite_map
45
+ value = {}
46
+ value[read_string] = decode_item until peek_type == :break_stop_code
47
+ read_end_indefinite_collection
48
+ value
49
+ when :indefinite_binary_string
50
+ read_info
51
+ value = String.new
52
+ value << read_binary_string until peek_type == :break_stop_code
53
+ read_end_indefinite_collection
54
+ value
55
+ when :indefinite_string
56
+ read_info
57
+ value = String.new
58
+ value << read_string until peek_type == :break_stop_code
59
+ read_end_indefinite_collection
60
+ value.force_encoding(Encoding::UTF_8)
61
+ when :tag
62
+ case (tag = read_tag)
63
+ when TAG_TYPE_EPOCH
64
+ type = peek_type
65
+ item = decode_item
66
+ item /= 1000.0 if type == :integer
67
+ Time.at(item)
68
+ when TAG_TYPE_BIGNUM, TAG_TYPE_NEG_BIGNUM
69
+ read_bignum(tag)
70
+ when TAG_TYPE_BIGDEC
71
+ read_big_decimal
72
+ else
73
+ Tagged.new(tag, decode_item)
74
+ end
75
+ when :break_stop_code
76
+ raise UnexpectedBreakCodeError
77
+ else
78
+ send("read_#{next_type}")
79
+ end
80
+ end
81
+
82
+ # low level streaming interface
83
+ def peek_type
84
+ ib = peek(1).ord
85
+ add_info = ib & FIVE_BIT_MASK
86
+ major_type = ib >> 5
87
+ case major_type
88
+ when 0, 1 then :integer
89
+ when 2
90
+ add_info == 31 ? :indefinite_binary_string : :binary_string
91
+ when 3
92
+ add_info == 31 ? :indefinite_string : :string
93
+ when 4
94
+ add_info == 31 ? :indefinite_array : :array
95
+ when 5
96
+ add_info == 31 ? :indefinite_map : :map
97
+ when 6 then :tag
98
+ when 7 # simple or float
99
+ case add_info
100
+ when 20, 21 then :boolean
101
+ when 22 then :nil
102
+ when 23 then :undefined # for smithy, this should be parsed as nil
103
+ when 25 then :half
104
+ when 26 then :float
105
+ when 27 then :double
106
+ when 31 then :break_stop_code
107
+ else
108
+ :reserved_undefined
109
+ end
110
+ end
111
+ end
112
+
113
+ def read_break_stop_code
114
+ read_info
115
+ :break_stop_code
116
+ end
117
+
118
+ def read_integer
119
+ major_type, add_info = read_info
120
+
121
+ val = read_count(add_info)
122
+ case major_type
123
+ when 0 then val
124
+ when 1 then -1 - val
125
+ else
126
+ raise Error,
127
+ "Expected Integer (0,1) got major type: #{major_type}"
128
+ end
129
+ end
130
+
131
+ def read_binary_string
132
+ _major_type, add_info = read_info
133
+ take(read_count(add_info)).force_encoding(Encoding::BINARY)
134
+ end
135
+
136
+ def read_string
137
+ _major_type, add_info = read_info
138
+ take(read_count(add_info)).force_encoding(Encoding::UTF_8)
139
+ end
140
+
141
+ # returns only the length of the array, caller must read the correct number of values after this
142
+ def read_array
143
+ _major_type, add_info = read_info
144
+ read_count(add_info)
145
+ end
146
+
147
+ # returns nothing but consumes and checks the type/info.
148
+ # Caller must keep reading until encountering the stop sequence
149
+ def read_start_indefinite_array
150
+ read_info
151
+ end
152
+
153
+ # returns nothing but consumes and checks the type/info.
154
+ # Caller must keep reading until encountering the stop sequence
155
+ def read_start_indefinite_map
156
+ read_info
157
+ end
158
+
159
+ # returns nothing but consumes and checks the type/info.
160
+ def read_end_indefinite_collection
161
+ read_info
162
+ end
163
+
164
+ # returns only the length of the array, caller must read the correct number of key value pairs after this
165
+ def read_map
166
+ _major_type, add_info = read_info
167
+ read_count(add_info)
168
+ end
169
+
170
+ # returns only the tag, caller must interpret the tag and read another value as appropriate
171
+ def read_tag
172
+ _major_type, add_info = read_info
173
+ read_count(add_info)
174
+ end
175
+
176
+ def read_reserved_undefined
177
+ _major_type, add_info = read_info
178
+ raise Error,
179
+ "Undefined reserved additional information: #{add_info}"
180
+ end
181
+
182
+ def read_boolean
183
+ _major_type, add_info = read_info
184
+ case add_info
185
+ when 20 then false
186
+ when 21 then true
187
+ else
188
+ raise Error,
189
+ 'Invalid Boolean simple type, expected add_info of 20 or 21, ' \
190
+ "got: #{add_info}"
191
+ end
192
+ end
193
+
194
+ def read_nil
195
+ read_info
196
+ nil
197
+ end
198
+
199
+ def read_undefined
200
+ read_info
201
+ :undefined
202
+ end
203
+
204
+ # 16 bit IEEE 754 half-precision floats
205
+ # Support decoding only
206
+ # format:
207
+ # sign - 1 bit
208
+ # exponent - 5 bits
209
+ # precision - 10 bits
210
+ def read_half
211
+ read_info
212
+ b16 = take(2).unpack1('n')
213
+ exp = (b16 >> 10) & 0x1f
214
+ mant = b16 & 0x3ff
215
+ val =
216
+ case exp
217
+ when 0
218
+ Math.ldexp(mant, -24)
219
+ when 31
220
+ mant.zero? ? Float::INFINITY : Float::NAN
221
+ else
222
+ # exp bias is 15, but to use ldexp we divide by 1024 (2^10) to get
223
+ # exp-15-10
224
+ Math.ldexp(1024 + mant, exp - 25)
225
+ end
226
+ if (b16[15]).zero?
227
+ val
228
+ else
229
+ -val
230
+ end
231
+ end
232
+
233
+ def read_float
234
+ read_info
235
+ take(4).unpack1('g')
236
+ end
237
+
238
+ def read_double
239
+ read_info
240
+ take(8).unpack1('G')
241
+ end
242
+
243
+ # tag type 2 or 3
244
+ def read_bignum(tag_value)
245
+ _major_type, add_info = read_info
246
+ bstr = take(read_count(add_info))
247
+ v = bstr.bytes.inject(0) do |sum, b|
248
+ sum <<= 8
249
+ sum + b
250
+ end
251
+ case tag_value
252
+ when 2 then v
253
+ when 3 then -1 - v
254
+ else
255
+ raise Error,
256
+ 'Invalid Tag value for BigNum, ' \
257
+ "expected 2 or 3, got: #{tag_value}"
258
+ end
259
+ end
260
+
261
+ # A decimal fraction or a bigfloat is represented as a tagged array
262
+ # that contains exactly two integer numbers:
263
+ # an exponent e and a mantissa m
264
+ # See: https://www.rfc-editor.org/rfc/rfc8949.html#name-decimal-fractions-and-bigfl
265
+ def read_big_decimal
266
+ unless (s = read_array) == 2
267
+ raise Error, "Expected array of length 2 but length is: #{s}"
268
+ end
269
+
270
+ e = read_integer
271
+ m = read_integer
272
+ BigDecimal(m) * (BigDecimal(10)**BigDecimal(e))
273
+ end
274
+
275
+ # return a tuple of major_type, add_info
276
+ def read_info
277
+ ib = take(1).ord
278
+ [ib >> 5, ib & FIVE_BIT_MASK]
279
+ end
280
+
281
+ def read_count(add_info)
282
+ case add_info
283
+ when 0..23 then add_info
284
+ when 24 then take(1).ord
285
+ when 25 then take(2).unpack1('n')
286
+ when 26 then take(4).unpack1('N')
287
+ when 27 then take(8).unpack1('Q>')
288
+ when 28 then take(16).unpack1('Q>')
289
+ when 29 then take(32).unpack1('Q>')
290
+ else raise UnexpectedAdditionalInformationError, add_info
291
+ end
292
+ end
293
+
294
+ def take(n_bytes)
295
+ opos = @pos
296
+ @pos += n_bytes
297
+
298
+ return @buffer[opos, n_bytes] if @pos <= @buffer.bytesize
299
+
300
+ raise OutOfBytesError.new(n_bytes, @buffer.bytesize - @pos)
301
+ end
302
+
303
+ def peek(n_bytes)
304
+ return @buffer[@pos, n_bytes] if (@pos + n_bytes) <= @buffer.bytesize
305
+
306
+ raise OutOfBytesError.new(n_bytes, @buffer.bytesize - @pos)
307
+ end
308
+ end
309
+ end
310
+ end
@@ -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,53 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'cbor/encoder'
4
+ require_relative 'cbor/decoder'
5
+
6
+ module Aws
7
+ # @api private
8
+ module Cbor
9
+
10
+ # CBOR Tagged data (Major type 6).
11
+ # A Tag consists of a tag number and a value.
12
+ # In the extended generic data model, a tag number's definition
13
+ # describes the additional semantics conveyed with the tag number.
14
+ # # @!method initialize(*args)
15
+ # @option args [Integer] :tag The tag number.
16
+ # @option args [Object] :value The tag's content.
17
+ # @!attribute tag
18
+ # The tag number.
19
+ # @return [Integer]
20
+ # @!attribute value
21
+ # The tag's content.
22
+ # @return [Object]
23
+ Tagged = Struct.new(:tag, :value)
24
+
25
+ class Error < StandardError; end
26
+
27
+ class OutOfBytesError < Error
28
+ def initialize(n, left)
29
+ super("Out of bytes. Trying to read #{n} bytes but buffer contains only #{left}")
30
+ end
31
+ end
32
+
33
+ class UnknownTypeError < Error
34
+ def initialize(type)
35
+ super("Unable to encode #{type}")
36
+ end
37
+ end
38
+
39
+ class ExtraBytesError < Error
40
+ def initialize(pos, size)
41
+ super("Extra bytes follow after decoding item. Read #{pos} / #{size} bytes")
42
+ end
43
+ end
44
+
45
+ class UnexpectedBreakCodeError < Error; end
46
+
47
+ class UnexpectedAdditionalInformationError < Error
48
+ def initialize(add_info)
49
+ super("Unexpected additional information: #{add_info}")
50
+ end
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Aws
4
+ # setup autoloading for ClientSideMonitoring module
5
+ module ClientSideMonitoring
6
+ autoload :RequestMetrics, 'aws-sdk-core/client_side_monitoring/request_metrics'
7
+ autoload :Publisher, 'aws-sdk-core/client_side_monitoring/publisher'
8
+ end
9
+ end
@@ -24,15 +24,16 @@ module Aws
24
24
  end
25
25
 
26
26
  # When a client is stubbed allow the user to access the requests made
27
- @api_requests = []
28
-
29
- requests = @api_requests
27
+ requests = @api_requests = []
28
+ requests_mutex = @requests_mutex = Mutex.new
30
29
  self.handle do |context|
31
- requests << {
32
- operation_name: context.operation_name,
33
- params: context.params,
34
- context: context
35
- }
30
+ requests_mutex.synchronize do
31
+ requests << {
32
+ operation_name: context.operation_name,
33
+ params: context.params,
34
+ context: context
35
+ }
36
+ end
36
37
  @handler.call(context)
37
38
  end
38
39
  end
@@ -194,10 +195,12 @@ module Aws
194
195
  # is not stubbed.
195
196
  def api_requests(options = {})
196
197
  if config.stub_responses
197
- if options[:exclude_presign]
198
- @api_requests.reject {|req| req[:context][:presigned_url] }
199
- else
200
- @api_requests
198
+ @requests_mutex.synchronize do
199
+ if options[:exclude_presign]
200
+ @api_requests.reject {|req| req[:context][:presigned_url] }
201
+ else
202
+ @api_requests
203
+ end
201
204
  end
202
205
  else
203
206
  msg = 'This method is only implemented for stubbed clients, and is '\
@@ -304,13 +307,14 @@ module Aws
304
307
 
305
308
  def protocol_helper
306
309
  case config.api.metadata['protocol']
307
- when 'json' then Stubbing::Protocols::Json
308
- when 'query' then Stubbing::Protocols::Query
309
- when 'ec2' then Stubbing::Protocols::EC2
310
- when 'rest-json' then Stubbing::Protocols::RestJson
311
- when 'rest-xml' then Stubbing::Protocols::RestXml
312
- when 'api-gateway' then Stubbing::Protocols::ApiGateway
313
- else raise "unsupported protocol"
310
+ when 'json' then Stubbing::Protocols::Json
311
+ when 'rest-json' then Stubbing::Protocols::RestJson
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
316
+ when 'api-gateway' then Stubbing::Protocols::ApiGateway
317
+ else raise 'unsupported protocol'
314
318
  end.new
315
319
  end
316
320
  end
@@ -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