aws-sdk-core 3.100.0 → 3.191.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 (258) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +1815 -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 +28 -0
  9. data/lib/aws-sdk-core/arn_parser.rb +2 -0
  10. data/lib/aws-sdk-core/assume_role_credentials.rb +23 -7
  11. data/lib/aws-sdk-core/assume_role_web_identity_credentials.rb +16 -10
  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 +14 -1
  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 +22 -13
  23. data/lib/aws-sdk-core/credential_provider.rb +5 -0
  24. data/lib/aws-sdk-core/credential_provider_chain.rb +31 -6
  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 +188 -53
  30. data/lib/aws-sdk-core/endpoint_cache.rb +2 -0
  31. data/lib/aws-sdk-core/endpoints/condition.rb +41 -0
  32. data/lib/aws-sdk-core/endpoints/endpoint.rb +17 -0
  33. data/lib/aws-sdk-core/endpoints/endpoint_rule.rb +75 -0
  34. data/lib/aws-sdk-core/endpoints/error_rule.rb +42 -0
  35. data/lib/aws-sdk-core/endpoints/function.rb +80 -0
  36. data/lib/aws-sdk-core/endpoints/matchers.rb +131 -0
  37. data/lib/aws-sdk-core/endpoints/reference.rb +31 -0
  38. data/lib/aws-sdk-core/endpoints/rule.rb +25 -0
  39. data/lib/aws-sdk-core/endpoints/rule_set.rb +52 -0
  40. data/lib/aws-sdk-core/endpoints/rules_provider.rb +37 -0
  41. data/lib/aws-sdk-core/endpoints/templater.rb +58 -0
  42. data/lib/aws-sdk-core/endpoints/tree_rule.rb +45 -0
  43. data/lib/aws-sdk-core/endpoints/url.rb +60 -0
  44. data/lib/aws-sdk-core/endpoints.rb +78 -0
  45. data/lib/aws-sdk-core/errors.rb +27 -5
  46. data/lib/aws-sdk-core/event_emitter.rb +2 -0
  47. data/lib/aws-sdk-core/ini_parser.rb +9 -0
  48. data/lib/aws-sdk-core/instance_profile_credentials.rb +167 -38
  49. data/lib/aws-sdk-core/json/builder.rb +2 -0
  50. data/lib/aws-sdk-core/json/error_handler.rb +22 -1
  51. data/lib/aws-sdk-core/json/handler.rb +10 -1
  52. data/lib/aws-sdk-core/json/json_engine.rb +12 -8
  53. data/lib/aws-sdk-core/json/oj_engine.rb +35 -6
  54. data/lib/aws-sdk-core/json/parser.rb +36 -1
  55. data/lib/aws-sdk-core/json.rb +10 -26
  56. data/lib/aws-sdk-core/log/formatter.rb +15 -3
  57. data/lib/aws-sdk-core/log/handler.rb +2 -0
  58. data/lib/aws-sdk-core/log/param_filter.rb +37 -12
  59. data/lib/aws-sdk-core/log/param_formatter.rb +2 -0
  60. data/lib/aws-sdk-core/pageable_response.rb +91 -32
  61. data/lib/aws-sdk-core/pager.rb +5 -0
  62. data/lib/aws-sdk-core/param_converter.rb +2 -0
  63. data/lib/aws-sdk-core/param_validator.rb +56 -6
  64. data/lib/aws-sdk-core/plugins/api_key.rb +5 -1
  65. data/lib/aws-sdk-core/plugins/apig_authorizer_token.rb +2 -0
  66. data/lib/aws-sdk-core/plugins/apig_credentials_configuration.rb +2 -0
  67. data/lib/aws-sdk-core/plugins/apig_user_agent.rb +2 -0
  68. data/lib/aws-sdk-core/plugins/bearer_authorization.rb +67 -0
  69. data/lib/aws-sdk-core/plugins/checksum_algorithm.rb +342 -0
  70. data/lib/aws-sdk-core/plugins/client_metrics_plugin.rb +3 -0
  71. data/lib/aws-sdk-core/plugins/client_metrics_send_plugin.rb +2 -0
  72. data/lib/aws-sdk-core/plugins/credentials_configuration.rb +52 -7
  73. data/lib/aws-sdk-core/plugins/defaults_mode.rb +40 -0
  74. data/lib/aws-sdk-core/plugins/endpoint_discovery.rb +8 -2
  75. data/lib/aws-sdk-core/plugins/endpoint_pattern.rb +8 -6
  76. data/lib/aws-sdk-core/plugins/event_stream_configuration.rb +2 -0
  77. data/lib/aws-sdk-core/plugins/global_configuration.rb +2 -0
  78. data/lib/aws-sdk-core/plugins/helpful_socket_errors.rb +2 -0
  79. data/lib/aws-sdk-core/plugins/http_checksum.rb +11 -1
  80. data/lib/aws-sdk-core/plugins/idempotency_token.rb +2 -0
  81. data/lib/aws-sdk-core/plugins/invocation_id.rb +2 -0
  82. data/lib/aws-sdk-core/plugins/jsonvalue_converter.rb +36 -6
  83. data/lib/aws-sdk-core/plugins/logging.rb +4 -0
  84. data/lib/aws-sdk-core/plugins/param_converter.rb +2 -0
  85. data/lib/aws-sdk-core/plugins/param_validator.rb +2 -0
  86. data/lib/aws-sdk-core/plugins/protocols/api_gateway.rb +19 -0
  87. data/lib/aws-sdk-core/plugins/protocols/ec2.rb +2 -0
  88. data/lib/aws-sdk-core/plugins/protocols/json_rpc.rb +2 -0
  89. data/lib/aws-sdk-core/plugins/protocols/query.rb +2 -0
  90. data/lib/aws-sdk-core/plugins/protocols/rest_json.rb +18 -1
  91. data/lib/aws-sdk-core/plugins/protocols/rest_xml.rb +2 -0
  92. data/lib/aws-sdk-core/plugins/recursion_detection.rb +38 -0
  93. data/lib/aws-sdk-core/plugins/regional_endpoint.rb +146 -17
  94. data/lib/aws-sdk-core/plugins/request_compression.rb +217 -0
  95. data/lib/aws-sdk-core/plugins/response_paging.rb +3 -1
  96. data/lib/aws-sdk-core/plugins/retries/client_rate_limiter.rb +2 -0
  97. data/lib/aws-sdk-core/plugins/retries/clock_skew.rb +2 -0
  98. data/lib/aws-sdk-core/plugins/retries/error_inspector.rb +9 -4
  99. data/lib/aws-sdk-core/plugins/retries/retry_quota.rb +2 -0
  100. data/lib/aws-sdk-core/plugins/retry_errors.rb +29 -8
  101. data/lib/aws-sdk-core/plugins/sign.rb +206 -0
  102. data/lib/aws-sdk-core/plugins/signature_v2.rb +3 -0
  103. data/lib/aws-sdk-core/plugins/signature_v4.rb +30 -31
  104. data/lib/aws-sdk-core/plugins/stub_responses.rb +10 -1
  105. data/lib/aws-sdk-core/plugins/transfer_encoding.rb +2 -0
  106. data/lib/aws-sdk-core/plugins/user_agent.rb +119 -14
  107. data/lib/aws-sdk-core/process_credentials.rb +14 -15
  108. data/lib/aws-sdk-core/query/ec2_param_builder.rb +2 -0
  109. data/lib/aws-sdk-core/query/handler.rb +2 -0
  110. data/lib/aws-sdk-core/query/param.rb +2 -0
  111. data/lib/aws-sdk-core/query/param_builder.rb +2 -0
  112. data/lib/aws-sdk-core/query/param_list.rb +2 -0
  113. data/lib/aws-sdk-core/query.rb +2 -0
  114. data/lib/aws-sdk-core/refreshing_credentials.rb +50 -17
  115. data/lib/aws-sdk-core/refreshing_token.rb +71 -0
  116. data/lib/aws-sdk-core/resources/collection.rb +2 -0
  117. data/lib/aws-sdk-core/rest/handler.rb +3 -1
  118. data/lib/aws-sdk-core/rest/request/body.rb +21 -1
  119. data/lib/aws-sdk-core/rest/request/builder.rb +2 -0
  120. data/lib/aws-sdk-core/rest/request/endpoint.rb +2 -0
  121. data/lib/aws-sdk-core/rest/request/headers.rb +16 -6
  122. data/lib/aws-sdk-core/rest/request/querystring_builder.rb +45 -29
  123. data/lib/aws-sdk-core/rest/response/body.rb +2 -0
  124. data/lib/aws-sdk-core/rest/response/headers.rb +6 -3
  125. data/lib/aws-sdk-core/rest/response/parser.rb +2 -0
  126. data/lib/aws-sdk-core/rest/response/status_code.rb +2 -0
  127. data/lib/aws-sdk-core/rest.rb +2 -0
  128. data/lib/aws-sdk-core/shared_config.rb +163 -8
  129. data/lib/aws-sdk-core/shared_credentials.rb +9 -1
  130. data/lib/aws-sdk-core/sso_credentials.rb +172 -0
  131. data/lib/aws-sdk-core/sso_token_provider.rb +135 -0
  132. data/lib/aws-sdk-core/static_token_provider.rb +14 -0
  133. data/lib/aws-sdk-core/structure.rb +19 -6
  134. data/lib/aws-sdk-core/stubbing/data_applicator.rb +2 -0
  135. data/lib/aws-sdk-core/stubbing/empty_stub.rb +2 -0
  136. data/lib/aws-sdk-core/stubbing/protocols/api_gateway.rb +2 -0
  137. data/lib/aws-sdk-core/stubbing/protocols/ec2.rb +2 -0
  138. data/lib/aws-sdk-core/stubbing/protocols/json.rb +3 -1
  139. data/lib/aws-sdk-core/stubbing/protocols/query.rb +2 -0
  140. data/lib/aws-sdk-core/stubbing/protocols/rest.rb +3 -1
  141. data/lib/aws-sdk-core/stubbing/protocols/rest_json.rb +3 -1
  142. data/lib/aws-sdk-core/stubbing/protocols/rest_xml.rb +2 -2
  143. data/lib/aws-sdk-core/stubbing/stub_data.rb +13 -0
  144. data/lib/aws-sdk-core/stubbing/xml_error.rb +2 -0
  145. data/lib/aws-sdk-core/token.rb +31 -0
  146. data/lib/aws-sdk-core/token_provider.rb +15 -0
  147. data/lib/aws-sdk-core/token_provider_chain.rb +51 -0
  148. data/lib/aws-sdk-core/type_builder.rb +2 -0
  149. data/lib/aws-sdk-core/util.rb +2 -0
  150. data/lib/aws-sdk-core/waiters/errors.rb +2 -0
  151. data/lib/aws-sdk-core/waiters/poller.rb +6 -2
  152. data/lib/aws-sdk-core/waiters/waiter.rb +2 -0
  153. data/lib/aws-sdk-core/waiters.rb +2 -0
  154. data/lib/aws-sdk-core/xml/builder.rb +4 -2
  155. data/lib/aws-sdk-core/xml/default_list.rb +2 -0
  156. data/lib/aws-sdk-core/xml/default_map.rb +2 -0
  157. data/lib/aws-sdk-core/xml/doc_builder.rb +8 -1
  158. data/lib/aws-sdk-core/xml/error_handler.rb +9 -0
  159. data/lib/aws-sdk-core/xml/parser/engines/libxml.rb +2 -0
  160. data/lib/aws-sdk-core/xml/parser/engines/nokogiri.rb +2 -0
  161. data/lib/aws-sdk-core/xml/parser/engines/oga.rb +4 -0
  162. data/lib/aws-sdk-core/xml/parser/engines/ox.rb +3 -1
  163. data/lib/aws-sdk-core/xml/parser/engines/rexml.rb +2 -0
  164. data/lib/aws-sdk-core/xml/parser/frame.rb +25 -0
  165. data/lib/aws-sdk-core/xml/parser/parsing_error.rb +2 -0
  166. data/lib/aws-sdk-core/xml/parser/stack.rb +2 -0
  167. data/lib/aws-sdk-core/xml/parser.rb +7 -0
  168. data/lib/aws-sdk-core/xml.rb +2 -0
  169. data/lib/aws-sdk-core.rb +29 -3
  170. data/lib/aws-sdk-sso/client.rb +630 -0
  171. data/lib/aws-sdk-sso/client_api.rb +190 -0
  172. data/lib/aws-sdk-sso/customizations.rb +1 -0
  173. data/lib/aws-sdk-sso/endpoint_parameters.rb +66 -0
  174. data/lib/aws-sdk-sso/endpoint_provider.rb +57 -0
  175. data/lib/aws-sdk-sso/endpoints.rb +72 -0
  176. data/lib/aws-sdk-sso/errors.rb +102 -0
  177. data/lib/aws-sdk-sso/plugins/endpoints.rb +78 -0
  178. data/lib/aws-sdk-sso/resource.rb +26 -0
  179. data/lib/aws-sdk-sso/types.rb +317 -0
  180. data/lib/aws-sdk-sso.rb +59 -0
  181. data/lib/aws-sdk-ssooidc/client.rb +935 -0
  182. data/lib/aws-sdk-ssooidc/client_api.rb +271 -0
  183. data/lib/aws-sdk-ssooidc/customizations.rb +1 -0
  184. data/lib/aws-sdk-ssooidc/endpoint_parameters.rb +66 -0
  185. data/lib/aws-sdk-ssooidc/endpoint_provider.rb +57 -0
  186. data/lib/aws-sdk-ssooidc/endpoints.rb +72 -0
  187. data/lib/aws-sdk-ssooidc/errors.rb +321 -0
  188. data/lib/aws-sdk-ssooidc/plugins/endpoints.rb +78 -0
  189. data/lib/aws-sdk-ssooidc/resource.rb +26 -0
  190. data/lib/aws-sdk-ssooidc/types.rb +755 -0
  191. data/lib/aws-sdk-ssooidc.rb +59 -0
  192. data/lib/aws-sdk-sts/client.rb +655 -490
  193. data/lib/aws-sdk-sts/client_api.rb +21 -2
  194. data/lib/aws-sdk-sts/customizations.rb +2 -0
  195. data/lib/aws-sdk-sts/endpoint_parameters.rb +78 -0
  196. data/lib/aws-sdk-sts/endpoint_provider.rb +112 -0
  197. data/lib/aws-sdk-sts/endpoints.rb +136 -0
  198. data/lib/aws-sdk-sts/errors.rb +3 -1
  199. data/lib/aws-sdk-sts/plugins/endpoints.rb +86 -0
  200. data/lib/aws-sdk-sts/plugins/sts_regional_endpoints.rb +7 -1
  201. data/lib/aws-sdk-sts/presigner.rb +16 -10
  202. data/lib/aws-sdk-sts/resource.rb +3 -1
  203. data/lib/aws-sdk-sts/types.rb +416 -316
  204. data/lib/aws-sdk-sts.rb +14 -3
  205. data/lib/seahorse/client/async_base.rb +2 -1
  206. data/lib/seahorse/client/async_response.rb +2 -0
  207. data/lib/seahorse/client/base.rb +3 -0
  208. data/lib/seahorse/client/block_io.rb +5 -2
  209. data/lib/seahorse/client/configuration.rb +7 -5
  210. data/lib/seahorse/client/events.rb +2 -0
  211. data/lib/seahorse/client/h2/connection.rb +29 -24
  212. data/lib/seahorse/client/h2/handler.rb +6 -5
  213. data/lib/seahorse/client/handler.rb +2 -0
  214. data/lib/seahorse/client/handler_builder.rb +2 -0
  215. data/lib/seahorse/client/handler_list.rb +2 -0
  216. data/lib/seahorse/client/handler_list_entry.rb +2 -0
  217. data/lib/seahorse/client/http/async_response.rb +2 -0
  218. data/lib/seahorse/client/http/headers.rb +2 -0
  219. data/lib/seahorse/client/http/request.rb +2 -0
  220. data/lib/seahorse/client/http/response.rb +3 -1
  221. data/lib/seahorse/client/logging/formatter.rb +2 -0
  222. data/lib/seahorse/client/logging/handler.rb +2 -0
  223. data/lib/seahorse/client/managed_file.rb +2 -0
  224. data/lib/seahorse/client/net_http/connection_pool.rb +12 -4
  225. data/lib/seahorse/client/net_http/handler.rb +19 -8
  226. data/lib/seahorse/client/net_http/patches.rb +14 -86
  227. data/lib/seahorse/client/networking_error.rb +2 -0
  228. data/lib/seahorse/client/plugin.rb +3 -0
  229. data/lib/seahorse/client/plugin_list.rb +2 -0
  230. data/lib/seahorse/client/plugins/content_length.rb +13 -5
  231. data/lib/seahorse/client/plugins/endpoint.rb +2 -0
  232. data/lib/seahorse/client/plugins/h2.rb +9 -4
  233. data/lib/seahorse/client/plugins/logging.rb +2 -0
  234. data/lib/seahorse/client/plugins/net_http.rb +39 -3
  235. data/lib/seahorse/client/plugins/operation_methods.rb +2 -0
  236. data/lib/seahorse/client/plugins/raise_response_errors.rb +2 -0
  237. data/lib/seahorse/client/plugins/request_callback.rb +141 -0
  238. data/lib/seahorse/client/plugins/response_target.rb +8 -8
  239. data/lib/seahorse/client/request.rb +2 -0
  240. data/lib/seahorse/client/request_context.rb +2 -0
  241. data/lib/seahorse/client/response.rb +8 -0
  242. data/lib/seahorse/model/api.rb +2 -0
  243. data/lib/seahorse/model/authorizer.rb +2 -0
  244. data/lib/seahorse/model/operation.rb +8 -0
  245. data/lib/seahorse/model/shapes.rb +27 -0
  246. data/lib/seahorse/util.rb +12 -1
  247. data/lib/seahorse/version.rb +2 -0
  248. data/lib/seahorse.rb +3 -0
  249. data/sig/aws-sdk-core/client_stubs.rbs +10 -0
  250. data/sig/aws-sdk-core/errors.rbs +22 -0
  251. data/sig/aws-sdk-core/resources/collection.rbs +21 -0
  252. data/sig/aws-sdk-core/structure.rbs +4 -0
  253. data/sig/aws-sdk-core/waiters/errors.rbs +20 -0
  254. data/sig/aws-sdk-core.rbs +7 -0
  255. data/sig/seahorse/client/base.rbs +25 -0
  256. data/sig/seahorse/client/handler_builder.rbs +16 -0
  257. data/sig/seahorse/client/response.rbs +61 -0
  258. metadata +93 -19
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Aws
2
4
  module Binary
3
5
 
@@ -11,7 +13,7 @@ module Aws
11
13
  context.config.api.metadata['protocol'],
12
14
  eventstream_member,
13
15
  context.operation.input,
14
- context.config.sigv4_signer
16
+ signer_for(context)
15
17
  )
16
18
  context[:input_event_emitter] = input_es_handler.event_emitter
17
19
  end
@@ -20,6 +22,17 @@ module Aws
20
22
 
21
23
  private
22
24
 
25
+ def signer_for(context)
26
+ # New endpoint/signing logic, use the auth scheme to make a signer
27
+ if context[:auth_scheme]
28
+ Aws::Plugins::Sign.signer_for(context[:auth_scheme], context.config)
29
+ else
30
+ # Previous implementation always assumed sigv4_signer from config.
31
+ # Relies only on sigv4 signing (and plugin) for event stream services
32
+ context.config.sigv4_signer
33
+ end
34
+ end
35
+
23
36
  def eventstream_input?(ctx)
24
37
  ctx.operation.input.shape.members.each do |_, ref|
25
38
  return ref if ref.eventstream
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Aws
2
4
  module Binary
3
5
  # @api private
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Aws
2
4
  module Binary
3
5
  # @api private
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'aws-eventstream'
2
4
 
3
5
  module Aws
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'aws-eventstream'
2
4
 
3
5
  module Aws
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative 'binary/decode_handler'
2
4
  require_relative 'binary/encode_handler'
3
5
  require_relative 'binary/event_stream_decoder'
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'thread'
2
4
  require 'socket'
3
5
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Aws
2
4
  module ClientSideMonitoring
3
5
  # @api private
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'thread'
2
4
 
3
5
  module Aws
@@ -22,15 +24,16 @@ module Aws
22
24
  end
23
25
 
24
26
  # When a client is stubbed allow the user to access the requests made
25
- @api_requests = []
26
-
27
- requests = @api_requests
27
+ requests = @api_requests = []
28
+ requests_mutex = @requests_mutex = Mutex.new
28
29
  self.handle do |context|
29
- requests << {
30
- operation_name: context.operation_name,
31
- params: context.params,
32
- context: context
33
- }
30
+ requests_mutex.synchronize do
31
+ requests << {
32
+ operation_name: context.operation_name,
33
+ params: context.params,
34
+ context: context
35
+ }
36
+ end
34
37
  @handler.call(context)
35
38
  end
36
39
  end
@@ -192,10 +195,12 @@ module Aws
192
195
  # is not stubbed.
193
196
  def api_requests(options = {})
194
197
  if config.stub_responses
195
- if options[:exclude_presign]
196
- @api_requests.reject {|req| req[:context][:presigned_url] }
197
- else
198
- @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
199
204
  end
200
205
  else
201
206
  msg = 'This method is only implemented for stubbed clients, and is '\
@@ -260,13 +265,17 @@ module Aws
260
265
  end
261
266
 
262
267
  def convert_stub(operation_name, stub)
263
- case stub
268
+ stub = case stub
264
269
  when Proc then stub
265
270
  when Exception, Class then { error: stub }
266
271
  when String then service_error_stub(stub)
267
272
  when Hash then http_response_stub(operation_name, stub)
268
273
  else { data: stub }
269
274
  end
275
+ if Hash === stub
276
+ stub[:mutex] = Mutex.new
277
+ end
278
+ stub
270
279
  end
271
280
 
272
281
  def service_error_stub(error_code)
@@ -1,9 +1,14 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Aws
2
4
  module CredentialProvider
3
5
 
4
6
  # @return [Credentials]
5
7
  attr_reader :credentials
6
8
 
9
+ # @return [Time]
10
+ attr_reader :expiration
11
+
7
12
  # @return [Boolean]
8
13
  def set?
9
14
  !!credentials && credentials.set?
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Aws
2
4
  # @api private
3
5
  class CredentialProviderChain
@@ -20,11 +22,13 @@ module Aws
20
22
  [
21
23
  [:static_credentials, {}],
22
24
  [:static_profile_assume_role_web_identity_credentials, {}],
25
+ [:static_profile_sso_credentials, {}],
23
26
  [:static_profile_assume_role_credentials, {}],
24
27
  [:static_profile_credentials, {}],
25
28
  [:static_profile_process_credentials, {}],
26
29
  [:env_credentials, {}],
27
30
  [:assume_role_web_identity_credentials, {}],
31
+ [:sso_credentials, {}],
28
32
  [:assume_role_credentials, {}],
29
33
  [:shared_credentials, {}],
30
34
  [:process_credentials, {}],
@@ -55,6 +59,14 @@ module Aws
55
59
  end
56
60
  end
57
61
 
62
+ def static_profile_sso_credentials(options)
63
+ if Aws.shared_config.config_enabled? && options[:config] && options[:config].profile
64
+ Aws.shared_config.sso_credentials_from_config(
65
+ profile: options[:config].profile
66
+ )
67
+ end
68
+ end
69
+
58
70
  def static_profile_assume_role_credentials(options)
59
71
  if Aws.shared_config.config_enabled? && options[:config] && options[:config].profile
60
72
  assume_role_with_profile(options, options[:config].profile)
@@ -113,6 +125,15 @@ module Aws
113
125
  nil
114
126
  end
115
127
 
128
+ def sso_credentials(options)
129
+ profile_name = determine_profile_name(options)
130
+ if Aws.shared_config.config_enabled?
131
+ Aws.shared_config.sso_credentials_from_config(profile: profile_name)
132
+ end
133
+ rescue Errors::NoSuchProfileError
134
+ nil
135
+ end
136
+
116
137
  def assume_role_credentials(options)
117
138
  if Aws.shared_config.config_enabled?
118
139
  assume_role_with_profile(options, determine_profile_name(options))
@@ -139,20 +160,24 @@ module Aws
139
160
  end
140
161
 
141
162
  def instance_profile_credentials(options)
142
- if ENV['AWS_CONTAINER_CREDENTIALS_RELATIVE_URI']
163
+ profile_name = determine_profile_name(options)
164
+ if ENV['AWS_CONTAINER_CREDENTIALS_RELATIVE_URI'] ||
165
+ ENV['AWS_CONTAINER_CREDENTIALS_FULL_URI']
143
166
  ECSCredentials.new(options)
144
167
  else
145
- InstanceProfileCredentials.new(options)
168
+ InstanceProfileCredentials.new(options.merge(profile: profile_name))
146
169
  end
147
170
  end
148
171
 
149
172
  def assume_role_with_profile(options, profile_name)
150
- region = (options[:config] && options[:config].region)
151
- Aws.shared_config.assume_role_credentials_from_config(
173
+ assume_opts = {
152
174
  profile: profile_name,
153
- region: region,
154
175
  chain_config: @config
155
- )
176
+ }
177
+ if options[:config] && options[:config].region
178
+ assume_opts[:region] = options[:config].region
179
+ end
180
+ Aws.shared_config.assume_role_credentials_from_config(assume_opts)
156
181
  end
157
182
  end
158
183
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Aws
2
4
  class Credentials
3
5
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Aws
2
4
 
3
5
  # A utility module that provides a class method that wraps
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'set'
2
4
 
3
5
  module Aws
@@ -0,0 +1,238 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'time'
4
+ require 'net/http'
5
+
6
+ module Aws
7
+ # A client that can query version 2 of the EC2 Instance Metadata
8
+ class EC2Metadata
9
+ # Path for PUT request for token
10
+ # @api private
11
+ METADATA_TOKEN_PATH = '/latest/api/token'.freeze
12
+
13
+ # Raised when the PUT request is not valid. This would be thrown if
14
+ # `token_ttl` is not an Integer.
15
+ # @api private
16
+ class TokenRetrievalError < RuntimeError; end
17
+
18
+ # Token has expired, and the request can be retried with a new token.
19
+ # @api private
20
+ class TokenExpiredError < RuntimeError; end
21
+
22
+ # The requested metadata path does not exist.
23
+ # @api private
24
+ class MetadataNotFoundError < RuntimeError; end
25
+
26
+ # The request is not allowed or IMDS is turned off.
27
+ # @api private
28
+ class RequestForbiddenError < RuntimeError; end
29
+
30
+ # Creates a client that can query version 2 of the EC2 Instance Metadata
31
+ # service (IMDS).
32
+ #
33
+ # @note Customers using containers may need to increase their hop limit
34
+ # to access IMDSv2.
35
+ # @see https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/configuring-instance-metadata-service.html#instance-metadata-transition-to-version-2
36
+ #
37
+ # @param [Hash] options
38
+ # @option options [Integer] :token_ttl (21600) The session token's TTL,
39
+ # defaulting to 6 hours.
40
+ # @option options [Integer] :retries (3) The number of retries for failed
41
+ # requests.
42
+ # @option options [String] :endpoint ('http://169.254.169.254') The IMDS
43
+ # endpoint. This option has precedence over the :endpoint_mode.
44
+ # @option options [String] :endpoint_mode ('IPv4') The endpoint mode for
45
+ # the instance metadata service. This is either 'IPv4'
46
+ # ('http://169.254.169.254') or 'IPv6' ('http://[fd00:ec2::254]').
47
+ # @option options [Integer] :port (80) The IMDS endpoint port.
48
+ # @option options [Integer] :http_open_timeout (1) The number of seconds to
49
+ # wait for the connection to open.
50
+ # @option options [Integer] :http_read_timeout (1) The number of seconds for
51
+ # one chunk of data to be read.
52
+ # @option options [IO] :http_debug_output An output stream for debugging. Do
53
+ # not use this in production.
54
+ # @option options [Integer,Proc] :backoff A backoff used for retryable
55
+ # requests. When given an Integer, it sleeps that amount. When given a
56
+ # Proc, it is called with the current number of failed retries.
57
+ def initialize(options = {})
58
+ @token_ttl = options[:token_ttl] || 21_600
59
+ @retries = options[:retries] || 3
60
+ @backoff = backoff(options[:backoff])
61
+
62
+ endpoint_mode = options[:endpoint_mode] || 'IPv4'
63
+ @endpoint = resolve_endpoint(options[:endpoint], endpoint_mode)
64
+ @port = options[:port] || 80
65
+
66
+ @http_open_timeout = options[:http_open_timeout] || 1
67
+ @http_read_timeout = options[:http_read_timeout] || 1
68
+ @http_debug_output = options[:http_debug_output]
69
+
70
+ @token = nil
71
+ @mutex = Mutex.new
72
+ end
73
+
74
+ # Fetches a given metadata category using a String path, and returns the
75
+ # result as a String. A path starts with the API version (usually
76
+ # "/latest/"). See the instance data categories for possible paths.
77
+ #
78
+ # @example Fetching the instance ID
79
+ #
80
+ # ec2_metadata = Aws::EC2Metadata.new
81
+ # ec2_metadata.get('/latest/meta-data/instance-id')
82
+ # => "i-023a25f10a73a0f79"
83
+ #
84
+ # @note This implementation always returns a String and will not parse any
85
+ # responses. Parsable responses may include JSON objects or directory
86
+ # listings, which are strings separated by line feeds (ASCII 10).
87
+ #
88
+ # @example Fetching and parsing JSON meta-data
89
+ #
90
+ # require 'json'
91
+ # data = ec2_metadata.get('/latest/dynamic/instance-identity/document')
92
+ # JSON.parse(data)
93
+ # => {"accountId"=>"012345678912", ... }
94
+ #
95
+ # @example Fetching and parsing directory listings
96
+ #
97
+ # listing = ec2_metadata.get('/latest/meta-data')
98
+ # listing.split(10.chr)
99
+ # => ["ami-id", "ami-launch-index", ...]
100
+ #
101
+ # @note Unlike other services, IMDS does not have a service API model. This
102
+ # means that we cannot confidently generate code with methods and
103
+ # response structures. This implementation ensures that new IMDS features
104
+ # are always supported by being deployed to the instance and does not
105
+ # require code changes.
106
+ #
107
+ # @see https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/instancedata-data-categories.html
108
+ # @see https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/instance-identity-documents.html
109
+ # @param [String] path The full path to the metadata.
110
+ def get(path)
111
+ retry_errors(max_retries: @retries) do
112
+ @mutex.synchronize do
113
+ fetch_token unless @token && !@token.expired?
114
+ end
115
+
116
+ open_connection do |conn|
117
+ http_get(conn, path, @token.value)
118
+ end
119
+ end
120
+ end
121
+
122
+ private
123
+
124
+ def resolve_endpoint(endpoint, endpoint_mode)
125
+ return endpoint if endpoint
126
+
127
+ case endpoint_mode.downcase
128
+ when 'ipv4' then 'http://169.254.169.254'
129
+ when 'ipv6' then 'http://[fd00:ec2::254]'
130
+ else
131
+ raise ArgumentError,
132
+ ':endpoint_mode is not valid, expected IPv4 or IPv6, '\
133
+ "got: #{endpoint_mode}"
134
+ end
135
+ end
136
+
137
+ def fetch_token
138
+ open_connection do |conn|
139
+ created_time = Time.now
140
+ token_value, token_ttl = http_put(conn, @token_ttl)
141
+ @token = Token.new(value: token_value, ttl: token_ttl, created_time: created_time)
142
+ end
143
+ end
144
+
145
+ def http_get(connection, path, token)
146
+ headers = {
147
+ 'User-Agent' => "aws-sdk-ruby3/#{CORE_GEM_VERSION}",
148
+ 'x-aws-ec2-metadata-token' => token
149
+ }
150
+ request = Net::HTTP::Get.new(path, headers)
151
+ response = connection.request(request)
152
+
153
+ case response.code.to_i
154
+ when 200
155
+ response.body
156
+ when 401
157
+ raise TokenExpiredError
158
+ when 404
159
+ raise MetadataNotFoundError
160
+ end
161
+ end
162
+
163
+ def http_put(connection, ttl)
164
+ headers = {
165
+ 'User-Agent' => "aws-sdk-ruby3/#{CORE_GEM_VERSION}",
166
+ 'x-aws-ec2-metadata-token-ttl-seconds' => ttl.to_s
167
+ }
168
+ request = Net::HTTP::Put.new(METADATA_TOKEN_PATH, headers)
169
+ response = connection.request(request)
170
+
171
+ case response.code.to_i
172
+ when 200
173
+ [
174
+ response.body,
175
+ response.header['x-aws-ec2-metadata-token-ttl-seconds'].to_i
176
+ ]
177
+ when 400
178
+ raise TokenRetrievalError
179
+ when 403
180
+ raise RequestForbiddenError
181
+ end
182
+ end
183
+
184
+ def open_connection
185
+ uri = URI.parse(@endpoint)
186
+ http = Net::HTTP.new(uri.hostname || @endpoint, @port || uri.port)
187
+ http.open_timeout = @http_open_timeout
188
+ http.read_timeout = @http_read_timeout
189
+ http.set_debug_output(@http_debug_output) if @http_debug_output
190
+ http.start
191
+ yield(http).tap { http.finish }
192
+ end
193
+
194
+ def retry_errors(options = {}, &_block)
195
+ max_retries = options[:max_retries]
196
+ retries = 0
197
+ begin
198
+ yield
199
+ # These errors should not be retried.
200
+ rescue TokenRetrievalError, MetadataNotFoundError, RequestForbiddenError
201
+ raise
202
+ # StandardError is not ideal but it covers Net::HTTP errors.
203
+ # https://gist.github.com/tenderlove/245188
204
+ rescue StandardError, TokenExpiredError
205
+ raise unless retries < max_retries
206
+
207
+ @backoff.call(retries)
208
+ retries += 1
209
+ retry
210
+ end
211
+ end
212
+
213
+ def backoff(backoff)
214
+ case backoff
215
+ when Proc then backoff
216
+ when Numeric then ->(_) { Kernel.sleep(backoff) }
217
+ else ->(num_failures) { Kernel.sleep(1.2**num_failures) }
218
+ end
219
+ end
220
+
221
+ # @api private
222
+ class Token
223
+ def initialize(options = {})
224
+ @ttl = options[:ttl]
225
+ @value = options[:value]
226
+ @created_time = options[:created_time] || Time.now
227
+ end
228
+
229
+ # [String] Returns the token value.
230
+ attr_reader :value
231
+
232
+ # [Boolean] Returns true if the token expired.
233
+ def expired?
234
+ Time.now - @created_time > @ttl
235
+ end
236
+ end
237
+ end
238
+ end