aws-sdk-core 3.121.1 → 3.174.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (112) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +491 -0
  3. data/VERSION +1 -1
  4. data/lib/aws-defaults/default_configuration.rb +153 -0
  5. data/lib/aws-defaults/defaults_mode_config_resolver.rb +107 -0
  6. data/lib/aws-defaults.rb +3 -0
  7. data/lib/aws-sdk-core/arn.rb +13 -0
  8. data/lib/aws-sdk-core/assume_role_credentials.rb +21 -7
  9. data/lib/aws-sdk-core/assume_role_web_identity_credentials.rb +14 -10
  10. data/lib/aws-sdk-core/binary/encode_handler.rb +12 -1
  11. data/lib/aws-sdk-core/client_stubs.rb +5 -1
  12. data/lib/aws-sdk-core/credential_provider_chain.rb +8 -5
  13. data/lib/aws-sdk-core/ec2_metadata.rb +3 -2
  14. data/lib/aws-sdk-core/ecs_credentials.rb +121 -53
  15. data/lib/aws-sdk-core/endpoints/condition.rb +41 -0
  16. data/lib/aws-sdk-core/endpoints/endpoint.rb +17 -0
  17. data/lib/aws-sdk-core/endpoints/endpoint_rule.rb +75 -0
  18. data/lib/aws-sdk-core/endpoints/error_rule.rb +42 -0
  19. data/lib/aws-sdk-core/endpoints/function.rb +80 -0
  20. data/lib/aws-sdk-core/endpoints/matchers.rb +127 -0
  21. data/lib/aws-sdk-core/endpoints/reference.rb +31 -0
  22. data/lib/aws-sdk-core/endpoints/rule.rb +25 -0
  23. data/lib/aws-sdk-core/endpoints/rule_set.rb +52 -0
  24. data/lib/aws-sdk-core/endpoints/rules_provider.rb +37 -0
  25. data/lib/aws-sdk-core/endpoints/templater.rb +58 -0
  26. data/lib/aws-sdk-core/endpoints/tree_rule.rb +45 -0
  27. data/lib/aws-sdk-core/endpoints/url.rb +60 -0
  28. data/lib/aws-sdk-core/endpoints.rb +74 -0
  29. data/lib/aws-sdk-core/errors.rb +14 -1
  30. data/lib/aws-sdk-core/instance_profile_credentials.rb +85 -14
  31. data/lib/aws-sdk-core/json/error_handler.rb +20 -1
  32. data/lib/aws-sdk-core/log/formatter.rb +6 -0
  33. data/lib/aws-sdk-core/pageable_response.rb +81 -32
  34. data/lib/aws-sdk-core/plugins/bearer_authorization.rb +67 -0
  35. data/lib/aws-sdk-core/plugins/checksum_algorithm.rb +340 -0
  36. data/lib/aws-sdk-core/plugins/credentials_configuration.rb +27 -1
  37. data/lib/aws-sdk-core/plugins/defaults_mode.rb +40 -0
  38. data/lib/aws-sdk-core/plugins/endpoint_discovery.rb +6 -2
  39. data/lib/aws-sdk-core/plugins/http_checksum.rb +8 -1
  40. data/lib/aws-sdk-core/plugins/jsonvalue_converter.rb +34 -6
  41. data/lib/aws-sdk-core/plugins/protocols/api_gateway.rb +17 -0
  42. data/lib/aws-sdk-core/plugins/protocols/rest_json.rb +16 -1
  43. data/lib/aws-sdk-core/plugins/recursion_detection.rb +38 -0
  44. data/lib/aws-sdk-core/plugins/regional_endpoint.rb +52 -1
  45. data/lib/aws-sdk-core/plugins/response_paging.rb +1 -1
  46. data/lib/aws-sdk-core/plugins/retries/error_inspector.rb +7 -4
  47. data/lib/aws-sdk-core/plugins/retry_errors.rb +21 -5
  48. data/lib/aws-sdk-core/plugins/sign.rb +200 -0
  49. data/lib/aws-sdk-core/plugins/signature_v2.rb +1 -0
  50. data/lib/aws-sdk-core/plugins/signature_v4.rb +28 -31
  51. data/lib/aws-sdk-core/plugins/stub_responses.rb +5 -1
  52. data/lib/aws-sdk-core/plugins/user_agent.rb +117 -14
  53. data/lib/aws-sdk-core/process_credentials.rb +9 -11
  54. data/lib/aws-sdk-core/refreshing_credentials.rb +42 -11
  55. data/lib/aws-sdk-core/refreshing_token.rb +71 -0
  56. data/lib/aws-sdk-core/rest/handler.rb +1 -1
  57. data/lib/aws-sdk-core/rest/request/body.rb +19 -1
  58. data/lib/aws-sdk-core/rest/request/headers.rb +14 -6
  59. data/lib/aws-sdk-core/rest/response/headers.rb +3 -1
  60. data/lib/aws-sdk-core/shared_config.rb +82 -12
  61. data/lib/aws-sdk-core/sso_credentials.rb +91 -50
  62. data/lib/aws-sdk-core/sso_token_provider.rb +135 -0
  63. data/lib/aws-sdk-core/static_token_provider.rb +14 -0
  64. data/lib/aws-sdk-core/structure.rb +6 -4
  65. data/lib/aws-sdk-core/token.rb +31 -0
  66. data/lib/aws-sdk-core/token_provider.rb +15 -0
  67. data/lib/aws-sdk-core/token_provider_chain.rb +51 -0
  68. data/lib/aws-sdk-core/waiters/poller.rb +3 -1
  69. data/lib/aws-sdk-core/xml/error_handler.rb +7 -0
  70. data/lib/aws-sdk-core/xml/parser/engines/oga.rb +2 -0
  71. data/lib/aws-sdk-core/xml/parser/engines/ox.rb +1 -1
  72. data/lib/aws-sdk-core.rb +20 -0
  73. data/lib/aws-sdk-sso/client.rb +82 -15
  74. data/lib/aws-sdk-sso/endpoint_parameters.rb +66 -0
  75. data/lib/aws-sdk-sso/endpoint_provider.rb +51 -0
  76. data/lib/aws-sdk-sso/endpoints.rb +71 -0
  77. data/lib/aws-sdk-sso/plugins/endpoints.rb +76 -0
  78. data/lib/aws-sdk-sso/types.rb +8 -43
  79. data/lib/aws-sdk-sso.rb +5 -1
  80. data/lib/aws-sdk-ssooidc/client.rb +611 -0
  81. data/lib/aws-sdk-ssooidc/client_api.rb +216 -0
  82. data/lib/aws-sdk-ssooidc/customizations.rb +1 -0
  83. data/lib/aws-sdk-ssooidc/endpoint_parameters.rb +66 -0
  84. data/lib/aws-sdk-ssooidc/endpoint_provider.rb +51 -0
  85. data/lib/aws-sdk-ssooidc/endpoints.rb +57 -0
  86. data/lib/aws-sdk-ssooidc/errors.rb +290 -0
  87. data/lib/aws-sdk-ssooidc/plugins/endpoints.rb +74 -0
  88. data/lib/aws-sdk-ssooidc/resource.rb +26 -0
  89. data/lib/aws-sdk-ssooidc/types.rb +502 -0
  90. data/lib/aws-sdk-ssooidc.rb +59 -0
  91. data/lib/aws-sdk-sts/client.rb +377 -361
  92. data/lib/aws-sdk-sts/endpoint_parameters.rb +78 -0
  93. data/lib/aws-sdk-sts/endpoint_provider.rb +112 -0
  94. data/lib/aws-sdk-sts/endpoints.rb +135 -0
  95. data/lib/aws-sdk-sts/plugins/endpoints.rb +84 -0
  96. data/lib/aws-sdk-sts/plugins/sts_regional_endpoints.rb +5 -1
  97. data/lib/aws-sdk-sts/presigner.rb +13 -9
  98. data/lib/aws-sdk-sts/types.rb +127 -225
  99. data/lib/aws-sdk-sts.rb +5 -1
  100. data/lib/seahorse/client/async_base.rb +0 -1
  101. data/lib/seahorse/client/configuration.rb +6 -2
  102. data/lib/seahorse/client/h2/connection.rb +12 -11
  103. data/lib/seahorse/client/net_http/connection_pool.rb +7 -0
  104. data/lib/seahorse/client/net_http/handler.rb +15 -7
  105. data/lib/seahorse/client/net_http/patches.rb +16 -0
  106. data/lib/seahorse/client/plugins/content_length.rb +11 -5
  107. data/lib/seahorse/client/plugins/net_http.rb +33 -2
  108. data/lib/seahorse/client/plugins/request_callback.rb +9 -9
  109. data/lib/seahorse/model/operation.rb +3 -0
  110. data/lib/seahorse/util.rb +4 -0
  111. metadata +61 -9
  112. data/lib/aws-sdk-sso/plugins/content_type.rb +0 -25
@@ -10,7 +10,7 @@ module Aws
10
10
  def call(context)
11
11
  context[:original_params] = context.params
12
12
  resp = @handler.call(context)
13
- resp.extend(PageableResponse)
13
+ PageableResponse.apply(resp)
14
14
  resp.pager = context.operation[:pager] || Aws::Pager::NullPager.new
15
15
  resp
16
16
  end
@@ -13,7 +13,8 @@ module Aws
13
13
  'InvalidAccessKeyId', # s3
14
14
  'AuthFailure', # ec2
15
15
  'InvalidIdentityToken', # sts
16
- 'ExpiredToken' # route53
16
+ 'ExpiredToken', # route53
17
+ 'ExpiredTokenException' # kinesis
17
18
  ]
18
19
  )
19
20
 
@@ -38,13 +39,15 @@ module Aws
38
39
 
39
40
  CHECKSUM_ERRORS = Set.new(
40
41
  [
41
- 'CRC32CheckFailed' # dynamodb
42
+ 'CRC32CheckFailed', # dynamodb
43
+ 'BadDigest' # s3
42
44
  ]
43
45
  )
44
46
 
45
47
  NETWORKING_ERRORS = Set.new(
46
48
  [
47
49
  'RequestTimeout', # s3
50
+ 'InternalError', # s3
48
51
  'RequestTimeoutException', # glacier
49
52
  'IDPCommunicationError' # sts
50
53
  ]
@@ -80,7 +83,7 @@ module Aws
80
83
  end
81
84
 
82
85
  def checksum?
83
- CHECKSUM_ERRORS.include?(@name) || @error.is_a?(Errors::ChecksumError)
86
+ CHECKSUM_ERRORS.include?(@name)
84
87
  end
85
88
 
86
89
  def networking?
@@ -141,4 +144,4 @@ module Aws
141
144
  end
142
145
  end
143
146
  end
144
- end
147
+ end
@@ -163,9 +163,15 @@ a clock skew correction and retry requests with skewed client clocks.
163
163
  option(:clock_skew) { Retries::ClockSkew.new }
164
164
 
165
165
  def self.resolve_retry_mode(cfg)
166
- value = ENV['AWS_RETRY_MODE'] ||
167
- Aws.shared_config.retry_mode(profile: cfg.profile) ||
168
- 'legacy'
166
+ default_mode_value =
167
+ if cfg.respond_to?(:defaults_mode_config_resolver)
168
+ cfg.defaults_mode_config_resolver.resolve(:retry_mode)
169
+ end
170
+
171
+ value = ENV['AWS_RETRY_MODE'] ||
172
+ Aws.shared_config.retry_mode(profile: cfg.profile) ||
173
+ default_mode_value ||
174
+ 'legacy'
169
175
  # Raise if provided value is not one of the retry modes
170
176
  if value != 'legacy' && value != 'standard' && value != 'adaptive'
171
177
  raise ArgumentError,
@@ -307,12 +313,17 @@ a clock skew correction and retry requests with skewed client clocks.
307
313
 
308
314
  def retry_request(context, error)
309
315
  context.retries += 1
310
- context.config.credentials.refresh! if error.expired_credentials?
316
+ context.config.credentials.refresh! if refresh_credentials?(context, error)
311
317
  context.http_request.body.rewind
312
318
  context.http_response.reset
313
319
  call(context)
314
320
  end
315
321
 
322
+ def refresh_credentials?(context, error)
323
+ error.expired_credentials? &&
324
+ context.config.credentials.respond_to?(:refresh!)
325
+ end
326
+
316
327
  def add_retry_headers(context)
317
328
  request_pairs = {
318
329
  'attempt' => context.retries,
@@ -377,7 +388,7 @@ a clock skew correction and retry requests with skewed client clocks.
377
388
  def retry_request(context, error)
378
389
  delay_retry(context)
379
390
  context.retries += 1
380
- context.config.credentials.refresh! if error.expired_credentials?
391
+ context.config.credentials.refresh! if refresh_credentials?(context, error)
381
392
  context.http_request.body.rewind
382
393
  context.http_response.reset
383
394
  call(context)
@@ -393,6 +404,11 @@ a clock skew correction and retry requests with skewed client clocks.
393
404
  response_truncatable?(context)
394
405
  end
395
406
 
407
+ def refresh_credentials?(context, error)
408
+ error.expired_credentials? &&
409
+ context.config.credentials.respond_to?(:refresh!)
410
+ end
411
+
396
412
  def retry_limit(context)
397
413
  context.config.retry_limit
398
414
  end
@@ -0,0 +1,200 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'aws-sigv4'
4
+
5
+ module Aws
6
+ module Plugins
7
+ # @api private
8
+ class Sign < Seahorse::Client::Plugin
9
+ # These once had defaults. But now they are used as overrides to
10
+ # new endpoint and auth resolution.
11
+ option(:sigv4_signer)
12
+ option(:sigv4_name)
13
+ option(:sigv4_region)
14
+ option(:unsigned_operations, default: [])
15
+
16
+ supported_auth_types = %w[sigv4 bearer none]
17
+ supported_auth_types += ['sigv4a'] if Aws::Sigv4::Signer.use_crt?
18
+ SUPPORTED_AUTH_TYPES = supported_auth_types.freeze
19
+
20
+ def add_handlers(handlers, cfg)
21
+ operations = cfg.api.operation_names - cfg.unsigned_operations
22
+ handlers.add(Handler, step: :sign, operations: operations)
23
+ end
24
+
25
+ # @api private
26
+ # Return a signer with the `sign(context)` method
27
+ def self.signer_for(auth_scheme, config, region_override = nil)
28
+ case auth_scheme['name']
29
+ when 'sigv4', 'sigv4a'
30
+ SignatureV4.new(auth_scheme, config, region_override)
31
+ when 'bearer'
32
+ Bearer.new
33
+ else
34
+ NullSigner.new
35
+ end
36
+ end
37
+
38
+ class Handler < Seahorse::Client::Handler
39
+ def call(context)
40
+ # Skip signing if using sigv2 signing from s3_signer in S3
41
+ unless v2_signing?(context.config)
42
+ signer = Sign.signer_for(
43
+ context[:auth_scheme],
44
+ context.config,
45
+ context[:sigv4_region]
46
+ )
47
+ signer.sign(context)
48
+ end
49
+ @handler.call(context)
50
+ end
51
+
52
+ private
53
+
54
+ def v2_signing?(config)
55
+ # 's3' is legacy signing, 'v4' is default
56
+ config.respond_to?(:signature_version) &&
57
+ config.signature_version == 's3'
58
+ end
59
+ end
60
+
61
+ # @api private
62
+ class Bearer
63
+ def initialize
64
+ end
65
+
66
+ def sign(context)
67
+ if context.http_request.endpoint.scheme != 'https'
68
+ raise ArgumentError,
69
+ 'Unable to use bearer authorization on non https endpoint.'
70
+ end
71
+
72
+ token_provider = context.config.token_provider
73
+
74
+ raise Errors::MissingBearerTokenError unless token_provider&.set?
75
+
76
+ context.http_request.headers['Authorization'] =
77
+ "Bearer #{token_provider.token.token}"
78
+ end
79
+
80
+ def presign_url(*args)
81
+ raise ArgumentError, 'Bearer auth does not support presigned urls'
82
+ end
83
+
84
+ def sign_event(*args)
85
+ raise ArgumentError, 'Bearer auth does not support event signing'
86
+ end
87
+ end
88
+
89
+ # @api private
90
+ class SignatureV4
91
+ def initialize(auth_scheme, config, region_override = nil)
92
+ scheme_name = auth_scheme['name']
93
+
94
+ unless %w[sigv4 sigv4a].include?(scheme_name)
95
+ raise ArgumentError,
96
+ "Expected sigv4 or sigv4a auth scheme, got #{scheme_name}"
97
+ end
98
+
99
+ region = if scheme_name == 'sigv4a'
100
+ auth_scheme['signingRegionSet'].first
101
+ else
102
+ auth_scheme['signingRegion']
103
+ end
104
+ begin
105
+ @signer = Aws::Sigv4::Signer.new(
106
+ service: config.sigv4_name || auth_scheme['signingName'],
107
+ region: region_override || config.sigv4_region || region,
108
+ credentials_provider: config.credentials,
109
+ signing_algorithm: scheme_name.to_sym,
110
+ uri_escape_path: !!!auth_scheme['disableDoubleEncoding'],
111
+ unsigned_headers: %w[content-length user-agent x-amzn-trace-id]
112
+ )
113
+ rescue Aws::Sigv4::Errors::MissingCredentialsError
114
+ raise Aws::Errors::MissingCredentialsError
115
+ end
116
+ end
117
+
118
+ def sign(context)
119
+ req = context.http_request
120
+
121
+ apply_authtype(context, req)
122
+ reset_signature(req)
123
+ apply_clock_skew(context, req)
124
+
125
+ # compute the signature
126
+ begin
127
+ signature = @signer.sign_request(
128
+ http_method: req.http_method,
129
+ url: req.endpoint,
130
+ headers: req.headers,
131
+ body: req.body
132
+ )
133
+ rescue Aws::Sigv4::Errors::MissingCredentialsError
134
+ # Necessary for when credentials is explicitly set to nil
135
+ raise Aws::Errors::MissingCredentialsError
136
+ end
137
+ # apply signature headers
138
+ req.headers.update(signature.headers)
139
+
140
+ # add request metadata with signature components for debugging
141
+ context[:canonical_request] = signature.canonical_request
142
+ context[:string_to_sign] = signature.string_to_sign
143
+ end
144
+
145
+ def presign_url(*args)
146
+ @signer.presign_url(*args)
147
+ end
148
+
149
+ def sign_event(*args)
150
+ @signer.sign_event(*args)
151
+ end
152
+
153
+ private
154
+
155
+ def apply_authtype(context, req)
156
+ if context.operation['authtype'].eql?('v4-unsigned-body') &&
157
+ req.endpoint.scheme.eql?('https')
158
+ req.headers['X-Amz-Content-Sha256'] ||= 'UNSIGNED-PAYLOAD'
159
+ end
160
+ end
161
+
162
+ def reset_signature(req)
163
+ # in case this request is being re-signed
164
+ req.headers.delete('Authorization')
165
+ req.headers.delete('X-Amz-Security-Token')
166
+ req.headers.delete('X-Amz-Date')
167
+ req.headers.delete('x-Amz-Region-Set')
168
+ end
169
+
170
+ def apply_clock_skew(context, req)
171
+ if context.config.respond_to?(:clock_skew) &&
172
+ context.config.clock_skew &&
173
+ context.config.correct_clock_skew
174
+
175
+ endpoint = context.http_request.endpoint
176
+ skew = context.config.clock_skew.clock_correction(endpoint)
177
+ if skew.abs.positive?
178
+ req.headers['X-Amz-Date'] =
179
+ (Time.now.utc + skew).strftime('%Y%m%dT%H%M%SZ')
180
+ end
181
+ end
182
+ end
183
+
184
+ end
185
+
186
+ # @api private
187
+ class NullSigner
188
+
189
+ def sign(context)
190
+ end
191
+
192
+ def presign_url(*args)
193
+ end
194
+
195
+ def sign_event(*args)
196
+ end
197
+ end
198
+ end
199
+ end
200
+ end
@@ -3,6 +3,7 @@
3
3
  module Aws
4
4
  module Plugins
5
5
  # @api private
6
+ # Necessary to keep after Endpoints 2.0
6
7
  class SignatureV2 < Seahorse::Client::Plugin
7
8
 
8
9
  option(:v2_signer) do |cfg|
@@ -5,50 +5,46 @@ require 'aws-sigv4'
5
5
  module Aws
6
6
  module Plugins
7
7
  # @api private
8
+ # Necessary to exist after endpoints 2.0
8
9
  class SignatureV4 < Seahorse::Client::Plugin
9
10
 
11
+ V4_AUTH = %w[v4 v4-unsigned-payload v4-unsigned-body]
12
+
10
13
  option(:sigv4_signer) do |cfg|
11
14
  SignatureV4.build_signer(cfg)
12
15
  end
13
16
 
14
17
  option(:sigv4_name) do |cfg|
15
- cfg.api.metadata['signingName'] || cfg.api.metadata['endpointPrefix']
18
+ signingName = if cfg.region
19
+ Aws::Partitions::EndpointProvider.signing_service(
20
+ cfg.region, cfg.api.metadata['endpointPrefix']
21
+ )
22
+ end
23
+ signingName || cfg.api.metadata['signingName'] || cfg.api.metadata['endpointPrefix']
16
24
  end
17
25
 
18
26
  option(:sigv4_region) do |cfg|
19
-
20
- # The signature version 4 signing region is most
21
- # commonly the configured region. There are a few
22
- # notable exceptions:
23
- #
24
- # * Some services have a global endpoint to the entire
25
- # partition. For example, when constructing a route53
26
- # client for a region like "us-west-2", we will
27
- # always use "route53.amazonaws.com". This endpoint
28
- # is actually global to the entire partition,
29
- # and must be signed as "us-east-1".
30
- #
31
- # * When the region is configured, but it is configured
32
- # to a non region, such as "aws-global". This is similar
33
- # to the previous case. We use the Aws::Partitions::EndpointProvider
34
- # to resolve to the actual signing region.
35
- #
36
- prefix = cfg.api.metadata['endpointPrefix']
37
- if prefix && cfg.endpoint.to_s.match(/#{prefix}\.amazonaws\.com/)
38
- 'us-east-1'
39
- elsif cfg.region
40
- Aws::Partitions::EndpointProvider.signing_region(cfg.region, cfg.sigv4_name)
27
+ if cfg.region
28
+ if cfg.respond_to?(:sts_regional_endpoints)
29
+ sts_regional = cfg.sts_regional_endpoints
30
+ end
31
+ Aws::Partitions::EndpointProvider.signing_region(
32
+ cfg.region, cfg.api.metadata['endpointPrefix'], sts_regional
33
+ )
41
34
  end
42
35
  end
43
36
 
44
37
  option(:unsigned_operations) do |cfg|
45
- cfg.api.operation_names.inject([]) do |unsigned, operation_name|
46
- if cfg.api.operation(operation_name)['authtype'] == 'none' ||
47
- cfg.api.operation(operation_name)['authtype'] == 'custom'
48
- # Unsign requests that has custom apigateway authorizer as well
49
- unsigned << operation_name
50
- else
51
- unsigned
38
+ if cfg.api.metadata['signatureVersion'] == 'v4'
39
+ # select operations where authtype is set and is not v4
40
+ cfg.api.operation_names.select do |o|
41
+ cfg.api.operation(o)['authtype'] && !V4_AUTH.include?(cfg.api.operation(o)['authtype'])
42
+ end
43
+ else # service is not v4 auth
44
+ # select all operations where authtype is not v4
45
+ # (includes operations with no explicit authtype)
46
+ cfg.api.operation_names.select do |o|
47
+ !V4_AUTH.include?(cfg.api.operation(o)['authtype'])
52
48
  end
53
49
  end
54
50
  end
@@ -108,6 +104,7 @@ module Aws
108
104
  req.headers.delete('Authorization')
109
105
  req.headers.delete('X-Amz-Security-Token')
110
106
  req.headers.delete('X-Amz-Date')
107
+ req.headers.delete('x-Amz-Region-Set')
111
108
 
112
109
  if context.config.respond_to?(:clock_skew) &&
113
110
  context.config.clock_skew &&
@@ -144,7 +141,7 @@ module Aws
144
141
  def apply_authtype(context)
145
142
  if context.operation['authtype'].eql?('v4-unsigned-body') &&
146
143
  context.http_request.endpoint.scheme.eql?('https')
147
- context.http_request.headers['X-Amz-Content-Sha256'] = 'UNSIGNED-PAYLOAD'
144
+ context.http_request.headers['X-Amz-Content-Sha256'] ||= 'UNSIGNED-PAYLOAD'
148
145
  end
149
146
  context
150
147
  end
@@ -51,7 +51,11 @@ requests are made, and retries are disabled.
51
51
  stub = context.client.next_stub(context)
52
52
  resp = Seahorse::Client::Response.new(context: context)
53
53
  async_mode = context.client.is_a? Seahorse::Client::AsyncBase
54
- apply_stub(stub, resp, async_mode)
54
+ if Hash === stub && stub[:mutex]
55
+ stub[:mutex].synchronize { apply_stub(stub, resp, async_mode) }
56
+ else
57
+ apply_stub(stub, resp, async_mode)
58
+ end
55
59
 
56
60
  async_mode ? Seahorse::Client::AsyncResponse.new(
57
61
  context: context, stream: context[:input_event_stream_handler].event_emitter.stream, sync_queue: Queue.new) : resp
@@ -4,7 +4,31 @@ module Aws
4
4
  module Plugins
5
5
  # @api private
6
6
  class UserAgent < Seahorse::Client::Plugin
7
+ # @api private
7
8
  option(:user_agent_suffix)
9
+ # @api private
10
+ option(:user_agent_frameworks, default: [])
11
+
12
+ option(
13
+ :sdk_ua_app_id,
14
+ doc_type: 'String',
15
+ docstring: <<-DOCS) do |cfg|
16
+ A unique and opaque application ID that is appended to the
17
+ User-Agent header as app/<sdk_ua_app_id>. It should have a
18
+ maximum length of 50.
19
+ DOCS
20
+ app_id = ENV['AWS_SDK_UA_APP_ID']
21
+ app_id ||= Aws.shared_config.sdk_ua_app_id(profile: cfg.profile)
22
+ app_id
23
+ end
24
+
25
+ def self.feature(feature, &block)
26
+ Thread.current[:aws_sdk_core_user_agent_feature] ||= []
27
+ Thread.current[:aws_sdk_core_user_agent_feature] << "ft/#{feature}"
28
+ block.call
29
+ ensure
30
+ Thread.current[:aws_sdk_core_user_agent_feature].pop
31
+ end
8
32
 
9
33
  # @api private
10
34
  class Handler < Seahorse::Client::Handler
@@ -14,33 +38,112 @@ module Aws
14
38
  end
15
39
 
16
40
  def set_user_agent(context)
17
- ua = "aws-sdk-ruby3/#{CORE_GEM_VERSION}"
41
+ context.http_request.headers['User-Agent'] = UserAgent.new(context).to_s
42
+ end
43
+
44
+ class UserAgent
45
+ def initialize(context)
46
+ @context = context
47
+ end
48
+
49
+ def to_s
50
+ ua = "aws-sdk-ruby3/#{CORE_GEM_VERSION}"
51
+ ua += ' ua/2.0'
52
+ ua += " #{api_metadata}" if api_metadata
53
+ ua += " #{os_metadata}"
54
+ ua += " #{language_metadata}"
55
+ ua += " #{env_metadata}" if env_metadata
56
+ ua += " #{config_metadata}" if config_metadata
57
+ ua += " #{app_id}" if app_id
58
+ ua += " #{feature_metadata}" if feature_metadata
59
+ ua += " #{framework_metadata}" if framework_metadata
60
+ if @context.config.user_agent_suffix
61
+ ua += " #{@context.config.user_agent_suffix}"
62
+ end
63
+ ua.strip
64
+ end
65
+
66
+ private
18
67
 
19
- begin
20
- ua += " #{RUBY_ENGINE}/#{RUBY_VERSION}"
21
- rescue
22
- ua += " RUBY_ENGINE_NA/#{RUBY_VERSION}"
68
+ # Used to be gem_name/gem_version
69
+ def api_metadata
70
+ service_id = @context.config.api.metadata['serviceId']
71
+ return unless service_id
72
+
73
+ service_id = service_id.gsub(' ', '_').downcase
74
+ gem_version = @context[:gem_version]
75
+ "api/#{service_id}##{gem_version}"
76
+ end
77
+
78
+ # Used to be RUBY_PLATFORM
79
+ def os_metadata
80
+ os =
81
+ case RbConfig::CONFIG['host_os']
82
+ when /mac|darwin/
83
+ 'macos'
84
+ when /linux|cygwin/
85
+ 'linux'
86
+ when /mingw|mswin/
87
+ 'windows'
88
+ else
89
+ 'other'
90
+ end
91
+ metadata = "os/#{os}"
92
+ local_version = Gem::Platform.local.version
93
+ metadata += "##{local_version}" if local_version
94
+ metadata += " md/#{RbConfig::CONFIG['host_cpu']}"
95
+ metadata
23
96
  end
24
97
 
25
- ua += " #{RUBY_PLATFORM}"
98
+ # Used to be RUBY_ENGINE/RUBY_VERSION
99
+ def language_metadata
100
+ "lang/#{RUBY_ENGINE}##{RUBY_ENGINE_VERSION} md/#{RUBY_VERSION}"
101
+ end
102
+
103
+ def env_metadata
104
+ return unless (execution_env = ENV['AWS_EXECUTION_ENV'])
105
+
106
+ "exec-env/#{execution_env}"
107
+ end
26
108
 
27
- if context[:gem_name] && context[:gem_version]
28
- ua += " #{context[:gem_name]}/#{context[:gem_version]}"
109
+ def config_metadata
110
+ "cfg/retry-mode##{@context.config.retry_mode}"
29
111
  end
30
112
 
31
- if (execution_env = ENV['AWS_EXECUTION_ENV'])
32
- ua += " exec-env/#{execution_env}"
113
+ def app_id
114
+ return unless (app_id = @context.config.sdk_ua_app_id)
115
+
116
+ # Sanitize and only allow these characters
117
+ app_id = app_id.gsub(/[^!#$%&'*+\-.^_`|~0-9A-Za-z]/, '-')
118
+ "app/#{app_id}"
33
119
  end
34
120
 
35
- if context.config.user_agent_suffix
36
- ua += " #{context.config.user_agent_suffix}"
121
+ def feature_metadata
122
+ return unless Thread.current[:aws_sdk_core_user_agent_feature]
123
+
124
+ Thread.current[:aws_sdk_core_user_agent_feature].join(' ')
37
125
  end
38
126
 
39
- context.http_request.headers['User-Agent'] = ua.strip
127
+ def framework_metadata
128
+ if (frameworks_cfg = @context.config.user_agent_frameworks).empty?
129
+ return
130
+ end
131
+
132
+ # Frameworks may be aws-record, aws-sdk-rails, etc.
133
+ regex = /gems\/(?<name>#{frameworks_cfg.join('|')})-(?<version>\d+\.\d+\.\d+)/.freeze
134
+ frameworks = {}
135
+ Kernel.caller.each do |line|
136
+ match = line.match(regex)
137
+ next unless match
138
+
139
+ frameworks[match[:name]] = match[:version]
140
+ end
141
+ frameworks.map { |n, v| "lib/#{n}##{v}" }.join(' ')
142
+ end
40
143
  end
41
144
  end
42
145
 
43
- handler(Handler)
146
+ handler(Handler, priority: 1)
44
147
  end
45
148
  end
46
149
  end
@@ -1,19 +1,16 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Aws
4
-
5
4
  # A credential provider that executes a given process and attempts
6
- # to read its stdout to recieve a JSON payload containing the credentials
7
- #
8
- # Automatically handles refreshing credentials if an Expiration time is
9
- # provided in the credentials payload
10
- #
11
- # credentials = Aws::ProcessCredentials.new('/usr/bin/credential_proc').credentials
5
+ # to read its stdout to recieve a JSON payload containing the credentials.
12
6
  #
7
+ # credentials = Aws::ProcessCredentials.new('/usr/bin/credential_proc')
13
8
  # ec2 = Aws::EC2::Client.new(credentials: credentials)
14
9
  #
15
- # More documentation on process based credentials can be found here:
16
- # https://docs.aws.amazon.com/cli/latest/topic/config-vars.html#sourcing-credentials-from-external-processes
10
+ # Automatically handles refreshing credentials if an Expiration time is
11
+ # provided in the credentials payload.
12
+ #
13
+ # @see https://docs.aws.amazon.com/cli/latest/topic/config-vars.html#sourcing-credentials-from-external-processes
17
14
  class ProcessCredentials
18
15
 
19
16
  include CredentialProvider
@@ -27,6 +24,7 @@ module Aws
27
24
  def initialize(process)
28
25
  @process = process
29
26
  @credentials = credentials_from_process(@process)
27
+ @async_refresh = false
30
28
 
31
29
  super
32
30
  end
@@ -73,9 +71,9 @@ module Aws
73
71
  @credentials = credentials_from_process(@process)
74
72
  end
75
73
 
76
- def near_expiration?
74
+ def near_expiration?(expiration_length)
77
75
  # are we within 5 minutes of expiration?
78
- @expiration && (Time.now.to_i + 5 * 60) > @expiration.to_i
76
+ @expiration && (Time.now.to_i + expiration_length) > @expiration.to_i
79
77
  end
80
78
  end
81
79
  end