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

68 lines
2 KiB
Ruby
Raw Normal View History

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')
service(:compute, 'hp/compute', 'Compute')
service(:storage, 'hp/storage', 'Storage')
2011-06-15 02:12:33 -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/"
endpoint = URI.parse(hp_auth_uri)
@scheme = endpoint.scheme || "http"
@host = endpoint.host || "region-a.geo-1.objects.hpcloudsvc.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, false, connection_options)
@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 => {
'X-Auth-Key' => @hp_secret_key,
'X-Auth-User' => @hp_account_id
2011-06-15 02:12:33 -04:00
},
:host => @host,
:port => @port,
2011-06-15 02:12:33 -04:00
:method => 'GET',
: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
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
end
2011-06-15 02:12:33 -04:00
end
end