Module: RazorRisk::Cassini::Applications::RouteVerbAdaptors::Utils

Includes:
Pantheios, RazorRisk::Core::Diagnostics::Logger, Razor::Connectivity::Razor3, Razor::Connectivity::Razor3::EntityConnectors, Xqsr3::Quality::ParameterChecking
Included in:
Login::AuthOnlyLogin, Login::BasicLogin, Login::JWTLogin, Login::JWTLogout
Defined in:
lib/razor_risk/cassini/applications/route_verb_adaptors/utils/open_session.rb,
lib/razor_risk/cassini/applications/route_verb_adaptors/utils/close_session.rb,
lib/razor_risk/cassini/applications/route_verb_adaptors/utils/call_system_status.rb

Instance Method Summary collapse

Instance Method Details

#call_system_status(cr, **options) ⇒ Object

Executes as Razor System Status request. Will halt the request if the provided credentials are invalid with a 403 status.

Parameters:

  • cr (Hash)

    A hash of credentials.

  • options (Hash)

    a customizable set of options

Options Hash (**options):

  • :razor_requester (#send_request)

    The Razor Requester to be used to send requests to the Razor application.

  • :message_map (Hash)

    The message map used to route razor requests.



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/razor_risk/cassini/applications/route_verb_adaptors/utils/call_system_status.rb', line 51

def call_system_status cr, **options

    trace ParamNames[ :cr, :options ], cr, options

    ssc = SystemStatusConnector.new(
        options[:razor_requester],
        message_map: options[:message_map],
        credentials: cr
    )

    begin
        qr = ssc.get indicate_result_by: :qualified_result
    rescue RazorRequester::InvalidCredentialsException
        halt 403, {}, 'Invalid credentials'
    rescue => x
        log :violation, "unexpected exception (#{x.class}): '#{x.message}': #{x.backtrace}"
        raise
    end

    halt 500, {}, 'Oops! Something went wrong!' unless qr.succeeded?
end

#close_session(session_id, **options) ⇒ Object

Closes a Razor Session.

Parameters:

  • session_id (String)

    The session ID to close.

  • options (Hash)

    a customizable set of options

Options Hash (**options):

  • :razor_requester (#send_request)

    The Razor Requester to be used to send requests to the Razor application.

  • :message_map (Hash)

    The message map used to route razor requests.



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/razor_risk/cassini/applications/route_verb_adaptors/utils/close_session.rb', line 53

def close_session session_id, **options

    trace ParamNames[ :session_id, :options ], session_id, options

    check_parameter session_id, 'session_id'

    ec = SessionsConnector.new(
        options[:razor_requester],
        message_map: options[:message_map],
        credentials: { session_id: session_id }
    )

    begin
        ec.close_session session_id, indicate_result_by: :qualified_result
    rescue => x
        log :violation, "unexpected exception (#{x.class}): '#{x.message}': #{x.backtrace}"
        raise
    end

    nil
end

#open_session(cr, **options) ⇒ Object

Opens a Razor session. Will halt the request if the provided credentials are invalid with a 403 status.

Parameters:

  • cr (Hash)

    A hash of credentials.

  • options (Hash)

    a customizable set of options

Options Hash (**options):

  • :razor_requester (#send_request)

    The Razor Requester to be used to send requests to the Razor application.

  • :message_map (Hash)

    The message map used to route razor requests.



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/razor_risk/cassini/applications/route_verb_adaptors/utils/open_session.rb', line 51

def open_session cr, **options

    trace ParamNames[ :cr, :options ], cr, options

    ec = SessionsConnector.new(
        options[:razor_requester],
        message_map: options[:message_map],
        credentials: cr
    )

    begin
        qr = ec.open_session indicate_result_by: :qualified_result
    rescue RazorRequester::InvalidCredentialsException
        halt 403, {}, 'Invalid credentials'
    rescue => x
        log :violation, "unexpected exception (#{x.class}): '#{x.message}': #{x.backtrace}"
        raise
    end

    halt 500, {}, 'Oops! Something went wrong!' unless qr.succeeded?

    begin
        [
            qr.result.at_xpath('@id').value,
            qr.result.at_xpath('userId').text,
            qr.result.at_xpath('userProfile/longName').text,
        ]
    rescue => x
        log :critical, "Could not extract user information from new session (#{x.class}): '#{x.message}': #{x.backtrace}"
        halt 500, {}, 'Oops! Something went wrong!'
    end
end