razorrisk-cassini-common 0.26.24

Sign up to get free protection for your applications and to get access to all the features.
Files changed (45) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG.md +22 -0
  3. data/LICENSE +5 -0
  4. data/README.md +2 -0
  5. data/Rakefile +102 -0
  6. data/lib/razor_risk/cassini/applications/microservice.rb +318 -0
  7. data/lib/razor_risk/cassini/applications/rest_framework/route_verb_dispatcher.rb +120 -0
  8. data/lib/razor_risk/cassini/applications/rest_framework/verb_handler.rb +117 -0
  9. data/lib/razor_risk/cassini/applications/route_verb_adaptors/utilities/collection_get_helper.rb +86 -0
  10. data/lib/razor_risk/cassini/applications/securable_microservice.rb +164 -0
  11. data/lib/razor_risk/cassini/applications/secured_microservice.rb +63 -0
  12. data/lib/razor_risk/cassini/applications/unsecured_microservice.rb +77 -0
  13. data/lib/razor_risk/cassini/authorisation/header_helpers.rb +271 -0
  14. data/lib/razor_risk/cassini/authorisation/security_model_helpers.rb +93 -0
  15. data/lib/razor_risk/cassini/authorisation.rb +27 -0
  16. data/lib/razor_risk/cassini/cli.rb +19 -0
  17. data/lib/razor_risk/cassini/common/version.rb +44 -0
  18. data/lib/razor_risk/cassini/common.rb +32 -0
  19. data/lib/razor_risk/cassini/constants.rb +68 -0
  20. data/lib/razor_risk/cassini/diagnostics/util_functions.rb +248 -0
  21. data/lib/razor_risk/cassini/diagnostics/zeroth_include.rb +35 -0
  22. data/lib/razor_risk/cassini/extensions/libclimate/common_options.rb +267 -0
  23. data/lib/razor_risk/cassini/extensions/libclimate.rb +26 -0
  24. data/lib/razor_risk/cassini/header_functions.rb +59 -0
  25. data/lib/razor_risk/cassini/main.rb +238 -0
  26. data/lib/razor_risk/cassini/mixin/razor_response_validator.rb +176 -0
  27. data/lib/razor_risk/cassini/testing/suppress_pantheios_logging.rb +31 -0
  28. data/lib/razor_risk/cassini/util/conversion_util.rb +176 -0
  29. data/lib/razor_risk/cassini/util/program_execution_util.rb +379 -0
  30. data/lib/razor_risk/cassini/util/secrets_util.rb +229 -0
  31. data/lib/razor_risk/cassini/util/version_util.rb +88 -0
  32. data/lib/razor_risk/sinatra/helpers/check_auth_helper.rb +209 -0
  33. data/lib/razor_risk/sinatra/helpers/validate_accept_helper.rb +69 -0
  34. data/lib/razor_risk/sinatra/helpers/validate_content_type_helper.rb +74 -0
  35. data/lib/razor_risk/sinatra/helpers/validate_query_parameters_helper.rb +198 -0
  36. data/test/scratch/cassini/util/convert_XML.rb +54 -0
  37. data/test/unit/applications/route_verb_adaptors/utilities/tc_collection_get_helper.rb +236 -0
  38. data/test/unit/applications/tc_verb_handler.rb +130 -0
  39. data/test/unit/mixin/tc_razor_response_validator.rb +328 -0
  40. data/test/unit/sinatra/helpers/tc_validate_query_parameters_helper.rb +134 -0
  41. data/test/unit/tc_authorisation_util.rb +265 -0
  42. data/test/unit/tc_load_secrets.rb +95 -0
  43. data/test/unit/util/tc_conversion_util.rb +393 -0
  44. data/test/unit/util/tc_program_execution_util.rb +462 -0
  45. metadata +380 -0
@@ -0,0 +1,267 @@
1
+ # encoding: UTF-8
2
+
3
+ # ######################################################################## #
4
+ # File: razor_risk/cassini/extensions/libclimate/common_options.rb
5
+ #
6
+ # Purpose: Extensions to libCLImate's LibCLImate::Climate class that
7
+ # are relevant to Cassini
8
+ #
9
+ # Created: 19th December 2017
10
+ # Updated: 7th November 2018
11
+ #
12
+ # Author: Matthew Wilson
13
+ #
14
+ # Copyright (c) 2017-2018, Razor Risk Technologies Pty Ltd
15
+ # All rights reserved.
16
+ #
17
+ # ######################################################################## #
18
+
19
+
20
+ require 'libclimate'
21
+
22
+ require 'highline/import'
23
+ require 'recls'
24
+ require 'xqsr3/extensions/string/map_option_string'
25
+ require 'xqsr3/quality/parameter_checking'
26
+
27
+ require 'resolv'
28
+ require 'socket'
29
+
30
+ require 'razor_risk/core/diagnostics/logger'
31
+
32
+ =begin
33
+ =end
34
+
35
+ module LibCLImate
36
+
37
+ class Climate
38
+ include ::RazorRisk::Core::Diagnostics::Logger
39
+ def option_web_server program_options, **options
40
+
41
+ ::Xqsr3::Quality::ParameterChecking.check_parameter program_options, 'program_options', type: ::Hash
42
+
43
+ self.add_option('--web-server', alias: '-w', help: 'specifies the web-server', required: options[:required]) do |o, a|
44
+
45
+ program_options[:web_server] = o.value or self.abort "invalid web server '#{o.value}'; use --help for usage"
46
+ end
47
+ end
48
+
49
+ def option_username program_options, **options
50
+
51
+ ::Xqsr3::Quality::ParameterChecking.check_parameter program_options, 'program_options', type: ::Hash
52
+
53
+ self.add_option('--username', help: 'specifies the username', required: options[:required]) do |o, a|
54
+
55
+ program_options[:username] = o.value or self.abort "invalid username '#{o.value}'; use --help for usage"
56
+ end
57
+ end
58
+
59
+ def option_password program_options, **options
60
+
61
+ ::Xqsr3::Quality::ParameterChecking.check_parameter program_options, 'program_options', type: ::Hash
62
+
63
+ self.add_option('--password', help: 'specifies the password. If no password is supplied, the user will be prompted for it', required: options[:required]) do |o, a|
64
+
65
+ password = o.value
66
+
67
+ if (password || '').empty?
68
+
69
+ password = $terminal.ask('enter password: ') { |q| q.echo = '*' }
70
+ end
71
+
72
+ program_options[:password] = password
73
+ end
74
+ end
75
+
76
+ def option_domain program_options, **options
77
+
78
+ ::Xqsr3::Quality::ParameterChecking.check_parameter program_options, 'program_options', type: ::Hash
79
+
80
+ self.add_option('--domain', help: 'specifies the domain', required: options[:required]) do |o, a|
81
+
82
+ program_options[:domain] = o.value or self.abort "invalid domain '#{o.value}'; use --help for usage"
83
+ end
84
+ end
85
+
86
+
87
+ def option_host program_options
88
+
89
+ ::Xqsr3::Quality::ParameterChecking.check_parameter program_options, 'program_options', type: ::Hash
90
+
91
+ self.add_option('--host', alias: '-h', help: 'specifies the host. Defaults to \'localhost\' in development; \'0.0.0.0\' otherwise. May also specify one of the host\'s adaptors, via a sentinel of the form \'adaptor-0\', \'adaptor-1\', ... or \'adaptor-?\' to get a list of available adaptors') do |o, a|
92
+
93
+ v = o.value or self.abort "invalid host '#{o.value}'; use --help for usage"
94
+
95
+ if /^adapt[eo]r-\?$/ =~ v
96
+
97
+ self.abort "available adaptors:\n#{Socket.ip_address_list.select { |ai| ai.ipv4_private? }.map.with_index(0) { |ai, index| "\t#{index}:\t#{ai.ip_address}" }.join(%<\n>)}", exit: 0
98
+ end
99
+
100
+ if /^adapt[eo]r-([0-9-]+)$/ =~ v
101
+
102
+ index = Integer $1
103
+
104
+ address = Socket.ip_address_list.select { |ai| ai.ipv4_private? }[index]
105
+
106
+ self.abort "invalid adaptor index #{index}" if index < 0
107
+ self.abort "this machine does not have a private adaptor at index #{index}. Specify 'adaptor-?' to obtain list of available adaptor addresses; use --help for usage" unless address
108
+
109
+ v = address.ip_address
110
+ else
111
+
112
+ begin
113
+
114
+ v = 'localhost' == v.downcase ? '127.0.0.1' : Resolv.getaddress(v)
115
+ rescue => x
116
+
117
+ self.abort "exception (#{x.class}) thrown when attempting to resolve given host name '#{v}': #{x}"
118
+ end
119
+ end
120
+
121
+ program_options[:host] = v
122
+ end
123
+ end
124
+
125
+ def option_port program_options
126
+
127
+ ::Xqsr3::Quality::ParameterChecking.check_parameter program_options, 'program_options', type: ::Hash
128
+
129
+ self.add_option('--port', alias: '-p', help: 'specifies the port. Required', required: true, required_message: "\0Port") do |o, a|
130
+
131
+ program_options[:port] = Integer(o.value, nil: true) or self.abort "invalid port '#{o.value}'; use --help for usage"
132
+ end
133
+ end
134
+
135
+ def option_clarite_config_path program_options
136
+
137
+ ::Xqsr3::Quality::ParameterChecking.check_parameter program_options, 'program_options', type: ::Hash
138
+
139
+ self.add_option('--clarite-config-path', alias: '-o', help: 'specifies the path of the ClarITe config file. Required', required: true, required_message: "\0ClarITe configuration path") do |o, a|
140
+
141
+ program_options[:clarite_config_path] = o.value or self.abort "invalid ClarITe config path '#{o.value}'; use --help for usage"
142
+ end
143
+ end
144
+
145
+ def option_authentication_scheme program_options, schemes, **options
146
+
147
+ ::Xqsr3::Quality::ParameterChecking.check_parameter program_options, 'program_options', type: ::Hash
148
+ ::Xqsr3::Quality::ParameterChecking.check_parameter schemes, 'schemes', type: [ ::String ]
149
+
150
+ self.add_option('--authentication-scheme', alias: '-a', help: "specifies the authentication scheme. Must be one of #{schemes.map { |s| %Q{'#{s}'} }.join(', ')}. Defaults to 'jwt'. If 'jwt', this requires a value to be provided for <jwt-secret-server-url>, which will be used to look up all the algorithms by the '--jwt-encoding-algorithm' and '--credentials-encoding-algorithm' as well as those specified as additional values", required: options[:required]) do |o, a|
151
+
152
+ program_options[:authentication_scheme] = (o.value || '').map_option_string(schemes) or self.abort "invalid authorisation scheme '#{o.value}'; use --help for usage"
153
+ end
154
+
155
+ self.add_flag('--authorization-test-mode', help: "specifies that the web services should be in authorization test mode which does not perform authentication. THIS MUST NOT BE USED IN PRODUCTION.") do |o, a|
156
+
157
+ program_options[:auth_test_mode] = true
158
+ end
159
+ end
160
+
161
+ # TODO: DEPRECIATED.
162
+ def option_credentials_encoding_algorithm program_options, **options
163
+
164
+ self.add_option('--credentials-encoding-algorithm', alias: '-c', help: 'Credentials encoding algorithm has been depreciated.') do |o, a|
165
+
166
+ log :warning, 'Credentials encoding algorithm has been depreciated.'
167
+ end
168
+ end
169
+
170
+ def option_jwt_encoding_algorithm program_options, **options
171
+
172
+ ::Xqsr3::Quality::ParameterChecking.check_parameter program_options, 'program_options', type: ::Hash
173
+
174
+ self.add_option('--jwt-encoding-algorithm', alias: '-j', help: 'specifies the JWT encoding algorithm (for which a secret must be retrieved). Required if the authentication scheme is \'jwt\'', required: options[:required]) do |o, a|
175
+
176
+ program_options[:jwt_encoding_algorithm] = o.value or self.abort "invalid JWT encoding algorithm '#{o.value}'; use --help for usage"
177
+ end
178
+ end
179
+
180
+ def option_secret_server_source program_options, **options
181
+
182
+ ::Xqsr3::Quality::ParameterChecking.check_parameter program_options, 'program_options', type: ::Hash
183
+
184
+ self.add_option('--secret-server-source', alias: '-s', help: 'specifies the secret server source, which may be the URL of a secret-server, or the path of a secrets file. Required if authentication scheme is \'jwt\'') do |o, a|
185
+
186
+ program_options[:secret_server_source] = o.value or self.abort "invalid secret server source '#{o.value}'; use --help for usage"
187
+ end
188
+ end
189
+
190
+ def option_razor_environment program_options
191
+
192
+ ::Xqsr3::Quality::ParameterChecking.check_parameter program_options, 'program_options', type: ::Hash
193
+
194
+ self.add_option('--razor-environment', alias: '-e', help: 'specifies the Razor environment name.') do |o, a|
195
+
196
+ program_options[:razor_environment] = o.value or self.abort "invalid Razor environment '#{o.value}'; use --help for usage"
197
+ end
198
+ end
199
+
200
+ def option_razor_alias program_options
201
+
202
+ ::Xqsr3::Quality::ParameterChecking.check_parameter program_options, 'program_options', type: ::Hash
203
+
204
+ self.add_option('--razor-alias', help: 'specifies the Razor alias.') do |o, a|
205
+
206
+ program_options[:razor_alias] = o.value or self.abort "invalid Razor alias '#{o.value}'; use --help for usage"
207
+ end
208
+ end
209
+
210
+ def option_razor_space program_options
211
+
212
+ ::Xqsr3::Quality::ParameterChecking.check_parameter program_options, 'program_options', type: ::Hash
213
+
214
+ self.add_option('--razor-space', help: 'specifies the Razor space.') do |o, a|
215
+
216
+ program_options[:razor_space] = o.value or self.abort "invalid Razor space '#{o.value}'; use --help for usage"
217
+ end
218
+ end
219
+
220
+ def option_razor_executable program_options
221
+
222
+ ::Xqsr3::Quality::ParameterChecking.check_parameter program_options, 'program_options', type: ::Hash
223
+
224
+ self.add_option('--razor-executable', alias: '-x', help: 'specifies the Razor executable path. Required', required: true, required_message: "\0Razor executable") do |o, a|
225
+
226
+ program_options[:razor_executable] = o.value or self.abort "invalid Razor executable path '#{o.value}'; use --help for usage"
227
+ end
228
+ end
229
+
230
+ def option_tls_cert_and_key program_options
231
+
232
+ ::Xqsr3::Quality::ParameterChecking.check_parameter program_options, 'program_options', type: ::Hash
233
+
234
+ self.add_option('--tls-certificate-file', help: 'specifies the TLS/SSL certificate file. If it has the extension \'.crt\' then the path will be used to infer the TLS/SSL public-key file with the extension \'.key\', otherwise the option \'--tls-public-key-file\' is required') do |o, a|
235
+
236
+ fe = Recls.stat(o.value) or self.abort "invalid/non-existant TLS certificate file '#{o.value}'; use --help for usage"
237
+
238
+ program_options[:tls_certificate_file] = fe.path
239
+
240
+ unless program_options[:tls_public_key_file]
241
+
242
+ if fe.extension == '.crt'
243
+
244
+ key_path = fe.path[0...-4] + '.key'
245
+
246
+ if File.exist? key_path
247
+
248
+ program_options[:tls_public_key_file] = key_path
249
+ end
250
+ end
251
+ end
252
+ end
253
+
254
+ self.add_option('--tls-public-key-file', help: 'specifies the TLS/SSL public-key file') do |o, a|
255
+
256
+ fe = Recls.stat(o.value) or self.abort "invalid/non-existant TLS public-key file '#{o.value}'; use --help for usage"
257
+
258
+ program_options[:tls_public_key_file] = fe.path
259
+ end
260
+ end
261
+ end
262
+
263
+ end # module LibCLImate
264
+
265
+ # ############################## end of file ############################# #
266
+
267
+
@@ -0,0 +1,26 @@
1
+ # encoding: UTF-8
2
+
3
+ # ######################################################################## #
4
+ # File: razor_risk/cassini/extensions/libclimate.rb
5
+ #
6
+ # Purpose: RazorRisk LibCLImate extensions
7
+ #
8
+ # Created: 19th December 2017
9
+ # Updated: 4th March 2018
10
+ #
11
+ # Author: Matthew Wilson
12
+ #
13
+ # Copyright (c) 2017-2018, Razor Risk Technologies Pty Ltd
14
+ # All rights reserved.
15
+ #
16
+ # ######################################################################## #
17
+
18
+
19
+ # ##########################################################################
20
+ # requires
21
+
22
+ require 'razor_risk/cassini/extensions/libclimate/common_options'
23
+
24
+ # ############################## end of file ############################# #
25
+
26
+
@@ -0,0 +1,59 @@
1
+ # encoding: UTF-8
2
+
3
+ # ######################################################################## #
4
+ # File: razor_risk/cassini/header_functions.rb
5
+ #
6
+ # Purpose: ::RazorRisk::Cassini::HeaderFunctions module
7
+ #
8
+ # Created: 25th November 2017
9
+ # Updated: 4th March 2018
10
+ #
11
+ # Author: Matthew Wilson
12
+ #
13
+ # Copyright (c) 2017-2018, Razor Risk Technologies Pty Ltd
14
+ # All rights reserved.
15
+ #
16
+ # ######################################################################## #
17
+
18
+
19
+ # ##########################################################################
20
+ # requires
21
+
22
+ require 'razor_risk/cassini/constants'
23
+
24
+ =begin
25
+ =end
26
+
27
+ module RazorRisk
28
+ module Cassini
29
+
30
+ module HeaderFunctions
31
+
32
+ #
33
+ # @return A hash, which will be empty when the scheme is not
34
+ def make_WWW_auth_header auth_by
35
+
36
+ case auth_by
37
+ when :basic
38
+
39
+ { 'WWW-Authenticate' => 'Basic' + ' realm="system", error="missing_token", error_description="The Authorization header was not supplied, or was empty"' }
40
+ when :authorisation_only
41
+
42
+ { 'WWW-Authenticate' => Constants::SCHEME_AUTH_ONLY + ' realm="system", error="missing_token", error_description="The Authorization header was not supplied, or was empty"' }
43
+ when :jwt
44
+
45
+ { 'WWW-Authenticate' => 'Bearer' + ' realm="system", error="missing_token", error_description="The Authorization header was not supplied, or was empty"' }
46
+ else
47
+
48
+ {}
49
+ end
50
+ end
51
+
52
+ end # module HeaderFunctions
53
+
54
+ end # module Cassini
55
+ end # module RazorRisk
56
+
57
+ # ############################## end of file ############################# #
58
+
59
+
@@ -0,0 +1,238 @@
1
+ # encoding: UTF-8
2
+
3
+ # ######################################################################## #
4
+ # File: razor_risk/cassini/main.rb
5
+ #
6
+ # Purpose: Main entry file for a Cassini application
7
+ #
8
+ # Author: Matthew Wilson
9
+ #
10
+ # Copyright (c) 2018, Razor Risk Technologies Pty Ltd
11
+ # All rights reserved.
12
+ #
13
+ # ######################################################################## #
14
+
15
+
16
+ # ##########################################################################
17
+ # requires
18
+
19
+ require 'razor_risk/cassini/cli'
20
+ require 'razor_risk/cassini/constants'
21
+ require 'razor_risk/cassini/diagnostics/util_functions'
22
+ require 'razor_risk/cassini/extensions/libclimate'
23
+ require 'razor_risk/cassini/util/secrets_util'
24
+
25
+ require 'razor_risk/razor/connectivity/razor_3/razor_requester'
26
+
27
+ require 'razor_risk/core/diagnostics/extensions/libclimate'
28
+
29
+ require 'razor_risk/core/diagnostics/logger'
30
+
31
+ require 'libclimate'
32
+
33
+ require 'pantheios'
34
+
35
+ require 'xqsr3/extensions/kernel/integer'
36
+
37
+ # ##########################################################################
38
+ # at_exit
39
+
40
+ at_exit do
41
+
42
+ class MainProgramLogic
43
+
44
+ extend ::RazorRisk::Cassini::Util::SecretsUtil
45
+ extend ::RazorRisk::Cassini::Diagnostics
46
+
47
+ include ::RazorRisk::Cassini::Constants
48
+ include ::RazorRisk::Razor::Connectivity::Razor3
49
+
50
+ include ::RazorRisk::Core::Diagnostics::Logger
51
+
52
+ module Constants
53
+
54
+ module Defaults
55
+
56
+ LOGGING_THRESHOLD = [ :informational, :debug ]
57
+ end # module Defaults
58
+ end # module Constants
59
+
60
+ def self.run!
61
+
62
+ abort "use of razor_risk/cassini/main requires definition of the constant TheApp" unless defined? TheApp
63
+
64
+ program_features = TheApp::PROGRAM_FEATURES.dup
65
+
66
+ program_features[:cli_has_web_server] = program_features[:has_web_server]
67
+
68
+ program_features[:cli_has_host] = program_features[:has_host]
69
+ program_features[:cli_has_port] = program_features[:has_port]
70
+
71
+ if program_features[:has_host_and_port]
72
+
73
+ program_features[:cli_has_host] = true
74
+ program_features[:cli_has_port] = true
75
+ end
76
+
77
+ if program_features[:has_razor_connectivity]
78
+
79
+ program_features[:cli_has_clarite_config_path] = true
80
+ program_features[:cli_has_razor_executable] = RazorRequester.requires_executable?
81
+ program_features[:cli_has_razor_environment] = true
82
+ program_features[:cli_has_razor_space] = true
83
+ program_features[:cli_has_razor_alias] = true
84
+ end
85
+
86
+ if program_features[:authentication]
87
+
88
+ program_features[:cli_has_authentication_scheme] = true
89
+ program_features[:cli_has_jwt_encoding_algorithm] = true
90
+ program_features[:cli_has_secret_server_source] = true
91
+ end
92
+
93
+ program_features[:copyright_year] ||= 2018
94
+
95
+ cli_usage_values = program_features[:cli_usage_values]
96
+
97
+ # ##########################################################################
98
+ # command-line parsing
99
+
100
+ options = {}
101
+
102
+ climate = LibCLImate::Climate.new do |cl|
103
+
104
+ cl.option_web_server options if program_features[:cli_has_web_server]
105
+
106
+ cl.option_host options if program_features[:cli_has_host]
107
+ cl.option_port options if program_features[:cli_has_port]
108
+
109
+ cl.option_clarite_config_path options if program_features[:cli_has_clarite_config_path]
110
+ cl.option_razor_executable options if program_features[:cli_has_razor_executable]
111
+ cl.option_razor_environment options if program_features[:cli_has_razor_environment]
112
+ cl.option_razor_space options if program_features[:cli_has_razor_space]
113
+ cl.option_razor_alias options if program_features[:cli_has_razor_alias]
114
+
115
+ cl.option_authentication_scheme options, SUPPORTED_AUTHENTICATION_SCHEMES if program_features[:cli_has_authentication_scheme]
116
+ cl.option_jwt_encoding_algorithm options if program_features[:cli_has_jwt_encoding_algorithm]
117
+ cl.option_secret_server_source options if program_features[:cli_has_secret_server_source]
118
+
119
+ cl.option_log_threshold options, default_level: Constants::Defaults::LOGGING_THRESHOLD, limit: -2
120
+
121
+ cl.info_lines = [
122
+
123
+ ::RazorRisk::Cassini::Common::DESCRIPTION,
124
+ ::RazorRisk::Cassini::CLI.Copyright(program_features[:copyright_year]),
125
+ :version,
126
+ TheApp.full_description,
127
+ ]
128
+
129
+ cl.usage_values = cli_usage_values if cli_usage_values
130
+ end
131
+
132
+ r = climate.run ARGV
133
+
134
+ # ##########################################################################
135
+ # sorting the diagnostic loggin
136
+
137
+ ::Pantheios::Core.program_name = options[:program_name] if options[:program_name]
138
+
139
+ program_name = ::Pantheios::Core.program_name
140
+ log_directory = options[:log_directory] || './logs'
141
+ log_threshold = options[:log_threshold] || Constants::Defaults::LOGGING_THRESHOLD
142
+
143
+ setup_diagnostic_logging program_name, log_directory, log_threshold
144
+
145
+ # ##########################################################################
146
+ # amass the arguments that are required
147
+
148
+ log :debug2, 'checking all required arguments are provided'
149
+
150
+ options[:host] ||= nil
151
+
152
+ if program_features[:authentication]
153
+
154
+ climate.abort 'authentication scheme not specified; use --help for usage' unless options[:authentication_scheme]
155
+
156
+ secret_server_source = options[:secret_server_source] or climate.abort 'no secret server url specified; use --help for usage' if :jwt == options[:authentication_scheme]
157
+
158
+ case options[:authentication_scheme]
159
+ when :jwt
160
+
161
+ options[:jwt_encoding_algorithm] or climate.abort "must specify JWT encoding algorithm; use --help for usage"
162
+ algorithms = r.values.empty? ? [ options[:jwt_encoding_algorithm] ] : r.values
163
+ else
164
+
165
+ algorithms = []
166
+ end
167
+ end
168
+
169
+ # ##########################################################################
170
+ # main
171
+
172
+ if :jwt == options[:authentication_scheme]
173
+ log :informational, 'loading secrets ...'
174
+ options[:secrets] = load_secrets(secret_server_source, *algorithms)
175
+ else
176
+ options[:secrets] = {}
177
+ end
178
+
179
+ log :informational, 'initialising Razor connector ...'
180
+ log :debug0, 'options: ', options
181
+
182
+ begin
183
+
184
+ rr_options = {}
185
+ rr_options[:executable] = options[:razor_executable] if RazorRequester.requires_executable?
186
+ rr_options[:razor_environment] = options[:razor_environment]
187
+ rr_options[:razor_space] = options[:razor_space]
188
+ rr_options[:razor_alias] = options[:razor_alias]
189
+
190
+ options[:razor_requester] = RazorRequester.new options[:clarite_config_path], **rr_options
191
+ rescue ::ArgumentError, ::NameError, ::NoMethodError, ::TypeError => x
192
+
193
+ log :violation, "unexpected exception (#{x.class}): '#{x.message}': #{x.backtrace}"
194
+
195
+ raise
196
+ rescue => x
197
+
198
+ log :alert, "exception(#{x.class}): #{x.message}"
199
+
200
+ climate.abort x.message
201
+ end
202
+
203
+ log :informational, 'initialising application ...'
204
+ log :debug0, 'options: ', options
205
+
206
+ begin
207
+
208
+ TheApp.init_service **options
209
+ rescue ::ArgumentError, ::NameError, ::NoMethodError, ::TypeError => x
210
+
211
+ log :violation, "unexpected exception (#{x.class}): '#{x.message}': #{x.backtrace}"
212
+
213
+ raise
214
+ rescue ::Errno::EADDRINUSE => x
215
+
216
+ log :debug, x.message
217
+ msg = "Cannot start #{self.process_name}, '#{options[:host]}:#{options[:port]}' in use"
218
+ log :critical, msg
219
+ climate.abort msg
220
+ rescue => x
221
+
222
+ log :alert, "exception(#{x.class}): #{x.message}"
223
+
224
+ climate.abort x.message
225
+ end
226
+
227
+ log :notice, 'starting ', TheApp::SHORT_DESIGNATION, ' server', options[:authentication_scheme] ? " with authentication scheme '#{options[:authentication_scheme]}'" : ''
228
+
229
+ TheApp.run!
230
+ end
231
+ end
232
+
233
+ MainProgramLogic.run!
234
+ end
235
+
236
+ # ############################## end of file ############################# #
237
+
238
+