aws-sdk-core 3.190.2 → 3.240.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 (203) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +650 -0
  3. data/VERSION +1 -1
  4. data/lib/aws-defaults.rb +4 -1
  5. data/lib/aws-sdk-core/arn.rb +1 -3
  6. data/lib/aws-sdk-core/assume_role_credentials.rb +21 -13
  7. data/lib/aws-sdk-core/assume_role_web_identity_credentials.rb +16 -9
  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 +308 -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 +39 -58
  18. data/lib/aws-sdk-core/credential_provider.rb +5 -1
  19. data/lib/aws-sdk-core/credential_provider_chain.rb +101 -25
  20. data/lib/aws-sdk-core/credentials.rb +19 -6
  21. data/lib/aws-sdk-core/ec2_metadata.rb +1 -1
  22. data/lib/aws-sdk-core/ecs_credentials.rb +16 -14
  23. data/lib/aws-sdk-core/endpoints/endpoint.rb +3 -1
  24. data/lib/aws-sdk-core/endpoints/matchers.rb +8 -10
  25. data/lib/aws-sdk-core/endpoints.rb +101 -21
  26. data/lib/aws-sdk-core/error_handler.rb +46 -0
  27. data/lib/aws-sdk-core/errors.rb +16 -4
  28. data/lib/aws-sdk-core/event_emitter.rb +1 -17
  29. data/lib/aws-sdk-core/instance_profile_credentials.rb +148 -157
  30. data/lib/aws-sdk-core/json/builder.rb +8 -1
  31. data/lib/aws-sdk-core/json/error_handler.rb +29 -13
  32. data/lib/aws-sdk-core/json/handler.rb +6 -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 +6 -1
  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/param_formatter.rb +7 -3
  39. data/lib/aws-sdk-core/log.rb +10 -0
  40. data/lib/aws-sdk-core/login_credentials.rb +229 -0
  41. data/lib/aws-sdk-core/lru_cache.rb +75 -0
  42. data/lib/aws-sdk-core/pageable_response.rb +1 -1
  43. data/lib/aws-sdk-core/param_validator.rb +7 -2
  44. data/lib/aws-sdk-core/plugins/bearer_authorization.rb +2 -0
  45. data/lib/aws-sdk-core/plugins/checksum_algorithm.rb +347 -170
  46. data/lib/aws-sdk-core/plugins/client_metrics_plugin.rb +1 -1
  47. data/lib/aws-sdk-core/plugins/client_metrics_send_plugin.rb +14 -2
  48. data/lib/aws-sdk-core/plugins/credentials_configuration.rb +78 -56
  49. data/lib/aws-sdk-core/plugins/endpoint_pattern.rb +40 -32
  50. data/lib/aws-sdk-core/plugins/global_configuration.rb +8 -9
  51. data/lib/aws-sdk-core/plugins/http_checksum.rb +2 -8
  52. data/lib/aws-sdk-core/plugins/invocation_id.rb +1 -11
  53. data/lib/aws-sdk-core/plugins/logging.rb +2 -0
  54. data/lib/aws-sdk-core/plugins/protocols/api_gateway.rb +3 -1
  55. data/lib/aws-sdk-core/plugins/protocols/ec2.rb +2 -24
  56. data/lib/aws-sdk-core/plugins/protocols/json_rpc.rb +6 -8
  57. data/lib/aws-sdk-core/plugins/protocols/query.rb +4 -2
  58. data/lib/aws-sdk-core/plugins/protocols/rest_json.rb +3 -15
  59. data/lib/aws-sdk-core/plugins/protocols/rest_xml.rb +3 -0
  60. data/lib/aws-sdk-core/plugins/protocols/rpc_v2.rb +17 -0
  61. data/lib/aws-sdk-core/plugins/regional_endpoint.rb +74 -25
  62. data/lib/aws-sdk-core/plugins/request_compression.rb +11 -2
  63. data/lib/aws-sdk-core/plugins/retry_errors.rb +12 -3
  64. data/lib/aws-sdk-core/plugins/sign.rb +42 -26
  65. data/lib/aws-sdk-core/plugins/signature_v2.rb +2 -1
  66. data/lib/aws-sdk-core/plugins/signature_v4.rb +2 -1
  67. data/lib/aws-sdk-core/plugins/stub_responses.rb +59 -9
  68. data/lib/aws-sdk-core/plugins/telemetry.rb +75 -0
  69. data/lib/aws-sdk-core/plugins/transfer_encoding.rb +16 -9
  70. data/lib/aws-sdk-core/plugins/user_agent.rb +103 -26
  71. data/lib/aws-sdk-core/plugins.rb +39 -0
  72. data/lib/aws-sdk-core/process_credentials.rb +48 -29
  73. data/lib/aws-sdk-core/query/ec2_handler.rb +27 -0
  74. data/lib/aws-sdk-core/query/ec2_param_builder.rb +5 -7
  75. data/lib/aws-sdk-core/query/handler.rb +4 -4
  76. data/lib/aws-sdk-core/query/param_builder.rb +2 -2
  77. data/lib/aws-sdk-core/query.rb +2 -1
  78. data/lib/aws-sdk-core/refreshing_credentials.rb +8 -11
  79. data/lib/aws-sdk-core/resources.rb +8 -0
  80. data/lib/aws-sdk-core/rest/content_type_handler.rb +60 -0
  81. data/lib/aws-sdk-core/rest/handler.rb +3 -4
  82. data/lib/aws-sdk-core/rest/request/body.rb +32 -5
  83. data/lib/aws-sdk-core/rest/request/endpoint.rb +24 -4
  84. data/lib/aws-sdk-core/rest/request/headers.rb +15 -7
  85. data/lib/aws-sdk-core/rest/request/querystring_builder.rb +23 -11
  86. data/lib/aws-sdk-core/rest/response/body.rb +15 -1
  87. data/lib/aws-sdk-core/rest/response/header_list_parser.rb +79 -0
  88. data/lib/aws-sdk-core/rest/response/headers.rb +8 -3
  89. data/lib/aws-sdk-core/rest.rb +1 -0
  90. data/lib/aws-sdk-core/rpc_v2/builder.rb +62 -0
  91. data/lib/aws-sdk-core/rpc_v2/cbor_engine.rb +18 -0
  92. data/lib/aws-sdk-core/rpc_v2/content_type_handler.rb +47 -0
  93. data/lib/aws-sdk-core/rpc_v2/error_handler.rb +95 -0
  94. data/lib/aws-sdk-core/rpc_v2/handler.rb +79 -0
  95. data/lib/aws-sdk-core/rpc_v2/parser.rb +98 -0
  96. data/lib/aws-sdk-core/rpc_v2.rb +69 -0
  97. data/lib/aws-sdk-core/shared_config.rb +108 -22
  98. data/lib/aws-sdk-core/shared_credentials.rb +1 -7
  99. data/lib/aws-sdk-core/sso_credentials.rb +5 -2
  100. data/lib/aws-sdk-core/static_token_provider.rb +1 -2
  101. data/lib/aws-sdk-core/stubbing/protocols/ec2.rb +12 -11
  102. data/lib/aws-sdk-core/stubbing/protocols/json.rb +11 -10
  103. data/lib/aws-sdk-core/stubbing/protocols/query.rb +7 -6
  104. data/lib/aws-sdk-core/stubbing/protocols/rest.rb +2 -1
  105. data/lib/aws-sdk-core/stubbing/protocols/rest_json.rb +9 -8
  106. data/lib/aws-sdk-core/stubbing/protocols/rest_xml.rb +6 -5
  107. data/lib/aws-sdk-core/stubbing/protocols/rpc_v2.rb +39 -0
  108. data/lib/aws-sdk-core/stubbing.rb +22 -0
  109. data/lib/aws-sdk-core/telemetry/base.rb +177 -0
  110. data/lib/aws-sdk-core/telemetry/no_op.rb +70 -0
  111. data/lib/aws-sdk-core/telemetry/otel.rb +235 -0
  112. data/lib/aws-sdk-core/telemetry/span_kind.rb +22 -0
  113. data/lib/aws-sdk-core/telemetry/span_status.rb +59 -0
  114. data/lib/aws-sdk-core/telemetry.rb +78 -0
  115. data/lib/aws-sdk-core/token.rb +3 -3
  116. data/lib/aws-sdk-core/token_provider.rb +4 -0
  117. data/lib/aws-sdk-core/token_provider_chain.rb +2 -6
  118. data/lib/aws-sdk-core/util.rb +41 -1
  119. data/lib/aws-sdk-core/waiters/poller.rb +10 -5
  120. data/lib/aws-sdk-core/xml/builder.rb +17 -9
  121. data/lib/aws-sdk-core/xml/error_handler.rb +35 -43
  122. data/lib/aws-sdk-core/xml/parser/frame.rb +4 -20
  123. data/lib/aws-sdk-core/xml/parser/stack.rb +2 -0
  124. data/lib/aws-sdk-core/xml/parser.rb +2 -6
  125. data/lib/aws-sdk-core.rb +86 -107
  126. data/lib/aws-sdk-signin/client.rb +604 -0
  127. data/lib/aws-sdk-signin/client_api.rb +119 -0
  128. data/lib/aws-sdk-signin/customizations.rb +1 -0
  129. data/lib/aws-sdk-signin/endpoint_parameters.rb +69 -0
  130. data/lib/aws-sdk-signin/endpoint_provider.rb +59 -0
  131. data/lib/aws-sdk-signin/endpoints.rb +20 -0
  132. data/lib/aws-sdk-signin/errors.rb +122 -0
  133. data/lib/aws-sdk-signin/plugins/endpoints.rb +77 -0
  134. data/lib/aws-sdk-signin/resource.rb +26 -0
  135. data/lib/aws-sdk-signin/types.rb +299 -0
  136. data/lib/aws-sdk-signin.rb +63 -0
  137. data/lib/aws-sdk-sso/client.rb +189 -96
  138. data/lib/aws-sdk-sso/client_api.rb +7 -0
  139. data/lib/aws-sdk-sso/endpoint_parameters.rb +13 -10
  140. data/lib/aws-sdk-sso/endpoint_provider.rb +16 -20
  141. data/lib/aws-sdk-sso/endpoints.rb +2 -54
  142. data/lib/aws-sdk-sso/plugins/endpoints.rb +20 -20
  143. data/lib/aws-sdk-sso/types.rb +1 -0
  144. data/lib/aws-sdk-sso.rb +15 -11
  145. data/lib/aws-sdk-ssooidc/client.rb +293 -122
  146. data/lib/aws-sdk-ssooidc/client_api.rb +38 -0
  147. data/lib/aws-sdk-ssooidc/endpoint_parameters.rb +13 -10
  148. data/lib/aws-sdk-ssooidc/endpoint_provider.rb +14 -18
  149. data/lib/aws-sdk-ssooidc/endpoints.rb +2 -54
  150. data/lib/aws-sdk-ssooidc/errors.rb +31 -0
  151. data/lib/aws-sdk-ssooidc/plugins/endpoints.rb +20 -20
  152. data/lib/aws-sdk-ssooidc/types.rb +142 -29
  153. data/lib/aws-sdk-ssooidc.rb +15 -11
  154. data/lib/aws-sdk-sts/client.rb +529 -156
  155. data/lib/aws-sdk-sts/client_api.rb +108 -8
  156. data/lib/aws-sdk-sts/customizations.rb +5 -2
  157. data/lib/aws-sdk-sts/endpoint_parameters.rb +15 -14
  158. data/lib/aws-sdk-sts/endpoint_provider.rb +50 -55
  159. data/lib/aws-sdk-sts/endpoints.rb +2 -118
  160. data/lib/aws-sdk-sts/errors.rb +79 -0
  161. data/lib/aws-sdk-sts/plugins/endpoints.rb +20 -28
  162. data/lib/aws-sdk-sts/presigner.rb +2 -6
  163. data/lib/aws-sdk-sts/types.rb +344 -32
  164. data/lib/aws-sdk-sts.rb +15 -11
  165. data/lib/seahorse/client/async_base.rb +4 -5
  166. data/lib/seahorse/client/async_response.rb +19 -0
  167. data/lib/seahorse/client/base.rb +18 -21
  168. data/lib/seahorse/client/h2/connection.rb +18 -28
  169. data/lib/seahorse/client/h2/handler.rb +19 -3
  170. data/lib/seahorse/client/handler.rb +1 -1
  171. data/lib/seahorse/client/http/response.rb +1 -1
  172. data/lib/seahorse/client/net_http/connection_pool.rb +15 -12
  173. data/lib/seahorse/client/net_http/handler.rb +21 -9
  174. data/lib/seahorse/client/networking_error.rb +1 -1
  175. data/lib/seahorse/client/plugin.rb +9 -0
  176. data/lib/seahorse/client/plugins/endpoint.rb +0 -1
  177. data/lib/seahorse/client/plugins/h2.rb +4 -4
  178. data/lib/seahorse/client/plugins/net_http.rb +57 -16
  179. data/lib/seahorse/client/request_context.rb +9 -2
  180. data/lib/seahorse/client/response.rb +2 -0
  181. data/lib/seahorse/model/shapes.rb +2 -2
  182. data/lib/seahorse/util.rb +2 -1
  183. data/sig/aws-sdk-core/async_client_stubs.rbs +21 -0
  184. data/sig/aws-sdk-core/client_stubs.rbs +10 -0
  185. data/sig/aws-sdk-core/errors.rbs +22 -0
  186. data/sig/aws-sdk-core/resources/collection.rbs +21 -0
  187. data/sig/aws-sdk-core/structure.rbs +4 -0
  188. data/sig/aws-sdk-core/telemetry/base.rbs +46 -0
  189. data/sig/aws-sdk-core/telemetry/otel.rbs +22 -0
  190. data/sig/aws-sdk-core/telemetry/span_kind.rbs +15 -0
  191. data/sig/aws-sdk-core/telemetry/span_status.rbs +24 -0
  192. data/sig/aws-sdk-core/waiters/errors.rbs +20 -0
  193. data/sig/aws-sdk-core.rbs +7 -0
  194. data/sig/seahorse/client/async_base.rbs +18 -0
  195. data/sig/seahorse/client/base.rbs +25 -0
  196. data/sig/seahorse/client/handler_builder.rbs +16 -0
  197. data/sig/seahorse/client/response.rbs +61 -0
  198. metadata +117 -23
  199. /data/lib/aws-sdk-core/xml/parser/{engines/libxml.rb → libxml_engine.rb} +0 -0
  200. /data/lib/aws-sdk-core/xml/parser/{engines/nokogiri.rb → nokogiri_engine.rb} +0 -0
  201. /data/lib/aws-sdk-core/xml/parser/{engines/oga.rb → oga_engine.rb} +0 -0
  202. /data/lib/aws-sdk-core/xml/parser/{engines/ox.rb → ox_engine.rb} +0 -0
  203. /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 = value.to_f
230
+ add_double(epoch)
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
@@ -15,29 +15,11 @@ module Aws
15
15
 
16
16
  # @api private
17
17
  def setup_stubbing
18
- @stubs = {}
19
- @stub_mutex = Mutex.new
20
18
  if Hash === @config.stub_responses
21
19
  @config.stub_responses.each do |operation_name, stubs|
22
20
  apply_stubs(operation_name, Array === stubs ? stubs : [stubs])
23
21
  end
24
22
  end
25
-
26
- # When a client is stubbed allow the user to access the requests made
27
- @api_requests = []
28
-
29
- requests = @api_requests
30
- requests_mutex = Mutex.new
31
- self.handle do |context|
32
- requests_mutex.synchronize do
33
- requests << {
34
- operation_name: context.operation_name,
35
- params: context.params,
36
- context: context
37
- }
38
- end
39
- @handler.call(context)
40
- end
41
23
  end
42
24
 
43
25
  # Configures what data / errors should be returned from the named operation
@@ -177,7 +159,7 @@ module Aws
177
159
  # on a client that has not enabled response stubbing via
178
160
  # `:stub_responses => true`.
179
161
  def stub_responses(operation_name, *stubs)
180
- if config.stub_responses
162
+ if @config.stub_responses
181
163
  apply_stubs(operation_name, stubs.flatten)
182
164
  else
183
165
  msg = 'stubbing is not enabled; enable stubbing in the constructor '\
@@ -196,11 +178,13 @@ module Aws
196
178
  # @raise [NotImplementedError] Raises `NotImplementedError` when the client
197
179
  # is not stubbed.
198
180
  def api_requests(options = {})
199
- if config.stub_responses
200
- if options[:exclude_presign]
201
- @api_requests.reject {|req| req[:context][:presigned_url] }
202
- else
203
- @api_requests
181
+ if @config.stub_responses
182
+ @config.api_requests_mutex.synchronize do
183
+ if options[:exclude_presign]
184
+ @config.api_requests.reject {|req| req[:context][:presigned_url] }
185
+ else
186
+ @config.api_requests
187
+ end
204
188
  end
205
189
  else
206
190
  msg = 'This method is only implemented for stubbed clients, and is '\
@@ -228,54 +212,44 @@ module Aws
228
212
  # @return [Structure] Returns a stubbed response data structure. The
229
213
  # actual class returned will depend on the given `operation_name`.
230
214
  def stub_data(operation_name, data = {})
231
- Stubbing::StubData.new(config.api.operation(operation_name)).stub(data)
215
+ Stubbing::StubData.new(@config.api.operation(operation_name)).stub(data)
232
216
  end
233
217
 
234
218
  # @api private
235
219
  def next_stub(context)
236
220
  operation_name = context.operation_name.to_sym
237
- stub = @stub_mutex.synchronize do
238
- stubs = @stubs[operation_name] || []
221
+ stub = @config.stubs_mutex.synchronize do
222
+ stubs = @config.stubs[operation_name] || []
239
223
  case stubs.length
240
- when 0 then default_stub(operation_name)
224
+ when 0 then stub_data(operation_name)
241
225
  when 1 then stubs.first
242
226
  else stubs.shift
243
227
  end
244
228
  end
245
- Proc === stub ? convert_stub(operation_name, stub.call(context)) : stub
229
+ stub = convert_stub(operation_name, stub, context)
230
+ stub[:mutex] = Mutex.new
231
+ stub
246
232
  end
247
233
 
248
234
  private
249
235
 
250
- def default_stub(operation_name)
251
- stub = stub_data(operation_name)
252
- http_response_stub(operation_name, stub)
236
+ def apply_stubs(operation_name, stubs)
237
+ @config.stubs_mutex.synchronize do
238
+ @config.stubs[operation_name.to_sym] = stubs
239
+ end
253
240
  end
254
241
 
255
242
  # This method converts the given stub data and converts it to a
256
243
  # HTTP response (when possible). This enables the response stubbing
257
244
  # plugin to provide a HTTP response that triggers all normal events
258
245
  # during response handling.
259
- def apply_stubs(operation_name, stubs)
260
- @stub_mutex.synchronize do
261
- @stubs[operation_name.to_sym] = stubs.map do |stub|
262
- convert_stub(operation_name, stub)
263
- end
264
- end
265
- end
266
-
267
- def convert_stub(operation_name, stub)
268
- stub = case stub
269
- when Proc then stub
246
+ def convert_stub(operation_name, stub, context)
247
+ case stub
248
+ when Proc then convert_stub(operation_name, stub.call(context), context)
270
249
  when Exception, Class then { error: stub }
271
250
  when String then service_error_stub(stub)
272
- when Hash then http_response_stub(operation_name, stub)
273
- else { data: stub }
251
+ else http_response_stub(operation_name, stub)
274
252
  end
275
- if Hash === stub
276
- stub[:mutex] = Mutex.new
277
- end
278
- stub
279
253
  end
280
254
 
281
255
  def service_error_stub(error_code)
@@ -299,21 +273,28 @@ module Aws
299
273
  end
300
274
 
301
275
  def data_to_http_resp(operation_name, data)
302
- api = config.api
276
+ api = @config.api
303
277
  operation = api.operation(operation_name)
304
278
  ParamValidator.new(operation.output, input: false).validate!(data)
305
279
  protocol_helper.stub_data(api, operation, data)
306
280
  end
307
281
 
308
282
  def protocol_helper
309
- case config.api.metadata['protocol']
310
- when 'json' then Stubbing::Protocols::Json
311
- when 'query' then Stubbing::Protocols::Query
312
- when 'ec2' then Stubbing::Protocols::EC2
313
- when 'rest-json' then Stubbing::Protocols::RestJson
314
- when 'rest-xml' then Stubbing::Protocols::RestXml
315
- when 'api-gateway' then Stubbing::Protocols::ApiGateway
316
- else raise "unsupported protocol"
283
+ # Prioritize JSON over CBOR when CBOR is the configured protocol but both are supported. This is to match similar
284
+ # prioritization in service.rb code generation.
285
+ if @config.api.metadata['protocol'] == 'smithy-rpc-v2-cbor' && @config.api.metadata['protocols']&.include?('json')
286
+ return Stubbing::Protocols::Json.new
287
+ end
288
+
289
+ case @config.api.metadata['protocol']
290
+ when 'json' then Stubbing::Protocols::Json
291
+ when 'rest-json' then Stubbing::Protocols::RestJson
292
+ when 'rest-xml' then Stubbing::Protocols::RestXml
293
+ when 'query' then Stubbing::Protocols::Query
294
+ when 'ec2' then Stubbing::Protocols::EC2
295
+ when 'smithy-rpc-v2-cbor' then Stubbing::Protocols::RpcV2
296
+ when 'api-gateway' then Stubbing::Protocols::ApiGateway
297
+ else raise 'unsupported protocol'
317
298
  end.new
318
299
  end
319
300
  end
@@ -9,9 +9,13 @@ module Aws
9
9
  # @return [Time]
10
10
  attr_reader :expiration
11
11
 
12
+ # @api private
13
+ # Returns UserAgent metrics for credentials.
14
+ attr_accessor :metrics
15
+
12
16
  # @return [Boolean]
13
17
  def set?
14
- !!credentials && credentials.set?
18
+ !!@credentials && @credentials.set?
15
19
  end
16
20
 
17
21
  end