2009-10-21 21:49:17 +00:00
|
|
|
require 'rubygems'
|
|
|
|
require 'base64'
|
|
|
|
require 'cgi'
|
|
|
|
require 'digest/md5'
|
2009-11-16 22:31:17 +00:00
|
|
|
require 'excon'
|
2009-10-21 21:49:17 +00:00
|
|
|
require 'hmac-sha1'
|
|
|
|
require 'hmac-sha2'
|
|
|
|
require 'json'
|
|
|
|
require 'mime/types'
|
2009-11-03 02:47:24 +00:00
|
|
|
require 'nokogiri'
|
|
|
|
require 'time'
|
2009-10-21 21:49:17 +00:00
|
|
|
|
2009-09-14 04:24:22 +00:00
|
|
|
__DIR__ = File.dirname(__FILE__)
|
|
|
|
|
|
|
|
$LOAD_PATH.unshift __DIR__ unless
|
|
|
|
$LOAD_PATH.include?(__DIR__) ||
|
|
|
|
$LOAD_PATH.include?(File.expand_path(__DIR__))
|
|
|
|
|
2009-08-07 07:28:53 +00:00
|
|
|
module Fog
|
|
|
|
|
2010-02-02 06:53:18 +00:00
|
|
|
class MockNotImplemented < StandardError; end
|
|
|
|
|
2009-09-15 04:14:34 +00:00
|
|
|
def self.mock!
|
|
|
|
@mocking = true
|
|
|
|
self.reload
|
2009-08-10 15:30:28 +00:00
|
|
|
end
|
|
|
|
|
2009-08-07 07:28:53 +00:00
|
|
|
def self.mocking?
|
2009-08-10 15:30:28 +00:00
|
|
|
!!@mocking
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.reload
|
2009-10-31 19:26:49 +00:00
|
|
|
load "fog/collection.rb"
|
|
|
|
load "fog/connection.rb"
|
|
|
|
load "fog/model.rb"
|
|
|
|
load "fog/parser.rb"
|
|
|
|
|
2009-09-14 04:24:22 +00:00
|
|
|
load "fog/aws.rb"
|
2009-10-11 02:05:17 +00:00
|
|
|
load "fog/rackspace.rb"
|
2009-11-27 05:04:49 +00:00
|
|
|
load "fog/slicehost.rb"
|
2010-02-12 05:34:44 +00:00
|
|
|
load "fog/terremark.rb"
|
2009-08-07 07:28:53 +00:00
|
|
|
end
|
|
|
|
|
2010-01-26 00:21:38 +00:00
|
|
|
def self.credential=(new_credential)
|
|
|
|
@credential = new_credential
|
|
|
|
@credentials = nil
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.credential
|
|
|
|
@credential || :default
|
|
|
|
end
|
|
|
|
|
2010-01-22 03:47:40 +00:00
|
|
|
def self.credentials
|
2009-11-22 22:53:29 +00:00
|
|
|
@credentials ||= begin
|
2010-01-15 05:27:08 +00:00
|
|
|
path = File.expand_path('~/.fog')
|
2010-01-22 03:47:40 +00:00
|
|
|
credentials = if File.exists?(path)
|
2010-01-15 05:27:08 +00:00
|
|
|
File.open(path) do |file|
|
2010-01-22 03:47:40 +00:00
|
|
|
YAML.load(file.read)
|
2010-01-15 05:27:08 +00:00
|
|
|
end
|
|
|
|
else
|
|
|
|
nil
|
2009-11-22 22:53:29 +00:00
|
|
|
end
|
2010-01-28 04:28:37 +00:00
|
|
|
unless credentials && credentials[credential]
|
|
|
|
print("\n To run as '#{credential}', add credentials like the following to ~/.fog\n")
|
2010-01-22 03:47:40 +00:00
|
|
|
yml = <<-YML
|
|
|
|
|
2010-01-28 04:28:37 +00:00
|
|
|
:#{credential}:
|
2010-01-31 21:54:36 +00:00
|
|
|
:aws_access_key_id: INTENTIONALLY_LEFT_BLANK
|
2010-01-22 03:47:40 +00:00
|
|
|
:aws_secret_access_key: INTENTIONALLY_LEFT_BLANK
|
2010-01-31 21:54:36 +00:00
|
|
|
:rackspace_api_key: INTENTIONALLY_LEFT_BLANK
|
|
|
|
:rackspace_username: INTENTIONALLY_LEFT_BLANK
|
|
|
|
:slicehost_password: INTENTIONALLY_LEFT_BLANK
|
2010-02-12 05:34:44 +00:00
|
|
|
:terremark_username: INTENTIONALLY_LEFT_BLANK
|
|
|
|
:terremark_password: INTENTIONALLY_LEFT_BLANK
|
2010-01-22 03:47:40 +00:00
|
|
|
|
|
|
|
YML
|
|
|
|
print(yml)
|
2010-01-31 21:54:36 +00:00
|
|
|
raise(ArgumentError.new("Missing Credentials"))
|
2010-01-22 03:47:40 +00:00
|
|
|
end
|
2010-01-26 00:21:38 +00:00
|
|
|
credentials[credential]
|
2009-11-22 22:53:29 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2009-08-07 07:28:53 +00:00
|
|
|
end
|
2009-08-08 02:55:11 +00:00
|
|
|
|
2009-08-17 22:11:53 +00:00
|
|
|
Fog.reload
|