legacy swauth 1.0/1.1 style authentication
# File lib/fog/hp.rb, line 64 def self.authenticate_v1(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}" # Set the User-Agent @user_agent = options[:user_agent] set_user_agent_header(connection_options, "fog/#{Fog::VERSION}", @user_agent) connection = Fog::Connection.new(service_url, false, connection_options) @hp_access_key = options[:hp_access_key] @hp_secret_key = options[:hp_secret_key] response = connection.request({ :expects => [200, 204], :headers => { 'X-Auth-Key' => @hp_secret_key, 'X-Auth-User' => @hp_access_key }, :host => @host, :port => @port, :method => 'GET', :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) end return { :auth_token => response.headers['X-Auth-Token'], :endpoint_url => nil, :cdn_endpoint_url => response.headers['X-Storage-Url'] } end
keystone based control services style authentication
# File lib/fog/hp.rb, line 105 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" # append /tokens if missing from auth uri @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) # remove the leading slash else @auth_path = "v2.0/tokens" end service_url = "#{@scheme}://#{@host}:#{@port}" # Set the User-Agent. If the caller sets a user_agent, use it. @user_agent = options[:user_agent] set_user_agent_header(connection_options, "fog/#{Fog::VERSION}", @user_agent) connection = Fog::Connection.new(service_url, false, connection_options) ### Implement HP Control Services Authentication services ### # Get the style of auth credentials passed, defaults to access/secret key style @hp_use_upass_auth_style = options[:hp_use_upass_auth_style] || false @hp_access_key = options[:hp_access_key] @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] ### Decide which auth style to use unless (@hp_use_upass_auth_style) # If Access Key style credentials are provided, use that request_body = { 'auth' => { 'apiAccessKeyCredentials' => { 'accessKey' => "#{@hp_access_key}", 'secretKey' => "#{@hp_secret_key}" } } } else # Otherwise use the Username/Password style request_body = { 'auth' => { 'passwordCredentials' => { 'username' => "#{@hp_access_key}", 'password' => "#{@hp_secret_key}" } } } end # add tenant_id if specified request_body['auth']['tenantId'] = @hp_tenant_id if @hp_tenant_id ### Make the call to CS to get auth token and service catalog 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) ### fish out auth_token and endpoint for the service auth_token = body['access']['token']['id'] endpoint_url = get_endpoint_from_catalog(body['access']['serviceCatalog'], @hp_service_type, @hp_avl_zone) # If service is Storage, then get the CDN endpoint as well. 'Name' is unique instead of 'Type' if @hp_service_type == "Object Storage" cdn_endpoint_url = get_endpoint_from_catalog(body['access']['serviceCatalog'], "CDN", @hp_avl_zone) end return { :auth_token => auth_token, :endpoint_url => endpoint_url, :cdn_endpoint_url => cdn_endpoint_url } end
CGI.escape, but without special treatment on spaces
# File lib/fog/hp.rb, line 192 def self.escape(str,extra_exclude_chars = '') str.gsub(/([^a-zA-Z0-9_.-#{extra_exclude_chars}]+)/) do '%' + $1.unpack('H2' * $1.bytesize).join('%').upcase end end
Generated with the Darkfish Rdoc Generator 2.