Class: EVSS::Configuration

Inherits:
Common::Client::Configuration::REST show all
Defined in:
lib/evss/configuration.rb

Instance Attribute Summary

Attributes inherited from Common::Client::Configuration::Base

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

Instance Method Summary collapse

Methods inherited from Common::Client::Configuration::Base

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

Instance Method Details

#cert?Boolean

:nocov:

Returns:

  • (Boolean)


38
39
40
41
42
43
# File 'lib/evss/configuration.rb', line 38

def cert?
  # TODO(knkski): Is this logic correct?
  Settings.evss.cert_path.present? ||
    Settings.evss.key_path.present? ||
    Settings.evss.root_cert_path.present?
end

#client_certObject

:nocov:



11
12
13
# File 'lib/evss/configuration.rb', line 11

def client_cert
  OpenSSL::X509::Certificate.new File.read(Settings.evss.cert_path)
end

#client_keyObject



15
16
17
# File 'lib/evss/configuration.rb', line 15

def client_key
  OpenSSL::PKey::RSA.new File.read(Settings.evss.key_path)
end

#connectionObject



58
59
60
61
62
# File 'lib/evss/configuration.rb', line 58

def connection
  @conn ||= Faraday.new(base_path, request: request_options, ssl: ssl_options) do |faraday|
    set_evss_middlewares(faraday)
  end
end

#mock_enabled?Boolean

Returns:

  • (Boolean)


64
65
66
67
# File 'lib/evss/configuration.rb', line 64

def mock_enabled?
  # sublcass to override
  false
end

#root_caObject



19
20
21
# File 'lib/evss/configuration.rb', line 19

def root_ca
  Settings.evss.root_cert_path
end

#set_evss_middlewares(faraday, snakecase: true) ⇒ Object



45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/evss/configuration.rb', line 45

def set_evss_middlewares(faraday, snakecase: true)
  faraday.use      :breakers
  faraday.use      EVSS::ErrorMiddleware
  faraday.use      Faraday::Response::RaiseError
  faraday.response :betamocks if mock_enabled?
  faraday.response :snakecase, symbolize: false if snakecase
  # calls to EVSS returns non JSON responses for some scenarios that don't make it through VAAFI
  # content_type: /\bjson$/ ensures only json content types are attempted to be parsed.
  faraday.response :json, content_type: /\bjson$/
  faraday.use :immutable_headers
  faraday.adapter Faraday.default_adapter
end

#ssl_optionsObject



23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/evss/configuration.rb', line 23

def ssl_options
  return { verify: false } if !cert? && (Rails.env.development? || Rails.env.test?)

  if cert?
    {
      version: :TLSv1_2,
      verify: true,
      client_cert:,
      client_key:,
      ca_file: root_ca
    }
  end
end