dxsdk-27 make generic credentials

This commit is contained in:
howete 2013-03-28 13:40:20 -06:00 committed by Rupak Ganguly
parent 6a97ca8c74
commit 8c9a2c7043
5 changed files with 25 additions and 25 deletions

View File

@ -114,14 +114,14 @@ module Fog
options = options.clone
options.delete(:credentials)
else
endpoints = options[:credentials][:endpoints]
service_catalog = options[:credentials][:service_catalog]
type = options[:hp_service_type]
zone = options[:hp_avl_zone]
begin
creds = options[:credentials].clone
creds[:endpoint_url] = endpoints_get(endpoints, type, zone)
creds[:endpoint_url] = get_endpoint_url(service_catalog, type, zone)
begin
creds[:cdn_endpoint_url] = endpoints_get(endpoints, "CDN", zone)
creds[:cdn_endpoint_url] = get_endpoint_url(service_catalog, "CDN", zone)
rescue
end
return creds
@ -201,17 +201,17 @@ module Fog
### fish out auth_token and endpoint for the service
auth_token = body['access']['token']['id']
expires = body['access']['token']['expires']
endpoints = service_catalog_endpoints(body['access']['serviceCatalog'])
endpoint_url = endpoints_get(endpoints, @hp_service_type, @hp_avl_zone)
service_catalog = get_service_catalog(body['access']['serviceCatalog'])
endpoint_url = get_endpoint_url(service_catalog, @hp_service_type, @hp_avl_zone)
begin
cdn_endpoint_url = endpoints_get(endpoints, "CDN", @hp_avl_zone)
cdn_endpoint_url = get_endpoint_url(service_catalog, "CDN", @hp_avl_zone)
rescue
end
creds = {
:auth_token => auth_token,
:expires => expires,
:endpoints => endpoints,
:service_catalog => service_catalog,
:endpoint_url => endpoint_url,
:cdn_endpoint_url => cdn_endpoint_url
}
@ -227,31 +227,31 @@ module Fog
private
def self.service_catalog_endpoints(service_catalog)
raise "Unable to parse service catalog." unless service_catalog
endpoints = {}
service_catalog.each do |s|
name = s["name"].to_sym
def self.get_service_catalog(body)
raise "Unable to parse service catalog." unless body
service_catalog = {}
body.each do |s|
name = s["name"]
next if name.nil?
name = name.to_sym
next if s['endpoints'].nil?
endpoints[name] = {}
service_catalog[name] = {}
s['endpoints'].each do |ep|
next if ep['region'].nil?
next if ep['publicURL'].nil?
next if ep['publicURL'].empty?
endpoints[name][ep['region'].to_sym] = ep['publicURL']
service_catalog[name][ep['region'].to_sym] = ep['publicURL']
end
end
return endpoints
return service_catalog
end
def self.endpoints_get(endpoints, service_type, avl_zone)
def self.get_endpoint_url(service_catalog, service_type, avl_zone)
service_type = service_type.to_sym
avl_zone = avl_zone.to_sym
unless endpoints[service_type].nil?
unless endpoints[service_type][avl_zone].nil?
return endpoints[service_type][avl_zone]
unless service_catalog[service_type].nil?
unless service_catalog[service_type][avl_zone].nil?
return service_catalog[service_type][avl_zone]
end
end
raise "Unable to retrieve endpoint service url for availability zone '#{avl_zone}' from service catalog. "

View File

@ -4,7 +4,7 @@ Shindo.tests('Fog::HP::BlockStorage', ['hp', 'blockstorage']) do
credentials = {
:auth_token => 'auth_token',
:endpoint_url => 'http://127.0.0.1/bpath/',
:endpoints => {
:service_catalog => {
:"Block Storage" => {
:zone => 'http://127.0.0.1/bpath/'}},
:expires => (DateTime.now + 1).to_s
@ -35,13 +35,13 @@ Shindo.tests('Fog::HP::BlockStorage', ['hp', 'blockstorage']) do
end
tests('Test no service') do
options[:credentials] = credentials
options[:credentials][:endpoints] = {
options[:credentials][:service_catalog] = {
:"CDN" => {
:zone => 'http://127.0.0.1/bpath/'}},
raises(Excon::Errors::Unauthorized) { Fog::HP::BlockStorage::Real.new(options) }
end
tests('Test no creds') do
options[:credentials][:endpoints] = nil
options[:credentials][:service_catalog] = nil
raises(Excon::Errors::Unauthorized) { Fog::HP::BlockStorage::Real.new(options) }
end
end

View File

@ -3,7 +3,7 @@ Shindo.tests('Fog::CDN::HP', ['hp', 'cdn']) do
:auth_token => 'auth_token',
:endpoint_url => 'http://127.0.0.1/cdnpath/',
:cdn_endpoint_url => "http://127.0.0.1/cdnpath/",
:endpoints => {
:service_catalog => {
:"CDN" => {
:zone => 'http://127.0.0.1/cdnpath/'}},
:expires => (DateTime.now + 1).to_s

View File

@ -2,7 +2,7 @@ Shindo.tests('Fog::Compute::HP', ['hp', 'compute']) do
credentials = {
:auth_token => 'auth_token',
:endpoint_url => 'http://127.0.0.1/computepath/',
:endpoints => {
:service_catalog => {
:"Compute" => {
:zone => 'http://127.0.0.1/computepath/'}},
:expires => (DateTime.now + 1).to_s

View File

@ -3,7 +3,7 @@ Shindo.tests('Fog::Storage::HP', ['hp', 'storage']) do
:auth_token => 'auth_token',
:endpoint_url => 'http://127.0.0.1/path/',
:cdn_endpoint_url => 'http://127.0.0.1/cdnpath/',
:endpoints => {
:service_catalog => {
:"Object Storage" => {
:zone => 'http://127.0.0.1/path/'},
:"CDN" => {