Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

VEBT-777 - Add API's to connect to four DGIB endpoints for VYE #19331

Open
wants to merge 19 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 17 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,7 @@ Lint/MissingSuper:
- 'modules/va_notify/lib/va_notify/service.rb'
- 'modules/vaos/app/services/vaos/session_service.rb'
- 'modules/veteran/app/models/veteran/user.rb'
- 'modules/vye/lib/dgib/service.rb'

# Offense count: 5
Lint/NoReturnInBeginEndBlocks:
Expand Down
14 changes: 12 additions & 2 deletions config/settings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1439,10 +1439,20 @@ genisis:
pass: bogus

# Settings for connecting AFS Veteran Services
# For locahost we can use the existing certs as long as we don't call out
dgi:
# add med_api here? Will need to reach out to that team
jwt:
public_key_path: modules/meb_api/spec/fixtures/dgi_public_test.pem
private_key_path: modules/meb_api/spec/fixtures/dgi_private_test.pem
public_key_path: ""
private_key_path: ""
vye:
jwt:
# May not need the public path
public_key_path: "/dsva-vagov/vets-api/#{Settings.vsp_environment}/dgib/jwt.key"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use fake paths

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

or empty strings

private_key_path: "/dsva-vagov/vets-api/#{Settings.vsp_environment}/dgib/jwt.crt"
vets:
url: "https://dgi-uat001-vaapi.np.afsp.io/vets-service/v1"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use a fake url

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe we need that url to test with

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can assign the url to settings.local.yml so that it's not pushed to prod

mock: false
vets:
url: "https://jenkins.ld.afsp.io:32512/vets-service/v1/" # Docker setup for microservice
mock: false
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
# frozen_string_literal: true

require 'dgib/claimant_lookup/service'
require 'dgib/claimant_status/service'
require 'dgib/verification_record/service'
require 'dgib/verify_claimant/service'

module Vye
module Vye::V1
class Vye::V1::DgibVerificationsController < Vye::V1::ApplicationController
def verification_record
head :forbidden unless authorize(user_info, policy_class: UserInfoPolicy)

response = verification_service.get_verification_record(params[:claimant_id])
serializer = Vye::ClaimantVerificationSerializer
process_response(response, serializer)
end

def verify_claimant
head :forbidden unless authorize(user_info, policy_class: UserInfoPolicy)

response = verify_claimant_service.verify_claimant(
params[:claimant_id],
params[:verified_period_begin_date],
params[:verified_period_end_date],
params[:verified_through_date],
params[:verification_method],
params.dig(:app_communication, :response_type)
)

serializer = Vye::VerifyClaimantSerializer
process_response(response, serializer)
end

# the serializer for this endpoint is the same as for verify_claimant
def claimant_status
head :forbidden unless authorize(user_info, policy_class: UserInfoPolicy)

response = claimant_status_service.get_claimant_status(params[:claimant_id])
serializer = Vye::VerifyClaimantSerializer
process_response(response, serializer)
end

def claimant_lookup
head :forbidden unless authorize(user_info, policy_class: UserInfoPolicy)

response = claimant_lookup_service.claimant_lookup(current_user.ssn)
serializer = Vye::ClaimantLookupSerializer
process_response(response, serializer)
end

private

# Vye Services related stuff
def claimant_lookup_service
Vye::DGIB::ClaimantLookup::Service.new(@current_user)
end

def claimant_status_service
Vye::DGIB::ClaimantStatus::Service.new(@current_user)
end

def verification_service
Vye::DGIB::VerificationRecord::Service.new(@current_user)
end

def verify_claimant_service
Vye::DGIB::VerifyClaimant::Service.new(@current_user)
end

def process_response(response, serializer)
Rails.logger.debug { "Processing response with status: #{response.status}" }
case response.status
when 200
Rails.logger.debug 'Rendering JSON response'
render json: serializer.new(response).to_json
when 204
Rails.logger.debug 'Sending no content'
head :no_content
when 403
Rails.logger.debug 'Sending forbidden'
head :forbidden
when 404
Rails.logger.debug 'Sending not found'
head :not_found
when 422
Rails.logger.debug 'Sending unprocessable entity'
head :unprocessable_entity
else
Rails.logger.debug 'Sending internal server error'
head :internal_server_error
end
end
# End Vye Services
end
end
end
24 changes: 24 additions & 0 deletions modules/vye/app/policies/vye/user_info_policy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,29 @@ def create?
end

alias_method :show?, :create?

def claimant_lookup?
return true if user.present?

false
end

def claimant_status?
return true if user.present?

false
end

def verify_claimant?
return true if user.present?

false
end

def verification_record?
return true if user.present?

false
end
end
end
11 changes: 11 additions & 0 deletions modules/vye/app/serializers/vye/claimant_lookup_serializer.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# frozen_string_literal: true

module Vye
class ClaimantLookupSerializer < Vye::VyeSerializer
def serializable_hash
{
claimant_id: @resource.claimant_id
}
end
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# frozen_string_literal: true

module Vye
class ClaimantVerificationSerializer < Vye::VyeSerializer
def serializable_hash
{
claimant_id: @resource.claimant_id,
delimiting_date: @resource.delimiting_date,
enrollment_verifications: @resource.enrollment_verifications,
verified_details: @resource.verified_details,
payment_on_hold: @resource.payment_on_hold
}
end
end
end
14 changes: 14 additions & 0 deletions modules/vye/app/serializers/vye/verify_claimant_serializer.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# frozen_string_literal: true

module Vye
class VerifyClaimantSerializer < Vye::VyeSerializer
def serializable_hash
{
claimant_id: @resource.claimant_id,
delimiting_date: @resource.delimiting_date,
verified_details: @resource.verified_details,
payment_on_hold: @resource.payment_on_hold
}
end
end
end
19 changes: 19 additions & 0 deletions modules/vye/app/serializers/vye/vye_serializer.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# frozen_string_literal: true

module Vye
class VyeSerializer
attr_reader :resource

def initialize(resource)
@resource = resource
end

def to_json(*)
Oj.dump(serializable_hash, mode: :compat, time_format: :ruby)
end

def status
@resource.status
end
end
end
33 changes: 33 additions & 0 deletions modules/vye/config/initializers/breakers.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# frozen_string_literal: true

require 'common/client/configuration/base'
require 'common/client/configuration/rest'
require 'breakers/statsd_plugin'

# Not sure if any or all of these are needed
require 'dgib/claimant_lookup/configuration'
require 'dgib/claimant_status/configuration'
require 'dgib/verification_record/configuration'
require 'dgib/verify_claimant/configuration'

Rails.application.reloader.to_prepare do
redis_namespace = Redis::Namespace.new('breakers', redis: $redis)

services = [
Vye::DGIB::Configuration.instance.breakers_service
]

plugin = Breakers::StatsdPlugin.new

client = Breakers::Client.new(
redis_connection: redis_namespace,
services:,
logger: Rails.logger,
plugins: [plugin]
)

# No need to prefix it when using the namespace
Breakers.redis_prefix = ''
Breakers.client = client
Breakers.disabled = true if Settings.breakers_disabled
end
8 changes: 8 additions & 0 deletions modules/vye/config/initializers/dgib_requires.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# frozen_string_literal: true

# Zeitwerk was giving me fits until I added this.
# It's a little ugly, but it works.
require Rails.root.join('modules', 'vye', 'lib', 'dgib', 'claimant_lookup', 'service')
require Rails.root.join('modules', 'vye', 'lib', 'dgib', 'claimant_status', 'service')
require Rails.root.join('modules', 'vye', 'lib', 'dgib', 'verification_record', 'service')
require Rails.root.join('modules', 'vye', 'lib', 'dgib', 'verify_claimant', 'service')
5 changes: 5 additions & 0 deletions modules/vye/config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,10 @@
resource :verifications, only: [:create], path: '/verify'
resource :address_changes, only: [:create], path: '/address'
resource :direct_deposit_changes, only: [:create], path: '/bank_info'

post 'dgib_verifications/verification_record', to: 'dgib_verifications#verification_record'
post 'dgib_verifications/verify_claimant', to: 'dgib_verifications#verify_claimant'
post 'dgib_verifications/claimant_status', to: 'dgib_verifications#claimant_status'
get 'dgib_verifications/claimant_lookup', to: 'dgib_verifications#claimant_lookup'
end
end
29 changes: 29 additions & 0 deletions modules/vye/lib/dgib/authentication_token_service.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# frozen_string_literal: true

module Vye
module DGIB
class AuthenticationTokenService
ALGORITHM_TYPE = 'RS256'
E = 'AQAB'
TYP = 'JWT'
KID = 'vye'
USE = 'sig'
SIGNING_KEY = Settings.dgi.vye.jwt.private_key_path
RSA_PRIVATE = OpenSSL::PKey::RSA.new(File.read(SIGNING_KEY)) if File.exist?(SIGNING_KEY)

def self.call
payload = {
exp: Time.now.to_i + (5 * 60), # JWT expiration time (5 minutes)
nbf: Time.now.to_i,
realm_access: {
roles: ['VYE']
}
}

header_fields = { kid: KID, typ: TYP }

JWT.encode payload, RSA_PRIVATE, ALGORITHM_TYPE, header_fields
end
end
end
end
15 changes: 15 additions & 0 deletions modules/vye/lib/dgib/claimant_lookup/configuration.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# frozen_string_literal: true

require 'dgib/configuration'

module Vye
module DGIB
module ClaimantLookup
class Configuration < Vye::DGIB::Configuration
def service_name
'DGIB/ClaimantLookup'
end
end
end
end
end
19 changes: 19 additions & 0 deletions modules/vye/lib/dgib/claimant_lookup/response.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# frozen_string_literal: true

require 'dgib/response'

module Vye
module DGIB
module ClaimantLookup
class Response < Vye::DGIB::Response
attribute :claimant_id, Integer

def initialize(status, response = nil)
attributes = { claimant_id: response.body['claimant_id'] }

super(status, attributes)
end
end
end
end
end
42 changes: 42 additions & 0 deletions modules/vye/lib/dgib/claimant_lookup/service.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# frozen_string_literal: true

require 'common/client/base'
require 'dgib/authentication_token_service'
require 'dgib/service'
require 'dgib/claimant_lookup/configuration'
require 'dgib/claimant_lookup/response'

module Vye
module DGIB
module ClaimantLookup
class Service < Vye::DGIB::Service
configuration Vye::DGIB::ClaimantLookup::Configuration
STATSD_KEY_PREFIX = 'api.dgi.claimant_lookup_service'

def claimant_lookup(ssn)
params = ActionController::Parameters.new({ ssn: })
with_monitoring do
headers = request_headers
options = { timeout: 60 }
response = perform(:post, end_point, camelize_keys_for_java_service(params).to_json, headers, options)
Vye::DGIB::ClaimantLookup::Response.new(response.status, response)
end
end

private

def end_point
'dgi/vye/claimantLookup'
end

def json
nil
end

def request_headers
{ Authorization: "Bearer #{DGIB::AuthenticationTokenService.call}" }
end
end
end
end
end
Loading
Loading