aws-sdk-core 3.191.1 → 3.228.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 (181) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +530 -1
  3. data/VERSION +1 -1
  4. data/lib/aws-defaults/default_configuration.rb +1 -2
  5. data/lib/aws-defaults.rb +4 -1
  6. data/lib/aws-sdk-core/arn.rb +1 -3
  7. data/lib/aws-sdk-core/assume_role_credentials.rb +13 -5
  8. data/lib/aws-sdk-core/assume_role_web_identity_credentials.rb +14 -7
  9. data/lib/aws-sdk-core/binary/decode_handler.rb +3 -9
  10. data/lib/aws-sdk-core/binary/encode_handler.rb +1 -1
  11. data/lib/aws-sdk-core/binary/event_builder.rb +34 -37
  12. data/lib/aws-sdk-core/binary/event_stream_decoder.rb +1 -0
  13. data/lib/aws-sdk-core/binary/event_stream_encoder.rb +4 -3
  14. data/lib/aws-sdk-core/cbor/decoder.rb +308 -0
  15. data/lib/aws-sdk-core/cbor/encoder.rb +243 -0
  16. data/lib/aws-sdk-core/cbor.rb +53 -0
  17. data/lib/aws-sdk-core/client_side_monitoring.rb +9 -0
  18. data/lib/aws-sdk-core/client_stubs.rb +30 -55
  19. data/lib/aws-sdk-core/credential_provider.rb +4 -0
  20. data/lib/aws-sdk-core/credential_provider_chain.rb +38 -11
  21. data/lib/aws-sdk-core/credentials.rb +19 -6
  22. data/lib/aws-sdk-core/ec2_metadata.rb +1 -1
  23. data/lib/aws-sdk-core/ecs_credentials.rb +1 -0
  24. data/lib/aws-sdk-core/endpoints/endpoint.rb +3 -1
  25. data/lib/aws-sdk-core/endpoints/matchers.rb +8 -10
  26. data/lib/aws-sdk-core/endpoints.rb +101 -21
  27. data/lib/aws-sdk-core/error_handler.rb +46 -0
  28. data/lib/aws-sdk-core/errors.rb +11 -2
  29. data/lib/aws-sdk-core/event_emitter.rb +1 -17
  30. data/lib/aws-sdk-core/instance_profile_credentials.rb +148 -158
  31. data/lib/aws-sdk-core/json/builder.rb +8 -1
  32. data/lib/aws-sdk-core/json/error_handler.rb +29 -13
  33. data/lib/aws-sdk-core/json/handler.rb +6 -6
  34. data/lib/aws-sdk-core/json/json_engine.rb +3 -1
  35. data/lib/aws-sdk-core/json/oj_engine.rb +7 -1
  36. data/lib/aws-sdk-core/json/parser.rb +6 -1
  37. data/lib/aws-sdk-core/json.rb +43 -14
  38. data/lib/aws-sdk-core/log/param_filter.rb +2 -2
  39. data/lib/aws-sdk-core/log/param_formatter.rb +7 -3
  40. data/lib/aws-sdk-core/log.rb +10 -0
  41. data/lib/aws-sdk-core/lru_cache.rb +75 -0
  42. data/lib/aws-sdk-core/pageable_response.rb +1 -1
  43. data/lib/aws-sdk-core/param_validator.rb +7 -2
  44. data/lib/aws-sdk-core/plugins/bearer_authorization.rb +2 -0
  45. data/lib/aws-sdk-core/plugins/checksum_algorithm.rb +332 -169
  46. data/lib/aws-sdk-core/plugins/client_metrics_plugin.rb +0 -1
  47. data/lib/aws-sdk-core/plugins/client_metrics_send_plugin.rb +14 -2
  48. data/lib/aws-sdk-core/plugins/credentials_configuration.rb +87 -68
  49. data/lib/aws-sdk-core/plugins/endpoint_pattern.rb +40 -32
  50. data/lib/aws-sdk-core/plugins/global_configuration.rb +8 -9
  51. data/lib/aws-sdk-core/plugins/http_checksum.rb +2 -8
  52. data/lib/aws-sdk-core/plugins/invocation_id.rb +1 -11
  53. data/lib/aws-sdk-core/plugins/protocols/api_gateway.rb +3 -1
  54. data/lib/aws-sdk-core/plugins/protocols/ec2.rb +2 -24
  55. data/lib/aws-sdk-core/plugins/protocols/json_rpc.rb +6 -8
  56. data/lib/aws-sdk-core/plugins/protocols/query.rb +4 -2
  57. data/lib/aws-sdk-core/plugins/protocols/rest_json.rb +3 -15
  58. data/lib/aws-sdk-core/plugins/protocols/rest_xml.rb +3 -0
  59. data/lib/aws-sdk-core/plugins/protocols/rpc_v2.rb +17 -0
  60. data/lib/aws-sdk-core/plugins/regional_endpoint.rb +74 -25
  61. data/lib/aws-sdk-core/plugins/request_compression.rb +11 -2
  62. data/lib/aws-sdk-core/plugins/retry_errors.rb +10 -3
  63. data/lib/aws-sdk-core/plugins/sign.rb +42 -26
  64. data/lib/aws-sdk-core/plugins/signature_v2.rb +2 -1
  65. data/lib/aws-sdk-core/plugins/signature_v4.rb +2 -1
  66. data/lib/aws-sdk-core/plugins/stub_responses.rb +58 -9
  67. data/lib/aws-sdk-core/plugins/telemetry.rb +75 -0
  68. data/lib/aws-sdk-core/plugins/transfer_encoding.rb +16 -9
  69. data/lib/aws-sdk-core/plugins/user_agent.rb +101 -26
  70. data/lib/aws-sdk-core/plugins.rb +39 -0
  71. data/lib/aws-sdk-core/process_credentials.rb +48 -29
  72. data/lib/aws-sdk-core/query/ec2_handler.rb +27 -0
  73. data/lib/aws-sdk-core/query/ec2_param_builder.rb +5 -7
  74. data/lib/aws-sdk-core/query/handler.rb +4 -4
  75. data/lib/aws-sdk-core/query/param_builder.rb +2 -2
  76. data/lib/aws-sdk-core/query.rb +2 -1
  77. data/lib/aws-sdk-core/resources.rb +8 -0
  78. data/lib/aws-sdk-core/rest/content_type_handler.rb +60 -0
  79. data/lib/aws-sdk-core/rest/handler.rb +3 -4
  80. data/lib/aws-sdk-core/rest/request/body.rb +32 -5
  81. data/lib/aws-sdk-core/rest/request/endpoint.rb +24 -4
  82. data/lib/aws-sdk-core/rest/request/headers.rb +15 -7
  83. data/lib/aws-sdk-core/rest/request/querystring_builder.rb +23 -11
  84. data/lib/aws-sdk-core/rest/response/body.rb +15 -1
  85. data/lib/aws-sdk-core/rest/response/header_list_parser.rb +79 -0
  86. data/lib/aws-sdk-core/rest/response/headers.rb +8 -3
  87. data/lib/aws-sdk-core/rest.rb +1 -0
  88. data/lib/aws-sdk-core/rpc_v2/builder.rb +62 -0
  89. data/lib/aws-sdk-core/rpc_v2/cbor_engine.rb +18 -0
  90. data/lib/aws-sdk-core/rpc_v2/content_type_handler.rb +47 -0
  91. data/lib/aws-sdk-core/rpc_v2/error_handler.rb +95 -0
  92. data/lib/aws-sdk-core/rpc_v2/handler.rb +79 -0
  93. data/lib/aws-sdk-core/rpc_v2/parser.rb +98 -0
  94. data/lib/aws-sdk-core/rpc_v2.rb +69 -0
  95. data/lib/aws-sdk-core/shared_config.rb +79 -22
  96. data/lib/aws-sdk-core/shared_credentials.rb +1 -7
  97. data/lib/aws-sdk-core/sso_credentials.rb +4 -1
  98. data/lib/aws-sdk-core/static_token_provider.rb +1 -2
  99. data/lib/aws-sdk-core/stubbing/protocols/ec2.rb +12 -11
  100. data/lib/aws-sdk-core/stubbing/protocols/json.rb +11 -10
  101. data/lib/aws-sdk-core/stubbing/protocols/query.rb +7 -6
  102. data/lib/aws-sdk-core/stubbing/protocols/rest.rb +2 -1
  103. data/lib/aws-sdk-core/stubbing/protocols/rest_json.rb +9 -8
  104. data/lib/aws-sdk-core/stubbing/protocols/rest_xml.rb +6 -5
  105. data/lib/aws-sdk-core/stubbing/protocols/rpc_v2.rb +39 -0
  106. data/lib/aws-sdk-core/stubbing.rb +22 -0
  107. data/lib/aws-sdk-core/telemetry/base.rb +177 -0
  108. data/lib/aws-sdk-core/telemetry/no_op.rb +70 -0
  109. data/lib/aws-sdk-core/telemetry/otel.rb +235 -0
  110. data/lib/aws-sdk-core/telemetry/span_kind.rb +22 -0
  111. data/lib/aws-sdk-core/telemetry/span_status.rb +59 -0
  112. data/lib/aws-sdk-core/telemetry.rb +78 -0
  113. data/lib/aws-sdk-core/token.rb +3 -3
  114. data/lib/aws-sdk-core/token_provider.rb +4 -0
  115. data/lib/aws-sdk-core/token_provider_chain.rb +2 -6
  116. data/lib/aws-sdk-core/util.rb +41 -1
  117. data/lib/aws-sdk-core/waiters/poller.rb +10 -5
  118. data/lib/aws-sdk-core/xml/builder.rb +17 -9
  119. data/lib/aws-sdk-core/xml/error_handler.rb +35 -43
  120. data/lib/aws-sdk-core/xml/parser/frame.rb +4 -20
  121. data/lib/aws-sdk-core/xml/parser/stack.rb +2 -0
  122. data/lib/aws-sdk-core/xml/parser.rb +2 -6
  123. data/lib/aws-sdk-core.rb +82 -107
  124. data/lib/aws-sdk-sso/client.rb +185 -89
  125. data/lib/aws-sdk-sso/client_api.rb +7 -0
  126. data/lib/aws-sdk-sso/endpoint_parameters.rb +9 -6
  127. data/lib/aws-sdk-sso/endpoint_provider.rb +14 -18
  128. data/lib/aws-sdk-sso/endpoints.rb +2 -54
  129. data/lib/aws-sdk-sso/plugins/endpoints.rb +19 -20
  130. data/lib/aws-sdk-sso/types.rb +1 -0
  131. data/lib/aws-sdk-sso.rb +15 -11
  132. data/lib/aws-sdk-ssooidc/client.rb +270 -109
  133. data/lib/aws-sdk-ssooidc/client_api.rb +33 -0
  134. data/lib/aws-sdk-ssooidc/endpoint_parameters.rb +9 -6
  135. data/lib/aws-sdk-ssooidc/endpoint_provider.rb +14 -18
  136. data/lib/aws-sdk-ssooidc/endpoints.rb +2 -54
  137. data/lib/aws-sdk-ssooidc/errors.rb +21 -0
  138. data/lib/aws-sdk-ssooidc/plugins/endpoints.rb +19 -20
  139. data/lib/aws-sdk-ssooidc/types.rb +125 -24
  140. data/lib/aws-sdk-ssooidc.rb +15 -11
  141. data/lib/aws-sdk-sts/client.rb +393 -141
  142. data/lib/aws-sdk-sts/client_api.rb +36 -8
  143. data/lib/aws-sdk-sts/customizations.rb +5 -1
  144. data/lib/aws-sdk-sts/endpoint_parameters.rb +10 -9
  145. data/lib/aws-sdk-sts/endpoint_provider.rb +50 -55
  146. data/lib/aws-sdk-sts/endpoints.rb +2 -118
  147. data/lib/aws-sdk-sts/errors.rb +15 -0
  148. data/lib/aws-sdk-sts/plugins/endpoints.rb +19 -28
  149. data/lib/aws-sdk-sts/presigner.rb +2 -6
  150. data/lib/aws-sdk-sts/types.rb +171 -28
  151. data/lib/aws-sdk-sts.rb +15 -11
  152. data/lib/seahorse/client/async_base.rb +4 -5
  153. data/lib/seahorse/client/async_response.rb +19 -0
  154. data/lib/seahorse/client/base.rb +18 -21
  155. data/lib/seahorse/client/h2/connection.rb +18 -28
  156. data/lib/seahorse/client/h2/handler.rb +14 -3
  157. data/lib/seahorse/client/handler.rb +1 -1
  158. data/lib/seahorse/client/http/response.rb +1 -1
  159. data/lib/seahorse/client/net_http/connection_pool.rb +15 -12
  160. data/lib/seahorse/client/net_http/handler.rb +21 -9
  161. data/lib/seahorse/client/networking_error.rb +1 -1
  162. data/lib/seahorse/client/plugin.rb +8 -0
  163. data/lib/seahorse/client/plugins/endpoint.rb +0 -1
  164. data/lib/seahorse/client/plugins/h2.rb +4 -4
  165. data/lib/seahorse/client/plugins/net_http.rb +57 -16
  166. data/lib/seahorse/client/request_context.rb +9 -2
  167. data/lib/seahorse/client/response.rb +2 -0
  168. data/lib/seahorse/model/shapes.rb +2 -2
  169. data/lib/seahorse/util.rb +2 -1
  170. data/sig/aws-sdk-core/async_client_stubs.rbs +21 -0
  171. data/sig/aws-sdk-core/telemetry/base.rbs +46 -0
  172. data/sig/aws-sdk-core/telemetry/otel.rbs +22 -0
  173. data/sig/aws-sdk-core/telemetry/span_kind.rbs +15 -0
  174. data/sig/aws-sdk-core/telemetry/span_status.rbs +24 -0
  175. data/sig/seahorse/client/async_base.rbs +18 -0
  176. metadata +96 -23
  177. /data/lib/aws-sdk-core/xml/parser/{engines/libxml.rb → libxml_engine.rb} +0 -0
  178. /data/lib/aws-sdk-core/xml/parser/{engines/nokogiri.rb → nokogiri_engine.rb} +0 -0
  179. /data/lib/aws-sdk-core/xml/parser/{engines/oga.rb → oga_engine.rb} +0 -0
  180. /data/lib/aws-sdk-core/xml/parser/{engines/ox.rb → ox_engine.rb} +0 -0
  181. /data/lib/aws-sdk-core/xml/parser/{engines/rexml.rb → rexml_engine.rb} +0 -0
@@ -0,0 +1,53 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'cbor/encoder'
4
+ require_relative 'cbor/decoder'
5
+
6
+ module Aws
7
+ # @api private
8
+ module Cbor
9
+
10
+ # CBOR Tagged data (Major type 6).
11
+ # A Tag consists of a tag number and a value.
12
+ # In the extended generic data model, a tag number's definition
13
+ # describes the additional semantics conveyed with the tag number.
14
+ # # @!method initialize(*args)
15
+ # @option args [Integer] :tag The tag number.
16
+ # @option args [Object] :value The tag's content.
17
+ # @!attribute tag
18
+ # The tag number.
19
+ # @return [Integer]
20
+ # @!attribute value
21
+ # The tag's content.
22
+ # @return [Object]
23
+ Tagged = Struct.new(:tag, :value)
24
+
25
+ class Error < StandardError; end
26
+
27
+ class OutOfBytesError < Error
28
+ def initialize(n, left)
29
+ super("Out of bytes. Trying to read #{n} bytes but buffer contains only #{left}")
30
+ end
31
+ end
32
+
33
+ class UnknownTypeError < Error
34
+ def initialize(type)
35
+ super("Unable to encode #{type}")
36
+ end
37
+ end
38
+
39
+ class ExtraBytesError < Error
40
+ def initialize(pos, size)
41
+ super("Extra bytes follow after decoding item. Read #{pos} / #{size} bytes")
42
+ end
43
+ end
44
+
45
+ class UnexpectedBreakCodeError < Error; end
46
+
47
+ class UnexpectedAdditionalInformationError < Error
48
+ def initialize(add_info)
49
+ super("Unexpected additional information: #{add_info}")
50
+ end
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Aws
4
+ # setup autoloading for ClientSideMonitoring module
5
+ module ClientSideMonitoring
6
+ autoload :RequestMetrics, 'aws-sdk-core/client_side_monitoring/request_metrics'
7
+ autoload :Publisher, 'aws-sdk-core/client_side_monitoring/publisher'
8
+ end
9
+ end
@@ -15,27 +15,11 @@ module Aws
15
15
 
16
16
  # @api private
17
17
  def setup_stubbing
18
- @stubs = {}
19
- @stub_mutex = Mutex.new
20
18
  if Hash === @config.stub_responses
21
19
  @config.stub_responses.each do |operation_name, stubs|
22
20
  apply_stubs(operation_name, Array === stubs ? stubs : [stubs])
23
21
  end
24
22
  end
25
-
26
- # When a client is stubbed allow the user to access the requests made
27
- requests = @api_requests = []
28
- requests_mutex = @requests_mutex = Mutex.new
29
- self.handle do |context|
30
- requests_mutex.synchronize do
31
- requests << {
32
- operation_name: context.operation_name,
33
- params: context.params,
34
- context: context
35
- }
36
- end
37
- @handler.call(context)
38
- end
39
23
  end
40
24
 
41
25
  # Configures what data / errors should be returned from the named operation
@@ -175,7 +159,7 @@ module Aws
175
159
  # on a client that has not enabled response stubbing via
176
160
  # `:stub_responses => true`.
177
161
  def stub_responses(operation_name, *stubs)
178
- if config.stub_responses
162
+ if @config.stub_responses
179
163
  apply_stubs(operation_name, stubs.flatten)
180
164
  else
181
165
  msg = 'stubbing is not enabled; enable stubbing in the constructor '\
@@ -194,12 +178,12 @@ module Aws
194
178
  # @raise [NotImplementedError] Raises `NotImplementedError` when the client
195
179
  # is not stubbed.
196
180
  def api_requests(options = {})
197
- if config.stub_responses
198
- @requests_mutex.synchronize do
181
+ if @config.stub_responses
182
+ @config.api_requests_mutex.synchronize do
199
183
  if options[:exclude_presign]
200
- @api_requests.reject {|req| req[:context][:presigned_url] }
184
+ @config.api_requests.reject {|req| req[:context][:presigned_url] }
201
185
  else
202
- @api_requests
186
+ @config.api_requests
203
187
  end
204
188
  end
205
189
  else
@@ -228,54 +212,44 @@ module Aws
228
212
  # @return [Structure] Returns a stubbed response data structure. The
229
213
  # actual class returned will depend on the given `operation_name`.
230
214
  def stub_data(operation_name, data = {})
231
- Stubbing::StubData.new(config.api.operation(operation_name)).stub(data)
215
+ Stubbing::StubData.new(@config.api.operation(operation_name)).stub(data)
232
216
  end
233
217
 
234
218
  # @api private
235
219
  def next_stub(context)
236
220
  operation_name = context.operation_name.to_sym
237
- stub = @stub_mutex.synchronize do
238
- stubs = @stubs[operation_name] || []
221
+ stub = @config.stubs_mutex.synchronize do
222
+ stubs = @config.stubs[operation_name] || []
239
223
  case stubs.length
240
- when 0 then default_stub(operation_name)
224
+ when 0 then stub_data(operation_name)
241
225
  when 1 then stubs.first
242
226
  else stubs.shift
243
227
  end
244
228
  end
245
- Proc === stub ? convert_stub(operation_name, stub.call(context)) : stub
229
+ stub = convert_stub(operation_name, stub, context)
230
+ stub[:mutex] = Mutex.new
231
+ stub
246
232
  end
247
233
 
248
234
  private
249
235
 
250
- def default_stub(operation_name)
251
- stub = stub_data(operation_name)
252
- http_response_stub(operation_name, stub)
236
+ def apply_stubs(operation_name, stubs)
237
+ @config.stubs_mutex.synchronize do
238
+ @config.stubs[operation_name.to_sym] = stubs
239
+ end
253
240
  end
254
241
 
255
242
  # This method converts the given stub data and converts it to a
256
243
  # HTTP response (when possible). This enables the response stubbing
257
244
  # plugin to provide a HTTP response that triggers all normal events
258
245
  # during response handling.
259
- def apply_stubs(operation_name, stubs)
260
- @stub_mutex.synchronize do
261
- @stubs[operation_name.to_sym] = stubs.map do |stub|
262
- convert_stub(operation_name, stub)
263
- end
264
- end
265
- end
266
-
267
- def convert_stub(operation_name, stub)
268
- stub = case stub
269
- when Proc then stub
246
+ def convert_stub(operation_name, stub, context)
247
+ case stub
248
+ when Proc then convert_stub(operation_name, stub.call(context), context)
270
249
  when Exception, Class then { error: stub }
271
250
  when String then service_error_stub(stub)
272
- when Hash then http_response_stub(operation_name, stub)
273
- else { data: stub }
274
- end
275
- if Hash === stub
276
- stub[:mutex] = Mutex.new
251
+ else http_response_stub(operation_name, stub)
277
252
  end
278
- stub
279
253
  end
280
254
 
281
255
  def service_error_stub(error_code)
@@ -299,21 +273,22 @@ module Aws
299
273
  end
300
274
 
301
275
  def data_to_http_resp(operation_name, data)
302
- api = config.api
276
+ api = @config.api
303
277
  operation = api.operation(operation_name)
304
278
  ParamValidator.new(operation.output, input: false).validate!(data)
305
279
  protocol_helper.stub_data(api, operation, data)
306
280
  end
307
281
 
308
282
  def protocol_helper
309
- case config.api.metadata['protocol']
310
- when 'json' then Stubbing::Protocols::Json
311
- when 'query' then Stubbing::Protocols::Query
312
- when 'ec2' then Stubbing::Protocols::EC2
313
- when 'rest-json' then Stubbing::Protocols::RestJson
314
- when 'rest-xml' then Stubbing::Protocols::RestXml
315
- when 'api-gateway' then Stubbing::Protocols::ApiGateway
316
- else raise "unsupported protocol"
283
+ case @config.api.metadata['protocol']
284
+ when 'json' then Stubbing::Protocols::Json
285
+ when 'rest-json' then Stubbing::Protocols::RestJson
286
+ when 'rest-xml' then Stubbing::Protocols::RestXml
287
+ when 'query' then Stubbing::Protocols::Query
288
+ when 'ec2' then Stubbing::Protocols::EC2
289
+ when 'smithy-rpc-v2-cbor' then Stubbing::Protocols::RpcV2
290
+ when 'api-gateway' then Stubbing::Protocols::ApiGateway
291
+ else raise 'unsupported protocol'
317
292
  end.new
318
293
  end
319
294
  end
@@ -9,6 +9,10 @@ module Aws
9
9
  # @return [Time]
10
10
  attr_reader :expiration
11
11
 
12
+ # @api private
13
+ # Returns UserAgent metrics for credentials.
14
+ attr_accessor :metrics
15
+
12
16
  # @return [Boolean]
13
17
  def set?
14
18
  !!@credentials && @credentials.set?
@@ -42,11 +42,14 @@ module Aws
42
42
 
43
43
  def static_credentials(options)
44
44
  if options[:config]
45
- Credentials.new(
45
+ creds = Credentials.new(
46
46
  options[:config].access_key_id,
47
47
  options[:config].secret_access_key,
48
- options[:config].session_token
48
+ options[:config].session_token,
49
+ account_id: options[:config].account_id
49
50
  )
51
+ creds.metrics = ['CREDENTIALS_PROFILE']
52
+ creds
50
53
  end
51
54
  end
52
55
 
@@ -75,7 +78,9 @@ module Aws
75
78
 
76
79
  def static_profile_credentials(options)
77
80
  if options[:config] && options[:config].profile
78
- SharedCredentials.new(profile_name: options[:config].profile)
81
+ creds = SharedCredentials.new(profile_name: options[:config].profile)
82
+ creds.metrics = ['CREDENTIALS_PROFILE']
83
+ creds
79
84
  end
80
85
  rescue Errors::NoSuchProfileError
81
86
  nil
@@ -84,7 +89,11 @@ module Aws
84
89
  def static_profile_process_credentials(options)
85
90
  if Aws.shared_config.config_enabled? && options[:config] && options[:config].profile
86
91
  process_provider = Aws.shared_config.credential_process(profile: options[:config].profile)
87
- ProcessCredentials.new(process_provider) if process_provider
92
+ if process_provider
93
+ creds = ProcessCredentials.new([process_provider])
94
+ creds.metrics << 'CREDENTIALS_PROFILE_PROCESS'
95
+ creds
96
+ end
88
97
  end
89
98
  rescue Errors::NoSuchProfileError
90
99
  nil
@@ -94,7 +103,15 @@ module Aws
94
103
  key = %w[AWS_ACCESS_KEY_ID AMAZON_ACCESS_KEY_ID AWS_ACCESS_KEY]
95
104
  secret = %w[AWS_SECRET_ACCESS_KEY AMAZON_SECRET_ACCESS_KEY AWS_SECRET_KEY]
96
105
  token = %w[AWS_SESSION_TOKEN AMAZON_SESSION_TOKEN]
97
- Credentials.new(envar(key), envar(secret), envar(token))
106
+ account_id = %w[AWS_ACCOUNT_ID]
107
+ creds = Credentials.new(
108
+ envar(key),
109
+ envar(secret),
110
+ envar(token),
111
+ account_id: envar(account_id)
112
+ )
113
+ creds.metrics = ['CREDENTIALS_ENV_VARS']
114
+ creds
98
115
  end
99
116
 
100
117
  def envar(keys)
@@ -110,16 +127,22 @@ module Aws
110
127
 
111
128
  def shared_credentials(options)
112
129
  profile_name = determine_profile_name(options)
113
- SharedCredentials.new(profile_name: profile_name)
130
+ creds = SharedCredentials.new(profile_name: profile_name)
131
+ creds.metrics = ['CREDENTIALS_PROFILE']
132
+ creds
114
133
  rescue Errors::NoSuchProfileError
115
134
  nil
116
135
  end
117
136
 
118
137
  def process_credentials(options)
119
138
  profile_name = determine_profile_name(options)
120
- if Aws.shared_config.config_enabled? &&
121
- (process_provider = Aws.shared_config.credential_process(profile: profile_name))
122
- ProcessCredentials.new(process_provider)
139
+ if Aws.shared_config.config_enabled?
140
+ process_provider = Aws.shared_config.credential_process(profile: profile_name)
141
+ if process_provider
142
+ creds = ProcessCredentials.new([process_provider])
143
+ creds.metrics << 'CREDENTIALS_PROFILE_PROCESS'
144
+ creds
145
+ end
123
146
  end
124
147
  rescue Errors::NoSuchProfileError
125
148
  nil
@@ -149,7 +172,11 @@ module Aws
149
172
  role_session_name: ENV['AWS_ROLE_SESSION_NAME']
150
173
  }
151
174
  cfg[:region] = region if region
152
- AssumeRoleWebIdentityCredentials.new(cfg)
175
+ Aws::Plugins::UserAgent.metric('CREDENTIALS_ENV_VARS_STS_WEB_ID_TOKEN') do
176
+ creds = AssumeRoleWebIdentityCredentials.new(cfg)
177
+ creds.metrics << 'CREDENTIALS_ENV_VARS_STS_WEB_ID_TOKEN'
178
+ creds
179
+ end
153
180
  elsif Aws.shared_config.config_enabled?
154
181
  profile = options[:config].profile if options[:config]
155
182
  Aws.shared_config.assume_role_web_identity_credentials_from_config(
@@ -164,7 +191,7 @@ module Aws
164
191
  if ENV['AWS_CONTAINER_CREDENTIALS_RELATIVE_URI'] ||
165
192
  ENV['AWS_CONTAINER_CREDENTIALS_FULL_URI']
166
193
  ECSCredentials.new(options)
167
- else
194
+ elsif !(ENV.fetch('AWS_EC2_METADATA_DISABLED', 'false').downcase == 'true')
168
195
  InstanceProfileCredentials.new(options.merge(profile: profile_name))
169
196
  end
170
197
  end
@@ -6,21 +6,34 @@ module Aws
6
6
  # @param [String] access_key_id
7
7
  # @param [String] secret_access_key
8
8
  # @param [String] session_token (nil)
9
- def initialize(access_key_id, secret_access_key, session_token = nil)
9
+ # @param [Hash] kwargs
10
+ # @option kwargs [String] :credential_scope (nil)
11
+ def initialize(access_key_id, secret_access_key, session_token = nil,
12
+ **kwargs)
10
13
  @access_key_id = access_key_id
11
14
  @secret_access_key = secret_access_key
12
15
  @session_token = session_token
16
+ @account_id = kwargs[:account_id]
17
+ @metrics = ['CREDENTIALS_CODE']
13
18
  end
14
19
 
15
- # @return [String, nil]
20
+ # @return [String]
16
21
  attr_reader :access_key_id
17
22
 
18
- # @return [String, nil]
23
+ # @return [String]
19
24
  attr_reader :secret_access_key
20
25
 
21
26
  # @return [String, nil]
22
27
  attr_reader :session_token
23
28
 
29
+ # @return [String, nil]
30
+ attr_reader :account_id
31
+
32
+ # @api private
33
+ # Returns the credentials source. Used for tracking credentials
34
+ # related UserAgent metrics.
35
+ attr_accessor :metrics
36
+
24
37
  # @return [Credentials]
25
38
  def credentials
26
39
  self
@@ -30,9 +43,9 @@ module Aws
30
43
  # access key are both set.
31
44
  def set?
32
45
  !access_key_id.nil? &&
33
- !access_key_id.empty? &&
34
- !secret_access_key.nil? &&
35
- !secret_access_key.empty?
46
+ !access_key_id.empty? &&
47
+ !secret_access_key.nil? &&
48
+ !secret_access_key.empty?
36
49
  end
37
50
 
38
51
  # Removing the secret access key from the default inspect string.
@@ -183,7 +183,7 @@ module Aws
183
183
 
184
184
  def open_connection
185
185
  uri = URI.parse(@endpoint)
186
- http = Net::HTTP.new(uri.hostname || @endpoint, @port || uri.port)
186
+ http = Net::HTTP.new(uri.hostname || @endpoint, uri.port || @port)
187
187
  http.open_timeout = @http_open_timeout
188
188
  http.read_timeout = @http_read_timeout
189
189
  http.set_debug_output(@http_debug_output) if @http_debug_output
@@ -77,6 +77,7 @@ module Aws
77
77
  @http_debug_output = options[:http_debug_output]
78
78
  @backoff = backoff(options[:backoff])
79
79
  @async_refresh = false
80
+ @metrics = ['CREDENTIALS_HTTP']
80
81
  super
81
82
  end
82
83
 
@@ -3,15 +3,17 @@
3
3
  module Aws
4
4
  module Endpoints
5
5
  class Endpoint
6
- def initialize(url:, properties: {}, headers: {})
6
+ def initialize(url:, properties: {}, headers: {}, metadata: {})
7
7
  @url = url
8
8
  @properties = properties
9
9
  @headers = headers
10
+ @metadata = metadata
10
11
  end
11
12
 
12
13
  attr_reader :url
13
14
  attr_reader :properties
14
15
  attr_reader :headers
16
+ attr_reader :metadata
15
17
  end
16
18
  end
17
19
  end
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'cgi'
3
+ require "cgi/escape"
4
+ require "cgi/util" if RUBY_VERSION < "3.5"
4
5
 
5
6
  module Aws
6
7
  module Endpoints
@@ -28,7 +29,11 @@ module Aws
28
29
 
29
30
  val = if (index = parts.first[BRACKET_REGEX, 1])
30
31
  # remove brackets and index from part before indexing
31
- value[parts.first.gsub(BRACKET_REGEX, '')][index.to_i]
32
+ if (base = parts.first.gsub(BRACKET_REGEX, '')) && !base.empty?
33
+ value[base][index.to_i]
34
+ else
35
+ value[index.to_i]
36
+ end
32
37
  else
33
38
  value[parts.first]
34
39
  end
@@ -90,14 +95,7 @@ module Aws
90
95
 
91
96
  # aws.partition(value: string) Option<Partition>
92
97
  def self.aws_partition(value)
93
- partition =
94
- Aws::Partitions.find { |p| p.region?(value) } ||
95
- Aws::Partitions.find { |p| value.match(p.region_regex) } ||
96
- Aws::Partitions.find { |p| p.name == 'aws' }
97
-
98
- return nil unless partition
99
-
100
- partition.metadata
98
+ Aws::Partitions::Metadata.partition(value)
101
99
  end
102
100
 
103
101
  # aws.parseArn(value: string) Option<ARN>
@@ -14,15 +14,33 @@ require_relative 'endpoints/templater'
14
14
  require_relative 'endpoints/tree_rule'
15
15
  require_relative 'endpoints/url'
16
16
 
17
+ require 'aws-sigv4'
18
+
17
19
  module Aws
18
20
  # @api private
19
21
  module Endpoints
22
+ # Maps config auth scheme preferences to endpoint auth scheme names.
23
+ ENDPOINT_AUTH_PREFERENCE_MAP = {
24
+ 'sigv4' => %w[sigv4 sigv4-s3express],
25
+ 'sigv4a' => ['sigv4a'],
26
+ 'httpBearerAuth' => ['bearer'],
27
+ 'noAuth' => ['none']
28
+ }.freeze
29
+ SUPPORTED_ENDPOINT_AUTH = ENDPOINT_AUTH_PREFERENCE_MAP.values.flatten.freeze
30
+
31
+ # Maps configured auth scheme preferences to modeled auth traits.
32
+ MODELED_AUTH_PREFERENCE_MAP = {
33
+ 'sigv4' => 'aws.auth#sigv4',
34
+ 'sigv4a' => 'aws.auth#sigv4a',
35
+ 'httpBearerAuth' => 'smithy.api#httpBearerAuth',
36
+ 'noAuth' => 'smithy.api#noAuth'
37
+ }.freeze
38
+ SUPPORTED_MODELED_AUTH = MODELED_AUTH_PREFERENCE_MAP.values.freeze
39
+
20
40
  class << self
21
41
  def resolve_auth_scheme(context, endpoint)
22
42
  if endpoint && (auth_schemes = endpoint.properties['authSchemes'])
23
- auth_scheme = auth_schemes.find do |scheme|
24
- Aws::Plugins::Sign::SUPPORTED_AUTH_TYPES.include?(scheme['name'])
25
- end
43
+ auth_scheme = endpoint_auth_scheme_preference(auth_schemes, context.config.auth_scheme_preference)
26
44
  raise 'No supported auth scheme for this endpoint.' unless auth_scheme
27
45
 
28
46
  merge_signing_defaults(auth_scheme, context.config)
@@ -33,8 +51,86 @@ module Aws
33
51
 
34
52
  private
35
53
 
54
+ def endpoint_auth_scheme_preference(auth_schemes, preferred_auth)
55
+ ordered_auth = preferred_auth.each_with_object([]) do |pref, list|
56
+ next unless ENDPOINT_AUTH_PREFERENCE_MAP.key?(pref)
57
+
58
+ ENDPOINT_AUTH_PREFERENCE_MAP[pref].each { |name| list << { 'name' => name } }
59
+ end
60
+ ordered_auth += auth_schemes
61
+ ordered_auth.find { |auth| SUPPORTED_ENDPOINT_AUTH.include?(auth['name']) }
62
+ end
63
+
64
+ def merge_signing_defaults(auth_scheme, config)
65
+ if %w[sigv4 sigv4a sigv4-s3express].include?(auth_scheme['name'])
66
+ auth_scheme['signingName'] ||= sigv4_name(config)
67
+
68
+ # back fill disableNormalizePath for S3 until it gets correctly set in the rules
69
+ if auth_scheme['signingName'] == 's3' &&
70
+ !auth_scheme.include?('disableNormalizePath') &&
71
+ auth_scheme.include?('disableDoubleEncoding')
72
+ auth_scheme['disableNormalizePath'] = auth_scheme['disableDoubleEncoding']
73
+ end
74
+ if auth_scheme['name'] == 'sigv4a'
75
+ # config option supersedes endpoint properties
76
+ auth_scheme['signingRegionSet'] =
77
+ config.sigv4a_signing_region_set || auth_scheme['signingRegionSet'] || [config.region]
78
+ else
79
+ auth_scheme['signingRegion'] ||= config.region
80
+ end
81
+ end
82
+ auth_scheme
83
+ end
84
+
85
+ def sigv4_name(config)
86
+ config.api.metadata['signingName'] || config.api.metadata['endpointPrefix']
87
+ end
88
+
36
89
  def default_auth_scheme(context)
37
- case default_api_authtype(context)
90
+ if (modeled_auth = default_api_auth(context))
91
+ auth = modeled_auth_scheme_preference(modeled_auth, context.config.auth_scheme_preference)
92
+ case auth
93
+ when 'aws.auth#sigv4', 'aws.auth#sigv4a'
94
+ auth_scheme = { 'name' => auth.split('#').last }
95
+ if s3_or_s3v4_signature_version?(context)
96
+ auth_scheme = auth_scheme.merge(
97
+ 'disableDoubleEncoding' => true,
98
+ 'disableNormalizePath' => true
99
+ )
100
+ end
101
+ merge_signing_defaults(auth_scheme, context.config)
102
+ when 'smithy.api#httpBearerAuth'
103
+ { 'name' => 'bearer' }
104
+ when 'smithy.api#noAuth'
105
+ { 'name' => 'none' }
106
+ else
107
+ raise 'No supported auth trait for this endpoint.'
108
+ end
109
+ else
110
+ legacy_default_auth_scheme(context)
111
+ end
112
+ end
113
+
114
+ def modeled_auth_scheme_preference(modeled_auth, preferred_auth)
115
+ ordered_auth = preferred_auth.map { |pref| MODELED_AUTH_PREFERENCE_MAP[pref] }.compact
116
+ ordered_auth += modeled_auth
117
+ ordered_auth.find { |auth| SUPPORTED_MODELED_AUTH.include?(auth) }
118
+ end
119
+
120
+ def default_api_auth(context)
121
+ context.config.api.operation(context.operation_name)['auth'] ||
122
+ context.config.api.metadata['auth']
123
+ end
124
+
125
+ def s3_or_s3v4_signature_version?(context)
126
+ %w[s3 s3v4].include?(context.config.api.metadata['signatureVersion'])
127
+ end
128
+
129
+ # Legacy auth resolution - looks for deprecated signatureVersion
130
+ # and authType traits.
131
+
132
+ def legacy_default_auth_scheme(context)
133
+ case legacy_default_api_authtype(context)
38
134
  when 'v4', 'v4-unsigned-body'
39
135
  auth_scheme = { 'name' => 'sigv4' }
40
136
  merge_signing_defaults(auth_scheme, context.config)
@@ -52,27 +148,11 @@ module Aws
52
148
  end
53
149
  end
54
150
 
55
- def merge_signing_defaults(auth_scheme, config)
56
- if %w[sigv4 sigv4a sigv4-s3express].include?(auth_scheme['name'])
57
- auth_scheme['signingName'] ||= sigv4_name(config)
58
- if auth_scheme['name'] == 'sigv4a'
59
- auth_scheme['signingRegionSet'] ||= ['*']
60
- else
61
- auth_scheme['signingRegion'] ||= config.region
62
- end
63
- end
64
- auth_scheme
65
- end
66
-
67
- def default_api_authtype(context)
151
+ def legacy_default_api_authtype(context)
68
152
  context.config.api.operation(context.operation_name)['authtype'] ||
69
153
  context.config.api.metadata['signatureVersion']
70
154
  end
71
155
 
72
- def sigv4_name(config)
73
- config.api.metadata['signingName'] ||
74
- config.api.metadata['endpointPrefix']
75
- end
76
156
  end
77
157
  end
78
158
  end
@@ -0,0 +1,46 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Aws
4
+ # @api private
5
+ class ErrorHandler < Seahorse::Client::Handler
6
+
7
+ private
8
+
9
+ def error(context)
10
+ body = context.http_response.body_contents
11
+ # This is not correct per protocol tests. Some headers will determine the error code.
12
+ # If the body is empty, there is still potentially an error code from the header, but
13
+ # we are making a generic http status error instead. In a new major version, we should
14
+ # always try to extract header, and during extraction, check headers and body.
15
+ if body.empty?
16
+ code, message, data = http_status_error(context)
17
+ else
18
+ code, message, data = extract_error(body, context)
19
+ end
20
+ build_error(context, code, message, data)
21
+ end
22
+
23
+ def build_error(context, code, message, data)
24
+ errors_module = context.client.class.errors_module
25
+ errors_module.error_class(code).new(context, message, data)
26
+ end
27
+
28
+ def http_status_error(context)
29
+ [http_status_error_code(context), '', EmptyStructure.new]
30
+ end
31
+
32
+ def http_status_error_code(context)
33
+ status_code = context.http_response.status_code
34
+ {
35
+ 302 => 'MovedTemporarily',
36
+ 304 => 'NotModified',
37
+ 400 => 'BadRequest',
38
+ 403 => 'Forbidden',
39
+ 404 => 'NotFound',
40
+ 412 => 'PreconditionFailed',
41
+ 413 => 'RequestEntityTooLarge',
42
+ }[status_code] || "Http#{status_code}Error"
43
+ end
44
+
45
+ end
46
+ end