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

[rackspace] adding auth 2.0 to compute, databases, dns, load balancers, cloud block storage

This commit is contained in:
Kyle Rames 2013-03-13 16:01:32 -05:00
parent 9cc79c90d8
commit 90c91078d3
14 changed files with 697 additions and 112 deletions

View file

@ -16,6 +16,8 @@ module Fog
requires :rackspace_api_key, :rackspace_username requires :rackspace_api_key, :rackspace_username
recognizes :rackspace_auth_url recognizes :rackspace_auth_url
recognizes :rackspace_endpoint recognizes :rackspace_endpoint
recognizes :rackspace_region
recognizes :rackspace_block_storage_url
model_path 'fog/rackspace/models/block_storage' model_path 'fog/rackspace/models/block_storage'
model :volume model :volume
@ -43,7 +45,7 @@ module Fog
request :get_snapshot request :get_snapshot
request :list_snapshots request :list_snapshots
class Mock class Mock < Fog::Rackspace::Service
include Fog::Rackspace::MockData include Fog::Rackspace::MockData
def initialize(options = {}) def initialize(options = {})
@ -67,26 +69,22 @@ module Fog
end end
end end
class Real class Real < Fog::Rackspace::Service
def initialize(options = {}) def initialize(options = {})
@rackspace_api_key = options[:rackspace_api_key] @rackspace_api_key = options[:rackspace_api_key]
@rackspace_username = options[:rackspace_username] @rackspace_username = options[:rackspace_username]
@rackspace_auth_url = options[:rackspace_auth_url] @rackspace_auth_url = options[:rackspace_auth_url]
@rackspace_must_reauthenticate = false @rackspace_must_reauthenticate = false
@connection_options = options[:connection_options] || {} @connection_options = options[:connection_options] || {}
@rackspace_endpoint = options[:rackspace_block_storage_url] || options[:rackspace_endpoint]
endpoint = options[:rackspace_endpoint] || DFW_ENDPOINT @rackspace_region = options[:rackspace_region] || :dfw
uri = URI.parse(endpoint)
@host = uri.host
@persistent = options[:persistent] || false
@path = uri.path
@port = uri.port
@scheme = uri.scheme
authenticate 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 end
def request(params) def request(params)
@ -95,10 +93,10 @@ module Fog
:headers => { :headers => {
'Content-Type' => 'application/json', 'Content-Type' => 'application/json',
'Accept' => 'application/json', 'Accept' => 'application/json',
'X-Auth-Token' => @auth_token 'X-Auth-Token' => auth_token
}.merge!(params[:headers] || {}), }.merge!(params[:headers] || {}),
:host => @host, :host => endpoint_uri.host,
:path => "#{@path}/#{params[:path]}" :path => "#{endpoint_uri.path}/#{params[:path]}"
})) }))
rescue Excon::Errors::NotFound => error rescue Excon::Errors::NotFound => error
raise NotFound.slurp error raise NotFound.slurp error
@ -115,19 +113,52 @@ module Fog
response response
end end
private
def authenticate def authenticate
options = { options = {
:rackspace_api_key => @rackspace_api_key, :rackspace_api_key => @rackspace_api_key,
:rackspace_username => @rackspace_username, :rackspace_username => @rackspace_username,
:rackspace_auth_url => @rackspace_auth_url :rackspace_auth_url => @rackspace_auth_url
} }
credentials = Fog::Rackspace.authenticate(options, @connection_options) super(options)
@auth_token = credentials['X-Auth-Token']
account_id = credentials['X-Server-Management-Url'].match(/.*\/([\d]+)$/)[1]
@path = "#{@path}/#{account_id}"
end 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 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 setup_endpoint(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)
setup_endpoint credentials
@auth_token = credentials['X-Auth-Token']
end
end end
end end
end end

View file

@ -7,7 +7,7 @@ module Fog
requires :rackspace_api_key, :rackspace_username requires :rackspace_api_key, :rackspace_username
recognizes :rackspace_auth_url, :rackspace_servicenet, :persistent 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_path 'fog/rackspace/models/compute'
model :flavor model :flavor
@ -41,7 +41,7 @@ module Fog
request :server_action request :server_action
request :update_server request :update_server
class Mock class Mock < Fog::Rackspace::Service
def self.data def self.data
@data ||= Hash.new do |hash, key| @data ||= Hash.new do |hash, key|
@ -180,7 +180,7 @@ module Fog
end end
class Real class Real < Fog::Rackspace::Service
def initialize(options={}) def initialize(options={})
@rackspace_api_key = options[:rackspace_api_key] @rackspace_api_key = options[:rackspace_api_key]
@ -188,13 +188,13 @@ module Fog
@rackspace_auth_url = options[:rackspace_auth_url] @rackspace_auth_url = options[:rackspace_auth_url]
@rackspace_servicenet = options[:rackspace_servicenet] @rackspace_servicenet = options[:rackspace_servicenet]
@rackspace_auth_token = options[:rackspace_auth_token] @rackspace_auth_token = options[:rackspace_auth_token]
@rackspace_management_url = options[:rackspace_management_url] @rackspace_endpoint = options[:rackspace_compute_v1_url] || options[:rackspace_management_url]
@rackspace_must_reauthenticate = false @rackspace_must_reauthenticate = false
@connection_options = options[:connection_options] || {} @connection_options = options[:connection_options] || {}
authenticate authenticate
Excon.ssl_verify_peer = false if options[:rackspace_servicenet] == true Excon.defaults[:ssl_verify_peer] = false if service_net?
@persistent = options[:persistent] || false @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 end
def reload def reload
@ -206,10 +206,10 @@ module Fog
response = @connection.request(params.merge({ response = @connection.request(params.merge({
:headers => { :headers => {
'Content-Type' => 'application/json', 'Content-Type' => 'application/json',
'X-Auth-Token' => @auth_token 'X-Auth-Token' => auth_token
}.merge!(params[:headers] || {}), }.merge!(params[:headers] || {}),
:host => @host, :host => endpoint_uri.host,
:path => "#{@path}/#{params[:path]}", :path => "#{endpoint_uri.path}/#{params[:path]}",
:query => ('ignore_awful_caching' << Time.now.to_i.to_s) :query => ('ignore_awful_caching' << Time.now.to_i.to_s)
})) }))
rescue Excon::Errors::Unauthorized => error rescue Excon::Errors::Unauthorized => error
@ -234,28 +234,53 @@ module Fog
response response
end end
private
def authenticate def service_net?
if @rackspace_must_reauthenticate || @rackspace_auth_token.nil? @rackspace_servicenet == true
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
end 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 end
end end

View file

@ -174,8 +174,8 @@ module Fog
Fog::Logger.deprecation("The :rackspace_endpoint option is deprecated. Please use :rackspace_compute_url for custom endpoints") if options[:rackspace_endpoint] Fog::Logger.deprecation("The :rackspace_endpoint option is deprecated. Please use :rackspace_compute_url for custom endpoints") if options[:rackspace_endpoint]
if [DFW_ENDPOINT, ORD_ENDPOINT, LON_ENDPOINT].include?(@rackspace_endpoint) && v2_authentication? if [DFW_ENDPOINT, ORD_ENDPOINT, LON_ENDPOINT].include?(@rackspace_endpoint) && v2_authentication?
regions = @identity_service.service_catalog.display_service_regions(:cloudServersOpenStack) 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}.") Fog::Logger.deprecation("Please specify region using :rackspace_region rather than :rackspace_endpoint. Valid regions for :rackspace_region are #{regions}.")
end end
end end

View file

@ -16,6 +16,9 @@ module Fog
recognizes :rackspace_auth_url recognizes :rackspace_auth_url
recognizes :rackspace_auth_token recognizes :rackspace_auth_token
recognizes :rackspace_endpoint recognizes :rackspace_endpoint
recognizes :rackspace_region
recognizes :rackspace_database_url
model_path 'fog/rackspace/models/databases' model_path 'fog/rackspace/models/databases'
model :flavor model :flavor
@ -49,32 +52,37 @@ module Fog
request :create_user request :create_user
request :delete_user request :delete_user
class Mock class Mock < Fog::Rackspace::Service
def request(params) def request(params)
Fog::Mock.not_implemented Fog::Mock.not_implemented
end end
end end
class Real class Real < Fog::Rackspace::Service
def service_name
:cloudDatabases
end
def region
@rackspace_region
end
def initialize(options = {}) def initialize(options = {})
@rackspace_api_key = options[:rackspace_api_key] @rackspace_api_key = options[:rackspace_api_key]
@rackspace_username = options[:rackspace_username] @rackspace_username = options[:rackspace_username]
@rackspace_auth_url = options[:rackspace_auth_url] @rackspace_auth_url = options[:rackspace_auth_url]
@rackspace_must_reauthenticate = false @rackspace_must_reauthenticate = false
@connection_options = options[:connection_options] || {} @connection_options = options[:connection_options] || {}
@rackspace_endpoint = options[:rackspace_database_url] || options[:rackspace_endpoint]
endpoint = options[:rackspace_endpoint] || DFW_ENDPOINT @rackspace_region = options[:rackspace_region] || :dfw
uri = URI.parse(endpoint)
@host = uri.host
@persistent = options[:persistent] || false
@path = uri.path
@port = uri.port
@scheme = uri.scheme
authenticate 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 end
def request(params) def request(params)
@ -83,10 +91,10 @@ module Fog
:headers => { :headers => {
'Content-Type' => 'application/json', 'Content-Type' => 'application/json',
'Accept' => 'application/json', 'Accept' => 'application/json',
'X-Auth-Token' => @auth_token 'X-Auth-Token' => auth_token
}.merge!(params[:headers] || {}), }.merge!(params[:headers] || {}),
:host => @host, :host => endpoint_uri.host,
:path => "#{@path}/#{params[:path]}" :path => "#{endpoint_uri.path}/#{params[:path]}"
})) }))
rescue Excon::Errors::NotFound => error rescue Excon::Errors::NotFound => error
raise NotFound.slurp error raise NotFound.slurp error
@ -103,7 +111,9 @@ module Fog
response response
end end
private def endpoint_uri(service_endpoint_url=nil)
@uri = super(@rackspace_endpoint || service_endpoint_url, :rackspace_database_url)
end
def authenticate def authenticate
options = { options = {
@ -111,10 +121,33 @@ module Fog
:rackspace_username => @rackspace_username, :rackspace_username => @rackspace_username,
:rackspace_auth_url => @rackspace_auth_url :rackspace_auth_url => @rackspace_auth_url
} }
credentials = Fog::Rackspace.authenticate(options, @connection_options)
@auth_token = credentials['X-Auth-Token'] super(options)
end
private
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 setup_endpoint(credentials)
account_id = credentials['X-Server-Management-Url'].match(/.*\/([\d]+)$/)[1] 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)
setup_endpoint credentials
@auth_token = credentials['X-Auth-Token']
end end
end end
end end

View file

@ -18,7 +18,7 @@ module Fog
UK_ENDPOINT = 'https://lon.dns.api.rackspacecloud.com/v1.0' UK_ENDPOINT = 'https://lon.dns.api.rackspacecloud.com/v1.0'
requires :rackspace_api_key, :rackspace_username 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_path 'fog/rackspace/models/dns'
model :record model :record
@ -43,7 +43,7 @@ module Fog
request :remove_records request :remove_records
request :add_records request :add_records
class Mock class Mock < Fog::Rackspace::Service
def initialize(options={}) def initialize(options={})
@rackspace_api_key = options[:rackspace_api_key] @rackspace_api_key = options[:rackspace_api_key]
@ -71,22 +71,38 @@ module Fog
end 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={}) def initialize(options={})
@rackspace_api_key = options[:rackspace_api_key] @rackspace_api_key = options[:rackspace_api_key]
@rackspace_username = options[:rackspace_username] @rackspace_username = options[:rackspace_username]
@rackspace_auth_url = options[:rackspace_auth_url] @rackspace_auth_url = options[:rackspace_auth_url]
@connection_options = options[:connection_options] || {} @connection_options = options[:connection_options] || {}
uri = URI.parse(options[:rackspace_dns_endpoint] || US_ENDPOINT) @rackspace_endpoint = options[:rackspace_dns_url] || options[:rackspace_dns_endpoint] || US_ENDPOINT
@rackspace_region = options[:rackspace_region]
@auth_token, @account_id = *authenticate authenticate
@persistent = options[:persistent] || false
@path = "#{uri.path}/#{@account_id}" deprecation_warnings(options)
@connection_options[:headers] ||= {} @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 end
private private
@ -95,7 +111,7 @@ module Fog
#TODO - Unify code with other rackspace services #TODO - Unify code with other rackspace services
begin begin
response = @connection.request(params.merge!({ response = @connection.request(params.merge!({
:path => "#{@path}/#{params[:path]}" :path => "#{endpoint_uri.path}/#{params[:path]}"
})) }))
rescue Excon::Errors::BadRequest => error rescue Excon::Errors::BadRequest => error
raise Fog::Rackspace::Errors::BadRequest.slurp error raise Fog::Rackspace::Errors::BadRequest.slurp error
@ -112,18 +128,6 @@ module Fog
response response
end 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) def array_to_query_string(arr)
arr.collect {|k,v| "#{k}=#{v}" }.join('&') arr.collect {|k,v| "#{k}=#{v}" }.join('&')
end end
@ -133,6 +137,35 @@ module Fog
raise ArgumentError.new("#{name} cannot be null or empty") raise ArgumentError.new("#{name} cannot be null or empty")
end end
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)
@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 end
end end

View file

@ -17,6 +17,8 @@ module Fog
recognizes :rackspace_auth_url recognizes :rackspace_auth_url
recognizes :rackspace_auth_token recognizes :rackspace_auth_token
recognizes :rackspace_lb_endpoint recognizes :rackspace_lb_endpoint
recognizes :rackspace_load_balancers_url
recognizes :rackspace_region
model_path 'fog/rackspace/models/load_balancers' model_path 'fog/rackspace/models/load_balancers'
collection :load_balancers collection :load_balancers
@ -87,7 +89,7 @@ module Fog
end end
class Mock class Mock < Fog::Rackspace::Service
include Shared include Shared
def initialize(options={}) def initialize(options={})
@ -98,7 +100,7 @@ module Fog
end end
class Real class Real < Fog::Rackspace::Service
include Shared include Shared
def initialize(options={}) def initialize(options={})
@ -107,16 +109,13 @@ module Fog
@rackspace_auth_url = options[:rackspace_auth_url] @rackspace_auth_url = options[:rackspace_auth_url]
@rackspace_must_reauthenticate = false @rackspace_must_reauthenticate = false
@connection_options = options[:connection_options] || {} @connection_options = options[:connection_options] || {}
uri = URI.parse(options[:rackspace_lb_endpoint] || DFW_ENDPOINT) @rackspace_endpoint = options[:rackspace_load_balancers_url] || options[:rackspace_lb_endpoint]
@host = uri.host @rackspace_region = options[:rackspace_region] || :dfw
@persistent = options[:persistent] || false
@path = uri.path.end_with?('/') ? uri.path.chop : uri.path
@port = uri.port
@scheme = uri.scheme
authenticate 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 end
def request(params) def request(params)
@ -128,8 +127,8 @@ module Fog
'Accept' => 'application/json', 'Accept' => 'application/json',
'X-Auth-Token' => @auth_token 'X-Auth-Token' => @auth_token
}.merge!(params[:headers] || {}), }.merge!(params[:headers] || {}),
:host => @host, :host => endpoint_uri.host,
:path => "#{@path}/#{params[:path]}" :path => "#{endpoint_uri.path}/#{params[:path]}"
})) }))
rescue Excon::Errors::NotFound => error rescue Excon::Errors::NotFound => error
raise NotFound.slurp error raise NotFound.slurp error
@ -148,15 +147,50 @@ module Fog
def authenticate def authenticate
options = { options = {
:rackspace_api_key => @rackspace_api_key, :rackspace_api_key => @rackspace_api_key,
:rackspace_username => @rackspace_username, :rackspace_username => @rackspace_username,
:rackspace_auth_url => @rackspace_auth_url :rackspace_auth_url => @rackspace_auth_url
} }
credentials = Fog::Rackspace.authenticate(options, @connection_options) super(options)
@auth_token = credentials['X-Auth-Token']
account_id = credentials['X-Server-Management-Url'].match(/.*\/([\d]+)$/)[1]
@path = "#{@path}/#{account_id}"
end 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 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 setup_endpoint(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)
setup_endpoint credentials
@auth_token = credentials['X-Auth-Token']
end
end end
end end
end end

View file

@ -194,6 +194,8 @@ module Fog
end end
def endpoint_uri(service_endpoint_url=nil) def endpoint_uri(service_endpoint_url=nil)
return @uri if @uri
@uri = super(@rackspace_storage_url || service_endpoint_url, :rackspace_storage_url) @uri = super(@rackspace_storage_url || service_endpoint_url, :rackspace_storage_url)
@uri.host = "snet-#{@uri.host}" if service_net? @uri.host = "snet-#{@uri.host}" if service_net?
@uri @uri

View file

@ -0,0 +1,91 @@
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?
@service = Fog::Rackspace::BlockStorage.new :rackspace_auth_url => 'https://identity.api.rackspacecloud.com/v1.0'
tests('variables populated') do
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? }
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?
@service = Fog::Rackspace::BlockStorage.new :rackspace_auth_url => 'https://identity.api.rackspacecloud.com/v2.0'
tests('variables populated') do
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? }
end
tests('dfw region') 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 }
end
tests('ord region') 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 }
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') 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 }
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 }
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

@ -6,7 +6,7 @@ Shindo.tests('Fog::CDN::Rackspace', ['rackspace']) do
end end
tests('#authentication_method') do tests('#authentication_method') do
@service = Fog::Storage::Rackspace.new @service = Fog::CDN::Rackspace.new
assert_method nil, :authenticate_v2 assert_method nil, :authenticate_v2
@ -38,7 +38,7 @@ Shindo.tests('Fog::CDN::Rackspace', ['rackspace']) do
end end
end end
tests('authentation v2') do tests('authentication v2') do
pending if Fog.mocking? pending if Fog.mocking?
@service = Fog::CDN::Rackspace.new :rackspace_auth_url => 'https://identity.api.rackspacecloud.com/v2.0' @service = Fog::CDN::Rackspace.new :rackspace_auth_url => 'https://identity.api.rackspacecloud.com/v2.0'

View file

@ -0,0 +1,84 @@
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?
@service = Fog::Compute::Rackspace.new :rackspace_auth_url => 'https://identity.api.rackspacecloud.com/v1.0'
tests('variables populated') do
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? }
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?
@service = Fog::Compute::Rackspace.new :rackspace_auth_url => 'https://identity.api.rackspacecloud.com/v2.0'
tests('variables populated') do
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? }
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') 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 }
end
tests('specify region') 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 }
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

@ -6,7 +6,7 @@ Shindo.tests('Fog::Compute::RackspaceV2', ['rackspace']) do
end end
tests('#authentication_method') do tests('#authentication_method') do
@service = Fog::Storage::Rackspace.new @service = Fog::Compute::RackspaceV2.new
assert_method nil, :authenticate_v2 assert_method nil, :authenticate_v2

View file

@ -2,6 +2,93 @@ Shindo.tests('Fog::Rackspace::Databases', ['rackspace']) do |variable|
pending if Fog.mocking? 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?
@service = Fog::Rackspace::Databases.new :rackspace_auth_url => 'https://identity.api.rackspacecloud.com/v1.0'
tests('variables populated') do
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? }
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?
@service = Fog::Rackspace::Databases.new :rackspace_auth_url => 'https://identity.api.rackspacecloud.com/v2.0'
tests('variables populated') do
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? }
end
tests('dfw region') 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? }
puts @service.instance_variable_get("@uri").host
returns(true) { (@service.instance_variable_get("@uri").host =~ /dfw/) != nil }
end
tests('ord region') 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 }
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') 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 }
end
tests('specify region') 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 }
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 @service = Fog::Rackspace::Databases.new
tests('#flavors').succeeds do tests('#flavors').succeeds do
@ -23,4 +110,5 @@ Shindo.tests('Fog::Rackspace::Databases', ['rackspace']) do |variable|
data = @service.users data = @service.users
returns(true) { data.is_a? Array } returns(true) { data.is_a? Array }
end end
end end

View file

@ -0,0 +1,76 @@
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?
@service = Fog::DNS::Rackspace.new :rackspace_auth_url => 'https://identity.api.rackspacecloud.com/v1.0'
tests('variables populated') do
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? }
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?
@service = Fog::DNS::Rackspace.new :rackspace_auth_url => 'https://identity.api.rackspacecloud.com/v2.0'
tests('variables populated') do
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? }
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') 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? }
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,93 @@
Shindo.tests('Fog::Rackspace::LoadBalancers', ['rackspace']) do 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?
@service = Fog::Rackspace::LoadBalancers.new :rackspace_auth_url => 'https://identity.api.rackspacecloud.com/v1.0'
tests('variables populated') do
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? }
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?
@service = Fog::Rackspace::LoadBalancers.new :rackspace_auth_url => 'https://identity.api.rackspacecloud.com/v2.0'
tests('variables populated') do
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? }
end
tests('dfw region') 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 }
end
tests('ord region') 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 }
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') 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 }
end
tests('specify region') 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 }
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? pending if Fog.mocking?
@service = Fog::Rackspace::LoadBalancers.new @service = Fog::Rackspace::LoadBalancers.new