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

consolidate credentials parsing

This commit is contained in:
Wesley Beary 2009-11-22 14:53:29 -08:00
parent 7636b845b6
commit 0f77090963
3 changed files with 31 additions and 39 deletions

26
bin/fog
View file

@ -3,28 +3,18 @@ require File.join(File.dirname(__FILE__), '..', 'lib', 'fog')
require 'irb'
require 'yaml'
def credentials
@credentials ||= begin
if ARGV[0] && File.exists?(File.expand_path(ARGV[0]))
YAML.load(File.open(File.expand_path(ARGV[0])).read)
elsif File.exists?(File.expand_path('~/.fog'))
YAML.load(File.open(File.expand_path('~/.fog')).read)
end
end
end
module AWS
class << self
if credentials[:aws_access_key_id] && credentials[:aws_secret_access_key]
if Fog.credentials[:aws_access_key_id] && Fog.credentials[:aws_secret_access_key]
@@ec2 = Fog::AWS::EC2.new(
:aws_access_key_id => credentials[:aws_access_key_id],
:aws_secret_access_key => credentials[:aws_secret_access_key]
:aws_access_key_id => Fog.credentials[:aws_access_key_id],
:aws_secret_access_key => Fog.credentials[:aws_secret_access_key]
)
@@s3 = Fog::AWS::S3.new(
:aws_access_key_id => credentials[:aws_access_key_id],
:aws_secret_access_key => credentials[:aws_secret_access_key]
:aws_access_key_id => Fog.credentials[:aws_access_key_id],
:aws_secret_access_key => Fog.credentials[:aws_secret_access_key]
)
def addresses
@ -61,11 +51,11 @@ end
module Rackspace
class << self
if credentials[:rackspace_api_key] && credentials[:rackspace_username]
if Fog.credentials[:rackspace_api_key] && Fog.credentials[:rackspace_username]
@@servers = Fog::Rackspace::Servers.new(
:rackspace_api_key => credentials[:rackspace_api_key],
:rackspace_username => credentials[:rackspace_username]
:rackspace_api_key => Fog.credentials[:rackspace_api_key],
:rackspace_username => Fog.credentials[:rackspace_username]
)
def flavors

View file

@ -37,6 +37,16 @@ module Fog
load "fog/rackspace.rb"
end
def self.credentials(path = File.expand_path('~/.fog'))
@credentials ||= begin
credentials = {}
File.open(path) do |file|
credentials = YAML.load(file.read)
end
credentials
end
end
end
Fog.reload

View file

@ -3,56 +3,48 @@ require 'open-uri'
current_directory = File.dirname(__FILE__)
require "#{current_directory}/../lib/fog"
# Fog.mock!
def credentials
@credentials ||= begin
credentials_path = File.expand_path('~/.fog')
credentials_data = File.open(credentials_path).read
YAML.load(credentials_data)
end
end
Fog.mock!
def ec2
Fog::AWS::EC2.new(
:aws_access_key_id => credentials[:aws_access_key_id],
:aws_secret_access_key => credentials[:aws_secret_access_key]
:aws_access_key_id => Fog.credentials[:aws_access_key_id],
:aws_secret_access_key => Fog.credentials[:aws_secret_access_key]
)
end
def eu_s3
Fog::AWS::S3.new(
:aws_access_key_id => credentials[:aws_access_key_id],
:aws_secret_access_key => credentials[:aws_secret_access_key],
:aws_access_key_id => Fog.credentials[:aws_access_key_id],
:aws_secret_access_key => Fog.credentials[:aws_secret_access_key],
:host => 's3-external-3.amazonaws.com'
)
end
def files
Fog::Rackspace::Files.new(
:rackspace_api_key => credentials[:rackspace_api_key],
:rackspace_username => credentials[:rackspace_username]
:rackspace_api_key => Fog.credentials[:rackspace_api_key],
:rackspace_username => Fog.credentials[:rackspace_username]
)
end
def sdb
Fog::AWS::SimpleDB.new(
:aws_access_key_id => credentials[:aws_access_key_id],
:aws_secret_access_key => credentials[:aws_secret_access_key]
:aws_access_key_id => Fog.credentials[:aws_access_key_id],
:aws_secret_access_key => Fog.credentials[:aws_secret_access_key]
)
end
def servers
Fog::Rackspace::Servers.new(
:rackspace_api_key => credentials[:rackspace_api_key],
:rackspace_username => credentials[:rackspace_username]
:rackspace_api_key => Fog.credentials[:rackspace_api_key],
:rackspace_username => Fog.credentials[:rackspace_username]
)
end
def s3
Fog::AWS::S3.new(
:aws_access_key_id => credentials[:aws_access_key_id],
:aws_secret_access_key => credentials[:aws_secret_access_key]
:aws_access_key_id => Fog.credentials[:aws_access_key_id],
:aws_secret_access_key => Fog.credentials[:aws_secret_access_key]
)
end