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

Closed
wants to merge 29 commits into from
Closed
Show file tree
Hide file tree
Changes from 24 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
4fa3eee
remove comment block
GcioGregg Nov 7, 2024
cacb020
add lines back in
GcioGregg Nov 7, 2024
5bd8774
cleanup authorization check
GcioGregg Nov 7, 2024
7a5ef34
Delete modules/vye/spec/fixtures/ICA11-RCA2-combined-cert.pem
GcioGregg Nov 7, 2024
91d6857
remove certs for PR
GcioGregg Nov 7, 2024
865784f
Merge branch 'vebt-777' of github.com:department-of-veterans-affairs/…
GcioGregg Nov 7, 2024
e65ddd4
remove cert
GcioGregg Nov 7, 2024
b1c9799
remove some more certs
GcioGregg Nov 7, 2024
bde066e
fix rubocop errors
GcioGregg Nov 7, 2024
d03b6f1
fix references to certs
GcioGregg Nov 7, 2024
cba3483
reference to cert
GcioGregg Nov 7, 2024
578996e
fix cert reference
GcioGregg Nov 7, 2024
13d6292
fix failing test
nfstern02 Nov 7, 2024
ca503ec
update dgib url
GcioGregg Nov 8, 2024
43fda79
Merge branch 'vebt-777' of github.com:department-of-veterans-affairs/…
GcioGregg Nov 8, 2024
28216f6
update staging cert urls
GcioGregg Nov 8, 2024
f3381e6
fix staging cert urls
GcioGregg Nov 8, 2024
fd6bfc7
fix settings path/filenames
GcioGregg Nov 14, 2024
97c7432
fix combined cert path
GcioGregg Nov 14, 2024
cf0d483
update vye url setting to use environ variable
GcioGregg Nov 19, 2024
2272782
empty strings instead of real paths
GcioGregg Nov 19, 2024
6fae674
empty string for url due to failed test
GcioGregg Nov 19, 2024
3e08bf8
fixes from platform's comments
GcioGregg Nov 20, 2024
aa92b80
add to original breaker initializer
GcioGregg Nov 20, 2024
82519ed
Merge branch 'master' into vebt-777
nfstern02 Nov 20, 2024
95b0b44
apply recommeneded changes
nfstern02 Nov 20, 2024
37dcc34
fix failing rspecs
nfstern02 Nov 21, 2024
6566fb0
changes per platform request
GcioGregg Nov 21, 2024
5107668
add alias to policy
GcioGregg Nov 21, 2024
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
1 change: 1 addition & 0 deletions config/initializers/breakers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@
SearchTypeahead::Configuration.instance.breakers_service,
SearchClickTracking::Configuration.instance.breakers_service,
VAOS::Configuration.instance.breakers_service,
Vye::DGIB::Configuration.instance.breakers_service,
RachalCassity marked this conversation as resolved.
Show resolved Hide resolved
IAMSSOeOAuth::Configuration.instance.breakers_service,
CovidVaccine::V0::VetextConfiguration.instance.breakers_service,
VEText::Configuration.instance.breakers_service,
Expand Down
15 changes: 13 additions & 2 deletions config/settings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1439,10 +1439,21 @@ 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: ""
private_key_path: ""
public_ica11_rca2_key_path: ""
vets:
url: ""
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,99 @@
# 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
when nil
Rails.logger.debug 'No response from server'
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?
Copy link
Member

Choose a reason for hiding this comment

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

Can these policies be combined since they are the same?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Based on our understanding of how Pundit works, we need to have a policy ending with ? that matches each corresponding action in the controller

Copy link
Member

Choose a reason for hiding this comment

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

In the controller you can call one policy:

modules/vye/app/controllers/vye/v1/dgib_verifications_controller.rb
before_action { authorize :vye, :access? }

app/policies/vye_policy.rb ### NEW POLICY FILE

  def access?
      return true if user.present?

      false
  end

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: 7 additions & 7 deletions modules/vye/app/serializers/vye/verification_serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ def to_json(*)

def serializable_hash
{
award_id: @resource.award_id,
act_begin: @resource.act_begin,
act_end: @resource.act_end,
transact_date: @resource.transact_date,
monthly_rate: @resource.monthly_rate,
number_hours: @resource.number_hours,
source_ind: @resource.source_ind
award_id: @resource&.award_id,
act_begin: @resource&.act_begin,
act_end: @resource&.act_end,
transact_date: @resource&.transact_date,
monthly_rate: @resource&.monthly_rate,
number_hours: @resource&.number_hours,
source_ind: @resource&.source_ind
}
end
end
Expand Down
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
Copy link
Member

Choose a reason for hiding this comment

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

Why is this service not added to the original breakers initializer? Matching redis namespaces can cause all the data in the other redis namespace to disappear.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Based on our understanding, we added this to the original vets-api breakers initializer. Good catch, thanks for bringing this to our attention, we're still learning our way around this.

Copy link
Member

Choose a reason for hiding this comment

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

I understand. Thank you for making all these changes.

Copy link
Member

Choose a reason for hiding this comment

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

This file needs to be removed. Breakers client should not be re-initialized.

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
Loading
Loading