1
0
Fork 0
mirror of https://github.com/fog/fog.git synced 2022-11-09 13:51:43 -05:00

Refactor into Fog::Storage::Rackspace::Common.

Makes #get_object_http_url and #get_object_https_url work properly.
This commit is contained in:
Ash Wilson 2013-12-19 13:59:49 -05:00
parent c55cab59c7
commit 139f97ffc6
4 changed files with 69 additions and 66 deletions

View file

@ -2,8 +2,7 @@ module Fog
module Storage
class Rackspace
class Real
module Common
# Get an expiring object http url from Cloud Files
#
# ==== Parameters
@ -25,6 +24,14 @@ module Fog
end
end
class Real
include Common
end
class Mock
include Common
end
end
end
end

View file

@ -2,7 +2,7 @@ module Fog
module Storage
class Rackspace
class Real
module Common
# Get an expiring object https url from Cloud Files
#
@ -47,7 +47,14 @@ module Fog
h.size == 1 ? "0#{h}" : h
}.join
end
end
class Mock
include Common
end
class Real
include Common
end
end

View file

@ -42,7 +42,21 @@ module Fog
request :put_static_obj_manifest
request :post_set_meta_temp_url_key
module Utils
module Common
def apply_options(options)
@rackspace_api_key = options[:rackspace_api_key]
@rackspace_username = options[:rackspace_username]
@rackspace_cdn_ssl = options[:rackspace_cdn_ssl]
@rackspace_auth_url = options[:rackspace_auth_url]
@rackspace_servicenet = options[:rackspace_servicenet]
@rackspace_auth_token = options[:rackspace_auth_token]
@rackspace_storage_url = options[:rackspace_storage_url]
@rackspace_cdn_url = options[:rackspace_cdn_url]
@rackspace_region = options[:rackspace_region] || :dfw
@rackspace_temp_url_key = options[:rackspace_temp_url_key]
@rackspace_must_reauthenticate = false
@connection_options = options[:connection_options] || {}
end
def cdn
@cdn ||= Fog::CDN.new(
@ -59,10 +73,40 @@ module Fog
end
end
def service_net?
@rackspace_servicenet == true
end
def authenticate
if @rackspace_must_reauthenticate || @rackspace_auth_token.nil?
options = {
:rackspace_api_key => @rackspace_api_key,
:rackspace_username => @rackspace_username,
:rackspace_auth_url => @rackspace_auth_url,
:connection_options => @connection_options
}
super(options)
else
@auth_token = @rackspace_auth_token
@uri = URI.parse(@rackspace_storage_url)
end
end
def service_name
:cloudFiles
end
def request_id_header
"X-Trans-Id"
end
def region
@rackspace_region
end
end
class Mock < Fog::Rackspace::Service
include Utils
include Common
class MockContainer
attr_reader :objects, :meta
@ -125,9 +169,9 @@ module Fog
end
def initialize(options={})
@rackspace_api_key = options[:rackspace_api_key]
@rackspace_username = options[:rackspace_username]
@rackspace_cdn_ssl = options[:rackspace_cdn_ssl]
apply_options(options)
authenticate
endpoint_uri
end
def data
@ -138,38 +182,18 @@ module Fog
self.class.data.delete(@rackspace_username)
end
def service_name
:cloudFiles
end
def region
@rackspace_region
end
def ssl?
!!@rackspace_cdn_ssl
end
end
class Real < Fog::Rackspace::Service
include Utils
include Common
attr_reader :rackspace_cdn_ssl
def initialize(options={})
@rackspace_api_key = options[:rackspace_api_key]
@rackspace_username = options[:rackspace_username]
@rackspace_cdn_ssl = options[:rackspace_cdn_ssl]
@rackspace_auth_url = options[:rackspace_auth_url]
@rackspace_servicenet = options[:rackspace_servicenet]
@rackspace_auth_token = options[:rackspace_auth_token]
@rackspace_storage_url = options[:rackspace_storage_url]
@rackspace_cdn_url = options[:rackspace_cdn_url]
@rackspace_region = options[:rackspace_region] || :dfw
@rackspace_temp_url_key = options[:rackspace_temp_url_key]
@rackspace_must_reauthenticate = false
@connection_options = options[:connection_options] || {}
apply_options(options)
authenticate
@persistent = options[:persistent] || false
@ -208,37 +232,6 @@ module Fog
raise ServiceError.slurp(error, self)
end
def service_net?
@rackspace_servicenet == true
end
def authenticate
if @rackspace_must_reauthenticate || @rackspace_auth_token.nil?
options = {
:rackspace_api_key => @rackspace_api_key,
:rackspace_username => @rackspace_username,
:rackspace_auth_url => @rackspace_auth_url,
:connection_options => @connection_options
}
super(options)
else
@auth_token = @rackspace_auth_token
@uri = URI.parse(@rackspace_storage_url)
end
end
def service_name
:cloudFiles
end
def request_id_header
"X-Trans-Id"
end
def region
@rackspace_region
end
def endpoint_uri(service_endpoint_url=nil)
return @uri if @uri
super(@rackspace_storage_url || service_endpoint_url, :rackspace_storage_url)
@ -251,8 +244,8 @@ module Fog
endpoint_uri credentials['X-Storage-Url']
@auth_token = credentials['X-Auth-Token']
end
end
end
end
end

View file

@ -36,7 +36,6 @@ Shindo.tests('Fog::Storage[:rackspace] | object requests', ["rackspace"]) do
# an object key with no special characters
tests("#get_object_http_url('fogobjecttests', 'fog_object','expiration timestamp')").succeeds do
pending if Fog.mocking?
expires_at = 1344149532 # 2012-08-05 16:52:12 +1000
storage = Fog::Storage::Rackspace.new(:rackspace_temp_url_key => "super_secret")
storage.extend RackspaceStorageHelpers
@ -47,7 +46,6 @@ Shindo.tests('Fog::Storage[:rackspace] | object requests', ["rackspace"]) do
# an object key with no special characters
tests("#get_object_https_url('fogobjecttests', 'fog_object','expiration timestamp')").succeeds do
pending if Fog.mocking?
expires_at = 1344149532 # 2012-08-05 16:52:12 +1000
storage = Fog::Storage::Rackspace.new(:rackspace_temp_url_key => "super_secret")
storage.extend RackspaceStorageHelpers
@ -58,7 +56,6 @@ Shindo.tests('Fog::Storage[:rackspace] | object requests', ["rackspace"]) do
# an object key nested under a /
tests("#get_object_https_url('fogobjecttests', 'fog/object','expiration timestamp')").succeeds do
pending if Fog.mocking?
expires_at = 1344149532 # 2012-08-05 16:52:12 +1000
storage = Fog::Storage::Rackspace.new(:rackspace_temp_url_key => "super_secret")
storage.extend RackspaceStorageHelpers
@ -69,7 +66,6 @@ Shindo.tests('Fog::Storage[:rackspace] | object requests', ["rackspace"]) do
# an object key containing a -
tests("#get_object_https_url('fogobjecttests', 'fog-object','expiration timestamp')").succeeds do
pending if Fog.mocking?
expires_at = 1344149532 # 2012-08-05 16:52:12 +1000
storage = Fog::Storage::Rackspace.new(:rackspace_temp_url_key => "super_secret")
storage.extend RackspaceStorageHelpers