razorrisk-cassini-common 0.26.24
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CHANGELOG.md +22 -0
- data/LICENSE +5 -0
- data/README.md +2 -0
- data/Rakefile +102 -0
- data/lib/razor_risk/cassini/applications/microservice.rb +318 -0
- data/lib/razor_risk/cassini/applications/rest_framework/route_verb_dispatcher.rb +120 -0
- data/lib/razor_risk/cassini/applications/rest_framework/verb_handler.rb +117 -0
- data/lib/razor_risk/cassini/applications/route_verb_adaptors/utilities/collection_get_helper.rb +86 -0
- data/lib/razor_risk/cassini/applications/securable_microservice.rb +164 -0
- data/lib/razor_risk/cassini/applications/secured_microservice.rb +63 -0
- data/lib/razor_risk/cassini/applications/unsecured_microservice.rb +77 -0
- data/lib/razor_risk/cassini/authorisation/header_helpers.rb +271 -0
- data/lib/razor_risk/cassini/authorisation/security_model_helpers.rb +93 -0
- data/lib/razor_risk/cassini/authorisation.rb +27 -0
- data/lib/razor_risk/cassini/cli.rb +19 -0
- data/lib/razor_risk/cassini/common/version.rb +44 -0
- data/lib/razor_risk/cassini/common.rb +32 -0
- data/lib/razor_risk/cassini/constants.rb +68 -0
- data/lib/razor_risk/cassini/diagnostics/util_functions.rb +248 -0
- data/lib/razor_risk/cassini/diagnostics/zeroth_include.rb +35 -0
- data/lib/razor_risk/cassini/extensions/libclimate/common_options.rb +267 -0
- data/lib/razor_risk/cassini/extensions/libclimate.rb +26 -0
- data/lib/razor_risk/cassini/header_functions.rb +59 -0
- data/lib/razor_risk/cassini/main.rb +238 -0
- data/lib/razor_risk/cassini/mixin/razor_response_validator.rb +176 -0
- data/lib/razor_risk/cassini/testing/suppress_pantheios_logging.rb +31 -0
- data/lib/razor_risk/cassini/util/conversion_util.rb +176 -0
- data/lib/razor_risk/cassini/util/program_execution_util.rb +379 -0
- data/lib/razor_risk/cassini/util/secrets_util.rb +229 -0
- data/lib/razor_risk/cassini/util/version_util.rb +88 -0
- data/lib/razor_risk/sinatra/helpers/check_auth_helper.rb +209 -0
- data/lib/razor_risk/sinatra/helpers/validate_accept_helper.rb +69 -0
- data/lib/razor_risk/sinatra/helpers/validate_content_type_helper.rb +74 -0
- data/lib/razor_risk/sinatra/helpers/validate_query_parameters_helper.rb +198 -0
- data/test/scratch/cassini/util/convert_XML.rb +54 -0
- data/test/unit/applications/route_verb_adaptors/utilities/tc_collection_get_helper.rb +236 -0
- data/test/unit/applications/tc_verb_handler.rb +130 -0
- data/test/unit/mixin/tc_razor_response_validator.rb +328 -0
- data/test/unit/sinatra/helpers/tc_validate_query_parameters_helper.rb +134 -0
- data/test/unit/tc_authorisation_util.rb +265 -0
- data/test/unit/tc_load_secrets.rb +95 -0
- data/test/unit/util/tc_conversion_util.rb +393 -0
- data/test/unit/util/tc_program_execution_util.rb +462 -0
- metadata +380 -0
@@ -0,0 +1,93 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
# ######################################################################## #
|
4
|
+
# File: razor_risk/cassini/authorisation/security_model_helpers.rb
|
5
|
+
#
|
6
|
+
# Purpose: Definition of the
|
7
|
+
# RazorRisk::Cassini::Authorisation::SecurityModelHelpers
|
8
|
+
# module
|
9
|
+
#
|
10
|
+
# Created: 16th February 2018
|
11
|
+
# Updated: 16th February 2018
|
12
|
+
#
|
13
|
+
# Author: Matthew Wilson
|
14
|
+
#
|
15
|
+
# Copyright (c) 2018, Razor Risk Technologies Pty Ltd
|
16
|
+
# All rights reserved.
|
17
|
+
#
|
18
|
+
# ######################################################################## #
|
19
|
+
|
20
|
+
|
21
|
+
=begin
|
22
|
+
=end
|
23
|
+
|
24
|
+
require 'pantheios'
|
25
|
+
require 'xqsr3/quality/parameter_checking'
|
26
|
+
|
27
|
+
require 'razor_risk/core/diagnostics/logger'
|
28
|
+
|
29
|
+
module RazorRisk
|
30
|
+
module Cassini
|
31
|
+
module Authorisation
|
32
|
+
|
33
|
+
module SecurityModelHelpers
|
34
|
+
|
35
|
+
include ::Pantheios
|
36
|
+
include ::Xqsr3::Quality::ParameterChecking
|
37
|
+
include ::RazorRisk::Core::Diagnostics::Logger
|
38
|
+
|
39
|
+
# Options a RazorRequester-compatible options hash containing
|
40
|
+
# credentials appropriate to the given +authentication_scheme+
|
41
|
+
def razor_requester_credentials_options authentication_scheme, credentials, **options
|
42
|
+
|
43
|
+
check_parameter authentication_scheme, 'authentication_scheme', type: ::Symbol, values: [ :none, :basic, :authorisation_only, :jwt ]
|
44
|
+
check_parameter(credentials, 'credentials', type: ::Array) { |value| value.empty? ? 'no credentials specified' : true }
|
45
|
+
|
46
|
+
r = {}
|
47
|
+
|
48
|
+
credentials = credentials.dup
|
49
|
+
|
50
|
+
|
51
|
+
case authentication_scheme
|
52
|
+
when :none
|
53
|
+
|
54
|
+
;
|
55
|
+
when :basic
|
56
|
+
|
57
|
+
if options[:auth_test_mode]
|
58
|
+
log :warning, "YOU ARE IN AUTHORIZATION TEST MODE! NO AUTHENTICATION WILL BE PERFORMED! THIS MUST NOT BE USED IN PRODUCTION!"
|
59
|
+
r[:impersonatee] = credentials.shift unless credentials.empty?
|
60
|
+
else
|
61
|
+
r[:username] = credentials.shift unless credentials.empty?
|
62
|
+
r[:password] = credentials.shift unless credentials.empty?
|
63
|
+
r[:domain] = credentials.shift unless credentials.empty?
|
64
|
+
end
|
65
|
+
when :jwt
|
66
|
+
|
67
|
+
if options[:auth_test_mode]
|
68
|
+
log :warning, "YOU ARE IN AUTHORIZATION TEST MODE! NO AUTHENTICATION WILL BE PERFORMED! THIS MUST NOT BE USED IN PRODUCTION!"
|
69
|
+
end
|
70
|
+
r[:session_id] = credentials.shift unless credentials.empty?
|
71
|
+
r[:user_id] = credentials.shift unless credentials.empty?
|
72
|
+
r[:user_name] = credentials.shift unless credentials.empty?
|
73
|
+
when :authorisation_only
|
74
|
+
|
75
|
+
r[:impersonatee] = credentials.shift unless credentials.empty?
|
76
|
+
else
|
77
|
+
|
78
|
+
log :violation, "unexpected authentication_scheme '#{authentication_scheme}' (#{authentication_scheme.class})"
|
79
|
+
end
|
80
|
+
|
81
|
+
r
|
82
|
+
end
|
83
|
+
|
84
|
+
end # module SecurityModelHelpers
|
85
|
+
|
86
|
+
end # module Authorisation
|
87
|
+
end # module Cassini
|
88
|
+
end # module RazorRisk
|
89
|
+
|
90
|
+
# ############################## end of file ############################# #
|
91
|
+
|
92
|
+
|
93
|
+
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
# ######################################################################## #
|
4
|
+
# File: razor_risk/cassini/authorisation.rb
|
5
|
+
#
|
6
|
+
# Purpose: Cassini Authorisation common file
|
7
|
+
#
|
8
|
+
# Created: 26th 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/authorisation/header_helpers'
|
23
|
+
require 'razor_risk/cassini/authorisation/security_model_helpers'
|
24
|
+
|
25
|
+
# ############################## end of file ############################# #
|
26
|
+
|
27
|
+
|
@@ -0,0 +1,19 @@
|
|
1
|
+
|
2
|
+
module RazorRisk
|
3
|
+
module Cassini
|
4
|
+
|
5
|
+
module CLI
|
6
|
+
|
7
|
+
def self.Copyright(year)
|
8
|
+
|
9
|
+
"Copyright Razor Risk Technologies Pty Ltd (c) #{year}"
|
10
|
+
end
|
11
|
+
|
12
|
+
end # module CLI
|
13
|
+
|
14
|
+
end # module Cassini
|
15
|
+
end # module RazorRisk
|
16
|
+
|
17
|
+
# ############################## end of file ############################# #
|
18
|
+
|
19
|
+
|
@@ -0,0 +1,44 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
# ######################################################################## #
|
4
|
+
#
|
5
|
+
# Version for RazorRisk.Cassini.Common library
|
6
|
+
|
7
|
+
# Copyright (c) 2017 Razor Risk Technologies Pty Limited. All rights reserved.
|
8
|
+
#
|
9
|
+
# ######################################################################## #
|
10
|
+
|
11
|
+
module RazorRisk
|
12
|
+
module Cassini
|
13
|
+
|
14
|
+
module Common
|
15
|
+
|
16
|
+
# Current version of the RazorRisk.Cassini.Common library
|
17
|
+
VERSION = '0.26.24'
|
18
|
+
|
19
|
+
private
|
20
|
+
VERSION_PARTS_ = VERSION.split(/[.]/).collect { |n| n.to_i } # :nodoc:
|
21
|
+
public
|
22
|
+
# Major version of the RazorRisk.Cassini.Common library
|
23
|
+
VERSION_MAJOR = VERSION_PARTS_[0] # :nodoc:
|
24
|
+
# Minor version of the RazorRisk.Cassini.Common library
|
25
|
+
VERSION_MINOR = VERSION_PARTS_[1] # :nodoc:
|
26
|
+
# Patch version of the RazorRisk.Cassini.Common library
|
27
|
+
VERSION_Patch = VERSION_PARTS_[2] # :nodoc:
|
28
|
+
# Commit version of the RazorRisk.Cassini.Common library
|
29
|
+
VERSION_COMMIT = VERSION_PARTS_[3] || 0 # :nodoc:
|
30
|
+
|
31
|
+
|
32
|
+
# The description of the framework
|
33
|
+
DESCRIPTION = 'Cassini Web Service framework for Razor Risk Razor system'
|
34
|
+
|
35
|
+
# [DEPRECATED] Instead use +DESCRIPTION+
|
36
|
+
FRAMEWORK_DESCRIPTION = DESCRIPTION
|
37
|
+
|
38
|
+
end # module Common
|
39
|
+
end # module Cassini
|
40
|
+
end # module RazorRisk
|
41
|
+
|
42
|
+
# ############################## end of file ############################# #
|
43
|
+
|
44
|
+
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
# ######################################################################## #
|
4
|
+
# File: razor_risk/cassini/common.rb
|
5
|
+
#
|
6
|
+
# Purpose: Cassini common file
|
7
|
+
#
|
8
|
+
# Created: 15th January 2018
|
9
|
+
# Updated: 4th March 2018
|
10
|
+
#
|
11
|
+
# Author: Matthew Wilson
|
12
|
+
#
|
13
|
+
# Copyright (c) 2018, Razor Risk Technologies Pty Ltd
|
14
|
+
# All rights reserved.
|
15
|
+
#
|
16
|
+
# ######################################################################## #
|
17
|
+
|
18
|
+
|
19
|
+
# ##########################################################################
|
20
|
+
# requires
|
21
|
+
|
22
|
+
=begin
|
23
|
+
require 'razor_risk/cassini/authorisation'
|
24
|
+
require 'razor_risk/cassini/constants'
|
25
|
+
require 'razor_risk/cassini/header_functions'
|
26
|
+
require 'razor_risk/cassini/management_plane'
|
27
|
+
require 'razor_risk/cassini/util/secrets_util'
|
28
|
+
=end
|
29
|
+
|
30
|
+
# ############################## end of file ############################# #
|
31
|
+
|
32
|
+
|
@@ -0,0 +1,68 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
# ######################################################################## #
|
4
|
+
# File: razor_risk/cassini/constants.rb
|
5
|
+
#
|
6
|
+
# Purpose: Cassini constants
|
7
|
+
#
|
8
|
+
# Created: 14th 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
|
+
=begin
|
23
|
+
=end
|
24
|
+
|
25
|
+
module RazorRisk
|
26
|
+
module Cassini
|
27
|
+
|
28
|
+
module Constants
|
29
|
+
|
30
|
+
# The WWW-Authenticate header scheme for Razor's Authentication-only
|
31
|
+
# authentication scheme
|
32
|
+
SCHEME_AUTH_ONLY = 'RazorRisk.Cassini.AuthorisationOnly'
|
33
|
+
|
34
|
+
REFERRED_ENV_PREFIX = 'razorrisk.cassini.ims'
|
35
|
+
|
36
|
+
SUPPORTED_VERB_NAMES = %w{ COPY DELETE GET HEAD LINK LOCK OPTIONS PATCH PROPFIND POST PURGE PUT VIEW UNLINK UNLOCK }
|
37
|
+
|
38
|
+
SUPPORTED_VERBS = SUPPORTED_VERB_NAMES.map { |name| name.downcase.to_sym }
|
39
|
+
|
40
|
+
HTTP_AUTHORIZATION = 'HTTP_AUTHORIZATION'
|
41
|
+
|
42
|
+
SUPPORTED_AUTHENTICATION_SCHEMES = %w{ [a]uthorisation-only [b]asic [j]wt }
|
43
|
+
|
44
|
+
# See RFC-2616 Section 13.5.1 @ https://tools.ietf.org/html/rfc2616#section-13.5.1
|
45
|
+
# and its errata 4522 @ https://www.rfc-editor.org/errata/eid4522
|
46
|
+
HOP_BY_HOP_HEADERS = [
|
47
|
+
'connection',
|
48
|
+
'keep-alive',
|
49
|
+
'proxy-authenticate',
|
50
|
+
'proxy-authorization',
|
51
|
+
'te',
|
52
|
+
'trailer',
|
53
|
+
'transfer-encoding',
|
54
|
+
'upgrade',
|
55
|
+
]
|
56
|
+
|
57
|
+
# Environment setting to allow exceptions to be propagated for
|
58
|
+
# development and testing purposes.
|
59
|
+
RZ_EXPOSE_MICROSERVICE_EXCEPTIONS = ENV['RZ_EXPOSE_MICROSERVICE_EXCEPTIONS']
|
60
|
+
|
61
|
+
end # module Constants
|
62
|
+
|
63
|
+
end # module Cassini
|
64
|
+
end # module RazorRisk
|
65
|
+
|
66
|
+
# ############################## end of file ############################# #
|
67
|
+
|
68
|
+
|
@@ -0,0 +1,248 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
# ######################################################################## #
|
4
|
+
# File: razor_risk/cassini/diagnostics/util_functions.rb
|
5
|
+
#
|
6
|
+
# Purpose: Centralised diagnostics utility functions
|
7
|
+
#
|
8
|
+
# Created: 8th February 2018
|
9
|
+
# Updated: 26th February 2018
|
10
|
+
#
|
11
|
+
# Author: Matthew Wilson
|
12
|
+
#
|
13
|
+
# Copyright (c) 2018, Razor Risk Technologies Pty Ltd
|
14
|
+
# All rights reserved.
|
15
|
+
#
|
16
|
+
# ######################################################################## #
|
17
|
+
|
18
|
+
|
19
|
+
require 'pantheios/application_layer/stock_severity_levels'
|
20
|
+
require 'pantheios/services/multiplexing_log_service'
|
21
|
+
require 'pantheios/services/null_log_service'
|
22
|
+
require 'pantheios/services/simple_console_log_service'
|
23
|
+
require 'pantheios/services/simple_file_log_service'
|
24
|
+
|
25
|
+
require 'xqsr3/quality/parameter_checking'
|
26
|
+
|
27
|
+
require 'fileutils'
|
28
|
+
|
29
|
+
require 'razor_risk/core/diagnostics/logger'
|
30
|
+
|
31
|
+
module RazorRisk
|
32
|
+
module Cassini
|
33
|
+
|
34
|
+
module Diagnostics
|
35
|
+
include ::RazorRisk::Core::Diagnostics::Logger
|
36
|
+
|
37
|
+
module SetupDiagnosticLogging_Constants
|
38
|
+
|
39
|
+
STOCK_SEVERITY_LEVEL_VALUES = Pantheios::ApplicationLayer::StockSeverityLevels::STOCK_SEVERITY_LEVEL_VALUES
|
40
|
+
|
41
|
+
DEFAULT_LOG_THRESHOLD_MAIN = :debug4
|
42
|
+
DEFAULT_LOG_THRESHOLD_CONSOLE = :informational
|
43
|
+
|
44
|
+
BENCHMARK_SEVERITY_VALUE = STOCK_SEVERITY_LEVEL_VALUES[:benchmark]
|
45
|
+
|
46
|
+
DEFAULT_LOG_SIZE_BENCHMARK = 1024 * 1024 * 10
|
47
|
+
DEFAULT_LOG_SIZE_MAIN = 1024 * 1024 * 100
|
48
|
+
|
49
|
+
DEFAULT_LOG_DEPTH = 20
|
50
|
+
end # module SetupDiagnosticLogging_Constants
|
51
|
+
|
52
|
+
# configure diagnostic logging:
|
53
|
+
#
|
54
|
+
# - set program name
|
55
|
+
# - set services:
|
56
|
+
# * benchmark logger : file, only responding to :benchmark, and only if
|
57
|
+
# --benchmark is specified
|
58
|
+
# * main file logger : file, stores all except :benchmark, according to
|
59
|
+
# :log_threshold
|
60
|
+
# * main cons logger : stdout/stderr, only :notice and above
|
61
|
+
#
|
62
|
+
# === Signature
|
63
|
+
#
|
64
|
+
# * *Parameters:*
|
65
|
+
# - +program_name+:: (::String) The program name. May not be +nil+
|
66
|
+
# - +log_directory+:: (::String) The directory in which log-files
|
67
|
+
# will be created. May not be +nil+, unless both +:no_benchmark_log+
|
68
|
+
# and +:no_main_log+ are truey
|
69
|
+
# - +log_threshold+:: (::String | ::Symbol |[ ::Symbol, ::Symbol ] )
|
70
|
+
# Specifies the log-threshold(s). The threshold(s) is specified as a
|
71
|
+
# string containing comma-separated values, or as a single symbol,
|
72
|
+
# or as an array of symbols, all of which are treated as a sequence
|
73
|
+
# of severity thresholds. The severity thresholds apply,
|
74
|
+
# respectively, to the modifiable-sequence of Console and Main.
|
75
|
+
#
|
76
|
+
# * *Options:*
|
77
|
+
# - +:no_benchmark_log+:: (boolean) Unless truey, a benchmark log will
|
78
|
+
# be created
|
79
|
+
# - +:no_console_log+:: (boolean) Unless truey, a console log will be
|
80
|
+
# created
|
81
|
+
# - +:no_main_log+:: (boolean) Unless truey, a main log will be
|
82
|
+
# created
|
83
|
+
#
|
84
|
+
# NOTE: If all of +:no_benchmark_log+, +:no_console_log+, and
|
85
|
+
# +:no_main_log+ are truey, a null logger will be created, and there will
|
86
|
+
# be no logging
|
87
|
+
|
88
|
+
def setup_diagnostic_logging program_name, log_directory, log_threshold, **options
|
89
|
+
|
90
|
+
::Xqsr3::Quality::ParameterChecking.check_parameter program_name, 'program_name', type: ::String
|
91
|
+
::Xqsr3::Quality::ParameterChecking.check_parameter log_directory, 'log_directory', type: ::String
|
92
|
+
::Xqsr3::Quality::ParameterChecking.check_parameter log_threshold, 'log_threshold', types: [ ::Array, ::Integer, ::Symbol ]
|
93
|
+
|
94
|
+
case log_threshold
|
95
|
+
when ::Array
|
96
|
+
|
97
|
+
log_thresholds = log_threshold.dup
|
98
|
+
when ::Symbol
|
99
|
+
|
100
|
+
log_thresholds = [ log_threshold ]
|
101
|
+
else
|
102
|
+
|
103
|
+
log_thresholds = []
|
104
|
+
end
|
105
|
+
|
106
|
+
console_threshold = log_thresholds.shift || options[:console_threshold] || SetupDiagnosticLogging_Constants::DEFAULT_LOG_THRESHOLD_CONSOLE
|
107
|
+
main_threshold = log_thresholds.shift || options[:main_threshold] || SetupDiagnosticLogging_Constants::DEFAULT_LOG_THRESHOLD_MAIN
|
108
|
+
|
109
|
+
console_threshold_v = ::Integer === console_threshold ? console_threshold : SetupDiagnosticLogging_Constants::STOCK_SEVERITY_LEVEL_VALUES[console_threshold]
|
110
|
+
main_threshold_v = ::Integer === main_threshold ? main_threshold : SetupDiagnosticLogging_Constants::STOCK_SEVERITY_LEVEL_VALUES[main_threshold]
|
111
|
+
|
112
|
+
unless options[:no_benchmark_log] && options[:no_main_log]
|
113
|
+
|
114
|
+
unless File.directory?(log_directory)
|
115
|
+
|
116
|
+
climate.abort "log directory '#{log_directory}' exists and is not a directory" if File.exist?(log_directory)
|
117
|
+
|
118
|
+
begin
|
119
|
+
|
120
|
+
FileUtils.mkdir_p log_directory
|
121
|
+
rescue => x
|
122
|
+
|
123
|
+
log :alert, "exception(#{x.class}): #{x.message}"
|
124
|
+
|
125
|
+
climate.abort x.message
|
126
|
+
end
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
services = []
|
131
|
+
|
132
|
+
unless options[:no_benchmark_log]
|
133
|
+
|
134
|
+
bm_log_file_name = program_name + '-benchmark.log'
|
135
|
+
|
136
|
+
bm_log_file_path = File.join(log_directory, bm_log_file_name)
|
137
|
+
|
138
|
+
bm_logger = Pantheios::Services::SimpleFileLogService.new bm_log_file_path, roll_size: SetupDiagnosticLogging_Constants::DEFAULT_LOG_SIZE_BENCHMARK, roll_depth: SetupDiagnosticLogging_Constants::DEFAULT_LOG_DEPTH
|
139
|
+
|
140
|
+
def bm_logger.severity_logged? severity
|
141
|
+
|
142
|
+
case severity
|
143
|
+
when :benchmark, SetupDiagnosticLogging_Constants::BENCHMARK_SEVERITY_VALUE
|
144
|
+
|
145
|
+
true
|
146
|
+
else
|
147
|
+
|
148
|
+
false
|
149
|
+
end
|
150
|
+
end
|
151
|
+
|
152
|
+
services << bm_logger
|
153
|
+
end
|
154
|
+
|
155
|
+
unless options[:no_main_log]
|
156
|
+
|
157
|
+
mf_log_file_name = program_name + '-main.log'
|
158
|
+
|
159
|
+
mf_log_file_path = File.join(log_directory, mf_log_file_name)
|
160
|
+
|
161
|
+
mf_logger = Pantheios::Services::SimpleFileLogService.new mf_log_file_path, roll_size: SetupDiagnosticLogging_Constants::DEFAULT_LOG_SIZE_MAIN, roll_depth: SetupDiagnosticLogging_Constants::DEFAULT_LOG_DEPTH
|
162
|
+
|
163
|
+
mf_logger.instance_variable_set :@main_threshold_v_, main_threshold_v
|
164
|
+
|
165
|
+
def mf_logger.severity_logged? severity
|
166
|
+
|
167
|
+
return true unless @main_threshold_v_
|
168
|
+
|
169
|
+
severity = :debug4 if :debug == severity
|
170
|
+
|
171
|
+
severity_v = nil
|
172
|
+
|
173
|
+
case severity
|
174
|
+
when :benchmark, SetupDiagnosticLogging_Constants::BENCHMARK_SEVERITY_VALUE
|
175
|
+
|
176
|
+
return false
|
177
|
+
when ::Symbol
|
178
|
+
|
179
|
+
severity_v = SetupDiagnosticLogging_Constants::STOCK_SEVERITY_LEVEL_VALUES[severity]
|
180
|
+
when ::Integer
|
181
|
+
|
182
|
+
severity_v = severity
|
183
|
+
else
|
184
|
+
|
185
|
+
;
|
186
|
+
end
|
187
|
+
|
188
|
+
return true unless severity_v
|
189
|
+
|
190
|
+
severity_v <= @main_threshold_v_
|
191
|
+
end
|
192
|
+
|
193
|
+
services << mf_logger
|
194
|
+
end
|
195
|
+
|
196
|
+
unless options[:no_console_log]
|
197
|
+
|
198
|
+
mc_logger = Pantheios::Services::SimpleConsoleLogService.new
|
199
|
+
|
200
|
+
mc_logger.instance_variable_set :@console_threshold_v_, console_threshold_v
|
201
|
+
|
202
|
+
def mc_logger.severity_logged? severity
|
203
|
+
|
204
|
+
return true unless @console_threshold_v_
|
205
|
+
|
206
|
+
severity = :debug4 if :debug == severity
|
207
|
+
|
208
|
+
severity_v = nil
|
209
|
+
|
210
|
+
case severity
|
211
|
+
when :benchmark, SetupDiagnosticLogging_Constants::BENCHMARK_SEVERITY_VALUE
|
212
|
+
|
213
|
+
return false
|
214
|
+
when ::Symbol
|
215
|
+
|
216
|
+
severity_v = SetupDiagnosticLogging_Constants::STOCK_SEVERITY_LEVEL_VALUES[severity]
|
217
|
+
when ::Integer
|
218
|
+
|
219
|
+
severity_v = severity
|
220
|
+
else
|
221
|
+
|
222
|
+
;
|
223
|
+
end
|
224
|
+
|
225
|
+
return true unless severity_v
|
226
|
+
|
227
|
+
severity_v <= @console_threshold_v_
|
228
|
+
end
|
229
|
+
|
230
|
+
services << mc_logger
|
231
|
+
end
|
232
|
+
|
233
|
+
if services.empty?
|
234
|
+
|
235
|
+
mx_logger = Pantheios::Services::NullLogService.new
|
236
|
+
else
|
237
|
+
|
238
|
+
mx_logger = Pantheios::Services::MultiplexingLogService.new services, level_cache_mode: :thread_fixed
|
239
|
+
end
|
240
|
+
|
241
|
+
::Pantheios::Core.set_service mx_logger
|
242
|
+
end
|
243
|
+
|
244
|
+
end # module Diagnostics
|
245
|
+
|
246
|
+
end # module RazorRisk
|
247
|
+
end # module Cassini
|
248
|
+
|
@@ -0,0 +1,35 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
# ######################################################################## #
|
4
|
+
# File: razor_risk/cassini/diagnostics/zeroth_include.rb
|
5
|
+
#
|
6
|
+
# Purpose: When required as the very first file it sets up, for
|
7
|
+
# diagnostics, the main thread name and the process name
|
8
|
+
#
|
9
|
+
# Created: 5th February 2018
|
10
|
+
# Updated: 4th March 2018
|
11
|
+
#
|
12
|
+
# Author: Matthew Wilson
|
13
|
+
#
|
14
|
+
# Copyright (c) 2018, Razor Risk Technologies Pty Ltd
|
15
|
+
# All rights reserved.
|
16
|
+
#
|
17
|
+
# ######################################################################## #
|
18
|
+
|
19
|
+
|
20
|
+
# ##########################################################################
|
21
|
+
# requires
|
22
|
+
|
23
|
+
require 'pantheios/globals'
|
24
|
+
|
25
|
+
# set main thread name
|
26
|
+
Pantheios::Globals.MAIN_THREAD_NAME = [ Thread.current, 'main' ]
|
27
|
+
|
28
|
+
# set process name
|
29
|
+
#
|
30
|
+
# If the script name is ws.rb, then the directory name is used
|
31
|
+
Pantheios::Globals.PROCESS_NAME = $0 =~ /[\\\/]ws\.rb$/ ? :script_dirname : :script_stem
|
32
|
+
|
33
|
+
# ############################## end of file ############################# #
|
34
|
+
|
35
|
+
|