Class: ChefMetal::AWSCredentials
- Inherits:
-
Object
- Object
- ChefMetal::AWSCredentials
- Defined in:
- lib/chef_metal/aws_credentials.rb
Overview
Reads in a credentials file in Amazon’s download format and presents the credentials to you
Class Method Summary collapse
Instance Method Summary collapse
- #[](name) ⇒ Object
- #default ⇒ Object
-
#initialize ⇒ AWSCredentials
constructor
A new instance of AWSCredentials.
- #keys ⇒ Object
- #load_csv(credentials_csv_file) ⇒ Object
- #load_default ⇒ Object
- #load_ini(credentials_ini_file) ⇒ Object
Constructor Details
#initialize ⇒ AWSCredentials
Returns a new instance of AWSCredentials.
4 5 6 |
# File 'lib/chef_metal/aws_credentials.rb', line 4 def initialize @credentials = {} end |
Class Method Details
.method_missing(name, *args, &block) ⇒ Object
50 51 52 |
# File 'lib/chef_metal/aws_credentials.rb', line 50 def self.method_missing(name, *args, &block) singleton.send(name, *args, &block) end |
.singleton ⇒ Object
54 55 56 |
# File 'lib/chef_metal/aws_credentials.rb', line 54 def self.singleton @aws_credentials ||= AWSCredentials.new end |
Instance Method Details
#[](name) ⇒ Object
16 17 18 |
# File 'lib/chef_metal/aws_credentials.rb', line 16 def [](name) @credentials[name] end |
#default ⇒ Object
8 9 10 |
# File 'lib/chef_metal/aws_credentials.rb', line 8 def default @credentials['default'] || @credentials.first[1] end |
#keys ⇒ Object
12 13 14 |
# File 'lib/chef_metal/aws_credentials.rb', line 12 def keys @credentials.keys end |
#load_csv(credentials_csv_file) ⇒ Object
35 36 37 38 39 40 41 42 43 44 |
# File 'lib/chef_metal/aws_credentials.rb', line 35 def load_csv(credentials_csv_file) require 'csv' CSV.new(File.open(credentials_csv_file), :headers => :first_row).each do |row| @credentials[row['User Name']] = { :user_name => row['User Name'], :access_key_id => row['Access Key Id'], :secret_access_key => row['Secret Access Key'] } end end |
#load_default ⇒ Object
46 47 48 |
# File 'lib/chef_metal/aws_credentials.rb', line 46 def load_default load_ini('~/.aws/config') end |
#load_ini(credentials_ini_file) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/chef_metal/aws_credentials.rb', line 20 def load_ini(credentials_ini_file) require 'inifile' inifile = IniFile.load(File.(credentials_ini_file)) inifile.each_section do |section| if section =~ /^\s*profile\s+(.+)$/ || section =~ /^\s*(default)\s*/ profile = $1.strip @credentials[profile] = { :access_key_id => inifile[section]['aws_access_key_id'], :secret_access_key => inifile[section]['aws_secret_access_key'], :region => inifile[section]['region'] } end end end |