Class: VeteranVerification::Configuration
- Inherits:
-
Common::Client::Configuration::REST
- Object
- Common::Client::Configuration::Base
- Common::Client::Configuration::REST
- VeteranVerification::Configuration
- Defined in:
- lib/lighthouse/veteran_verification/configuration.rb
Constant Summary collapse
- API_SCOPES =
%w[disability_rating.read veteran_status.read].freeze
- VETERAN_VERIFICATION_PATH =
'services/veteran_verification/v2'
- TOKEN_PATH =
'oauth2/veteran-verification/system/v1/token'
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
- #access_token(lighthouse_client_id = nil, lighthouse_rsa_key_path = nil, options = {}) ⇒ Object private
- #base_api_path(host = nil) ⇒ Object
-
#base_path(host = nil) ⇒ String
Base path for veteran_verification URLs.
-
#connection ⇒ Faraday::Connection
Creates a Faraday connection with parsing json and breakers functionality.
- #get(path, lighthouse_client_id = nil, lighthouse_rsa_key_path = nil, options = {}) ⇒ Object
- #get_access_token? ⇒ Boolean private
-
#service_name ⇒ String
Service name to use in breakers and metrics.
-
#settings ⇒ Config::Options
Settings for veteran_verification API.
- #token_service(lighthouse_client_id, lighthouse_rsa_key_path, aud_claim_url = nil, host = nil) ⇒ Object private
-
#use_mocks? ⇒ Boolean
private
Should the service use mock data in lower environments.
Methods inherited from Common::Client::Configuration::Base
#breakers_error_threshold, #breakers_exception_handler, #breakers_matcher, #breakers_service, #create_new_breakers_service, #current_module, #request_options, #service_exception
Instance Method Details
#access_token(lighthouse_client_id = nil, lighthouse_rsa_key_path = nil, options = {}) ⇒ Object (private)
102 103 104 105 106 107 108 109 110 111 |
# File 'lib/lighthouse/veteran_verification/configuration.rb', line 102 def access_token(lighthouse_client_id = nil, lighthouse_rsa_key_path = nil, = {}) if get_access_token? token_service( lighthouse_client_id, lighthouse_rsa_key_path, [:aud_claim_url], [:host] ).get_token([:auth_params]) end end |
#base_api_path(host = nil) ⇒ Object
32 33 34 |
# File 'lib/lighthouse/veteran_verification/configuration.rb', line 32 def base_api_path(host = nil) "#{base_path(host)}/#{VETERAN_VERIFICATION_PATH}" end |
#base_path(host = nil) ⇒ String
Returns Base path for veteran_verification URLs.
28 29 30 |
# File 'lib/lighthouse/veteran_verification/configuration.rb', line 28 def base_path(host = nil) (host || settings.host).to_s end |
#connection ⇒ Faraday::Connection
Creates a Faraday connection with parsing json and breakers functionality.
75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/lighthouse/veteran_verification/configuration.rb', line 75 def connection @conn ||= Faraday.new(base_api_path, headers: base_request_headers, request: ) do |faraday| faraday.use :breakers faraday.use Faraday::Response::RaiseError faraday.request :multipart faraday.request :json faraday.response :betamocks if use_mocks? faraday.response :json faraday.adapter Faraday.default_adapter end end |
#get(path, lighthouse_client_id = nil, lighthouse_rsa_key_path = nil, options = {}) ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/lighthouse/veteran_verification/configuration.rb', line 53 def get(path, lighthouse_client_id = nil, lighthouse_rsa_key_path = nil, = {}) connection .get( path, [:params], { Authorization: "Bearer #{ access_token( lighthouse_client_id, lighthouse_rsa_key_path, ) }" } ) end |
#get_access_token? ⇒ Boolean (private)
98 99 100 |
# File 'lib/lighthouse/veteran_verification/configuration.rb', line 98 def get_access_token? !use_mocks? || Settings.betamocks.recording end |
#service_name ⇒ String
Returns Service name to use in breakers and metrics.
39 40 41 |
# File 'lib/lighthouse/veteran_verification/configuration.rb', line 39 def service_name 'VeteranVerification' end |
#settings ⇒ Config::Options
Returns Settings for veteran_verification API.
19 20 21 |
# File 'lib/lighthouse/veteran_verification/configuration.rb', line 19 def settings Settings.lighthouse.veteran_verification end |
#token_service(lighthouse_client_id, lighthouse_rsa_key_path, aud_claim_url = nil, host = nil) ⇒ Object (private)
113 114 115 116 117 118 119 120 121 122 123 124 125 |
# File 'lib/lighthouse/veteran_verification/configuration.rb', line 113 def token_service(lighthouse_client_id, lighthouse_rsa_key_path, aud_claim_url = nil, host = nil) # default client id and rsa key is used from the form526 block lighthouse_client_id = settings.form526.access_token.client_id if lighthouse_client_id.nil? lighthouse_rsa_key_path = settings.form526.access_token.rsa_key if lighthouse_rsa_key_path.nil? host ||= base_path(host) url = "#{host}/#{TOKEN_PATH}" aud_claim_url ||= settings.aud_claim_url @token_service ||= Auth::ClientCredentials::Service.new( url, API_SCOPES, lighthouse_client_id, aud_claim_url, lighthouse_rsa_key_path, 'veteran-verification' ) end |
#use_mocks? ⇒ Boolean (private)
Returns Should the service use mock data in lower environments.
94 95 96 |
# File 'lib/lighthouse/veteran_verification/configuration.rb', line 94 def use_mocks? settings.use_mocks || false end |