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:
parent
7636b845b6
commit
0f77090963
3 changed files with 31 additions and 39 deletions
26
bin/fog
26
bin/fog
|
@ -3,28 +3,18 @@ require File.join(File.dirname(__FILE__), '..', 'lib', 'fog')
|
||||||
require 'irb'
|
require 'irb'
|
||||||
require 'yaml'
|
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
|
module AWS
|
||||||
class << self
|
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(
|
@@ec2 = Fog::AWS::EC2.new(
|
||||||
:aws_access_key_id => credentials[:aws_access_key_id],
|
:aws_access_key_id => Fog.credentials[:aws_access_key_id],
|
||||||
:aws_secret_access_key => credentials[:aws_secret_access_key]
|
:aws_secret_access_key => Fog.credentials[:aws_secret_access_key]
|
||||||
)
|
)
|
||||||
|
|
||||||
@@s3 = Fog::AWS::S3.new(
|
@@s3 = Fog::AWS::S3.new(
|
||||||
:aws_access_key_id => credentials[:aws_access_key_id],
|
:aws_access_key_id => Fog.credentials[:aws_access_key_id],
|
||||||
:aws_secret_access_key => credentials[:aws_secret_access_key]
|
:aws_secret_access_key => Fog.credentials[:aws_secret_access_key]
|
||||||
)
|
)
|
||||||
|
|
||||||
def addresses
|
def addresses
|
||||||
|
@ -61,11 +51,11 @@ end
|
||||||
|
|
||||||
module Rackspace
|
module Rackspace
|
||||||
class << self
|
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(
|
@@servers = Fog::Rackspace::Servers.new(
|
||||||
:rackspace_api_key => credentials[:rackspace_api_key],
|
:rackspace_api_key => Fog.credentials[:rackspace_api_key],
|
||||||
:rackspace_username => credentials[:rackspace_username]
|
:rackspace_username => Fog.credentials[:rackspace_username]
|
||||||
)
|
)
|
||||||
|
|
||||||
def flavors
|
def flavors
|
||||||
|
|
10
lib/fog.rb
10
lib/fog.rb
|
@ -37,6 +37,16 @@ module Fog
|
||||||
load "fog/rackspace.rb"
|
load "fog/rackspace.rb"
|
||||||
end
|
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
|
end
|
||||||
|
|
||||||
Fog.reload
|
Fog.reload
|
||||||
|
|
|
@ -3,56 +3,48 @@ require 'open-uri'
|
||||||
|
|
||||||
current_directory = File.dirname(__FILE__)
|
current_directory = File.dirname(__FILE__)
|
||||||
require "#{current_directory}/../lib/fog"
|
require "#{current_directory}/../lib/fog"
|
||||||
# Fog.mock!
|
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
|
|
||||||
|
|
||||||
def ec2
|
def ec2
|
||||||
Fog::AWS::EC2.new(
|
Fog::AWS::EC2.new(
|
||||||
:aws_access_key_id => credentials[:aws_access_key_id],
|
:aws_access_key_id => Fog.credentials[:aws_access_key_id],
|
||||||
:aws_secret_access_key => credentials[:aws_secret_access_key]
|
:aws_secret_access_key => Fog.credentials[:aws_secret_access_key]
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
def eu_s3
|
def eu_s3
|
||||||
Fog::AWS::S3.new(
|
Fog::AWS::S3.new(
|
||||||
:aws_access_key_id => credentials[:aws_access_key_id],
|
:aws_access_key_id => Fog.credentials[:aws_access_key_id],
|
||||||
:aws_secret_access_key => credentials[:aws_secret_access_key],
|
:aws_secret_access_key => Fog.credentials[:aws_secret_access_key],
|
||||||
:host => 's3-external-3.amazonaws.com'
|
:host => 's3-external-3.amazonaws.com'
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
def files
|
def files
|
||||||
Fog::Rackspace::Files.new(
|
Fog::Rackspace::Files.new(
|
||||||
:rackspace_api_key => credentials[:rackspace_api_key],
|
:rackspace_api_key => Fog.credentials[:rackspace_api_key],
|
||||||
:rackspace_username => credentials[:rackspace_username]
|
:rackspace_username => Fog.credentials[:rackspace_username]
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
def sdb
|
def sdb
|
||||||
Fog::AWS::SimpleDB.new(
|
Fog::AWS::SimpleDB.new(
|
||||||
:aws_access_key_id => credentials[:aws_access_key_id],
|
:aws_access_key_id => Fog.credentials[:aws_access_key_id],
|
||||||
:aws_secret_access_key => credentials[:aws_secret_access_key]
|
:aws_secret_access_key => Fog.credentials[:aws_secret_access_key]
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
def servers
|
def servers
|
||||||
Fog::Rackspace::Servers.new(
|
Fog::Rackspace::Servers.new(
|
||||||
:rackspace_api_key => credentials[:rackspace_api_key],
|
:rackspace_api_key => Fog.credentials[:rackspace_api_key],
|
||||||
:rackspace_username => credentials[:rackspace_username]
|
:rackspace_username => Fog.credentials[:rackspace_username]
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
def s3
|
def s3
|
||||||
Fog::AWS::S3.new(
|
Fog::AWS::S3.new(
|
||||||
:aws_access_key_id => credentials[:aws_access_key_id],
|
:aws_access_key_id => Fog.credentials[:aws_access_key_id],
|
||||||
:aws_secret_access_key => credentials[:aws_secret_access_key]
|
:aws_secret_access_key => Fog.credentials[:aws_secret_access_key]
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue