Class: VeteranVerification::Configuration

Inherits:
Common::Client::Configuration::REST show all
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

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, options = {})
  if get_access_token?
    token_service(
      lighthouse_client_id,
      lighthouse_rsa_key_path,
      options[:aud_claim_url],
      options[:host]
    ).get_token(options[: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.

Parameters:

  • host (String) (defaults to: nil)

    (optional): a configurable base url host if the client application does not want to use the default

Returns:

  • (String)

    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

#connectionFaraday::Connection

Creates a Faraday connection with parsing json and breakers functionality.

Returns:

  • (Faraday::Connection)

    a Faraday connection instance.



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: request_options) 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

Parameters:

  • path: (string)

    the endpoint to call

  • lighthouse_client_id: (string)

    client id retrieved from Lighthouse team to call Veteran Verification APIs

  • lighthouse_rsa_key_path: (string)

    the absolute path to the file that the client id was created from

  • options: (hash)

    options to override aud_claim_url, params, and auth_params

  • options (Hash) (defaults to: {})

    a customizable set of options

Options Hash (options):

  • :params (hash)

    body for the request

  • :aud_claim_url (string)

    option to override the aud_claim_url for LH Veteran Verification APIs

  • :auth_params (hash)

    a hash to send in auth params to create the access token such as the launch context

  • :host (string)

    a base host for the Lighthouse API call



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, options = {})
  connection
    .get(
      path,
      options[:params],
      {
        Authorization: "Bearer #{
          access_token(
            lighthouse_client_id,
            lighthouse_rsa_key_path,
            options
          )
        }"
      }
    )
end

#get_access_token?Boolean (private)

Returns:

  • (Boolean)


98
99
100
# File 'lib/lighthouse/veteran_verification/configuration.rb', line 98

def get_access_token?
  !use_mocks? || Settings.betamocks.recording
end

#service_nameString

Returns Service name to use in breakers and metrics.

Returns:

  • (String)

    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

#settingsConfig::Options

Returns Settings for veteran_verification API.

Returns:

  • (Config::Options)

    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.

Returns:

  • (Boolean)

    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