def self.authenticate_v2(options, connection_options = {})
hp_auth_uri = options[:hp_auth_uri] || "https://region-a.geo-1.identity.hpcloudsvc.com:35357/v2.0/tokens"
@hp_auth_uri = hp_auth_uri.include?('tokens')? hp_auth_uri : hp_auth_uri + "tokens"
endpoint = URI.parse(@hp_auth_uri)
@scheme = endpoint.scheme || "https"
@host = endpoint.host || "region-a.geo-1.identity.hpcloudsvc.com"
@port = endpoint.port.to_s || "35357"
if (endpoint.path)
@auth_path = endpoint.path.slice(1, endpoint.path.length)
else
@auth_path = "v2.0/tokens"
end
service_url = "#{@scheme}://#{@host}:#{@port}"
connection = Fog::Connection.new(service_url, false, connection_options)
@hp_use_upass_auth_style = options[:hp_use_upass_auth_style] || false
@hp_account_id = options[:hp_account_id]
@hp_secret_key = options[:hp_secret_key]
@hp_tenant_id = options[:hp_tenant_id]
@hp_service_type = options[:hp_service_type]
@hp_avl_zone = options[:hp_avl_zone] || :az1
unless (@hp_use_upass_auth_style)
request_body = {
'auth' => {
'apiAccessKeyCredentials' => {
'accessKey' => "#{@hp_account_id}",
'secretKey' => "#{@hp_secret_key}"
}
}
}
else
request_body = {
'auth' => {
'passwordCredentials' => {
'username' => "#{@hp_account_id}",
'password' => "#{@hp_secret_key}"
}
}
}
end
request_body['auth']['tenantId'] = "#{@hp_tenant_id}" if @hp_tenant_id
response = connection.request(
{
:expects => 200,
:headers => {
'Content-Type' => 'application/json'
},
:host => @host,
:port => @port,
:method => 'POST',
:body => Fog::JSON.encode(request_body),
:path => @auth_path
}
)
body = Fog::JSON.decode(response.body)
auth_token = body['access']['token']['id']
endpoint_url = get_endpoint_from_catalog(body['access']['serviceCatalog'], @hp_service_type, @hp_avl_zone)
if @hp_service_type == "object-store"
cdn_endpoint_url = get_endpoint_from_catalog(body['access']['serviceCatalog'], "hpext:cdn", @hp_avl_zone)
end
return {
:auth_token => auth_token,
:endpoint_url => endpoint_url,
:cdn_endpoint_url => cdn_endpoint_url
}
end