Class: ChefMetalFog::Providers::AWS::Credentials
- Inherits:
-
Object
- Object
- ChefMetalFog::Providers::AWS::Credentials
- Includes:
- Enumerable
- Defined in:
- lib/chef_metal_fog/providers/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
- #each(&block) ⇒ Object
-
#initialize ⇒ Credentials
constructor
A new instance of Credentials.
- #keys ⇒ Object
- #load_csv(credentials_csv_file) ⇒ Object
- #load_default ⇒ Object
- #load_ini(credentials_ini_file) ⇒ Object
Constructor Details
#initialize ⇒ Credentials
Returns a new instance of Credentials.
9 10 11 |
# File 'lib/chef_metal_fog/providers/aws/credentials.rb', line 9 def initialize @credentials = {} end |
Class Method Details
.method_missing(name, *args, &block) ⇒ Object
61 62 63 |
# File 'lib/chef_metal_fog/providers/aws/credentials.rb', line 61 def self.method_missing(name, *args, &block) singleton.send(name, *args, &block) end |
.singleton ⇒ Object
65 66 67 |
# File 'lib/chef_metal_fog/providers/aws/credentials.rb', line 65 def self.singleton @aws_credentials ||= Credentials.new end |
Instance Method Details
#[](name) ⇒ Object
23 24 25 |
# File 'lib/chef_metal_fog/providers/aws/credentials.rb', line 23 def [](name) @credentials[name] end |
#default ⇒ Object
15 16 17 |
# File 'lib/chef_metal_fog/providers/aws/credentials.rb', line 15 def default @credentials[ENV['AWS_DEFAULT_PROFILE'] || 'default'] || @credentials.first[1] end |
#each(&block) ⇒ Object
27 28 29 |
# File 'lib/chef_metal_fog/providers/aws/credentials.rb', line 27 def each(&block) @credentials.each(&block) end |
#keys ⇒ Object
19 20 21 |
# File 'lib/chef_metal_fog/providers/aws/credentials.rb', line 19 def keys @credentials.keys end |
#load_csv(credentials_csv_file) ⇒ Object
46 47 48 49 50 51 52 53 54 55 |
# File 'lib/chef_metal_fog/providers/aws/credentials.rb', line 46 def load_csv(credentials_csv_file) CSV.new(File.open(credentials_csv_file), :headers => :first_row).each do |row| @credentials[row['User Name']] = { :name => row['User Name'], :user_name => row['User Name'], :aws_access_key_id => row['Access Key Id'], :aws_secret_access_key => row['Secret Access Key'] } end end |
#load_default ⇒ Object
57 58 59 |
# File 'lib/chef_metal_fog/providers/aws/credentials.rb', line 57 def load_default load_ini(ENV['AWS_CONFIG_FILE'] || File.('~/.aws/config')) end |
#load_ini(credentials_ini_file) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/chef_metal_fog/providers/aws/credentials.rb', line 31 def load_ini(credentials_ini_file) inifile = IniFile.load(File.(credentials_ini_file)) inifile.each_section do |section| if section =~ /^\s*profile\s+(.+)$/ || section =~ /^\s*(default)\s*/ profile_name = $1.strip profile = inifile[section].inject({}) do |result, pair| result[pair[0].to_sym] = pair[1] result end profile[:name] = profile_name @credentials[profile_name] = profile end end end |