Class: Identity::ConnectionHandler

Inherits:
Object
  • Object
show all
Defined in:
lib/connection_handler.rb

Constant Summary collapse

@@resolver =
Identity::Resolver::StaticIdentityResolver.new

Instance Method Summary collapse

Constructor Details

#initialize(key_file, key_pass, cert_file, ca_certs = 'truststore.pem') ⇒ ConnectionHandler

Returns a new instance of ConnectionHandler.



8
9
10
11
12
13
14
15
# File 'lib/connection_handler.rb', line 8

def initialize(key_file, key_pass, cert_file, ca_certs='truststore.pem')
  @resource = RestClient::Resource.new(
    @@resolver.get_host,
    :ssl_client_key   => OpenSSL::PKey::RSA.new(File.read(key_file), key_pass),
    :ssl_client_cert  => OpenSSL::X509::Certificate.new(File.read(cert_file)),
    :ssl_ca_file      => ca_certs,
    :verify_ssl       => OpenSSL::SSL::VERIFY_PEER)
end

Instance Method Details

#make_request(path, parameters) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
# File 'lib/connection_handler.rb', line 17

def make_request(path, parameters)
  @resource = @resource.class.new(@@resolver.get_host, @resource.options)
  response = @resource[path].get :params => parameters

  if response.code != 200
    result = "<context><name>%s</name><result xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:type=\"defaultResult\" message=\"Identity Service Failure : %d\">FAILURE</result></context>" %  (parameters[:name].nil? || parameters[:name].empty?) ? 'Unknown' : parameters[:name], response.code
  else
    result = response.to_s
  end
  return result
end