2009-10-21 17:49:17 -04:00
|
|
|
require 'rubygems'
|
|
|
|
require 'base64'
|
|
|
|
require 'cgi'
|
|
|
|
require 'digest/md5'
|
2009-11-16 17:31:17 -05:00
|
|
|
require 'excon'
|
2009-10-21 17:49:17 -04:00
|
|
|
require 'hmac-sha1'
|
|
|
|
require 'hmac-sha2'
|
|
|
|
require 'json'
|
|
|
|
require 'mime/types'
|
2009-11-02 21:47:24 -05:00
|
|
|
require 'nokogiri'
|
|
|
|
require 'time'
|
2009-10-21 17:49:17 -04:00
|
|
|
|
2009-09-14 00:24:22 -04:00
|
|
|
__DIR__ = File.dirname(__FILE__)
|
|
|
|
|
|
|
|
$LOAD_PATH.unshift __DIR__ unless
|
|
|
|
$LOAD_PATH.include?(__DIR__) ||
|
|
|
|
$LOAD_PATH.include?(File.expand_path(__DIR__))
|
|
|
|
|
2009-08-07 03:28:53 -04:00
|
|
|
module Fog
|
|
|
|
|
2009-09-15 00:14:34 -04:00
|
|
|
def self.mock!
|
|
|
|
@mocking = true
|
|
|
|
self.reload
|
2009-08-10 11:30:28 -04:00
|
|
|
end
|
|
|
|
|
2009-08-07 03:28:53 -04:00
|
|
|
def self.mocking?
|
2009-08-10 11:30:28 -04:00
|
|
|
!!@mocking
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.reload
|
2009-10-31 15:26:49 -04:00
|
|
|
load "fog/collection.rb"
|
|
|
|
load "fog/connection.rb"
|
|
|
|
load "fog/model.rb"
|
|
|
|
load "fog/parser.rb"
|
|
|
|
|
2009-09-14 00:24:22 -04:00
|
|
|
load "fog/aws.rb"
|
2009-10-10 22:05:17 -04:00
|
|
|
load "fog/rackspace.rb"
|
2009-11-27 00:04:49 -05:00
|
|
|
load "fog/slicehost.rb"
|
2009-08-07 03:28:53 -04:00
|
|
|
end
|
|
|
|
|
2010-01-25 19:21:38 -05:00
|
|
|
def self.credential=(new_credential)
|
|
|
|
@credential = new_credential
|
|
|
|
@credentials = nil
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.credential
|
|
|
|
@credential || :default
|
|
|
|
end
|
|
|
|
|
2010-01-21 22:47:40 -05:00
|
|
|
def self.credentials
|
2009-11-22 17:53:29 -05:00
|
|
|
@credentials ||= begin
|
2010-01-15 00:27:08 -05:00
|
|
|
path = File.expand_path('~/.fog')
|
2010-01-21 22:47:40 -05:00
|
|
|
credentials = if File.exists?(path)
|
2010-01-15 00:27:08 -05:00
|
|
|
File.open(path) do |file|
|
2010-01-21 22:47:40 -05:00
|
|
|
YAML.load(file.read)
|
2010-01-15 00:27:08 -05:00
|
|
|
end
|
|
|
|
else
|
|
|
|
nil
|
2009-11-22 17:53:29 -05:00
|
|
|
end
|
2010-01-21 22:47:40 -05:00
|
|
|
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
|
2010-01-25 19:21:38 -05:00
|
|
|
credentials[credential]
|
2009-11-22 17:53:29 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2009-08-07 03:28:53 -04:00
|
|
|
end
|
2009-08-07 22:55:11 -04:00
|
|
|
|
2009-08-17 18:11:53 -04:00
|
|
|
Fog.reload
|