Class: EVSS::BaseService
Constant Summary
collapse
- SYSTEM_NAME =
'vets.gov'
- DEFAULT_TIMEOUT =
40
Class Method Summary
collapse
Instance Method Summary
collapse
#log_exception_to_sentry, #log_message_to_sentry, #non_nil_hash?, #normalize_level, #rails_logger, #set_sentry_metadata
Constructor Details
#initialize(headers, use_mock = false) ⇒ BaseService
Returns a new instance of BaseService.
14
15
16
17
|
# File 'lib/evss/base_service.rb', line 14
def initialize(, use_mock = false)
@headers =
@use_mock = use_mock
end
|
Class Method Details
.create_breakers_service(name:, url:) ⇒ Object
19
20
21
22
23
24
25
26
27
28
29
30
|
# File 'lib/evss/base_service.rb', line 19
def self.create_breakers_service(name:, url:)
path = URI.parse(url).path
host = URI.parse(url).host
matcher = proc do |request_env|
request_env.url.host == host && request_env.url.path =~ /^#{path}/
end
Breakers::Service.new(
name:,
request_matcher: matcher
)
end
|
Instance Method Details
#base_url ⇒ Object
42
43
44
|
# File 'lib/evss/base_service.rb', line 42
def base_url
self.class::BASE_URL
end
|
#cert? ⇒ Boolean
85
86
87
88
89
90
|
# File 'lib/evss/base_service.rb', line 85
def cert?
Settings.evss.cert_path.present? ||
Settings.evss.key_path.present? ||
Settings.evss.root_cert_path.present?
end
|
#client_cert ⇒ Object
93
94
95
|
# File 'lib/evss/base_service.rb', line 93
def client_cert
OpenSSL::X509::Certificate.new File.read(Settings.evss.cert_path)
end
|
#client_key ⇒ Object
97
98
99
|
# File 'lib/evss/base_service.rb', line 97
def client_key
OpenSSL::PKey::RSA.new File.read(Settings.evss.key_path)
end
|
#conn ⇒ Object
Uses HTTPClient adapter because headers need to be sent unmanipulated Net/HTTP capitalizes headers
58
59
60
61
62
63
64
65
66
67
68
69
|
# File 'lib/evss/base_service.rb', line 58
def conn
@conn ||= Faraday.new(base_url, headers: @headers, ssl: ssl_options, request: timeout) do |faraday|
faraday.use :breakers
faraday.use Faraday::Response::RaiseError
faraday.use EVSS::ErrorMiddleware
faraday.response :betamocks if @use_mock
faraday.response :snakecase, symbolize: false
faraday.response :json_parser
faraday.use :remove_cookies
faraday.adapter :httpclient
end
end
|
#get(url) ⇒ Object
34
35
36
|
# File 'lib/evss/base_service.rb', line 34
def get(url)
conn.get url
end
|
#post(url, body = nil, headers = { 'Content-Type' => 'application/json' }) ⇒ Object
38
39
40
|
# File 'lib/evss/base_service.rb', line 38
def post(url, body = nil, = { 'Content-Type' => 'application/json' }, &)
conn.post(url, body, , &)
end
|
#root_ca ⇒ Object
101
102
103
|
# File 'lib/evss/base_service.rb', line 101
def root_ca
Settings.evss.root_cert_path
end
|
#ssl_options ⇒ Object
71
72
73
74
75
76
77
78
79
80
81
82
83
|
# File 'lib/evss/base_service.rb', line 71
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
|
#timeout ⇒ Object
46
47
48
49
50
51
52
|
# File 'lib/evss/base_service.rb', line 46
def timeout
{
timeout: self.class::DEFAULT_TIMEOUT,
open_timeout: self.class::DEFAULT_TIMEOUT,
write_timeout: self.class::DEFAULT_TIMEOUT
}
end
|