aws-sdk-core 3.201.2 → 3.226.1

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 (115) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +319 -0
  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/cbor/decoder.rb +0 -2
  10. data/lib/aws-sdk-core/cbor/encoder.rb +2 -2
  11. data/lib/aws-sdk-core/cbor.rb +3 -56
  12. data/lib/aws-sdk-core/client_side_monitoring.rb +9 -0
  13. data/lib/aws-sdk-core/client_stubs.rb +29 -55
  14. data/lib/aws-sdk-core/credential_provider.rb +4 -0
  15. data/lib/aws-sdk-core/credential_provider_chain.rb +35 -8
  16. data/lib/aws-sdk-core/credentials.rb +19 -6
  17. data/lib/aws-sdk-core/ecs_credentials.rb +1 -0
  18. data/lib/aws-sdk-core/endpoints/endpoint.rb +3 -1
  19. data/lib/aws-sdk-core/endpoints/matchers.rb +3 -9
  20. data/lib/aws-sdk-core/endpoints.rb +13 -3
  21. data/lib/aws-sdk-core/errors.rb +2 -2
  22. data/lib/aws-sdk-core/event_emitter.rb +1 -1
  23. data/lib/aws-sdk-core/instance_profile_credentials.rb +1 -0
  24. data/lib/aws-sdk-core/json/error_handler.rb +2 -1
  25. data/lib/aws-sdk-core/json/handler.rb +1 -0
  26. data/lib/aws-sdk-core/log/param_formatter.rb +7 -3
  27. data/lib/aws-sdk-core/log.rb +10 -0
  28. data/lib/aws-sdk-core/plugins/checksum_algorithm.rb +332 -170
  29. data/lib/aws-sdk-core/plugins/client_metrics_plugin.rb +0 -1
  30. data/lib/aws-sdk-core/plugins/credentials_configuration.rb +7 -3
  31. data/lib/aws-sdk-core/plugins/endpoint_pattern.rb +40 -32
  32. data/lib/aws-sdk-core/plugins/http_checksum.rb +2 -8
  33. data/lib/aws-sdk-core/plugins/regional_endpoint.rb +44 -24
  34. data/lib/aws-sdk-core/plugins/sign.rb +18 -5
  35. data/lib/aws-sdk-core/plugins/stub_responses.rb +52 -9
  36. data/lib/aws-sdk-core/plugins/telemetry.rb +75 -0
  37. data/lib/aws-sdk-core/plugins/user_agent.rb +48 -9
  38. data/lib/aws-sdk-core/plugins.rb +39 -0
  39. data/lib/aws-sdk-core/process_credentials.rb +3 -2
  40. data/lib/aws-sdk-core/resources.rb +8 -0
  41. data/lib/aws-sdk-core/rest/request/headers.rb +3 -3
  42. data/lib/aws-sdk-core/rpc_v2/builder.rb +1 -1
  43. data/lib/aws-sdk-core/{cbor → rpc_v2}/cbor_engine.rb +4 -5
  44. data/lib/aws-sdk-core/rpc_v2/content_type_handler.rb +3 -1
  45. data/lib/aws-sdk-core/rpc_v2/error_handler.rb +3 -2
  46. data/lib/aws-sdk-core/rpc_v2/handler.rb +7 -2
  47. data/lib/aws-sdk-core/rpc_v2/parser.rb +9 -1
  48. data/lib/aws-sdk-core/rpc_v2.rb +65 -2
  49. data/lib/aws-sdk-core/shared_config.rb +77 -22
  50. data/lib/aws-sdk-core/shared_credentials.rb +1 -7
  51. data/lib/aws-sdk-core/sso_credentials.rb +4 -1
  52. data/lib/aws-sdk-core/stubbing/protocols/ec2.rb +12 -11
  53. data/lib/aws-sdk-core/stubbing/protocols/json.rb +11 -10
  54. data/lib/aws-sdk-core/stubbing/protocols/query.rb +7 -6
  55. data/lib/aws-sdk-core/stubbing/protocols/rest.rb +2 -1
  56. data/lib/aws-sdk-core/stubbing/protocols/rest_json.rb +9 -8
  57. data/lib/aws-sdk-core/stubbing/protocols/rest_xml.rb +6 -5
  58. data/lib/aws-sdk-core/stubbing/protocols/rpc_v2.rb +13 -15
  59. data/lib/aws-sdk-core/stubbing.rb +22 -0
  60. data/lib/aws-sdk-core/telemetry/base.rb +177 -0
  61. data/lib/aws-sdk-core/telemetry/no_op.rb +70 -0
  62. data/lib/aws-sdk-core/telemetry/otel.rb +235 -0
  63. data/lib/aws-sdk-core/telemetry/span_kind.rb +22 -0
  64. data/lib/aws-sdk-core/telemetry/span_status.rb +59 -0
  65. data/lib/aws-sdk-core/telemetry.rb +78 -0
  66. data/lib/aws-sdk-core/util.rb +2 -1
  67. data/lib/aws-sdk-core/waiters/poller.rb +9 -4
  68. data/lib/aws-sdk-core/xml/error_handler.rb +2 -1
  69. data/lib/aws-sdk-core.rb +82 -112
  70. data/lib/aws-sdk-sso/client.rb +86 -37
  71. data/lib/aws-sdk-sso/client_api.rb +1 -0
  72. data/lib/aws-sdk-sso/endpoint_parameters.rb +9 -6
  73. data/lib/aws-sdk-sso/endpoint_provider.rb +14 -18
  74. data/lib/aws-sdk-sso/endpoints.rb +2 -54
  75. data/lib/aws-sdk-sso/plugins/endpoints.rb +19 -20
  76. data/lib/aws-sdk-sso/types.rb +1 -0
  77. data/lib/aws-sdk-sso.rb +15 -11
  78. data/lib/aws-sdk-ssooidc/client.rb +123 -57
  79. data/lib/aws-sdk-ssooidc/client_api.rb +7 -0
  80. data/lib/aws-sdk-ssooidc/endpoint_parameters.rb +9 -6
  81. data/lib/aws-sdk-ssooidc/endpoint_provider.rb +14 -18
  82. data/lib/aws-sdk-ssooidc/endpoints.rb +2 -54
  83. data/lib/aws-sdk-ssooidc/plugins/endpoints.rb +19 -20
  84. data/lib/aws-sdk-ssooidc/types.rb +49 -16
  85. data/lib/aws-sdk-ssooidc.rb +15 -11
  86. data/lib/aws-sdk-sts/client.rb +294 -89
  87. data/lib/aws-sdk-sts/client_api.rb +34 -8
  88. data/lib/aws-sdk-sts/customizations.rb +5 -1
  89. data/lib/aws-sdk-sts/endpoint_parameters.rb +10 -9
  90. data/lib/aws-sdk-sts/endpoint_provider.rb +50 -55
  91. data/lib/aws-sdk-sts/endpoints.rb +2 -118
  92. data/lib/aws-sdk-sts/errors.rb +16 -0
  93. data/lib/aws-sdk-sts/plugins/endpoints.rb +19 -28
  94. data/lib/aws-sdk-sts/types.rb +171 -28
  95. data/lib/aws-sdk-sts.rb +15 -11
  96. data/lib/seahorse/client/async_base.rb +4 -5
  97. data/lib/seahorse/client/base.rb +0 -14
  98. data/lib/seahorse/client/h2/connection.rb +18 -28
  99. data/lib/seahorse/client/h2/handler.rb +13 -3
  100. data/lib/seahorse/client/http/response.rb +1 -1
  101. data/lib/seahorse/client/net_http/connection_pool.rb +12 -3
  102. data/lib/seahorse/client/net_http/handler.rb +21 -9
  103. data/lib/seahorse/client/networking_error.rb +1 -1
  104. data/lib/seahorse/client/plugins/h2.rb +4 -4
  105. data/lib/seahorse/client/plugins/net_http.rb +9 -0
  106. data/lib/seahorse/client/request_context.rb +8 -1
  107. data/lib/seahorse/client/response.rb +2 -0
  108. data/lib/seahorse/util.rb +2 -1
  109. data/sig/aws-sdk-core/async_client_stubs.rbs +21 -0
  110. data/sig/aws-sdk-core/telemetry/base.rbs +46 -0
  111. data/sig/aws-sdk-core/telemetry/otel.rbs +22 -0
  112. data/sig/aws-sdk-core/telemetry/span_kind.rbs +15 -0
  113. data/sig/aws-sdk-core/telemetry/span_status.rbs +24 -0
  114. data/sig/seahorse/client/async_base.rbs +18 -0
  115. metadata +61 -19
@@ -4,62 +4,70 @@ module Aws
4
4
  module Plugins
5
5
  # @api private
6
6
  class EndpointPattern < Seahorse::Client::Plugin
7
-
8
- option(:disable_host_prefix_injection,
7
+ option(
8
+ :disable_host_prefix_injection,
9
9
  default: false,
10
10
  doc_type: 'Boolean',
11
- docstring: <<-DOCS
12
- Set to true to disable SDK automatically adding host prefix
13
- to default service endpoint when available.
14
- DOCS
15
- )
11
+ docstring: 'When `true`, the SDK will not prepend the modeled host prefix to the endpoint.'
12
+ ) do |cfg|
13
+ resolve_disable_host_prefix_injection(cfg)
14
+ end
16
15
 
17
- def add_handlers(handlers, config)
16
+ def add_handlers(handlers, _config)
18
17
  handlers.add(Handler, priority: 10)
19
18
  end
20
19
 
21
- class Handler < Seahorse::Client::Handler
20
+ class << self
21
+ private
22
+
23
+ def resolve_disable_host_prefix_injection(cfg)
24
+ value = ENV['AWS_DISABLE_HOST_PREFIX_INJECTION'] ||
25
+ Aws.shared_config.disable_host_prefix_injection(profile: cfg.profile) ||
26
+ 'false'
27
+ value = Aws::Util.str_2_bool(value)
28
+ unless [true, false].include?(value)
29
+ raise ArgumentError,
30
+ 'Must provide either `true` or `false` for '\
31
+ 'disable_host_prefix_injection profile option or for '\
32
+ 'ENV[\'AWS_DISABLE_HOST_PREFIX_INJECTION\']'
33
+ end
34
+ value
35
+ end
36
+ end
22
37
 
38
+ # @api private
39
+ class Handler < Seahorse::Client::Handler
23
40
  def call(context)
24
- if !context.config.disable_host_prefix_injection
41
+ unless context.config.disable_host_prefix_injection
25
42
  endpoint_trait = context.operation.endpoint_pattern
26
- if endpoint_trait && !endpoint_trait.empty?
27
- _apply_endpoint_trait(context, endpoint_trait)
28
- end
43
+ apply_endpoint_trait(context, endpoint_trait) if endpoint_trait && !endpoint_trait.empty?
29
44
  end
30
45
  @handler.call(context)
31
46
  end
32
47
 
33
48
  private
34
49
 
35
- def _apply_endpoint_trait(context, trait)
36
- # currently only support host pattern
37
- ori_host = context.http_request.endpoint.host
38
- if pattern = trait['hostPrefix']
39
- host_prefix = pattern.gsub(/\{.+?\}/) do |label|
40
- label = label.delete("{}")
41
- _replace_label_value(
42
- ori_host, label, context.operation.input, context.params)
43
- end
44
- context.http_request.endpoint.host = host_prefix + context.http_request.endpoint.host
50
+ def apply_endpoint_trait(context, trait)
51
+ pattern = trait['hostPrefix']
52
+ return unless pattern
53
+
54
+ host_prefix = pattern.gsub(/\{.+?}/) do |label|
55
+ label = label.delete('{}')
56
+ replace_label_value(label, context.operation.input, context.params)
45
57
  end
58
+ context.http_request.endpoint.host = host_prefix + context.http_request.endpoint.host
46
59
  end
47
60
 
48
- def _replace_label_value(ori, label, input_ref, params)
61
+ def replace_label_value(label, input_ref, params)
49
62
  name = nil
50
63
  input_ref.shape.members.each do |m_name, ref|
51
- if ref['hostLabel'] && ref['hostLabelName'] == label
52
- name = m_name
53
- end
54
- end
55
- if name.nil? || params[name].nil?
56
- raise Errors::MissingEndpointHostLabelValue.new(name)
64
+ name = m_name if ref['hostLabel'] && ref['hostLabelName'] == label
57
65
  end
66
+ raise Errors::MissingEndpointHostLabelValue, name if name.nil? || params[name].nil?
67
+
58
68
  params[name]
59
69
  end
60
-
61
70
  end
62
-
63
71
  end
64
72
  end
65
73
  end
@@ -11,8 +11,8 @@ module Aws
11
11
  CHUNK_SIZE = 1 * 1024 * 1024 # one MB
12
12
 
13
13
  def call(context)
14
- if checksum_required?(context) &&
15
- !context[:checksum_algorithms] && # skip in favor of flexible checksum
14
+ if context.operation.http_checksum_required &&
15
+ !context[:http_checksum][:request_algorithm] && # skip in favor of flexible checksum
16
16
  !context[:s3_express_endpoint] # s3 express endpoints do not support md5
17
17
  body = context.http_request.body
18
18
  context.http_request.headers['Content-Md5'] ||= md5(body)
@@ -22,12 +22,6 @@ module Aws
22
22
 
23
23
  private
24
24
 
25
- def checksum_required?(context)
26
- context.operation.http_checksum_required ||
27
- (context.operation.http_checksum &&
28
- context.operation.http_checksum['requestChecksumRequired'])
29
- end
30
-
31
25
  # @param [File, Tempfile, IO#read, String] value
32
26
  # @return [String<MD5>]
33
27
  def md5(value)
@@ -20,7 +20,7 @@ a default `:region` is searched for in the following locations:
20
20
  * `ENV['AWS_DEFAULT_REGION']`
21
21
  * `~/.aws/credentials`
22
22
  * `~/.aws/config`
23
- DOCS
23
+ DOCS
24
24
  resolve_region(cfg)
25
25
  end
26
26
 
@@ -35,7 +35,7 @@ in the following locations:
35
35
  * `Aws.config[:sigv4a_signing_region_set]`
36
36
  * `ENV['AWS_SIGV4A_SIGNING_REGION_SET']`
37
37
  * `~/.aws/config`
38
- DOCS
38
+ DOCS
39
39
  resolve_sigv4a_signing_region_set(cfg)
40
40
  end
41
41
 
@@ -44,7 +44,7 @@ in the following locations:
44
44
  docstring: <<-DOCS) do |cfg|
45
45
  When set to `true`, dualstack enabled endpoints (with `.aws` TLD)
46
46
  will be used if available.
47
- DOCS
47
+ DOCS
48
48
  resolve_use_dualstack_endpoint(cfg)
49
49
  end
50
50
 
@@ -54,7 +54,7 @@ will be used if available.
54
54
  When set to `true`, fips compatible endpoints will be used if available.
55
55
  When a `fips` region is used, the region is normalized and this config
56
56
  is set to `true`.
57
- DOCS
57
+ DOCS
58
58
  resolve_use_fips_endpoint(cfg)
59
59
  end
60
60
 
@@ -67,7 +67,7 @@ is set to `true`.
67
67
  docstring: <<-DOCS) do |cfg|
68
68
  Setting to true disables use of endpoint URLs provided via environment
69
69
  variables and the shared configuration file.
70
- DOCS
70
+ DOCS
71
71
  resolve_ignore_configured_endpoint_urls(cfg)
72
72
  end
73
73
 
@@ -75,7 +75,7 @@ variables and the shared configuration file.
75
75
  The client endpoint is normally constructed from the `:region`
76
76
  option. You should only configure an `:endpoint` when connecting
77
77
  to test or custom endpoints. This should be a valid HTTP(S) URI.
78
- DOCS
78
+ DOCS
79
79
  resolve_endpoint(cfg)
80
80
  end
81
81
 
@@ -83,6 +83,9 @@ to test or custom endpoints. This should be a valid HTTP(S) URI.
83
83
  region = client.config.region
84
84
  raise Errors::MissingRegionError if region.nil? || region == ''
85
85
 
86
+ # resolve a default endpoint to preserve legacy behavior
87
+ initialize_default_endpoint(client) if client.config.endpoint.nil?
88
+
86
89
  region_set = client.config.sigv4a_signing_region_set
87
90
  return if region_set.nil?
88
91
  raise Errors::InvalidRegionSetError unless region_set.is_a?(Array)
@@ -93,6 +96,39 @@ to test or custom endpoints. This should be a valid HTTP(S) URI.
93
96
  client.config.sigv4a_signing_region_set = region_set
94
97
  end
95
98
 
99
+ private
100
+
101
+ def initialize_default_endpoint(client)
102
+ client_module = Object.const_get(client.class.name.rpartition('::').first)
103
+ param_class = client_module.const_get(:EndpointParameters)
104
+ endpoint_provider = client.config.endpoint_provider
105
+ params = param_class.create(client.config)
106
+ endpoint = endpoint_provider.resolve_endpoint(params)
107
+ client.config.endpoint = endpoint.url
108
+ rescue ArgumentError, NameError
109
+ # fallback to legacy
110
+ client.config.endpoint = resolve_legacy_endpoint(client.config)
111
+ end
112
+
113
+ # set a default endpoint in config using legacy (endpoints.json) resolver
114
+ def resolve_legacy_endpoint(cfg)
115
+ endpoint_prefix = cfg.api.metadata['endpointPrefix']
116
+ if cfg.respond_to?(:sts_regional_endpoints)
117
+ sts_regional = cfg.sts_regional_endpoints
118
+ end
119
+
120
+ endpoint = Aws::Partitions::EndpointProvider.resolve(
121
+ cfg.region,
122
+ endpoint_prefix,
123
+ sts_regional,
124
+ {
125
+ dualstack: cfg.use_dualstack_endpoint,
126
+ fips: cfg.use_fips_endpoint
127
+ }
128
+ )
129
+ URI(endpoint)
130
+ end
131
+
96
132
  class << self
97
133
  private
98
134
 
@@ -150,7 +186,8 @@ to test or custom endpoints. This should be a valid HTTP(S) URI.
150
186
  # that a custom endpoint has NOT been configured by the user
151
187
  cfg.override_config(:regional_endpoint, true)
152
188
 
153
- resolve_legacy_endpoint(cfg)
189
+ # a default endpoint is resolved in after_initialize
190
+ nil
154
191
  end
155
192
 
156
193
  # get a custom configured endpoint from ENV or configuration
@@ -205,23 +242,6 @@ to test or custom endpoints. This should be a valid HTTP(S) URI.
205
242
  cfg.override_config(:region, new_region)
206
243
  end
207
244
  end
208
- # set a default endpoint in config using legacy (endpoints.json) resolver
209
- def resolve_legacy_endpoint(cfg)
210
- endpoint_prefix = cfg.api.metadata['endpointPrefix']
211
- if cfg.respond_to?(:sts_regional_endpoints)
212
- sts_regional = cfg.sts_regional_endpoints
213
- end
214
-
215
- Aws::Partitions::EndpointProvider.resolve(
216
- cfg.region,
217
- endpoint_prefix,
218
- sts_regional,
219
- {
220
- dualstack: cfg.use_dualstack_endpoint,
221
- fips: cfg.use_fips_endpoint
222
- }
223
- )
224
- end
225
245
  end
226
246
  end
227
247
  end
@@ -13,8 +13,7 @@ module Aws
13
13
  option(:sigv4_region)
14
14
  option(:unsigned_operations, default: [])
15
15
 
16
- supported_auth_types = %w[sigv4 bearer sigv4-s3express none]
17
- supported_auth_types += ['sigv4a'] if Aws::Sigv4::Signer.use_crt?
16
+ supported_auth_types = %w[sigv4 bearer sigv4-s3express sigv4a none]
18
17
  SUPPORTED_AUTH_TYPES = supported_auth_types.freeze
19
18
 
20
19
  def add_handlers(handlers, cfg)
@@ -42,6 +41,7 @@ module Aws
42
41
  class Handler < Seahorse::Client::Handler
43
42
  def call(context)
44
43
  # Skip signing if using sigv2 signing from s3_signer in S3
44
+ credentials = nil
45
45
  unless v2_signing?(context.config)
46
46
  signer = Sign.signer_for(
47
47
  context[:auth_scheme],
@@ -49,13 +49,20 @@ module Aws
49
49
  context[:sigv4_region],
50
50
  context[:sigv4_credentials]
51
51
  )
52
+ credentials = signer.credentials if signer.is_a?(SignatureV4)
52
53
  signer.sign(context)
53
54
  end
54
- @handler.call(context)
55
+ with_metrics(credentials) { @handler.call(context) }
55
56
  end
56
57
 
57
58
  private
58
59
 
60
+ def with_metrics(credentials, &block)
61
+ return block.call unless credentials&.respond_to?(:metrics)
62
+
63
+ Aws::Plugins::UserAgent.metric(*credentials.metrics, &block)
64
+ end
65
+
59
66
  def v2_signing?(config)
60
67
  # 's3' is legacy signing, 'v4' is default
61
68
  config.respond_to?(:signature_version) &&
@@ -93,6 +100,8 @@ module Aws
93
100
 
94
101
  # @api private
95
102
  class SignatureV4
103
+ attr_reader :signer
104
+
96
105
  def initialize(auth_scheme, config, sigv4_overrides = {})
97
106
  scheme_name = auth_scheme['name']
98
107
 
@@ -107,14 +116,14 @@ module Aws
107
116
  auth_scheme['signingRegion']
108
117
  end
109
118
  begin
110
- @signer = Aws::Sigv4::Signer.new(
119
+ @signer = config.sigv4_signer || Aws::Sigv4::Signer.new(
111
120
  service: config.sigv4_name || auth_scheme['signingName'],
112
121
  region: sigv4_overrides[:region] || config.sigv4_region || region,
113
122
  credentials_provider: sigv4_overrides[:credentials] || config.credentials,
114
123
  signing_algorithm: scheme_name.to_sym,
115
124
  uri_escape_path: !!!auth_scheme['disableDoubleEncoding'],
116
125
  normalize_path: !!!auth_scheme['disableNormalizePath'],
117
- unsigned_headers: %w[content-length user-agent x-amzn-trace-id]
126
+ unsigned_headers: %w[content-length user-agent x-amzn-trace-id expect transfer-encoding connection]
118
127
  )
119
128
  rescue Aws::Sigv4::Errors::MissingCredentialsError
120
129
  raise Aws::Errors::MissingCredentialsError
@@ -156,6 +165,10 @@ module Aws
156
165
  @signer.sign_event(*args)
157
166
  end
158
167
 
168
+ def credentials
169
+ @signer.credentials_provider
170
+ end
171
+
159
172
  private
160
173
 
161
174
  def apply_authtype(context, req)
@@ -29,8 +29,16 @@ requests are made, and retries are disabled.
29
29
  end
30
30
  end
31
31
 
32
+ option(:stubs) { {} }
33
+ option(:stubs_mutex) { Mutex.new }
34
+ option(:api_requests) { [] }
35
+ option(:api_requests_mutex) { Mutex.new }
36
+
32
37
  def add_handlers(handlers, config)
33
- handlers.add(Handler, step: :send) if config.stub_responses
38
+ return unless config.stub_responses
39
+
40
+ handlers.add(ApiRequestsHandler)
41
+ handlers.add(StubbingHandler, step: :send)
34
42
  end
35
43
 
36
44
  def after_initialize(client)
@@ -46,20 +54,43 @@ requests are made, and retries are disabled.
46
54
  end
47
55
  end
48
56
 
49
- class Handler < Seahorse::Client::Handler
57
+ class ApiRequestsHandler < Seahorse::Client::Handler
58
+ def call(context)
59
+ context.config.api_requests_mutex.synchronize do
60
+ context.config.api_requests << {
61
+ operation_name: context.operation_name,
62
+ params: context.params,
63
+ context: context
64
+ }
65
+ end
66
+ @handler.call(context)
67
+ end
68
+ end
50
69
 
70
+ class StubbingHandler < Seahorse::Client::Handler
51
71
  def call(context)
52
- stub = context.client.next_stub(context)
72
+ span_wrapper(context) do
73
+ stub_responses(context)
74
+ end
75
+ end
76
+
77
+ private
78
+
79
+ def stub_responses(context)
53
80
  resp = Seahorse::Client::Response.new(context: context)
54
81
  async_mode = context.client.is_a? Seahorse::Client::AsyncBase
55
- if Hash === stub && stub[:mutex]
56
- stub[:mutex].synchronize { apply_stub(stub, resp, async_mode) }
82
+ stub = context.client.next_stub(context)
83
+ stub[:mutex].synchronize { apply_stub(stub, resp, async_mode) }
84
+
85
+ if async_mode
86
+ Seahorse::Client::AsyncResponse.new(
87
+ context: context,
88
+ stream: context[:input_event_stream_handler].event_emitter.stream,
89
+ sync_queue: Queue.new
90
+ )
57
91
  else
58
- apply_stub(stub, resp, async_mode)
92
+ resp
59
93
  end
60
-
61
- async_mode ? Seahorse::Client::AsyncResponse.new(
62
- context: context, stream: context[:input_event_stream_handler].event_emitter.stream, sync_queue: Queue.new) : resp
63
94
  end
64
95
 
65
96
  def apply_stub(stub, response, async_mode = false)
@@ -99,6 +130,18 @@ requests are made, and retries are disabled.
99
130
  http_resp.signal_done
100
131
  end
101
132
 
133
+ def span_wrapper(context, &block)
134
+ context.tracer.in_span(
135
+ 'Handler.StubResponses',
136
+ attributes: Aws::Telemetry.http_request_attrs(context)
137
+ ) do |span|
138
+ block.call.tap do
139
+ span.add_attributes(
140
+ Aws::Telemetry.http_response_attrs(context)
141
+ )
142
+ end
143
+ end
144
+ end
102
145
  end
103
146
  end
104
147
  end
@@ -0,0 +1,75 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Aws
4
+ module Plugins
5
+ # @api private
6
+ class Telemetry < Seahorse::Client::Plugin
7
+ option(
8
+ :telemetry_provider,
9
+ default: Aws::Telemetry::NoOpTelemetryProvider,
10
+ doc_type: Aws::Telemetry::TelemetryProviderBase,
11
+ rbs_type: Aws::Telemetry::TelemetryProviderBase,
12
+ docstring: <<-DOCS) do |_cfg|
13
+ Allows you to provide a telemetry provider, which is used to
14
+ emit telemetry data. By default, uses `NoOpTelemetryProvider` which
15
+ will not record or emit any telemetry data. The SDK supports the
16
+ following telemetry providers:
17
+
18
+ * OpenTelemetry (OTel) - To use the OTel provider, install and require the
19
+ `opentelemetry-sdk` gem and then, pass in an instance of a
20
+ `Aws::Telemetry::OTelProvider` for telemetry provider.
21
+ DOCS
22
+ Aws::Telemetry::NoOpTelemetryProvider.new
23
+ end
24
+
25
+ def after_initialize(client)
26
+ validate_telemetry_provider(client.config)
27
+ end
28
+
29
+ def validate_telemetry_provider(config)
30
+ unless config.telemetry_provider.is_a?(Aws::Telemetry::TelemetryProviderBase)
31
+ raise ArgumentError,
32
+ 'Must provide a telemetry provider for the '\
33
+ '`telemetry_provider` configuration option.'
34
+ end
35
+ end
36
+
37
+ class Handler < Seahorse::Client::Handler
38
+ def call(context)
39
+ span_wrapper(context) { @handler.call(context) }
40
+ end
41
+
42
+ private
43
+
44
+ def span_wrapper(context, &block)
45
+ service_id = service_id(context)
46
+ attributes = {
47
+ 'rpc.system' => 'aws-api',
48
+ 'rpc.service' => service_id,
49
+ 'rpc.method' => context.operation.name,
50
+ 'code.function' => context.operation_name.to_s,
51
+ 'code.namespace' => 'Aws::Plugins::Telemetry'
52
+ }
53
+ context.tracer.in_span(
54
+ parent_span_name(context, service_id),
55
+ attributes: attributes,
56
+ kind: Aws::Telemetry::SpanKind::CLIENT,
57
+ &block
58
+ )
59
+ end
60
+
61
+ def service_id(context)
62
+ context.config.api.metadata['serviceId'] ||
63
+ context.config.api.metadata['serviceAbbreviation'] ||
64
+ context.config.api.metadata['serviceFullName']
65
+ end
66
+
67
+ def parent_span_name(context, service_id)
68
+ "#{service_id}.#{context.operation.name}".delete(' ')
69
+ end
70
+ end
71
+
72
+ handler(Handler, step: :initialize, priority: 99)
73
+ end
74
+ end
75
+ end
@@ -17,7 +17,44 @@ module Aws
17
17
  "S3_CRYPTO_V2": "I",
18
18
  "S3_EXPRESS_BUCKET": "J",
19
19
  "S3_ACCESS_GRANTS": "K",
20
- "GZIP_REQUEST_COMPRESSION": "L"
20
+ "GZIP_REQUEST_COMPRESSION": "L",
21
+ "PROTOCOL_RPC_V2_CBOR": "M",
22
+ "ENDPOINT_OVERRIDE": "N",
23
+ "ACCOUNT_ID_ENDPOINT": "O",
24
+ "ACCOUNT_ID_MODE_PREFERRED": "P",
25
+ "ACCOUNT_ID_MODE_DISABLED": "Q",
26
+ "ACCOUNT_ID_MODE_REQUIRED": "R",
27
+ "SIGV4A_SIGNING": "S",
28
+ "RESOLVED_ACCOUNT_ID": "T",
29
+ "FLEXIBLE_CHECKSUMS_REQ_CRC32" : "U",
30
+ "FLEXIBLE_CHECKSUMS_REQ_CRC32C" : "V",
31
+ "FLEXIBLE_CHECKSUMS_REQ_CRC64" : "W",
32
+ "FLEXIBLE_CHECKSUMS_REQ_SHA1" : "X",
33
+ "FLEXIBLE_CHECKSUMS_REQ_SHA256" : "Y",
34
+ "FLEXIBLE_CHECKSUMS_REQ_WHEN_SUPPORTED" : "Z",
35
+ "FLEXIBLE_CHECKSUMS_REQ_WHEN_REQUIRED" : "a",
36
+ "FLEXIBLE_CHECKSUMS_RES_WHEN_SUPPORTED" : "b",
37
+ "FLEXIBLE_CHECKSUMS_RES_WHEN_REQUIRED" : "c",
38
+ "DDB_MAPPER": "d",
39
+ "CREDENTIALS_CODE" : "e",
40
+ "CREDENTIALS_ENV_VARS" : "g",
41
+ "CREDENTIALS_ENV_VARS_STS_WEB_ID_TOKEN" : "h",
42
+ "CREDENTIALS_STS_ASSUME_ROLE" : "i",
43
+ "CREDENTIALS_STS_ASSUME_ROLE_WEB_ID" : "k",
44
+ "CREDENTIALS_PROFILE" : "n",
45
+ "CREDENTIALS_PROFILE_SOURCE_PROFILE" : "o",
46
+ "CREDENTIALS_PROFILE_NAMED_PROVIDER" : "p",
47
+ "CREDENTIALS_PROFILE_STS_WEB_ID_TOKEN" : "q",
48
+ "CREDENTIALS_PROFILE_SSO" : "r",
49
+ "CREDENTIALS_SSO" : "s",
50
+ "CREDENTIALS_PROFILE_SSO_LEGACY" : "t",
51
+ "CREDENTIALS_SSO_LEGACY" : "u",
52
+ "CREDENTIALS_PROFILE_PROCESS" : "v",
53
+ "CREDENTIALS_PROCESS" : "w",
54
+ "CREDENTIALS_HTTP" : "z",
55
+ "CREDENTIALS_IMDS" : "0",
56
+ "SSO_LOGIN_DEVICE" : "1",
57
+ "SSO_LOGIN_AUTH" : "2"
21
58
  }
22
59
  METRICS
23
60
 
@@ -45,15 +82,13 @@ variable AWS_SDK_UA_APP_ID or the shared config profile attribute sdk_ua_app_id.
45
82
  block.call
46
83
  end
47
84
 
48
- def self.metric(metric, &block)
85
+ def self.metric(*metrics, &block)
49
86
  Thread.current[:aws_sdk_core_user_agent_metric] ||= []
50
- Thread.current[:aws_sdk_core_user_agent_metric] << METRICS[metric]
87
+ metrics = metrics.map { |metric| METRICS[metric] }.compact
88
+ Thread.current[:aws_sdk_core_user_agent_metric].concat(metrics)
51
89
  block.call
52
90
  ensure
53
- Thread.current[:aws_sdk_core_user_agent_metric].pop
54
- if Thread.current[:aws_sdk_core_user_agent_metric].empty?
55
- Thread.current[:aws_sdk_core_user_agent_metric] = nil
56
- end
91
+ Thread.current[:aws_sdk_core_user_agent_metric].pop(metrics.size)
57
92
  end
58
93
 
59
94
  # @api private
@@ -166,7 +201,10 @@ variable AWS_SDK_UA_APP_ID or the shared config profile attribute sdk_ua_app_id.
166
201
  end
167
202
 
168
203
  def metric_metadata
169
- return unless Thread.current[:aws_sdk_core_user_agent_metric]
204
+ if Thread.current[:aws_sdk_core_user_agent_metric].nil? ||
205
+ Thread.current[:aws_sdk_core_user_agent_metric].empty?
206
+ return
207
+ end
170
208
 
171
209
  metrics = Thread.current[:aws_sdk_core_user_agent_metric].join(',')
172
210
  # Metric metadata is limited to 1024 bytes
@@ -178,7 +216,8 @@ variable AWS_SDK_UA_APP_ID or the shared config profile attribute sdk_ua_app_id.
178
216
  end
179
217
  end
180
218
 
181
- handler(Handler, step: :sign, priority: 97)
219
+ # Priority set to 5 in order to add user agent as late as possible after signing
220
+ handler(Handler, step: :sign, priority: 5)
182
221
  end
183
222
  end
184
223
  end
@@ -0,0 +1,39 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Aws
4
+ # setup autoloading for Plugins
5
+ # Most plugins are required explicitly from service clients
6
+ # but users may reference them outside of client usage.
7
+ module Plugins
8
+ autoload :ApiKey, 'aws-sdk-core/plugins/api_key'
9
+ autoload :BearerAuthorization, 'aws-sdk-core/plugins/bearer_authorization'
10
+ autoload :ChecksumAlgorithm, 'aws-sdk-core/plugins/checksum_algorithm'
11
+ autoload :ClientMetricsPlugin, 'aws-sdk-core/plugins/client_metrics_plugin'
12
+ autoload :ClientMetricsSendPlugin, 'aws-sdk-core/plugins/client_metrics_send_plugin'
13
+ autoload :CredentialsConfiguration, 'aws-sdk-core/plugins/credentials_configuration'
14
+ autoload :DefaultsMode, 'aws-sdk-core/plugins/defaults_mode'
15
+ autoload :EndpointDiscovery, 'aws-sdk-core/plugins/endpoint_discovery'
16
+ autoload :EndpointPattern, 'aws-sdk-core/plugins/endpoint_pattern'
17
+ autoload :EventStreamConfiguration, 'aws-sdk-core/plugins/event_stream_configuration'
18
+ autoload :GlobalConfiguration, 'aws-sdk-core/plugins/global_configuration'
19
+ autoload :HelpfulSocketErrors, 'aws-sdk-core/plugins/helpful_socket_errors'
20
+ autoload :HttpChecksum, 'aws-sdk-core/plugins/http_checksum'
21
+ autoload :IdempotencyToken, 'aws-sdk-core/plugins/idempotency_token'
22
+ autoload :InvocationId, 'aws-sdk-core/plugins/invocation_id'
23
+ autoload :JsonvalueConverter, 'aws-sdk-core/plugins/jsonvalue_converter'
24
+ autoload :Logging, 'aws-sdk-core/plugins/logging'
25
+ autoload :ParamConverter, 'aws-sdk-core/plugins/param_converter'
26
+ autoload :ParamValidator, 'aws-sdk-core/plugins/param_validator'
27
+ autoload :RecursionDetection, 'aws-sdk-core/plugins/recursion_detection'
28
+ autoload :RegionalEndpoint, 'aws-sdk-core/plugins/regional_endpoint'
29
+ autoload :RequestCompression, 'aws-sdk-core/plugins/request_compression'
30
+ autoload :ResponsePaging, 'aws-sdk-core/plugins/response_paging'
31
+ autoload :RetryErrors, 'aws-sdk-core/plugins/retry_errors'
32
+ autoload :Sign, 'aws-sdk-core/plugins/sign'
33
+ autoload :SignatureV4, 'aws-sdk-core/plugins/signature_v4'
34
+ autoload :StubResponses, 'aws-sdk-core/plugins/stub_responses'
35
+ autoload :Telemetry, 'aws-sdk-core/plugins/telemetry'
36
+ autoload :TransferEncoding, 'aws-sdk-core/plugins/transfer_encoding'
37
+ autoload :UserAgent, 'aws-sdk-core/plugins/user_agent'
38
+ end
39
+ end
@@ -36,7 +36,7 @@ module Aws
36
36
  @process = process
37
37
  @credentials = credentials_from_process
38
38
  @async_refresh = false
39
-
39
+ @metrics = ['CREDENTIALS_PROCESS']
40
40
  super
41
41
  end
42
42
 
@@ -74,7 +74,8 @@ module Aws
74
74
  creds = Credentials.new(
75
75
  creds_json['AccessKeyId'],
76
76
  creds_json['SecretAccessKey'],
77
- creds_json['SessionToken']
77
+ creds_json['SessionToken'],
78
+ account_id: creds_json['AccountId']
78
79
  )
79
80
 
80
81
  @expiration = creds_json['Expiration'] ? Time.iso8601(creds_json['Expiration']) : nil
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Aws
4
+ # setup autoloading for Resources module
5
+ module Resources
6
+ autoload :Collection, 'aws-sdk-core/resources/collection'
7
+ end
8
+ end