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

Merge pull request #1674 from rackspace/auth_deux

[Rackspace] update other services to use Auth 2.0
This commit is contained in:
Kyle Rames 2013-03-22 07:12:27 -07:00
commit 6576dd5b1f
20 changed files with 891 additions and 150 deletions

View file

@ -1,5 +1,6 @@
require 'fog/core'
require 'fog/rackspace/mock_data'
require 'fog/rackspace/service'
module Fog
module Rackspace
@ -89,6 +90,13 @@ module Fog
end
end
def self.normalize_url(endpoint)
return nil unless endpoint
str = endpoint.chomp " "
str = str.chomp "/"
str.downcase
end
# CGI.escape, but without special treatment on spaces
def self.escape(str,extra_exclude_chars = '')
str.gsub(/([^a-zA-Z0-9_.-#{extra_exclude_chars}]+)/) do

View file

@ -16,6 +16,8 @@ module Fog
requires :rackspace_api_key, :rackspace_username
recognizes :rackspace_auth_url
recognizes :rackspace_endpoint
recognizes :rackspace_region
recognizes :rackspace_block_storage_url
model_path 'fog/rackspace/models/block_storage'
model :volume
@ -43,7 +45,7 @@ module Fog
request :get_snapshot
request :list_snapshots
class Mock
class Mock < Fog::Rackspace::Service
include Fog::Rackspace::MockData
def initialize(options = {})
@ -67,26 +69,21 @@ module Fog
end
end
class Real
class Real < Fog::Rackspace::Service
def initialize(options = {})
@rackspace_api_key = options[:rackspace_api_key]
@rackspace_username = options[:rackspace_username]
@rackspace_auth_url = options[:rackspace_auth_url]
@rackspace_must_reauthenticate = false
@connection_options = options[:connection_options] || {}
endpoint = options[:rackspace_endpoint] || DFW_ENDPOINT
uri = URI.parse(endpoint)
@host = uri.host
@persistent = options[:persistent] || false
@path = uri.path
@port = uri.port
@scheme = uri.scheme
setup_custom_endpoint(options)
authenticate
@connection = Fog::Connection.new(uri.to_s, @persistent, @connection_options)
deprecation_warnings(options)
@persistent = options[:persistent] || false
@connection = Fog::Connection.new(endpoint_uri.to_s, @persistent, @connection_options)
end
def request(params)
@ -95,10 +92,10 @@ module Fog
:headers => {
'Content-Type' => 'application/json',
'Accept' => 'application/json',
'X-Auth-Token' => @auth_token
'X-Auth-Token' => auth_token
}.merge!(params[:headers] || {}),
:host => @host,
:path => "#{@path}/#{params[:path]}"
:host => endpoint_uri.host,
:path => "#{endpoint_uri.path}/#{params[:path]}"
}))
rescue Excon::Errors::NotFound => error
raise NotFound.slurp error
@ -115,19 +112,75 @@ module Fog
response
end
private
def authenticate
options = {
:rackspace_api_key => @rackspace_api_key,
:rackspace_api_key => @rackspace_api_key,
:rackspace_username => @rackspace_username,
:rackspace_auth_url => @rackspace_auth_url
}
credentials = Fog::Rackspace.authenticate(options, @connection_options)
@auth_token = credentials['X-Auth-Token']
account_id = credentials['X-Server-Management-Url'].match(/.*\/([\d]+)$/)[1]
@path = "#{@path}/#{account_id}"
super(options)
end
def service_name
:cloudBlockStorage
end
def region
@rackspace_region
end
def endpoint_uri(service_endpoint_url=nil)
@uri = super(@rackspace_endpoint || service_endpoint_url, :rackspace_block_storage_url)
end
private
def setup_custom_endpoint(options)
@rackspace_endpoint = Fog::Rackspace.normalize_url(options[:rackspace_block_storage_url] || options[:rackspace_endpoint])
if v2_authentication?
case @rackspace_endpoint
when DFW_ENDPOINT
@rackspace_endpoint = nil
@rackspace_region = :dfw
when ORD_ENDPOINT
@rackspace_endpoint = nil
@rackspace_region = :ord
when LON_ENDPOINT
@rackspace_endpoint = nil
@rackspace_region = :lon
else
@rackspace_region = options[:rackspace_region] || :dfw
end
else
#if we are using auth1 and the endpoint is not set, default to DFW_ENDPOINT for historical reasons
@rackspace_endpoint ||= DFW_ENDPOINT
end
end
def deprecation_warnings(options)
Fog::Logger.deprecation("The :rackspace_endpoint option is deprecated. Please use :rackspace_block_storage_url for custom endpoints") if options[:rackspace_endpoint]
if [DFW_ENDPOINT, ORD_ENDPOINT, LON_ENDPOINT].include?(@rackspace_endpoint) && v2_authentication?
regions = @identity_service.service_catalog.display_service_regions(service_name)
Fog::Logger.deprecation("Please specify region using :rackspace_region rather than :rackspace_endpoint. Valid region for :rackspace_region are #{regions}.")
end
end
def append_tenant_v1(credentials)
account_id = credentials['X-Server-Management-Url'].match(/.*\/([\d]+)$/)[1]
endpoint = @rackspace_endpoint || credentials['X-Server-Management-Url'] || DFW_ENDPOINT
@uri = URI.parse(endpoint)
@uri.path = "#{@uri.path}/#{account_id}"
end
def authenticate_v1(options)
credentials = Fog::Rackspace.authenticate(options, @connection_options)
append_tenant_v1 credentials
@auth_token = credentials['X-Auth-Token']
end
end
end
end

View file

@ -1,5 +1,4 @@
require 'fog/rackspace'
require 'fog/rackspace/service'
require 'fog/cdn'
module Fog

View file

@ -7,7 +7,7 @@ module Fog
requires :rackspace_api_key, :rackspace_username
recognizes :rackspace_auth_url, :rackspace_servicenet, :persistent
recognizes :rackspace_auth_token, :rackspace_management_url
recognizes :rackspace_auth_token, :rackspace_management_url, :rackspace_compute_v1_url, :rackspace_region
model_path 'fog/rackspace/models/compute'
model :flavor
@ -41,7 +41,7 @@ module Fog
request :server_action
request :update_server
class Mock
class Mock < Fog::Rackspace::Service
def self.data
@data ||= Hash.new do |hash, key|
@ -180,7 +180,7 @@ module Fog
end
class Real
class Real < Fog::Rackspace::Service
def initialize(options={})
@rackspace_api_key = options[:rackspace_api_key]
@ -188,13 +188,13 @@ module Fog
@rackspace_auth_url = options[:rackspace_auth_url]
@rackspace_servicenet = options[:rackspace_servicenet]
@rackspace_auth_token = options[:rackspace_auth_token]
@rackspace_management_url = options[:rackspace_management_url]
@rackspace_endpoint = Fog::Rackspace.normalize_url(options[:rackspace_compute_v1_url] || options[:rackspace_management_url])
@rackspace_must_reauthenticate = false
@connection_options = options[:connection_options] || {}
authenticate
Excon.ssl_verify_peer = false if options[:rackspace_servicenet] == true
Excon.defaults[:ssl_verify_peer] = false if service_net?
@persistent = options[:persistent] || false
@connection = Fog::Connection.new("#{@scheme}://#{@host}:#{@port}", @persistent, @connection_options)
@connection = Fog::Connection.new(endpoint_uri.to_s, @persistent, @connection_options)
end
def reload
@ -206,10 +206,10 @@ module Fog
response = @connection.request(params.merge({
:headers => {
'Content-Type' => 'application/json',
'X-Auth-Token' => @auth_token
'X-Auth-Token' => auth_token
}.merge!(params[:headers] || {}),
:host => @host,
:path => "#{@path}/#{params[:path]}",
:host => endpoint_uri.host,
:path => "#{endpoint_uri.path}/#{params[:path]}",
:query => ('ignore_awful_caching' << Time.now.to_i.to_s)
}))
rescue Excon::Errors::Unauthorized => error
@ -234,28 +234,53 @@ module Fog
response
end
private
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
}
credentials = Fog::Rackspace.authenticate(options, @connection_options)
@auth_token = credentials['X-Auth-Token']
uri = URI.parse(credentials['X-Server-Management-Url'])
else
@auth_token = @rackspace_auth_token
uri = URI.parse(@rackspace_management_url)
end
@host = @rackspace_servicenet == true ? "snet-#{uri.host}" : uri.host
@path = uri.path
@port = uri.port
@scheme = uri.scheme
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
}
super(options)
else
@auth_token = @rackspace_auth_token
@uri = URI.parse(@rackspace_endpoint)
end
end
def service_name
:cloudServers
end
def region
@rackspace_region
end
def endpoint_uri(service_endpoint_url=nil)
return @uri if @uri
@uri = super(@rackspace_endpoint || service_endpoint_url, :rackspace_compute_v1_url)
@uri.host = "snet-#{@uri.host}" if service_net?
@uri
end
private
def deprecation_warnings(options)
Fog::Logger.deprecation("The :rackspace_management_url option is deprecated. Please use :rackspace_compute_v1_url for custom endpoints") if options[:rackspace_management_url]
end
def authenticate_v1(options)
credentials = Fog::Rackspace.authenticate(options, @connection_options)
endpoint_uri credentials['X-Server-Management-Url']
@auth_token = credentials['X-Auth-Token']
end
end
end
end

View file

@ -1,6 +1,4 @@
require 'fog/compute'
require 'fog/rackspace/service'
module Fog
module Compute
@ -170,7 +168,7 @@ module Fog
private
def setup_custom_endpoint(options)
@rackspace_endpoint = options[:rackspace_compute_url] || options[:rackspace_endpoint]
@rackspace_endpoint = Fog::Rackspace.normalize_url(options[:rackspace_compute_url] || options[:rackspace_endpoint])
if v2_authentication?
case @rackspace_endpoint
@ -187,6 +185,9 @@ module Fog
# we are actually using a custom endpoint
@rackspace_region = options[:rackspace_region] || :dfw
end
else
#if we are using auth1 and the endpoint is not set, default to DFW_ENDPOINT for historical reasons
@rackspace_endpoint ||= DFW_ENDPOINT
end
end

View file

@ -16,6 +16,9 @@ module Fog
recognizes :rackspace_auth_url
recognizes :rackspace_auth_token
recognizes :rackspace_endpoint
recognizes :rackspace_region
recognizes :rackspace_database_url
model_path 'fog/rackspace/models/databases'
model :flavor
@ -49,32 +52,36 @@ module Fog
request :create_user
request :delete_user
class Mock
class Mock < Fog::Rackspace::Service
def request(params)
Fog::Mock.not_implemented
end
end
class Real
class Real < Fog::Rackspace::Service
def service_name
:cloudDatabases
end
def region
@rackspace_region
end
def initialize(options = {})
@rackspace_api_key = options[:rackspace_api_key]
@rackspace_username = options[:rackspace_username]
@rackspace_auth_url = options[:rackspace_auth_url]
@rackspace_must_reauthenticate = false
@connection_options = options[:connection_options] || {}
endpoint = options[:rackspace_endpoint] || DFW_ENDPOINT
uri = URI.parse(endpoint)
@host = uri.host
@persistent = options[:persistent] || false
@path = uri.path
@port = uri.port
@scheme = uri.scheme
setup_custom_endpoint(options)
authenticate
@connection = Fog::Connection.new(uri.to_s, @persistent, @connection_options)
deprecation_warnings(options)
@persistent = options[:persistent] || false
@connection = Fog::Connection.new(endpoint_uri.to_s, @persistent, @connection_options)
end
def request(params)
@ -83,10 +90,10 @@ module Fog
:headers => {
'Content-Type' => 'application/json',
'Accept' => 'application/json',
'X-Auth-Token' => @auth_token
'X-Auth-Token' => auth_token
}.merge!(params[:headers] || {}),
:host => @host,
:path => "#{@path}/#{params[:path]}"
:host => endpoint_uri.host,
:path => "#{endpoint_uri.path}/#{params[:path]}"
}))
rescue Excon::Errors::NotFound => error
raise NotFound.slurp error
@ -103,7 +110,9 @@ module Fog
response
end
private
def endpoint_uri(service_endpoint_url=nil)
@uri = super(@rackspace_endpoint || service_endpoint_url, :rackspace_database_url)
end
def authenticate
options = {
@ -111,10 +120,57 @@ module Fog
:rackspace_username => @rackspace_username,
:rackspace_auth_url => @rackspace_auth_url
}
credentials = Fog::Rackspace.authenticate(options, @connection_options)
@auth_token = credentials['X-Auth-Token']
super(options)
end
private
def setup_custom_endpoint(options)
@rackspace_endpoint = Fog::Rackspace.normalize_url(options[:rackspace_database_url] || options[:rackspace_endpoint])
if v2_authentication?
case @rackspace_endpoint
when DFW_ENDPOINT
@rackspace_endpoint = nil
@rackspace_region = :dfw
when ORD_ENDPOINT
@rackspace_endpoint = nil
@rackspace_region = :ord
when LON_ENDPOINT
@rackspace_endpoint = nil
@rackspace_region = :lon
else
# we are actually using a custom endpoint
@rackspace_region = options[:rackspace_region] || :dfw
end
else
#if we are using auth1 and the endpoint is not set, default to DFW_ENDPOINT for historical reasons
@rackspace_endpoint ||= DFW_ENDPOINT
end
end
def deprecation_warnings(options)
Fog::Logger.deprecation("The :rackspace_endpoint option is deprecated. Please use :rackspace_database_url for custom endpoints") if options[:rackspace_endpoint]
if [DFW_ENDPOINT, ORD_ENDPOINT, LON_ENDPOINT].include?(@rackspace_endpoint) && v2_authentication?
regions = @identity_service.service_catalog.display_service_regions(service_name)
Fog::Logger.deprecation("Please specify region using :rackspace_region rather than :rackspace_endpoint. Valid region for :rackspace_region are #{regions}.")
end
end
def append_tenant_v1(credentials)
account_id = credentials['X-Server-Management-Url'].match(/.*\/([\d]+)$/)[1]
@path = "#{@path}/#{account_id}"
endpoint = @rackspace_endpoint || credentials['X-Server-Management-Url'] || DFW_ENDPOINT
@uri = URI.parse(endpoint)
@uri.path = "#{@uri.path}/#{account_id}"
end
def authenticate_v1(options)
credentials = Fog::Rackspace.authenticate(options, @connection_options)
append_tenant_v1 credentials
@auth_token = credentials['X-Auth-Token']
end
end
end

View file

@ -18,7 +18,7 @@ module Fog
UK_ENDPOINT = 'https://lon.dns.api.rackspacecloud.com/v1.0'
requires :rackspace_api_key, :rackspace_username
recognizes :rackspace_auth_url, :rackspace_auth_token, :rackspace_dns_endpoint
recognizes :rackspace_auth_url, :rackspace_auth_token, :rackspace_dns_endpoint, :rackspace_dns_url, :rackspace_region
model_path 'fog/rackspace/models/dns'
model :record
@ -43,7 +43,7 @@ module Fog
request :remove_records
request :add_records
class Mock
class Mock < Fog::Rackspace::Service
def initialize(options={})
@rackspace_api_key = options[:rackspace_api_key]
@ -71,22 +71,38 @@ module Fog
end
class Real
class Real < Fog::Rackspace::Service
def service_name
:cloudDNS
end
def region
#Note: DNS does not currently support multiple regions
@rackspace_region
end
def initialize(options={})
@rackspace_api_key = options[:rackspace_api_key]
@rackspace_username = options[:rackspace_username]
@rackspace_auth_url = options[:rackspace_auth_url]
@connection_options = options[:connection_options] || {}
uri = URI.parse(options[:rackspace_dns_endpoint] || US_ENDPOINT)
@rackspace_endpoint = Fog::Rackspace.normalize_url(options[:rackspace_dns_url] || options[:rackspace_dns_endpoint])
@rackspace_region = options[:rackspace_region]
@auth_token, @account_id = *authenticate
@persistent = options[:persistent] || false
@path = "#{uri.path}/#{@account_id}"
authenticate
deprecation_warnings(options)
@connection_options[:headers] ||= {}
@connection_options[:headers].merge!({ 'Content-Type' => 'application/json', 'X-Auth-Token' => @auth_token })
@connection_options[:headers].merge!({ 'Content-Type' => 'application/json', 'X-Auth-Token' => auth_token })
@connection = Fog::Connection.new(uri.to_s, @persistent, @connection_options)
@persistent = options[:persistent] || false
@connection = Fog::Connection.new(endpoint_uri.to_s, @persistent, @connection_options)
end
def endpoint_uri(service_endpoint_url=nil)
@uri = super(@rackspace_endpoint || service_endpoint_url, :rackspace_dns_url)
end
private
@ -95,7 +111,7 @@ module Fog
#TODO - Unify code with other rackspace services
begin
response = @connection.request(params.merge!({
:path => "#{@path}/#{params[:path]}"
:path => "#{endpoint_uri.path}/#{params[:path]}"
}))
rescue Excon::Errors::BadRequest => error
raise Fog::Rackspace::Errors::BadRequest.slurp error
@ -112,18 +128,6 @@ module Fog
response
end
def authenticate
options = {
:rackspace_api_key => @rackspace_api_key,
:rackspace_username => @rackspace_username,
:rackspace_auth_url => @rackspace_auth_url
}
credentials = Fog::Rackspace.authenticate(options, @connection_options)
auth_token = credentials['X-Auth-Token']
account_id = credentials['X-Server-Management-Url'].match(/.*\/([\d]+)$/)[1]
[auth_token, account_id]
end
def array_to_query_string(arr)
arr.collect {|k,v| "#{k}=#{v}" }.join('&')
end
@ -133,6 +137,35 @@ module Fog
raise ArgumentError.new("#{name} cannot be null or empty")
end
end
private
def deprecation_warnings(options)
Fog::Logger.deprecation("The :rackspace_dns_endpoint option is deprecated. Please use :rackspace_dns_url for custom endpoints") if options[:rackspace_dns_endpoint]
end
def setup_endpoint(credentials)
account_id = credentials['X-Server-Management-Url'].match(/.*\/([\d]+)$/)[1]
@uri = URI.parse(@rackspace_endpoint || US_ENDPOINT)
@uri.path = "#{@uri.path}/#{account_id}"
end
def authenticate_v1(options)
credentials = Fog::Rackspace.authenticate(options, @connection_options)
setup_endpoint credentials
@auth_token = credentials['X-Auth-Token']
end
def authenticate
options = {
:rackspace_api_key => @rackspace_api_key,
:rackspace_username => @rackspace_username,
:rackspace_auth_url => @rackspace_auth_url
}
super(options)
end
end
end
end

View file

@ -58,7 +58,7 @@ compute_service = Fog::Compute.new({
cbs_service = Fog::Rackspace::BlockStorage.new({
:rackspace_username => rackspace_username,
:rackspace_api_key => rackspace_api_key,
:rackspace_endpoint => Fog::Rackspace::BlockStorage::ORD_ENDPOINT #Use Chicago Region
:rackspace_region => :ord #Use Chicago Region
})
# retrieve list of servers

View file

@ -9,14 +9,16 @@ module Fog
class InternalServerError < Fog::Rackspace::Errors::InternalServerError; end
class BadRequest < Fog::Rackspace::Errors::BadRequest; end
DFW_ENDPOINT = 'https://dfw.loadbalancers.api.rackspacecloud.com/v1.0/'
ORD_ENDPOINT = 'https://ord.loadbalancers.api.rackspacecloud.com/v1.0/'
LON_ENDPOINT = 'https://lon.loadbalancers.api.rackspacecloud.com/v1.0/'
DFW_ENDPOINT = 'https://dfw.loadbalancers.api.rackspacecloud.com/v1.0'
ORD_ENDPOINT = 'https://ord.loadbalancers.api.rackspacecloud.com/v1.0'
LON_ENDPOINT = 'https://lon.loadbalancers.api.rackspacecloud.com/v1.0'
requires :rackspace_api_key, :rackspace_username
recognizes :rackspace_auth_url
recognizes :rackspace_auth_token
recognizes :rackspace_lb_endpoint
recognizes :rackspace_load_balancers_url
recognizes :rackspace_region
model_path 'fog/rackspace/models/load_balancers'
collection :load_balancers
@ -87,7 +89,7 @@ module Fog
end
class Mock
class Mock < Fog::Rackspace::Service
include Shared
def initialize(options={})
@ -98,7 +100,7 @@ module Fog
end
class Real
class Real < Fog::Rackspace::Service
include Shared
def initialize(options={})
@ -107,16 +109,13 @@ module Fog
@rackspace_auth_url = options[:rackspace_auth_url]
@rackspace_must_reauthenticate = false
@connection_options = options[:connection_options] || {}
uri = URI.parse(options[:rackspace_lb_endpoint] || DFW_ENDPOINT)
@host = uri.host
@persistent = options[:persistent] || false
@path = uri.path.end_with?('/') ? uri.path.chop : uri.path
@port = uri.port
@scheme = uri.scheme
setup_custom_endpoint(options)
authenticate
@connection = Fog::Connection.new(uri.to_s, @persistent, @connection_options)
@persistent = options[:persistent] || false
@connection = Fog::Connection.new(endpoint_uri.to_s, @persistent, @connection_options)
end
def request(params)
@ -126,10 +125,10 @@ module Fog
:headers => {
'Content-Type' => 'application/json',
'Accept' => 'application/json',
'X-Auth-Token' => @auth_token
'X-Auth-Token' => auth_token
}.merge!(params[:headers] || {}),
:host => @host,
:path => "#{@path}/#{params[:path]}"
:host => endpoint_uri.host,
:path => "#{endpoint_uri.path}/#{params[:path]}"
}))
rescue Excon::Errors::NotFound => error
raise NotFound.slurp error
@ -148,15 +147,74 @@ module Fog
def authenticate
options = {
:rackspace_api_key => @rackspace_api_key,
:rackspace_api_key => @rackspace_api_key,
:rackspace_username => @rackspace_username,
:rackspace_auth_url => @rackspace_auth_url
}
credentials = Fog::Rackspace.authenticate(options, @connection_options)
@auth_token = credentials['X-Auth-Token']
account_id = credentials['X-Server-Management-Url'].match(/.*\/([\d]+)$/)[1]
@path = "#{@path}/#{account_id}"
super(options)
end
def service_name
:cloudLoadBalancers
end
def region
@rackspace_region
end
def endpoint_uri(service_endpoint_url=nil)
@uri = super(@rackspace_endpoint || service_endpoint_url, :rackspace_load_balancers_url)
end
private
def setup_custom_endpoint(options)
@rackspace_endpoint = Fog::Rackspace.normalize_url(options[:rackspace_load_balancers_url] || options[:rackspace_lb_endpoint])
if v2_authentication?
case @rackspace_endpoint
when DFW_ENDPOINT
@rackspace_endpoint = nil
@rackspace_region = :dfw
when ORD_ENDPOINT
@rackspace_endpoint = nil
@rackspace_region = :ord
when LON_ENDPOINT
@rackspace_endpoint = nil
@rackspace_region = :lon
else
# we are actually using a custom endpoint
@rackspace_region = options[:rackspace_region] || :dfw
end
else
#if we are using auth1 and the endpoint is not set, default to DFW_ENDPOINT for historical reasons
@rackspace_endpoint ||= DFW_ENDPOINT
end
end
def deprecation_warnings(options)
Fog::Logger.deprecation("The :rackspace_lb_endpoint option is deprecated. Please use :rackspace_load_balancers_url for custom endpoints") if options[:rackspace_lb_endpoint]
if [DFW_ENDPOINT, ORD_ENDPOINT, LON_ENDPOINT].include?(@rackspace_endpoint) && v2_authentication?
regions = @identity_service.service_catalog.display_service_regions(service_name)
Fog::Logger.deprecation("Please specify region using :rackspace_region rather than :rackspace_endpoint. Valid regions for :rackspace_region are #{regions}.")
end
end
def append_tenant_v1(credentials)
account_id = credentials['X-Server-Management-Url'].match(/.*\/([\d]+)$/)[1]
endpoint = @rackspace_endpoint || credentials['X-Server-Management-Url'] || DFW_ENDPOINT
@uri = URI.parse(endpoint)
@uri.path = "#{@uri.path}/#{account_id}"
end
def authenticate_v1(options)
credentials = Fog::Rackspace.authenticate(options, @connection_options)
append_tenant_v1 credentials
@auth_token = credentials['X-Auth-Token']
end
end
end
end

View file

@ -1,5 +1,4 @@
require 'fog/rackspace'
require 'fog/rackspace/service'
require 'fog/storage'
module Fog
@ -194,6 +193,8 @@ module Fog
end
def endpoint_uri(service_endpoint_url=nil)
return @uri if @uri
@uri = super(@rackspace_storage_url || service_endpoint_url, :rackspace_storage_url)
@uri.host = "snet-#{@uri.host}" if service_net?
@uri

View file

@ -0,0 +1,101 @@
Shindo.tests('Fog::Rackspace::BlockStorage', ['rackspace']) do
def assert_method(url, method)
@service.instance_variable_set "@rackspace_auth_url", url
returns(method) { @service.send :authentication_method }
end
tests('#authentication_method') do
@service = Fog::Rackspace::BlockStorage.new
assert_method nil, :authenticate_v2
assert_method 'auth.api.rackspacecloud.com', :authenticate_v1 # chef's default auth endpoint
assert_method 'https://identity.api.rackspacecloud.com', :authenticate_v1
assert_method 'https://identity.api.rackspacecloud.com/v1', :authenticate_v1
assert_method 'https://identity.api.rackspacecloud.com/v1.1', :authenticate_v1
assert_method 'https://identity.api.rackspacecloud.com/v2.0', :authenticate_v2
assert_method 'https://lon.identity.api.rackspacecloud.com', :authenticate_v1
assert_method 'https://lon.identity.api.rackspacecloud.com/v1', :authenticate_v1
assert_method 'https://lon.identity.api.rackspacecloud.com/v1.1', :authenticate_v1
assert_method 'https://lon.identity.api.rackspacecloud.com/v2.0', :authenticate_v2
end
tests('legacy authentication') do
pending if Fog.mocking?
tests('variables populated').succeeds do
@service = Fog::Rackspace::BlockStorage.new :rackspace_auth_url => 'https://identity.api.rackspacecloud.com/v1.0'
returns(true, "auth token populated") { !@service.send(:auth_token).nil? }
returns(false, "path populated") { @service.instance_variable_get("@uri").path.nil? }
returns(true, "identity_service was not used") { @service.instance_variable_get("@identity_service").nil? }
@service.list_volumes
end
tests('custom endpoint') do
@service = Fog::Rackspace::BlockStorage.new :rackspace_auth_url => 'https://identity.api.rackspacecloud.com/v1.0',
:rackspace_block_storage_url => 'https://my-custom-endpoint.com'
returns(true, "auth token populated") { !@service.send(:auth_token).nil? }
returns(true, "uses custom endpoint") { (@service.instance_variable_get("@uri").host =~ /my-custom-endpoint\.com/) != nil }
end
end
tests('current authentation') do
pending if Fog.mocking?
tests('variables populated').succeeds do
@service = Fog::Rackspace::BlockStorage.new :rackspace_auth_url => 'https://identity.api.rackspacecloud.com/v2.0'
returns(true, "auth token populated") { !@service.send(:auth_token).nil? }
returns(false, "path populated") { @service.instance_variable_get("@uri").host.nil? }
returns(false, "identity service was used") { @service.instance_variable_get("@identity_service").nil? }
@service.list_volumes
end
tests('dfw region').succeeds do
@service = Fog::Rackspace::BlockStorage.new :rackspace_auth_url => 'https://identity.api.rackspacecloud.com/v2.0', :rackspace_region => :dfw
returns(true, "auth token populated") { !@service.send(:auth_token).nil? }
returns(true) { (@service.instance_variable_get("@uri").host =~ /dfw/) != nil }
@service.list_volumes
end
tests('ord region').succeeds do
@service = Fog::Rackspace::BlockStorage.new :rackspace_auth_url => 'https://identity.api.rackspacecloud.com/v2.0', :rackspace_region => :ord
returns(true, "auth token populated") { !@service.send(:auth_token).nil? }
returns(true) { (@service.instance_variable_get("@uri").host =~ /ord/) != nil }
@service.list_volumes
end
tests('custom endpoint') do
@service = Fog::Rackspace::BlockStorage.new :rackspace_auth_url => 'https://identity.api.rackspacecloud.com/v2.0',
:rackspace_block_storage_url => 'https://my-custom-endpoint.com'
returns(true, "auth token populated") { !@service.send(:auth_token).nil? }
returns(true, "uses custom endpoint") { (@service.instance_variable_get("@uri").host =~ /my-custom-endpoint\.com/) != nil }
end
end
tests('default auth') do
pending if Fog.mocking?
tests('no params').succeeds do
@service = Fog::Rackspace::BlockStorage.new
returns(true, "auth token populated") { !@service.send(:auth_token).nil? }
returns(true) { (@service.instance_variable_get("@uri").host =~ /dfw/) != nil }
@service.list_volumes
end
tests('specify old contstant style service endoint').succeeds do
@service = Fog::Rackspace::BlockStorage.new :rackspace_endpoint => Fog::Rackspace::BlockStorage::ORD_ENDPOINT
@service.list_volumes
end
tests('specify region') do
@service = Fog::Rackspace::BlockStorage.new :rackspace_region => :ord
returns(true, "auth token populated") { !@service.send(:auth_token).nil? }
returns(true) { (@service.instance_variable_get("@uri").host =~ /ord/ ) != nil }
@service.list_volumes
end
tests('custom endpoint') do
@service = Fog::Rackspace::BlockStorage.new :rackspace_block_storage_url => 'https://my-custom-endpoint.com'
returns(true, "auth token populated") { !@service.send(:auth_token).nil? }
returns(true, "uses custom endpoint") { (@service.instance_variable_get("@uri").host =~ /my-custom-endpoint\.com/) != nil }
end
end
end

View file

@ -23,12 +23,13 @@ Shindo.tests('Fog::CDN::Rackspace', ['rackspace']) do
tests('authentication v1') do
pending if Fog.mocking?
@service = Fog::CDN::Rackspace.new :rackspace_auth_url => 'https://identity.api.rackspacecloud.com/v1.0'
tests('variables populated') do
tests('variables populated').succeeds do
@service = Fog::CDN::Rackspace.new :rackspace_auth_url => 'https://identity.api.rackspacecloud.com/v1.0'
returns(true, "auth token populated") { !@service.send(:auth_token).nil? }
returns(false, "path populated") { @service.instance_variable_get("@uri").path.nil? }
returns(true, "identity_service was not used") { @service.instance_variable_get("@identity_service").nil? }
returns(true, "identity_service was not used") { @service.instance_variable_get("@identity_service").nil? }
@service.get_containers
end
tests('custom endpoint') do
@service = Fog::CDN::Rackspace.new :rackspace_auth_url => 'https://identity.api.rackspacecloud.com/v1.0',
@ -38,24 +39,27 @@ Shindo.tests('Fog::CDN::Rackspace', ['rackspace']) do
end
end
tests('authentation v2') do
tests('authentication v2') do
pending if Fog.mocking?
@service = Fog::CDN::Rackspace.new :rackspace_auth_url => 'https://identity.api.rackspacecloud.com/v2.0'
tests('variables populated') do
tests('variables populated').succeeds do
@service = Fog::CDN::Rackspace.new :rackspace_auth_url => 'https://identity.api.rackspacecloud.com/v2.0'
returns(true, "auth token populated") { !@service.send(:auth_token).nil? }
returns(false, "path populated") { @service.instance_variable_get("@uri").path.nil? }
returns(false, "identity service was used") { @service.instance_variable_get("@identity_service").nil? }
returns(false, "identity service was used") { @service.instance_variable_get("@identity_service").nil? }
@service.get_containers
end
tests('dfw region') do
tests('dfw region').succeeds do
@service = Fog::CDN::Rackspace.new :rackspace_auth_url => 'https://identity.api.rackspacecloud.com/v2.0', :rackspace_region => :dfw
returns(true, "auth token populated") { !@service.send(:auth_token).nil? }
returns(true) { (@service.instance_variable_get("@uri").host =~ /cdn1/) != nil }
@service.get_containers
end
tests('ord region') do
tests('ord region').succeeds do
@service = Fog::CDN::Rackspace.new :rackspace_auth_url => 'https://identity.api.rackspacecloud.com/v2.0', :rackspace_region => :ord
returns(true, "auth token populated") { !@service.send(:auth_token).nil? }
returns(true) { (@service.instance_variable_get("@uri").host =~ /cdn2/) != nil }
@service.get_containers
end
tests('custom endpoint') do
@service = Fog::CDN::Rackspace.new :rackspace_auth_url => 'https://identity.api.rackspacecloud.com/v2.0',
@ -68,16 +72,18 @@ Shindo.tests('Fog::CDN::Rackspace', ['rackspace']) do
tests('default auth') do
pending if Fog.mocking?
tests('no params') do
tests('no params').succeeds do
@service = Fog::CDN::Rackspace.new
returns(true, "auth token populated") { !@service.send(:auth_token).nil? }
returns(true, "uses DFW") { (@service.instance_variable_get("@uri").host =~ /cdn1/) != nil }
@service.get_containers
end
tests('specify region') do
tests('specify region').succeeds do
@service = Fog::CDN::Rackspace.new :rackspace_region => :ord
returns(true, "auth token populated") { !@service.send(:auth_token).nil? }
returns(true) { (@service.instance_variable_get("@uri").host =~ /cdn2/) != nil }
@service.get_containers
end
tests('custom endpoint') do

View file

@ -0,0 +1,88 @@
Shindo.tests('Rackspace | Compute', ['rackspace']) do
def assert_method(url, method)
@service.instance_variable_set "@rackspace_auth_url", url
returns(method) { @service.send :authentication_method }
end
tests('#authentication_method') do
@service = Fog::Compute::Rackspace.new
assert_method nil, :authenticate_v2
assert_method 'https://identity.api.rackspacecloud.com', :authenticate_v1
assert_method 'https://identity.api.rackspacecloud.com/v1', :authenticate_v1
assert_method 'https://identity.api.rackspacecloud.com/v1.1', :authenticate_v1
assert_method 'https://identity.api.rackspacecloud.com/v2.0', :authenticate_v2
assert_method 'https://lon.identity.api.rackspacecloud.com', :authenticate_v1
assert_method 'https://lon.identity.api.rackspacecloud.com/v1', :authenticate_v1
assert_method 'https://lon.identity.api.rackspacecloud.com/v1.1', :authenticate_v1
assert_method 'https://lon.identity.api.rackspacecloud.com/v2.0', :authenticate_v2
end
tests('authentication v1') do
pending if Fog.mocking?
tests('variables populated').succeeds do
@service = Fog::Compute::Rackspace.new :rackspace_auth_url => 'https://identity.api.rackspacecloud.com/v1.0'
returns(true, "auth token populated") { !@service.send(:auth_token).nil? }
returns(false, "path populated") { @service.instance_variable_get("@uri").nil? }
returns(true, "identity_service was not used") { @service.instance_variable_get("@identity_service").nil? }
@service.list_flavors
end
tests('custom endpoint') do
@service = Fog::Compute::Rackspace.new :rackspace_auth_url => 'https://identity.api.rackspacecloud.com/v1.0',
:rackspace_compute_v1_url => 'https://my-custom-endpoint.com'
returns(false, "auth token populated") { @service.send(:auth_token).nil? }
returns(true, "uses custom endpoint") { (@service.instance_variable_get("@uri").host =~ /my-custom-endpoint\.com/) != nil }
end
end
tests('authentication v2') do
pending if Fog.mocking?
tests('variables populated').succeeds do
@service = Fog::Compute::Rackspace.new :rackspace_auth_url => 'https://identity.api.rackspacecloud.com/v2.0'
returns(true, "auth token populated") { !@service.send(:auth_token).nil? }
returns(true) { (@service.instance_variable_get("@uri").host == 'servers.api.rackspacecloud.com') != nil }
returns(false, "identity service was used") { @service.instance_variable_get("@identity_service").nil? }
@service.list_flavors
end
tests('custom endpoint') do
@service = Fog::Compute::Rackspace.new :rackspace_auth_url => 'https://identity.api.rackspacecloud.com/v2.0',
:rackspace_compute_v1_url => 'https://my-custom-endpoint.com'
returns(true, "auth token populated") { !@service.send(:auth_token).nil? }
returns(true, "uses custom endpoint") { (@service.instance_variable_get("@uri").host =~ /my-custom-endpoint\.com/) != nil }
end
end
tests('default auth') do
pending if Fog.mocking?
tests('no params').succeeds do
@service = Fog::Compute::Rackspace.new
returns(true, "auth token populated") { !@service.send(:auth_token).nil? }
returns(true) { (@service.instance_variable_get("@uri").host == 'servers.api.rackspacecloud.com') != nil }
@service.list_flavors
end
tests('specify region').succeeds do
@service = Fog::Compute::Rackspace.new :rackspace_region => :ord
returns(true, "auth token populated") { !@service.send(:auth_token).nil? }
returns(true) { (@service.instance_variable_get("@uri").host == 'servers.api.rackspacecloud.com') != nil }
@service.list_flavors
end
tests('custom endpoint') do
@service = Fog::Compute::Rackspace.new :rackspace_compute_v1_url => 'https://my-custom-endpoint.com'
returns(true, "auth token populated") { !@service.send(:auth_token).nil? }
returns(true, "uses custom endpoint") { (@service.instance_variable_get("@uri").host =~ /my-custom-endpoint\.com/) != nil }
end
tests('rackspace_servicenet') do
@service = Fog::Compute::Rackspace.new :rackspace_servicenet => true
returns(true, "auth token populated") { !@service.send(:auth_token).nil? }
returns(true, "uses custom endpoint") { (@service.instance_variable_get("@uri").host =~ /snet-/) != nil }
end
end
end

View file

@ -25,12 +25,13 @@ Shindo.tests('Fog::Compute::RackspaceV2', ['rackspace']) do
tests('legacy authentication') do
pending if Fog.mocking?
@service = Fog::Compute::RackspaceV2.new :rackspace_auth_url => 'https://identity.api.rackspacecloud.com/v1.0'
tests('variables populated') do
tests('variables populated').succeeds do
@service = Fog::Compute::RackspaceV2.new :rackspace_auth_url => 'https://identity.api.rackspacecloud.com/v1.0'
returns(true, "auth token populated") { !@service.send(:auth_token).nil? }
returns(false, "path populated") { @service.instance_variable_get("@uri").path.nil? }
returns(true, "identity_service was not used") { @service.instance_variable_get("@identity_service").nil? }
@service.list_flavors
end
tests('custom endpoint') do
@ -43,22 +44,25 @@ Shindo.tests('Fog::Compute::RackspaceV2', ['rackspace']) do
tests('current authentation') do
pending if Fog.mocking?
@service = Fog::Compute::RackspaceV2.new :rackspace_auth_url => 'https://identity.api.rackspacecloud.com/v2.0'
tests('variables populated') do
tests('variables populated').succeeds do
@service = Fog::Compute::RackspaceV2.new :rackspace_auth_url => 'https://identity.api.rackspacecloud.com/v2.0'
returns(true, "auth token populated") { !@service.send(:auth_token).nil? }
returns(false, "path populated") { @service.instance_variable_get("@uri").host.nil? }
returns(false, "identity service was used") { @service.instance_variable_get("@identity_service").nil? }
returns(false, "identity service was used") { @service.instance_variable_get("@identity_service").nil? }
@service.list_flavors
end
tests('dfw region') do
tests('dfw region').succeeds do
@service = Fog::Compute::RackspaceV2.new :rackspace_auth_url => 'https://identity.api.rackspacecloud.com/v2.0', :rackspace_region => :dfw
returns(true, "auth token populated") { !@service.send(:auth_token).nil? }
returns(true) { (@service.instance_variable_get("@uri").host =~ /dfw/) != nil }
@service.list_flavors
end
tests('ord region') do
tests('ord region').succeeds do
@service = Fog::Compute::RackspaceV2.new :rackspace_auth_url => 'https://identity.api.rackspacecloud.com/v2.0', :rackspace_region => :ord
returns(true, "auth token populated") { !@service.send(:auth_token).nil? }
returns(true) { (@service.instance_variable_get("@uri").host =~ /ord/) != nil }
@service.list_flavors
end
tests('custom endpoint') do
@service = Fog::Compute::RackspaceV2.new :rackspace_auth_url => 'https://identity.api.rackspacecloud.com/v2.0',
@ -71,19 +75,21 @@ Shindo.tests('Fog::Compute::RackspaceV2', ['rackspace']) do
tests('default auth') do
pending if Fog.mocking?
tests('no params') do
tests('no params').succeeds do
@service = Fog::Compute::RackspaceV2.new
returns(true, "auth token populated") { !@service.send(:auth_token).nil? }
returns(true) { (@service.instance_variable_get("@uri").host =~ /dfw/) != nil }
@service.list_flavors
end
tests('specify old contstant style service endoint').succeeds do
@service = Fog::Compute::RackspaceV2.new :rackspace_endpoint => Fog::Compute::RackspaceV2::ORD_ENDPOINT
@service.list_flavors
end
tests('specify region') do
tests('specify region').succeeds do
@service = Fog::Compute::RackspaceV2.new :rackspace_region => :ord
returns(true, "auth token populated") { !@service.send(:auth_token).nil? }
returns(true) { (@service.instance_variable_get("@uri").host =~ /ord/ ) != nil }
@service.list_flavors
end
tests('custom endpoint') do
@service = Fog::Compute::RackspaceV2.new :rackspace_compute_url => 'https://my-custom-endpoint.com'

View file

@ -2,6 +2,103 @@ Shindo.tests('Fog::Rackspace::Databases', ['rackspace']) do |variable|
pending if Fog.mocking?
def assert_method(url, method)
@service.instance_variable_set "@rackspace_auth_url", url
returns(method) { @service.send :authentication_method }
end
tests('#authentication_method') do
@service = Fog::Rackspace::Databases.new
assert_method nil, :authenticate_v2
assert_method 'https://identity.api.rackspacecloud.com', :authenticate_v1
assert_method 'https://identity.api.rackspacecloud.com/v1', :authenticate_v1
assert_method 'https://identity.api.rackspacecloud.com/v1.1', :authenticate_v1
assert_method 'https://identity.api.rackspacecloud.com/v2.0', :authenticate_v2
assert_method 'https://lon.identity.api.rackspacecloud.com', :authenticate_v1
assert_method 'https://lon.identity.api.rackspacecloud.com/v1', :authenticate_v1
assert_method 'https://lon.identity.api.rackspacecloud.com/v1.1', :authenticate_v1
assert_method 'https://lon.identity.api.rackspacecloud.com/v2.0', :authenticate_v2
end
tests('authentication v1') do
pending if Fog.mocking?
tests('variables populated') do
@service = Fog::Rackspace::Databases.new :rackspace_auth_url => 'https://identity.api.rackspacecloud.com/v1.0'
returns(true, "auth token populated") { !@service.send(:auth_token).nil? }
returns(false, "path populated") { @service.instance_variable_get("@uri").nil? }
returns(true, "identity_service was not used") { @service.instance_variable_get("@identity_service").nil? }
@service.flavors
end
tests('custom endpoint') do
@service = Fog::Rackspace::Databases.new :rackspace_auth_url => 'https://identity.api.rackspacecloud.com/v1.0',
:rackspace_database_url => 'https://my-custom-endpoint.com'
returns(false, "auth token populated") { @service.send(:auth_token).nil? }
returns(true, "uses custom endpoint") { (@service.instance_variable_get("@uri").host =~ /my-custom-endpoint\.com/) != nil }
end
end
tests('authentication v2') do
pending if Fog.mocking?
tests('variables populated').succeeds do
@service = Fog::Rackspace::Databases.new :rackspace_auth_url => 'https://identity.api.rackspacecloud.com/v2.0'
returns(true, "auth token populated") { !@service.send(:auth_token).nil? }
returns(false, "path populated") { @service.instance_variable_get("@uri").nil? }
returns(false, "identity service was used") { @service.instance_variable_get("@identity_service").nil? }
@service.flavors
end
tests('dfw region').succeeds do
@service = Fog::Rackspace::Databases.new :rackspace_auth_url => 'https://identity.api.rackspacecloud.com/v2.0', :rackspace_region => :dfw
returns(true, "auth token populated") { !@service.send(:auth_token).nil? }
returns(true) { (@service.instance_variable_get("@uri").host =~ /dfw/) != nil }
@service.flavors
end
tests('ord region').succeeds do
@service = Fog::Rackspace::Databases.new :rackspace_auth_url => 'https://identity.api.rackspacecloud.com/v2.0', :rackspace_region => :ord
returns(true, "auth token populated") { !@service.send(:auth_token).nil? }
returns(true) { (@service.instance_variable_get("@uri").host =~ /ord/) != nil }
@service.flavors
end
tests('custom endpoint') do
@service = Fog::Rackspace::Databases.new :rackspace_auth_url => 'https://identity.api.rackspacecloud.com/v2.0',
:rackspace_database_url => 'https://my-custom-endpoint.com'
returns(true, "auth token populated") { !@service.send(:auth_token).nil? }
returns(true, "uses custom endpoint") { (@service.instance_variable_get("@uri").host =~ /my-custom-endpoint\.com/) != nil }
end
end
tests('default auth') do
pending if Fog.mocking?
tests('no params').succeeds do
@service = Fog::Rackspace::Databases.new
returns(true, "auth token populated") { !@service.send(:auth_token).nil? }
returns(true) { (@service.instance_variable_get("@uri").host =~ /dfw/) != nil }
@service.flavors
end
tests('specify old contstant style service endoint').succeeds do
@service = Fog::Rackspace::Databases.new :rackspace_endpoint => Fog::Rackspace::Databases::ORD_ENDPOINT
returns(true) { (@service.instance_variable_get("@uri").host =~ /ord/ ) != nil }
@service.flavors
end
tests('specify region').succeeds do
@service = Fog::Rackspace::Databases.new :rackspace_region => :ord
returns(true, "auth token populated") { !@service.send(:auth_token).nil? }
returns(true) { (@service.instance_variable_get("@uri").host =~ /ord/ ) != nil }
@service.flavors
end
tests('custom endpoint') do
@service = Fog::Rackspace::Databases.new :rackspace_database_url => 'https://my-custom-endpoint.com'
returns(true, "auth token populated") { !@service.send(:auth_token).nil? }
returns(true, "uses custom endpoint") { (@service.instance_variable_get("@uri").host =~ /my-custom-endpoint\.com/) != nil }
end
end
@service = Fog::Rackspace::Databases.new
tests('#flavors').succeeds do
@ -23,4 +120,5 @@ Shindo.tests('Fog::Rackspace::Databases', ['rackspace']) do |variable|
data = @service.users
returns(true) { data.is_a? Array }
end
end

View file

@ -0,0 +1,82 @@
Shindo.tests('Fog::DNS::Rackspace', ['rackspace']) do
def assert_method(url, method)
@service.instance_variable_set "@rackspace_auth_url", url
returns(method) { @service.send :authentication_method }
end
tests('#authentication_method') do
@service = Fog::DNS::Rackspace.new
assert_method nil, :authenticate_v2
assert_method 'auth.api.rackspacecloud.com', :authenticate_v1 # chef's default auth endpoint
assert_method 'https://identity.api.rackspacecloud.com', :authenticate_v1
assert_method 'https://identity.api.rackspacecloud.com/v1', :authenticate_v1
assert_method 'https://identity.api.rackspacecloud.com/v1.1', :authenticate_v1
assert_method 'https://identity.api.rackspacecloud.com/v2.0', :authenticate_v2
assert_method 'https://lon.identity.api.rackspacecloud.com', :authenticate_v1
assert_method 'https://lon.identity.api.rackspacecloud.com/v1', :authenticate_v1
assert_method 'https://lon.identity.api.rackspacecloud.com/v1.1', :authenticate_v1
assert_method 'https://lon.identity.api.rackspacecloud.com/v2.0', :authenticate_v2
end
tests('legacy authentication') do
pending if Fog.mocking?
tests('variables populated').succeeds do
@service = Fog::DNS::Rackspace.new :rackspace_auth_url => 'https://identity.api.rackspacecloud.com/v1.0'
returns(true, "auth token populated") { !@service.send(:auth_token).nil? }
returns(true, "contains tenant id") { (@service.instance_variable_get("@uri").path =~ /\/v1\.0\/\d+$/) != nil} #dns does not error if tenant id is missing
returns(false, "path populated") { @service.instance_variable_get("@uri").path.nil? }
returns(true, "identity_service was not used") { @service.instance_variable_get("@identity_service").nil? }
@service.list_domains
end
tests('custom endpoint') do
@service = Fog::DNS::Rackspace.new :rackspace_auth_url => 'https://identity.api.rackspacecloud.com/v1.0',
:rackspace_dns_url => 'https://my-custom-endpoint.com'
returns(true, "auth token populated") { !@service.send(:auth_token).nil? }
returns(true, "uses custom endpoint") { (@service.instance_variable_get("@uri").host =~ /my-custom-endpoint\.com/) != nil }
end
end
tests('current authentication') do
pending if Fog.mocking?
tests('variables populated').succeeds do
@service = Fog::DNS::Rackspace.new :rackspace_auth_url => 'https://identity.api.rackspacecloud.com/v2.0'
returns(true, "auth token populated") { !@service.send(:auth_token).nil? }
returns(false, "path populated") { @service.instance_variable_get("@uri").host.nil? }
returns(true, "contains tenant id") { (@service.instance_variable_get("@uri").path =~ /\/v1\.0\/\d+$/) != nil} #dns does not error if tenant id is missing
returns(false, "identity service was used") { @service.instance_variable_get("@identity_service").nil? }
@service.list_domains
end
tests('custom endpoint') do
@service = Fog::DNS::Rackspace.new :rackspace_auth_url => 'https://identity.api.rackspacecloud.com/v2.0',
:rackspace_dns_url => 'https://my-custom-endpoint.com'
returns(true, "auth token populated") { !@service.send(:auth_token).nil? }
returns(true, "uses custom endpoint") { (@service.instance_variable_get("@uri").host =~ /my-custom-endpoint\.com/) != nil }
end
end
tests('default auth') do
pending if Fog.mocking?
tests('no params').succeeds do
@service = Fog::DNS::Rackspace.new
returns(true, "auth token populated") { !@service.send(:auth_token).nil? }
returns(false, "path populated") { @service.instance_variable_get("@uri").host.nil? }
returns(true, "contains tenant id") { (@service.instance_variable_get("@uri").path =~ /\/v1\.0\/\d+$/) != nil} #dns does not error if tenant id is missing
@service.list_domains
end
tests('custom endpoint') do
@service = Fog::DNS::Rackspace.new :rackspace_dns_url => 'https://my-custom-endpoint.com'
returns(true, "auth token populated") { !@service.send(:auth_token).nil? }
returns(true, "uses custom endpoint") { (@service.instance_variable_get("@uri").host =~ /my-custom-endpoint\.com/) != nil }
end
end
end

View file

@ -1,5 +1,104 @@
Shindo.tests('Fog::Rackspace::LoadBalancers', ['rackspace']) do
def assert_method(url, method)
@service.instance_variable_set "@rackspace_auth_url", url
returns(method) { @service.send :authentication_method }
end
tests('#authentication_method') do
@service = Fog::Rackspace::LoadBalancers.new
assert_method nil, :authenticate_v2
assert_method 'auth.api.rackspacecloud.com', :authenticate_v1 # chef's default auth endpoint
assert_method 'https://identity.api.rackspacecloud.com', :authenticate_v1
assert_method 'https://identity.api.rackspacecloud.com/v1', :authenticate_v1
assert_method 'https://identity.api.rackspacecloud.com/v1.1', :authenticate_v1
assert_method 'https://identity.api.rackspacecloud.com/v2.0', :authenticate_v2
assert_method 'https://lon.identity.api.rackspacecloud.com', :authenticate_v1
assert_method 'https://lon.identity.api.rackspacecloud.com/v1', :authenticate_v1
assert_method 'https://lon.identity.api.rackspacecloud.com/v1.1', :authenticate_v1
assert_method 'https://lon.identity.api.rackspacecloud.com/v2.0', :authenticate_v2
end
tests('legacy authentication') do
pending if Fog.mocking?
tests('variables populated').succeeds do
@service = Fog::Rackspace::LoadBalancers.new :rackspace_auth_url => 'https://identity.api.rackspacecloud.com/v1.0'
returns(true, "auth token populated") { !@service.send(:auth_token).nil? }
returns(false, "path populated") { @service.instance_variable_get("@uri").path.nil? }
returns(true, "identity_service was not used") { @service.instance_variable_get("@identity_service").nil? }
@service.list_load_balancers
end
tests('custom endpoint') do
@service = Fog::Rackspace::LoadBalancers.new :rackspace_auth_url => 'https://identity.api.rackspacecloud.com/v1.0',
:rackspace_load_balancers_url => 'https://my-custom-endpoint.com'
returns(true, "auth token populated") { !@service.send(:auth_token).nil? }
returns(true, "uses custom endpoint") { (@service.instance_variable_get("@uri").host =~ /my-custom-endpoint\.com/) != nil }
end
end
tests('current authentation') do
pending if Fog.mocking?
tests('variables populated').succeeds do
@service = Fog::Rackspace::LoadBalancers.new :rackspace_auth_url => 'https://identity.api.rackspacecloud.com/v2.0'
returns(true, "auth token populated") { !@service.send(:auth_token).nil? }
returns(false, "path populated") { @service.instance_variable_get("@uri").host.nil? }
returns(false, "identity service was used") { @service.instance_variable_get("@identity_service").nil? }
@service.list_load_balancers
end
tests('dfw region').succeeds do
@service = Fog::Rackspace::LoadBalancers.new :rackspace_auth_url => 'https://identity.api.rackspacecloud.com/v2.0', :rackspace_region => :dfw
returns(true, "auth token populated") { !@service.send(:auth_token).nil? }
returns(true) { (@service.instance_variable_get("@uri").host =~ /dfw/) != nil }
@service.list_load_balancers
end
tests('ord region').succeeds do
@service = Fog::Rackspace::LoadBalancers.new :rackspace_auth_url => 'https://identity.api.rackspacecloud.com/v2.0', :rackspace_region => :ord
returns(true, "auth token populated") { !@service.send(:auth_token).nil? }
returns(true) { (@service.instance_variable_get("@uri").host =~ /ord/) != nil }
@service.list_load_balancers
end
tests('custom endpoint') do
@service = Fog::Rackspace::LoadBalancers.new :rackspace_auth_url => 'https://identity.api.rackspacecloud.com/v2.0',
:rackspace_load_balancers_url => 'https://my-custom-endpoint.com'
returns(true, "auth token populated") { !@service.send(:auth_token).nil? }
returns(true, "uses custom endpoint") { (@service.instance_variable_get("@uri").host =~ /my-custom-endpoint\.com/) != nil }
end
end
tests('default auth') do
pending if Fog.mocking?
tests('no params').succeeds do
@service = Fog::Rackspace::LoadBalancers.new
returns(true, "auth token populated") { !@service.send(:auth_token).nil? }
returns(true) { (@service.instance_variable_get("@uri").host =~ /dfw/) != nil }
@service.list_load_balancers
end
tests('specify old contstant style service endoint').succeeds do
@service = Fog::Rackspace::LoadBalancers.new :rackspace_lb_endpoint => Fog::Rackspace::LoadBalancers::ORD_ENDPOINT
returns(true) { (@service.instance_variable_get("@uri").host =~ /ord/ ) != nil }
@service.list_load_balancers
end
tests('specify region').succeeds do
@service = Fog::Rackspace::LoadBalancers.new :rackspace_region => :ord
returns(true, "auth token populated") { !@service.send(:auth_token).nil? }
returns(true) { (@service.instance_variable_get("@uri").host =~ /ord/ ) != nil }
@service.list_load_balancers
end
tests('custom endpoint') do
@service = Fog::Rackspace::LoadBalancers.new :rackspace_load_balancers_url => 'https://my-custom-endpoint.com'
returns(true, "auth token populated") { !@service.send(:auth_token).nil? }
returns(true, "uses custom endpoint") { (@service.instance_variable_get("@uri").host =~ /my-custom-endpoint\.com/) != nil }
end
end
pending if Fog.mocking?
@service = Fog::Rackspace::LoadBalancers.new

View file

@ -0,0 +1,21 @@
Shindo.tests('Fog::Rackspace', ['rackspace']) do
tests('normalize_url') do
tests('should return nil if endpoint is nil').returns(nil) do
Fog::Rackspace.normalize_url nil
end
tests('should remove trailing spaces').returns("https://dfw.blockstorage.api.rackspacecloud.com/v1") do
Fog::Rackspace.normalize_url "https://dfw.blockstorage.api.rackspacecloud.com/v1 "
end
tests('should remove trailing /').returns("https://dfw.blockstorage.api.rackspacecloud.com/v1") do
Fog::Rackspace.normalize_url "https://dfw.blockstorage.api.rackspacecloud.com/v1/"
end
tests('should downcase url').returns("https://dfw.blockstorage.api.rackspacecloud.com/v1") do
Fog::Rackspace.normalize_url "HTTPS://DFW.BLOCKSTORAGE.API.RACKSPACECLOUD.COM/V1"
end
tests('show do all three').returns("https://dfw.blockstorage.api.rackspacecloud.com/v1") do
Fog::Rackspace.normalize_url "HTTPS://DFW.BLOCKSTORAGE.API.RACKSPACECLOUD.COM/V1/ "
end
end
end

View file

@ -16,8 +16,8 @@ Shindo.tests('Fog::Compute::RackspaceV2 | metadata_tests', ['rackspace']) do
@server_id = @server.id
@image_id = @server.create_image(name, :metadata => metadata)
@image = @service.images.get @image_id
@image = @server.create_image(name, :metadata => metadata)
@image_id = @image.id
else
@image_id = 1
@server_id = 1

View file

@ -23,12 +23,13 @@ Shindo.tests('Rackspace | Storage', ['rackspace']) do
tests('authentication v1') do
pending if Fog.mocking?
@service = Fog::Storage::Rackspace.new :rackspace_auth_url => 'https://identity.api.rackspacecloud.com/v1.0'
tests('variables populated') do
tests('variables populated').succeeds do
@service = Fog::Storage::Rackspace.new :rackspace_auth_url => 'https://identity.api.rackspacecloud.com/v1.0'
returns(true, "auth token populated") { !@service.send(:auth_token).nil? }
returns(false, "path populated") { @service.instance_variable_get("@uri").nil? }
returns(true, "identity_service was not used") { @service.instance_variable_get("@identity_service").nil? }
returns(true, "identity_service was not used") { @service.instance_variable_get("@identity_service").nil? }
@service.head_containers
end
tests('custom endpoint') do
@service = Fog::Storage::Rackspace.new :rackspace_auth_url => 'https://identity.api.rackspacecloud.com/v1.0',
@ -40,24 +41,27 @@ Shindo.tests('Rackspace | Storage', ['rackspace']) do
tests('authentation v2') do
pending if Fog.mocking?
@service = Fog::Storage::Rackspace.new :rackspace_auth_url => 'https://identity.api.rackspacecloud.com/v2.0'
tests('variables populated') do
tests('variables populated').succeeds do
@service = Fog::Storage::Rackspace.new :rackspace_auth_url => 'https://identity.api.rackspacecloud.com/v2.0'
returns(true, "auth token populated") { !@service.send(:auth_token).nil? }
returns(false, "path populated") { @service.instance_variable_get("@uri").nil? }
returns(false, "identity service was used") { @service.instance_variable_get("@identity_service").nil? }
returns(false, "identity service was used") { @service.instance_variable_get("@identity_service").nil? }
@service.head_containers
end
tests('dfw region') do
tests('dfw region').succeeds do
@service = Fog::Storage::Rackspace.new :rackspace_auth_url => 'https://identity.api.rackspacecloud.com/v2.0', :rackspace_region => :dfw
returns(true, "auth token populated") { !@service.send(:auth_token).nil? }
returns(true) { (@service.instance_variable_get("@uri").host =~ /dfw\d/) != nil }
@service.head_containers
end
tests('ord region') do
tests('ord region').succeeds do
@service = Fog::Storage::Rackspace.new :rackspace_auth_url => 'https://identity.api.rackspacecloud.com/v2.0', :rackspace_region => :ord
returns(true, "auth token populated") { !@service.send(:auth_token).nil? }
returns(true) { (@service.instance_variable_get("@uri").host =~ /ord\d/) != nil }
@service.head_containers
end
tests('custom endpoint') do
tests('custom endpoint').succeeds do
@service = Fog::Storage::Rackspace.new :rackspace_auth_url => 'https://identity.api.rackspacecloud.com/v2.0',
:rackspace_storage_url => 'https://my-custom-endpoint.com'
returns(true, "auth token populated") { !@service.send(:auth_token).nil? }
@ -68,15 +72,17 @@ Shindo.tests('Rackspace | Storage', ['rackspace']) do
tests('default auth') do
pending if Fog.mocking?
tests('no params') do
tests('no params').succeeds do
@service = Fog::Storage::Rackspace.new
returns(true, "auth token populated") { !@service.send(:auth_token).nil? }
returns(true) { (@service.instance_variable_get("@uri").host =~ /dfw\d/) != nil }
@service.head_containers
end
tests('specify region') do
tests('specify region').succeeds do
@service = Fog::Storage::Rackspace.new :rackspace_region => :ord
returns(true, "auth token populated") { !@service.send(:auth_token).nil? }
returns(true) { (@service.instance_variable_get("@uri").host =~ /ord\d/ ) != nil }
@service.head_containers
end
tests('custom endpoint') do
@service = Fog::Storage::Rackspace.new :rackspace_storage_url => 'https://my-custom-endpoint.com'