mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
simplify credential management stuff for bin/fog
This commit is contained in:
parent
8901d97dd2
commit
47c53e06b0
2 changed files with 28 additions and 29 deletions
36
bin/fog
36
bin/fog
|
@ -5,20 +5,8 @@ require 'yaml'
|
||||||
|
|
||||||
module Fog
|
module Fog
|
||||||
module Credentials
|
module Credentials
|
||||||
key = (ARGV.first && :"#{ARGV.first}") || :default
|
credential = (ARGV.first && :"#{ARGV.first}") || :default
|
||||||
unless Fog.credentials(key)
|
unless Fog.credentials[credential]
|
||||||
print("\n To run as '#{key}', add credentials like the following to ~/.fog\n")
|
|
||||||
yml = <<-YML
|
|
||||||
|
|
||||||
:#{key}:
|
|
||||||
:aws_access_key_id: INTENTIONALLY_LEFT_BLANK
|
|
||||||
:aws_secret_access_key: INTENTIONALLY_LEFT_BLANK
|
|
||||||
:rackspace_api_key: INTENTIONALLY_LEFT_BLANK
|
|
||||||
:rackspace_username: INTENTIONALLY_LEFT_BLANK
|
|
||||||
:slicehost_password: INTENTIONALLY_LEFT_BLANK
|
|
||||||
|
|
||||||
YML
|
|
||||||
print(yml)
|
|
||||||
exit
|
exit
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -26,15 +14,13 @@ end
|
||||||
|
|
||||||
module AWS
|
module AWS
|
||||||
class << self
|
class << self
|
||||||
key = (ARGV.first && :"#{ARGV.first}") || :default
|
credential = (ARGV.first && :"#{ARGV.first}") || :default
|
||||||
if Fog.credentials(key)[:aws_access_key_id] && Fog.credentials(key)[:aws_secret_access_key]
|
if Fog.credentials[credential][:aws_access_key_id] && Fog.credentials[credential][:aws_secret_access_key]
|
||||||
|
|
||||||
def connections
|
def connections
|
||||||
@@connections ||= Hash.new do |hash, key|
|
@@connections ||= Hash.new do |hash, key|
|
||||||
credentials = {
|
credential = (ARGV.first && :"#{ARGV.first}") || :default
|
||||||
:aws_access_key_id => Fog.credentials[:aws_access_key_id],
|
credentials = Fog.credentials[credential]
|
||||||
:aws_secret_access_key => Fog.credentials[:aws_secret_access_key]
|
|
||||||
}
|
|
||||||
hash[key] = case key
|
hash[key] = case key
|
||||||
when :ec2
|
when :ec2
|
||||||
Fog::AWS::EC2.new(credentials)
|
Fog::AWS::EC2.new(credentials)
|
||||||
|
@ -86,15 +72,13 @@ end
|
||||||
|
|
||||||
module Rackspace
|
module Rackspace
|
||||||
class << self
|
class << self
|
||||||
key = (ARGV.first && :"#{ARGV.first}") || :default
|
credential = (ARGV.first && :"#{ARGV.first}") || :default
|
||||||
if Fog.credentials(key)[:rackspace_api_key] && Fog.credentials(key)[:rackspace_username]
|
if Fog.credentials[credential][:rackspace_api_key] && Fog.credentials[credential][:rackspace_username]
|
||||||
|
|
||||||
def connections
|
def connections
|
||||||
@@connections ||= Hash.new do |hash, key|
|
@@connections ||= Hash.new do |hash, key|
|
||||||
credentials = {
|
credential = (ARGV.first && :"#{ARGV.first}") || :default
|
||||||
:rackspace_api_key => Fog.credentials[:rackspace_api_key],
|
credentials = Fog.credentials[credential]
|
||||||
:rackspace_username => Fog.credentials[:rackspace_username]
|
|
||||||
}
|
|
||||||
hash[key] = case key
|
hash[key] = case key
|
||||||
when :files
|
when :files
|
||||||
Fog::Rackspace::Files.new(credentials)
|
Fog::Rackspace::Files.new(credentials)
|
||||||
|
|
21
lib/fog.rb
21
lib/fog.rb
|
@ -38,16 +38,31 @@ module Fog
|
||||||
load "fog/slicehost.rb"
|
load "fog/slicehost.rb"
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.credentials(key = :default)
|
def self.credentials
|
||||||
@credentials ||= begin
|
@credentials ||= begin
|
||||||
path = File.expand_path('~/.fog')
|
path = File.expand_path('~/.fog')
|
||||||
if File.exists?(path)
|
credentials = if File.exists?(path)
|
||||||
File.open(path) do |file|
|
File.open(path) do |file|
|
||||||
YAML.load(file.read)[key]
|
YAML.load(file.read)
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
nil
|
nil
|
||||||
end
|
end
|
||||||
|
unless credentials
|
||||||
|
print("\n To run as '#{key}', add credentials like the following to ~/.fog\n")
|
||||||
|
yml = <<-YML
|
||||||
|
|
||||||
|
:#{key}:
|
||||||
|
:aws_access_key_id: INTENTIONALLY_LEFT_BLANK
|
||||||
|
:aws_secret_access_key: INTENTIONALLY_LEFT_BLANK
|
||||||
|
:rackspace_api_key: INTENTIONALLY_LEFT_BLANK
|
||||||
|
:rackspace_username: INTENTIONALLY_LEFT_BLANK
|
||||||
|
:slicehost_password: INTENTIONALLY_LEFT_BLANK
|
||||||
|
|
||||||
|
YML
|
||||||
|
print(yml)
|
||||||
|
end
|
||||||
|
credentials
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue