razorrisk-cassini-utilities-cassid 0.8.11
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/bin/cassid +279 -0
- data/bin/razorrisk-service-cassid +90 -0
- data/lib/razor_risk/cassini/utilities/cassid/configuration.rb +367 -0
- data/lib/razor_risk/cassini/utilities/cassid/constants.rb +48 -0
- data/lib/razor_risk/cassini/utilities/cassid/main.rb +643 -0
- data/lib/razor_risk/cassini/utilities/cassid/service_controller.rb +149 -0
- data/lib/razor_risk/cassini/utilities/cassid/validations.rb +460 -0
- data/lib/razor_risk/cassini/utilities/cassid/version.rb +54 -0
- data/lib/razor_risk/cassini/utilities/cassid.rb +11 -0
- metadata +210 -0
@@ -0,0 +1,367 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
|
4
|
+
# ##########################################################################
|
5
|
+
#
|
6
|
+
# Definition of RazorRisk::Cassini::Utilities::CassiD::Configuration class
|
7
|
+
#
|
8
|
+
# Copyright (c) 2018 Razor Risk Technologies Pty Limited. All rights reserved.
|
9
|
+
#
|
10
|
+
# ##########################################################################
|
11
|
+
|
12
|
+
# ##########################################################
|
13
|
+
# requires
|
14
|
+
|
15
|
+
require 'pantheios'
|
16
|
+
require 'xqsr3/extensions/kernel/integer'
|
17
|
+
require 'xqsr3/quality/parameter_checking'
|
18
|
+
|
19
|
+
|
20
|
+
# ##########################################################
|
21
|
+
# Configuration
|
22
|
+
|
23
|
+
module RazorRisk
|
24
|
+
module Cassini
|
25
|
+
module Utilities
|
26
|
+
module CassiD
|
27
|
+
|
28
|
+
# Class that represents a parsed Cassini configuration
|
29
|
+
class Configuration
|
30
|
+
|
31
|
+
include ::Pantheios
|
32
|
+
include ::Xqsr3::Quality::ParameterChecking
|
33
|
+
|
34
|
+
class Element
|
35
|
+
|
36
|
+
include ::Pantheios
|
37
|
+
include ::Xqsr3::Quality::ParameterChecking
|
38
|
+
|
39
|
+
private
|
40
|
+
|
41
|
+
def initialize_from_hash h, attributes, **options
|
42
|
+
|
43
|
+
trace ParamNames[ :h, :attributes, :options ], h, attributes, options
|
44
|
+
|
45
|
+
check_parameter h, 'h', type: ::Hash
|
46
|
+
check_parameter attributes, 'attributes', type: ::Hash
|
47
|
+
|
48
|
+
attributes.each do |name, spec|
|
49
|
+
|
50
|
+
v = nil
|
51
|
+
v = h[name] if v.nil?
|
52
|
+
v = h[name.to_s] if v.nil?
|
53
|
+
|
54
|
+
unless v.nil?
|
55
|
+
|
56
|
+
convert = spec[:convert]
|
57
|
+
|
58
|
+
if false
|
59
|
+
elsif convert.nil?
|
60
|
+
elsif ::Integer == convert
|
61
|
+
|
62
|
+
v = Integer(v, nil: true)
|
63
|
+
elsif ::Proc === convert
|
64
|
+
|
65
|
+
v = convert.call(v)
|
66
|
+
elsif ::Symbol == convert
|
67
|
+
|
68
|
+
v = v.to_sym
|
69
|
+
end
|
70
|
+
|
71
|
+
types = spec[:types]
|
72
|
+
types ||= [ spec[:type] ].reject { |t| t.nil? }
|
73
|
+
|
74
|
+
raise ::ArgumentError, "the value - #{v} - for attribute '#{name}' is of type #{v.class} but is required to be #{types}" unless types.empty? || types.any? { |type| v.kind_of?(type) }
|
75
|
+
|
76
|
+
values = [ spec[:values] || [ v ] ].flatten
|
77
|
+
|
78
|
+
raise ::ArgumentError, "the value - #{v} - is not one of the required values #{values}" unless values.include?(v)
|
79
|
+
|
80
|
+
define_singleton_method(name) { v }
|
81
|
+
else
|
82
|
+
|
83
|
+
if spec[:optional]
|
84
|
+
|
85
|
+
define_singleton_method(name) { spec[:default] }
|
86
|
+
else
|
87
|
+
|
88
|
+
raise ::ArgumentError, "missing required attribute '#{name}'"
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
@attribute_names = attributes.keys
|
94
|
+
end
|
95
|
+
|
96
|
+
public
|
97
|
+
|
98
|
+
def inspect
|
99
|
+
|
100
|
+
attrs = @attribute_names
|
101
|
+
|
102
|
+
"#<#{self.class}:0x00#{object_id} attributes : #{attrs}>"
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
class CassiniSecretServerElement < Element
|
107
|
+
|
108
|
+
Attributes = {
|
109
|
+
|
110
|
+
host: {
|
111
|
+
|
112
|
+
optional: true,
|
113
|
+
},
|
114
|
+
port: {
|
115
|
+
|
116
|
+
optional: true,
|
117
|
+
type: ::Integer,
|
118
|
+
},
|
119
|
+
secrets_path: {
|
120
|
+
|
121
|
+
optional: true,
|
122
|
+
},
|
123
|
+
service_path: {
|
124
|
+
|
125
|
+
optional: true,
|
126
|
+
},
|
127
|
+
}
|
128
|
+
|
129
|
+
def initialize h, **options
|
130
|
+
|
131
|
+
trace ParamNames[ :h, :options ], h, options
|
132
|
+
|
133
|
+
initialize_from_hash h, Attributes, **options
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
137
|
+
class CassiniElement < Element
|
138
|
+
|
139
|
+
Attributes = {
|
140
|
+
|
141
|
+
auth_mode: {
|
142
|
+
|
143
|
+
types: [ ::String, ::Symbol ],
|
144
|
+
convert: Proc.new do |v|
|
145
|
+
|
146
|
+
case v.strip.downcase
|
147
|
+
when 'b', 'basic'
|
148
|
+
|
149
|
+
:'basic'
|
150
|
+
when 'a', /^auth(?:|ori[sz]ation)[-_]only$/
|
151
|
+
|
152
|
+
:'authorisation_only'
|
153
|
+
when 'j', 'jwt'
|
154
|
+
|
155
|
+
:'jwt'
|
156
|
+
else
|
157
|
+
|
158
|
+
v
|
159
|
+
end
|
160
|
+
end,
|
161
|
+
values: [ 'authorisation_only', 'basic', 'jwt' ].map { |s| s.to_sym },
|
162
|
+
},
|
163
|
+
ces: {
|
164
|
+
|
165
|
+
type: ::Hash,
|
166
|
+
},
|
167
|
+
first_port: {
|
168
|
+
|
169
|
+
type: ::Integer,
|
170
|
+
},
|
171
|
+
host: {
|
172
|
+
|
173
|
+
optional: true,
|
174
|
+
type: ::String,
|
175
|
+
},
|
176
|
+
microservices: {
|
177
|
+
|
178
|
+
type: ::Hash,
|
179
|
+
},
|
180
|
+
external_services: {
|
181
|
+
|
182
|
+
type: ::Hash,
|
183
|
+
optional: true,
|
184
|
+
},
|
185
|
+
root_dir: {
|
186
|
+
|
187
|
+
optional: true,
|
188
|
+
type: ::String,
|
189
|
+
},
|
190
|
+
secret_server: {
|
191
|
+
|
192
|
+
optional: true,
|
193
|
+
type: ::Hash,
|
194
|
+
},
|
195
|
+
tls: {
|
196
|
+
|
197
|
+
optional: true,
|
198
|
+
types: [ ::Hash, ::String ],
|
199
|
+
},
|
200
|
+
us_multiplier: {
|
201
|
+
|
202
|
+
optional: true,
|
203
|
+
type: ::Integer,
|
204
|
+
default: 1,
|
205
|
+
},
|
206
|
+
web_server: {
|
207
|
+
|
208
|
+
optional: true,
|
209
|
+
type: ::String,
|
210
|
+
},
|
211
|
+
web_ui_server: {
|
212
|
+
|
213
|
+
optional: true,
|
214
|
+
type: ::String,
|
215
|
+
},
|
216
|
+
auth_test_mode: {
|
217
|
+
optional: true,
|
218
|
+
types: [ ::FalseClass, ::TrueClass ],
|
219
|
+
}
|
220
|
+
}
|
221
|
+
|
222
|
+
def initialize h, **options
|
223
|
+
|
224
|
+
trace ParamNames[ :h, :options ], h, options
|
225
|
+
|
226
|
+
initialize_from_hash h, Attributes, **options
|
227
|
+
|
228
|
+
if secret_server
|
229
|
+
|
230
|
+
ss = CassiniSecretServerElement.new(secret_server, **options)
|
231
|
+
|
232
|
+
define_singleton_method(:secret_server) { ss }
|
233
|
+
end
|
234
|
+
end
|
235
|
+
end
|
236
|
+
|
237
|
+
class ControlElement < Element
|
238
|
+
|
239
|
+
Attributes = {
|
240
|
+
|
241
|
+
detach: {
|
242
|
+
|
243
|
+
types: [ ::FalseClass, ::TrueClass ],
|
244
|
+
},
|
245
|
+
cassid_wait: {
|
246
|
+
|
247
|
+
optional: true,
|
248
|
+
type: ::Integer,
|
249
|
+
},
|
250
|
+
ss_wait: {
|
251
|
+
|
252
|
+
optional: true,
|
253
|
+
type: ::Integer,
|
254
|
+
},
|
255
|
+
}
|
256
|
+
|
257
|
+
def initialize h, **options
|
258
|
+
|
259
|
+
trace ParamNames[ :h, :options ], h, options
|
260
|
+
|
261
|
+
check_parameter h, 'h', type: ::Hash
|
262
|
+
|
263
|
+
initialize_from_hash h, Attributes, **options
|
264
|
+
end
|
265
|
+
end
|
266
|
+
|
267
|
+
class DiagnosticsElement < Element
|
268
|
+
|
269
|
+
Attributes = {
|
270
|
+
|
271
|
+
benchmark: {
|
272
|
+
|
273
|
+
types: [ ::FalseClass, ::TrueClass ],
|
274
|
+
},
|
275
|
+
console: {
|
276
|
+
|
277
|
+
type: ::Hash,
|
278
|
+
},
|
279
|
+
main: {
|
280
|
+
|
281
|
+
type: ::Hash,
|
282
|
+
},
|
283
|
+
directory: {
|
284
|
+
type: ::String,
|
285
|
+
optional: true,
|
286
|
+
},
|
287
|
+
}
|
288
|
+
|
289
|
+
def initialize h, **options
|
290
|
+
|
291
|
+
trace ParamNames[ :h, :options ], h, options
|
292
|
+
|
293
|
+
check_parameter h, 'h', type: ::Hash
|
294
|
+
|
295
|
+
initialize_from_hash h, Attributes, **options
|
296
|
+
end
|
297
|
+
end
|
298
|
+
|
299
|
+
class RazorElement < Element
|
300
|
+
|
301
|
+
Attributes = {
|
302
|
+
|
303
|
+
clarite_config: {
|
304
|
+
|
305
|
+
type: ::String,
|
306
|
+
},
|
307
|
+
executable: {
|
308
|
+
|
309
|
+
type: ::String,
|
310
|
+
},
|
311
|
+
environment: {
|
312
|
+
|
313
|
+
type: ::String,
|
314
|
+
optional: true,
|
315
|
+
},
|
316
|
+
alias: {
|
317
|
+
|
318
|
+
type: ::String,
|
319
|
+
optional: true,
|
320
|
+
},
|
321
|
+
space: {
|
322
|
+
|
323
|
+
type: ::String,
|
324
|
+
optional: true,
|
325
|
+
},
|
326
|
+
}
|
327
|
+
|
328
|
+
def initialize h, **options
|
329
|
+
|
330
|
+
trace ParamNames[ :h, :options ], h, options
|
331
|
+
|
332
|
+
check_parameter h, 'h', type: ::Hash
|
333
|
+
|
334
|
+
initialize_from_hash h, Attributes, **options
|
335
|
+
end
|
336
|
+
end
|
337
|
+
|
338
|
+
def initialize h, **options
|
339
|
+
|
340
|
+
trace ParamNames[ :h, :options ], h, options
|
341
|
+
|
342
|
+
check_parameter h, 'h', type: ::Hash
|
343
|
+
|
344
|
+
@cassini = CassiniElement.new h['cassini'], **options
|
345
|
+
@control = ControlElement.new h['control'], **options
|
346
|
+
@diagnostics = DiagnosticsElement.new h['diagnostics'], **options
|
347
|
+
@razor = RazorElement.new h['razor'], **options
|
348
|
+
end
|
349
|
+
|
350
|
+
# Object representing the configurations's 'cassini' node
|
351
|
+
attr_reader :cassini
|
352
|
+
# Object representing the configurations's 'control' node
|
353
|
+
attr_reader :control
|
354
|
+
# Object representing the configurations's 'diagnostics' node
|
355
|
+
attr_reader :diagnostics
|
356
|
+
# Object representing the configurations's 'razor' node
|
357
|
+
attr_reader :razor
|
358
|
+
|
359
|
+
end # class Configuration
|
360
|
+
end # module CassiD
|
361
|
+
end # module Utilities
|
362
|
+
end # module Cassini
|
363
|
+
end # module RazorRisk
|
364
|
+
|
365
|
+
# ############################## end of file ############################# #
|
366
|
+
|
367
|
+
|
@@ -0,0 +1,48 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
# ######################################################################## #
|
4
|
+
# File: razor_risk/cassini/utilities/cassid/constants.rb
|
5
|
+
#
|
6
|
+
# Purpose: CassiD constants
|
7
|
+
#
|
8
|
+
# Created: 23rd February 2018
|
9
|
+
# Updated: 5th November 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
|
+
=begin
|
20
|
+
=end
|
21
|
+
|
22
|
+
module RazorRisk
|
23
|
+
module Cassini
|
24
|
+
module Utilities
|
25
|
+
module CassiD
|
26
|
+
|
27
|
+
CONFIG_TOP_LEVEL_KEYS = %w{ properties cassini control diagnostics razor }
|
28
|
+
|
29
|
+
CONFIG_cassini_KEYS_REQ = %w{ ces first_port host auth_mode microservices us_multiplier }
|
30
|
+
CONFIG_cassini_KEYS_OPT = %w{ root_dir secret_server tls web_server web_ui_server external_services auth_test_mode }
|
31
|
+
|
32
|
+
CONFIG_control_KEYS_REQ = %w{ }
|
33
|
+
CONFIG_control_KEYS_OPT = %w{ detach cassid_wait ss_wait }
|
34
|
+
|
35
|
+
CONFIG_diag_KEYS_REQ = %w{ }
|
36
|
+
CONFIG_diag_KEYS_OPT = %w{ benchmark console main directory }
|
37
|
+
|
38
|
+
CONFIG_razor_KEYS_REQ = %w{ clarite_config }
|
39
|
+
CONFIG_razor_KEYS_OPT = %w{ executable environment alias space }
|
40
|
+
|
41
|
+
end # module CassiD
|
42
|
+
end # module Utilities
|
43
|
+
end # module Cassini
|
44
|
+
end # module RazorRisk
|
45
|
+
|
46
|
+
# ############################## end of file ############################# #
|
47
|
+
|
48
|
+
|