aws-sdk-core 3.54.2 → 3.126.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (206) hide show
  1. checksums.yaml +5 -5
  2. data/CHANGELOG.md +1247 -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 +92 -0
  9. data/lib/aws-sdk-core/arn_parser.rb +40 -0
  10. data/lib/aws-sdk-core/assume_role_credentials.rb +2 -0
  11. data/lib/aws-sdk-core/assume_role_web_identity_credentials.rb +104 -0
  12. data/lib/aws-sdk-core/async_client_stubs.rb +4 -2
  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 +8 -6
  16. data/lib/aws-sdk-core/binary/event_parser.rb +5 -3
  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 +11 -1
  21. data/lib/aws-sdk-core/client_side_monitoring/request_metrics.rb +2 -0
  22. data/lib/aws-sdk-core/client_stubs.rb +15 -12
  23. data/lib/aws-sdk-core/credential_provider.rb +1 -30
  24. data/lib/aws-sdk-core/credential_provider_chain.rb +102 -40
  25. data/lib/aws-sdk-core/credentials.rb +2 -0
  26. data/lib/aws-sdk-core/deprecations.rb +17 -11
  27. data/lib/aws-sdk-core/eager_loader.rb +2 -0
  28. data/lib/aws-sdk-core/ec2_metadata.rb +237 -0
  29. data/lib/aws-sdk-core/ecs_credentials.rb +5 -4
  30. data/lib/aws-sdk-core/endpoint_cache.rb +16 -11
  31. data/lib/aws-sdk-core/errors.rb +102 -15
  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 +153 -39
  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 +11 -28
  42. data/lib/aws-sdk-core/log/formatter.rb +16 -4
  43. data/lib/aws-sdk-core/log/handler.rb +2 -0
  44. data/lib/aws-sdk-core/log/param_filter.rb +38 -13
  45. data/lib/aws-sdk-core/log/param_formatter.rb +2 -0
  46. data/lib/aws-sdk-core/pageable_response.rb +48 -24
  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 +55 -7
  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/client_metrics_plugin.rb +28 -1
  55. data/lib/aws-sdk-core/plugins/client_metrics_send_plugin.rb +2 -0
  56. data/lib/aws-sdk-core/plugins/credentials_configuration.rb +26 -7
  57. data/lib/aws-sdk-core/plugins/defaults_mode.rb +40 -0
  58. data/lib/aws-sdk-core/plugins/endpoint_discovery.rb +12 -4
  59. data/lib/aws-sdk-core/plugins/endpoint_pattern.rb +8 -6
  60. data/lib/aws-sdk-core/plugins/event_stream_configuration.rb +2 -0
  61. data/lib/aws-sdk-core/plugins/global_configuration.rb +2 -0
  62. data/lib/aws-sdk-core/plugins/helpful_socket_errors.rb +2 -0
  63. data/lib/aws-sdk-core/plugins/http_checksum.rb +57 -0
  64. data/lib/aws-sdk-core/plugins/idempotency_token.rb +2 -0
  65. data/lib/aws-sdk-core/plugins/invocation_id.rb +2 -0
  66. data/lib/aws-sdk-core/plugins/jsonvalue_converter.rb +2 -0
  67. data/lib/aws-sdk-core/plugins/logging.rb +2 -0
  68. data/lib/aws-sdk-core/plugins/param_converter.rb +2 -0
  69. data/lib/aws-sdk-core/plugins/param_validator.rb +2 -0
  70. data/lib/aws-sdk-core/plugins/protocols/api_gateway.rb +19 -0
  71. data/lib/aws-sdk-core/plugins/protocols/ec2.rb +2 -0
  72. data/lib/aws-sdk-core/plugins/protocols/json_rpc.rb +2 -0
  73. data/lib/aws-sdk-core/plugins/protocols/query.rb +2 -0
  74. data/lib/aws-sdk-core/plugins/protocols/rest_json.rb +18 -1
  75. data/lib/aws-sdk-core/plugins/protocols/rest_xml.rb +2 -0
  76. data/lib/aws-sdk-core/plugins/recursion_detection.rb +27 -0
  77. data/lib/aws-sdk-core/plugins/regional_endpoint.rb +74 -16
  78. data/lib/aws-sdk-core/plugins/response_paging.rb +2 -0
  79. data/lib/aws-sdk-core/plugins/retries/client_rate_limiter.rb +139 -0
  80. data/lib/aws-sdk-core/plugins/retries/clock_skew.rb +100 -0
  81. data/lib/aws-sdk-core/plugins/retries/error_inspector.rb +146 -0
  82. data/lib/aws-sdk-core/plugins/retries/retry_quota.rb +59 -0
  83. data/lib/aws-sdk-core/plugins/retry_errors.rb +295 -108
  84. data/lib/aws-sdk-core/plugins/signature_v2.rb +2 -0
  85. data/lib/aws-sdk-core/plugins/signature_v4.rb +28 -25
  86. data/lib/aws-sdk-core/plugins/stub_responses.rb +5 -0
  87. data/lib/aws-sdk-core/plugins/transfer_encoding.rb +4 -4
  88. data/lib/aws-sdk-core/plugins/user_agent.rb +6 -8
  89. data/lib/aws-sdk-core/process_credentials.rb +8 -7
  90. data/lib/aws-sdk-core/query/ec2_param_builder.rb +2 -0
  91. data/lib/aws-sdk-core/query/handler.rb +2 -0
  92. data/lib/aws-sdk-core/query/param.rb +2 -0
  93. data/lib/aws-sdk-core/query/param_builder.rb +2 -0
  94. data/lib/aws-sdk-core/query/param_list.rb +2 -0
  95. data/lib/aws-sdk-core/query.rb +2 -0
  96. data/lib/aws-sdk-core/refreshing_credentials.rb +2 -0
  97. data/lib/aws-sdk-core/resources/collection.rb +2 -0
  98. data/lib/aws-sdk-core/rest/handler.rb +2 -0
  99. data/lib/aws-sdk-core/rest/request/body.rb +21 -1
  100. data/lib/aws-sdk-core/rest/request/builder.rb +2 -0
  101. data/lib/aws-sdk-core/rest/request/endpoint.rb +10 -3
  102. data/lib/aws-sdk-core/rest/request/headers.rb +20 -6
  103. data/lib/aws-sdk-core/rest/request/querystring_builder.rb +4 -2
  104. data/lib/aws-sdk-core/rest/response/body.rb +2 -0
  105. data/lib/aws-sdk-core/rest/response/headers.rb +6 -3
  106. data/lib/aws-sdk-core/rest/response/parser.rb +2 -0
  107. data/lib/aws-sdk-core/rest/response/status_code.rb +2 -0
  108. data/lib/aws-sdk-core/rest.rb +2 -0
  109. data/lib/aws-sdk-core/shared_config.rb +153 -122
  110. data/lib/aws-sdk-core/shared_credentials.rb +9 -1
  111. data/lib/aws-sdk-core/sso_credentials.rb +131 -0
  112. data/lib/aws-sdk-core/structure.rb +13 -2
  113. data/lib/aws-sdk-core/stubbing/data_applicator.rb +2 -0
  114. data/lib/aws-sdk-core/stubbing/empty_stub.rb +2 -0
  115. data/lib/aws-sdk-core/stubbing/protocols/api_gateway.rb +2 -0
  116. data/lib/aws-sdk-core/stubbing/protocols/ec2.rb +2 -0
  117. data/lib/aws-sdk-core/stubbing/protocols/json.rb +3 -1
  118. data/lib/aws-sdk-core/stubbing/protocols/query.rb +4 -2
  119. data/lib/aws-sdk-core/stubbing/protocols/rest.rb +33 -7
  120. data/lib/aws-sdk-core/stubbing/protocols/rest_json.rb +3 -1
  121. data/lib/aws-sdk-core/stubbing/protocols/rest_xml.rb +2 -2
  122. data/lib/aws-sdk-core/stubbing/stub_data.rb +2 -0
  123. data/lib/aws-sdk-core/stubbing/xml_error.rb +2 -0
  124. data/lib/aws-sdk-core/type_builder.rb +2 -0
  125. data/lib/aws-sdk-core/util.rb +6 -0
  126. data/lib/aws-sdk-core/waiters/errors.rb +2 -0
  127. data/lib/aws-sdk-core/waiters/poller.rb +2 -0
  128. data/lib/aws-sdk-core/waiters/waiter.rb +2 -0
  129. data/lib/aws-sdk-core/waiters.rb +2 -0
  130. data/lib/aws-sdk-core/xml/builder.rb +5 -3
  131. data/lib/aws-sdk-core/xml/default_list.rb +2 -0
  132. data/lib/aws-sdk-core/xml/default_map.rb +2 -0
  133. data/lib/aws-sdk-core/xml/doc_builder.rb +15 -4
  134. data/lib/aws-sdk-core/xml/error_handler.rb +3 -1
  135. data/lib/aws-sdk-core/xml/parser/engines/libxml.rb +2 -0
  136. data/lib/aws-sdk-core/xml/parser/engines/nokogiri.rb +2 -0
  137. data/lib/aws-sdk-core/xml/parser/engines/oga.rb +2 -0
  138. data/lib/aws-sdk-core/xml/parser/engines/ox.rb +3 -1
  139. data/lib/aws-sdk-core/xml/parser/engines/rexml.rb +4 -1
  140. data/lib/aws-sdk-core/xml/parser/frame.rb +25 -0
  141. data/lib/aws-sdk-core/xml/parser/parsing_error.rb +2 -0
  142. data/lib/aws-sdk-core/xml/parser/stack.rb +2 -0
  143. data/lib/aws-sdk-core/xml/parser.rb +7 -0
  144. data/lib/aws-sdk-core/xml.rb +2 -0
  145. data/lib/aws-sdk-core.rb +22 -4
  146. data/lib/aws-sdk-sso/client.rb +568 -0
  147. data/lib/aws-sdk-sso/client_api.rb +190 -0
  148. data/lib/aws-sdk-sso/customizations.rb +1 -0
  149. data/lib/aws-sdk-sso/errors.rb +102 -0
  150. data/lib/aws-sdk-sso/resource.rb +26 -0
  151. data/lib/aws-sdk-sso/types.rb +352 -0
  152. data/lib/aws-sdk-sso.rb +55 -0
  153. data/lib/aws-sdk-sts/client.rb +970 -414
  154. data/lib/aws-sdk-sts/client_api.rb +41 -1
  155. data/lib/aws-sdk-sts/customizations.rb +4 -0
  156. data/lib/aws-sdk-sts/errors.rb +33 -9
  157. data/lib/aws-sdk-sts/plugins/sts_regional_endpoints.rb +38 -0
  158. data/lib/aws-sdk-sts/presigner.rb +75 -0
  159. data/lib/aws-sdk-sts/resource.rb +4 -1
  160. data/lib/aws-sdk-sts/types.rb +632 -236
  161. data/lib/aws-sdk-sts.rb +16 -6
  162. data/lib/seahorse/client/async_base.rb +2 -0
  163. data/lib/seahorse/client/async_response.rb +2 -0
  164. data/lib/seahorse/client/base.rb +6 -1
  165. data/lib/seahorse/client/block_io.rb +6 -2
  166. data/lib/seahorse/client/configuration.rb +6 -0
  167. data/lib/seahorse/client/events.rb +2 -0
  168. data/lib/seahorse/client/h2/connection.rb +31 -25
  169. data/lib/seahorse/client/h2/handler.rb +6 -5
  170. data/lib/seahorse/client/handler.rb +2 -0
  171. data/lib/seahorse/client/handler_builder.rb +2 -0
  172. data/lib/seahorse/client/handler_list.rb +2 -0
  173. data/lib/seahorse/client/handler_list_entry.rb +6 -4
  174. data/lib/seahorse/client/http/async_response.rb +2 -0
  175. data/lib/seahorse/client/http/headers.rb +2 -0
  176. data/lib/seahorse/client/http/request.rb +5 -3
  177. data/lib/seahorse/client/http/response.rb +5 -3
  178. data/lib/seahorse/client/logging/formatter.rb +6 -2
  179. data/lib/seahorse/client/logging/handler.rb +2 -0
  180. data/lib/seahorse/client/managed_file.rb +2 -0
  181. data/lib/seahorse/client/net_http/connection_pool.rb +30 -23
  182. data/lib/seahorse/client/net_http/handler.rb +24 -7
  183. data/lib/seahorse/client/net_http/patches.rb +15 -84
  184. data/lib/seahorse/client/networking_error.rb +2 -0
  185. data/lib/seahorse/client/plugin.rb +9 -6
  186. data/lib/seahorse/client/plugin_list.rb +2 -0
  187. data/lib/seahorse/client/plugins/content_length.rb +13 -7
  188. data/lib/seahorse/client/plugins/endpoint.rb +4 -2
  189. data/lib/seahorse/client/plugins/h2.rb +6 -1
  190. data/lib/seahorse/client/plugins/logging.rb +2 -0
  191. data/lib/seahorse/client/plugins/net_http.rb +39 -3
  192. data/lib/seahorse/client/plugins/operation_methods.rb +2 -0
  193. data/lib/seahorse/client/plugins/raise_response_errors.rb +2 -0
  194. data/lib/seahorse/client/plugins/request_callback.rb +110 -0
  195. data/lib/seahorse/client/plugins/response_target.rb +23 -14
  196. data/lib/seahorse/client/request.rb +2 -0
  197. data/lib/seahorse/client/request_context.rb +2 -0
  198. data/lib/seahorse/client/response.rb +5 -5
  199. data/lib/seahorse/model/api.rb +6 -0
  200. data/lib/seahorse/model/authorizer.rb +2 -0
  201. data/lib/seahorse/model/operation.rb +5 -0
  202. data/lib/seahorse/model/shapes.rb +27 -0
  203. data/lib/seahorse/util.rb +8 -1
  204. data/lib/seahorse/version.rb +2 -0
  205. data/lib/seahorse.rb +3 -0
  206. metadata +43 -11
@@ -1,16 +1,22 @@
1
- require 'json'
1
+ # frozen_string_literal: true
2
+
2
3
  require 'time'
3
4
  require 'net/http'
4
5
 
5
6
  module Aws
6
7
  class InstanceProfileCredentials
7
-
8
8
  include CredentialProvider
9
9
  include RefreshingCredentials
10
10
 
11
11
  # @api private
12
12
  class Non200Response < RuntimeError; end
13
13
 
14
+ # @api private
15
+ class TokenRetrivalError < RuntimeError; end
16
+
17
+ # @api private
18
+ class TokenExpiredError < RuntimeError; end
19
+
14
20
  # These are the errors we trap when attempting to talk to the
15
21
  # instance metadata service. Any of these imply the service
16
22
  # is not present, no responding or some other non-recoverable
@@ -23,16 +29,30 @@ module Aws
23
29
  Errno::ENETUNREACH,
24
30
  SocketError,
25
31
  Timeout::Error,
26
- Non200Response,
27
- ]
32
+ Non200Response
33
+ ].freeze
34
+
35
+ # Path base for GET request for profile and credentials
36
+ # @api private
37
+ METADATA_PATH_BASE = '/latest/meta-data/iam/security-credentials/'.freeze
38
+
39
+ # Path for PUT request for token
40
+ # @api private
41
+ METADATA_TOKEN_PATH = '/latest/api/token'.freeze
28
42
 
29
43
  # @param [Hash] options
30
- # @option options [Integer] :retries (5) Number of times to retry
44
+ # @option options [Integer] :retries (1) Number of times to retry
31
45
  # when retrieving credentials.
32
- # @option options [String] :ip_address ('169.254.169.254')
46
+ # @option options [String] :endpoint ('http://169.254.169.254') The IMDS
47
+ # endpoint. This option has precedence over the :endpoint_mode.
48
+ # @option options [String] :endpoint_mode ('IPv4') The endpoint mode for
49
+ # the instance metadata service. This is either 'IPv4' ('169.254.169.254')
50
+ # or 'IPv6' ('[fd00:ec2::254]').
51
+ # @option options [String] :ip_address ('169.254.169.254') Deprecated. Use
52
+ # :endpoint instead. The IP address for the endpoint.
33
53
  # @option options [Integer] :port (80)
34
- # @option options [Float] :http_open_timeout (5)
35
- # @option options [Float] :http_read_timeout (5)
54
+ # @option options [Float] :http_open_timeout (1)
55
+ # @option options [Float] :http_read_timeout (1)
36
56
  # @option options [Numeric, Proc] :delay By default, failures are retried
37
57
  # with exponential back-off, i.e. `sleep(1.2 ** num_failures)`. You can
38
58
  # pass a number of seconds to sleep between failed attempts, or
@@ -40,28 +60,63 @@ module Aws
40
60
  # @option options [IO] :http_debug_output (nil) HTTP wire
41
61
  # traces are sent to this object. You can specify something
42
62
  # like $stdout.
43
- def initialize options = {}
44
- @retries = options[:retries] || 5
45
- @ip_address = options[:ip_address] || '169.254.169.254'
63
+ # @option options [Integer] :token_ttl Time-to-Live in seconds for EC2
64
+ # Metadata Token used for fetching Metadata Profile Credentials, defaults
65
+ # to 21600 seconds
66
+ def initialize(options = {})
67
+ @retries = options[:retries] || 1
68
+ endpoint_mode = resolve_endpoint_mode(options)
69
+ @endpoint = resolve_endpoint(options, endpoint_mode)
46
70
  @port = options[:port] || 80
47
- @http_open_timeout = options[:http_open_timeout] || 5
48
- @http_read_timeout = options[:http_read_timeout] || 5
71
+ @http_open_timeout = options[:http_open_timeout] || 1
72
+ @http_read_timeout = options[:http_read_timeout] || 1
49
73
  @http_debug_output = options[:http_debug_output]
50
74
  @backoff = backoff(options[:backoff])
75
+ @token_ttl = options[:token_ttl] || 21_600
76
+ @token = nil
51
77
  super
52
78
  end
53
79
 
54
- # @return [Integer] The number of times to retry failed attempts to
55
- # fetch credentials from the instance metadata service. Defaults to 0.
80
+ # @return [Integer] Number of times to retry when retrieving credentials
81
+ # from the instance metadata service. Defaults to 0 when resolving from
82
+ # the default credential chain ({Aws::CredentialProviderChain}).
56
83
  attr_reader :retries
57
84
 
58
85
  private
59
86
 
87
+ def resolve_endpoint_mode(options)
88
+ value = options[:endpoint_mode]
89
+ value ||= ENV['AWS_EC2_METADATA_SERVICE_ENDPOINT_MODE']
90
+ value ||= Aws.shared_config.ec2_metadata_service_endpoint_mode(
91
+ profile: options[:profile]
92
+ )
93
+ value || 'IPv4'
94
+ end
95
+
96
+ def resolve_endpoint(options, endpoint_mode)
97
+ value = options[:endpoint] || options[:ip_address]
98
+ value ||= ENV['AWS_EC2_METADATA_SERVICE_ENDPOINT']
99
+ value ||= Aws.shared_config.ec2_metadata_service_endpoint(
100
+ profile: options[:profile]
101
+ )
102
+
103
+ return value if value
104
+
105
+ case endpoint_mode.downcase
106
+ when 'ipv4' then 'http://169.254.169.254'
107
+ when 'ipv6' then 'http://[fd00:ec2::254]'
108
+ else
109
+ raise ArgumentError,
110
+ ':endpoint_mode is not valid, expected IPv4 or IPv6, '\
111
+ "got: #{endpoint_mode}"
112
+ end
113
+ end
114
+
60
115
  def backoff(backoff)
61
116
  case backoff
62
117
  when Proc then backoff
63
- when Numeric then lambda { |_| sleep(backoff) }
64
- else lambda { |num_failures| Kernel.sleep(1.2 ** num_failures) }
118
+ when Numeric then ->(_) { sleep(backoff) }
119
+ else ->(num_failures) { Kernel.sleep(1.2**num_failures) }
65
120
  end
66
121
  end
67
122
 
@@ -70,8 +125,8 @@ module Aws
70
125
  # service is responding but is returning invalid JSON documents
71
126
  # in response to the GET profile credentials call.
72
127
  begin
73
- retry_errors([JSON::ParserError, StandardError], max_retries: 3) do
74
- c = JSON.parse(get_credentials.to_s)
128
+ retry_errors([Aws::Json::ParseError, StandardError], max_retries: 3) do
129
+ c = Aws::Json.load(get_credentials.to_s)
75
130
  @credentials = Credentials.new(
76
131
  c['AccessKeyId'],
77
132
  c['SecretAccessKey'],
@@ -79,8 +134,8 @@ module Aws
79
134
  )
80
135
  @expiration = c['Expiration'] ? Time.iso8601(c['Expiration']) : nil
81
136
  end
82
- rescue JSON::ParserError
83
- raise Aws::Errors::MetadataParserError.new
137
+ rescue Aws::Json::ParseError
138
+ raise Aws::Errors::MetadataParserError
84
139
  end
85
140
  end
86
141
 
@@ -93,9 +148,27 @@ module Aws
93
148
  begin
94
149
  retry_errors(NETWORK_ERRORS, max_retries: @retries) do
95
150
  open_connection do |conn|
96
- path = '/latest/meta-data/iam/security-credentials/'
97
- profile_name = http_get(conn, path).lines.first.strip
98
- http_get(conn, path + profile_name)
151
+ # attempt to fetch token to start secure flow first
152
+ # and rescue to failover
153
+ begin
154
+ retry_errors(NETWORK_ERRORS, max_retries: @retries) do
155
+ unless token_set?
156
+ token_value, ttl = http_put(
157
+ conn, METADATA_TOKEN_PATH, @token_ttl
158
+ )
159
+ @token = Token.new(token_value, ttl) if token_value && ttl
160
+ end
161
+ end
162
+ rescue *NETWORK_ERRORS
163
+ # token attempt failed, reset token
164
+ # fallback to non-token mode
165
+ @token = nil
166
+ end
167
+
168
+ token = @token.value if token_set?
169
+ metadata = http_get(conn, METADATA_PATH_BASE, token)
170
+ profile_name = metadata.lines.first.strip
171
+ http_get(conn, METADATA_PATH_BASE + profile_name, token)
99
172
  end
100
173
  end
101
174
  rescue
@@ -104,13 +177,17 @@ module Aws
104
177
  end
105
178
  end
106
179
 
180
+ def token_set?
181
+ @token && !@token.expired?
182
+ end
183
+
107
184
  def _metadata_disabled?
108
- flag = ENV["AWS_EC2_METADATA_DISABLED"]
109
- !flag.nil? && flag.downcase == "true"
185
+ ENV.fetch('AWS_EC2_METADATA_DISABLED', 'false').downcase == 'true'
110
186
  end
111
187
 
112
188
  def open_connection
113
- http = Net::HTTP.new(@ip_address, @port, nil)
189
+ uri = URI.parse(@endpoint)
190
+ http = Net::HTTP.new(uri.hostname || @endpoint, @port || uri.port)
114
191
  http.open_timeout = @http_open_timeout
115
192
  http.read_timeout = @http_read_timeout
116
193
  http.set_debug_output(@http_debug_output) if @http_debug_output
@@ -118,30 +195,67 @@ module Aws
118
195
  yield(http).tap { http.finish }
119
196
  end
120
197
 
121
- def http_get(connection, path)
122
- response = connection.request(Net::HTTP::Get.new(path, {"User-Agent" => "aws-sdk-ruby3/#{CORE_GEM_VERSION}"}))
123
- if response.code.to_i == 200
124
- response.body
198
+ # GET request fetch profile and credentials
199
+ def http_get(connection, path, token = nil)
200
+ headers = { 'User-Agent' => "aws-sdk-ruby3/#{CORE_GEM_VERSION}" }
201
+ headers['x-aws-ec2-metadata-token'] = token if token
202
+ response = connection.request(Net::HTTP::Get.new(path, headers))
203
+ raise Non200Response unless response.code.to_i == 200
204
+
205
+ response.body
206
+ end
207
+
208
+ # PUT request fetch token with ttl
209
+ def http_put(connection, path, ttl)
210
+ headers = {
211
+ 'User-Agent' => "aws-sdk-ruby3/#{CORE_GEM_VERSION}",
212
+ 'x-aws-ec2-metadata-token-ttl-seconds' => ttl.to_s
213
+ }
214
+ response = connection.request(Net::HTTP::Put.new(path, headers))
215
+ case response.code.to_i
216
+ when 200
217
+ [
218
+ response.body,
219
+ response.header['x-aws-ec2-metadata-token-ttl-seconds'].to_i
220
+ ]
221
+ when 400
222
+ raise TokenRetrivalError
223
+ when 401
224
+ raise TokenExpiredError
125
225
  else
126
226
  raise Non200Response
127
227
  end
128
228
  end
129
229
 
130
- def retry_errors(error_classes, options = {}, &block)
230
+ def retry_errors(error_classes, options = {}, &_block)
131
231
  max_retries = options[:max_retries]
132
232
  retries = 0
133
233
  begin
134
234
  yield
135
235
  rescue *error_classes
136
- if retries < max_retries
137
- @backoff.call(retries)
138
- retries += 1
139
- retry
140
- else
141
- raise
142
- end
236
+ raise unless retries < max_retries
237
+
238
+ @backoff.call(retries)
239
+ retries += 1
240
+ retry
143
241
  end
144
242
  end
145
243
 
244
+ # @api private
245
+ # Token used to fetch IMDS profile and credentials
246
+ class Token
247
+ def initialize(value, ttl)
248
+ @ttl = ttl
249
+ @value = value
250
+ @created_time = Time.now
251
+ end
252
+
253
+ # [String] token value
254
+ attr_reader :value
255
+
256
+ def expired?
257
+ Time.now - @created_time > @ttl
258
+ end
259
+ end
146
260
  end
147
261
  end
@@ -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
@@ -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
@@ -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
 
@@ -26,8 +28,16 @@ module Aws
26
28
  member_name, member_ref = shape.member_by_location_name(key)
27
29
  if member_ref
28
30
  target[member_name] = parse_ref(member_ref, value)
31
+ elsif shape.union
32
+ target[:unknown] = { 'name' => key, 'value' => value }
29
33
  end
30
34
  end
35
+ if shape.union
36
+ # convert to subclass
37
+ member_subclass = shape.member_subclass(target.member).new
38
+ member_subclass[target.member] = target.value
39
+ target = member_subclass
40
+ end
31
41
  target
32
42
  end
33
43
 
@@ -1,66 +1,49 @@
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
9
13
  module Json
10
-
11
14
  class ParseError < StandardError
12
-
13
15
  def initialize(error)
14
16
  @error = error
15
17
  super(error.message)
16
18
  end
17
19
 
18
20
  attr_reader :error
19
-
20
21
  end
21
22
 
22
23
  class << self
23
-
24
24
  def load(json)
25
- ENGINE.load(json, *ENGINE_LOAD_OPTIONS)
26
- rescue ENGINE_ERROR => e
27
- raise ParseError.new(e)
25
+ ENGINE.load(json)
28
26
  end
29
27
 
30
28
  def load_file(path)
31
- self.load(File.open(path, 'r', encoding: 'UTF-8') { |f| f.read })
29
+ load(File.open(path, 'r', encoding: 'UTF-8', &:read))
32
30
  end
33
31
 
34
32
  def dump(value)
35
- ENGINE.dump(value, *ENGINE_DUMP_OPTIONS)
33
+ ENGINE.dump(value)
36
34
  end
37
35
 
38
36
  private
39
37
 
40
- def oj_engine
38
+ def select_engine
41
39
  require 'oj'
42
- [Oj, [{mode: :compat, symbol_keys: false}], [{ mode: :compat }], oj_parse_error]
40
+ OjEngine
43
41
  rescue LoadError
44
- false
42
+ JSONEngine
45
43
  end
46
-
47
- def json_engine
48
- [JSON, [], [], JSON::ParserError]
49
- end
50
-
51
- def oj_parse_error
52
- if Oj.const_defined?('ParseError')
53
- Oj::ParseError
54
- else
55
- SyntaxError
56
- end
57
- end
58
-
59
44
  end
60
45
 
61
46
  # @api private
62
- ENGINE, ENGINE_LOAD_OPTIONS, ENGINE_DUMP_OPTIONS, ENGINE_ERROR =
63
- oj_engine || json_engine
64
-
47
+ ENGINE = select_engine
65
48
  end
66
49
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'pathname'
2
4
 
3
5
  module Aws
@@ -83,6 +85,9 @@ module Aws
83
85
  # The default list of filtered parameters is documented on the
84
86
  # {ParamFilter} class.
85
87
  #
88
+ # @option options [Boolean] :filter_sensitive_params (true) Set to false
89
+ # to disable the sensitive parameter filtering when logging
90
+ # `:request_params`.
86
91
  def initialize(pattern, options = {})
87
92
  @pattern = pattern
88
93
  @param_formatter = ParamFormatter.new(options)
@@ -92,12 +97,12 @@ module Aws
92
97
  # @return [String]
93
98
  attr_reader :pattern
94
99
 
95
- # Given a resopnse, this will format a log message and return it as a
100
+ # Given a response, this will format a log message and return it as a
96
101
  # string according to {#pattern}.
97
102
  # @param [Seahorse::Client::Response] response
98
103
  # @return [String]
99
104
  def format(response)
100
- pattern.gsub(/:(\w+)/) {|sym| send("_#{sym[1..-1]}", response) }
105
+ pattern.gsub(/:(\w+)/) { |sym| send("_#{sym[1..-1]}", response) }
101
106
  end
102
107
 
103
108
  # @api private
@@ -121,7 +126,8 @@ module Aws
121
126
 
122
127
  def _request_params(response)
123
128
  params = response.context.params
124
- @param_formatter.summarize(@param_filter.filter(params))
129
+ type = response.context.operation.input.shape.struct_class
130
+ @param_formatter.summarize(@param_filter.filter(params, type))
125
131
  end
126
132
 
127
133
  def _time(response)
@@ -171,7 +177,13 @@ module Aws
171
177
  end
172
178
 
173
179
  def _http_response_body(response)
174
- @param_formatter.summarize(response.context.http_response.body_contents)
180
+ if response.context.http_response.body.respond_to?(:rewind)
181
+ @param_formatter.summarize(
182
+ response.context.http_response.body_contents
183
+ )
184
+ else
185
+ ''
186
+ end
175
187
  end
176
188
 
177
189
  def _error_class(response)
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Seahorse
2
4
  module Client
3
5
  module Logging
@@ -1,43 +1,68 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'pathname'
2
4
  require 'set'
3
5
 
4
6
  module Aws
5
7
  module Log
6
8
  class ParamFilter
7
-
9
+ # DEPRECATED - This must exist for backwards compatibility. Sensitive
10
+ # members are now computed for each request/response type. This can be
11
+ # removed in a new major version. This list is no longer updated.
12
+ #
8
13
  # A managed list of sensitive parameters that should be filtered from
9
14
  # logs. This is updated automatically as part of each release. See the
10
- # `tasks/sensitive.rake` for more information.
15
+ # `tasks/update-sensitive-params.rake` for more information.
11
16
  #
12
17
  # @api private
13
18
  # begin
14
- SENSITIVE = [:access_token, :account_name, :account_password, :address, :admin_contact, :admin_password, :artifact_credentials, :auth_code, :authentication_token, :authorization_result, :backup_plan_tags, :backup_vault_tags, :base_32_string_seed, :body, :bot_configuration, :bot_email, :cause, :client_id, :client_secret, :configuration, :copy_source_sse_customer_key, :credentials, :current_password, :custom_attributes, :db_password, :default_phone_number, :definition, :description, :display_name, :e164_phone_number, :email, :email_address, :email_message, :embed_url, :error, :feedback_token, :file, :first_name, :id, :id_token, :input, :input_text, :key_id, :key_store_password, :kms_key_id, :kms_master_key_id, :lambda_function_arn, :last_name, :local_console_password, :master_account_email, :master_user_password, :message, :name, :new_password, :next_password, :notes, :old_password, :outbound_events_https_endpoint, :output, :owner_information, :parameters, :passphrase, :password, :payload, :phone_number, :plaintext, :previous_password, :primary_email, :primary_provisioned_number, :private_key, :proposed_password, :public_key, :qr_code_png, :query, :recovery_point_tags, :refresh_token, :registrant_contact, :request_attributes, :search_query, :secret_access_key, :secret_binary, :secret_code, :secret_hash, :secret_string, :secret_to_authenticate_initiator, :secret_to_authenticate_target, :security_token, :service_password, :session_attributes, :share_notes, :shared_secret, :slots, :sse_customer_key, :ssekms_key_id, :status_message, :tag_key_list, :tags, :task_parameters, :tech_contact, :temporary_password, :text, :token, :trust_password, :upload_credentials, :upload_url, :user_email, :user_name, :username, :value, :values, :variables, :zip_file]
19
+ SENSITIVE = [:access_token, :account_name, :account_password, :address, :admin_contact, :admin_password, :alexa_for_business_room_arn, :artifact_credentials, :auth_code, :auth_parameters, :authentication_token, :authorization_result, :backup_plan_tags, :backup_vault_tags, :base_32_string_seed, :basic_auth_credentials, :block, :block_address, :block_data, :blocks, :body, :bot_configuration, :bot_email, :calling_name, :cause, :client_id, :client_request_token, :client_secret, :comment, :configuration, :content, :copy_source_sse_customer_key, :credentials, :current_password, :custom_attributes, :custom_private_key, :db_password, :default_phone_number, :definition, :description, :destination_access_token, :digest_tip_address, :display_name, :domain_signing_private_key, :e164_phone_number, :email, :email_address, :email_message, :embed_url, :emergency_phone_number, :error, :external_meeting_id, :external_model_endpoint_data_blobs, :external_user_id, :fall_back_phone_number, :feedback_token, :file, :filter_expression, :first_name, :full_name, :host_key, :id, :id_token, :input, :input_text, :ion_text, :join_token, :key, :key_id, :key_material, :key_store_password, :kms_key_id, :kms_master_key_id, :lambda_function_arn, :last_name, :local_console_password, :master_account_email, :master_user_name, :master_user_password, :meeting_host_id, :message, :metadata, :name, :new_password, :next_password, :notes, :number, :oauth_token, :old_password, :outbound_events_https_endpoint, :output, :owner_information, :parameters, :passphrase, :password, :payload, :phone_number, :plaintext, :previous_password, :primary_email, :primary_provisioned_number, :private_key, :private_key_plaintext, :proof, :proposed_password, :proxy_phone_number, :public_key, :qr_code_png, :query, :random_password, :recovery_point_tags, :refresh_token, :registrant_contact, :request_attributes, :resource_arn, :restore_metadata, :revision, :saml_assertion, :search_query, :secret_access_key, :secret_binary, :secret_code, :secret_hash, :secret_string, :secret_to_authenticate_initiator, :secret_to_authenticate_target, :security_token, :service_password, :session_attributes, :session_token, :share_notes, :shared_secret, :slots, :sns_topic_arn, :source_access_token, :sqs_queue_arn, :sse_customer_key, :ssekms_encryption_context, :ssekms_key_id, :status_message, :tag_key_list, :tags, :target_address, :task_parameters, :tech_contact, :temporary_password, :test_phone_number, :text, :token, :trust_password, :type, :upload_credentials, :upload_url, :uri, :user_data, :user_email, :user_name, :user_password, :username, :value, :values, :variables, :vpn_psk, :web_identity_token, :zip_file]
15
20
  # end
16
21
 
17
22
  def initialize(options = {})
18
- @filters = Set.new(SENSITIVE + Array(options[:filter]))
23
+ @enabled = options[:filter_sensitive_params] != false
24
+ @additional_filters = options[:filter] || []
19
25
  end
20
26
 
21
- def filter(value)
22
- case value
23
- when Struct, Hash then filter_hash(value)
24
- when Array then filter_array(value)
25
- else value
27
+ def filter(values, type)
28
+ case values
29
+ when Struct then filter_struct(values, type)
30
+ when Hash then filter_hash(values, type)
31
+ when Array then filter_array(values, type)
32
+ else values
26
33
  end
27
34
  end
28
35
 
29
36
  private
30
37
 
31
- def filter_hash(values)
38
+ def filter_struct(values, type)
39
+ if values.class.include? Aws::Structure::Union
40
+ values = { values.member => values.value }
41
+ end
42
+ filter_hash(values, type)
43
+ end
44
+
45
+ def filter_hash(values, type)
46
+ if type.const_defined?('SENSITIVE')
47
+ filters = type::SENSITIVE + @additional_filters
48
+ else
49
+ # Support backwards compatibility (new core + old service)
50
+ filters = SENSITIVE + @additional_filters
51
+ end
52
+
32
53
  filtered = {}
33
54
  values.each_pair do |key, value|
34
- filtered[key] = @filters.include?(key) ? '[FILTERED]' : filter(value)
55
+ filtered[key] = if @enabled && filters.include?(key)
56
+ '[FILTERED]'
57
+ else
58
+ filter(value, type)
59
+ end
35
60
  end
36
61
  filtered
37
62
  end
38
63
 
39
- def filter_array(values)
40
- values.map { |value| filter(value) }
64
+ def filter_array(values, type)
65
+ values.map { |value| filter(value, type) }
41
66
  end
42
67
 
43
68
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'pathname'
2
4
 
3
5
  module Aws