class Chef::Provisioning::AWSDriver::Credentials2
Loads the credentials for the AWS
SDK V2 Attempts to load credentials in the order specified at docs.aws.amazon.com/sdkforruby/api/index.html#Configuration
Attributes
profile_name[R]
Public Class Methods
new(options = {})
click to toggle source
@param [Hash] options @option options [String] :profile_name (ENV) The profile name to use
when loading the config from '~/.aws/credentials'. This can be nil.
# File lib/chef/provisioning/aws_driver/credentials2.rb, line 20 def initialize(options = {}) @profile_name = options[:profile_name] || ENV["AWS_DEFAULT_PROFILE"] end
Public Instance Methods
get_credentials()
click to toggle source
Try to load the credentials from an ordered list of sources and return the first one that can be loaded successfully.
# File lib/chef/provisioning/aws_driver/credentials2.rb, line 26 def get_credentials # http://docs.aws.amazon.com/cli/latest/userguide/cli-chap-getting-started.html#cli-environment credentials_file = ENV.fetch("AWS_SHARED_CREDENTIALS_FILE", ENV["AWS_CONFIG_FILE"]) shared_creds = ::Aws::SharedCredentials.new( profile_name: profile_name, path: credentials_file ) instance_profile_creds = ::Aws::InstanceProfileCredentials.new(retries: 1) if ENV["AWS_ACCESS_KEY_ID"] && ENV["AWS_SECRET_ACCESS_KEY"] creds = ::Aws::Credentials.new( ENV["AWS_ACCESS_KEY_ID"], ENV["AWS_SECRET_ACCESS_KEY"], ENV["AWS_SESSION_TOKEN"] ) elsif shared_creds.set? creds = shared_creds elsif instance_profile_creds.set? creds = instance_profile_creds else raise LoadCredentialsError, "Could not load credentials from the environment variables, the .aws/credentials file or the metadata service" end creds end