aws-sdk-core 3.130.2 → 3.136.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (39) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +65 -1
  3. data/VERSION +1 -1
  4. data/lib/aws-sdk-core/assume_role_credentials.rb +5 -10
  5. data/lib/aws-sdk-core/assume_role_web_identity_credentials.rb +6 -7
  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 +12 -3
  13. data/lib/aws-sdk-core/plugins/signature_v4.rb +12 -7
  14. data/lib/aws-sdk-core/process_credentials.rb +6 -9
  15. data/lib/aws-sdk-core/refreshing_token.rb +71 -0
  16. data/lib/aws-sdk-core/rest/handler.rb +1 -1
  17. data/lib/aws-sdk-core/shared_config.rb +43 -0
  18. data/lib/aws-sdk-core/sso_credentials.rb +8 -12
  19. data/lib/aws-sdk-core/sso_token_provider.rb +134 -0
  20. data/lib/aws-sdk-core/static_token_provider.rb +14 -0
  21. data/lib/aws-sdk-core/structure.rb +6 -4
  22. data/lib/aws-sdk-core/token.rb +31 -0
  23. data/lib/aws-sdk-core/token_provider.rb +15 -0
  24. data/lib/aws-sdk-core/token_provider_chain.rb +51 -0
  25. data/lib/aws-sdk-core/xml/error_handler.rb +7 -0
  26. data/lib/aws-sdk-core.rb +10 -0
  27. data/lib/aws-sdk-sso/client.rb +42 -14
  28. data/lib/aws-sdk-sso/types.rb +29 -20
  29. data/lib/aws-sdk-sso.rb +1 -1
  30. data/lib/aws-sdk-ssooidc/client.rb +574 -0
  31. data/lib/aws-sdk-ssooidc/client_api.rb +216 -0
  32. data/lib/aws-sdk-ssooidc/customizations.rb +1 -0
  33. data/lib/aws-sdk-ssooidc/errors.rb +290 -0
  34. data/lib/aws-sdk-ssooidc/resource.rb +26 -0
  35. data/lib/aws-sdk-ssooidc/types.rb +498 -0
  36. data/lib/aws-sdk-ssooidc.rb +55 -0
  37. data/lib/aws-sdk-sts/client.rb +14 -5
  38. data/lib/aws-sdk-sts.rb +1 -1
  39. metadata +24 -4
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ff22a0d39db864fb7a965fedeb1f45730a70840d8ae4475e2222529604e3a707
4
- data.tar.gz: 90117e48ef4377412254102c08d95718c14b407c64be26b8bb0c62b4b349bfa2
3
+ metadata.gz: 4eff23899ad65b2216827b94ccd1dac1af4bb745f8e2fa678cd1d03cabecd695
4
+ data.tar.gz: b8ab13643d0608277ca9f73e7205f48c892e6d2701b106d70e06faf5d5b6caff
5
5
  SHA512:
6
- metadata.gz: dded90c284f709ca41f859ffb832c243728e2d19d630a84c6ba960052e8004af3e90c292f307c8ab76d2f0578ae2259402c4b96ad3a73c7a7e48e9b72c23a919
7
- data.tar.gz: bf2b97dc6ce9aafca32582f0e06b0245bf0741f897cfe1ebadf7369f1e7344604247803b396aedc6da37415594baacdce933cd22afba09abc61684884dafe135
6
+ metadata.gz: cad017d37382b5d9bd75029f288cc5bf0955d5badb2746e45d077ca92d79733355e1c9cadd92da668b094c3144c770b15dade821d0a2eb3da87f9bc160b6a325
7
+ data.tar.gz: eb6f1a7c8521c612ffa96a6735adb9a126f11b4e3c2110aa4d74d3a10fa27aa7d5582cc43f04ecb7529fb00a2c441a97b24aa33ef9d5e10bb1643814ff08cec0
data/CHANGELOG.md CHANGED
@@ -1,6 +1,70 @@
1
1
  Unreleased Changes
2
2
  ------------------
3
3
 
4
+ 3.136.0 (2022-08-25)
5
+ ------------------
6
+
7
+ * Feature - Updated Aws::SSO::Client with the latest API changes.
8
+
9
+ 3.135.0 (2022-08-24)
10
+ ------------------
11
+
12
+ * Feature - Updated Aws::SSO::Client with the latest API changes.
13
+
14
+ 3.134.0 (2022-08-23)
15
+ ------------------
16
+
17
+ * Feature - Updated Aws::SSO::Client with the latest API changes.
18
+
19
+ * Feature - Add support for Bearer Token Authentication and TokenProviders.
20
+ * Issue - Validate that `_X_AMZN_TRACE_ID` ENV value contains only valid, non-control characters.
21
+
22
+ 3.133.0 (2022-08-22)
23
+ ------------------
24
+
25
+ * Feature - Moved functionality from `aws-sdk-ssoidc` into core.
26
+
27
+ 3.132.0 (2022-08-08)
28
+ ------------------
29
+
30
+ * Feature - Updated Aws::SSO::Client with the latest API changes.
31
+
32
+ 3.131.6 (2022-08-03)
33
+ ------------------
34
+
35
+ * Issue - Fix typo in `RecursionDetection`, change amz to amzn in header and env name.
36
+
37
+ 3.131.5 (2022-07-28)
38
+ ------------------
39
+
40
+ * Issue - Fix `to_json` usage in nested hashes by defining `as_json` (#2733).
41
+
42
+ 3.131.4 (2022-07-27)
43
+ ------------------
44
+
45
+ * Issue - Fix `to_json` usage on pageable responses when using Rails (#2733).
46
+ * Issue - Use `expand_path` on credential/config paths in SharedConfig (#2735).
47
+
48
+ 3.131.3 (2022-07-18)
49
+ ------------------
50
+
51
+ * Issue - Add support for serializing shapes on the body with `jsonvalue` members.
52
+
53
+ 3.131.2 (2022-06-20)
54
+ ------------------
55
+
56
+ * Issue - Populate context :request_id for XML error responses.
57
+
58
+ 3.131.1 (2022-05-20)
59
+ ------------------
60
+
61
+ * Issue - Bump the minimum version of `jmespath` dependency.
62
+
63
+ 3.131.0 (2022-05-16)
64
+ ------------------
65
+
66
+ * Feature - Updated Aws::STS::Client with the latest API changes.
67
+
4
68
  3.130.2 (2022-04-22)
5
69
  ------------------
6
70
 
@@ -50,7 +114,7 @@ Unreleased Changes
50
114
  3.126.2 (2022-02-16)
51
115
  ------------------
52
116
 
53
- * Issue - Add a before_refresh callback to AssumeRoleCredentials (#2529).
117
+ * Issue - Add a before_refresh callback to AssumeRoleCredentials (#2529).
54
118
  * Issue - Raise a `NoSuchProfileError` when config and credentials files don't exist.
55
119
 
56
120
  3.126.1 (2022-02-14)
data/VERSION CHANGED
@@ -1 +1 @@
1
- 3.130.2
1
+ 3.136.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
@@ -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
@@ -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,23 @@ 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
+ if (header_value.chars & (0..31).map(&:chr)).any?
24
+ raise ArgumentError, 'Invalid _X_AMZN_TRACE_ID value: '\
25
+ 'contains ASCII control characters'
26
+ end
27
+ header_value
28
+ end
20
29
  end
21
30
 
22
31
  # should be at the end of build so that
@@ -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
@@ -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
@@ -4,6 +4,9 @@ module Aws
4
4
  # @api private
5
5
  class SharedConfig
6
6
  SSO_PROFILE_KEYS = %w[sso_start_url sso_region sso_account_id sso_role_name].freeze
7
+ SSO_TOKEN_PROFILE_KEYS = %w[sso_session].freeze
8
+ SSO_SESSION_KEYS = %w[sso_region]
9
+
7
10
 
8
11
  # @return [String]
9
12
  attr_reader :credentials_path
@@ -51,10 +54,12 @@ module Aws
51
54
  @config_enabled = options[:config_enabled]
52
55
  @credentials_path = options[:credentials_path] ||
53
56
  determine_credentials_path
57
+ @credentials_path = File.expand_path(@credentials_path) if @credentials_path
54
58
  @parsed_credentials = {}
55
59
  load_credentials_file if loadable?(@credentials_path)
56
60
  if @config_enabled
57
61
  @config_path = options[:config_path] || determine_config_path
62
+ @config_path = File.expand_path(@config_path) if @config_path
58
63
  load_config_file if loadable?(@config_path)
59
64
  end
60
65
  end
@@ -149,6 +154,18 @@ module Aws
149
154
  credentials
150
155
  end
151
156
 
157
+ # Attempts to load from shared config or shared credentials file.
158
+ # Will always attempt first to load from the shared credentials
159
+ # file, if present.
160
+ def sso_token_from_config(opts = {})
161
+ p = opts[:profile] || @profile_name
162
+ token = sso_token_from_profile(@parsed_credentials, p)
163
+ if @parsed_config
164
+ token ||= sso_token_from_profile(@parsed_config, p)
165
+ end
166
+ token
167
+ end
168
+
152
169
  # Add an accessor method (similar to attr_reader) to return a configuration value
153
170
  # Uses the get_config_value below to control where
154
171
  # values are loaded from
@@ -325,6 +342,32 @@ module Aws
325
342
  end
326
343
  end
327
344
 
345
+ # If the required sso_ profile values are present, attempt to construct
346
+ # SSOTokenProvider
347
+ def sso_token_from_profile(cfg, profile)
348
+ if @parsed_config &&
349
+ (prof_config = cfg[profile]) &&
350
+ !(prof_config.keys & SSO_TOKEN_PROFILE_KEYS).empty?
351
+
352
+ sso_session_name = prof_config['sso_session']
353
+ sso_session = cfg["sso-session #{sso_session_name}"]
354
+ unless sso_session
355
+ raise ArgumentError,
356
+ "sso-session #{sso_session_name} must be defined in the config file." /
357
+ "Referenced by profile #{profile}"
358
+ end
359
+
360
+ unless sso_session['sso_region']
361
+ raise ArgumentError, "sso-session #{sso_session_name} missing required parameter: sso_region"
362
+ end
363
+
364
+ SSOTokenProvider.new(
365
+ sso_session: sso_session_name,
366
+ sso_region: sso_session['sso_region']
367
+ )
368
+ end
369
+ end
370
+
328
371
  def credentials_from_profile(prof_config)
329
372
  creds = Credentials.new(
330
373
  prof_config['aws_access_key_id'],
@@ -1,17 +1,12 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Aws
4
- # An auto-refreshing credential provider that works by assuming a
5
- # role via {Aws::SSO::Client#get_role_credentials} using a cached access
6
- # token. This class does NOT implement the SSO login token flow - tokens
4
+ # An auto-refreshing credential provider that assumes a role via
5
+ # {Aws::SSO::Client#get_role_credentials} using a cached access
6
+ # token. This class does NOT implement the SSO login token flow - tokens
7
7
  # must generated and refreshed separately by running `aws login` from the
8
8
  # AWS CLI with the correct profile.
9
9
  #
10
- # For more background on AWS SSO see the official
11
- # {https://docs.aws.amazon.com/singlesignon/latest/userguide/what-is.html what is SSO Userguide}
12
- #
13
- # ## Refreshing Credentials from SSO
14
- #
15
10
  # The `SSOCredentials` will auto-refresh the AWS credentials from SSO. In
16
11
  # addition to AWS credentials expiring after a given amount of time, the
17
12
  # access token generated and cached from `aws login` will also expire.
@@ -20,7 +15,6 @@ module Aws
20
15
  # the token value, but this can be done by running `aws login` with the
21
16
  # correct profile.
22
17
  #
23
- #
24
18
  # # You must first run aws sso login --profile your-sso-profile
25
19
  # sso_credentials = Aws::SSOCredentials.new(
26
20
  # sso_account_id: '123456789',
@@ -28,11 +22,13 @@ module Aws
28
22
  # sso_region: "us-east-1",
29
23
  # sso_start_url: 'https://your-start-url.awsapps.com/start'
30
24
  # )
31
- #
32
25
  # ec2 = Aws::EC2::Client.new(credentials: sso_credentials)
33
26
  #
34
- # If you omit `:client` option, a new {SSO::Client} object will be
35
- # constructed.
27
+ # If you omit `:client` option, a new {Aws::SSO::Client} object will be
28
+ # constructed with additional options that were provided.
29
+ #
30
+ # @see Aws::SSO::Client#get_role_credentials
31
+ # @see https://docs.aws.amazon.com/singlesignon/latest/userguide/what-is.html
36
32
  class SSOCredentials
37
33
 
38
34
  include CredentialProvider