2011-10-17 15:25:07 -04:00
|
|
|
require(File.expand_path(File.join(File.dirname(__FILE__), 'core')))
|
2011-06-15 02:12:33 -04:00
|
|
|
|
|
|
|
module Fog
|
|
|
|
module HP
|
|
|
|
extend Fog::Provider
|
|
|
|
|
2011-10-21 00:11:08 -04:00
|
|
|
service(:cdn, 'hp/cdn', 'CDN')
|
2011-10-17 15:25:07 -04:00
|
|
|
service(:compute, 'hp/compute', 'Compute')
|
|
|
|
service(:storage, 'hp/storage', 'Storage')
|
2011-06-15 02:12:33 -04:00
|
|
|
|
2011-10-20 22:07:42 -04:00
|
|
|
def self.authenticate(options, connection_options = {})
|
|
|
|
hp_auth_uri = options[:hp_auth_uri] || "https://region-a.geo-1.objects.hpcloudsvc.com/auth/v1.0/"
|
2011-07-11 10:46:24 -04:00
|
|
|
endpoint = URI.parse(hp_auth_uri)
|
|
|
|
@scheme = endpoint.scheme || "http"
|
2011-10-20 22:07:42 -04:00
|
|
|
@host = endpoint.host || "region-a.geo-1.objects.hpcloudsvc.com"
|
2011-07-11 10:46:24 -04:00
|
|
|
@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}"
|
2011-10-20 22:07:42 -04:00
|
|
|
connection = Fog::Connection.new(service_url, false, connection_options)
|
2011-07-11 10:46:24 -04:00
|
|
|
@hp_account_id = options[:hp_account_id]
|
|
|
|
@hp_secret_key = options[:hp_secret_key]
|
2011-06-15 02:12:33 -04:00
|
|
|
response = connection.request({
|
|
|
|
:expects => [200, 204],
|
|
|
|
:headers => {
|
2011-07-11 10:46:24 -04:00
|
|
|
'X-Auth-Key' => @hp_secret_key,
|
|
|
|
'X-Auth-User' => @hp_account_id
|
2011-06-15 02:12:33 -04:00
|
|
|
},
|
2011-07-11 10:46:24 -04:00
|
|
|
:host => @host,
|
|
|
|
:port => @port,
|
2011-06-15 02:12:33 -04:00
|
|
|
:method => 'GET',
|
2011-07-11 10:46:24 -04:00
|
|
|
:path => @auth_path
|
2011-06-15 02:12:33 -04:00
|
|
|
})
|
|
|
|
response.headers.reject do |key, value|
|
|
|
|
!['X-Server-Management-Url', 'X-Storage-Url', 'X-CDN-Management-Url', 'X-Auth-Token'].include?(key)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2011-07-29 11:33:28 -04:00
|
|
|
class Mock
|
|
|
|
def self.etag
|
|
|
|
Fog::Mock.random_hex(32)
|
|
|
|
end
|
|
|
|
|
2011-11-23 13:17:43 -05:00
|
|
|
def self.key_fingerprint
|
|
|
|
fingerprint = []
|
|
|
|
20.times do
|
|
|
|
fingerprint << Fog::Mock.random_hex(2)
|
|
|
|
end
|
|
|
|
fingerprint.join(':')
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.key_material
|
|
|
|
private_key = OpenSSL::PKey::RSA.generate(1024)
|
|
|
|
public_key = private_key.public_key
|
|
|
|
return private_key.to_s, public_key.to_s
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.user_id
|
|
|
|
"dev_" + Fog::Mock.random_numbers(14)
|
|
|
|
end
|
2011-07-29 11:33:28 -04:00
|
|
|
end
|
|
|
|
|
2011-06-15 02:12:33 -04:00
|
|
|
end
|
|
|
|
end
|