1
0
Fork 0
mirror of https://github.com/fog/fog.git synced 2022-11-09 13:51:43 -05:00
fog--fog/lib/fog/core/credentials.rb

62 lines
2.1 KiB
Ruby
Raw Normal View History

require 'yaml'
module Fog
class << self
def credential=(new_credential)
@credential = new_credential
@credentials = nil
end
def credential
@credential || :default
end
2010-05-14 02:50:34 +08:00
def config_path
ENV["FOG_RC"] || '~/.fog'
end
def credentials
@credentials ||= begin
2010-05-14 02:50:34 +08:00
path = File.expand_path(config_path)
credentials = if File.exists?(path)
File.open(path) do |file|
YAML.load(file.read)
end
else
nil
end
unless credentials && credentials[credential]
2010-05-14 02:50:34 +08:00
print("\n To run as '#{credential}', add the following to #{config_path}\n")
yml = <<-YML
:#{credential}:
:aws_access_key_id: INTENTIONALLY_LEFT_BLANK
:aws_secret_access_key: INTENTIONALLY_LEFT_BLANK
:bluebox_api_key: INTENTIONALLY_LEFT_BLANK
:bluebox_customer_id: INTENTIONALLY_LEFT_BLANK
:brightbox_client_id: INTENTIONALLY_LEFT_BLANK
:brightbox_secret: INTENTIONALLY_LEFT_BLANK
:go_grid_api_key: INTENTIONALLY_LEFT_BLANK
:go_grid_shared_secret: INTENTIONALLY_LEFT_BLANK
:google_storage_access_key_id: INTENTIONALLY_LEFT_BLANK
:google_storage_secret_access_key: INTENTIONALLY_LEFT_BLANK
:local_root: INTENTIONALLY_LEFT_BLANK
:new_servers_password: INTENTIONALLY_LEFT_BLANK
:new_servers_username: INTENTIONALLY_LEFT_BLANK
:public_key_path: INTENTIONALLY_LEFT_BLANK
:private_key_path: INTENTIONALLY_LEFT_BLANK
:rackspace_api_key: INTENTIONALLY_LEFT_BLANK
:rackspace_username: INTENTIONALLY_LEFT_BLANK
:slicehost_password: INTENTIONALLY_LEFT_BLANK
:terremark_username: INTENTIONALLY_LEFT_BLANK
:terremark_password: INTENTIONALLY_LEFT_BLANK
YML
This is a combination of 23 commits (included merges from upstream); this commit(s) include changes to enforces recognizes/requires parameters for all supported services. Comments from the included commits follow: - Added google_storage_* keys - Fixed indentations. - Factored out requires and recognizes method implementation (now relies on the requires and recognizes clause from the NamedParameters module) - Added dependency to named-parameters gem. - Added recognizes declaration to classes for all supported services to enforce parameter name checks - - passing an unrecognized key when instantiating a service object will now cause an ArgumentError to be raised. - Added NOTE - comment added - check/filter-out keys from credentials that are not required by the class being instantiated - [local|storage] properly write out file contents - Added google_storage_* keys - Fixed indentations. - added put_object_acl request (ref: https://github.com/geemus/fog/issues#issue/74) - Release 0.3.24 - remove tracker reference from README - issues is now the goto for bugs/todo - notify and gracefully skip credential-less testsa - [rackspace|storage] fixes for directory/files - [local|storage] CGI.escape file names - Release 0.3.25 - updated deps; recognized_parameters -> declared_parameters; restored options filtering if Fog.bin - Added requires/recognizes to Fog::Terremark::Ecloud - Updted to use latest named-parameters gem. - Filter out unwanted parameters when Fog.bin - Updated to latest named-parameters gem - commented out unnecessary code - fix missing "volume" parameter error when setting Fog::AWS::Volume#server to nil (in order to detach it) - documentation update for key_pairs and helper - [aws|compute] commented/documented flavors/volumes - Fixes for issue 38 and 39 Closes #96
2010-11-21 02:56:41 -08:00
print("\n#{yml}\n")
raise(ArgumentError.new("Missing Credentials"))
end
credentials[credential]
end
end
end
end