-
Notifications
You must be signed in to change notification settings - Fork 63
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
base: master
Are you sure you want to change the base?
Changes from 17 commits
4fa3eee
cacb020
5bd8774
7a5ef34
91d6857
865784f
e65ddd4
b1c9799
bde066e
d03b6f1
cba3483
578996e
13d6292
ca503ec
43fda79
28216f6
f3381e6
fd6bfc7
97c7432
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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" | ||
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" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please use a fake url There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I believe we need that url to test with There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
|
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 |
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 |
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 |
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 |
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 |
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') |
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 |
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 |
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 |
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use fake paths
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
or empty strings