fog--fog/lib/fog.rb

87 lines
1.8 KiB
Ruby
Raw Normal View History

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'
require 'nokogiri'
require 'time'
2009-10-21 21:49:17 +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
class MockNotImplemented < StandardError; end
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
load "fog/collection.rb"
load "fog/connection.rb"
load "fog/model.rb"
load "fog/parser.rb"
load "fog/aws.rb"
2009-10-11 02:05:17 +00:00
load "fog/rackspace.rb"
load "fog/slicehost.rb"
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
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')
credentials = if File.exists?(path)
2010-01-15 05:27:08 +00:00
File.open(path) do |file|
YAML.load(file.read)
2010-01-15 05:27:08 +00:00
end
else
nil
2009-11-22 22:53:29 +00:00
end
unless credentials && credentials[credential]
print("\n To run as '#{credential}', add credentials like the following to ~/.fog\n")
yml = <<-YML
:#{credential}:
: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
:terremark_username: INTENTIONALLY_LEFT_BLANK
:terremark_password: INTENTIONALLY_LEFT_BLANK
YML
print(yml)
raise(ArgumentError.new("Missing Credentials"))
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-17 22:11:53 +00:00
Fog.reload