Class: Mongo::Auth::Aws::CredentialsRetriever Private
- Inherits:
-
Object
- Object
- Mongo::Auth::Aws::CredentialsRetriever
- Defined in:
- build/ruby-driver-v2.19/lib/mongo/auth/aws/credentials_retriever.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Retrieves AWS credentials from a variety of sources.
This class provides for AWS credentials retrieval from:
-
the passed user (which receives the credentials passed to the client via URI options and Ruby options)
-
AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, AWS_SESSION_TOKEN environment variables (commonly used by AWS SDKs and various tools, as well as AWS Lambda)
-
AssumeRoleWithWebIdentity API call
-
EC2 metadata endpoint
-
ECS metadata endpoint
The sources listed above are consulted in the order specified. The first source that contains any of the three credential components (access key id, secret access key or session token) is used. The credential components must form a valid set if any of the components is specified; meaning, access key id and secret access key must always be provided together, and if a session token is provided the key id and secret key must also be provided. If a source provides partial credentials, credential retrieval fails with an exception.
Constant Summary collapse
- METADATA_TIMEOUT =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
Timeout for metadata operations, in seconds.
The auth spec suggests a 10 second timeout but this seems excessively long given that the endpoint is essentially local.
5
Instance Attribute Summary collapse
-
#user ⇒ Auth::User | nil
readonly
private
The user object, if one was provided.
Instance Method Summary collapse
-
#credentials ⇒ Auth::Aws::Credentials
private
Retrieves a valid set of credentials, if possible, or raises Auth::InvalidConfiguration.
-
#initialize(user = nil, credentials_cache: CredentialsCache.instance) ⇒ CredentialsRetriever
constructor
private
A new instance of CredentialsRetriever.
Constructor Details
#initialize(user = nil, credentials_cache: CredentialsCache.instance) ⇒ CredentialsRetriever
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of CredentialsRetriever.
61 62 63 64 |
# File 'build/ruby-driver-v2.19/lib/mongo/auth/aws/credentials_retriever.rb', line 61 def initialize(user = nil, credentials_cache: CredentialsCache.instance) @user = user @credentials_cache = credentials_cache end |
Instance Attribute Details
#user ⇒ Auth::User | nil (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns The user object, if one was provided.
67 68 69 |
# File 'build/ruby-driver-v2.19/lib/mongo/auth/aws/credentials_retriever.rb', line 67 def user @user end |
Instance Method Details
#credentials ⇒ Auth::Aws::Credentials
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Retrieves a valid set of credentials, if possible, or raises Auth::InvalidConfiguration.
78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'build/ruby-driver-v2.19/lib/mongo/auth/aws/credentials_retriever.rb', line 78 def credentials credentials = credentials_from_user(user) return credentials unless credentials.nil? credentials = credentials_from_environment return credentials unless credentials.nil? credentials = @credentials_cache.fetch { obtain_credentials_from_endpoints } return credentials unless credentials.nil? raise Auth::Aws::CredentialsNotFound end |