Skip to content

Commit

Permalink
Mobile: Relocate logging of sso information to controller concern (#1…
Browse files Browse the repository at this point in the history
…2486)

* Add logging for contact information updates

* Add more logging locations and start tweaking tests

* Add expiration to test

* Move logging and tests to profile base controller

* Please rubocop

* Remove duplicate logging

* Remove duplicate logging

* Move files back

* Remove unnecessary file

* Make rubocop happy

* Relocate sso logging logic to a controller concern and include that in payment information

* Zeitwerk fix
  • Loading branch information
Tonksthebear authored Apr 26, 2023
1 parent ecdd161 commit 45d5818
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 49 deletions.
56 changes: 56 additions & 0 deletions modules/mobile/app/controllers/mobile/concerns/sso_logging.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# frozen_string_literal: true

module Mobile::Concerns::SSOLogging
extend ActiveSupport::Concern

included do
after_action :log_sso_info, only: %i[create update destroy]

def log_sso_info
action = request.controller_instance.controller_path.classify.to_s
action += 'Controller#'
action += request.parameters['action'].to_s

Rails.logger.warn(
"#{action} request completed", sso_logging_info
)
end

def sso_logging_info
{ user_uuid: @current_user&.uuid,
sso_cookie_contents: sso_cookie_content,
request_host: request.host }
end

def sso_cookie_content
return nil if @current_user.blank?

{ 'patientIcn' => @current_user.icn,
'signIn' => @current_user.identity.sign_in.deep_transform_keys { |key| key.to_s.camelize(:lower) },
'credential_used' => @current_user.identity.sign_in[:service_name],
'expirationTime' => if sis_authentication?
sign_in_expiration_time
else
@current_user.identity.expiration_timestamp
end }
end

def sign_in_expiration_time
if sis_authentication?
if sign_in_service_session
sign_in_service_session.refresh_expiration.iso8601(0)
else
@session_object.ttl_in_time.iso8601(0)
end
else
@current_user.identity.expiration_timestamp
end
end

def sign_in_service_session
return unless @access_token

@sign_in_service_session ||= SignIn::OAuthSession.find_by(handle: @access_token.session_handle)
end
end
end
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
# frozen_string_literal: true

require 'evss/ppiu/service'
require_relative '../concerns/sso_logging'

module Mobile
module V0
class PaymentInformationController < ApplicationController
include Mobile::Concerns::SSOLogging

before_action { authorize :evss, :access? }
before_action { authorize :ppiu, :access? }
before_action :validate_pay_info, only: :update
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@

require_dependency 'mobile/application_controller'
require 'va_profile/address_validation/service'
require_relative '../concerns/sso_logging'

module Mobile
module V0
class ProfileBaseController < ApplicationController
include Vet360::Writeable
include Mobile::Concerns::SSOLogging

before_action { authorize :vet360, :access? }

after_action :log_sso_info, only: %i[create update destroy]
after_action :invalidate_cache

skip_after_action :invalidate_cache, only: [:validation]
Expand All @@ -24,53 +24,6 @@ def render_transaction_to_json(transaction)
def service
Mobile::V0::Profile::SyncUpdateService.new(@current_user)
end

def log_sso_info
action = request.controller_instance.controller_path.classify.to_s
action += 'Controller#'
action += request.parameters['action'].to_s

Rails.logger.warn(
"#{action} request completed", sso_logging_info
)
end

def sso_logging_info
{ user_uuid: @current_user&.uuid,
sso_cookie_contents: sso_cookie_content,
request_host: request.host }
end

def sso_cookie_content
return nil if @current_user.blank?

{ 'patientIcn' => @current_user.icn,
'signIn' => @current_user.identity.sign_in.deep_transform_keys { |key| key.to_s.camelize(:lower) },
'credential_used' => @current_user.identity.sign_in[:service_name],
'expirationTime' => if sis_authentication?
sign_in_expiration_time
else
@current_user.identity.expiration_timestamp
end }
end

def sign_in_expiration_time
if sis_authentication?
if sign_in_service_session
sign_in_service_session.refresh_expiration.iso8601(0)
else
@session_object.ttl_in_time.iso8601(0)
end
else
@current_user.identity.expiration_timestamp
end
end

def sign_in_service_session
return unless @access_token

@sign_in_service_session ||= SignIn::OAuthSession.find_by(handle: @access_token.session_handle)
end
end
end
end

0 comments on commit 45d5818

Please sign in to comment.