-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into MBMS-61276-Self-Service-Pre-Need-Pre-Integ…
…ration-CMP-UUID-Text-size-Increase
- Loading branch information
Showing
63 changed files
with
1,294 additions
and
348 deletions.
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
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,73 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'decision_review_v1/utilities/logging_utils' | ||
|
||
module V1 | ||
class PensionIpfCallbacksController < ApplicationController | ||
include ActionController::HttpAuthentication::Token::ControllerMethods | ||
include DecisionReviewV1::Appeals::LoggingUtils | ||
|
||
service_tag 'pension-ipf-callbacks' | ||
|
||
skip_before_action :verify_authenticity_token, only: [:create] | ||
skip_before_action :authenticate, only: [:create] | ||
skip_after_action :set_csrf_header, only: [:create] | ||
before_action :authenticate_header, only: [:create] | ||
|
||
STATUSES_TO_IGNORE = %w[sent delivered temporary-failure].freeze | ||
|
||
def create | ||
return render json: nil, status: :not_found unless Flipper.enabled? :pension_ipf_callbacks_endpoint | ||
|
||
payload = JSON.parse(request.body.string) | ||
|
||
# save encrypted request body in database table for non-successful notifications | ||
payload_status = payload['status']&.downcase | ||
if STATUSES_TO_IGNORE.exclude? payload_status | ||
begin | ||
PensionIpfNotification.create!(payload:) | ||
rescue ActiveRecord::RecordInvalid => e | ||
log_formatted(**log_params(payload).merge(is_success: false), params: { exception_message: e.message }) | ||
return render json: { message: 'failed' } | ||
end | ||
end | ||
|
||
log_formatted(**log_params(payload).merge(is_success: true)) | ||
render json: { message: 'success' } | ||
end | ||
|
||
private | ||
|
||
def authenticate_header | ||
authenticate_user_with_token || authenticity_error | ||
end | ||
|
||
def authenticate_user_with_token | ||
Rails.logger.info('pension-ipf-callbacks-69766 - Received request, authenticating') | ||
authenticate_with_http_token do |token| | ||
return false if bearer_token_secret.nil? | ||
|
||
token == bearer_token_secret | ||
end | ||
end | ||
|
||
def authenticity_error | ||
Rails.logger.info('pension-ipf-callbacks-69766 - Failed to authenticate request') | ||
render json: { message: 'Invalid credentials' }, status: :unauthorized | ||
end | ||
|
||
def bearer_token_secret | ||
Settings.dig(:pension_ipf_vanotify_status_callback, :bearer_token) | ||
end | ||
|
||
def log_params(payload) | ||
{ | ||
key: :callbacks, | ||
form_id: '21P-527EZ', | ||
user_uuid: nil, | ||
upstream_system: 'VANotify', | ||
body: payload.merge('to' => '<FILTERED>') # scrub PII from logs | ||
} | ||
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,20 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'json_marshal/marshaller' | ||
|
||
class PensionIpfNotification < ApplicationRecord | ||
serialize :payload, JsonMarshal::Marshaller | ||
|
||
has_kms_key | ||
has_encrypted :payload, key: :kms_key, **lockbox_options | ||
|
||
validates(:payload, presence: true) | ||
|
||
before_save :serialize_payload | ||
|
||
private | ||
|
||
def serialize_payload | ||
self.payload = payload.to_json unless payload.is_a?(String) | ||
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
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
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
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
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
Binary file not shown.
Oops, something went wrong.