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,58 @@
|
|
1
|
+
########################################################################
|
2
|
+
# File:: for_amqp.rb
|
3
|
+
# (C):: Loyalty New Zealand 2015
|
4
|
+
#
|
5
|
+
# Purpose:: Describe a resource endpoint location in a way that allows
|
6
|
+
# it to be contacted over AMQP (e.g. via Alchemy).
|
7
|
+
# ----------------------------------------------------------------------
|
8
|
+
# 03-Mar-2015 (ADH): Created.
|
9
|
+
########################################################################
|
10
|
+
|
11
|
+
module Hoodoo
|
12
|
+
module Services
|
13
|
+
class Discovery # Just used as a namespace here
|
14
|
+
|
15
|
+
# Describe a resource endpoint location in a way that allows
|
16
|
+
# it to be contacted over AMQP (e.g. via Alchemy).
|
17
|
+
#
|
18
|
+
class ForAMQP
|
19
|
+
|
20
|
+
# The resource name described, as a Symbol (e.g. +:Purchase+).
|
21
|
+
#
|
22
|
+
attr_accessor :resource
|
23
|
+
|
24
|
+
# Resource endpoint version, as an Integer (e.g. 2).
|
25
|
+
#
|
26
|
+
attr_accessor :version
|
27
|
+
|
28
|
+
# Queue name for the target service implementation, as a
|
29
|
+
# String (e.g. "service.account").
|
30
|
+
#
|
31
|
+
attr_accessor :queue_name
|
32
|
+
|
33
|
+
# URL path equivalent that should be mapped to the queue in
|
34
|
+
# #queue_name, as a String (e.g. "/v2/accounts").
|
35
|
+
#
|
36
|
+
attr_accessor :equivalent_path
|
37
|
+
|
38
|
+
# Create an instance with named parameters as follows:
|
39
|
+
#
|
40
|
+
# +resource+:: See #resource.
|
41
|
+
# +version+:: See #version.
|
42
|
+
# +queue_name+:: See #queue_name.
|
43
|
+
# +equivalent_pat+:: See #equivalent_pat.
|
44
|
+
#
|
45
|
+
def initialize( resource:,
|
46
|
+
version:,
|
47
|
+
queue_name:,
|
48
|
+
equivalent_path: )
|
49
|
+
|
50
|
+
self.resource = resource.to_sym
|
51
|
+
self.version = version.to_i
|
52
|
+
self.queue_name = queue_name
|
53
|
+
self.equivalent_path = equivalent_path
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,85 @@
|
|
1
|
+
########################################################################
|
2
|
+
# File:: for_http.rb
|
3
|
+
# (C):: Loyalty New Zealand 2015
|
4
|
+
#
|
5
|
+
# Purpose:: Describe a resource endpoint location in a way that allows
|
6
|
+
# it to be contacted over HTTP.
|
7
|
+
# ----------------------------------------------------------------------
|
8
|
+
# 03-Mar-2015 (ADH): Created.
|
9
|
+
########################################################################
|
10
|
+
|
11
|
+
module Hoodoo
|
12
|
+
module Services
|
13
|
+
class Discovery # Just used as a namespace here
|
14
|
+
|
15
|
+
# Describe a resource endpoint location in a way that allows
|
16
|
+
# it to be contacted over HTTP.
|
17
|
+
#
|
18
|
+
class ForHTTP
|
19
|
+
|
20
|
+
# The resource name described, as a Symbol (e.g. +:Purchase+).
|
21
|
+
#
|
22
|
+
attr_accessor :resource
|
23
|
+
|
24
|
+
# Resource endpoint version, as an Integer (e.g. 2).
|
25
|
+
#
|
26
|
+
attr_accessor :version
|
27
|
+
|
28
|
+
# Full URI (as a URI object) at which the resource endpoint
|
29
|
+
# implementation can be contacted.
|
30
|
+
#
|
31
|
+
attr_accessor :endpoint_uri
|
32
|
+
|
33
|
+
# Full URI (as a URI object) of an HTTP proxy to use as an
|
34
|
+
# override to <tt>ENV['HTTP_PROXY']</tt> which Ruby itself
|
35
|
+
# will otherwise read. Will be +nil+ for no proxy override.
|
36
|
+
#
|
37
|
+
attr_accessor :proxy_uri
|
38
|
+
|
39
|
+
# An optional String indicating a relative or absolute file
|
40
|
+
# path to the location of a .pem format Certificate
|
41
|
+
# Authority file (trust store), which may include multliple
|
42
|
+
# certificates. The certificates in the file will be used
|
43
|
+
# by Net::HTTP to validate the SSL Ceritificate Chain
|
44
|
+
# presented by remote servers, when calling endpoints over
|
45
|
+
# HTTPS with Hoodoo::Client.
|
46
|
+
#
|
47
|
+
# Default +nil+ value should be used in nearly all cases
|
48
|
+
# and uses Ruby OpenSSL defaults which are generally
|
49
|
+
# Operating System provided.
|
50
|
+
#
|
51
|
+
attr_accessor :ca_file
|
52
|
+
|
53
|
+
# Optional Float indicating the Net::HTTP read timeout value.
|
54
|
+
# This operates at the HTTP transport level and is independent
|
55
|
+
# of any timeouts set within the API providing server.
|
56
|
+
#
|
57
|
+
attr_accessor :http_timeout
|
58
|
+
|
59
|
+
# Create an instance with named parameters as follows:
|
60
|
+
#
|
61
|
+
# +resource+:: See #resource.
|
62
|
+
# +version+:: See #version.
|
63
|
+
# +endpoint_uri+:: See #endpoint_uri.
|
64
|
+
# +proxy_uri+:: See #proxy_uri. Optional.
|
65
|
+
# +ca_file+:: See #ca_file. Optional.
|
66
|
+
# +http_timeout+:: See #http_timeout. Optional.
|
67
|
+
#
|
68
|
+
def initialize( resource:,
|
69
|
+
version:,
|
70
|
+
endpoint_uri:,
|
71
|
+
proxy_uri: nil,
|
72
|
+
ca_file: nil,
|
73
|
+
http_timeout: nil )
|
74
|
+
|
75
|
+
self.resource = resource.to_sym
|
76
|
+
self.version = version.to_i
|
77
|
+
self.endpoint_uri = endpoint_uri
|
78
|
+
self.proxy_uri = proxy_uri
|
79
|
+
self.ca_file = ca_file
|
80
|
+
self.http_timeout = http_timeout
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
@@ -0,0 +1,85 @@
|
|
1
|
+
########################################################################
|
2
|
+
# File:: for_local.rb
|
3
|
+
# (C):: Loyalty New Zealand 2015
|
4
|
+
#
|
5
|
+
# Purpose:: Describe a resource endpoint location in a way that allows
|
6
|
+
# it to be method-called from the service middleware directly.
|
7
|
+
# ----------------------------------------------------------------------
|
8
|
+
# 10-Mar-2015 (ADH): Created.
|
9
|
+
########################################################################
|
10
|
+
|
11
|
+
module Hoodoo
|
12
|
+
module Services
|
13
|
+
class Discovery # Just used as a namespace here
|
14
|
+
|
15
|
+
# Describe a resource endpoint location in a way that allows it to be
|
16
|
+
# method-called from the service middleware directly.
|
17
|
+
#
|
18
|
+
# This is a very special case class used for the inter-resource local
|
19
|
+
# call code in Hoodoo::Services::Middleware. It really exists only for
|
20
|
+
# semantic purposes; the middleware calls via Hoodoo::Client::Endpoint
|
21
|
+
# subclass Hoodoo::Sevices::Middleware::InterResourceLocal; and the
|
22
|
+
# Endpoint subclass family are supposed to use result classes from the
|
23
|
+
# Hoodoo::Services::Discovery engine when they configure instances.
|
24
|
+
#
|
25
|
+
# This isn't actually enforced anywhere, but conceptually it's cleanest
|
26
|
+
# to follow the same pattern.
|
27
|
+
#
|
28
|
+
class ForLocal
|
29
|
+
|
30
|
+
# The resource name described, as a Symbol (e.g. +:Purchase+).
|
31
|
+
#
|
32
|
+
attr_accessor :resource
|
33
|
+
|
34
|
+
# Resource endpoint version, as an Integer (e.g. 2).
|
35
|
+
#
|
36
|
+
attr_accessor :version
|
37
|
+
|
38
|
+
# The base path of this resource and version - for example,
|
39
|
+
# "/v1/products" or "/v2/members". String.
|
40
|
+
#
|
41
|
+
attr_accessor :base_path
|
42
|
+
|
43
|
+
# A regular expression which matches the #base_path and any
|
44
|
+
# identifier data, allowing inbound URI-based requests to be
|
45
|
+
# routed to this endpoint. Regexp instance.
|
46
|
+
#
|
47
|
+
attr_accessor :routing_regexp
|
48
|
+
|
49
|
+
# The Hoodoo::Services::Interface subclass _class_ describing the
|
50
|
+
# resource interface.
|
51
|
+
#
|
52
|
+
attr_accessor :interface_class
|
53
|
+
|
54
|
+
# The Hoodoo::Services::Implementation subclass _instance_
|
55
|
+
# which implements the interface described by #interface_class.
|
56
|
+
#
|
57
|
+
attr_accessor :implementation_instance
|
58
|
+
|
59
|
+
# Create an instance with named parameters as follows:
|
60
|
+
#
|
61
|
+
# +resource+:: See #resource.
|
62
|
+
# +version+:: See #version.
|
63
|
+
# +base_path+:: See #base_path.
|
64
|
+
# +routing_regexp+:: See #routing_regexp.
|
65
|
+
# +interface_class+:: See #interface_class.
|
66
|
+
# +implementation_instance+:: See #implementation_instance.
|
67
|
+
#
|
68
|
+
def initialize( resource:,
|
69
|
+
version:,
|
70
|
+
base_path:,
|
71
|
+
routing_regexp:,
|
72
|
+
interface_class:,
|
73
|
+
implementation_instance: )
|
74
|
+
|
75
|
+
self.resource = resource.to_sym
|
76
|
+
self.version = version.to_i
|
77
|
+
self.base_path = base_path
|
78
|
+
self.routing_regexp = routing_regexp
|
79
|
+
self.interface_class = interface_class
|
80
|
+
self.implementation_instance = implementation_instance
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
########################################################################
|
2
|
+
# File:: for_remote.rb
|
3
|
+
# (C):: Loyalty New Zealand 2015
|
4
|
+
#
|
5
|
+
# Purpose:: Describe a "pseudo" resource endpoint location in terms of
|
6
|
+
# an interation context and wrapped "real" endpoint instance.
|
7
|
+
# ----------------------------------------------------------------------
|
8
|
+
# 10-Mar-2015 (ADH): Created.
|
9
|
+
########################################################################
|
10
|
+
|
11
|
+
module Hoodoo
|
12
|
+
module Services
|
13
|
+
class Discovery # Just used as a namespace here
|
14
|
+
|
15
|
+
# Describe a "pseudo" resource endpoint location in terms of
|
16
|
+
# an interation context and wrapped "real" endpoint instance.
|
17
|
+
#
|
18
|
+
# This is a very special case class used for wrapping endpoints in, for
|
19
|
+
# example, the inter-resource remote call code in the middleware and in
|
20
|
+
# the auto-session code in Hoodoo::Client::Endpoint::AutoSession.
|
21
|
+
#
|
22
|
+
class ForRemote
|
23
|
+
|
24
|
+
# The resource name described, as a Symbol (e.g. +:Purchase+).
|
25
|
+
#
|
26
|
+
attr_accessor :resource
|
27
|
+
|
28
|
+
# Resource endpoint version, as an Integer (e.g. 2).
|
29
|
+
#
|
30
|
+
attr_accessor :version
|
31
|
+
|
32
|
+
# A wrapped Endpoint class, which will be used for the *actual* call
|
33
|
+
# to the remote resource, after pre/post-processing in the context of
|
34
|
+
# #source_interaction (e.g. augmenting session permissions with
|
35
|
+
# source-resource-interface-specified additions necessary to call the
|
36
|
+
# target remote resource).
|
37
|
+
#
|
38
|
+
attr_accessor :wrapped_endpoint
|
39
|
+
|
40
|
+
# Create an instance with named parameters as follows:
|
41
|
+
#
|
42
|
+
# +resource+:: See #resource.
|
43
|
+
# +version+:: See #version.
|
44
|
+
# +wrapped_endpoint+:: See #wrapped_endpoint.
|
45
|
+
#
|
46
|
+
def initialize( resource:,
|
47
|
+
version:,
|
48
|
+
wrapped_endpoint: )
|
49
|
+
|
50
|
+
self.resource = resource.to_sym
|
51
|
+
self.version = version.to_i
|
52
|
+
self.wrapped_endpoint = wrapped_endpoint
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,186 @@
|
|
1
|
+
########################################################################
|
2
|
+
# File:: amqp_log_message.rb
|
3
|
+
# (C):: Loyalty New Zealand 2014
|
4
|
+
#
|
5
|
+
# Purpose:: Structured logging onto an AMQP-based queue, via the
|
6
|
+
# AlchemyAMQ gem. Optional; class is defined only if the
|
7
|
+
# supporting AlchemyAMQ gem's classes are defined.
|
8
|
+
#
|
9
|
+
# The middleware uses this to put log and error messages
|
10
|
+
# on the queue. Interested services use this to read such
|
11
|
+
# messages from the queue.
|
12
|
+
# ----------------------------------------------------------------------
|
13
|
+
# 20-Nov-2014 (ADH): Created.
|
14
|
+
########################################################################
|
15
|
+
|
16
|
+
# TODO: See spec/alchemy/alchemy-amq.rb. Remove this once 'real' Alchemy
|
17
|
+
# is opened.
|
18
|
+
#
|
19
|
+
$LOAD_PATH.unshift File.join( File.dirname( __FILE__ ), 'alchemy' )
|
20
|
+
|
21
|
+
module Hoodoo; module Services
|
22
|
+
class Middleware
|
23
|
+
|
24
|
+
begin
|
25
|
+
require 'alchemy-amq' # Optional
|
26
|
+
|
27
|
+
# For AlchemyAMQ gem users, the AMQPLogMessage class provides an
|
28
|
+
# AlchemyAMQ::Message subclass used for sending structured log data to
|
29
|
+
# the queue. Hoodoo::Logger uses this.
|
30
|
+
#
|
31
|
+
# See the AlchemyAMQ gem for more details.
|
32
|
+
#
|
33
|
+
class AMQPLogMessage < ::AlchemyAMQ::Message
|
34
|
+
|
35
|
+
# The named "type" of this message, to be registered with AlchemyAMQ.
|
36
|
+
#
|
37
|
+
TYPE = 'hoodoo_service_middleware_amqp_log_message'
|
38
|
+
|
39
|
+
# The Time +strftime+ formatter used for string conversions in this
|
40
|
+
# class.
|
41
|
+
#
|
42
|
+
TIME_FORMATTER = '%Y-%m-%d %H:%M:%S.%12N %Z'
|
43
|
+
|
44
|
+
# This line of code registers wth AlchemyAMQ, but also makes RDoc
|
45
|
+
# screw up. RDoc decides that we have a new module,
|
46
|
+
# Hoodoo::Services::Middleware::AMQPLogMessage::AlchemyAMQ. Very
|
47
|
+
# strange...
|
48
|
+
#
|
49
|
+
::AlchemyAMQ::Message.register_type( TYPE, self )
|
50
|
+
|
51
|
+
# ...so do _this_ purely so that we can get 100% real documentation
|
52
|
+
# coverage without it being clouded by RDoc's hiccups.
|
53
|
+
|
54
|
+
# This documentation exists purely to work around an RDoc hiccup where
|
55
|
+
# it thinks such a module exists.
|
56
|
+
#
|
57
|
+
# See file "services/middleware/amqp_log_message.rb" for details.
|
58
|
+
#
|
59
|
+
module AlchemyAMQ
|
60
|
+
end
|
61
|
+
|
62
|
+
# A UUID to assign to this log message. See Hoodoo::UUID::generate.
|
63
|
+
#
|
64
|
+
attr_accessor :id
|
65
|
+
|
66
|
+
# Logging level. See Hoodoo::Logger.
|
67
|
+
#
|
68
|
+
attr_accessor :level
|
69
|
+
|
70
|
+
# Logging component. See Hoodoo::Logger.
|
71
|
+
#
|
72
|
+
attr_accessor :component
|
73
|
+
|
74
|
+
# Component log code. See Hoodoo::Logger.
|
75
|
+
#
|
76
|
+
attr_accessor :code
|
77
|
+
|
78
|
+
# The time at which this log message is being reported to the Logger
|
79
|
+
# instance. This is a formatted *String* to high accuracy. See also
|
80
|
+
# #reported_at=.
|
81
|
+
#
|
82
|
+
attr_reader :reported_at
|
83
|
+
|
84
|
+
# Set the time read back by #reported_at using a Time instance. This
|
85
|
+
# is formatted internally as a String via TIME_FORMATTER and reported
|
86
|
+
# as such in subsequent calls to #reported_at.
|
87
|
+
#
|
88
|
+
# Conversion from Time to String is done here, rather than by the
|
89
|
+
# caller setting this instance's variables, so that we can internally
|
90
|
+
# enforce the accuracy required for this field.
|
91
|
+
#
|
92
|
+
# +time+:: The Time instance to set (and process into a string
|
93
|
+
# internally via TIME_FORMATTER), *or* a String instance
|
94
|
+
# already so formatted, *or* +nil+ to clear the value.
|
95
|
+
#
|
96
|
+
def reported_at=( time )
|
97
|
+
if time.is_a?( String )
|
98
|
+
@reported_at = time
|
99
|
+
elsif time.is_a?( Time )
|
100
|
+
@reported_at = time.strftime( TIME_FORMATTER )
|
101
|
+
else
|
102
|
+
@reported_at = nil
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
# Log payload. See Hoodoo::Logger.
|
107
|
+
#
|
108
|
+
attr_accessor :data
|
109
|
+
|
110
|
+
# Optional calling Caller ID, via session data inside the payload - see
|
111
|
+
# Hoodoo::Logger.
|
112
|
+
#
|
113
|
+
attr_accessor :caller_id
|
114
|
+
|
115
|
+
# Optional interaction UUID, via session data inside the payload - see
|
116
|
+
# Hoodoo::Logger.
|
117
|
+
#
|
118
|
+
attr_accessor :interaction_id
|
119
|
+
|
120
|
+
# Optional hash of identity properties from the session data inside the
|
121
|
+
# payload - see Hoodoo::Logger.
|
122
|
+
#
|
123
|
+
attr_accessor :identity
|
124
|
+
|
125
|
+
# Create an instance with options keyed on the attributes defined for
|
126
|
+
# the class.
|
127
|
+
#
|
128
|
+
def initialize(options = {})
|
129
|
+
update( options ) # Should be called before 'super'
|
130
|
+
super( options )
|
131
|
+
|
132
|
+
@type = AMQPLogMessage::TYPE
|
133
|
+
end
|
134
|
+
|
135
|
+
# Seralize this instance. See the AlchemyAMQ gem and
|
136
|
+
# AlchemyAMQ::Message#serialize.
|
137
|
+
#
|
138
|
+
def serialize
|
139
|
+
@content = {
|
140
|
+
:id => @id,
|
141
|
+
:level => @level,
|
142
|
+
:component => @component,
|
143
|
+
:code => @code,
|
144
|
+
:reported_at => @reported_at,
|
145
|
+
|
146
|
+
:data => @data,
|
147
|
+
|
148
|
+
:interaction_id => @interaction_id,
|
149
|
+
:caller_id => @caller_id,
|
150
|
+
:identity => @identity
|
151
|
+
}
|
152
|
+
|
153
|
+
super
|
154
|
+
end
|
155
|
+
|
156
|
+
# Unpack a serialized representation into this instance. See the
|
157
|
+
# AlchemyAMQ gem and AlchemyAMQ::Message#deserialize.
|
158
|
+
#
|
159
|
+
def deserialize
|
160
|
+
super
|
161
|
+
update( @content )
|
162
|
+
end
|
163
|
+
|
164
|
+
# Set public attribute values according to an options hash keyed on
|
165
|
+
# the attributes defined for the class.
|
166
|
+
#
|
167
|
+
def update( options )
|
168
|
+
self.id = options[ :id ]
|
169
|
+
self.level = options[ :level ]
|
170
|
+
self.component = options[ :component ]
|
171
|
+
self.code = options[ :code ]
|
172
|
+
self.reported_at = options[ :reported_at ]
|
173
|
+
|
174
|
+
self.data = options[ :data ]
|
175
|
+
|
176
|
+
self.interaction_id = options[ :interaction_id ]
|
177
|
+
self.caller_id = options[ :caller_id ]
|
178
|
+
self.identity = options[ :identity ]
|
179
|
+
end
|
180
|
+
end
|
181
|
+
|
182
|
+
rescue LoadError # Optional file 'alchemy-amq' is absent
|
183
|
+
end
|
184
|
+
|
185
|
+
end
|
186
|
+
end; end
|