mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
Refactor connection parameters to accept a single endpoint and credentials.
This commit is contained in:
parent
a9b71af395
commit
469ff71ff6
2 changed files with 27 additions and 22 deletions
|
@ -10,25 +10,30 @@ module Fog
|
|||
service(:storage, 'storage/hp')
|
||||
|
||||
def self.authenticate(options)
|
||||
scheme = options[:scheme] || "http://"
|
||||
#hp_auth_url = options[:hp_auth_url] || "auth.api.rackspacecloud.com"
|
||||
@hp_host = options[:hp_host] || "fake-endpoint.api.hpcloud.com"
|
||||
@hp_port = options[:hp_port] || "80"
|
||||
@hp_auth_path = options[:hp_auth_path] || "auth/v1.0"
|
||||
hp_auth_url = "#{@hp_host}:#{@hp_port}"
|
||||
connection = Fog::Connection.new(scheme + hp_auth_url)
|
||||
@hp_username = options[:hp_username]
|
||||
@hp_password = options[:hp_password]
|
||||
hp_auth_uri = options[:hp_auth_uri] || "http://agpa-ge1.csbu.hpl.hp.com/auth/v1.0"
|
||||
endpoint = URI.parse(hp_auth_uri)
|
||||
@scheme = endpoint.scheme || "http"
|
||||
@host = endpoint.host || "agpa-ge1.csbu.hpl.hp.com"
|
||||
@port = endpoint.port.to_s || "80"
|
||||
if (endpoint.path)
|
||||
@auth_path = endpoint.path.slice(1, endpoint.path.length) # remove the leading slash
|
||||
else
|
||||
@auth_path = "auth/v1.0"
|
||||
end
|
||||
service_url = "#{@scheme}://#{@host}:#{@port}"
|
||||
connection = Fog::Connection.new(service_url)
|
||||
@hp_account_id = options[:hp_account_id]
|
||||
@hp_secret_key = options[:hp_secret_key]
|
||||
response = connection.request({
|
||||
:expects => [200, 204],
|
||||
:headers => {
|
||||
'X-Auth-Key' => @hp_password,
|
||||
'X-Auth-User' => @hp_username
|
||||
'X-Auth-Key' => @hp_secret_key,
|
||||
'X-Auth-User' => @hp_account_id
|
||||
},
|
||||
:host => @hp_host,
|
||||
:port => @hp_port,
|
||||
:host => @host,
|
||||
:port => @port,
|
||||
:method => 'GET',
|
||||
:path => @hp_auth_path
|
||||
:path => @auth_path
|
||||
})
|
||||
response.headers.reject do |key, value|
|
||||
!['X-Server-Management-Url', 'X-Storage-Url', 'X-CDN-Management-Url', 'X-Auth-Token'].include?(key)
|
||||
|
|
|
@ -2,8 +2,8 @@ module Fog
|
|||
module HP
|
||||
class Storage < Fog::Service
|
||||
|
||||
requires :hp_password, :hp_username
|
||||
recognizes :hp_host, :hp_port, :hp_auth_path, :hp_servicenet, :hp_cdn_ssl, :persistent
|
||||
requires :hp_secret_key, :hp_account_id
|
||||
recognizes :hp_auth_uri, :hp_servicenet, :hp_cdn_ssl, :persistent
|
||||
recognizes :provider # remove post deprecation
|
||||
|
||||
model_path 'fog/storage/models/hp'
|
||||
|
@ -59,16 +59,16 @@ module Fog
|
|||
end
|
||||
|
||||
require 'mime/types'
|
||||
@hp_password = options[:hp_password]
|
||||
@hp_username = options[:hp_username]
|
||||
@hp_secret_key = options[:hp_secret_key]
|
||||
@hp_account_id = options[:hp_account_id]
|
||||
end
|
||||
|
||||
def data
|
||||
self.class.data[@hp_username]
|
||||
self.class.data[@hp_account_id]
|
||||
end
|
||||
|
||||
def reset_data
|
||||
self.class.data.delete(@hp_username)
|
||||
self.class.data.delete(@hp_account_id)
|
||||
end
|
||||
|
||||
end
|
||||
|
@ -87,8 +87,8 @@ module Fog
|
|||
|
||||
require 'mime/types'
|
||||
require 'json'
|
||||
@hp_password = options[:hp_password]
|
||||
@hp_username = options[:hp_username]
|
||||
@hp_secret_key = options[:hp_secret_key]
|
||||
@hp_account_id = options[:hp_account_id]
|
||||
@hp_cdn_ssl = options[:hp_cdn_ssl]
|
||||
credentials = Fog::HP.authenticate(options)
|
||||
@auth_token = credentials['X-Auth-Token']
|
||||
|
|
Loading…
Reference in a new issue