-
Notifications
You must be signed in to change notification settings - Fork 66
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
Changes from all commits
Commits
Show all changes
29 commits
Select commit
Hold shift + click to select a range
4fa3eee
remove comment block
GcioGregg cacb020
add lines back in
GcioGregg 5bd8774
cleanup authorization check
GcioGregg 7a5ef34
Delete modules/vye/spec/fixtures/ICA11-RCA2-combined-cert.pem
GcioGregg 91d6857
remove certs for PR
GcioGregg 865784f
Merge branch 'vebt-777' of github.com:department-of-veterans-affairs/…
GcioGregg e65ddd4
remove cert
GcioGregg b1c9799
remove some more certs
GcioGregg bde066e
fix rubocop errors
GcioGregg d03b6f1
fix references to certs
GcioGregg cba3483
reference to cert
GcioGregg 578996e
fix cert reference
GcioGregg 13d6292
fix failing test
nfstern02 ca503ec
update dgib url
GcioGregg 43fda79
Merge branch 'vebt-777' of github.com:department-of-veterans-affairs/…
GcioGregg 28216f6
update staging cert urls
GcioGregg f3381e6
fix staging cert urls
GcioGregg fd6bfc7
fix settings path/filenames
GcioGregg 97c7432
fix combined cert path
GcioGregg cf0d483
update vye url setting to use environ variable
GcioGregg 2272782
empty strings instead of real paths
GcioGregg 6fae674
empty string for url due to failed test
GcioGregg 3e08bf8
fixes from platform's comments
GcioGregg aa92b80
add to original breaker initializer
GcioGregg 82519ed
Merge branch 'master' into vebt-777
nfstern02 95b0b44
apply recommeneded changes
nfstern02 37dcc34
fix failing rspecs
nfstern02 6566fb0
changes per platform request
GcioGregg 5107668
add alias to policy
GcioGregg File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# frozen_string_literal: true | ||
|
||
VyePolicy = Struct.new(:user, :user_info) do | ||
def access? | ||
return true if user.present? | ||
|
||
false | ||
end | ||
|
||
alias_method :claimant_lookup?, :access? | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
101 changes: 101 additions & 0 deletions
101
modules/vye/app/controllers/vye/v1/dgib_verifications_controller.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
# 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 | ||
before_action { authorize :vye, :access? } | ||
|
||
def verification_record | ||
head :forbidden unless authorize(user_info, policy_class: VyePolicy) | ||
|
||
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: VyePolicy) | ||
|
||
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: VyePolicy) | ||
|
||
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: VyePolicy) | ||
|
||
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 |
11 changes: 11 additions & 0 deletions
11
modules/vye/app/serializers/vye/claimant_lookup_serializer.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
15 changes: 15 additions & 0 deletions
15
modules/vye/app/serializers/vye/claimant_verification_serializer.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
modules/vye/app/serializers/vye/verify_claimant_serializer.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 ClaimantStatus | ||
class Configuration < Vye::DGIB::Configuration | ||
def service_name | ||
'DGIB/ClaimantStatus' | ||
end | ||
end | ||
end | ||
end | ||
end |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.