From fe480bbaa3f1f4ecb51d3712af6db20fa43173cd Mon Sep 17 00:00:00 2001 From: geemus Date: Wed, 29 Sep 2010 17:53:32 -0700 Subject: [PATCH] [eucalyptus] clean up some stuff to allow eucalyptus to use AWS::Compute --- lib/fog/aws.rb | 2 +- lib/fog/aws/compute.rb | 20 +++++++++++++++----- lib/fog/aws/elb.rb | 4 +++- lib/fog/aws/simpledb.rb | 4 +++- lib/fog/aws/storage.rb | 21 +++++++++++++++------ 5 files changed, 37 insertions(+), 14 deletions(-) diff --git a/lib/fog/aws.rb b/lib/fog/aws.rb index dfebe1248..a56fda75f 100644 --- a/lib/fog/aws.rb +++ b/lib/fog/aws.rb @@ -37,7 +37,7 @@ module Fog body << "#{key}=#{CGI.escape(value.to_s).gsub(/\+/, '%20')}&" end end - string_to_sign = "POST\n#{options[:host]}\n/\n" << body.chop + string_to_sign = "POST\n#{options[:host]}\n#{options[:path]}\n" << body.chop signed_string = options[:hmac].sign(string_to_sign) body << "Signature=#{CGI.escape(Base64.encode64(signed_string).chomp!).gsub(/\+/, '%20')}" diff --git a/lib/fog/aws/compute.rb b/lib/fog/aws/compute.rb index 7faea26b8..0663d01bd 100644 --- a/lib/fog/aws/compute.rb +++ b/lib/fog/aws/compute.rb @@ -153,8 +153,15 @@ module Fog @aws_access_key_id = options[:aws_access_key_id] @aws_secret_access_key = options[:aws_secret_access_key] @hmac = Fog::HMAC.new('sha256', @aws_secret_access_key) - options[:region] ||= 'us-east-1' - @host = options[:host] || case options[:region] + if @endpoint = options[:endpoint] + endpoint = URI.parse(@endpoint) + @host = endpoint.host + @path = endpoint.path + @port = endpoint.port + @scheme = endpoint.scheme + else + options[:region] ||= 'us-east-1' + @host = options[:host] || case options[:region] when 'ap-southeast-1' 'ec2.ap-southeast-1.amazonaws.com' when 'eu-west-1' @@ -166,9 +173,11 @@ module Fog else raise ArgumentError, "Unknown region: #{options[:region].inspect}" end - @port = options[:port] || 443 - @scheme = options[:scheme] || 'https' - @connection = Fog::Connection.new("#{@scheme}://#{@host}:#{@port}", options[:persistent]) + @path = options[:path] || '/' + @port = options[:port] || 443 + @scheme = options[:scheme] || 'https' + end + @connection = Fog::Connection.new("#{@scheme}://#{@host}:#{@port}#{@path}", options[:persistent]) end def reload @@ -187,6 +196,7 @@ module Fog :aws_access_key_id => @aws_access_key_id, :hmac => @hmac, :host => @host, + :path => @path, :version => '2010-08-31' } ) diff --git a/lib/fog/aws/elb.rb b/lib/fog/aws/elb.rb index 05610bc2f..230a39d86 100644 --- a/lib/fog/aws/elb.rb +++ b/lib/fog/aws/elb.rb @@ -59,9 +59,10 @@ module Fog else raise ArgumentError, "Unknown region: #{options[:region].inspect}" end + @path = options[:path] || '/' @port = options[:port] || 443 @scheme = options[:scheme] || 'https' - @connection = Fog::Connection.new("#{@scheme}://#{@host}:#{@port}", options[:persistent]) + @connection = Fog::Connection.new("#{@scheme}://#{@host}:#{@port}#{@path}", options[:persistent]) end def reload @@ -80,6 +81,7 @@ module Fog :aws_access_key_id => @aws_access_key_id, :hmac => @hmac, :host => @host, + :path => @path, :version => '2009-11-25' } ) diff --git a/lib/fog/aws/simpledb.rb b/lib/fog/aws/simpledb.rb index e571c7675..bd975defc 100644 --- a/lib/fog/aws/simpledb.rb +++ b/lib/fog/aws/simpledb.rb @@ -63,9 +63,10 @@ module Fog @hmac = Fog::HMAC.new('sha256', @aws_secret_access_key) @host = options[:host] || 'sdb.amazonaws.com' @nil_string = options[:nil_string]|| 'nil' + @path = options[:path] || '/' @port = options[:port] || 443 @scheme = options[:scheme] || 'https' - @connection = Fog::Connection.new("#{@scheme}://#{@host}:#{@port}", options[:persistent]) + @connection = Fog::Connection.new("#{@scheme}://#{@host}:#{@port}#{@path}", options[:persistent]) end private @@ -137,6 +138,7 @@ module Fog :aws_access_key_id => @aws_access_key_id, :hmac => @hmac, :host => @host, + :path => @path, :version => '2009-04-15' } ) diff --git a/lib/fog/aws/storage.rb b/lib/fog/aws/storage.rb index 90aa5cbd9..9ad7532f4 100644 --- a/lib/fog/aws/storage.rb +++ b/lib/fog/aws/storage.rb @@ -138,8 +138,15 @@ module Fog @aws_access_key_id = options[:aws_access_key_id] @aws_secret_access_key = options[:aws_secret_access_key] @hmac = Fog::HMAC.new('sha1', @aws_secret_access_key) - options[:region] ||= 'us-east-1' - @host = options[:host] || case options[:region] + if @endpoint = options[:endpoint] + endpoint = URI.parse(@endpoint) + @host = endpoint.host + @path = endpoint.path + @port = endpoint.port + @scheme = endpoint.scheme + else + options[:region] ||= 'us-east-1' + @host = options[:host] || case options[:region] when 'eu-west-1' 's3-eu-west-1.amazonaws.com' when 'us-east-1' @@ -151,9 +158,11 @@ module Fog else raise ArgumentError, "Unknown region: #{options[:region].inspect}" end - @port = options[:port] || 443 - @scheme = options[:scheme] || 'https' - @connection = Fog::Connection.new("#{@scheme}://#{@host}:#{@port}", options[:persistent] || true) + @path = options[:path] || '/' + @port = options[:port] || 443 + @scheme = options[:scheme] || 'https' + end + @connection = Fog::Connection.new("#{@scheme}://#{@host}:#{@port}#{@path}", options[:persistent] || true) end def reload @@ -213,7 +222,7 @@ DATA subdomain = nil end - canonical_resource = "/" + canonical_resource = @path unless subdomain.nil? || subdomain == @host canonical_resource << "#{CGI.escape(subdomain).downcase}/" end