aws-sdk-core 3.100.0 → 3.130.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 (207) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +1294 -0
  3. data/LICENSE.txt +202 -0
  4. data/VERSION +1 -1
  5. data/lib/aws-defaults/default_configuration.rb +153 -0
  6. data/lib/aws-defaults/defaults_mode_config_resolver.rb +107 -0
  7. data/lib/aws-defaults.rb +3 -0
  8. data/lib/aws-sdk-core/arn.rb +15 -0
  9. data/lib/aws-sdk-core/arn_parser.rb +2 -0
  10. data/lib/aws-sdk-core/assume_role_credentials.rb +21 -0
  11. data/lib/aws-sdk-core/assume_role_web_identity_credentials.rb +9 -1
  12. data/lib/aws-sdk-core/async_client_stubs.rb +2 -0
  13. data/lib/aws-sdk-core/binary/decode_handler.rb +2 -0
  14. data/lib/aws-sdk-core/binary/encode_handler.rb +2 -0
  15. data/lib/aws-sdk-core/binary/event_builder.rb +2 -0
  16. data/lib/aws-sdk-core/binary/event_parser.rb +2 -0
  17. data/lib/aws-sdk-core/binary/event_stream_decoder.rb +2 -0
  18. data/lib/aws-sdk-core/binary/event_stream_encoder.rb +2 -0
  19. data/lib/aws-sdk-core/binary.rb +2 -0
  20. data/lib/aws-sdk-core/client_side_monitoring/publisher.rb +2 -0
  21. data/lib/aws-sdk-core/client_side_monitoring/request_metrics.rb +2 -0
  22. data/lib/aws-sdk-core/client_stubs.rb +7 -1
  23. data/lib/aws-sdk-core/credential_provider.rb +2 -0
  24. data/lib/aws-sdk-core/credential_provider_chain.rb +23 -1
  25. data/lib/aws-sdk-core/credentials.rb +2 -0
  26. data/lib/aws-sdk-core/deprecations.rb +2 -0
  27. data/lib/aws-sdk-core/eager_loader.rb +2 -0
  28. data/lib/aws-sdk-core/ec2_metadata.rb +238 -0
  29. data/lib/aws-sdk-core/ecs_credentials.rb +10 -4
  30. data/lib/aws-sdk-core/endpoint_cache.rb +2 -0
  31. data/lib/aws-sdk-core/errors.rb +11 -2
  32. data/lib/aws-sdk-core/event_emitter.rb +2 -0
  33. data/lib/aws-sdk-core/ini_parser.rb +2 -0
  34. data/lib/aws-sdk-core/instance_profile_credentials.rb +124 -22
  35. data/lib/aws-sdk-core/json/builder.rb +2 -0
  36. data/lib/aws-sdk-core/json/error_handler.rb +2 -0
  37. data/lib/aws-sdk-core/json/handler.rb +2 -0
  38. data/lib/aws-sdk-core/json/json_engine.rb +12 -8
  39. data/lib/aws-sdk-core/json/oj_engine.rb +35 -6
  40. data/lib/aws-sdk-core/json/parser.rb +10 -0
  41. data/lib/aws-sdk-core/json.rb +10 -26
  42. data/lib/aws-sdk-core/log/formatter.rb +9 -3
  43. data/lib/aws-sdk-core/log/handler.rb +2 -0
  44. data/lib/aws-sdk-core/log/param_filter.rb +37 -12
  45. data/lib/aws-sdk-core/log/param_formatter.rb +2 -0
  46. data/lib/aws-sdk-core/pageable_response.rb +82 -32
  47. data/lib/aws-sdk-core/pager.rb +5 -0
  48. data/lib/aws-sdk-core/param_converter.rb +2 -0
  49. data/lib/aws-sdk-core/param_validator.rb +54 -4
  50. data/lib/aws-sdk-core/plugins/api_key.rb +5 -1
  51. data/lib/aws-sdk-core/plugins/apig_authorizer_token.rb +2 -0
  52. data/lib/aws-sdk-core/plugins/apig_credentials_configuration.rb +2 -0
  53. data/lib/aws-sdk-core/plugins/apig_user_agent.rb +2 -0
  54. data/lib/aws-sdk-core/plugins/checksum_algorithm.rb +340 -0
  55. data/lib/aws-sdk-core/plugins/client_metrics_plugin.rb +2 -0
  56. data/lib/aws-sdk-core/plugins/client_metrics_send_plugin.rb +2 -0
  57. data/lib/aws-sdk-core/plugins/credentials_configuration.rb +26 -7
  58. data/lib/aws-sdk-core/plugins/defaults_mode.rb +40 -0
  59. data/lib/aws-sdk-core/plugins/endpoint_discovery.rb +2 -0
  60. data/lib/aws-sdk-core/plugins/endpoint_pattern.rb +8 -6
  61. data/lib/aws-sdk-core/plugins/event_stream_configuration.rb +2 -0
  62. data/lib/aws-sdk-core/plugins/global_configuration.rb +2 -0
  63. data/lib/aws-sdk-core/plugins/helpful_socket_errors.rb +2 -0
  64. data/lib/aws-sdk-core/plugins/http_checksum.rb +10 -1
  65. data/lib/aws-sdk-core/plugins/idempotency_token.rb +2 -0
  66. data/lib/aws-sdk-core/plugins/invocation_id.rb +2 -0
  67. data/lib/aws-sdk-core/plugins/jsonvalue_converter.rb +2 -0
  68. data/lib/aws-sdk-core/plugins/logging.rb +2 -0
  69. data/lib/aws-sdk-core/plugins/param_converter.rb +2 -0
  70. data/lib/aws-sdk-core/plugins/param_validator.rb +2 -0
  71. data/lib/aws-sdk-core/plugins/protocols/api_gateway.rb +19 -0
  72. data/lib/aws-sdk-core/plugins/protocols/ec2.rb +2 -0
  73. data/lib/aws-sdk-core/plugins/protocols/json_rpc.rb +2 -0
  74. data/lib/aws-sdk-core/plugins/protocols/query.rb +2 -0
  75. data/lib/aws-sdk-core/plugins/protocols/rest_json.rb +18 -1
  76. data/lib/aws-sdk-core/plugins/protocols/rest_xml.rb +2 -0
  77. data/lib/aws-sdk-core/plugins/recursion_detection.rb +27 -0
  78. data/lib/aws-sdk-core/plugins/regional_endpoint.rb +50 -2
  79. data/lib/aws-sdk-core/plugins/response_paging.rb +3 -1
  80. data/lib/aws-sdk-core/plugins/retries/client_rate_limiter.rb +2 -0
  81. data/lib/aws-sdk-core/plugins/retries/clock_skew.rb +2 -0
  82. data/lib/aws-sdk-core/plugins/retries/error_inspector.rb +7 -3
  83. data/lib/aws-sdk-core/plugins/retries/retry_quota.rb +2 -0
  84. data/lib/aws-sdk-core/plugins/retry_errors.rb +15 -6
  85. data/lib/aws-sdk-core/plugins/signature_v2.rb +2 -0
  86. data/lib/aws-sdk-core/plugins/signature_v4.rb +17 -24
  87. data/lib/aws-sdk-core/plugins/stub_responses.rb +9 -1
  88. data/lib/aws-sdk-core/plugins/transfer_encoding.rb +2 -0
  89. data/lib/aws-sdk-core/plugins/user_agent.rb +2 -0
  90. data/lib/aws-sdk-core/process_credentials.rb +8 -6
  91. data/lib/aws-sdk-core/query/ec2_param_builder.rb +2 -0
  92. data/lib/aws-sdk-core/query/handler.rb +2 -0
  93. data/lib/aws-sdk-core/query/param.rb +2 -0
  94. data/lib/aws-sdk-core/query/param_builder.rb +2 -0
  95. data/lib/aws-sdk-core/query/param_list.rb +2 -0
  96. data/lib/aws-sdk-core/query.rb +2 -0
  97. data/lib/aws-sdk-core/refreshing_credentials.rb +42 -11
  98. data/lib/aws-sdk-core/resources/collection.rb +2 -0
  99. data/lib/aws-sdk-core/rest/handler.rb +2 -0
  100. data/lib/aws-sdk-core/rest/request/body.rb +21 -1
  101. data/lib/aws-sdk-core/rest/request/builder.rb +2 -0
  102. data/lib/aws-sdk-core/rest/request/endpoint.rb +2 -0
  103. data/lib/aws-sdk-core/rest/request/headers.rb +20 -6
  104. data/lib/aws-sdk-core/rest/request/querystring_builder.rb +2 -0
  105. data/lib/aws-sdk-core/rest/response/body.rb +2 -0
  106. data/lib/aws-sdk-core/rest/response/headers.rb +6 -3
  107. data/lib/aws-sdk-core/rest/response/parser.rb +2 -0
  108. data/lib/aws-sdk-core/rest/response/status_code.rb +2 -0
  109. data/lib/aws-sdk-core/rest.rb +2 -0
  110. data/lib/aws-sdk-core/shared_config.rb +62 -8
  111. data/lib/aws-sdk-core/shared_credentials.rb +9 -1
  112. data/lib/aws-sdk-core/sso_credentials.rb +137 -0
  113. data/lib/aws-sdk-core/structure.rb +13 -2
  114. data/lib/aws-sdk-core/stubbing/data_applicator.rb +2 -0
  115. data/lib/aws-sdk-core/stubbing/empty_stub.rb +2 -0
  116. data/lib/aws-sdk-core/stubbing/protocols/api_gateway.rb +2 -0
  117. data/lib/aws-sdk-core/stubbing/protocols/ec2.rb +2 -0
  118. data/lib/aws-sdk-core/stubbing/protocols/json.rb +3 -1
  119. data/lib/aws-sdk-core/stubbing/protocols/query.rb +2 -0
  120. data/lib/aws-sdk-core/stubbing/protocols/rest.rb +3 -1
  121. data/lib/aws-sdk-core/stubbing/protocols/rest_json.rb +3 -1
  122. data/lib/aws-sdk-core/stubbing/protocols/rest_xml.rb +2 -2
  123. data/lib/aws-sdk-core/stubbing/stub_data.rb +2 -0
  124. data/lib/aws-sdk-core/stubbing/xml_error.rb +2 -0
  125. data/lib/aws-sdk-core/type_builder.rb +2 -0
  126. data/lib/aws-sdk-core/util.rb +2 -0
  127. data/lib/aws-sdk-core/waiters/errors.rb +2 -0
  128. data/lib/aws-sdk-core/waiters/poller.rb +2 -0
  129. data/lib/aws-sdk-core/waiters/waiter.rb +2 -0
  130. data/lib/aws-sdk-core/waiters.rb +2 -0
  131. data/lib/aws-sdk-core/xml/builder.rb +4 -2
  132. data/lib/aws-sdk-core/xml/default_list.rb +2 -0
  133. data/lib/aws-sdk-core/xml/default_map.rb +2 -0
  134. data/lib/aws-sdk-core/xml/doc_builder.rb +8 -1
  135. data/lib/aws-sdk-core/xml/error_handler.rb +2 -0
  136. data/lib/aws-sdk-core/xml/parser/engines/libxml.rb +2 -0
  137. data/lib/aws-sdk-core/xml/parser/engines/nokogiri.rb +2 -0
  138. data/lib/aws-sdk-core/xml/parser/engines/oga.rb +2 -0
  139. data/lib/aws-sdk-core/xml/parser/engines/ox.rb +3 -1
  140. data/lib/aws-sdk-core/xml/parser/engines/rexml.rb +2 -0
  141. data/lib/aws-sdk-core/xml/parser/frame.rb +25 -0
  142. data/lib/aws-sdk-core/xml/parser/parsing_error.rb +2 -0
  143. data/lib/aws-sdk-core/xml/parser/stack.rb +2 -0
  144. data/lib/aws-sdk-core/xml/parser.rb +7 -0
  145. data/lib/aws-sdk-core/xml.rb +2 -0
  146. data/lib/aws-sdk-core.rb +15 -3
  147. data/lib/aws-sdk-sso/client.rb +570 -0
  148. data/lib/aws-sdk-sso/client_api.rb +190 -0
  149. data/lib/aws-sdk-sso/customizations.rb +1 -0
  150. data/lib/aws-sdk-sso/errors.rb +102 -0
  151. data/lib/aws-sdk-sso/resource.rb +26 -0
  152. data/lib/aws-sdk-sso/types.rb +352 -0
  153. data/lib/aws-sdk-sso.rb +55 -0
  154. data/lib/aws-sdk-sts/client.rb +538 -435
  155. data/lib/aws-sdk-sts/client_api.rb +9 -1
  156. data/lib/aws-sdk-sts/customizations.rb +2 -0
  157. data/lib/aws-sdk-sts/errors.rb +3 -1
  158. data/lib/aws-sdk-sts/plugins/sts_regional_endpoints.rb +7 -1
  159. data/lib/aws-sdk-sts/presigner.rb +9 -1
  160. data/lib/aws-sdk-sts/resource.rb +3 -1
  161. data/lib/aws-sdk-sts/types.rb +360 -191
  162. data/lib/aws-sdk-sts.rb +10 -3
  163. data/lib/seahorse/client/async_base.rb +2 -0
  164. data/lib/seahorse/client/async_response.rb +2 -0
  165. data/lib/seahorse/client/base.rb +3 -0
  166. data/lib/seahorse/client/block_io.rb +5 -2
  167. data/lib/seahorse/client/configuration.rb +6 -0
  168. data/lib/seahorse/client/events.rb +2 -0
  169. data/lib/seahorse/client/h2/connection.rb +17 -13
  170. data/lib/seahorse/client/h2/handler.rb +6 -5
  171. data/lib/seahorse/client/handler.rb +2 -0
  172. data/lib/seahorse/client/handler_builder.rb +2 -0
  173. data/lib/seahorse/client/handler_list.rb +2 -0
  174. data/lib/seahorse/client/handler_list_entry.rb +2 -0
  175. data/lib/seahorse/client/http/async_response.rb +2 -0
  176. data/lib/seahorse/client/http/headers.rb +2 -0
  177. data/lib/seahorse/client/http/request.rb +2 -0
  178. data/lib/seahorse/client/http/response.rb +3 -1
  179. data/lib/seahorse/client/logging/formatter.rb +2 -0
  180. data/lib/seahorse/client/logging/handler.rb +2 -0
  181. data/lib/seahorse/client/managed_file.rb +2 -0
  182. data/lib/seahorse/client/net_http/connection_pool.rb +12 -4
  183. data/lib/seahorse/client/net_http/handler.rb +19 -8
  184. data/lib/seahorse/client/net_http/patches.rb +15 -84
  185. data/lib/seahorse/client/networking_error.rb +2 -0
  186. data/lib/seahorse/client/plugin.rb +2 -0
  187. data/lib/seahorse/client/plugin_list.rb +2 -0
  188. data/lib/seahorse/client/plugins/content_length.rb +13 -5
  189. data/lib/seahorse/client/plugins/endpoint.rb +2 -0
  190. data/lib/seahorse/client/plugins/h2.rb +6 -1
  191. data/lib/seahorse/client/plugins/logging.rb +2 -0
  192. data/lib/seahorse/client/plugins/net_http.rb +39 -3
  193. data/lib/seahorse/client/plugins/operation_methods.rb +2 -0
  194. data/lib/seahorse/client/plugins/raise_response_errors.rb +2 -0
  195. data/lib/seahorse/client/plugins/request_callback.rb +110 -0
  196. data/lib/seahorse/client/plugins/response_target.rb +8 -8
  197. data/lib/seahorse/client/request.rb +2 -0
  198. data/lib/seahorse/client/request_context.rb +2 -0
  199. data/lib/seahorse/client/response.rb +2 -0
  200. data/lib/seahorse/model/api.rb +2 -0
  201. data/lib/seahorse/model/authorizer.rb +2 -0
  202. data/lib/seahorse/model/operation.rb +5 -0
  203. data/lib/seahorse/model/shapes.rb +27 -0
  204. data/lib/seahorse/util.rb +8 -1
  205. data/lib/seahorse/version.rb +2 -0
  206. data/lib/seahorse.rb +3 -0
  207. metadata +26 -9
@@ -0,0 +1,340 @@
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[:checksum_algorithms] = request_algorithm_input
122
+
123
+ request_checksum_property = {
124
+ 'algorithm' => request_algorithm_input,
125
+ 'in' => checksum_request_in(context),
126
+ 'name' => "x-amz-checksum-#{request_algorithm_input.downcase}"
127
+ }
128
+
129
+ calculate_request_checksum(context, request_checksum_property)
130
+ end
131
+
132
+ if should_verify_response_checksum?(context)
133
+ add_verify_response_checksum_handlers(context)
134
+ end
135
+
136
+ @handler.call(context)
137
+ end
138
+
139
+ private
140
+
141
+ def should_calculate_request_checksum?(context)
142
+ context.operation.http_checksum &&
143
+ ChecksumAlgorithm.request_algorithm_selection(context)
144
+ end
145
+
146
+ def should_verify_response_checksum?(context)
147
+ context[:http_checksum][:validation_list] && !context[:http_checksum][:validation_list].empty?
148
+ end
149
+
150
+ def calculate_request_checksum(context, checksum_properties)
151
+ case checksum_properties['in']
152
+ when 'header'
153
+ header_name = checksum_properties['name']
154
+ body = context.http_request.body_contents
155
+ if body
156
+ context.http_request.headers[header_name] ||=
157
+ ChecksumAlgorithm.calculate_checksum(checksum_properties['algorithm'], body)
158
+ end
159
+ when 'trailer'
160
+ apply_request_trailer_checksum(context, checksum_properties)
161
+ end
162
+ end
163
+
164
+ def apply_request_trailer_checksum(context, checksum_properties)
165
+ location_name = checksum_properties['name']
166
+
167
+ # set required headers
168
+ headers = context.http_request.headers
169
+ headers['Content-Encoding'] = 'aws-chunked'
170
+ headers['X-Amz-Content-Sha256'] = 'STREAMING-UNSIGNED-PAYLOAD-TRAILER'
171
+ headers['X-Amz-Trailer'] = location_name
172
+
173
+ # We currently always compute the size in the modified body wrapper - allowing us
174
+ # to set the Content-Length header (set by content_length plugin).
175
+ # This means we cannot use Transfer-Encoding=chunked
176
+
177
+ if !context.http_request.body.respond_to?(:size)
178
+ raise Aws::Errors::ChecksumError, 'Could not determine length of the body'
179
+ end
180
+ headers['X-Amz-Decoded-Content-Length'] = context.http_request.body.size
181
+
182
+ context.http_request.body = AwsChunkedTrailerDigestIO.new(
183
+ context.http_request.body,
184
+ checksum_properties['algorithm'],
185
+ location_name
186
+ )
187
+ end
188
+
189
+ # Add events to the http_response to verify the checksum as its read
190
+ # This prevents the body from being read multiple times
191
+ # verification is done only once a successful response has completed
192
+ def add_verify_response_checksum_handlers(context)
193
+ http_response = context.http_response
194
+ checksum_context = { }
195
+ http_response.on_headers do |_status, headers|
196
+ header_name, algorithm = response_header_to_verify(headers, context[:http_checksum][:validation_list])
197
+ if header_name
198
+ expected = headers[header_name]
199
+
200
+ unless context[:http_checksum][:skip_on_suffix] && /-[\d]+$/.match(expected)
201
+ checksum_context[:algorithm] = algorithm
202
+ checksum_context[:header_name] = header_name
203
+ checksum_context[:digest] = ChecksumAlgorithm.digest_for_algorithm(algorithm)
204
+ checksum_context[:expected] = expected
205
+ end
206
+ end
207
+ end
208
+
209
+ http_response.on_data do |chunk|
210
+ checksum_context[:digest].update(chunk) if checksum_context[:digest]
211
+ end
212
+
213
+ http_response.on_success do
214
+ if checksum_context[:digest] &&
215
+ (computed = checksum_context[:digest].base64digest)
216
+
217
+ if computed != checksum_context[:expected]
218
+ raise Aws::Errors::ChecksumError,
219
+ "Checksum validation failed on #{checksum_context[:header_name]} "\
220
+ "computed: #{computed}, expected: #{checksum_context[:expected]}"
221
+ end
222
+
223
+ context[:http_checksum][:validated] = checksum_context[:algorithm]
224
+ end
225
+ end
226
+ end
227
+
228
+ # returns nil if no headers to verify
229
+ def response_header_to_verify(headers, validation_list)
230
+ validation_list.each do |algorithm|
231
+ header_name = "x-amz-checksum-#{algorithm}"
232
+ return [header_name, algorithm] if headers[header_name]
233
+ end
234
+ nil
235
+ end
236
+
237
+ # determine where (header vs trailer) a request checksum should be added
238
+ def checksum_request_in(context)
239
+ if context.operation['authtype'].eql?('v4-unsigned-body')
240
+ 'trailer'
241
+ else
242
+ 'header'
243
+ end
244
+ end
245
+
246
+ end
247
+
248
+ def self.calculate_checksum(algorithm, body)
249
+ digest = ChecksumAlgorithm.digest_for_algorithm(algorithm)
250
+ if body.respond_to?(:read)
251
+ ChecksumAlgorithm.update_in_chunks(digest, body)
252
+ else
253
+ digest.update(body)
254
+ end
255
+ digest.base64digest
256
+ end
257
+
258
+ def self.digest_for_algorithm(algorithm)
259
+ case algorithm
260
+ when 'CRC32'
261
+ Digest32.new(Zlib.method(:crc32))
262
+ when 'CRC32C'
263
+ # this will only be used if input algorithm is CRC32C AND client supports it (crt available)
264
+ Digest32.new(Aws::Crt::Checksums.method(:crc32c))
265
+ when 'SHA1'
266
+ Digest::SHA1.new
267
+ when 'SHA256'
268
+ Digest::SHA256.new
269
+ end
270
+ end
271
+
272
+ # The trailer size (in bytes) is the overhead + the trailer name +
273
+ # the length of the base64 encoded checksum
274
+ def self.trailer_length(algorithm, location_name)
275
+ CHECKSUM_SIZE[algorithm] + location_name.size
276
+ end
277
+
278
+ def self.update_in_chunks(digest, io)
279
+ loop do
280
+ chunk = io.read(CHUNK_SIZE)
281
+ break unless chunk
282
+ digest.update(chunk)
283
+ end
284
+ io.rewind
285
+ end
286
+
287
+ # Wrapper for request body that implements application-layer
288
+ # chunking with Digest computed on chunks + added as a trailer
289
+ class AwsChunkedTrailerDigestIO
290
+ CHUNK_SIZE = 16384
291
+
292
+ def initialize(io, algorithm, location_name)
293
+ @io = io
294
+ @location_name = location_name
295
+ @algorithm = algorithm
296
+ @digest = ChecksumAlgorithm.digest_for_algorithm(algorithm)
297
+ @trailer_io = nil
298
+ end
299
+
300
+ # the size of the application layer aws-chunked + trailer body
301
+ def size
302
+ # compute the number of chunks
303
+ # a full chunk has 4 + 4 bytes overhead, a partial chunk is len.to_s(16).size + 4
304
+ orig_body_size = @io.size
305
+ n_full_chunks = orig_body_size / CHUNK_SIZE
306
+ partial_bytes = orig_body_size % CHUNK_SIZE
307
+ chunked_body_size = n_full_chunks * (CHUNK_SIZE + 8)
308
+ chunked_body_size += partial_bytes.to_s(16).size + partial_bytes + 4 unless partial_bytes.zero?
309
+ trailer_size = ChecksumAlgorithm.trailer_length(@algorithm, @location_name)
310
+ chunked_body_size + trailer_size
311
+ end
312
+
313
+ def rewind
314
+ @io.rewind
315
+ end
316
+
317
+ def read(length, buf)
318
+ # account for possible leftover bytes at the end, if we have trailer bytes, send them
319
+ if @trailer_io
320
+ return @trailer_io.read(length, buf)
321
+ end
322
+
323
+ chunk = @io.read(length)
324
+ if chunk
325
+ @digest.update(chunk)
326
+ application_chunked = "#{chunk.bytesize.to_s(16)}\r\n#{chunk}\r\n"
327
+ return StringIO.new(application_chunked).read(application_chunked.size, buf)
328
+ else
329
+ trailers = {}
330
+ trailers[@location_name] = @digest.base64digest
331
+ trailers = trailers.map { |k,v| "#{k}:#{v}"}.join("\r\n")
332
+ @trailer_io = StringIO.new("0\r\n#{trailers}\r\n\r\n")
333
+ chunk = @trailer_io.read(length, buf)
334
+ end
335
+ chunk
336
+ end
337
+ end
338
+ end
339
+ end
340
+ end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'date'
2
4
  require_relative 'retries/error_inspector'
3
5
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'date'
2
4
 
3
5
  module Aws
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Aws
2
4
  # @api private
3
5
  module Plugins
@@ -28,13 +30,28 @@ following classes:
28
30
  * `Aws::Credentials` - Used for configuring static, non-refreshing
29
31
  credentials.
30
32
 
33
+ * `Aws::SharedCredentials` - Used for loading static credentials from a
34
+ shared file, such as `~/.aws/config`.
35
+
36
+ * `Aws::AssumeRoleCredentials` - Used when you need to assume a role.
37
+
38
+ * `Aws::AssumeRoleWebIdentityCredentials` - Used when you need to
39
+ assume a role after providing credentials via the web.
40
+
41
+ * `Aws::SSOCredentials` - Used for loading credentials from AWS SSO using an
42
+ access token generated from `aws login`.
43
+
44
+ * `Aws::ProcessCredentials` - Used for loading credentials from a
45
+ process that outputs to stdout.
46
+
31
47
  * `Aws::InstanceProfileCredentials` - Used for loading credentials
32
48
  from an EC2 IMDS on an EC2 instance.
33
49
 
34
- * `Aws::SharedCredentials` - Used for loading credentials from a
35
- shared file, such as `~/.aws/config`.
50
+ * `Aws::ECSCredentials` - Used for loading credentials from
51
+ instances running in ECS.
36
52
 
37
- * `Aws::AssumeRoleCredentials` - Used when you need to assume a role.
53
+ * `Aws::CognitoIdentityCredentials` - Used for loading credentials
54
+ from the Cognito Identity service.
38
55
 
39
56
  When `:credentials` are not configured directly, the following
40
57
  locations will be searched for credentials:
@@ -44,10 +61,12 @@ locations will be searched for credentials:
44
61
  * ENV['AWS_ACCESS_KEY_ID'], ENV['AWS_SECRET_ACCESS_KEY']
45
62
  * `~/.aws/credentials`
46
63
  * `~/.aws/config`
47
- * EC2 IMDS instance profile - When used by default, the timeouts are
48
- very aggressive. Construct and pass an instance of
49
- `Aws::InstanceProfileCredentails` to enable retries and extended
50
- timeouts.
64
+ * EC2/ECS IMDS instance profile - When used by default, the timeouts
65
+ are very aggressive. Construct and pass an instance of
66
+ `Aws::InstanceProfileCredentails` or `Aws::ECSCredentials` to
67
+ enable retries and extended timeouts. Instance profile credential
68
+ fetching can be disabled by setting ENV['AWS_EC2_METADATA_DISABLED']
69
+ to true.
51
70
  DOCS
52
71
  ) do |config|
53
72
  CredentialProviderChain.new(config).resolve
@@ -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
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Aws
2
4
  module Plugins
3
5
  # @api private
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Aws
2
4
  module Plugins
3
5
  # @api private
@@ -13,17 +15,17 @@ to default service endpoint when available.
13
15
  )
14
16
 
15
17
  def add_handlers(handlers, config)
16
- if config.regional_endpoint && !config.disable_host_prefix_injection
17
- handlers.add(Handler, priority: 90)
18
- end
18
+ handlers.add(Handler, priority: 10)
19
19
  end
20
20
 
21
21
  class Handler < Seahorse::Client::Handler
22
22
 
23
23
  def call(context)
24
- endpoint_trait = context.operation.endpoint_pattern
25
- if endpoint_trait && !endpoint_trait.empty?
26
- _apply_endpoint_trait(context, endpoint_trait)
24
+ if !context.config.disable_host_prefix_injection
25
+ endpoint_trait = context.operation.endpoint_pattern
26
+ if endpoint_trait && !endpoint_trait.empty?
27
+ _apply_endpoint_trait(context, endpoint_trait)
28
+ end
27
29
  end
28
30
  @handler.call(context)
29
31
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Aws
2
4
  module Plugins
3
5
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'set'
2
4
 
3
5
  module Aws
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Aws
2
4
  module Plugins
3
5
  # @api private
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'openssl'
2
4
 
3
5
  module Aws
@@ -9,7 +11,8 @@ module Aws
9
11
  CHUNK_SIZE = 1 * 1024 * 1024 # one MB
10
12
 
11
13
  def call(context)
12
- if context.operation.http_checksum_required
14
+ if checksum_required?(context) &&
15
+ !context[:checksum_algorithms] # skip in favor of flexible checksum
13
16
  body = context.http_request.body
14
17
  context.http_request.headers['Content-Md5'] ||= md5(body)
15
18
  end
@@ -18,6 +21,12 @@ module Aws
18
21
 
19
22
  private
20
23
 
24
+ def checksum_required?(context)
25
+ context.operation.http_checksum_required ||
26
+ (context.operation.http_checksum &&
27
+ context.operation.http_checksum['requestChecksumRequired'])
28
+ end
29
+
21
30
  # @param [File, Tempfile, IO#read, String] value
22
31
  # @return [String<MD5>]
23
32
  def md5(value)
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'securerandom'
2
4
 
3
5
  module Aws
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'securerandom'
2
4
 
3
5
  module Aws
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Aws
2
4
  module Plugins
3
5
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Aws
2
4
  module Plugins
3
5
  # @see Log::Formatter
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Aws
2
4
  module Plugins
3
5
  # @api private
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Aws
2
4
  module Plugins
3
5
  # @api private
@@ -1,10 +1,29 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Aws
2
4
  module Plugins
3
5
  module Protocols
4
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
+
5
22
  handler(Rest::Handler)
23
+ handler(ContentTypeHandler, priority: 30)
6
24
  handler(Json::ErrorHandler, step: :sign)
7
25
  end
26
+
8
27
  end
9
28
  end
10
29
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative '../../query'
2
4
 
3
5
  module Aws
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Aws
2
4
  module Plugins
3
5
  module Protocols
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative '../../query'
2
4
 
3
5
  module Aws
@@ -1,12 +1,29 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Aws
2
4
  module Plugins
3
5
  module Protocols
4
6
  class RestJson < Seahorse::Client::Plugin
5
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
+
6
22
  handler(Rest::Handler)
23
+ handler(ContentTypeHandler, priority: 30)
7
24
  handler(Json::ErrorHandler, step: :sign)
8
-
9
25
  end
26
+
10
27
  end
11
28
  end
12
29
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Aws
2
4
  module Plugins
3
5
  module Protocols