restful-riskpointdata-domains 0.6.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 3d70bc8e2a192aea547f2f2c895a3c25ccebe814
4
+ data.tar.gz: '09027935e119fa72b666057d7832389077bf94a0'
5
+ SHA512:
6
+ metadata.gz: cd82124bcb0f51ae5943edec291d05c09c887417c24a022640fc47a2ae1b94ca8e9d0e4bc8d2bc5c1c1384b487c06d422f328ae44d2df32c2173277905e722a3
7
+ data.tar.gz: 954fcc67180a73e71fc7346dfe72933d70ac66640ede88f9ffd0c329cb92de0c08e9b9de7a79f5fb4fb230e9c17ad5eed4456b86be4b1638fe883697987c4564
@@ -0,0 +1,412 @@
1
+ #!/usr/bin/env ruby
2
+ # encoding: UTF-8
3
+
4
+ # ######################################################################## #
5
+ # File: tools/servers/restful/rpd/ws.rb
6
+ #
7
+ # Purpose: Main module/entry file for the RiskPointData.Domain Microservice
8
+ #
9
+ # Author: Matthew Wilson
10
+ #
11
+ # Copyright (c) 2017-2018, Razor Risk Technologies Pty Ltd
12
+ # All rights reserved.
13
+ #
14
+ # ######################################################################## #
15
+
16
+
17
+ # ##########################################################################
18
+
19
+ # Microservices: RiskPointData.Domain (rpd)
20
+ #
21
+ # Supported:
22
+ #
23
+ # - [GET] /:domain {Unsecured}
24
+ # - [DELETE] /delete/:domain/:id {Secured}
25
+ # - [GET] /get/:domain {Secured}
26
+ # - [GET] /get/:domain/:id {Secured}
27
+ # - [PUT] /put/:domain/:id {Secured}
28
+ # - [GET] /get/:domain/:id/tree {Secured}
29
+
30
+ # ##########################################################################
31
+ # requires
32
+
33
+ require 'razor_risk/cassini/diagnostics/zeroth_include'
34
+
35
+ require 'razor_risk/cassini/applications/microservices/restful/risk_point_data/domains'
36
+
37
+ require 'razor_risk/cassini/applications/route_verb_adaptors/risk_point_data/domains'
38
+
39
+ require 'razor_risk/cassini/main'
40
+
41
+ require 'razor_risk/cassini/applications/rest_framework/route_verb_dispatcher'
42
+ require 'razor_risk/cassini/applications/secured_microservice'
43
+ require 'razor_risk/cassini/authorisation'
44
+ require 'razor_risk/cassini/common/version'
45
+ require 'razor_risk/cassini/util/version_util'
46
+
47
+ require 'razor_risk/razor/connectivity/razor_3/header_maker'
48
+ require 'razor_risk/razor/connectivity/razor_3/razor_requester'
49
+ require 'razor_risk/razor/connectivity/version'
50
+
51
+ require 'razor_risk/core/diagnostics/extensions/libclimate'
52
+ require 'razor_risk/core/diagnostics/logger'
53
+
54
+ require 'active_support/core_ext/hash'
55
+ require 'pantheios'
56
+ require 'xqsr3/version'
57
+
58
+ require 'csv'
59
+ require 'json'
60
+ require 'nokogiri'
61
+
62
+ # ##########################################################################
63
+ # includes
64
+
65
+ include ::RazorRisk::Cassini::Applications
66
+ include ::RazorRisk::Cassini::Applications::RESTFramework
67
+ include ::RazorRisk::Cassini::Applications::RouteVerbAdaptors
68
+ include ::RazorRisk::Cassini::Authorisation::SecurityModelHelpers
69
+ include ::RazorRisk::Cassini::Constants
70
+ include ::RazorRisk::Cassini::Util::SecretsUtil
71
+ include ::RazorRisk::Cassini::Util::VersionUtil
72
+
73
+ include ::RazorRisk::Razor::Connectivity::Razor3
74
+
75
+ include ::RazorRisk::Cassini::Diagnostics
76
+ include ::RazorRisk::Core::Diagnostics::Logger
77
+
78
+ include ::Pantheios
79
+
80
+ # ##########################################################################
81
+ # constants
82
+
83
+ PROGRAM_VERSION = ::RazorRisk::Cassini::Applications::Microservices::RESTful::RiskPointData::Domains::VERSION
84
+
85
+ SUPPORTED_ROUTES = [
86
+
87
+ [ '/delete/:domain/:id', :delete, 'deletes the specified rpd', ],
88
+ [ '/get/:domain', :get, 'gets the collection of rpd', ],
89
+ [ '/get/:domain/:id', :get, 'gets the specified rpd', ],
90
+ [ '/put/:domain/:id', :put, 'puts the specified rpd', ],
91
+ [ '/get/:domain/:id/tree', :get, 'gets the realationship hierarchy for the specified rpd', ],
92
+ [ '/get/audit/:domain/:id', :get, 'gets the specified audit data', ],
93
+ [ '/get/riskpointdata/?', :get, 'gets the risk point data', ],
94
+ ]
95
+
96
+ HTTP_ACCEPTS = %w{ text/html application/json application/xml text/xml text/csv text/plain text/tab-separated-values text/tsv }
97
+
98
+ # ##########################################################################
99
+ # compatibility checks
100
+
101
+ check_version_compatibility ::RazorRisk::Cassini::Common, [ 0, 21 ], 'RazorRisk.Cassini.Common'
102
+ check_version_compatibility ::RazorRisk::Razor::Connectivity, [ 0, 11, 2 ], 'RazorRisk.Razor.Connectivity'
103
+ check_version_compatibility ::LibCLImate, '0.10'
104
+ check_version_compatibility ::Pantheios, '0.20'
105
+ check_version_compatibility ::Xqsr3::VERSION, '0.30'
106
+
107
+ # ##########################################################################
108
+ # functions
109
+
110
+ def make_CSV_routes routes
111
+
112
+ CSV.generate do |csv|
113
+
114
+ routes.each do |ar|
115
+
116
+ csv << ar
117
+ end
118
+ end
119
+ end
120
+
121
+ def make_HTML_routes routes, **options
122
+
123
+ # TODO: use erb
124
+
125
+ routes = routes.map do |ar|
126
+
127
+ <<END_OF_tr
128
+ <tr>
129
+ <td>#{ar[0]}</td>
130
+ <td>#{ar[1]}</td>
131
+ <td>#{ar[2]}</td>
132
+ </tr>
133
+ END_OF_tr
134
+ end
135
+
136
+ <<END_OF_html
137
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.we.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
138
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
139
+ <head>
140
+ <title>Razor Risk Web Service API - Internal Microservice - RiskPointData.Domains/title>
141
+ <meta name="revisit-after" content="24 hours" />
142
+ <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
143
+ </head>
144
+ <body>
145
+ <h1>Routes</h1>
146
+ <table>
147
+ <tr>
148
+ <th>Route</th>
149
+ <th>Verb</th>
150
+ <th>Description</th>
151
+ </tr>
152
+ #{routes.map { |r| r.chomp("\n") }.join("\n")}
153
+ </table>
154
+ </body>
155
+ </html>
156
+ END_OF_html
157
+ end
158
+
159
+ def make_JSON_routes routes, **options
160
+
161
+ r = {
162
+
163
+ 'routes' => []
164
+ }
165
+
166
+ r['routes'] = SUPPORTED_ROUTES.map { |ar| { route: ar[0], verb: ar[1].to_s.upcase, description: ar[2] } }
167
+
168
+ r.to_json
169
+ end
170
+
171
+ def make_Plain_routes routes
172
+
173
+ make_TSV_routes routes
174
+ end
175
+
176
+ def make_TSV_routes routes
177
+
178
+ routes.map { |ar| "#{ar[0]}\t#{ar[1]}\t#{ar[2]}\n" }
179
+ end
180
+
181
+ def make_XML_routes routes
182
+
183
+ <<END_OF_xml
184
+ <?xml version="1.0">
185
+ <routes>#{routes.map { |ar| %Q{ <route route="#{ar[0]}" verb="#{ar[1].to_s.upcase}" description="#{ar[2]}"/>}}.join(%Q{\n})}
186
+ </routes>
187
+ END_OF_xml
188
+ end
189
+
190
+ # ##########################################################################
191
+ # static set-up
192
+
193
+ # ##########################################################################
194
+ # lambdas
195
+
196
+ Lambdas_XML_to_JSON = lambda do |xml|
197
+
198
+ ConversionUtil.convert_XML_to_JSON xml
199
+ end
200
+
201
+ # ##########################################################################
202
+ # application
203
+
204
+ class RiskPointData_DomainApp < SecuredMicroservice
205
+
206
+ include RouteVerbDispatch
207
+
208
+ include ::Pantheios
209
+
210
+
211
+ FULL_DESIGNATION = 'RiskPointData.Domain'
212
+ SHORT_DESIGNATION = 'rpd'
213
+ SERVICE_TYPE = :microservice
214
+
215
+ PROGRAM_FEATURES = {
216
+
217
+ has_web_server: true,
218
+
219
+ has_host_and_port: true,
220
+
221
+ has_razor_connectivity: true,
222
+
223
+ authentication: :with_credentials_algorithm,
224
+
225
+ copyright_year: 2017,
226
+ }
227
+
228
+
229
+ def self.on_init_service options
230
+
231
+ trace ParamNames[ :options ], options
232
+
233
+ raise ArgumentError, 'missing keyword: razor_requester' unless options.has_key? :razor_requester
234
+
235
+ set :razor_requester, options[:razor_requester]
236
+ end
237
+
238
+
239
+
240
+ private
241
+ def sec
242
+
243
+ return '' if credentials.empty?
244
+ " (for #{credentials.join(':')})"
245
+ end
246
+ public
247
+
248
+
249
+ # functional routes (DELETE, GET, PUT, POST)
250
+
251
+ # params:
252
+ # +result-form+:: Specifies the form of the result: +default+ gets the
253
+ # full Razor body, and is the default if none specified;
254
+ get '/get/hierarchy/:domain/:id/?' do
255
+
256
+ # trace
257
+
258
+ trace ParamNames[ :request, :params ], request, params
259
+
260
+ dispatch RiskPointData::Domains::HierarchyItemGet
261
+ end
262
+
263
+ delete '/delete/:domain/:id/?' do
264
+
265
+ # trace
266
+
267
+ trace ParamNames[ :request, :params ], request, params
268
+
269
+ dispatch RiskPointData::Domains::ItemDelete
270
+ end
271
+
272
+ # params:
273
+ # +result-form+:: Specifies the form of the result: +default+ gets the
274
+ # full Razor body, and is the default if none specified; +summary+ gets
275
+ # the rpd-summary form; +rpd+ gets the rpd form
276
+ get '/get/:domain/:id/?' do
277
+
278
+ # trace
279
+
280
+ trace ParamNames[ :request, :params ], request, params
281
+
282
+ dispatch RiskPointData::Domains::ItemGet
283
+ end
284
+
285
+ get '/get/audit/:domain/:id/?' do
286
+
287
+ # trace
288
+
289
+ trace ParamNames[ :request, :params ], request, params
290
+
291
+ dispatch RiskPointData::Domains::ItemAuditGet
292
+ end
293
+
294
+ get '/get/riskpointdata/?' do
295
+
296
+ # trace
297
+ trace ParamNames[ :request, :params ], request, params
298
+ dispatch RiskPointData::Domains::RiskPointGet
299
+ end
300
+
301
+ # params:
302
+ # +page-base+:: Specifies the (0-based) index index of the first element
303
+ # to be presented. Defaults to 0 if not specified
304
+ # +page-extent+:: Specifies the number of records to return in the
305
+ # retrieval window. Defaults to 1000 if not specified
306
+ # +quick-search+:: Specifies a quick-search string
307
+ # +sort_field+:: Specifies the field to sort results by
308
+ # +sort_direction+:: Specifies the direction to sort the results by. May
309
+ # be +ascending+ or +descending+ and is case insensitive.
310
+ get '/get/:domain/?' do
311
+
312
+ trace ParamNames[ :request, :params ], request, params
313
+
314
+ dispatch RiskPointData::Domains::CollectionGet
315
+ end
316
+
317
+ put '/put/:domain/:id/?' do
318
+
319
+ trace ParamNames[ :request, :params ], request, params
320
+
321
+ dispatch RiskPointData::Domains::ItemPut
322
+ end
323
+
324
+ post '/post/:domain/?' do
325
+
326
+ trace ParamNames[ :request, :params ], request, params
327
+
328
+ dispatch RiskPointData::Domains::ItemPost
329
+ end
330
+
331
+
332
+ get '/' do
333
+
334
+ HTTP_ACCEPTS.each do |accept_type|
335
+
336
+ if request.accept? accept_type
337
+
338
+ content_type accept_type
339
+
340
+ case accept_type
341
+ when 'application/json'
342
+
343
+ r = make_JSON_routes SUPPORTED_ROUTES
344
+ when 'application/xml', 'text/xml'
345
+
346
+ r = make_XML_routes SUPPORTED_ROUTES
347
+ when 'text/csv'
348
+
349
+ r = make_CSV_routes SUPPORTED_ROUTES
350
+ when 'text/html'
351
+
352
+ r = make_HTML_routes SUPPORTED_ROUTES
353
+ when 'text/plain'
354
+
355
+ r = make_Plain_routes SUPPORTED_ROUTES
356
+ when 'text/tsv', 'text/tab-separated-values'
357
+
358
+ r = make_TSV_routes SUPPORTED_ROUTES
359
+ else
360
+
361
+ log :violation, 'unrecognised accept type \'', accept_type, '\''
362
+
363
+ halt *[ 500, {}, 'internal server failure' ]
364
+ end
365
+
366
+ return r
367
+ end
368
+ end
369
+
370
+ halt *[ 406, {}, "supports only the Accept types #{HTTP_ACCEPTS.map { |t| %Q<'#{t}'> }.join(', ')}" ]
371
+ end
372
+
373
+ define_catch_all_handlers
374
+ end
375
+
376
+ TheApp = RiskPointData_DomainApp
377
+
378
+ # now define the OPTIONS support
379
+
380
+ supported_routes = Hash.new { |h, k| h[k] = [] }
381
+
382
+ SUPPORTED_ROUTES.each do |ar|
383
+
384
+ supported_routes[ar[0]].push ar[1]
385
+ end
386
+
387
+ supported_routes.each do |k, v|
388
+
389
+ if k =~ /:domain\/:id(?:\/\?)?$/
390
+
391
+ route = "#$`*"
392
+ else
393
+
394
+ route = k
395
+ end
396
+
397
+ TheApp.options route do
398
+
399
+ verbs = v.map { |t| t.upcase }.join(',')
400
+
401
+ halt *[200, { 'Allow' => verbs }, [ verbs ] ]
402
+ end
403
+ end
404
+
405
+ TheApp.options '/' do
406
+
407
+ halt *[200, { 'Allow' => 'GET' }, '' ]
408
+ end
409
+
410
+ # ############################## end of file ############################# #
411
+
412
+
@@ -0,0 +1,61 @@
1
+ # encoding: UTF-8
2
+
3
+ # ######################################################################## #
4
+ # File: razor_risk/cassini/applications/microservices/restful/rsik_point_data/domains/version.rb
5
+ #
6
+ # Purpose: Version for RazorRisk.Cassini.Microservices.RESTful.RiskPointData.Domains library
7
+ #
8
+ # Created: 7th January 2019
9
+ # Updated: 15th January 2019
10
+ #
11
+ # Copyright (c) 2019, Razor Risk Technologies Pty Ltd
12
+ # All rights reserved.
13
+ #
14
+ # ######################################################################## #
15
+
16
+
17
+ =begin
18
+ =end
19
+
20
+ module RazorRisk
21
+ module Cassini
22
+ module Applications
23
+ module Microservices
24
+ module RESTful
25
+ module RiskPointData
26
+
27
+ module Domains
28
+
29
+ # Current version of the RazorRisk.Cassini.Microservices.RESTful.RiskPointData.Domains library
30
+ VERSION = '0.6.13'
31
+
32
+ private
33
+ VERSION_PARTS_ = VERSION.split(/[.]/).collect { |n| n.to_i } # :nodoc:
34
+ public
35
+ # Major version of the RazorRisk.Cassini.Microservices.RESTful.RiskPointData.Domains library
36
+ VERSION_MAJOR = VERSION_PARTS_[0] # :nodoc:
37
+ # Minor version of the RazorRisk.Cassini.Microservices.RESTful.RiskPointData.Domains library
38
+ VERSION_MINOR = VERSION_PARTS_[1] # :nodoc:
39
+ # Patch version of the RazorRisk.Cassini.Microservices.RESTful.RiskPointData.Domains library
40
+ VERSION_PATCH = VERSION_PARTS_[2] # :nodoc:
41
+ # Commit version of the RazorRisk.Cassini.Microservices.RESTful.RiskPointData.Domains library
42
+ VERSION_COMMIT = VERSION_PARTS_[3] || 0 # :nodoc:
43
+
44
+
45
+ # The description of the framework
46
+ DESCRIPTION = "Razor Risk's Cassini Web-framework's RiskPointData.Domains RESTful microservice"
47
+
48
+ # [DEPRECATED] Instead use +DESCRIPTION+
49
+ FRAMEWORK_DESCRIPTION = DESCRIPTION
50
+ end # module Domains
51
+
52
+ end # module RiskPointData
53
+ end # module RESTful
54
+ end # module Microservices
55
+ end # module Applications
56
+ end # module Cassini
57
+ end # module RazorRisk
58
+
59
+ # ############################## end of file ############################# #
60
+
61
+
@@ -0,0 +1,2 @@
1
+
2
+ require 'razor_risk/cassini/applications/microservices/restful/risk_point_data/domains/version'