You are viewing documentation for version 1 of the AWS SDK for Ruby. Version 2 documentation can be found here.
Class: AWS::Core::CredentialProviders::CredentialFileProvider
- Inherits:
-
Object
- Object
- AWS::Core::CredentialProviders::CredentialFileProvider
- Includes:
- Provider
- Defined in:
- lib/aws/core/credential_providers.rb
Overview
This credential provider gets credentials from a credential file with the following format:
AWSAccessKeyId=your_key AWSSecretKey=your_secret
Constant Summary
- CREDENTIAL_FILE_KEY_MAP =
Map of AWS credential file key names to accepted provider key names
{ "AWSAccessKeyId" => :access_key_id, "AWSSecretKey" => :secret_access_key }
Constants included from Provider
Instance Attribute Summary collapse
-
#credential_file ⇒ Object
readonly
Returns the value of attribute credential_file.
Instance Method Summary collapse
-
#get_credentials ⇒ Hash
This method is called on a credential provider to fetch credentials.
-
#initialize(credential_file) ⇒ CredentialFileProvider
constructor
A new instance of CredentialFileProvider.
Methods included from Provider
#access_key_id, #credentials, #refresh, #secret_access_key, #session_token, #set?
Constructor Details
#initialize(credential_file) ⇒ CredentialFileProvider
Returns a new instance of CredentialFileProvider
247 248 249 |
# File 'lib/aws/core/credential_providers.rb', line 247 def initialize(credential_file) @credential_file = credential_file end |
Instance Attribute Details
#credential_file ⇒ Object (readonly)
Returns the value of attribute credential_file
244 245 246 |
# File 'lib/aws/core/credential_providers.rb', line 244 def credential_file @credential_file end |
Instance Method Details
#get_credentials ⇒ Hash
This method is called on a credential provider to fetch credentials. The credentials hash returned from this method will be cached until the client calls Provider#refresh.
252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 |
# File 'lib/aws/core/credential_providers.rb', line 252 def get_credentials credentials = {} if File.exist?(credential_file) && File.readable?(credential_file) File.open(credential_file, 'r') do |fh| fh.each_line do |line| key, val = line.strip.split(%r(\s*=\s*)) if key && val && CREDENTIAL_FILE_KEY_MAP[key] && KEYS.include?(CREDENTIAL_FILE_KEY_MAP[key]) credentials[CREDENTIAL_FILE_KEY_MAP[key]] = val end end fh.close end end credentials end |