Class: RazorRisk::Razor::Connectivity::Razor3::RazorRequester
- Inherits:
-
Object
- Object
- RazorRisk::Razor::Connectivity::Razor3::RazorRequester
- 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
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Class Method Summary collapse
-
.requires_executable? ⇒ Boolean
Indicates whether the instance requires an executable.
-
.stopgap_sql_string_validator_fix_me(str) { ... } ⇒ Object
FIXME: THIS MUST BE FIXED.
Instance Method Summary collapse
- #environment ⇒ Object
- #executable ⇒ Object
-
#initialize(config, **options) ⇒ RazorRequester
constructor
Initialises an instance with configuration and set-up options.
-
#send_request(request, **options) ⇒ Object
Sends the given request.
-
#stopgap_sql_string_validator_fix_me(*args, &block) ⇒ Object
see #stopgap_sql_string_validator_fix_me.
Constructor Details
#initialize(config, **options) ⇒ RazorRequester
Initialises an instance with configuration and set-up options
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, ** trace ParamNames[ :config, :options ], config, check_parameter config, 'config', type: ::String, allow_nil: true warn ':aborter option is not longer recognised' if [: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([:config]) or raise ArgumentError, 'config not specified' unless [:config_as_string] raise ArgumentError, "given config file '#{config}' does not exist, or is not a file" unless File.file? config end unless [:razor_environment] or [:razor_alias] raise ArgumentError, 'either :razor_environment or :razor_alias options must be specified' end if self.class.requires_executable? executable = [:executable] or raise ArgumentError, ':executable option is required' @executable = Executable.new executable end @config = config @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 end |
Class Method Details
.requires_executable? ⇒ Boolean
Indicates whether the instance requires an executable
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.
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.
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, ** trace ParamNames[ :request, :options ], request, .reject! { |k,v| v.empty? if v.respond_to? :empty? } unless ([:username] && [:password]) || [:single_sign_on] || [:impersonatee] || [:session_id] raise ArgumentError, 'Some form of credentials must be provided.' end # Disable session option if session already provided [:session] = false if [:session_id] = @options.merge .reject { |k| [ :config_as_string, :config ].include? k } raise ArgumentError, ':request_as_string option no longer supported' if [:request_as_string] if ([:razor_environment] or [:razor_space]) and [: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 [:domain] and not [:username] warn ':password option will be ignored as no username was specified' if [:password] and not [:username] if [: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, .reject { |k| k == :config_as_string } ensure File.unlink(cc_path) end else do_send_request_ @config, request, 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 |