Module: RazorRisk::Cassini::Util::ProgramExecutionUtil

Includes:
Pantheios, RazorRisk::Core::Diagnostics::Logger, RazorRisk::Core::System::SystemTraits, Xqsr3::Quality::ParameterChecking
Defined in:
lib/razor_risk/cassini/util/program_execution_util.rb

Defined Under Namespace

Modules: Constants, Util_Internals_ Classes: Command

Instance Method Summary collapse

Instance Method Details

#make_microservice_command(microservice_name, security_model, razor_executable, cassini_root_directory, clarite_config_path, host, port, url_path, **options) ⇒ Array<::String, ::String>

Creates a string that can be used to start a mircoservice from the CLI.

Parameters:

  • microservice_name (::String) —

    The name of the microservice.

  • security_model (:basic, :authorisation_only, :jwt) —

    The security model the microservice is to use.

  • razor_executable (::String) —

    The path to the RazorRequest executable file.

  • cassini_root_directory (::String) —

    The path to the root direcotry Cassini is installed in.

  • clarite_config_path (::String) —

    The path the ClarITe config XML file.

  • host (::String) —

    The URI host the microservice will be accessible at.

  • port (::String) —

    The URI port the microservice will be accessible at.

  • url_path (::String) —

    The URL path the microservice will be accessible at.

  • options (::Hash) —

    The options hash.

Options Hash (**options):

  • razor_environment (::String) —

    The Razor environment to connect to.

  • razor_space (::String) —

    The Razor space to connect to.

  • razor_alias (::String) —

    The Razor alias to connect to.

  • :benchmark (Boolean) —

    Causes the child processes to be run with benchmarking enabled.

  • :debug (Boolean) —

    Determines whether to run child processes in debug mode.

  • :log_threshold (::Symbol) —

    Specifies the log-threshold to be used with the child process.

  • :uri_scheme ('http', 'https') —

    Determines whether to the target URI is to be hit with the HTTPS protocol, rather than HTTP.

  • :path (::String) —

    Specifies a specific path to be used, thereby suppressing the normal inference mechanism.

  • :additional_arguments (::String, Array<::String>) —

    Some additional arguments to be incorporated, which will be ...

Returns:

  • (Array<::String, ::String>) —

    A tuple of command + URL



233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
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
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
# File 'lib/razor_risk/cassini/util/program_execution_util.rb', line 233

def make_microservice_command \
    microservice_name,
    security_model,
    razor_executable,
    cassini_root_directory,
    clarite_config_path,
    host,
    port,
    url_path,
    **options

    trace ParamNames[ :microservice_name, :security_model, :razor_executable, :cassini_root_directory, :clarite_config_path, :host, :port, :url_path, :options ], microservice_name, security_model, razor_executable, cassini_root_directory, clarite_config_path, host, port, url_path, options

    check_parameter security_model, 'security_model', type: ::Symbol, values: [ :basic, :authorisation_only, :jwt ]
    check_parameter cassini_root_directory, 'cassini_root_directory', types: [ ::Recls::Entry, ::String ]
    check_parameter port, 'port', type: ::Integer


    # 1. Form command


    cmd = if options[:ruby_path]
        options[:ruby_path]
    else
        "ruby" + (Recls::Ximpl::OS::OS_IS_WINDOWS ? '.exe' : '')
    end

    cmd     =   add_command_element_ cmd, '-d' if options[:debug]

    rel_l1  =   options[:restful] ? 'tools/services/restful' : 'tools/services'

    if options[:path]

        cmd =   add_command_element_ cmd, options[:path]
    else

        cmd =   add_command_element_ cmd, Recls.combine_paths(cassini_root_directory, rel_l1, microservice_name, 'ws.rb', canonicalise: true)
    end

    cmd     =   add_command_element_ cmd, '-x', [razor_executable].flatten.join(windows? ? ';' : ':') if razor_executable
    cmd     =   add_command_element_ cmd, '-e', options[:razor_environment] if options[:razor_environment]
    cmd     =   add_command_element_ cmd, '--razor-alias', options[:razor_alias] if options[:razor_alias]
    cmd     =   add_command_element_ cmd, '--razor-space', options[:razor_space] if options[:razor_space]

    case security_model
    when :basic

        sm  =   'b'
    when :authorisation_only

        sm  =   'a'
    when :jwt

        sm  =   'j'
    else

        log :violation, 'unrecognised security model \'', security_model, ?'
    end

    cmd = add_command_element_ cmd, '-a', sm
    cmd = add_command_element_ cmd, '-h', host if host
    cmd = add_command_element_ cmd, '-p', port
    cmd = add_command_element_ cmd, '-o', clarite_config_path if clarite_config_path
    cmd = add_command_element_ cmd, '-s', options[:secret_server] if options[:secret_server]
    cmd = add_command_element_ cmd, '-j', options[:jwt_encoding_algorithm] if options[:jwt_encoding_algorithm]
    cmd = add_command_element_ cmd, '-w', options[:web_server] if options[:web_server]
    cmd = add_command_element_ cmd, '-u', options[:web_ui_server] if options[:web_ui_server]
    cmd = add_command_element_ cmd, '--benchmark' if options[:benchmark]
    cmd = add_command_element_ cmd, '--authorization-test-mode' if options[:auth_test_mode]

    if lt = options[:log_threshold]

        case lt
        when :debug4, 'debug4'

            lt  =   :debug
        when ::Array

            lt  =   lt.empty? ? nil : lt.join(',')
        else

        end

        cmd =   add_command_element_ cmd, '--log-threshold', lt, use_equal: true
    end

    if ld = options[:log_directory]
        cmd =   add_command_element_ cmd, '--log-directory', ld, use_equal: true
    end

    pr_name =   options[:program_name] || microservice_name

    cmd     =   add_command_element_ cmd, '--program-name', pr_name, use_equal: true

    if rc = options[:routes_config]

        cmd =   add_command_element_ cmd, rc
    end

    case aa = options[:additional_arguments]
    when nil

        ;
    when ::Array

        aa.each do |a|

            case a
            when ::Array

                warn "processing additional arguments array element that does not contain exactly two elements" unless 2 == a.size

                cmd =   add_command_element_ cmd, a[0], a[1], use_equal: true
            else # ::String


                cmd =   add_command_element_ cmd, a
            end
        end

    else # ::String


        cmd =   add_command_element_ cmd, aa
    end

    # 2. Form URL


    scheme  =   options[:uri_scheme] || 'http'
    host    ||= 'localhost'
    path    =   '/' == (url_path || '')[0] ? url_path : "/#{url_path}"
    url     =   "#{scheme}://#{host}:#{port}#{path}"
    uri     =   URI.parse url

    # 3. Form return value


    log :debug2, 'creating microservice: url=\'', url, '\'; cmd=\'', cmd, ?'

    Command.[](cmd, uri)
end

#make_secretserver_command(cassini_root_directory, secrets_path, host, port, **options) ⇒ Object



108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
# File 'lib/razor_risk/cassini/util/program_execution_util.rb', line 108

def make_secretserver_command \
    cassini_root_directory,
    secrets_path,
    host,
    port,
    **options

    trace ParamNames[ :cassini_root_directory, :secrets_path, :host, :port, :options ], cassini_root_directory, secrets_path, host, port, options

    check_parameter cassini_root_directory, 'cassini_root_directory', types: [ ::Recls::Entry, ::String ]
    check_parameter port, 'port', type: ::Integer

    # 1. Form command


    cmd = if options[:ruby_path]
        options[:ruby_path]
    else
        "ruby" + (Recls::Ximpl::OS::OS_IS_WINDOWS ? '.exe' : '')
    end

    cmd     =   add_command_element_ cmd, '-d' if options[:debug]

    if options[:path]

        cmd =   add_command_element_ cmd, options[:path]
    else

        cmd =   add_command_element_ cmd, Recls.combine_paths(cassini_root_directory, 'tools/utilities', Constants::SecretServer::DEFAULT_NAME, 'ws.rb', canonicalise: true)
    end

    cmd     =   add_command_element_ cmd, '-h', host if host

    cmd     =   add_command_element_ cmd, '-p', port

    cmd     =   add_command_element_ cmd, '-w', options[:web_server] if options[:web_server]

    cmd     =   add_command_element_ cmd, Recls.combine_paths(cassini_root_directory, secrets_path, canonicalise: true)

    if lt = options[:log_threshold]

        case lt
        when :debug4, 'debug4'

            lt  =   :debug
        when ::Array

            lt  =   lt.empty? ? nil : lt.join(',')
        else

        end

        cmd =   add_command_element_ cmd, '--log-threshold', lt, use_equal: true
    end

    if ld = options[:log_directory]
        cmd =   add_command_element_ cmd, '--log-directory', ld, use_equal: true
    end

    pr_name =   options[:program_name] || Constants::SecretServer::DEFAULT_NAME

    cmd     =   add_command_element_ cmd, '--program-name', pr_name, use_equal: true

    if rc = options[:routes_config]

        cmd =   add_command_element_ cmd, rc
    end


    # 2. Form URL


    url_path=   '/'
    scheme  =   options[:uri_scheme] || 'http'
    host    ||= 'localhost'
    path    =   '/' == (url_path || '')[0] ? url_path : '/' + url_path
    url     =   "#{scheme}://#{host}:#{port}#{path}"
    uri     =   URI.parse url


    # 3. Form return value


    log :debug2, 'creating secret server: url=\'', url, '\'; cmd=\'', cmd, ?'

    Command.[](cmd, uri)
end

#program_name_from_executable(p) ⇒ Object



103
104
105
106
# File 'lib/razor_risk/cassini/util/program_execution_util.rb', line 103

def program_name_from_executable p

    p.to_s.split(windows? ? /[;|]/ : /[:|]/)[0]
end