Class: RazorRisk::Razor::Connectivity::Razor3::RazorRequester

Inherits:
Object
  • Object
show all
Includes:
Pantheios, Core::Diagnostics::Logger, Xqsr3::Quality::ParameterChecking
Defined in:
lib/razor_risk/razor/connectivity/razor_3/razor_requester.rb

Overview

Class that provides easy call interface to Razor, following along with the "traditional" behaviour of the RazorRequest tool

It is used by creating an instance, which requires the ClarITe config (path) and the Razor Environment name, as in:

+rr = RazorRequester.new cc_path, env_name

and then requests are dispatched to the relevant Razor installation (as named by the environment) via the send_request method, as in:

+rr.send_request request

where request is a Razor request document.

Both initialiser and send_request methods take options, as detailed in their respective documentation sections. The initialiser's :executable option is required when the class method requires_executable? returns true, and should point to the full path of the underlying RazorRequest program to be used for connectivity with the Razor system

Defined Under Namespace

Classes: Exception, Executable, InvalidCredentialsException, InvalidResponseException, RequestFailedException

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config, **options) ⇒ RazorRequester

Initialises an instance with configuration and set-up options

Parameters:

  • config (::String, nil) —

    The ClarITe configuration. By default this is interpreted as a file path, unless the option :config_as_string is given. If nil it will be obtained from option :config. One or the other must be supplied.

  • options (::Hash) —

    The options hash.

Options Hash (**options):

  • :config (::String) —

    The ClarITe configuration. By default this is interpreted as a file path, unless the option :config_as_string is given. Ignored if the parameter config is not nil.

  • :razor_environment (::String) —

    Specifies the Razor environment. May not be combinbed with :razor_alias.

  • :razor_space (::String) —

    Specifies the ClarITe space. May not be combinbed with :razor_alias.

  • :razor_alias (::String) —

    Specifies the Razor alias. May not be combinbed with :razor_environment or :razor_space.

  • :config_as_string (Boolean) —

    The config parameter [or :config option] is treated as a string containing the configuration, rather than the path to a configuration file.

  • :executable (::String) —

    Specifies the executable for RazorRequest. Required if the class method requires_executable? is true. May contain program arguments, separated using the platform-independent path separator '|' [or the platform-specific path separator - ';' for Windows; ':' otherwise].

  • :aborter (Object) —

    DEPRECATED



303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
# File 'lib/razor_risk/razor/connectivity/razor_3/razor_requester.rb', line 303

def initialize config, **options

    trace ParamNames[ :config, :options ], config, options

    check_parameter config, 'config', type: ::String, allow_nil: true

    warn ':aborter option is not longer recognised' if options[:aborter]

    # NOTE: This (ctor) method concerns itself only with specifying (and
    # validating) the executable and the configuration

    config          =   nil_if_empty(config) || nil_if_empty(options[:config]) or raise ArgumentError, 'config not specified'

    unless options[:config_as_string]
        raise ArgumentError, "given config file '#{config}' does not exist, or is not a file" unless File.file? config
    end

    unless options[:razor_environment] or options[:razor_alias]
        raise ArgumentError, 'either :razor_environment or :razor_alias options must be specified'
    end

    if self.class.requires_executable?

        executable  =   options[:executable]  or raise ArgumentError, ':executable option is required'

        @executable =   Executable.new executable
    end

    @config         =   config
    @options        =   options
end

Instance Attribute Details

#config ⇒ Object (readonly)

Returns the value of attribute config.



335
336
337
# File 'lib/razor_risk/razor/connectivity/razor_3/razor_requester.rb', line 335

def config
  @config
end

#options ⇒ Object (readonly)

Returns the value of attribute options.



336
337
338
# File 'lib/razor_risk/razor/connectivity/razor_3/razor_requester.rb', line 336

def options
  @options
end

Class Method Details

.requires_executable? ⇒ Boolean

Indicates whether the instance requires an executable

Returns:

  • (Boolean)


270
271
272
273
# File 'lib/razor_risk/razor/connectivity/razor_3/razor_requester.rb', line 270

def self.requires_executable?

    true
end

.stopgap_sql_string_validator_fix_me(str) { ... } ⇒ Object

FIXME: THIS MUST BE FIXED.

Validate that all characters in the string are alphanumerics, spaces, or underscores.

This check is temporary and does not grantee SQL safety. This must be addressed as a larger issue around sanitization of user inputs to Razor.

Examples:

Raise an exception if unsafe.

stopgap_sql_string_validator_fix_me '.!?' { raise ArgumentError }

Parameters:

  • str (String) —

    The string to be validated.

Yields:

  • Executes the block if the string is not safe.

Raises:

  • (ArgumentError) —

    If the argument is not a string.

  • (ArgumentError) —

    If the argument is not a string.



96
97
98
99
100
101
102
103
104
105
# File 'lib/razor_risk/razor/connectivity/razor_3/razor_requester.rb', line 96

def self.stopgap_sql_string_validator_fix_me str, &block

    raise ArgumentError.new 'No block was given' unless block_given?

    check_parameter str, 'str', type: ::String

    unless /^[A-Za-z0-9_ ]+$/ =~ str
        yield
    end
end

Instance Method Details

#environment ⇒ Object



342
343
344
# File 'lib/razor_risk/razor/connectivity/razor_3/razor_requester.rb', line 342

def environment
    @options[:razor_environment] || @options[:razor_alias]
end

#executable ⇒ Object



338
339
340
# File 'lib/razor_risk/razor/connectivity/razor_3/razor_requester.rb', line 338

def executable
    @executable.program_path
end

#send_request(request, **options) ⇒ Object

Sends the given request.

Parameters:

  • request (#to_s) —

    The string form of this object is used as the request.

  • options (::Hash) —

    The options hash.

Options Hash (**options):

  • :username (::String) —

    The username part of the credentials.

  • :password (::String) —

    The password to be specified as part of the credentials. Ignored unless options[:username] is specified.

  • :domain (::String) —

    The domain to be specified as part of the credentials. Ignored unless options :username] is specified.

  • :impersonatee (::String) —

    The name of the account that will be impersonated for the purposes of the request.

  • :session (Boolean) —

    Causes a Razor session to be used for the request.

  • :request_as_path (Boolean) —

    The request parameter is treated as a path to a file containing the request contents, rather than the request contents.

  • :debug (Boolean) —

    Causes certain debugging actions, including not removing temporary files.

  • :log_to_stderr (Boolean) —

    Causes the RazorRequest CLI flag '/logStderr' to be included in the command-line.

  • :request_as_string (Object) —

    DEPRECATED

Raises:

  • (ArgumentError)


372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
# File 'lib/razor_risk/razor/connectivity/razor_3/razor_requester.rb', line 372

def send_request request, **options

    trace ParamNames[ :request, :options ], request, options

    options.reject! { |k,v| v.empty? if v.respond_to? :empty? }

    unless (options[:username] && options[:password]) ||
            options[:single_sign_on]                  ||
            options[:impersonatee]                    ||
            options[:session_id]
        raise ArgumentError, 'Some form of credentials must be provided.'
    end

    # Disable session option if session already provided
    options[:session] = false if options[:session_id]

    options = @options.merge options.reject { |k| [ :config_as_string, :config ].include? k }

    raise ArgumentError, ':request_as_string option no longer supported' if options[:request_as_string]

    if (options[:razor_environment] or options[:razor_space]) and options[:razor_alias]
        raise ArgumentError, 'option :razor_alias may not be combined with :razor_environment or :razor_space'
    end

    warn ':domain option will be ignored as no username was specified' if options[:domain] and not options[:username]
    warn ':password option will be ignored as no username was specified' if options[:password] and not options[:username]

    if options[:config_as_string]

        tf = Tempfile.new('clarite_config')

        begin

            cc_path = tf.path

            tf.close

            File.open(cc_path, 'w') do |f|

                f.write @config
                f.write "\n"
            end

            do_send_request_ cc_path, request, options.reject { |k| k == :config_as_string }
        ensure

            File.unlink(cc_path)
        end
    else

        do_send_request_ @config, request, options
    end
end

#stopgap_sql_string_validator_fix_me(*args, &block) ⇒ Object

see #stopgap_sql_string_validator_fix_me



108
109
110
# File 'lib/razor_risk/razor/connectivity/razor_3/razor_requester.rb', line 108

def stopgap_sql_string_validator_fix_me *args, &block
    self.class.stopgap_sql_string_validator_fix_me(*args, &block)
end