Class: Common::Client::Configuration::SOAP

Inherits:
Base
  • Object
show all
Defined in:
lib/common/client/configuration/soap.rb

Overview

Configuration for SOAP based services.

Examples:

Create a configuration and use it in a service.

class MyConfiguration < Common::Client::Configuration::REST
  def base_path
    Settings.my_service.url
  end

  def service_name
    'MyServiceName'
  end

  def connection
    Faraday.new(base_path, headers: base_request_headers, request: request_opts, ssl: ssl_opts) do |conn|
      conn.use :breakers
      conn.request :soap_headers

      conn.response :soap_parser
      conn.response :betamocks if Settings.emis.mock
      conn.adapter Faraday.default_adapter
    end
  end
end

class MyService < Common::Client::Base
  configuration MyConfiguration
end

Instance Attribute Summary

Attributes inherited from Base

#base_request_headers, #open_timeout, #read_timeout, #request_types, #user_agent

Instance Method Summary collapse

Methods inherited from Base

#base_path, #breakers_error_threshold, #breakers_exception_handler, #breakers_matcher, #breakers_service, #create_new_breakers_service, #request_options, #service_exception, #service_name

Instance Method Details

#allow_missing_certs?Boolean

Used to allow testing without SSL certs in place. Override this method in sub-classes.

Returns:

  • (Boolean)

    Boolean false by default



83
84
85
# File 'lib/common/client/configuration/soap.rb', line 83

def allow_missing_certs?
  false
end

#ssl_certObject

Reads in the SSL cert to use for the connection

Returns:

  • OpenSSL::X509::Certificate cert instance



50
51
52
53
54
55
56
57
58
59
60
# File 'lib/common/client/configuration/soap.rb', line 50

def ssl_cert
  OpenSSL::X509::Certificate.new(File.read(self.class.ssl_cert_path))
rescue => e
  # :nocov:
  unless allow_missing_certs?
    Rails.logger.warn "Could not load #{service_name} SSL cert: #{e.message}"
    raise e if Rails.env.production?
  end
  nil
  # :nocov:
end

#ssl_keyObject

Reads in the SSL key to use for the connection

Returns:

  • OpenSSL::PKey::RSA key instance



67
68
69
70
71
72
73
74
75
76
# File 'lib/common/client/configuration/soap.rb', line 67

def ssl_key
  OpenSSL::PKey::RSA.new(File.read(self.class.ssl_key_path))
rescue => e
  # :nocov:
  Rails.logger.warn "Could not load #{service_name} SSL key: #{e.message}"
  raise e if Rails.env.production?

  nil
  # :nocov:
end