aws-sdk-core 3.100.0 → 3.191.0

Sign up to get free protection for your applications and to get access to all the features.
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,10 +1,15 @@
1
- require 'json'
1
+ # frozen_string_literal: true
2
+
2
3
  require 'time'
3
4
  require 'net/http'
4
5
 
5
6
  module Aws
7
+ # An auto-refreshing credential provider that loads credentials from
8
+ # EC2 instances.
9
+ #
10
+ # instance_credentials = Aws::InstanceProfileCredentials.new
11
+ # ec2 = Aws::EC2::Client.new(credentials: instance_credentials)
6
12
  class InstanceProfileCredentials
7
-
8
13
  include CredentialProvider
9
14
  include RefreshingCredentials
10
15
 
@@ -43,7 +48,15 @@ module Aws
43
48
  # @param [Hash] options
44
49
  # @option options [Integer] :retries (1) Number of times to retry
45
50
  # when retrieving credentials.
46
- # @option options [String] :ip_address ('169.254.169.254')
51
+ # @option options [String] :endpoint ('http://169.254.169.254') The IMDS
52
+ # endpoint. This option has precedence over the :endpoint_mode.
53
+ # @option options [String] :endpoint_mode ('IPv4') The endpoint mode for
54
+ # the instance metadata service. This is either 'IPv4' ('169.254.169.254')
55
+ # or 'IPv6' ('[fd00:ec2::254]').
56
+ # @option options [Boolean] :disable_imds_v1 (false) Disable the use of the
57
+ # legacy EC2 Metadata Service v1.
58
+ # @option options [String] :ip_address ('169.254.169.254') Deprecated. Use
59
+ # :endpoint instead. The IP address for the endpoint.
47
60
  # @option options [Integer] :port (80)
48
61
  # @option options [Float] :http_open_timeout (1)
49
62
  # @option options [Float] :http_read_timeout (1)
@@ -57,16 +70,26 @@ module Aws
57
70
  # @option options [Integer] :token_ttl Time-to-Live in seconds for EC2
58
71
  # Metadata Token used for fetching Metadata Profile Credentials, defaults
59
72
  # to 21600 seconds
73
+ # @option options [Callable] before_refresh Proc called before
74
+ # credentials are refreshed. `before_refresh` is called
75
+ # with an instance of this object when
76
+ # AWS credentials are required and need to be refreshed.
60
77
  def initialize(options = {})
61
78
  @retries = options[:retries] || 1
62
- @ip_address = options[:ip_address] || '169.254.169.254'
79
+ endpoint_mode = resolve_endpoint_mode(options)
80
+ @endpoint = resolve_endpoint(options, endpoint_mode)
63
81
  @port = options[:port] || 80
82
+ @disable_imds_v1 = resolve_disable_v1(options)
83
+ # Flag for if v2 flow fails, skip future attempts
84
+ @imds_v1_fallback = false
64
85
  @http_open_timeout = options[:http_open_timeout] || 1
65
86
  @http_read_timeout = options[:http_read_timeout] || 1
66
87
  @http_debug_output = options[:http_debug_output]
67
88
  @backoff = backoff(options[:backoff])
68
89
  @token_ttl = options[:token_ttl] || 21_600
69
90
  @token = nil
91
+ @no_refresh_until = nil
92
+ @async_refresh = false
70
93
  super
71
94
  end
72
95
 
@@ -77,6 +100,44 @@ module Aws
77
100
 
78
101
  private
79
102
 
103
+ def resolve_endpoint_mode(options)
104
+ value = options[:endpoint_mode]
105
+ value ||= ENV['AWS_EC2_METADATA_SERVICE_ENDPOINT_MODE']
106
+ value ||= Aws.shared_config.ec2_metadata_service_endpoint_mode(
107
+ profile: options[:profile]
108
+ )
109
+ value || 'IPv4'
110
+ end
111
+
112
+ def resolve_endpoint(options, endpoint_mode)
113
+ value = options[:endpoint] || options[:ip_address]
114
+ value ||= ENV['AWS_EC2_METADATA_SERVICE_ENDPOINT']
115
+ value ||= Aws.shared_config.ec2_metadata_service_endpoint(
116
+ profile: options[:profile]
117
+ )
118
+
119
+ return value if value
120
+
121
+ case endpoint_mode.downcase
122
+ when 'ipv4' then 'http://169.254.169.254'
123
+ when 'ipv6' then 'http://[fd00:ec2::254]'
124
+ else
125
+ raise ArgumentError,
126
+ ':endpoint_mode is not valid, expected IPv4 or IPv6, '\
127
+ "got: #{endpoint_mode}"
128
+ end
129
+ end
130
+
131
+ def resolve_disable_v1(options)
132
+ value = options[:disable_imds_v1]
133
+ value ||= ENV['AWS_EC2_METADATA_V1_DISABLED']
134
+ value ||= Aws.shared_config.ec2_metadata_v1_disabled(
135
+ profile: options[:profile]
136
+ )
137
+ value = value.to_s.downcase if value
138
+ Aws::Util.str_2_bool(value) || false
139
+ end
140
+
80
141
  def backoff(backoff)
81
142
  case backoff
82
143
  when Proc then backoff
@@ -86,20 +147,49 @@ module Aws
86
147
  end
87
148
 
88
149
  def refresh
150
+ if @no_refresh_until && @no_refresh_until > Time.now
151
+ warn_expired_credentials
152
+ return
153
+ end
154
+
89
155
  # Retry loading credentials up to 3 times is the instance metadata
90
156
  # service is responding but is returning invalid JSON documents
91
157
  # in response to the GET profile credentials call.
92
158
  begin
93
- retry_errors([JSON::ParserError, StandardError], max_retries: 3) do
94
- c = JSON.parse(get_credentials.to_s)
95
- @credentials = Credentials.new(
96
- c['AccessKeyId'],
97
- c['SecretAccessKey'],
98
- c['Token']
99
- )
100
- @expiration = c['Expiration'] ? Time.iso8601(c['Expiration']) : nil
159
+ retry_errors([Aws::Json::ParseError], max_retries: 3) do
160
+ c = Aws::Json.load(get_credentials.to_s)
161
+ if empty_credentials?(@credentials)
162
+ @credentials = Credentials.new(
163
+ c['AccessKeyId'],
164
+ c['SecretAccessKey'],
165
+ c['Token']
166
+ )
167
+ @expiration = c['Expiration'] ? Time.iso8601(c['Expiration']) : nil
168
+ if @expiration && @expiration < Time.now
169
+ @no_refresh_until = Time.now + refresh_offset
170
+ warn_expired_credentials
171
+ end
172
+ else
173
+ # credentials are already set, update them only if the new ones are not empty
174
+ if !c['AccessKeyId'] || c['AccessKeyId'].empty?
175
+ # error getting new credentials
176
+ @no_refresh_until = Time.now + refresh_offset
177
+ warn_expired_credentials
178
+ else
179
+ @credentials = Credentials.new(
180
+ c['AccessKeyId'],
181
+ c['SecretAccessKey'],
182
+ c['Token']
183
+ )
184
+ @expiration = c['Expiration'] ? Time.iso8601(c['Expiration']) : nil
185
+ if @expiration && @expiration < Time.now
186
+ @no_refresh_until = Time.now + refresh_offset
187
+ warn_expired_credentials
188
+ end
189
+ end
190
+ end
101
191
  end
102
- rescue JSON::ParserError
192
+ rescue Aws::Json::ParseError
103
193
  raise Aws::Errors::MetadataParserError
104
194
  end
105
195
  end
@@ -115,25 +205,14 @@ module Aws
115
205
  open_connection do |conn|
116
206
  # attempt to fetch token to start secure flow first
117
207
  # and rescue to failover
118
- begin
119
- retry_errors(NETWORK_ERRORS, max_retries: @retries) do
120
- unless token_set?
121
- token_value, ttl = http_put(
122
- conn, METADATA_TOKEN_PATH, @token_ttl
123
- )
124
- @token = Token.new(token_value, ttl) if token_value && ttl
125
- end
126
- end
127
- rescue *NETWORK_ERRORS
128
- # token attempt failed, reset token
129
- # fallback to non-token mode
130
- @token = nil
131
- end
132
-
208
+ fetch_token(conn) unless @imds_v1_fallback
133
209
  token = @token.value if token_set?
134
- metadata = http_get(conn, METADATA_PATH_BASE, token)
135
- profile_name = metadata.lines.first.strip
136
- http_get(conn, METADATA_PATH_BASE + profile_name, token)
210
+
211
+ # disable insecure flow if we couldn't get token
212
+ # and imds v1 is disabled
213
+ raise TokenRetrivalError if token.nil? && @disable_imds_v1
214
+
215
+ _get_credentials(conn, token)
137
216
  end
138
217
  end
139
218
  rescue
@@ -142,6 +221,36 @@ module Aws
142
221
  end
143
222
  end
144
223
 
224
+ def fetch_token(conn)
225
+ retry_errors(NETWORK_ERRORS, max_retries: @retries) do
226
+ unless token_set?
227
+ created_time = Time.now
228
+ token_value, ttl = http_put(
229
+ conn, METADATA_TOKEN_PATH, @token_ttl
230
+ )
231
+ @token = Token.new(token_value, ttl, created_time) if token_value && ttl
232
+ end
233
+ end
234
+ rescue *NETWORK_ERRORS
235
+ # token attempt failed, reset token
236
+ # fallback to non-token mode
237
+ @token = nil
238
+ @imds_v1_fallback = true
239
+ end
240
+
241
+ # token is optional - if nil, uses v1 (insecure) flow
242
+ def _get_credentials(conn, token)
243
+ metadata = http_get(conn, METADATA_PATH_BASE, token)
244
+ profile_name = metadata.lines.first.strip
245
+ http_get(conn, METADATA_PATH_BASE + profile_name, token)
246
+ rescue TokenExpiredError
247
+ # Token has expired, reset it
248
+ # The next retry should fetch it
249
+ @token = nil
250
+ @imds_v1_fallback = false
251
+ raise Non200Response
252
+ end
253
+
145
254
  def token_set?
146
255
  @token && !@token.expired?
147
256
  end
@@ -151,7 +260,8 @@ module Aws
151
260
  end
152
261
 
153
262
  def open_connection
154
- http = Net::HTTP.new(@ip_address, @port, nil)
263
+ uri = URI.parse(@endpoint)
264
+ http = Net::HTTP.new(uri.hostname || @endpoint, @port || uri.port)
155
265
  http.open_timeout = @http_open_timeout
156
266
  http.read_timeout = @http_read_timeout
157
267
  http.set_debug_output(@http_debug_output) if @http_debug_output
@@ -164,9 +274,15 @@ module Aws
164
274
  headers = { 'User-Agent' => "aws-sdk-ruby3/#{CORE_GEM_VERSION}" }
165
275
  headers['x-aws-ec2-metadata-token'] = token if token
166
276
  response = connection.request(Net::HTTP::Get.new(path, headers))
167
- raise Non200Response unless response.code.to_i == 200
168
277
 
169
- response.body
278
+ case response.code.to_i
279
+ when 200
280
+ response.body
281
+ when 401
282
+ raise TokenExpiredError
283
+ else
284
+ raise Non200Response
285
+ end
170
286
  end
171
287
 
172
288
  # PUT request fetch token with ttl
@@ -184,8 +300,6 @@ module Aws
184
300
  ]
185
301
  when 400
186
302
  raise TokenRetrivalError
187
- when 401
188
- raise TokenExpiredError
189
303
  else
190
304
  raise Non200Response
191
305
  end
@@ -205,13 +319,28 @@ module Aws
205
319
  end
206
320
  end
207
321
 
322
+ def warn_expired_credentials
323
+ warn("Attempting credential expiration extension due to a credential "\
324
+ "service availability issue. A refresh of these credentials "\
325
+ "will be attempted again in 5 minutes.")
326
+ end
327
+
328
+ def empty_credentials?(creds)
329
+ !creds || !creds.access_key_id || creds.access_key_id.empty?
330
+ end
331
+
332
+ # Compute an offset for refresh with jitter
333
+ def refresh_offset
334
+ 300 + rand(0..60)
335
+ end
336
+
208
337
  # @api private
209
338
  # Token used to fetch IMDS profile and credentials
210
339
  class Token
211
- def initialize(value, ttl)
340
+ def initialize(value, ttl, created_time = Time.now)
212
341
  @ttl = ttl
213
342
  @value = value
214
- @created_time = Time.now
343
+ @created_time = created_time
215
344
  end
216
345
 
217
346
  # [String] token value
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'base64'
2
4
 
3
5
  module Aws
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Aws
2
4
  module Json
3
5
  class ErrorHandler < Xml::ErrorHandler
@@ -24,7 +26,13 @@ module Aws
24
26
  end
25
27
 
26
28
  def error_code(json, context)
27
- code = json['__type']
29
+ code =
30
+ if aws_query_error?(context)
31
+ error = context.http_response.headers['x-amzn-query-error'].split(';')[0]
32
+ remove_prefix(error, context)
33
+ else
34
+ json['__type']
35
+ end
28
36
  code ||= json['code']
29
37
  code ||= context.http_response.headers['x-amzn-errortype']
30
38
  if code
@@ -34,6 +42,19 @@ module Aws
34
42
  end
35
43
  end
36
44
 
45
+ def aws_query_error?(context)
46
+ context.config.api.metadata['awsQueryCompatible'] &&
47
+ context.http_response.headers['x-amzn-query-error']
48
+ end
49
+
50
+ def remove_prefix(error_code, context)
51
+ if prefix = context.config.api.metadata['errorPrefix']
52
+ error_code.sub(/^#{prefix}/, '')
53
+ else
54
+ error_code
55
+ end
56
+ end
57
+
37
58
  def error_message(code, json)
38
59
  if code == 'RequestEntityTooLarge'
39
60
  'Request body must be less than 1 MB'
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Aws
2
4
  module Json
3
5
  class Handler < Seahorse::Client::Handler
@@ -57,7 +59,10 @@ module Aws
57
59
  end
58
60
  resp_struct
59
61
  else
60
- Parser.new(rules).parse(json == '' ? '{}' : json)
62
+ Parser.new(
63
+ rules,
64
+ query_compatible: query_compatible?(context)
65
+ ).parse(json == '' ? '{}' : json)
61
66
  end
62
67
  else
63
68
  EmptyStructure.new
@@ -81,6 +86,10 @@ module Aws
81
86
  context.config.simple_json
82
87
  end
83
88
 
89
+ def query_compatible?(context)
90
+ context.config.api.metadata.key?('awsQueryCompatible')
91
+ end
92
+
84
93
  end
85
94
  end
86
95
  end
@@ -1,15 +1,19 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Aws
2
4
  module Json
3
- class OjEngine
4
-
5
- def self.load(json)
6
- Oj.load(json)
7
- end
5
+ module JSONEngine
6
+ class << self
7
+ def load(json)
8
+ JSON.parse(json)
9
+ rescue JSON::ParserError => e
10
+ raise ParseError.new(e)
11
+ end
8
12
 
9
- def self.dump(value)
10
- Oj.dump(value)
13
+ def dump(value)
14
+ JSON.dump(value)
15
+ end
11
16
  end
12
-
13
17
  end
14
18
  end
15
19
  end
@@ -1,15 +1,44 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Aws
2
4
  module Json
3
- class JSONEngine
5
+ module OjEngine
6
+ # @api private
7
+ LOAD_OPTIONS = { mode: :compat, symbol_keys: false, empty_string: false }.freeze
4
8
 
5
- def self.load(json)
6
- JSON.load(json)
7
- end
9
+ # @api private
10
+ DUMP_OPTIONS = { mode: :compat }.freeze
11
+
12
+ class << self
13
+ def load(json)
14
+ Oj.load(json, LOAD_OPTIONS)
15
+ rescue *PARSE_ERRORS => e
16
+ raise ParseError.new(e)
17
+ end
18
+
19
+ def dump(value)
20
+ Oj.dump(value, DUMP_OPTIONS)
21
+ end
22
+
23
+ private
24
+
25
+ # Oj before 1.4.0 does not define Oj::ParseError and instead raises
26
+ # SyntaxError on failure
27
+ def detect_oj_parse_errors
28
+ require 'oj'
8
29
 
9
- def self.dump(value)
10
- JSON.dump(value)
30
+ if Oj.const_defined?(:ParseError)
31
+ [Oj::ParseError, EncodingError, JSON::ParserError]
32
+ else
33
+ [SyntaxError]
34
+ end
35
+ rescue LoadError
36
+ nil
37
+ end
11
38
  end
12
39
 
40
+ # @api private
41
+ PARSE_ERRORS = detect_oj_parse_errors
13
42
  end
14
43
  end
15
44
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'base64'
2
4
  require 'time'
3
5
 
@@ -8,8 +10,9 @@ module Aws
8
10
  include Seahorse::Model::Shapes
9
11
 
10
12
  # @param [Seahorse::Model::ShapeRef] rules
11
- def initialize(rules)
13
+ def initialize(rules, query_compatible: false)
12
14
  @rules = rules
15
+ @query_compatible = query_compatible
13
16
  end
14
17
 
15
18
  # @param [String<JSON>] json
@@ -26,8 +29,32 @@ module Aws
26
29
  member_name, member_ref = shape.member_by_location_name(key)
27
30
  if member_ref
28
31
  target[member_name] = parse_ref(member_ref, value)
32
+ elsif shape.union && key != '__type'
33
+ target[:unknown] = { 'name' => key, 'value' => value }
29
34
  end
30
35
  end
36
+ # In services that were previously Query/XML, members that were
37
+ # "flattened" defaulted to empty lists. In JSON, these values are nil,
38
+ # which is backwards incompatible. To preserve backwards compatibility,
39
+ # we set a default value of [] for these members.
40
+ if @query_compatible
41
+ ref.shape.members.each do |member_name, member_target|
42
+ next unless target[member_name].nil?
43
+
44
+ if flattened_list?(member_target.shape)
45
+ target[member_name] = []
46
+ elsif flattened_map?(member_target.shape)
47
+ target[member_name] = {}
48
+ end
49
+ end
50
+ end
51
+
52
+ if shape.union
53
+ # convert to subclass
54
+ member_subclass = shape.member_subclass(target.member).new
55
+ member_subclass[target.member] = target.value
56
+ target = member_subclass
57
+ end
31
58
  target
32
59
  end
33
60
 
@@ -69,6 +96,14 @@ module Aws
69
96
  value.is_a?(Numeric) ? Time.at(value) : Time.parse(value)
70
97
  end
71
98
 
99
+ def flattened_list?(shape)
100
+ shape.is_a?(ListShape) && shape.flattened
101
+ end
102
+
103
+ def flattened_map?(shape)
104
+ shape.is_a?(MapShape) && shape.flattened
105
+ end
106
+
72
107
  end
73
108
  end
74
109
  end
@@ -1,8 +1,12 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'json'
2
4
  require_relative 'json/builder'
3
5
  require_relative 'json/error_handler'
4
6
  require_relative 'json/handler'
5
7
  require_relative 'json/parser'
8
+ require_relative 'json/json_engine'
9
+ require_relative 'json/oj_engine'
6
10
 
7
11
  module Aws
8
12
  # @api private
@@ -18,9 +22,7 @@ module Aws
18
22
 
19
23
  class << self
20
24
  def load(json)
21
- ENGINE.load(json, *ENGINE_LOAD_OPTIONS)
22
- rescue *ENGINE_ERRORS => e
23
- raise ParseError, e
25
+ ENGINE.load(json)
24
26
  end
25
27
 
26
28
  def load_file(path)
@@ -28,38 +30,20 @@ module Aws
28
30
  end
29
31
 
30
32
  def dump(value)
31
- ENGINE.dump(value, *ENGINE_DUMP_OPTIONS)
33
+ ENGINE.dump(value)
32
34
  end
33
35
 
34
36
  private
35
37
 
36
- def oj_engine
38
+ def select_engine
37
39
  require 'oj'
38
- [
39
- Oj,
40
- [{ mode: :compat, symbol_keys: false }],
41
- [{ mode: :compat }],
42
- oj_parse_error
43
- ]
40
+ OjEngine
44
41
  rescue LoadError
45
- false
46
- end
47
-
48
- def json_engine
49
- [JSON, [], [], [JSON::ParserError]]
50
- end
51
-
52
- def oj_parse_error
53
- if Oj.const_defined?('ParseError')
54
- [Oj::ParseError, EncodingError, JSON::ParserError]
55
- else
56
- [SyntaxError]
57
- end
42
+ JSONEngine
58
43
  end
59
44
  end
60
45
 
61
46
  # @api private
62
- ENGINE, ENGINE_LOAD_OPTIONS, ENGINE_DUMP_OPTIONS, ENGINE_ERRORS =
63
- oj_engine || json_engine
47
+ ENGINE = select_engine
64
48
  end
65
49
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'pathname'
2
4
 
3
5
  module Aws
@@ -24,6 +26,8 @@ module Aws
24
26
  #
25
27
  # You can put any of these placeholders into you pattern.
26
28
  #
29
+ # * `:region` - The region configured for the client.
30
+ #
27
31
  # * `:client_class` - The name of the client class.
28
32
  #
29
33
  # * `:operation` - The name of the client request method.
@@ -83,6 +87,9 @@ module Aws
83
87
  # The default list of filtered parameters is documented on the
84
88
  # {ParamFilter} class.
85
89
  #
90
+ # @option options [Boolean] :filter_sensitive_params (true) Set to false
91
+ # to disable the sensitive parameter filtering when logging
92
+ # `:request_params`.
86
93
  def initialize(pattern, options = {})
87
94
  @pattern = pattern
88
95
  @param_formatter = ParamFormatter.new(options)
@@ -92,12 +99,12 @@ module Aws
92
99
  # @return [String]
93
100
  attr_reader :pattern
94
101
 
95
- # Given a resopnse, this will format a log message and return it as a
102
+ # Given a response, this will format a log message and return it as a
96
103
  # string according to {#pattern}.
97
104
  # @param [Seahorse::Client::Response] response
98
105
  # @return [String]
99
106
  def format(response)
100
- pattern.gsub(/:(\w+)/) {|sym| send("_#{sym[1..-1]}", response) }
107
+ pattern.gsub(/:(\w+)/) { |sym| send("_#{sym[1..-1]}", response) }
101
108
  end
102
109
 
103
110
  # @api private
@@ -111,6 +118,10 @@ module Aws
111
118
 
112
119
  private
113
120
 
121
+ def _region(response)
122
+ response.context.config.region
123
+ end
124
+
114
125
  def _client_class(response)
115
126
  response.context.client.class.name
116
127
  end
@@ -121,7 +132,8 @@ module Aws
121
132
 
122
133
  def _request_params(response)
123
134
  params = response.context.params
124
- @param_formatter.summarize(@param_filter.filter(params))
135
+ type = response.context.operation.input.shape.struct_class
136
+ @param_formatter.summarize(@param_filter.filter(params, type))
125
137
  end
126
138
 
127
139
  def _time(response)
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Seahorse
2
4
  module Client
3
5
  module Logging