aws-sdk-core 3.130.0 → 3.150.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 (41) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +147 -1
  3. data/VERSION +1 -1
  4. data/lib/aws-sdk-core/assume_role_credentials.rb +6 -11
  5. data/lib/aws-sdk-core/assume_role_web_identity_credentials.rb +8 -10
  6. data/lib/aws-sdk-core/ecs_credentials.rb +5 -0
  7. data/lib/aws-sdk-core/errors.rb +13 -0
  8. data/lib/aws-sdk-core/instance_profile_credentials.rb +5 -0
  9. data/lib/aws-sdk-core/pageable_response.rb +7 -0
  10. data/lib/aws-sdk-core/plugins/bearer_authorization.rb +67 -0
  11. data/lib/aws-sdk-core/plugins/jsonvalue_converter.rb +34 -6
  12. data/lib/aws-sdk-core/plugins/recursion_detection.rb +14 -3
  13. data/lib/aws-sdk-core/plugins/retry_errors.rb +12 -2
  14. data/lib/aws-sdk-core/plugins/signature_v4.rb +12 -7
  15. data/lib/aws-sdk-core/process_credentials.rb +6 -9
  16. data/lib/aws-sdk-core/refreshing_credentials.rb +2 -0
  17. data/lib/aws-sdk-core/refreshing_token.rb +71 -0
  18. data/lib/aws-sdk-core/rest/handler.rb +1 -1
  19. data/lib/aws-sdk-core/shared_config.rb +43 -0
  20. data/lib/aws-sdk-core/sso_credentials.rb +15 -15
  21. data/lib/aws-sdk-core/sso_token_provider.rb +134 -0
  22. data/lib/aws-sdk-core/static_token_provider.rb +14 -0
  23. data/lib/aws-sdk-core/structure.rb +6 -4
  24. data/lib/aws-sdk-core/token.rb +31 -0
  25. data/lib/aws-sdk-core/token_provider.rb +15 -0
  26. data/lib/aws-sdk-core/token_provider_chain.rb +51 -0
  27. data/lib/aws-sdk-core/xml/error_handler.rb +7 -0
  28. data/lib/aws-sdk-core.rb +10 -0
  29. data/lib/aws-sdk-sso/client.rb +32 -9
  30. data/lib/aws-sdk-sso/types.rb +8 -8
  31. data/lib/aws-sdk-sso.rb +1 -1
  32. data/lib/aws-sdk-ssooidc/client.rb +574 -0
  33. data/lib/aws-sdk-ssooidc/client_api.rb +216 -0
  34. data/lib/aws-sdk-ssooidc/customizations.rb +1 -0
  35. data/lib/aws-sdk-ssooidc/errors.rb +290 -0
  36. data/lib/aws-sdk-ssooidc/resource.rb +26 -0
  37. data/lib/aws-sdk-ssooidc/types.rb +498 -0
  38. data/lib/aws-sdk-ssooidc.rb +55 -0
  39. data/lib/aws-sdk-sts/client.rb +14 -5
  40. data/lib/aws-sdk-sts.rb +1 -1
  41. metadata +24 -4
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d7804cbac83996a95b2cacbd808389798eb0b461229a9e8e2a966cd28d599aa6
4
- data.tar.gz: ce3557bcbd4d6a5edaa1bc99fbd7e75f9b2e23eb6fadb8be06a69b91e2e8a4a7
3
+ metadata.gz: 6e48c7a4f814d1be349fc135259cf773061e0b433c1dd1227b4e1dff040725cc
4
+ data.tar.gz: 8fe44d28c5302975a2590296d5af2e2eb6337e79a9c38f4f07c380728974c1ad
5
5
  SHA512:
6
- metadata.gz: d1d0b4ec0b478389290d84409869ed012e4a2ce6408d3dc5c46c618771cc970d9086eb4686dd64b740ebd5eeafe7cc0e8b6fa63d3f89202e8f2841d9a203bdbb
7
- data.tar.gz: f4c41ffb85d712bcaf8701aa61a886837517df23e14a53c2b9201d86bfcc1fd41b5b8badded9f91aeb0ee77553c9e2af80b4c82d1e249486b5630afc1582939c
6
+ metadata.gz: c17d6185b0dbcccde742918b1a78ec4fa73b7235216f99ff83b44eb7b4282cb2925cc6deaa0cd79a5f1e7f9acef0e074279279bf318d252352954aa38a7c1648
7
+ data.tar.gz: 679cbcc65fedea907a6aab89e4bd86b04bac83ca61d4f1c00b21f2e3c0e595f20a06f07ab1b49b2c68cb63091b005804dfcc771b9c5a0abe6238a43e398e4c06
data/CHANGELOG.md CHANGED
@@ -1,6 +1,152 @@
1
1
  Unreleased Changes
2
2
  ------------------
3
3
 
4
+ 3.150.0 (2022-09-19)
5
+ ------------------
6
+
7
+ * Feature - Updated Aws::SSO::Client with the latest API changes.
8
+
9
+ 3.149.0 (2022-09-16)
10
+ ------------------
11
+
12
+ * Feature - Updated Aws::SSO::Client with the latest API changes.
13
+
14
+ 3.148.0 (2022-09-15)
15
+ ------------------
16
+
17
+ * Feature - Updated Aws::SSO::Client with the latest API changes.
18
+
19
+ 3.147.0 (2022-09-14)
20
+ ------------------
21
+
22
+ * Feature - Updated Aws::SSO::Client with the latest API changes.
23
+
24
+ 3.146.0 (2022-09-13)
25
+ ------------------
26
+
27
+ * Feature - Updated Aws::SSO::Client with the latest API changes.
28
+
29
+ 3.145.0 (2022-09-12)
30
+ ------------------
31
+
32
+ * Feature - Updated Aws::SSO::Client with the latest API changes.
33
+
34
+ 3.144.0 (2022-09-09)
35
+ ------------------
36
+
37
+ * Feature - Updated Aws::SSO::Client with the latest API changes.
38
+
39
+ 3.143.0 (2022-09-08)
40
+ ------------------
41
+
42
+ * Feature - Updated Aws::SSO::Client with the latest API changes.
43
+
44
+ 3.142.0 (2022-09-07)
45
+ ------------------
46
+
47
+ * Feature - Updated Aws::SSO::Client with the latest API changes.
48
+
49
+ 3.141.0 (2022-09-06)
50
+ ------------------
51
+
52
+ * Feature - Updated Aws::SSO::Client with the latest API changes.
53
+
54
+ 3.140.0 (2022-09-02)
55
+ ------------------
56
+
57
+ * Feature - Updated Aws::SSO::Client with the latest API changes.
58
+
59
+ 3.139.0 (2022-09-01)
60
+ ------------------
61
+
62
+ * Feature - Updated Aws::SSO::Client with the latest API changes.
63
+
64
+ 3.138.0 (2022-08-31)
65
+ ------------------
66
+
67
+ * Feature - Updated Aws::SSO::Client with the latest API changes.
68
+
69
+ 3.137.0 (2022-08-30)
70
+ ------------------
71
+
72
+ * Feature - Updated Aws::SSO::Client with the latest API changes.
73
+
74
+ * Issue - Fix errors in recursion detection when `_X_AMZN_TRACE_ID` is unset (#2748).
75
+
76
+ 3.136.0 (2022-08-25)
77
+ ------------------
78
+
79
+ * Feature - Updated Aws::SSO::Client with the latest API changes.
80
+
81
+ 3.135.0 (2022-08-24)
82
+ ------------------
83
+
84
+ * Feature - Updated Aws::SSO::Client with the latest API changes.
85
+
86
+ 3.134.0 (2022-08-23)
87
+ ------------------
88
+
89
+ * Feature - Updated Aws::SSO::Client with the latest API changes.
90
+
91
+ * Feature - Add support for Bearer Token Authentication and TokenProviders.
92
+ * Issue - Validate that `_X_AMZN_TRACE_ID` ENV value contains only valid, non-control characters.
93
+
94
+ 3.133.0 (2022-08-22)
95
+ ------------------
96
+
97
+ * Feature - Moved functionality from `aws-sdk-ssoidc` into core.
98
+
99
+ 3.132.0 (2022-08-08)
100
+ ------------------
101
+
102
+ * Feature - Updated Aws::SSO::Client with the latest API changes.
103
+
104
+ 3.131.6 (2022-08-03)
105
+ ------------------
106
+
107
+ * Issue - Fix typo in `RecursionDetection`, change amz to amzn in header and env name.
108
+
109
+ 3.131.5 (2022-07-28)
110
+ ------------------
111
+
112
+ * Issue - Fix `to_json` usage in nested hashes by defining `as_json` (#2733).
113
+
114
+ 3.131.4 (2022-07-27)
115
+ ------------------
116
+
117
+ * Issue - Fix `to_json` usage on pageable responses when using Rails (#2733).
118
+ * Issue - Use `expand_path` on credential/config paths in SharedConfig (#2735).
119
+
120
+ 3.131.3 (2022-07-18)
121
+ ------------------
122
+
123
+ * Issue - Add support for serializing shapes on the body with `jsonvalue` members.
124
+
125
+ 3.131.2 (2022-06-20)
126
+ ------------------
127
+
128
+ * Issue - Populate context :request_id for XML error responses.
129
+
130
+ 3.131.1 (2022-05-20)
131
+ ------------------
132
+
133
+ * Issue - Bump the minimum version of `jmespath` dependency.
134
+
135
+ 3.131.0 (2022-05-16)
136
+ ------------------
137
+
138
+ * Feature - Updated Aws::STS::Client with the latest API changes.
139
+
140
+ 3.130.2 (2022-04-22)
141
+ ------------------
142
+
143
+ * Issue - Don't pass `:before_refresh` to Client constructors in RefreshingCredential implementations (#2690).
144
+
145
+ 3.130.1 (2022-04-12)
146
+ ------------------
147
+
148
+ * Issue - Don't call `refresh!` on non-refreshable `Credentials` when retrying errors (#2685).
149
+
4
150
  3.130.0 (2022-03-11)
5
151
  ------------------
6
152
 
@@ -40,7 +186,7 @@ Unreleased Changes
40
186
  3.126.2 (2022-02-16)
41
187
  ------------------
42
188
 
43
- * Issue - Add a before_refresh callback to AssumeRoleCredentials (#2529).
189
+ * Issue - Add a before_refresh callback to AssumeRoleCredentials (#2529).
44
190
  * Issue - Raise a `NoSuchProfileError` when config and credentials files don't exist.
45
191
 
46
192
  3.126.1 (2022-02-14)
data/VERSION CHANGED
@@ -1 +1 @@
1
- 3.130.0
1
+ 3.150.0
@@ -3,25 +3,20 @@
3
3
  require 'set'
4
4
 
5
5
  module Aws
6
-
7
- # An auto-refreshing credential provider that works by assuming
8
- # a role via {Aws::STS::Client#assume_role}.
6
+ # An auto-refreshing credential provider that assumes a role via
7
+ # {Aws::STS::Client#assume_role}.
9
8
  #
10
9
  # role_credentials = Aws::AssumeRoleCredentials.new(
11
10
  # client: Aws::STS::Client.new(...),
12
11
  # role_arn: "linked::account::arn",
13
12
  # role_session_name: "session-name"
14
13
  # )
15
- #
16
14
  # ec2 = Aws::EC2::Client.new(credentials: role_credentials)
17
15
  #
18
- # If you omit `:client` option, a new {STS::Client} object will be
19
- # constructed.
16
+ # If you omit `:client` option, a new {Aws::STS::Client} object will be
17
+ # constructed with additional options that were provided.
20
18
  #
21
- # The AssumeRoleCredentials also provides a `before_refresh` callback
22
- # that can be used to help manage refreshing tokens.
23
- # `before_refresh` is called when AWS credentials are required and need
24
- # to be refreshed and it is called with the AssumeRoleCredentials object.
19
+ # @see Aws::STS::Client#assume_role
25
20
  class AssumeRoleCredentials
26
21
 
27
22
  include CredentialProvider
@@ -49,7 +44,7 @@ module Aws
49
44
  options.each_pair do |key, value|
50
45
  if self.class.assume_role_options.include?(key)
51
46
  @assume_role_params[key] = value
52
- else
47
+ elsif !CLIENT_EXCLUDE_OPTIONS.include?(key)
53
48
  client_opts[key] = value
54
49
  end
55
50
  end
@@ -5,9 +5,8 @@ require 'securerandom'
5
5
  require 'base64'
6
6
 
7
7
  module Aws
8
-
9
- # An auto-refreshing credential provider that works by assuming
10
- # a role via {Aws::STS::Client#assume_role_with_web_identity}.
8
+ # An auto-refreshing credential provider that assumes a role via
9
+ # {Aws::STS::Client#assume_role_with_web_identity}.
11
10
  #
12
11
  # role_credentials = Aws::AssumeRoleWebIdentityCredentials.new(
13
12
  # client: Aws::STS::Client.new(...),
@@ -16,12 +15,12 @@ module Aws
16
15
  # role_session_name: "session-name"
17
16
  # ...
18
17
  # )
19
- # For full list of parameters accepted
20
- # @see Aws::STS::Client#assume_role_with_web_identity
18
+ # ec2 = Aws::EC2::Client.new(credentials: role_credentials)
21
19
  #
20
+ # If you omit `:client` option, a new {Aws::STS::Client} object will be
21
+ # constructed with additional options that were provided.
22
22
  #
23
- # If you omit `:client` option, a new {STS::Client} object will be
24
- # constructed.
23
+ # @see Aws::STS::Client#assume_role_with_web_identity
25
24
  class AssumeRoleWebIdentityCredentials
26
25
 
27
26
  include CredentialProvider
@@ -52,7 +51,7 @@ module Aws
52
51
  options.each_pair do |key, value|
53
52
  if self.class.assume_role_web_identity_options.include?(key)
54
53
  @assume_role_web_identity_params[key] = value
55
- else
54
+ elsif !CLIENT_EXCLUDE_OPTIONS.include?(key)
56
55
  client_opts[key] = value
57
56
  end
58
57
  end
@@ -100,11 +99,10 @@ module Aws
100
99
  # @api private
101
100
  def assume_role_web_identity_options
102
101
  @arwio ||= begin
103
- input = STS::Client.api.operation(:assume_role_with_web_identity).input
102
+ input = Aws::STS::Client.api.operation(:assume_role_with_web_identity).input
104
103
  Set.new(input.shape.member_names)
105
104
  end
106
105
  end
107
-
108
106
  end
109
107
  end
110
108
  end
@@ -4,6 +4,11 @@ require 'time'
4
4
  require 'net/http'
5
5
 
6
6
  module Aws
7
+ # An auto-refreshing credential provider that loads credentials from
8
+ # instances running in ECS.
9
+ #
10
+ # ecs_credentials = Aws::ECSCredentials.new(retries: 3)
11
+ # ec2 = Aws::EC2::Client.new(credentials: ecs_credentials)
7
12
  class ECSCredentials
8
13
 
9
14
  include CredentialProvider
@@ -210,6 +210,19 @@ module Aws
210
210
  # Raised when SSO Credentials are invalid
211
211
  class InvalidSSOCredentials < RuntimeError; end
212
212
 
213
+ # Raised when SSO Token is invalid
214
+ class InvalidSSOToken < RuntimeError; end
215
+
216
+ # Raised when a client is unable to sign a request because
217
+ # the bearer token is not configured or available
218
+ class MissingBearerTokenError < RuntimeError
219
+ def initialize(*args)
220
+ msg = 'unable to sign request without token set'
221
+ super(msg)
222
+ end
223
+ end
224
+
225
+
213
226
  # Raised when there is a circular reference in chained
214
227
  # source_profiles
215
228
  class SourceProfileCircularReferenceError < RuntimeError; end
@@ -4,6 +4,11 @@ require 'time'
4
4
  require 'net/http'
5
5
 
6
6
  module Aws
7
+ # An auto-refreshing credential provider that loads credentials from
8
+ # EC2 instances.
9
+ #
10
+ # instance_credentials = Aws::InstanceProfileCredentials.new
11
+ # ec2 = Aws::EC2::Client.new(credentials: instance_credentials)
7
12
  class InstanceProfileCredentials
8
13
  include CredentialProvider
9
14
  include RefreshingCredentials
@@ -146,6 +146,13 @@ module Aws
146
146
  data.to_h
147
147
  end
148
148
 
149
+ def as_json(_options = {})
150
+ data.to_h(data, as_json: true)
151
+ end
152
+
153
+ def to_json(options = {})
154
+ as_json.to_json(options)
155
+ end
149
156
  end
150
157
 
151
158
  # The actual decorator module implementation. It is in a distinct module
@@ -0,0 +1,67 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Aws
4
+ # @api private
5
+ module Plugins
6
+ # @api private
7
+ class BearerAuthorization < Seahorse::Client::Plugin
8
+
9
+ option(:token_provider,
10
+ required: false,
11
+ doc_type: 'Aws::TokenProvider',
12
+ docstring: <<-DOCS
13
+ A Bearer Token Provider. This can be an instance of any one of the
14
+ following classes:
15
+
16
+ * `Aws::StaticTokenProvider` - Used for configuring static, non-refreshing
17
+ tokens.
18
+
19
+ * `Aws::SSOTokenProvider` - Used for loading tokens from AWS SSO using an
20
+ access token generated from `aws login`.
21
+
22
+ When `:token_provider` is not configured directly, the `Aws::TokenProviderChain`
23
+ will be used to search for tokens configured for your profile in shared configuration files.
24
+ DOCS
25
+ ) do |config|
26
+ if config.stub_responses
27
+ StaticTokenProvider.new('token')
28
+ else
29
+ TokenProviderChain.new(config).resolve
30
+ end
31
+ end
32
+
33
+
34
+ def add_handlers(handlers, cfg)
35
+ bearer_operations =
36
+ if cfg.api.metadata['signatureVersion'] == 'bearer'
37
+ # select operations where authtype is either not set or is bearer
38
+ cfg.api.operation_names.select do |o|
39
+ !cfg.api.operation(o)['authtype'] || cfg.api.operation(o)['authtype'] == 'bearer'
40
+ end
41
+ else # service is not bearer auth
42
+ # select only operations where authtype is explicitly bearer
43
+ cfg.api.operation_names.select do |o|
44
+ cfg.api.operation(o)['authtype'] == 'bearer'
45
+ end
46
+ end
47
+ handlers.add(Handler, step: :sign, operations: bearer_operations)
48
+ end
49
+
50
+ class Handler < Seahorse::Client::Handler
51
+ def call(context)
52
+ if context.http_request.endpoint.scheme != 'https'
53
+ raise ArgumentError, 'Unable to use bearer authorization on non https endpoint.'
54
+ end
55
+
56
+ token_provider = context.config.token_provider
57
+ if token_provider && token_provider.set?
58
+ context.http_request.headers['Authorization'] = "Bearer #{token_provider.token.token}"
59
+ else
60
+ raise Errors::MissingBearerTokenError
61
+ end
62
+ @handler.call(context)
63
+ end
64
+ end
65
+ end
66
+ end
67
+ end
@@ -11,15 +11,43 @@ module Aws
11
11
 
12
12
  def call(context)
13
13
  context.operation.input.shape.members.each do |m, ref|
14
- if ref['jsonvalue']
15
- param_value = context.params[m]
16
- unless param_value.respond_to?(:to_json)
17
- raise ArgumentError, "The value of params[#{m}] is not JSON serializable."
14
+ convert_jsonvalue(m, ref, context.params, 'params')
15
+ end
16
+ @handler.call(context)
17
+ end
18
+
19
+ def convert_jsonvalue(m, ref, params, context)
20
+ return if params.nil? || !params.key?(m)
21
+
22
+ if ref['jsonvalue']
23
+ params[m] = serialize_jsonvalue(params[m], "#{context}[#{m}]")
24
+ else
25
+ case ref.shape
26
+ when Seahorse::Model::Shapes::StructureShape
27
+ ref.shape.members.each do |member_m, ref|
28
+ convert_jsonvalue(member_m, ref, params[m], "#{context}[#{m}]")
29
+ end
30
+ when Seahorse::Model::Shapes::ListShape
31
+ if ref.shape.member['jsonvalue']
32
+ params[m] = params[m].each_with_index.map do |v, i|
33
+ serialize_jsonvalue(v, "#{context}[#{m}][#{i}]")
34
+ end
35
+ end
36
+ when Seahorse::Model::Shapes::MapShape
37
+ if ref.shape.value['jsonvalue']
38
+ params[m].each do |k, v|
39
+ params[m][k] = serialize_jsonvalue(v, "#{context}[#{m}][#{k}]")
40
+ end
18
41
  end
19
- context.params[m] = param_value.to_json
20
42
  end
21
43
  end
22
- @handler.call(context)
44
+ end
45
+
46
+ def serialize_jsonvalue(v, context)
47
+ unless v.respond_to?(:to_json)
48
+ raise ArgumentError, "The value of #{context} is not JSON serializable."
49
+ end
50
+ v.to_json
23
51
  end
24
52
 
25
53
  end
@@ -9,14 +9,25 @@ module Aws
9
9
  class Handler < Seahorse::Client::Handler
10
10
  def call(context)
11
11
 
12
- unless context.http_request.headers.key?('x-amz-trace-id')
12
+ unless context.http_request.headers.key?('x-amzn-trace-id')
13
13
  if ENV['AWS_LAMBDA_FUNCTION_NAME'] &&
14
- (trace_id = ENV['_X_AMZ_TRACE_ID'])
15
- context.http_request.headers['x-amz-trace-id'] = trace_id
14
+ (trace_id = validate_header(ENV['_X_AMZN_TRACE_ID']))
15
+ context.http_request.headers['x-amzn-trace-id'] = trace_id
16
16
  end
17
17
  end
18
18
  @handler.call(context)
19
19
  end
20
+
21
+ private
22
+ def validate_header(header_value)
23
+ return unless header_value
24
+
25
+ if (header_value.chars & (0..31).map(&:chr)).any?
26
+ raise ArgumentError, 'Invalid _X_AMZN_TRACE_ID value: '\
27
+ 'contains ASCII control characters'
28
+ end
29
+ header_value
30
+ end
20
31
  end
21
32
 
22
33
  # should be at the end of build so that
@@ -313,12 +313,17 @@ a clock skew correction and retry requests with skewed client clocks.
313
313
 
314
314
  def retry_request(context, error)
315
315
  context.retries += 1
316
- context.config.credentials.refresh! if error.expired_credentials?
316
+ context.config.credentials.refresh! if refresh_credentials?(context, error)
317
317
  context.http_request.body.rewind
318
318
  context.http_response.reset
319
319
  call(context)
320
320
  end
321
321
 
322
+ def refresh_credentials?(context, error)
323
+ error.expired_credentials? &&
324
+ context.config.credentials.respond_to?(:refresh!)
325
+ end
326
+
322
327
  def add_retry_headers(context)
323
328
  request_pairs = {
324
329
  'attempt' => context.retries,
@@ -383,7 +388,7 @@ a clock skew correction and retry requests with skewed client clocks.
383
388
  def retry_request(context, error)
384
389
  delay_retry(context)
385
390
  context.retries += 1
386
- context.config.credentials.refresh! if error.expired_credentials?
391
+ context.config.credentials.refresh! if refresh_credentials?(context, error)
387
392
  context.http_request.body.rewind
388
393
  context.http_response.reset
389
394
  call(context)
@@ -399,6 +404,11 @@ a clock skew correction and retry requests with skewed client clocks.
399
404
  response_truncatable?(context)
400
405
  end
401
406
 
407
+ def refresh_credentials?(context, error)
408
+ error.expired_credentials? &&
409
+ context.config.credentials.respond_to?(:refresh!)
410
+ end
411
+
402
412
  def retry_limit(context)
403
413
  context.config.retry_limit
404
414
  end
@@ -7,6 +7,8 @@ module Aws
7
7
  # @api private
8
8
  class SignatureV4 < Seahorse::Client::Plugin
9
9
 
10
+ V4_AUTH = %w[v4 v4-unsigned-payload v4-unsigned-body]
11
+
10
12
  option(:sigv4_signer) do |cfg|
11
13
  SignatureV4.build_signer(cfg)
12
14
  end
@@ -32,13 +34,16 @@ module Aws
32
34
  end
33
35
 
34
36
  option(:unsigned_operations) do |cfg|
35
- cfg.api.operation_names.inject([]) do |unsigned, operation_name|
36
- if cfg.api.operation(operation_name)['authtype'] == 'none' ||
37
- cfg.api.operation(operation_name)['authtype'] == 'custom'
38
- # Unsign requests that has custom apigateway authorizer as well
39
- unsigned << operation_name
40
- else
41
- unsigned
37
+ if cfg.api.metadata['signatureVersion'] == 'v4'
38
+ # select operations where authtype is set and is not v4
39
+ cfg.api.operation_names.select do |o|
40
+ cfg.api.operation(o)['authtype'] && !V4_AUTH.include?(cfg.api.operation(o)['authtype'])
41
+ end
42
+ else # service is not v4 auth
43
+ # select all operations where authtype is not v4
44
+ # (includes operations with no explicit authtype)
45
+ cfg.api.operation_names.select do |o|
46
+ !V4_AUTH.include?(cfg.api.operation(o)['authtype'])
42
47
  end
43
48
  end
44
49
  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
@@ -20,6 +20,8 @@ module Aws
20
20
  SYNC_EXPIRATION_LENGTH = 300 # 5 minutes
21
21
  ASYNC_EXPIRATION_LENGTH = 600 # 10 minutes
22
22
 
23
+ CLIENT_EXCLUDE_OPTIONS = Set.new([:before_refresh]).freeze
24
+
23
25
  def initialize(options = {})
24
26
  @mutex = Mutex.new
25
27
  @before_refresh = options.delete(:before_refresh) if Hash === options
@@ -0,0 +1,71 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'thread'
4
+
5
+ module Aws
6
+
7
+ # Module/mixin used by token provider classes that can be refreshed. This
8
+ # provides basic refresh logic in a thread-safe manner. Classes mixing in
9
+ # this module are expected to implement a #refresh method that populates
10
+ # the following instance variable:
11
+ #
12
+ # * `@token` [Token] - {Aws::Token} object with the `expiration` and `token`
13
+ # fields set.
14
+ #
15
+ # @api private
16
+ module RefreshingToken
17
+
18
+ def initialize(options = {})
19
+ @mutex = Mutex.new
20
+ @before_refresh = options.delete(:before_refresh) if Hash === options
21
+
22
+ @before_refresh.call(self) if @before_refresh
23
+ refresh
24
+ end
25
+
26
+ # @return [Token]
27
+ def token
28
+ refresh_if_near_expiration
29
+ @token
30
+ end
31
+
32
+ # @return [Time,nil]
33
+ def expiration
34
+ refresh_if_near_expiration
35
+ @expiration
36
+ end
37
+
38
+ # Refresh token.
39
+ # @return [void]
40
+ def refresh!
41
+ @mutex.synchronize do
42
+ @before_refresh.call(self) if @before_refresh
43
+ refresh
44
+ end
45
+ end
46
+
47
+ private
48
+
49
+ # Refreshes token if it is within
50
+ # 5 minutes of expiration.
51
+ def refresh_if_near_expiration
52
+ if near_expiration?
53
+ @mutex.synchronize do
54
+ if near_expiration?
55
+ @before_refresh.call(self) if @before_refresh
56
+ refresh
57
+ end
58
+ end
59
+ end
60
+ end
61
+
62
+ def near_expiration?
63
+ if @token && @token.expiration
64
+ # are we within 5 minutes of expiration?
65
+ (Time.now.to_i + 5 * 60) > @token.expiration.to_i
66
+ else
67
+ true
68
+ end
69
+ end
70
+ end
71
+ end
@@ -17,7 +17,7 @@ module Aws
17
17
 
18
18
  def apply_request_id(context)
19
19
  h = context.http_response.headers
20
- context[:request_id] = h['x-amz-request-id'] || h['x-amzn-requestid']
20
+ context[:request_id] ||= h['x-amz-request-id'] || h['x-amzn-requestid']
21
21
  end
22
22
 
23
23
  end