2010-06-02 17:40:25 -04:00
|
|
|
require 'yaml'
|
2010-12-09 21:44:02 -05:00
|
|
|
|
2010-04-02 13:14:37 -04:00
|
|
|
module Fog
|
2010-12-15 18:32:33 -05:00
|
|
|
require 'fog/core/deprecation'
|
|
|
|
|
|
|
|
# Assign a new credential to use from configuration file
|
|
|
|
# @param [String, Symbol] new_credential name of new credential to use
|
|
|
|
# @ return [String, Symbol] name of the new credential
|
2010-12-09 21:44:02 -05:00
|
|
|
def self.credential=(new_credential)
|
2011-02-27 14:08:56 -05:00
|
|
|
@credentials = nil
|
2010-12-15 18:32:33 -05:00
|
|
|
@credential = new_credential
|
2010-12-09 21:44:02 -05:00
|
|
|
end
|
2010-04-02 13:14:37 -04:00
|
|
|
|
2010-12-15 18:32:33 -05:00
|
|
|
# @return [String, Symbol] The credential to use in Fog
|
2010-12-09 21:44:02 -05:00
|
|
|
def self.credential
|
|
|
|
@credential ||= :default
|
|
|
|
end
|
2010-04-02 13:14:37 -04:00
|
|
|
|
2010-12-15 18:32:33 -05:00
|
|
|
# @return [String] The path for configuration_file
|
|
|
|
def self.credentials_path
|
2011-03-07 14:02:54 -05:00
|
|
|
@credential_path ||= File.expand_path(ENV["FOG_RC"] || (ENV['HOME'] && '~/.fog'))
|
2010-12-09 21:44:02 -05:00
|
|
|
end
|
2010-04-02 13:14:37 -04:00
|
|
|
|
2010-12-15 18:32:33 -05:00
|
|
|
# @return [String] The new path for credentials file
|
|
|
|
def self.credentials_path=(new_credentials_path)
|
2011-02-27 14:08:56 -05:00
|
|
|
@credentials = nil
|
2010-12-15 18:32:33 -05:00
|
|
|
@credential_path = new_credentials_path
|
2010-12-09 21:44:02 -05:00
|
|
|
end
|
2010-05-13 14:50:34 -04:00
|
|
|
|
2010-12-15 18:32:33 -05:00
|
|
|
# @return [Hash] The credentials pulled from the configuration file
|
|
|
|
# @raise [LoadError] Configuration unavailable in configuration file
|
|
|
|
def self.credentials
|
|
|
|
@credentials ||= begin
|
2011-03-07 14:02:54 -05:00
|
|
|
if credentials_path && File.exists?(credentials_path)
|
2011-03-10 17:49:17 -05:00
|
|
|
credentials = self.symbolize_credentials(YAML.load_file(credentials_path))
|
2011-02-15 16:47:14 -05:00
|
|
|
(credentials && credentials[credential]) or raise LoadError.new(missing_credentials)
|
2010-12-22 13:20:13 -05:00
|
|
|
else
|
|
|
|
{}
|
|
|
|
end
|
2010-04-02 13:14:37 -04:00
|
|
|
end
|
2010-12-09 21:44:02 -05:00
|
|
|
end
|
2011-03-10 17:49:17 -05:00
|
|
|
|
|
|
|
def self.symbolize_credentials(args)
|
|
|
|
if args.is_a? Hash
|
|
|
|
Hash[ args.collect do |key, value|
|
|
|
|
[key.to_sym, self.symbolize_credentials(value)]
|
|
|
|
end ]
|
|
|
|
else
|
|
|
|
args
|
|
|
|
end
|
|
|
|
end
|
2010-12-09 21:44:02 -05:00
|
|
|
|
|
|
|
private
|
2010-12-15 18:32:33 -05:00
|
|
|
|
2010-12-09 21:44:02 -05:00
|
|
|
# @return [String] The error message that will be raised, if credentials cannot be found
|
2010-12-13 18:42:56 -05:00
|
|
|
def self.missing_credentials
|
|
|
|
<<-YML
|
2010-12-09 21:44:02 -05:00
|
|
|
Missing Credentials
|
2010-04-02 13:14:37 -04:00
|
|
|
|
2011-01-14 13:51:41 -05:00
|
|
|
To run as '#{credential}', add the following to your resource config file: #{credentials_path}
|
2010-12-09 21:44:02 -05:00
|
|
|
An alternate file may be used by placing its path in the FOG_RC environment variable
|
|
|
|
|
|
|
|
#######################################################
|
2010-12-15 18:45:19 -05:00
|
|
|
# Fog Credentials File
|
2010-12-09 21:44:02 -05:00
|
|
|
#
|
|
|
|
# Key-value pairs should look like:
|
2010-12-15 18:45:19 -05:00
|
|
|
# :aws_access_key_id: 022QF06E7MXBSAMPLE
|
2010-12-10 17:18:44 -05:00
|
|
|
:#{credential}:
|
2010-12-15 18:45:19 -05:00
|
|
|
:aws_access_key_id:
|
|
|
|
:aws_secret_access_key:
|
|
|
|
:bluebox_api_key:
|
|
|
|
:bluebox_customer_id:
|
|
|
|
:brightbox_client_id:
|
|
|
|
:brightbox_secret:
|
|
|
|
:go_grid_api_key:
|
|
|
|
:go_grid_shared_secret:
|
|
|
|
:google_storage_access_key_id:
|
|
|
|
:google_storage_secret_access_key:
|
2011-01-14 14:01:02 -05:00
|
|
|
:linode_api_key:
|
2010-12-15 18:45:19 -05:00
|
|
|
:local_root:
|
|
|
|
:new_servers_password:
|
|
|
|
:new_servers_username:
|
|
|
|
:public_key_path:
|
|
|
|
:private_key_path:
|
|
|
|
:rackspace_api_key:
|
|
|
|
:rackspace_username:
|
|
|
|
:slicehost_password:
|
|
|
|
:terremark_username:
|
|
|
|
:terremark_password:
|
2011-01-19 15:47:35 -05:00
|
|
|
:voxel_api_key:
|
|
|
|
:voxel_api_secret:
|
2010-12-15 18:45:19 -05:00
|
|
|
:zerigo_email:
|
2010-12-21 16:45:53 -05:00
|
|
|
:zerigo_token:
|
2011-02-24 00:54:13 -05:00
|
|
|
:dnsimple_email:
|
|
|
|
:dnsimple_password:
|
2010-12-09 21:44:02 -05:00
|
|
|
#
|
2010-12-15 18:45:19 -05:00
|
|
|
# End of Fog Credentials File
|
2010-12-09 21:44:02 -05:00
|
|
|
#######################################################
|
|
|
|
|
|
|
|
YML
|
2010-04-02 13:14:37 -04:00
|
|
|
end
|
|
|
|
end
|