hoodoo 1.0.2
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 +7 -0
- data/bin/hoodoo +5 -0
- data/lib/hoodoo.rb +27 -0
- data/lib/hoodoo/active.rb +32 -0
- data/lib/hoodoo/active/active_model/uuid_validator.rb +45 -0
- data/lib/hoodoo/active/active_record/base.rb +81 -0
- data/lib/hoodoo/active/active_record/creator.rb +134 -0
- data/lib/hoodoo/active/active_record/dated.rb +343 -0
- data/lib/hoodoo/active/active_record/error_mapping.rb +351 -0
- data/lib/hoodoo/active/active_record/finder.rb +606 -0
- data/lib/hoodoo/active/active_record/search_helper.rb +189 -0
- data/lib/hoodoo/active/active_record/secure.rb +431 -0
- data/lib/hoodoo/active/active_record/support.rb +106 -0
- data/lib/hoodoo/active/active_record/translated.rb +87 -0
- data/lib/hoodoo/active/active_record/uuid.rb +80 -0
- data/lib/hoodoo/active/active_record/writer.rb +321 -0
- data/lib/hoodoo/client.rb +23 -0
- data/lib/hoodoo/client/augmented_array.rb +29 -0
- data/lib/hoodoo/client/augmented_base.rb +168 -0
- data/lib/hoodoo/client/augmented_hash.rb +23 -0
- data/lib/hoodoo/client/client.rb +354 -0
- data/lib/hoodoo/client/endpoint/endpoint.rb +427 -0
- data/lib/hoodoo/client/endpoint/endpoints/amqp.rb +180 -0
- data/lib/hoodoo/client/endpoint/endpoints/auto_session.rb +194 -0
- data/lib/hoodoo/client/endpoint/endpoints/http.rb +203 -0
- data/lib/hoodoo/client/endpoint/endpoints/http_based.rb +367 -0
- data/lib/hoodoo/client/endpoint/endpoints/not_found.rb +59 -0
- data/lib/hoodoo/client/headers.rb +269 -0
- data/lib/hoodoo/communicators.rb +23 -0
- data/lib/hoodoo/communicators/fast.rb +44 -0
- data/lib/hoodoo/communicators/pool.rb +601 -0
- data/lib/hoodoo/communicators/slow.rb +84 -0
- data/lib/hoodoo/data.rb +51 -0
- data/lib/hoodoo/data/resources/caller.rb +39 -0
- data/lib/hoodoo/data/resources/errors.rb +28 -0
- data/lib/hoodoo/data/resources/log.rb +31 -0
- data/lib/hoodoo/data/resources/session.rb +26 -0
- data/lib/hoodoo/data/types/error_primitive.rb +27 -0
- data/lib/hoodoo/data/types/permissions.rb +40 -0
- data/lib/hoodoo/data/types/permissions_defaults.rb +32 -0
- data/lib/hoodoo/data/types/permissions_full.rb +28 -0
- data/lib/hoodoo/data/types/permissions_resources.rb +31 -0
- data/lib/hoodoo/discovery.rb +20 -0
- data/lib/hoodoo/errors.rb +19 -0
- data/lib/hoodoo/errors/error_descriptions.rb +229 -0
- data/lib/hoodoo/errors/errors.rb +322 -0
- data/lib/hoodoo/generator.rb +139 -0
- data/lib/hoodoo/logger.rb +23 -0
- data/lib/hoodoo/logger/fast_writer.rb +27 -0
- data/lib/hoodoo/logger/flattener_mixin.rb +36 -0
- data/lib/hoodoo/logger/logger.rb +387 -0
- data/lib/hoodoo/logger/slow_writer.rb +49 -0
- data/lib/hoodoo/logger/writer_mixin.rb +52 -0
- data/lib/hoodoo/logger/writers/file_writer.rb +45 -0
- data/lib/hoodoo/logger/writers/log_entries_dot_com_writer.rb +64 -0
- data/lib/hoodoo/logger/writers/stream_writer.rb +43 -0
- data/lib/hoodoo/middleware.rb +33 -0
- data/lib/hoodoo/presenters.rb +45 -0
- data/lib/hoodoo/presenters/base.rb +281 -0
- data/lib/hoodoo/presenters/base_dsl.rb +519 -0
- data/lib/hoodoo/presenters/common_resource_fields.rb +31 -0
- data/lib/hoodoo/presenters/embedding.rb +232 -0
- data/lib/hoodoo/presenters/types/array.rb +118 -0
- data/lib/hoodoo/presenters/types/boolean.rb +26 -0
- data/lib/hoodoo/presenters/types/date.rb +26 -0
- data/lib/hoodoo/presenters/types/date_time.rb +26 -0
- data/lib/hoodoo/presenters/types/decimal.rb +47 -0
- data/lib/hoodoo/presenters/types/enum.rb +55 -0
- data/lib/hoodoo/presenters/types/field.rb +158 -0
- data/lib/hoodoo/presenters/types/float.rb +26 -0
- data/lib/hoodoo/presenters/types/hash.rb +361 -0
- data/lib/hoodoo/presenters/types/integer.rb +26 -0
- data/lib/hoodoo/presenters/types/object.rb +117 -0
- data/lib/hoodoo/presenters/types/string.rb +53 -0
- data/lib/hoodoo/presenters/types/tags.rb +24 -0
- data/lib/hoodoo/presenters/types/text.rb +26 -0
- data/lib/hoodoo/presenters/types/uuid.rb +54 -0
- data/lib/hoodoo/services.rb +34 -0
- data/lib/hoodoo/services/discovery/discoverers/by_consul.rb +66 -0
- data/lib/hoodoo/services/discovery/discoverers/by_convention.rb +173 -0
- data/lib/hoodoo/services/discovery/discoverers/by_drb/by_drb.rb +195 -0
- data/lib/hoodoo/services/discovery/discoverers/by_drb/drb_server.rb +166 -0
- data/lib/hoodoo/services/discovery/discoverers/by_drb/drb_server_start.rb +37 -0
- data/lib/hoodoo/services/discovery/discovery.rb +186 -0
- data/lib/hoodoo/services/discovery/results/for_amqp.rb +58 -0
- data/lib/hoodoo/services/discovery/results/for_http.rb +85 -0
- data/lib/hoodoo/services/discovery/results/for_local.rb +85 -0
- data/lib/hoodoo/services/discovery/results/for_remote.rb +57 -0
- data/lib/hoodoo/services/middleware/amqp_log_message.rb +186 -0
- data/lib/hoodoo/services/middleware/amqp_log_writer.rb +119 -0
- data/lib/hoodoo/services/middleware/endpoints/inter_resource_local.rb +130 -0
- data/lib/hoodoo/services/middleware/endpoints/inter_resource_remote.rb +202 -0
- data/lib/hoodoo/services/middleware/exception_reporting/base_reporter.rb +105 -0
- data/lib/hoodoo/services/middleware/exception_reporting/exception_reporting.rb +115 -0
- data/lib/hoodoo/services/middleware/exception_reporting/reporters/airbrake_reporter.rb +64 -0
- data/lib/hoodoo/services/middleware/exception_reporting/reporters/raygun_reporter.rb +63 -0
- data/lib/hoodoo/services/middleware/interaction.rb +127 -0
- data/lib/hoodoo/services/middleware/middleware.rb +2705 -0
- data/lib/hoodoo/services/middleware/rack_monkey_patch.rb +73 -0
- data/lib/hoodoo/services/services/context.rb +153 -0
- data/lib/hoodoo/services/services/implementation.rb +132 -0
- data/lib/hoodoo/services/services/interface.rb +934 -0
- data/lib/hoodoo/services/services/permissions.rb +250 -0
- data/lib/hoodoo/services/services/request.rb +189 -0
- data/lib/hoodoo/services/services/response.rb +316 -0
- data/lib/hoodoo/services/services/service.rb +141 -0
- data/lib/hoodoo/services/services/session.rb +729 -0
- data/lib/hoodoo/utilities.rb +12 -0
- data/lib/hoodoo/utilities/string_inquirer.rb +54 -0
- data/lib/hoodoo/utilities/utilities.rb +380 -0
- data/lib/hoodoo/utilities/uuid.rb +44 -0
- data/lib/hoodoo/version.rb +17 -0
- data/spec/active/active_record/base_spec.rb +57 -0
- data/spec/active/active_record/creator_spec.rb +88 -0
- data/spec/active/active_record/dated_spec.rb +248 -0
- data/spec/active/active_record/error_mapping_spec.rb +360 -0
- data/spec/active/active_record/finder_spec.rb +744 -0
- data/spec/active/active_record/search_helper_spec.rb +384 -0
- data/spec/active/active_record/secure_spec.rb +435 -0
- data/spec/active/active_record/support_spec.rb +225 -0
- data/spec/active/active_record/translated_spec.rb +19 -0
- data/spec/active/active_record/uuid_spec.rb +72 -0
- data/spec/active/active_record/writer_spec.rb +272 -0
- data/spec/alchemy/alchemy-amq.rb +33 -0
- data/spec/client/augmented_array_spec.rb +15 -0
- data/spec/client/augmented_base_spec.rb +50 -0
- data/spec/client/augmented_hash_spec.rb +15 -0
- data/spec/client/client_spec.rb +955 -0
- data/spec/client/endpoint/endpoint_spec.rb +70 -0
- data/spec/client/endpoint/endpoints/amqp_spec.rb +16 -0
- data/spec/client/endpoint/endpoints/auto_session_spec.rb +9 -0
- data/spec/client/endpoint/endpoints/http_based_spec.rb +9 -0
- data/spec/client/endpoint/endpoints/http_spec.rb +103 -0
- data/spec/client/endpoint/endpoints/not_found_spec.rb +35 -0
- data/spec/client/headers_spec.rb +172 -0
- data/spec/communicators/fast_spec.rb +9 -0
- data/spec/communicators/pool_spec.rb +339 -0
- data/spec/communicators/slow_spec.rb +15 -0
- data/spec/data/resources/caller_spec.rb +156 -0
- data/spec/data/resources/errors_spec.rb +22 -0
- data/spec/data/resources/log_spec.rb +20 -0
- data/spec/data/resources/session_spec.rb +15 -0
- data/spec/data/types/error_primitive_spec.rb +15 -0
- data/spec/data/types/permissions_defaults_spec.rb +25 -0
- data/spec/data/types/permissions_full_spec.rb +44 -0
- data/spec/data/types/permissions_resources_spec.rb +34 -0
- data/spec/data/types/permissions_spec.rb +37 -0
- data/spec/errors/error_descriptions_spec.rb +98 -0
- data/spec/errors/errors_spec.rb +346 -0
- data/spec/integration/service_actions_spec.rb +112 -0
- data/spec/logger/fast_writer_spec.rb +18 -0
- data/spec/logger/logger_spec.rb +259 -0
- data/spec/logger/slow_writer_spec.rb +144 -0
- data/spec/logger/writers/file_writer_spec.rb +37 -0
- data/spec/logger/writers/log_entries_dot_com_writer_spec.rb +29 -0
- data/spec/logger/writers/stream_writer_spec.rb +38 -0
- data/spec/presenters/base_dsl_spec.rb +111 -0
- data/spec/presenters/base_spec.rb +871 -0
- data/spec/presenters/common_resource_fields_spec.rb +30 -0
- data/spec/presenters/embedding_spec.rb +87 -0
- data/spec/presenters/types/array_spec.rb +249 -0
- data/spec/presenters/types/boolean_spec.rb +51 -0
- data/spec/presenters/types/date_spec.rb +57 -0
- data/spec/presenters/types/date_time_spec.rb +59 -0
- data/spec/presenters/types/decimal_spec.rb +58 -0
- data/spec/presenters/types/enum_spec.rb +71 -0
- data/spec/presenters/types/field_spec.rb +77 -0
- data/spec/presenters/types/float_spec.rb +50 -0
- data/spec/presenters/types/hash_spec.rb +1069 -0
- data/spec/presenters/types/integer_spec.rb +50 -0
- data/spec/presenters/types/object_spec.rb +177 -0
- data/spec/presenters/types/string_spec.rb +65 -0
- data/spec/presenters/types/tags_spec.rb +56 -0
- data/spec/presenters/types/text_spec.rb +50 -0
- data/spec/presenters/types/uuid_spec.rb +46 -0
- data/spec/presenters/walk_spec.rb +198 -0
- data/spec/services/discovery/discoverers/by_consul_spec.rb +29 -0
- data/spec/services/discovery/discoverers/by_convention_spec.rb +67 -0
- data/spec/services/discovery/discoverers/by_drb/by_drb_spec.rb +80 -0
- data/spec/services/discovery/discoverers/by_drb/drb_server_spec.rb +205 -0
- data/spec/services/discovery/discovery_spec.rb +73 -0
- data/spec/services/discovery/results/for_amqp_spec.rb +17 -0
- data/spec/services/discovery/results/for_http_spec.rb +37 -0
- data/spec/services/discovery/results/for_local_spec.rb +21 -0
- data/spec/services/discovery/results/for_remote_spec.rb +15 -0
- data/spec/services/middleware/amqp_log_message_spec.rb +60 -0
- data/spec/services/middleware/amqp_log_writer_spec.rb +95 -0
- data/spec/services/middleware/endpoints/inter_resource_local_spec.rb +9 -0
- data/spec/services/middleware/endpoints/inter_resource_remote_spec.rb +9 -0
- data/spec/services/middleware/exception_reporting/base_reporter_spec.rb +16 -0
- data/spec/services/middleware/exception_reporting/exception_reporting_spec.rb +92 -0
- data/spec/services/middleware/exception_reporting/reporters/airbrake_reporter_spec.rb +24 -0
- data/spec/services/middleware/exception_reporting/reporters/raygun_reporter_spec.rb +23 -0
- data/spec/services/middleware/middleware_cors_spec.rb +93 -0
- data/spec/services/middleware/middleware_create_update_spec.rb +489 -0
- data/spec/services/middleware/middleware_dated_at_spec.rb +186 -0
- data/spec/services/middleware/middleware_exotic_communication_spec.rb +560 -0
- data/spec/services/middleware/middleware_logging_spec.rb +356 -0
- data/spec/services/middleware/middleware_multi_local_spec.rb +1094 -0
- data/spec/services/middleware/middleware_multi_remote_spec.rb +1440 -0
- data/spec/services/middleware/middleware_permissions_spec.rb +1014 -0
- data/spec/services/middleware/middleware_public_spec.rb +238 -0
- data/spec/services/middleware/middleware_spec.rb +1569 -0
- data/spec/services/middleware/string_inquirer_spec.rb +30 -0
- data/spec/services/services/application_spec.rb +74 -0
- data/spec/services/services/context_spec.rb +48 -0
- data/spec/services/services/implementation_spec.rb +45 -0
- data/spec/services/services/interface_spec.rb +262 -0
- data/spec/services/services/permissions_spec.rb +249 -0
- data/spec/services/services/request_spec.rb +95 -0
- data/spec/services/services/response_spec.rb +250 -0
- data/spec/services/services/session_spec.rb +432 -0
- data/spec/spec_helper.rb +298 -0
- data/spec/utilities/utilities_spec.rb +537 -0
- data/spec/utilities/uuid_spec.rb +20 -0
- metadata +615 -0
@@ -0,0 +1,105 @@
|
|
1
|
+
########################################################################
|
2
|
+
# File:: base.rb
|
3
|
+
# (C):: Loyalty New Zealand 2014
|
4
|
+
#
|
5
|
+
# Purpose:: Abstracted links to third party error management services.
|
6
|
+
# ----------------------------------------------------------------------
|
7
|
+
# 08-Dec-2014 (ADH): Created.
|
8
|
+
########################################################################
|
9
|
+
|
10
|
+
require 'singleton'
|
11
|
+
|
12
|
+
module Hoodoo; module Services
|
13
|
+
class Middleware
|
14
|
+
|
15
|
+
class ExceptionReporting
|
16
|
+
|
17
|
+
# Subclass this method to create a custom class used to contact external
|
18
|
+
# exception monitoring / reporting engine. Examples include:
|
19
|
+
#
|
20
|
+
# * Raygun: https://raygun.io
|
21
|
+
# * Honeybadger: https://www.honeybadger.io
|
22
|
+
# * Exceptional: http://www.exceptional.io
|
23
|
+
# * Airbrake: https://airbrake.io
|
24
|
+
#
|
25
|
+
# Hoodoo includes some classes for integration which you can choose from
|
26
|
+
# if you want to use the integrated service. Alternatively write your own.
|
27
|
+
# When you do this, name your class *outside* the Hoodoo namespace (the
|
28
|
+
# class's name can be anything you like). Otherwise you will trample upon
|
29
|
+
# Hoodoo' reserved namespace and may cause a naming collision in future
|
30
|
+
# Hoodoo versions.
|
31
|
+
#
|
32
|
+
# "Under the hood" the Hoodoo::Communicators::Pool mechanism is used.
|
33
|
+
# All reporters are assumed to be (comparatively) slow communicators so
|
34
|
+
# are descendants of Hoodoo::Communicators::Slow.
|
35
|
+
#
|
36
|
+
# Add a reporter class to the middleware from any service application by
|
37
|
+
# calling Hoodoo::Services::Middleware::ExceptionReporting.add.
|
38
|
+
#
|
39
|
+
class BaseReporter < Hoodoo::Communicators::Slow
|
40
|
+
|
41
|
+
include ::Singleton
|
42
|
+
|
43
|
+
# Subclasses implement this method. The middleware creates the singleton
|
44
|
+
# instance of the subclass, then calls your implementation of the method
|
45
|
+
# when it catches an exception in its top level handler. The subclass
|
46
|
+
# implementation sends details of the exception to the desired exception
|
47
|
+
# monitoring or reporting service. The return value is ignored.
|
48
|
+
#
|
49
|
+
# The middleware wraps calls to your subclass in a nested exception
|
50
|
+
# handler. If you raise an exception, the middleware logs details with
|
51
|
+
# a +:debug+ level through its logger instance if possible (see
|
52
|
+
# Hoodoo::Services::Middleware::logger) along with printing details to
|
53
|
+
# $stderr, then continues processing.
|
54
|
+
#
|
55
|
+
# If service applications are expecting potential exceptions to occur
|
56
|
+
# and they catch them without re-raising for the middleware to catch,
|
57
|
+
# this reporting method will not be called. If a service author thinks
|
58
|
+
# such an exception ought to be logged, they must re-raise it.
|
59
|
+
#
|
60
|
+
# The middleware runs calls here in a processing Thread to avoid delays
|
61
|
+
# to the calling client. This means your implementation of this method
|
62
|
+
# can use blocking network calls should you so wish; but beware, you are
|
63
|
+
# running in your own Thread on every call and more than one call might
|
64
|
+
# be running concurrently. If your implementation is not threadsafe,
|
65
|
+
# use a Mutex. For example, add a mutex class variable to your class:
|
66
|
+
#
|
67
|
+
# @@mutex = Mutex.new
|
68
|
+
#
|
69
|
+
# ...then use it inside +report+ with something like:
|
70
|
+
#
|
71
|
+
# def report( e )
|
72
|
+
# @@mutex.synchronize do
|
73
|
+
# # Your reporting service's custom code goes here
|
74
|
+
# end
|
75
|
+
# end
|
76
|
+
#
|
77
|
+
# +e+:: Exception (or subclass) instance to be reported.
|
78
|
+
#
|
79
|
+
# +env+:: Optional Rack environment hash for the inbound request, for
|
80
|
+
# exception reports made in the context of Rack request
|
81
|
+
# handling.
|
82
|
+
#
|
83
|
+
def report( e, env = nil )
|
84
|
+
raise( 'Subclasses must implement #report' )
|
85
|
+
end
|
86
|
+
|
87
|
+
# Subclasses *MUST* *NOT* override this method, which is part of the
|
88
|
+
# base class implementation and implements
|
89
|
+
# Hoodoo::Communicators::Slow#communicate. It calls through to the
|
90
|
+
# #report method which subclasses do implement, unpacking a payload
|
91
|
+
# used for the internal communicators into the parameters that
|
92
|
+
# #report expects.
|
93
|
+
#
|
94
|
+
# +object+:: Hoodoo::Services::Middleware::ExceptionReporting::Payload
|
95
|
+
# instance.
|
96
|
+
#
|
97
|
+
def communicate( object )
|
98
|
+
self.report( object.exception, object.rack_env )
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
end
|
103
|
+
|
104
|
+
end
|
105
|
+
end; end
|
@@ -0,0 +1,115 @@
|
|
1
|
+
########################################################################
|
2
|
+
# File:: exception_reporting.rb
|
3
|
+
# (C):: Loyalty New Zealand 2014
|
4
|
+
#
|
5
|
+
# Purpose:: Reporting exceptions to third party error management
|
6
|
+
# services.
|
7
|
+
# ----------------------------------------------------------------------
|
8
|
+
# 08-Dec-2014 (ADH): Created.
|
9
|
+
########################################################################
|
10
|
+
|
11
|
+
module Hoodoo; module Services
|
12
|
+
class Middleware
|
13
|
+
|
14
|
+
# Exception reporting / monitoring through external services.
|
15
|
+
#
|
16
|
+
class ExceptionReporting
|
17
|
+
|
18
|
+
# Pool of exception reporters.
|
19
|
+
#
|
20
|
+
@@reporter_pool = Hoodoo::Communicators::Pool.new
|
21
|
+
|
22
|
+
# Add an exception reporter class to the set of reporters. See the
|
23
|
+
# Hoodoo::Services::Middleware::ExceptionReporting::BaseReporter class for an
|
24
|
+
# overview.
|
25
|
+
#
|
26
|
+
# Whenever the middleware's own exception handler catches an exception,
|
27
|
+
# it will run through the set of exception reporters (if any) and call
|
28
|
+
# each one to report exception details.
|
29
|
+
#
|
30
|
+
# Reporters are maintained in a Set. Only one class will ever be
|
31
|
+
# stored and called once per exception; the original order of addition
|
32
|
+
# before duplicates is maintained (so if you add class A, then B, then
|
33
|
+
# A again, then class A is called first and only once, then B once).
|
34
|
+
#
|
35
|
+
# Each reporter is called from its own Ruby Thread so that client API
|
36
|
+
# call response is kept fast. If a call fails, a debug log entry is
|
37
|
+
# made but processing of other reporters continues uninterrupted. It is
|
38
|
+
# up to individual reporter classes to manage thread safety.
|
39
|
+
#
|
40
|
+
# +klass+:: Hoodoo::Services::Middleware::ExceptionReporting::BaseReporter
|
41
|
+
# subclass (class, not instance) to add.
|
42
|
+
#
|
43
|
+
def self.add( klass )
|
44
|
+
unless klass < Hoodoo::Services::Middleware::ExceptionReporting::BaseReporter
|
45
|
+
raise "Hoodoo::Services::Middleware.add must be called with a Hoodoo::Services::Middleware::ExceptionReporting::BaseReporter subclass"
|
46
|
+
end
|
47
|
+
|
48
|
+
@@reporter_pool.add( klass.instance )
|
49
|
+
end
|
50
|
+
|
51
|
+
# Remove an exception reporter class from the set of reporters. See
|
52
|
+
# ::add for details.
|
53
|
+
#
|
54
|
+
# +klass+:: Hoodoo::Services::Middleware::ExceptionReporting::BaseReporter
|
55
|
+
# subclass (class, not instance) to remove.
|
56
|
+
#
|
57
|
+
def self.remove( klass )
|
58
|
+
unless klass < Hoodoo::Services::Middleware::ExceptionReporting::BaseReporter
|
59
|
+
raise "Hoodoo::Services::Middleware.remove must be called with a Hoodoo::Services::Middleware::ExceptionReporting::BaseReporter subclass"
|
60
|
+
end
|
61
|
+
|
62
|
+
@@reporter_pool.remove( klass.instance )
|
63
|
+
end
|
64
|
+
|
65
|
+
# Call all added exception reporters (see ::add) to report an exception.
|
66
|
+
#
|
67
|
+
# +exception+:: Exception or Exception subclass instance to report.
|
68
|
+
#
|
69
|
+
# +rack_env+:: Optional Rack environment hash for the inbound request,
|
70
|
+
# for exception reports made in the context of Rack request
|
71
|
+
# handling.
|
72
|
+
#
|
73
|
+
def self.report( exception, rack_env = nil )
|
74
|
+
payload = Payload.new( exception: exception, rack_env: rack_env )
|
75
|
+
@@reporter_pool.communicate( payload )
|
76
|
+
end
|
77
|
+
|
78
|
+
# Wait for all executing reporter threads to catch up before continuing.
|
79
|
+
#
|
80
|
+
# +timeout+:: Optional timeout wait delay *for* *each* *thread*. Default
|
81
|
+
# is 5 seconds.
|
82
|
+
#
|
83
|
+
def self.wait( timeout = 5 )
|
84
|
+
@@reporter_pool.wait( per_instance_timeout: timeout )
|
85
|
+
end
|
86
|
+
|
87
|
+
# Implementation detail of
|
88
|
+
# Hoodoo::Services::Middleware::ExceptionReporting used to carry
|
89
|
+
# multiple parameters describing exception related data through the
|
90
|
+
# Hoodoo::Communicators::Pool#communicate mechanism.
|
91
|
+
#
|
92
|
+
class Payload
|
93
|
+
|
94
|
+
# Exception (or Exception subclass) instance.
|
95
|
+
#
|
96
|
+
attr_accessor :exception
|
97
|
+
|
98
|
+
# Rack environment (the unprocessed, original Hash). May be +nil+.
|
99
|
+
#
|
100
|
+
attr_accessor :rack_env
|
101
|
+
|
102
|
+
# Initialize this instance with named parameters:
|
103
|
+
#
|
104
|
+
# +exception+:: Exception (or Exception subclass) instance. Mandatory.
|
105
|
+
# +rack_env+:: Rack environment hash. Optional.
|
106
|
+
#
|
107
|
+
def initialize( exception:, rack_env: nil )
|
108
|
+
@exception = exception
|
109
|
+
@rack_env = rack_env
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
end
|
115
|
+
end; end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
########################################################################
|
2
|
+
# File:: airbrake_reporter.rb
|
3
|
+
# (C):: Loyalty New Zealand 2014
|
4
|
+
#
|
5
|
+
# Purpose:: Send exception details to Airbrake.
|
6
|
+
# ----------------------------------------------------------------------
|
7
|
+
# 08-Dec-2014 (ADH): Created.
|
8
|
+
########################################################################
|
9
|
+
|
10
|
+
module Hoodoo; module Services
|
11
|
+
class Middleware
|
12
|
+
|
13
|
+
class ExceptionReporting
|
14
|
+
|
15
|
+
# Hoodoo::Services::Middleware::ExceptionReporting::BaseReporter subclass
|
16
|
+
# giving Hoodoo::Services::Middleware::ExceptionReporting access to
|
17
|
+
# Airbrake for error reporting. See https://airbrake.io.
|
18
|
+
#
|
19
|
+
# Your application must include the Airbrake gem 'airbrake' via Gemfile
|
20
|
+
# (+gem 'airbrake'+ / +bundle install) or direct installation (+gem
|
21
|
+
# install airbrake+).
|
22
|
+
#
|
23
|
+
# The API key must be set during your application initialization and the
|
24
|
+
# class must be added to Hoodoo for use as an error reporter, e.g.
|
25
|
+
# through a 'config/initializers' folder, as follows:
|
26
|
+
#
|
27
|
+
# require 'airbrake'
|
28
|
+
#
|
29
|
+
# Airbrake.configure do | config |
|
30
|
+
# config.api_key = 'YOUR_AIRBRAKE_API_KEY'
|
31
|
+
# end
|
32
|
+
#
|
33
|
+
# Hoodoo::Services::Middleware::ExceptionReporting.add(
|
34
|
+
# Hoodoo::Services::Middleware::ExceptionReporting::AirbrakeReporter
|
35
|
+
# ) unless Service.config.env.test? || Service.config.env.development?
|
36
|
+
#
|
37
|
+
# Services and the Hoodoo middleware do not pass Rails-like params
|
38
|
+
# around in forms or query strings, but do beware of search or filter
|
39
|
+
# query data containing sensitive material or POST bodies in e.g. JSON
|
40
|
+
# encoding containing sensitive data. This comes down to the filtering
|
41
|
+
# ability of the Airbrake gem:
|
42
|
+
#
|
43
|
+
# https://github.com/airbrake/airbrake/wiki/Customizing-your-airbrake.rb
|
44
|
+
#
|
45
|
+
class AirbrakeReporter < Hoodoo::Services::Middleware::ExceptionReporting::BaseReporter
|
46
|
+
|
47
|
+
# Report an exception to Airbrake.
|
48
|
+
#
|
49
|
+
# +e+:: Exception (or subclass) instance to be reported.
|
50
|
+
#
|
51
|
+
# +env+:: Optional Rack environment hash for the inbound request, for
|
52
|
+
# exception reports made in the context of Rack request
|
53
|
+
# handling. In the case of Airbrake, the call may just hang
|
54
|
+
# unless a Rack environment is provided.
|
55
|
+
#
|
56
|
+
def report( e, env = nil )
|
57
|
+
Airbrake.notify_or_ignore( e, :rack_env => env )
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
end
|
62
|
+
|
63
|
+
end
|
64
|
+
end; end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
########################################################################
|
2
|
+
# File:: raygun_reporter.rb
|
3
|
+
# (C):: Loyalty New Zealand 2014
|
4
|
+
#
|
5
|
+
# Purpose:: Send exception details to Raygun.
|
6
|
+
# ----------------------------------------------------------------------
|
7
|
+
# 08-Dec-2014 (ADH): Created.
|
8
|
+
########################################################################
|
9
|
+
|
10
|
+
module Hoodoo; module Services
|
11
|
+
class Middleware
|
12
|
+
|
13
|
+
class ExceptionReporting
|
14
|
+
|
15
|
+
# Hoodoo::Services::Middleware::ExceptionReporting::BaseReporter subclass
|
16
|
+
# giving Hoodoo::Services::Middleware::ExceptionReporting access to
|
17
|
+
# Raygun for error reporting. See https://raygun.io.
|
18
|
+
#
|
19
|
+
# Your application must include the Raygun gem 'raygun4ruby' via Gemfile
|
20
|
+
# (+gem 'raygun4ruby'+ / +bundle install) or direct installation (+gem
|
21
|
+
# install raygun4ruby+).
|
22
|
+
#
|
23
|
+
# The API key must be set during your application initialization and the
|
24
|
+
# class must be added to Hoodoo for use as an error reporter, e.g.
|
25
|
+
# through a 'config/initializers' folder, as follows:
|
26
|
+
#
|
27
|
+
# require 'raygun4ruby'
|
28
|
+
#
|
29
|
+
# Raygun.setup do | config |
|
30
|
+
# config.api_key = 'YOUR_RAYGUN_API_KEY'
|
31
|
+
# end
|
32
|
+
#
|
33
|
+
# Hoodoo::Services::Middleware::ExceptionReporting.add(
|
34
|
+
# Hoodoo::Services::Middleware::ExceptionReporting::RaygunReporter
|
35
|
+
# ) unless Service.config.env.test? || Service.config.env.development?
|
36
|
+
#
|
37
|
+
# Services and the Hoodoo middleware do not pass Rails-like params
|
38
|
+
# around in forms or query strings, but do beware of search or filter
|
39
|
+
# query data containing sensitive material or POST bodies in e.g. JSON
|
40
|
+
# encoding containing sensitive data. This comes down to the filtering
|
41
|
+
# ability of the Raygun gem:
|
42
|
+
#
|
43
|
+
# https://github.com/MindscapeHQ/raygun4ruby
|
44
|
+
#
|
45
|
+
class RaygunReporter < Hoodoo::Services::Middleware::ExceptionReporting::BaseReporter
|
46
|
+
|
47
|
+
# Report an exception to Raygun.
|
48
|
+
#
|
49
|
+
# +e+:: Exception (or subclass) instance to be reported.
|
50
|
+
#
|
51
|
+
# +env+:: Optional Rack environment hash for the inbound request, for
|
52
|
+
# exception reports made in the context of Rack request
|
53
|
+
# handling.
|
54
|
+
#
|
55
|
+
def report( e, env = nil )
|
56
|
+
Raygun.track_exception( e, env )
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
end
|
61
|
+
|
62
|
+
end
|
63
|
+
end; end
|
@@ -0,0 +1,127 @@
|
|
1
|
+
########################################################################
|
2
|
+
# File:: interaction.rb
|
3
|
+
# (C):: Loyalty New Zealand 2015
|
4
|
+
#
|
5
|
+
# Purpose:: Encapsulate all data related to an interaction (API call)
|
6
|
+
# inside an object.
|
7
|
+
# ----------------------------------------------------------------------
|
8
|
+
# 13-Feb-2015 (ADH): Created.
|
9
|
+
########################################################################
|
10
|
+
|
11
|
+
module Hoodoo; module Services; class Middleware
|
12
|
+
|
13
|
+
# Encapsulate all data related to an interaction (API call) within
|
14
|
+
# one object.
|
15
|
+
#
|
16
|
+
class Interaction
|
17
|
+
|
18
|
+
public
|
19
|
+
|
20
|
+
# API calls are handled by the middleware, so Interactions are
|
21
|
+
# created by Hoodoo::Services::Middleware instances. This is that
|
22
|
+
# creating instance, or the instance that should be treated as if
|
23
|
+
# it were the creator.
|
24
|
+
#
|
25
|
+
attr_reader :owning_middleware_instance
|
26
|
+
|
27
|
+
# The inbound Rack request a Rack::Request instance.
|
28
|
+
#
|
29
|
+
attr_reader :rack_request
|
30
|
+
|
31
|
+
# Every interaction has a UUID passed back in API responses via
|
32
|
+
# the X-Interaction-ID HTTP header. This is that UUID.
|
33
|
+
#
|
34
|
+
attr_reader :interaction_id
|
35
|
+
|
36
|
+
# A Hoodoo::Services::Context instance representing this API call.
|
37
|
+
# May be updated/replaced during processing.
|
38
|
+
#
|
39
|
+
attr_accessor :context
|
40
|
+
|
41
|
+
# The Hoodoo::Services::Interface subclass describing the resource
|
42
|
+
# interface that is the target of the API call.
|
43
|
+
#
|
44
|
+
attr_accessor :target_interface
|
45
|
+
|
46
|
+
# The target Hoodoo::Services::Implementation instance for the
|
47
|
+
# API call. See #target_interface.
|
48
|
+
#
|
49
|
+
attr_accessor :target_implementation
|
50
|
+
|
51
|
+
# The requested action, as a symbol; see
|
52
|
+
# Hoodoo::Services::Middleware::ALLOWED_ACTIONS.
|
53
|
+
#
|
54
|
+
attr_accessor :requested_action
|
55
|
+
|
56
|
+
# The requested content type as a String - e.g. "application/json".
|
57
|
+
#
|
58
|
+
attr_accessor :requested_content_type
|
59
|
+
|
60
|
+
# The requested content encoding as a String - e.g. "utf-8".
|
61
|
+
#
|
62
|
+
attr_accessor :requested_content_encoding
|
63
|
+
|
64
|
+
# Hoodoo middleware calls here to say "I'm using the test session" (or
|
65
|
+
# not), so that this can be enquired about via #using_test_session? if
|
66
|
+
# need be.
|
67
|
+
#
|
68
|
+
def using_test_session
|
69
|
+
@using_test_session = true
|
70
|
+
end
|
71
|
+
|
72
|
+
# Returns +true+ if Hoodoo has previously called #using_test_session.
|
73
|
+
#
|
74
|
+
def using_test_session?
|
75
|
+
@using_test_session === true
|
76
|
+
end
|
77
|
+
|
78
|
+
# Create a new Interaction instance, acquiring a new interaction
|
79
|
+
# ID automatically or picking up one from an X-Interaction-ID
|
80
|
+
# header if available.
|
81
|
+
#
|
82
|
+
# A new context instance (see #context) is generated with a new
|
83
|
+
# empty request and response object attached, along with +nil+
|
84
|
+
# session data or the given session information in the input
|
85
|
+
# parameters:
|
86
|
+
#
|
87
|
+
# +env+:: The raw Rack request Hash. May be "{}" in some test
|
88
|
+
# scenarios. Converted to a Rack::Request instance. If
|
89
|
+
# this describes an X-Interaction-ID header then this
|
90
|
+
# Interaction will use - without validation - whatever
|
91
|
+
# value the header holds, else a new UUID is generated.
|
92
|
+
#
|
93
|
+
# +owning_middleware_instance+:: See #owning_middleware_instance.
|
94
|
+
#
|
95
|
+
# +session+:: The session data attached to the #context value;
|
96
|
+
# optional; if omitted, +nil+ is used.
|
97
|
+
#
|
98
|
+
def initialize( env, owning_middleware_instance, session = nil )
|
99
|
+
@rack_request = ::Rack::Request.new( env )
|
100
|
+
@interaction_id = find_or_generate_interaction_id()
|
101
|
+
@context = Hoodoo::Services::Context.new(
|
102
|
+
session,
|
103
|
+
Hoodoo::Services::Request.new,
|
104
|
+
Hoodoo::Services::Response.new( @interaction_id ),
|
105
|
+
self
|
106
|
+
)
|
107
|
+
|
108
|
+
@owning_middleware_instance = owning_middleware_instance
|
109
|
+
@context.request.headers = env.select() do | k,v |
|
110
|
+
k.to_s.start_with?( 'HTTP_' ) || k == 'CONTENT_TYPE' || k == 'CONTENT_LENGTH'
|
111
|
+
end.freeze()
|
112
|
+
end
|
113
|
+
|
114
|
+
private
|
115
|
+
|
116
|
+
# Find the value of an X-Interaction-ID header (if one is already present)
|
117
|
+
# or generate a new Interaction ID.
|
118
|
+
#
|
119
|
+
def find_or_generate_interaction_id
|
120
|
+
iid = self.rack_request.env[ 'HTTP_X_INTERACTION_ID' ]
|
121
|
+
iid = Hoodoo::UUID.generate() if iid.nil? || iid == ''
|
122
|
+
iid
|
123
|
+
end
|
124
|
+
|
125
|
+
end
|
126
|
+
|
127
|
+
end; end; end
|