aws-sdk-core 3.117.0 → 3.197.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (163) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +836 -0
  3. data/VERSION +1 -1
  4. data/lib/aws-defaults/default_configuration.rb +153 -0
  5. data/lib/aws-defaults/defaults_mode_config_resolver.rb +107 -0
  6. data/lib/aws-defaults.rb +3 -0
  7. data/lib/aws-sdk-core/arn.rb +13 -0
  8. data/lib/aws-sdk-core/assume_role_credentials.rb +21 -7
  9. data/lib/aws-sdk-core/assume_role_web_identity_credentials.rb +14 -10
  10. data/lib/aws-sdk-core/binary/decode_handler.rb +0 -5
  11. data/lib/aws-sdk-core/binary/encode_handler.rb +12 -1
  12. data/lib/aws-sdk-core/binary/event_builder.rb +34 -37
  13. data/lib/aws-sdk-core/client_stubs.rb +20 -13
  14. data/lib/aws-sdk-core/credential_provider.rb +4 -1
  15. data/lib/aws-sdk-core/credential_provider_chain.rb +8 -5
  16. data/lib/aws-sdk-core/ec2_metadata.rb +4 -3
  17. data/lib/aws-sdk-core/ecs_credentials.rb +187 -52
  18. data/lib/aws-sdk-core/endpoints/condition.rb +41 -0
  19. data/lib/aws-sdk-core/endpoints/endpoint.rb +17 -0
  20. data/lib/aws-sdk-core/endpoints/endpoint_rule.rb +75 -0
  21. data/lib/aws-sdk-core/endpoints/error_rule.rb +42 -0
  22. data/lib/aws-sdk-core/endpoints/function.rb +80 -0
  23. data/lib/aws-sdk-core/endpoints/matchers.rb +135 -0
  24. data/lib/aws-sdk-core/endpoints/reference.rb +31 -0
  25. data/lib/aws-sdk-core/endpoints/rule.rb +25 -0
  26. data/lib/aws-sdk-core/endpoints/rule_set.rb +52 -0
  27. data/lib/aws-sdk-core/endpoints/rules_provider.rb +37 -0
  28. data/lib/aws-sdk-core/endpoints/templater.rb +58 -0
  29. data/lib/aws-sdk-core/endpoints/tree_rule.rb +45 -0
  30. data/lib/aws-sdk-core/endpoints/url.rb +60 -0
  31. data/lib/aws-sdk-core/endpoints.rb +78 -0
  32. data/lib/aws-sdk-core/errors.rb +17 -4
  33. data/lib/aws-sdk-core/event_emitter.rb +0 -16
  34. data/lib/aws-sdk-core/ini_parser.rb +7 -0
  35. data/lib/aws-sdk-core/instance_profile_credentials.rb +127 -33
  36. data/lib/aws-sdk-core/json/builder.rb +8 -1
  37. data/lib/aws-sdk-core/json/error_handler.rb +30 -4
  38. data/lib/aws-sdk-core/json/handler.rb +8 -1
  39. data/lib/aws-sdk-core/json/json_engine.rb +10 -8
  40. data/lib/aws-sdk-core/json/oj_engine.rb +33 -6
  41. data/lib/aws-sdk-core/json/parser.rb +38 -2
  42. data/lib/aws-sdk-core/json.rb +8 -26
  43. data/lib/aws-sdk-core/log/formatter.rb +6 -0
  44. data/lib/aws-sdk-core/log/param_filter.rb +9 -1
  45. data/lib/aws-sdk-core/lru_cache.rb +75 -0
  46. data/lib/aws-sdk-core/pageable_response.rb +81 -32
  47. data/lib/aws-sdk-core/param_validator.rb +36 -2
  48. data/lib/aws-sdk-core/plugins/bearer_authorization.rb +67 -0
  49. data/lib/aws-sdk-core/plugins/checksum_algorithm.rb +342 -0
  50. data/lib/aws-sdk-core/plugins/client_metrics_plugin.rb +1 -0
  51. data/lib/aws-sdk-core/plugins/client_metrics_send_plugin.rb +14 -2
  52. data/lib/aws-sdk-core/plugins/credentials_configuration.rb +29 -1
  53. data/lib/aws-sdk-core/plugins/defaults_mode.rb +40 -0
  54. data/lib/aws-sdk-core/plugins/endpoint_discovery.rb +6 -2
  55. data/lib/aws-sdk-core/plugins/http_checksum.rb +9 -1
  56. data/lib/aws-sdk-core/plugins/invocation_id.rb +1 -11
  57. data/lib/aws-sdk-core/plugins/jsonvalue_converter.rb +34 -6
  58. data/lib/aws-sdk-core/plugins/logging.rb +2 -0
  59. data/lib/aws-sdk-core/plugins/protocols/api_gateway.rb +17 -0
  60. data/lib/aws-sdk-core/plugins/protocols/rest_json.rb +4 -2
  61. data/lib/aws-sdk-core/plugins/protocols/rest_xml.rb +1 -2
  62. data/lib/aws-sdk-core/plugins/recursion_detection.rb +38 -0
  63. data/lib/aws-sdk-core/plugins/regional_endpoint.rb +144 -17
  64. data/lib/aws-sdk-core/plugins/request_compression.rb +226 -0
  65. data/lib/aws-sdk-core/plugins/response_paging.rb +1 -1
  66. data/lib/aws-sdk-core/plugins/retries/error_inspector.rb +7 -4
  67. data/lib/aws-sdk-core/plugins/retry_errors.rb +33 -7
  68. data/lib/aws-sdk-core/plugins/sign.rb +211 -0
  69. data/lib/aws-sdk-core/plugins/signature_v2.rb +1 -0
  70. data/lib/aws-sdk-core/plugins/signature_v4.rb +28 -31
  71. data/lib/aws-sdk-core/plugins/stub_responses.rb +6 -1
  72. data/lib/aws-sdk-core/plugins/user_agent.rb +152 -14
  73. data/lib/aws-sdk-core/process_credentials.rb +50 -34
  74. data/lib/aws-sdk-core/query/ec2_param_builder.rb +5 -7
  75. data/lib/aws-sdk-core/query/param_builder.rb +2 -2
  76. data/lib/aws-sdk-core/refreshing_credentials.rb +49 -18
  77. data/lib/aws-sdk-core/refreshing_token.rb +71 -0
  78. data/lib/aws-sdk-core/rest/handler.rb +1 -1
  79. data/lib/aws-sdk-core/rest/request/body.rb +49 -4
  80. data/lib/aws-sdk-core/rest/request/content_type.rb +60 -0
  81. data/lib/aws-sdk-core/rest/request/endpoint.rb +24 -4
  82. data/lib/aws-sdk-core/rest/request/headers.rb +23 -7
  83. data/lib/aws-sdk-core/rest/request/querystring_builder.rb +62 -36
  84. data/lib/aws-sdk-core/rest/response/body.rb +15 -1
  85. data/lib/aws-sdk-core/rest/response/header_list_parser.rb +79 -0
  86. data/lib/aws-sdk-core/rest/response/headers.rb +10 -3
  87. data/lib/aws-sdk-core/rest.rb +1 -0
  88. data/lib/aws-sdk-core/shared_config.rb +112 -12
  89. data/lib/aws-sdk-core/sso_credentials.rb +92 -51
  90. data/lib/aws-sdk-core/sso_token_provider.rb +135 -0
  91. data/lib/aws-sdk-core/static_token_provider.rb +14 -0
  92. data/lib/aws-sdk-core/structure.rb +16 -5
  93. data/lib/aws-sdk-core/stubbing/stub_data.rb +11 -0
  94. data/lib/aws-sdk-core/token.rb +31 -0
  95. data/lib/aws-sdk-core/token_provider.rb +15 -0
  96. data/lib/aws-sdk-core/token_provider_chain.rb +51 -0
  97. data/lib/aws-sdk-core/util.rb +39 -0
  98. data/lib/aws-sdk-core/waiters/poller.rb +4 -2
  99. data/lib/aws-sdk-core/xml/builder.rb +17 -9
  100. data/lib/aws-sdk-core/xml/error_handler.rb +31 -8
  101. data/lib/aws-sdk-core/xml/parser/engines/oga.rb +2 -0
  102. data/lib/aws-sdk-core/xml/parser/engines/ox.rb +1 -1
  103. data/lib/aws-sdk-core/xml/parser/engines/rexml.rb +0 -8
  104. data/lib/aws-sdk-core/xml/parser/frame.rb +27 -20
  105. data/lib/aws-sdk-core/xml/parser/stack.rb +2 -0
  106. data/lib/aws-sdk-core.rb +21 -0
  107. data/lib/aws-sdk-sso/client.rb +157 -50
  108. data/lib/aws-sdk-sso/endpoint_parameters.rb +66 -0
  109. data/lib/aws-sdk-sso/endpoint_provider.rb +57 -0
  110. data/lib/aws-sdk-sso/endpoints.rb +72 -0
  111. data/lib/aws-sdk-sso/plugins/endpoints.rb +78 -0
  112. data/lib/aws-sdk-sso/types.rb +8 -43
  113. data/lib/aws-sdk-sso.rb +5 -1
  114. data/lib/aws-sdk-ssooidc/client.rb +1008 -0
  115. data/lib/aws-sdk-ssooidc/client_api.rb +293 -0
  116. data/lib/aws-sdk-ssooidc/customizations.rb +1 -0
  117. data/lib/aws-sdk-ssooidc/endpoint_parameters.rb +66 -0
  118. data/lib/aws-sdk-ssooidc/endpoint_provider.rb +57 -0
  119. data/lib/aws-sdk-ssooidc/endpoints.rb +72 -0
  120. data/lib/aws-sdk-ssooidc/errors.rb +342 -0
  121. data/lib/aws-sdk-ssooidc/plugins/endpoints.rb +78 -0
  122. data/lib/aws-sdk-ssooidc/resource.rb +26 -0
  123. data/lib/aws-sdk-ssooidc/types.rb +823 -0
  124. data/lib/aws-sdk-ssooidc.rb +59 -0
  125. data/lib/aws-sdk-sts/client.rb +472 -398
  126. data/lib/aws-sdk-sts/client_api.rb +20 -9
  127. data/lib/aws-sdk-sts/endpoint_parameters.rb +78 -0
  128. data/lib/aws-sdk-sts/endpoint_provider.rb +112 -0
  129. data/lib/aws-sdk-sts/endpoints.rb +136 -0
  130. data/lib/aws-sdk-sts/plugins/endpoints.rb +86 -0
  131. data/lib/aws-sdk-sts/plugins/sts_regional_endpoints.rb +5 -1
  132. data/lib/aws-sdk-sts/presigner.rb +14 -10
  133. data/lib/aws-sdk-sts/types.rb +168 -227
  134. data/lib/aws-sdk-sts.rb +5 -1
  135. data/lib/seahorse/client/async_base.rb +1 -2
  136. data/lib/seahorse/client/async_response.rb +19 -0
  137. data/lib/seahorse/client/base.rb +1 -0
  138. data/lib/seahorse/client/configuration.rb +5 -5
  139. data/lib/seahorse/client/h2/connection.rb +15 -16
  140. data/lib/seahorse/client/h2/handler.rb +5 -5
  141. data/lib/seahorse/client/net_http/connection_pool.rb +10 -9
  142. data/lib/seahorse/client/net_http/handler.rb +15 -7
  143. data/lib/seahorse/client/net_http/patches.rb +12 -86
  144. data/lib/seahorse/client/plugin.rb +9 -0
  145. data/lib/seahorse/client/plugins/content_length.rb +11 -5
  146. data/lib/seahorse/client/plugins/h2.rb +3 -3
  147. data/lib/seahorse/client/plugins/net_http.rb +73 -10
  148. data/lib/seahorse/client/plugins/request_callback.rb +40 -9
  149. data/lib/seahorse/client/response.rb +6 -0
  150. data/lib/seahorse/model/operation.rb +6 -0
  151. data/lib/seahorse/model/shapes.rb +27 -2
  152. data/lib/seahorse/util.rb +4 -0
  153. data/sig/aws-sdk-core/client_stubs.rbs +10 -0
  154. data/sig/aws-sdk-core/errors.rbs +22 -0
  155. data/sig/aws-sdk-core/resources/collection.rbs +21 -0
  156. data/sig/aws-sdk-core/structure.rbs +4 -0
  157. data/sig/aws-sdk-core/waiters/errors.rbs +20 -0
  158. data/sig/aws-sdk-core.rbs +7 -0
  159. data/sig/seahorse/client/base.rbs +25 -0
  160. data/sig/seahorse/client/handler_builder.rbs +16 -0
  161. data/sig/seahorse/client/response.rbs +61 -0
  162. metadata +82 -17
  163. data/lib/aws-sdk-sso/plugins/content_type.rb +0 -25
@@ -0,0 +1,342 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Aws
4
+ module Plugins
5
+ # @api private
6
+ class ChecksumAlgorithm < Seahorse::Client::Plugin
7
+ CHUNK_SIZE = 1 * 1024 * 1024 # one MB
8
+
9
+ # determine the set of supported client side checksum algorithms
10
+ # CRC32c requires aws-crt (optional sdk dependency) for support
11
+ CLIENT_ALGORITHMS = begin
12
+ supported = %w[SHA256 SHA1 CRC32]
13
+ begin
14
+ require 'aws-crt'
15
+ supported << 'CRC32C'
16
+ rescue LoadError
17
+ end
18
+ supported
19
+ end.freeze
20
+
21
+ # priority order of checksum algorithms to validate responses against
22
+ # Remove any algorithms not supported by client (ie, depending on CRT availability)
23
+ CHECKSUM_ALGORITHM_PRIORITIES = %w[CRC32C SHA1 CRC32 SHA256] & CLIENT_ALGORITHMS
24
+
25
+ # byte size of checksums, used in computing the trailer length
26
+ CHECKSUM_SIZE = {
27
+ 'CRC32' => 16,
28
+ 'CRC32C' => 16,
29
+ 'SHA1' => 36,
30
+ 'SHA256' => 52
31
+ }
32
+
33
+ # Interface for computing digests on request/response bodies
34
+ # which may be files, strings or IO like objects
35
+ # Applies only to digest functions that produce 32 bit integer checksums
36
+ # (eg CRC32)
37
+ class Digest32
38
+
39
+ attr_reader :value
40
+
41
+ # @param [Object] digest_fn
42
+ def initialize(digest_fn)
43
+ @digest_fn = digest_fn
44
+ @value = 0
45
+ end
46
+
47
+ def update(chunk)
48
+ @value = @digest_fn.call(chunk, @value)
49
+ end
50
+
51
+ def base64digest
52
+ Base64.encode64([@value].pack('N')).chomp
53
+ end
54
+ end
55
+
56
+ def add_handlers(handlers, _config)
57
+ handlers.add(OptionHandler, step: :initialize)
58
+ # priority set low to ensure checksum is computed AFTER the request is
59
+ # built but before it is signed
60
+ handlers.add(ChecksumHandler, priority: 15, step: :build)
61
+ end
62
+
63
+ private
64
+
65
+ def self.request_algorithm_selection(context)
66
+ return unless context.operation.http_checksum
67
+
68
+ input_member = context.operation.http_checksum['requestAlgorithmMember']
69
+ context.params[input_member.to_sym]&.upcase if input_member
70
+ end
71
+
72
+ def self.request_validation_mode(context)
73
+ return unless context.operation.http_checksum
74
+
75
+ input_member = context.operation.http_checksum['requestValidationModeMember']
76
+ context.params[input_member.to_sym] if input_member
77
+ end
78
+
79
+ def self.operation_response_algorithms(context)
80
+ return unless context.operation.http_checksum
81
+
82
+ context.operation.http_checksum['responseAlgorithms']
83
+ end
84
+
85
+
86
+ # @api private
87
+ class OptionHandler < Seahorse::Client::Handler
88
+ def call(context)
89
+ context[:http_checksum] ||= {}
90
+
91
+ # validate request configuration
92
+ if (request_input = ChecksumAlgorithm.request_algorithm_selection(context))
93
+ unless CLIENT_ALGORITHMS.include? request_input
94
+ if (request_input == 'CRC32C')
95
+ raise ArgumentError, "CRC32C requires crt support - install the aws-crt gem for support."
96
+ else
97
+ raise ArgumentError, "#{request_input} is not a supported checksum algorithm."
98
+ end
99
+ end
100
+ end
101
+
102
+ # validate response configuration
103
+ if (ChecksumAlgorithm.request_validation_mode(context))
104
+ # Compute an ordered list as the union between priority supported and the
105
+ # operation's modeled response algorithms.
106
+ validation_list = CHECKSUM_ALGORITHM_PRIORITIES &
107
+ ChecksumAlgorithm.operation_response_algorithms(context)
108
+ context[:http_checksum][:validation_list] = validation_list
109
+ end
110
+
111
+ @handler.call(context)
112
+ end
113
+ end
114
+
115
+ # @api private
116
+ class ChecksumHandler < Seahorse::Client::Handler
117
+
118
+ def call(context)
119
+ if should_calculate_request_checksum?(context)
120
+ request_algorithm_input = ChecksumAlgorithm.request_algorithm_selection(context) ||
121
+ context[:default_request_checksum_algorithm]
122
+ context[:checksum_algorithms] = request_algorithm_input
123
+
124
+ request_checksum_property = {
125
+ 'algorithm' => request_algorithm_input,
126
+ 'in' => checksum_request_in(context),
127
+ 'name' => "x-amz-checksum-#{request_algorithm_input.downcase}"
128
+ }
129
+
130
+ calculate_request_checksum(context, request_checksum_property)
131
+ end
132
+
133
+ if should_verify_response_checksum?(context)
134
+ add_verify_response_checksum_handlers(context)
135
+ end
136
+
137
+ @handler.call(context)
138
+ end
139
+
140
+ private
141
+
142
+ def should_calculate_request_checksum?(context)
143
+ context.operation.http_checksum &&
144
+ (ChecksumAlgorithm.request_algorithm_selection(context) ||
145
+ context[:default_request_checksum_algorithm])
146
+ end
147
+
148
+ def should_verify_response_checksum?(context)
149
+ context[:http_checksum][:validation_list] && !context[:http_checksum][:validation_list].empty?
150
+ end
151
+
152
+ def calculate_request_checksum(context, checksum_properties)
153
+ case checksum_properties['in']
154
+ when 'header'
155
+ header_name = checksum_properties['name']
156
+ body = context.http_request.body_contents
157
+ if body
158
+ context.http_request.headers[header_name] ||=
159
+ ChecksumAlgorithm.calculate_checksum(checksum_properties['algorithm'], body)
160
+ end
161
+ when 'trailer'
162
+ apply_request_trailer_checksum(context, checksum_properties)
163
+ end
164
+ end
165
+
166
+ def apply_request_trailer_checksum(context, checksum_properties)
167
+ location_name = checksum_properties['name']
168
+
169
+ # set required headers
170
+ headers = context.http_request.headers
171
+ headers['Content-Encoding'] = 'aws-chunked'
172
+ headers['X-Amz-Content-Sha256'] = 'STREAMING-UNSIGNED-PAYLOAD-TRAILER'
173
+ headers['X-Amz-Trailer'] = location_name
174
+
175
+ # We currently always compute the size in the modified body wrapper - allowing us
176
+ # to set the Content-Length header (set by content_length plugin).
177
+ # This means we cannot use Transfer-Encoding=chunked
178
+
179
+ if !context.http_request.body.respond_to?(:size)
180
+ raise Aws::Errors::ChecksumError, 'Could not determine length of the body'
181
+ end
182
+ headers['X-Amz-Decoded-Content-Length'] = context.http_request.body.size
183
+
184
+ context.http_request.body = AwsChunkedTrailerDigestIO.new(
185
+ context.http_request.body,
186
+ checksum_properties['algorithm'],
187
+ location_name
188
+ )
189
+ end
190
+
191
+ # Add events to the http_response to verify the checksum as its read
192
+ # This prevents the body from being read multiple times
193
+ # verification is done only once a successful response has completed
194
+ def add_verify_response_checksum_handlers(context)
195
+ http_response = context.http_response
196
+ checksum_context = { }
197
+ http_response.on_headers do |_status, headers|
198
+ header_name, algorithm = response_header_to_verify(headers, context[:http_checksum][:validation_list])
199
+ if header_name
200
+ expected = headers[header_name]
201
+
202
+ unless context[:http_checksum][:skip_on_suffix] && /-[\d]+$/.match(expected)
203
+ checksum_context[:algorithm] = algorithm
204
+ checksum_context[:header_name] = header_name
205
+ checksum_context[:digest] = ChecksumAlgorithm.digest_for_algorithm(algorithm)
206
+ checksum_context[:expected] = expected
207
+ end
208
+ end
209
+ end
210
+
211
+ http_response.on_data do |chunk|
212
+ checksum_context[:digest].update(chunk) if checksum_context[:digest]
213
+ end
214
+
215
+ http_response.on_success do
216
+ if checksum_context[:digest] &&
217
+ (computed = checksum_context[:digest].base64digest)
218
+
219
+ if computed != checksum_context[:expected]
220
+ raise Aws::Errors::ChecksumError,
221
+ "Checksum validation failed on #{checksum_context[:header_name]} "\
222
+ "computed: #{computed}, expected: #{checksum_context[:expected]}"
223
+ end
224
+
225
+ context[:http_checksum][:validated] = checksum_context[:algorithm]
226
+ end
227
+ end
228
+ end
229
+
230
+ # returns nil if no headers to verify
231
+ def response_header_to_verify(headers, validation_list)
232
+ validation_list.each do |algorithm|
233
+ header_name = "x-amz-checksum-#{algorithm}"
234
+ return [header_name, algorithm] if headers[header_name]
235
+ end
236
+ nil
237
+ end
238
+
239
+ # determine where (header vs trailer) a request checksum should be added
240
+ def checksum_request_in(context)
241
+ if context.operation['authtype'].eql?('v4-unsigned-body')
242
+ 'trailer'
243
+ else
244
+ 'header'
245
+ end
246
+ end
247
+
248
+ end
249
+
250
+ def self.calculate_checksum(algorithm, body)
251
+ digest = ChecksumAlgorithm.digest_for_algorithm(algorithm)
252
+ if body.respond_to?(:read)
253
+ ChecksumAlgorithm.update_in_chunks(digest, body)
254
+ else
255
+ digest.update(body)
256
+ end
257
+ digest.base64digest
258
+ end
259
+
260
+ def self.digest_for_algorithm(algorithm)
261
+ case algorithm
262
+ when 'CRC32'
263
+ Digest32.new(Zlib.method(:crc32))
264
+ when 'CRC32C'
265
+ # this will only be used if input algorithm is CRC32C AND client supports it (crt available)
266
+ Digest32.new(Aws::Crt::Checksums.method(:crc32c))
267
+ when 'SHA1'
268
+ Digest::SHA1.new
269
+ when 'SHA256'
270
+ Digest::SHA256.new
271
+ end
272
+ end
273
+
274
+ # The trailer size (in bytes) is the overhead + the trailer name +
275
+ # the length of the base64 encoded checksum
276
+ def self.trailer_length(algorithm, location_name)
277
+ CHECKSUM_SIZE[algorithm] + location_name.size
278
+ end
279
+
280
+ def self.update_in_chunks(digest, io)
281
+ loop do
282
+ chunk = io.read(CHUNK_SIZE)
283
+ break unless chunk
284
+ digest.update(chunk)
285
+ end
286
+ io.rewind
287
+ end
288
+
289
+ # Wrapper for request body that implements application-layer
290
+ # chunking with Digest computed on chunks + added as a trailer
291
+ class AwsChunkedTrailerDigestIO
292
+ CHUNK_SIZE = 16384
293
+
294
+ def initialize(io, algorithm, location_name)
295
+ @io = io
296
+ @location_name = location_name
297
+ @algorithm = algorithm
298
+ @digest = ChecksumAlgorithm.digest_for_algorithm(algorithm)
299
+ @trailer_io = nil
300
+ end
301
+
302
+ # the size of the application layer aws-chunked + trailer body
303
+ def size
304
+ # compute the number of chunks
305
+ # a full chunk has 4 + 4 bytes overhead, a partial chunk is len.to_s(16).size + 4
306
+ orig_body_size = @io.size
307
+ n_full_chunks = orig_body_size / CHUNK_SIZE
308
+ partial_bytes = orig_body_size % CHUNK_SIZE
309
+ chunked_body_size = n_full_chunks * (CHUNK_SIZE + 8)
310
+ chunked_body_size += partial_bytes.to_s(16).size + partial_bytes + 4 unless partial_bytes.zero?
311
+ trailer_size = ChecksumAlgorithm.trailer_length(@algorithm, @location_name)
312
+ chunked_body_size + trailer_size
313
+ end
314
+
315
+ def rewind
316
+ @io.rewind
317
+ end
318
+
319
+ def read(length, buf = nil)
320
+ # account for possible leftover bytes at the end, if we have trailer bytes, send them
321
+ if @trailer_io
322
+ return @trailer_io.read(length, buf)
323
+ end
324
+
325
+ chunk = @io.read(length)
326
+ if chunk
327
+ @digest.update(chunk)
328
+ application_chunked = "#{chunk.bytesize.to_s(16)}\r\n#{chunk}\r\n"
329
+ return StringIO.new(application_chunked).read(application_chunked.size, buf)
330
+ else
331
+ trailers = {}
332
+ trailers[@location_name] = @digest.base64digest
333
+ trailers = trailers.map { |k,v| "#{k}:#{v}"}.join("\r\n")
334
+ @trailer_io = StringIO.new("0\r\n#{trailers}\r\n\r\n")
335
+ chunk = @trailer_io.read(length, buf)
336
+ end
337
+ chunk
338
+ end
339
+ end
340
+ end
341
+ end
342
+ end
@@ -40,6 +40,7 @@ side monitoring agent is running on, where client metrics will be published via
40
40
  option(:client_side_monitoring_publisher,
41
41
  default: ClientSideMonitoring::Publisher,
42
42
  doc_type: Aws::ClientSideMonitoring::Publisher,
43
+ rbs_type: 'untyped',
43
44
  docstring: <<-DOCS) do |cfg|
44
45
  Allows you to provide a custom client-side monitoring publisher class. By default,
45
46
  will use the Client Side Monitoring Agent Publisher.
@@ -11,6 +11,8 @@ module Aws
11
11
  # AttemptHandler comes just before we would retry an error.
12
12
  # Or before we would follow redirects.
13
13
  handlers.add(AttemptHandler, step: :sign, priority: 39)
14
+ # ErrorHandler comes after we have parsed an error.
15
+ handlers.add(ErrorHandler, step: :sign, priority: 95)
14
16
  # LatencyHandler is as close to sending as possible.
15
17
  handlers.add(LatencyHandler, step: :sign, priority: 0)
16
18
  end
@@ -62,17 +64,27 @@ module Aws
62
64
  call_attempt.x_amzn_request_id = headers["x-amzn-request-id"]
63
65
  end
64
66
  call_attempt.http_status_code = context.http_response.status_code
65
- if e = resp.error
67
+ context.metadata[:current_call_attempt] = call_attempt
68
+ request_metrics.add_call_attempt(call_attempt)
69
+ resp
70
+ end
71
+ end
72
+
73
+ class ErrorHandler < Seahorse::Client::Handler
74
+ def call(context)
75
+ resp = @handler.call(context)
76
+ call_attempt = context.metadata[:current_call_attempt]
77
+ if (e = resp.error)
66
78
  e_name = _extract_error_name(e)
67
79
  e_msg = e.message
68
80
  call_attempt.aws_exception = "#{e_name}"
69
81
  call_attempt.aws_exception_msg = "#{e_msg}"
70
82
  end
71
- request_metrics.add_call_attempt(call_attempt)
72
83
  resp
73
84
  end
74
85
 
75
86
  private
87
+
76
88
  def _extract_error_name(error)
77
89
  if error.is_a?(Aws::Errors::ServiceError)
78
90
  error.class.code
@@ -23,6 +23,7 @@ at HOME/.aws/credentials. When not specified, 'default' is used.
23
23
  option(:credentials,
24
24
  required: true,
25
25
  doc_type: 'Aws::CredentialProvider',
26
+ rbs_type: 'untyped',
26
27
  docstring: <<-DOCS
27
28
  Your AWS credentials. This can be an instance of any one of the
28
29
  following classes:
@@ -64,7 +65,9 @@ locations will be searched for credentials:
64
65
  * EC2/ECS IMDS instance profile - When used by default, the timeouts
65
66
  are very aggressive. Construct and pass an instance of
66
67
  `Aws::InstanceProfileCredentails` or `Aws::ECSCredentials` to
67
- enable retries and extended timeouts.
68
+ enable retries and extended timeouts. Instance profile credential
69
+ fetching can be disabled by setting ENV['AWS_EC2_METADATA_DISABLED']
70
+ to true.
68
71
  DOCS
69
72
  ) do |config|
70
73
  CredentialProviderChain.new(config).resolve
@@ -74,6 +77,31 @@ locations will be searched for credentials:
74
77
 
75
78
  option(:instance_profile_credentials_timeout, 1)
76
79
 
80
+ option(:token_provider,
81
+ required: false,
82
+ doc_type: 'Aws::TokenProvider',
83
+ rbs_type: 'untyped',
84
+ docstring: <<-DOCS
85
+ A Bearer Token Provider. This can be an instance of any one of the
86
+ following classes:
87
+
88
+ * `Aws::StaticTokenProvider` - Used for configuring static, non-refreshing
89
+ tokens.
90
+
91
+ * `Aws::SSOTokenProvider` - Used for loading tokens from AWS SSO using an
92
+ access token generated from `aws login`.
93
+
94
+ When `:token_provider` is not configured directly, the `Aws::TokenProviderChain`
95
+ will be used to search for tokens configured for your profile in shared configuration files.
96
+ DOCS
97
+ ) do |config|
98
+ if config.stub_responses
99
+ StaticTokenProvider.new('token')
100
+ else
101
+ TokenProviderChain.new(config).resolve
102
+ end
103
+ end
104
+
77
105
  end
78
106
  end
79
107
  end
@@ -0,0 +1,40 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Aws
4
+ # @api private
5
+ module Plugins
6
+ # @api private
7
+ class DefaultsMode < Seahorse::Client::Plugin
8
+
9
+ option(:defaults_mode,
10
+ default: 'legacy',
11
+ doc_type: String,
12
+ docstring: <<-DOCS
13
+ See {Aws::DefaultsModeConfiguration} for a list of the
14
+ accepted modes and the configuration defaults that are included.
15
+ DOCS
16
+ ) do |cfg|
17
+ resolve_defaults_mode(cfg)
18
+ end
19
+
20
+ option(:defaults_mode_config_resolver,
21
+ doc_type: 'Aws::DefaultsModeConfigResolver') do |cfg|
22
+ Aws::DefaultsModeConfigResolver.new(
23
+ Aws::DefaultsModeConfiguration::SDK_DEFAULT_CONFIGURATION, cfg)
24
+ end
25
+
26
+ class << self
27
+ private
28
+
29
+ def resolve_defaults_mode(cfg)
30
+ value = ENV['AWS_DEFAULTS_MODE']
31
+ value ||= Aws.shared_config.defaults_mode(
32
+ profile: cfg.profile
33
+ )
34
+ value&.downcase || "legacy"
35
+ end
36
+ end
37
+
38
+ end
39
+ end
40
+ end
@@ -72,7 +72,11 @@ the background every 60 secs (default). Defaults to `false`.
72
72
  context,
73
73
  Aws::Util.str_2_bool(discovery_cfg["required"])
74
74
  )
75
- context.http_request.endpoint = _valid_uri(endpoint.address) if endpoint
75
+ if endpoint
76
+ context.http_request.endpoint = _valid_uri(endpoint.address)
77
+ # Skips dynamic endpoint usage, use this endpoint instead
78
+ context[:discovered_endpoint] = true
79
+ end
76
80
  if endpoint || context.config.endpoint_discovery
77
81
  _apply_endpoint_discovery_user_agent(context)
78
82
  end
@@ -100,7 +104,7 @@ the background every 60 secs (default). Defaults to `false`.
100
104
  end
101
105
 
102
106
  def _discover_endpoint(ctx, required)
103
- cache = ctx.config.endpoint_cache
107
+ cache = ctx.config.endpoint_cache
104
108
  key = cache.extract_key(ctx)
105
109
 
106
110
  if required
@@ -11,7 +11,9 @@ module Aws
11
11
  CHUNK_SIZE = 1 * 1024 * 1024 # one MB
12
12
 
13
13
  def call(context)
14
- if context.operation.http_checksum_required
14
+ if checksum_required?(context) &&
15
+ !context[:checksum_algorithms] && # skip in favor of flexible checksum
16
+ !context[:s3_express_endpoint] # s3 express endpoints do not support md5
15
17
  body = context.http_request.body
16
18
  context.http_request.headers['Content-Md5'] ||= md5(body)
17
19
  end
@@ -20,6 +22,12 @@ module Aws
20
22
 
21
23
  private
22
24
 
25
+ def checksum_required?(context)
26
+ context.operation.http_checksum_required ||
27
+ (context.operation.http_checksum &&
28
+ context.operation.http_checksum['requestChecksumRequired'])
29
+ end
30
+
23
31
  # @param [File, Tempfile, IO#read, String] value
24
32
  # @return [String<MD5>]
25
33
  def md5(value)
@@ -12,18 +12,8 @@ module Aws
12
12
  class Handler < Seahorse::Client::Handler
13
13
 
14
14
  def call(context)
15
- apply_invocation_id(context)
16
- @handler.call(context)
17
- end
18
-
19
- private
20
-
21
- def apply_invocation_id(context)
22
15
  context.http_request.headers['amz-sdk-invocation-id'] = SecureRandom.uuid
23
- if context[:input_event_emitter]
24
- # only used for eventstreaming at input
25
- context.http_request.headers['x-amz-content-sha256'] = 'STREAMING-AWS4-HMAC-SHA256-EVENTS'
26
- end
16
+ @handler.call(context)
27
17
  end
28
18
 
29
19
  end
@@ -11,15 +11,43 @@ module Aws
11
11
 
12
12
  def call(context)
13
13
  context.operation.input.shape.members.each do |m, ref|
14
- if ref['jsonvalue']
15
- param_value = context.params[m]
16
- unless param_value.respond_to?(:to_json)
17
- raise ArgumentError, "The value of params[#{m}] is not JSON serializable."
14
+ convert_jsonvalue(m, ref, context.params, 'params')
15
+ end
16
+ @handler.call(context)
17
+ end
18
+
19
+ def convert_jsonvalue(m, ref, params, context)
20
+ return if params.nil? || !params.key?(m)
21
+
22
+ if ref['jsonvalue']
23
+ params[m] = serialize_jsonvalue(params[m], "#{context}[#{m}]")
24
+ else
25
+ case ref.shape
26
+ when Seahorse::Model::Shapes::StructureShape
27
+ ref.shape.members.each do |member_m, ref|
28
+ convert_jsonvalue(member_m, ref, params[m], "#{context}[#{m}]")
29
+ end
30
+ when Seahorse::Model::Shapes::ListShape
31
+ if ref.shape.member['jsonvalue']
32
+ params[m] = params[m].each_with_index.map do |v, i|
33
+ serialize_jsonvalue(v, "#{context}[#{m}][#{i}]")
34
+ end
35
+ end
36
+ when Seahorse::Model::Shapes::MapShape
37
+ if ref.shape.value['jsonvalue']
38
+ params[m].each do |k, v|
39
+ params[m][k] = serialize_jsonvalue(v, "#{context}[#{m}][#{k}]")
40
+ end
18
41
  end
19
- context.params[m] = param_value.to_json
20
42
  end
21
43
  end
22
- @handler.call(context)
44
+ end
45
+
46
+ def serialize_jsonvalue(v, context)
47
+ unless v.respond_to?(:to_json)
48
+ raise ArgumentError, "The value of #{context} is not JSON serializable."
49
+ end
50
+ v.to_json
23
51
  end
24
52
 
25
53
  end
@@ -8,6 +8,7 @@ module Aws
8
8
 
9
9
  option(:logger,
10
10
  doc_type: 'Logger',
11
+ rbs_type: 'untyped',
11
12
  docstring: <<-DOCS
12
13
  The Logger instance to send log messages to. If this option
13
14
  is not set, logging will be disabled.
@@ -22,6 +23,7 @@ is not set, logging will be disabled.
22
23
 
23
24
  option(:log_formatter,
24
25
  doc_type: 'Aws::Log::Formatter',
26
+ rbs_type: 'untyped',
25
27
  doc_default: literal('Aws::Log::Formatter.default'),
26
28
  docstring: 'The log formatter.'
27
29
  ) do |config|
@@ -4,9 +4,26 @@ module Aws
4
4
  module Plugins
5
5
  module Protocols
6
6
  class ApiGateway < Seahorse::Client::Plugin
7
+
8
+ class ContentTypeHandler < Seahorse::Client::Handler
9
+ def call(context)
10
+ body = context.http_request.body
11
+ # Rest::Handler will set a default JSON body, so size can be checked
12
+ # if this handler is run after serialization.
13
+ if !body.respond_to?(:size) ||
14
+ (body.respond_to?(:size) && body.size > 0)
15
+ context.http_request.headers['Content-Type'] ||=
16
+ 'application/json'
17
+ end
18
+ @handler.call(context)
19
+ end
20
+ end
21
+
7
22
  handler(Rest::Handler)
23
+ handler(ContentTypeHandler, priority: 30)
8
24
  handler(Json::ErrorHandler, step: :sign)
9
25
  end
26
+
10
27
  end
11
28
  end
12
29
  end
@@ -4,11 +4,13 @@ module Aws
4
4
  module Plugins
5
5
  module Protocols
6
6
  class RestJson < Seahorse::Client::Plugin
7
-
8
7
  handler(Rest::Handler)
8
+ # Rest::Handler will set a default JSON body, so size can be checked
9
+ # if this handler is run after serialization.
10
+ handler(Rest::ContentTypeHandler, priority: 30)
9
11
  handler(Json::ErrorHandler, step: :sign)
10
-
11
12
  end
13
+
12
14
  end
13
15
  end
14
16
  end
@@ -4,10 +4,9 @@ module Aws
4
4
  module Plugins
5
5
  module Protocols
6
6
  class RestXml < Seahorse::Client::Plugin
7
-
8
7
  handler(Rest::Handler)
8
+ handler(Rest::ContentTypeHandler)
9
9
  handler(Xml::ErrorHandler, step: :sign)
10
-
11
10
  end
12
11
  end
13
12
  end